Added scene renderer

This commit is contained in:
HOEGLER Stefan
2020-03-05 11:43:38 +01:00
parent 4c2535931e
commit 328edf5196
23 changed files with 334 additions and 113 deletions
+2
View File
@@ -17,6 +17,7 @@ namespace Seele
, arraySize(0)
{
_data = (T*)malloc(DEFAULT_ALLOC_SIZE * sizeof(T));
memset(_data, 0, sizeof(T) * DEFAULT_ALLOC_SIZE);
refreshIterators();
}
Array(size_t size, T value = T())
@@ -112,6 +113,7 @@ namespace Seele
allocated += DEFAULT_ALLOC_SIZE;
void* tempArray = malloc(sizeof(T) * allocated);
std::memcpy(tempArray, _data, arraySize * sizeof(T));
memset(tempArray, 0, sizeof(T) * allocated);
delete _data;
_data = (T*)tempArray;
}
+6
View File
@@ -2,10 +2,16 @@ target_sources(SeeleEngine
PRIVATE
Graphics.h
Graphics.cpp
RenderCore.h
RenderCore.cpp
RenderPath.h
RenderPath.cpp
SceneRenderPath.h
SceneRenderPath.cpp
View.h
View.cpp
SceneView.h
SceneView.cpp
WindowManager.h
WindowManager.cpp
Window.h
+3 -5
View File
@@ -9,12 +9,10 @@ namespace Seele {
{
public:
virtual void init(GraphicsInitializer initializer) = 0;
virtual void beginFrame() = 0;
virtual void endFrame() = 0;
virtual void beginFrame(void* windowHandle) = 0;
virtual void endFrame(void* windowHandle) = 0;
virtual void* createWindow(const WindowCreateInfo& createInfo) = 0;
//Singleton
private:
protected:
Graphics();
~Graphics();
friend class Window;
+1 -1
View File
@@ -1,5 +1,5 @@
#pragma once
#include "MinimalEngine.h"
namespace Seele
{
struct GraphicsInitializer
+33
View File
@@ -0,0 +1,33 @@
#include "RenderCore.h"
Seele::RenderCore::RenderCore()
{
windowManager = new WindowManager();
}
Seele::RenderCore::~RenderCore()
{
}
void Seele::RenderCore::init()
{
WindowCreateInfo mainWindowInfo;
mainWindowInfo.title = "SeeleEngine";
mainWindowInfo.width = 1280;
mainWindowInfo.height = 720;
mainWindowInfo.bFullscreen = false;
windowManager->addWindow(mainWindowInfo);
}
void Seele::RenderCore::renderLoop()
{
while (true)
{
windowManager->beginFrame();
windowManager->endFrame();
}
}
void Seele::RenderCore::shutdown()
{
}
+16
View File
@@ -0,0 +1,16 @@
#pragma once
#include "WindowManager.h"
namespace Seele
{
class RenderCore
{
public:
RenderCore();
~RenderCore();
void init();
void renderLoop();
void shutdown();
private:
PWindowManager windowManager;
};
}
+4
View File
@@ -4,3 +4,7 @@ Seele::RenderPath::RenderPath(Graphics* graphics)
: graphics(graphics)
{
}
Seele::RenderPath::~RenderPath()
{
}
+2
View File
@@ -8,12 +8,14 @@ namespace Seele
public:
RenderPath(Graphics* graphics);
virtual ~RenderPath();
virtual void applyArea(Rect area) = 0;
virtual void init() = 0;
virtual void beginFrame() = 0;
virtual void render() = 0;
virtual void endFrame() = 0;
protected:
Graphics* graphics;
Rect area;
};
DECLARE_REF(RenderPath);
}
+17
View File
@@ -0,0 +1,17 @@
#pragma once
#include "RenderPath.h"
namespace Seele
{
class SceneRenderPath : public RenderPath
{
public:
SceneRenderPath();
virtual ~SceneRenderPath();
virtual void applyArea(Rect area) override;
virtual void init() override;
virtual void beginFrame() override;
virtual void render() override;
virtual void endFrame() override;
};
}
+15
View File
@@ -0,0 +1,15 @@
#include "SceneView.h"
#include "SceneRenderPath.h"
Seele::SceneView::SceneView()
{
}
Seele::SceneView::~SceneView()
{
}
void Seele::SceneView::initRenderer()
{
renderer = new SceneRenderPath();
}
+12
View File
@@ -0,0 +1,12 @@
#pragma once
#include "View.h"
namespace Seele
{
class SceneView : public View
{
public:
SceneView();
~SceneView();
virtual void initRenderer() override;
};
}
+16 -2
View File
@@ -1,10 +1,24 @@
#include "View.h"
Seele::View::View(PSection owner)
: owner(owner)
Seele::View::View()
{
}
Seele::View::~View()
{
}
void Seele::View::beginFrame()
{
renderer->beginFrame();
}
void Seele::View::endFrame()
{
renderer->endFrame();
}
void Seele::View::applyArea(Rect area)
{
renderer->applyArea(area);
}
+7 -5
View File
@@ -1,5 +1,4 @@
#pragma once
#include "Window.h"
#include "RenderPath.h"
namespace Seele
{
@@ -7,11 +6,14 @@ namespace Seele
class View
{
public:
View(PSection owner);
~View();
private:
View();
virtual ~View();
virtual void initRenderer() = 0;
void beginFrame();
void endFrame();
void applyArea(Rect area);
protected:
PRenderPath renderer;
PSection owner;
};
DECLARE_REF(View)
+20 -3
View File
@@ -1,18 +1,35 @@
#include "VulkanGraphics.h"
#include <GLFW/glfw3.h>
void Seele::VulkanGraphics::init(GraphicsInitializer initializer)
{
}
void Seele::VulkanGraphics::beginFrame()
void Seele::VulkanGraphics::beginFrame(void* windowHandle)
{
GLFWwindow* window = static_cast<GLFWwindow*>(windowHandle);
glfwPollEvents();
}
void Seele::VulkanGraphics::endFrame()
void Seele::VulkanGraphics::endFrame(void* windowHandle)
{
GLFWwindow* window = static_cast<GLFWwindow*>(windowHandle);
}
void* Seele::VulkanGraphics::createWindow(const WindowCreateInfo& createInfo)
{
return nullptr;
GLFWwindow* window = glfwCreateWindow(createInfo.width, createInfo.height, createInfo.title, createInfo.bFullscreen ? glfwGetPrimaryMonitor() : nullptr, nullptr);
return window;
}
Seele::VulkanGraphics::VulkanGraphics()
{
glfwInit();
glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
}
Seele::VulkanGraphics::~VulkanGraphics()
{
glfwTerminate();
}
+6 -2
View File
@@ -7,8 +7,12 @@ namespace Seele
public:
// Inherited via Graphics
virtual void init(GraphicsInitializer initializer) override;
virtual void beginFrame() override;
virtual void endFrame() override;
virtual void beginFrame(void* windowHandle) override;
virtual void endFrame(void* windowHandle) override;
virtual void* createWindow(const WindowCreateInfo& createInfo) override;
protected:
VulkanGraphics();
virtual ~VulkanGraphics();
friend class Window;
};
}
+16 -1
View File
@@ -1,14 +1,29 @@
#include "Window.h"
#include "Vulkan/VulkanGraphics.h"
#include "SceneView.h"
Seele::Window::Window(const WindowCreateInfo& createInfo)
: width(createInfo.width)
, height(createInfo.height)
, windowHandle(nullptr)
{
center = new Section();
center->resizeArea(Rect(1, 1, 0, 0));
center->addView(new SceneView());
graphics = new VulkanGraphics();
windowHandle = graphics->createWindow(createInfo);
}
Seele::Window::~Window()
{
}
void Seele::Window::beginFrame()
{
graphics->beginFrame(windowHandle);
center->beginFrame();
}
void Seele::Window::endFrame()
{
graphics->endFrame(windowHandle);
}
+38 -8
View File
@@ -1,5 +1,6 @@
#pragma once
#include "MinimalEngine.h"
#include "GraphicsResources.h"
#include "View.h"
namespace Seele {
// A window is divided into 5 sections, using a border layout
@@ -13,23 +14,52 @@ namespace Seele {
// +-------------BOTTOM----------------+
// In every section, there can be any number
// of views, when there are multiple, they stack to tabs
struct Section
class Section
{
public:
Section()
{}
void resizeArea(Rect area)
{
this->area = area;
}
void beginFrame()
{
views[0]->beginFrame();
}
void endFrame()
{
views[0]->endFrame();
}
void addView(PView view)
{
view->applyArea(area);
views.add(view);
}
void clearViews(PView view)
{
views.clear();
}
void removeView(PView view)
{
views.remove(views.find(view));
}
private:
Rect area;
Array<PView> views;
};
DECLARE_REF(Section)
class Graphics;
class Window
{
public:
Window(const WindowCreateInfo& createInfo);
~Window();
void beginFrame();
void endFrame();
private:
void* windowHandle;
Section top;
Section bot;
Section left;
Section right;
Section center;
PSection center;
uint32 width;
uint32 height;
Graphics* graphics;
+23 -8
View File
@@ -1,16 +1,31 @@
#include "WindowManager.h"
Seele::WindowManager::WindowManager(GraphicsInitializer initializer)
Seele::WindowManager::WindowManager()
{
//TODO Parse layout file
WindowCreateInfo mainWindowInfo;
mainWindowInfo.title = "SeeleEngine";
mainWindowInfo.width = 1280;
mainWindowInfo.height = 720;
Window* mainWindow = new Window(mainWindowInfo);
windows.add(mainWindow);
}
Seele::WindowManager::~WindowManager()
{
}
void Seele::WindowManager::addWindow(const WindowCreateInfo& createInfo)
{
PWindow window = new Window(createInfo);
windows.add(window);
}
void Seele::WindowManager::beginFrame()
{
for (auto window : windows)
{
window->beginFrame();
}
}
void Seele::WindowManager::endFrame()
{
for (auto window : windows)
{
window->endFrame();
}
}
+5 -1
View File
@@ -8,9 +8,13 @@ namespace Seele
class WindowManager
{
public:
WindowManager(GraphicsInitializer initializer);
WindowManager();
~WindowManager();
void addWindow(const WindowCreateInfo& createInfo);
void beginFrame();
void endFrame();
private:
Array<PWindow> windows;
};
DECLARE_REF(WindowManager);
}
+32
View File
@@ -0,0 +1,32 @@
#include "Vector.h"
#include "Matrix.h"
namespace Seele
{
struct Rect
{
Rect()
: size(0, 0)
, offset(0, 0)
{}
Rect(float sizeX, float sizeY, float offsetX, float offsetY)
: size(sizeX, sizeY)
, offset(offsetX, offsetY)
{}
Rect(Vector2 size, Vector2 offset)
: size(size)
, offset(offset)
{}
bool isEmpty() const
{
return size.x == 0 || size.y == 0;
}
Vector2 size;
Vector2 offset;
};
struct Rect3D
{
Vector3 size;
Vector3 offset;
};
}
+52 -5
View File
@@ -1,12 +1,14 @@
#pragma once
#include <stdint.h>
#include <array>
#include <assert.h>
#include <memory>
#include <atomic>
#include "Math/Math.h"
#define DECLARE_REF(x) class x; \
typedef RefPtr<x> P##x; \
typedef UniquePtr<x> UP##x;
typedef UniquePtr<x> UP##x; \
typedef WeakPtr<x> W##x;
namespace Seele
{
@@ -24,6 +26,10 @@ namespace Seele
class RefPtr
{
public:
RefPtr()
{
object = nullptr;
}
RefPtr(T* ptr)
{
object = new RefObject(ptr);
@@ -37,7 +43,10 @@ namespace Seele
{
if (this != &other)
{
object->removeRef();
if (object != nullptr)
{
object->removeRef();
}
object = other.object;
object->addRef();
}
@@ -47,11 +56,17 @@ namespace Seele
{
object->removeRef();
}
bool operator==(const RefPtr& other) const
{
return object == other.object;
}
T* operator->()
{
assert(object != nullptr);
return object->getHandle();
}
private:
class RefObject
{
public:
@@ -68,7 +83,10 @@ namespace Seele
}
~RefObject()
{}
bool operator==(const RefObject& other) const
{
return handle == other.handle && refCount == other.refCount;
}
void addRef()
{
refCount++;
@@ -92,8 +110,37 @@ namespace Seele
std::atomic_uint64_t refCount;
};
RefObject* object;
template<typename T>
friend class WeakPtr;
};
template<typename T>
class WeakPtr
{
public:
WeakPtr()
{}
WeakPtr(RefPtr<T>& sharedPtr)
: pointer(sharedPtr.object)
{}
WeakPtr& operator=(WeakPtr<T>& weakPtr)
{
pointer = weakPtr.pointer;
return *this;
}
WeakPtr& operator=(RefPtr<T>& sharedPtr)
{
pointer = sharedPtr;
return *this;
}
RefPtr<T>& lock()
{
RefPtr<T> temp;
temp.object = pointer;
return temp;
}
private:
RefPtr::RefObject* pointer;
};
template<typename T>
class UniquePtr
{
+8 -72
View File
@@ -1,74 +1,10 @@
#include <fstream>
// include headers that implement a archive in simple text format
#include <boost/archive/text_oarchive.hpp>
#include <boost/archive/text_iarchive.hpp>
#include <iostream>
#include <vulkan/vulkan.h>
#include <glm/vec4.hpp>
#include <GLFW/glfw3.h>
#include "Graphics/Graphics.h"
/////////////////////////////////////////////////////////////
// gps coordinate
//
// illustrates serialization for a simple type
//
class gps_position
#include "Graphics/RenderCore.h"
using namespace Seele;
int main()
{
private:
friend class boost::serialization::access;
// When the class Archive corresponds to an output archive, the
// & operator is defined similar to <<. Likewise, when the class Archive
// is a type of input archive the & operator is defined similar to >>.
template<class Archive>
void serialize(Archive& ar, const unsigned int version)
{
ar& degrees;
ar& minutes;
ar& seconds;
}
int degrees;
int minutes;
float seconds;
public:
gps_position() {};
gps_position(int d, int m, float s) :
degrees(d), minutes(m), seconds(s)
{}
};
int main() {
// create and open a character archive for output
std::ofstream ofs("filename");
// create class instance
const gps_position g(35, 59, 24.567f);
// save _data to archive
{
boost::archive::text_oarchive oa(ofs);
// write class instance to archive
oa << g;
// archive and stream closed when destructors are called
}
// ... some time later restore the class instance to its orginal state
gps_position newg;
{
// create and open an archive for input
std::ifstream ifs("filename");
boost::archive::text_iarchive ia(ifs);
// read class state from archive
ia >> newg;
// archive and stream closed when destructors are called
}
std::cout << "Hello World! " << std::endl;
VkInstance instance;
glm::vec4 vector(0, 1, 0, 1);
Seele::Graphics& graphics = Seele::Graphics::getInstance();
std::cout << vector.y << std::endl;
std::cout << glfwInit() << std::endl;
return 0;
RenderCore core;
core.init();
core.renderLoop();
core.shutdown();
return 0;
}