From 4c2535931ea94575e0f47653f682b715ef776ac7 Mon Sep 17 00:00:00 2001 From: HOEGLER Stefan Date: Mon, 2 Mar 2020 19:07:49 +0100 Subject: [PATCH] Basic graphics structure --- CMakeLists.txt | 1 + src/Engine/Containers/Array.h | 6 +-- src/Engine/Graphics/CMakeLists.txt | 3 ++ src/Engine/Graphics/Graphics.h | 18 +++------ src/Engine/Graphics/GraphicsResources.h | 8 ++++ src/Engine/Graphics/RenderPath.cpp | 6 +++ src/Engine/Graphics/RenderPath.h | 19 ++++++++++ src/Engine/Graphics/View.cpp | 10 +++++ src/Engine/Graphics/View.h | 22 +++++++---- src/Engine/Graphics/Vulkan/CMakeLists.txt | 4 ++ src/Engine/Graphics/Vulkan/VulkanGraphics.cpp | 18 +++++++++ src/Engine/Graphics/Vulkan/VulkanGraphics.h | 14 +++++++ src/Engine/Graphics/Window.cpp | 10 +++-- src/Engine/Graphics/Window.h | 37 +++++++++---------- src/Engine/Graphics/WindowManager.h | 2 +- src/Engine/MinimalEngine.h | 7 +++- 16 files changed, 137 insertions(+), 48 deletions(-) create mode 100644 src/Engine/Graphics/RenderPath.cpp create mode 100644 src/Engine/Graphics/RenderPath.h create mode 100644 src/Engine/Graphics/View.cpp create mode 100644 src/Engine/Graphics/Vulkan/VulkanGraphics.cpp create mode 100644 src/Engine/Graphics/Vulkan/VulkanGraphics.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 6fe0aec..f13cc93 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -47,6 +47,7 @@ include_directories(src/Engine) add_definitions(${GLM_DEFINITIONS}) add_definitions(${Vulkan_DEFINITIONS}) add_definitions(${Boost_DEFINITIONS}) +add_compile_definitions(GLFW_WINDOWS) add_executable(SeeleEngine "") add_subdirectory(src/) target_link_libraries(SeeleEngine ${Boost_LIBRARIES}) diff --git a/src/Engine/Containers/Array.h b/src/Engine/Containers/Array.h index 8f95001..678d59e 100644 --- a/src/Engine/Containers/Array.h +++ b/src/Engine/Containers/Array.h @@ -16,7 +16,7 @@ namespace Seele : allocated(DEFAULT_ALLOC_SIZE) , arraySize(0) { - _data = new T[DEFAULT_ALLOC_SIZE]; + _data = (T*)malloc(DEFAULT_ALLOC_SIZE * sizeof(T)); refreshIterators(); } Array(size_t size, T value = T()) @@ -110,10 +110,10 @@ namespace Seele if (arraySize == allocated) { allocated += DEFAULT_ALLOC_SIZE; - T* tempArray = new T[allocated]; + void* tempArray = malloc(sizeof(T) * allocated); std::memcpy(tempArray, _data, arraySize * sizeof(T)); delete _data; - _data = tempArray; + _data = (T*)tempArray; } _data[arraySize++] = item; refreshIterators(); diff --git a/src/Engine/Graphics/CMakeLists.txt b/src/Engine/Graphics/CMakeLists.txt index 54a2362..3962a2b 100644 --- a/src/Engine/Graphics/CMakeLists.txt +++ b/src/Engine/Graphics/CMakeLists.txt @@ -2,7 +2,10 @@ target_sources(SeeleEngine PRIVATE Graphics.h Graphics.cpp + RenderPath.h + RenderPath.cpp View.h + View.cpp WindowManager.h WindowManager.cpp Window.h diff --git a/src/Engine/Graphics/Graphics.h b/src/Engine/Graphics/Graphics.h index ce42019..f758442 100644 --- a/src/Engine/Graphics/Graphics.h +++ b/src/Engine/Graphics/Graphics.h @@ -1,28 +1,22 @@ #pragma once #include "MinimalEngine.h" #include "GraphicsResources.h" +#include "Containers/Array.h" namespace Seele { class Window; class Graphics { public: - static Graphics& getInstance() - { - static Graphics instance; - - return instance; - } - void init(GraphicsInitializer initializer); - void beginFrame(); - void endFrame(); + virtual void init(GraphicsInitializer initializer) = 0; + virtual void beginFrame() = 0; + virtual void endFrame() = 0; + virtual void* createWindow(const WindowCreateInfo& createInfo) = 0; //Singleton private: Graphics(); - Graphics(Graphics const&) = delete; - void operator=(Graphics const&) = delete; ~Graphics(); - + friend class Window; }; } \ No newline at end of file diff --git a/src/Engine/Graphics/GraphicsResources.h b/src/Engine/Graphics/GraphicsResources.h index 1be0e41..5d018f5 100644 --- a/src/Engine/Graphics/GraphicsResources.h +++ b/src/Engine/Graphics/GraphicsResources.h @@ -6,4 +6,12 @@ namespace Seele { const char* windowLayoutFile; }; + struct WindowCreateInfo + { + int32 width; + int32 height; + const char* title; + bool bFullscreen; + }; + } \ No newline at end of file diff --git a/src/Engine/Graphics/RenderPath.cpp b/src/Engine/Graphics/RenderPath.cpp new file mode 100644 index 0000000..979078d --- /dev/null +++ b/src/Engine/Graphics/RenderPath.cpp @@ -0,0 +1,6 @@ +#include "RenderPath.h" + +Seele::RenderPath::RenderPath(Graphics* graphics) + : graphics(graphics) +{ +} diff --git a/src/Engine/Graphics/RenderPath.h b/src/Engine/Graphics/RenderPath.h new file mode 100644 index 0000000..a11e706 --- /dev/null +++ b/src/Engine/Graphics/RenderPath.h @@ -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); +} \ No newline at end of file diff --git a/src/Engine/Graphics/View.cpp b/src/Engine/Graphics/View.cpp new file mode 100644 index 0000000..80d79a5 --- /dev/null +++ b/src/Engine/Graphics/View.cpp @@ -0,0 +1,10 @@ +#include "View.h" + +Seele::View::View(PSection owner) + : owner(owner) +{ +} + +Seele::View::~View() +{ +} diff --git a/src/Engine/Graphics/View.h b/src/Engine/Graphics/View.h index f2e2888..7ca9a4c 100644 --- a/src/Engine/Graphics/View.h +++ b/src/Engine/Graphics/View.h @@ -1,10 +1,18 @@ #pragma once #include "Window.h" - -// A view is a part of the window, which can be anything from a viewport to an editor -class View +#include "RenderPath.h" +namespace Seele { -public: -private: - Window::Section* owner; -}; \ No newline at end of file + // A view is a part of the window, which can be anything from a viewport to an editor + class View + { + public: + View(PSection owner); + ~View(); + private: + PRenderPath renderer; + PSection owner; + }; + + DECLARE_REF(View) +} \ No newline at end of file diff --git a/src/Engine/Graphics/Vulkan/CMakeLists.txt b/src/Engine/Graphics/Vulkan/CMakeLists.txt index e69de29..3a82d43 100644 --- a/src/Engine/Graphics/Vulkan/CMakeLists.txt +++ b/src/Engine/Graphics/Vulkan/CMakeLists.txt @@ -0,0 +1,4 @@ +target_sources(SeeleEngine + PRIVATE + VulkanGraphics.h + VulkanGraphics.cpp) \ No newline at end of file diff --git a/src/Engine/Graphics/Vulkan/VulkanGraphics.cpp b/src/Engine/Graphics/Vulkan/VulkanGraphics.cpp new file mode 100644 index 0000000..cc15545 --- /dev/null +++ b/src/Engine/Graphics/Vulkan/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; +} diff --git a/src/Engine/Graphics/Vulkan/VulkanGraphics.h b/src/Engine/Graphics/Vulkan/VulkanGraphics.h new file mode 100644 index 0000000..d1c955c --- /dev/null +++ b/src/Engine/Graphics/Vulkan/VulkanGraphics.h @@ -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; + }; +} \ No newline at end of file diff --git a/src/Engine/Graphics/Window.cpp b/src/Engine/Graphics/Window.cpp index e1613e1..34dbad4 100644 --- a/src/Engine/Graphics/Window.cpp +++ b/src/Engine/Graphics/Window.cpp @@ -1,12 +1,14 @@ #include "Window.h" -#include "Graphics.h" -#include +#include "Vulkan/VulkanGraphics.h" Seele::Window::Window(const WindowCreateInfo& createInfo) + : width(createInfo.width) + , height(createInfo.height) + , windowHandle(nullptr) { + graphics = new VulkanGraphics(); } Seele::Window::~Window() { - -} \ No newline at end of file +} diff --git a/src/Engine/Graphics/Window.h b/src/Engine/Graphics/Window.h index 2e6bcbc..bab48c9 100644 --- a/src/Engine/Graphics/Window.h +++ b/src/Engine/Graphics/Window.h @@ -1,33 +1,30 @@ #pragma once #include "MinimalEngine.h" namespace Seele { - struct WindowCreateInfo + + // A window is divided into 5 sections, using a border layout + // +--------------TOP------------------+ + // | | + // L R + // E I + // F CENTER G + // T H + // | T + // +-------------BOTTOM----------------+ + // In every section, there can be any number + // of views, when there are multiple, they stack to tabs + struct Section { - int32 width; - int32 height; - const char* title; }; + DECLARE_REF(Section) + class Window { public: Window(const WindowCreateInfo& createInfo); ~Window(); private: - // A window is divided into 5 sections, using a border layout - // +--------------TOP------------------+ - // | | - // L R - // E I - // F CENTER G - // T H - // | T - // +-------------BOTTOM----------------+ - // In every section, there can be any number - // of views, when there are multiple, they stack to tabs - struct Section - { - - }; + void* windowHandle; Section top; Section bot; Section left; @@ -35,5 +32,7 @@ namespace Seele { Section center; uint32 width; uint32 height; + Graphics* graphics; }; + DECLARE_REF(Window) } \ No newline at end of file diff --git a/src/Engine/Graphics/WindowManager.h b/src/Engine/Graphics/WindowManager.h index 63ce4a3..2c88026 100644 --- a/src/Engine/Graphics/WindowManager.h +++ b/src/Engine/Graphics/WindowManager.h @@ -11,6 +11,6 @@ namespace Seele WindowManager(GraphicsInitializer initializer); ~WindowManager(); private: - Array> windows; + Array windows; }; } \ No newline at end of file diff --git a/src/Engine/MinimalEngine.h b/src/Engine/MinimalEngine.h index 360efcc..40d2983 100644 --- a/src/Engine/MinimalEngine.h +++ b/src/Engine/MinimalEngine.h @@ -4,6 +4,10 @@ #include #include +#define DECLARE_REF(x) class x; \ + typedef RefPtr P##x; \ + typedef UniquePtr UP##x; + namespace Seele { typedef uint64_t uint64; @@ -16,7 +20,6 @@ namespace Seele typedef int16_t int16; typedef int8_t int8; - template class RefPtr { @@ -35,7 +38,7 @@ namespace Seele if (this != &other) { object->removeRef(); - object = other->object; + object = other.object; object->addRef(); } return *this;