Basic graphics structure

This commit is contained in:
HOEGLER Stefan
2020-03-02 19:07:49 +01:00
parent a14237d6ce
commit 4c2535931e
16 changed files with 137 additions and 48 deletions
+1
View File
@@ -47,6 +47,7 @@ include_directories(src/Engine)
add_definitions(${GLM_DEFINITIONS}) add_definitions(${GLM_DEFINITIONS})
add_definitions(${Vulkan_DEFINITIONS}) add_definitions(${Vulkan_DEFINITIONS})
add_definitions(${Boost_DEFINITIONS}) add_definitions(${Boost_DEFINITIONS})
add_compile_definitions(GLFW_WINDOWS)
add_executable(SeeleEngine "") add_executable(SeeleEngine "")
add_subdirectory(src/) add_subdirectory(src/)
target_link_libraries(SeeleEngine ${Boost_LIBRARIES}) target_link_libraries(SeeleEngine ${Boost_LIBRARIES})
+3 -3
View File
@@ -16,7 +16,7 @@ namespace Seele
: allocated(DEFAULT_ALLOC_SIZE) : allocated(DEFAULT_ALLOC_SIZE)
, arraySize(0) , arraySize(0)
{ {
_data = new T[DEFAULT_ALLOC_SIZE]; _data = (T*)malloc(DEFAULT_ALLOC_SIZE * sizeof(T));
refreshIterators(); refreshIterators();
} }
Array(size_t size, T value = T()) Array(size_t size, T value = T())
@@ -110,10 +110,10 @@ namespace Seele
if (arraySize == allocated) if (arraySize == allocated)
{ {
allocated += DEFAULT_ALLOC_SIZE; allocated += DEFAULT_ALLOC_SIZE;
T* tempArray = new T[allocated]; void* tempArray = malloc(sizeof(T) * allocated);
std::memcpy(tempArray, _data, arraySize * sizeof(T)); std::memcpy(tempArray, _data, arraySize * sizeof(T));
delete _data; delete _data;
_data = tempArray; _data = (T*)tempArray;
} }
_data[arraySize++] = item; _data[arraySize++] = item;
refreshIterators(); refreshIterators();
+3
View File
@@ -2,7 +2,10 @@ target_sources(SeeleEngine
PRIVATE PRIVATE
Graphics.h Graphics.h
Graphics.cpp Graphics.cpp
RenderPath.h
RenderPath.cpp
View.h View.h
View.cpp
WindowManager.h WindowManager.h
WindowManager.cpp WindowManager.cpp
Window.h Window.h
+6 -12
View File
@@ -1,28 +1,22 @@
#pragma once #pragma once
#include "MinimalEngine.h" #include "MinimalEngine.h"
#include "GraphicsResources.h" #include "GraphicsResources.h"
#include "Containers/Array.h"
namespace Seele { namespace Seele {
class Window; class Window;
class Graphics class Graphics
{ {
public: public:
static Graphics& getInstance() virtual void init(GraphicsInitializer initializer) = 0;
{ virtual void beginFrame() = 0;
static Graphics instance; virtual void endFrame() = 0;
virtual void* createWindow(const WindowCreateInfo& createInfo) = 0;
return instance;
}
void init(GraphicsInitializer initializer);
void beginFrame();
void endFrame();
//Singleton //Singleton
private: private:
Graphics(); Graphics();
Graphics(Graphics const&) = delete;
void operator=(Graphics const&) = delete;
~Graphics(); ~Graphics();
friend class Window;
}; };
} }
+8
View File
@@ -6,4 +6,12 @@ namespace Seele
{ {
const char* windowLayoutFile; const char* windowLayoutFile;
}; };
struct WindowCreateInfo
{
int32 width;
int32 height;
const char* title;
bool bFullscreen;
};
} }
+6
View File
@@ -0,0 +1,6 @@
#include "RenderPath.h"
Seele::RenderPath::RenderPath(Graphics* graphics)
: graphics(graphics)
{
}
+19
View File
@@ -0,0 +1,19 @@
#pragma once
#include "Graphics.h"
namespace Seele
{
//A renderpath is a general Renderer for a view.
class RenderPath
{
public:
RenderPath(Graphics* graphics);
virtual ~RenderPath();
virtual void init() = 0;
virtual void beginFrame() = 0;
virtual void render() = 0;
virtual void endFrame() = 0;
protected:
Graphics* graphics;
};
DECLARE_REF(RenderPath);
}
+10
View File
@@ -0,0 +1,10 @@
#include "View.h"
Seele::View::View(PSection owner)
: owner(owner)
{
}
Seele::View::~View()
{
}
+15 -7
View File
@@ -1,10 +1,18 @@
#pragma once #pragma once
#include "Window.h" #include "Window.h"
#include "RenderPath.h"
// A view is a part of the window, which can be anything from a viewport to an editor namespace Seele
class View
{ {
public: // A view is a part of the window, which can be anything from a viewport to an editor
private: class View
Window::Section* owner; {
}; public:
View(PSection owner);
~View();
private:
PRenderPath renderer;
PSection owner;
};
DECLARE_REF(View)
}
@@ -0,0 +1,4 @@
target_sources(SeeleEngine
PRIVATE
VulkanGraphics.h
VulkanGraphics.cpp)
@@ -0,0 +1,18 @@
#include "VulkanGraphics.h"
void Seele::VulkanGraphics::init(GraphicsInitializer initializer)
{
}
void Seele::VulkanGraphics::beginFrame()
{
}
void Seele::VulkanGraphics::endFrame()
{
}
void* Seele::VulkanGraphics::createWindow(const WindowCreateInfo& createInfo)
{
return nullptr;
}
@@ -0,0 +1,14 @@
#include "Graphics/Graphics.h"
namespace Seele
{
class VulkanGraphics : public Graphics
{
public:
// Inherited via Graphics
virtual void init(GraphicsInitializer initializer) override;
virtual void beginFrame() override;
virtual void endFrame() override;
virtual void* createWindow(const WindowCreateInfo& createInfo) override;
};
}
+5 -3
View File
@@ -1,12 +1,14 @@
#include "Window.h" #include "Window.h"
#include "Graphics.h" #include "Vulkan/VulkanGraphics.h"
#include <iostream>
Seele::Window::Window(const WindowCreateInfo& createInfo) Seele::Window::Window(const WindowCreateInfo& createInfo)
: width(createInfo.width)
, height(createInfo.height)
, windowHandle(nullptr)
{ {
graphics = new VulkanGraphics();
} }
Seele::Window::~Window() Seele::Window::~Window()
{ {
} }
+12 -13
View File
@@ -1,18 +1,7 @@
#pragma once #pragma once
#include "MinimalEngine.h" #include "MinimalEngine.h"
namespace Seele { namespace Seele {
struct WindowCreateInfo
{
int32 width;
int32 height;
const char* title;
};
class Window
{
public:
Window(const WindowCreateInfo& createInfo);
~Window();
private:
// A window is divided into 5 sections, using a border layout // A window is divided into 5 sections, using a border layout
// +--------------TOP------------------+ // +--------------TOP------------------+
// | | // | |
@@ -26,8 +15,16 @@ namespace Seele {
// of views, when there are multiple, they stack to tabs // of views, when there are multiple, they stack to tabs
struct Section struct Section
{ {
}; };
DECLARE_REF(Section)
class Window
{
public:
Window(const WindowCreateInfo& createInfo);
~Window();
private:
void* windowHandle;
Section top; Section top;
Section bot; Section bot;
Section left; Section left;
@@ -35,5 +32,7 @@ namespace Seele {
Section center; Section center;
uint32 width; uint32 width;
uint32 height; uint32 height;
Graphics* graphics;
}; };
DECLARE_REF(Window)
} }
+1 -1
View File
@@ -11,6 +11,6 @@ namespace Seele
WindowManager(GraphicsInitializer initializer); WindowManager(GraphicsInitializer initializer);
~WindowManager(); ~WindowManager();
private: private:
Array<RefPtr<Window>> windows; Array<PWindow> windows;
}; };
} }
+5 -2
View File
@@ -4,6 +4,10 @@
#include <memory> #include <memory>
#include <atomic> #include <atomic>
#define DECLARE_REF(x) class x; \
typedef RefPtr<x> P##x; \
typedef UniquePtr<x> UP##x;
namespace Seele namespace Seele
{ {
typedef uint64_t uint64; typedef uint64_t uint64;
@@ -16,7 +20,6 @@ namespace Seele
typedef int16_t int16; typedef int16_t int16;
typedef int8_t int8; typedef int8_t int8;
template<typename T> template<typename T>
class RefPtr class RefPtr
{ {
@@ -35,7 +38,7 @@ namespace Seele
if (this != &other) if (this != &other)
{ {
object->removeRef(); object->removeRef();
object = other->object; object = other.object;
object->addRef(); object->addRef();
} }
return *this; return *this;