Added scene renderer
This commit is contained in:
@@ -17,6 +17,7 @@ namespace Seele
|
|||||||
, arraySize(0)
|
, arraySize(0)
|
||||||
{
|
{
|
||||||
_data = (T*)malloc(DEFAULT_ALLOC_SIZE * sizeof(T));
|
_data = (T*)malloc(DEFAULT_ALLOC_SIZE * sizeof(T));
|
||||||
|
memset(_data, 0, sizeof(T) * DEFAULT_ALLOC_SIZE);
|
||||||
refreshIterators();
|
refreshIterators();
|
||||||
}
|
}
|
||||||
Array(size_t size, T value = T())
|
Array(size_t size, T value = T())
|
||||||
@@ -112,6 +113,7 @@ namespace Seele
|
|||||||
allocated += DEFAULT_ALLOC_SIZE;
|
allocated += DEFAULT_ALLOC_SIZE;
|
||||||
void* tempArray = malloc(sizeof(T) * allocated);
|
void* tempArray = malloc(sizeof(T) * allocated);
|
||||||
std::memcpy(tempArray, _data, arraySize * sizeof(T));
|
std::memcpy(tempArray, _data, arraySize * sizeof(T));
|
||||||
|
memset(tempArray, 0, sizeof(T) * allocated);
|
||||||
delete _data;
|
delete _data;
|
||||||
_data = (T*)tempArray;
|
_data = (T*)tempArray;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,10 +2,16 @@ target_sources(SeeleEngine
|
|||||||
PRIVATE
|
PRIVATE
|
||||||
Graphics.h
|
Graphics.h
|
||||||
Graphics.cpp
|
Graphics.cpp
|
||||||
|
RenderCore.h
|
||||||
|
RenderCore.cpp
|
||||||
RenderPath.h
|
RenderPath.h
|
||||||
RenderPath.cpp
|
RenderPath.cpp
|
||||||
|
SceneRenderPath.h
|
||||||
|
SceneRenderPath.cpp
|
||||||
View.h
|
View.h
|
||||||
View.cpp
|
View.cpp
|
||||||
|
SceneView.h
|
||||||
|
SceneView.cpp
|
||||||
WindowManager.h
|
WindowManager.h
|
||||||
WindowManager.cpp
|
WindowManager.cpp
|
||||||
Window.h
|
Window.h
|
||||||
|
|||||||
@@ -9,12 +9,10 @@ namespace Seele {
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
virtual void init(GraphicsInitializer initializer) = 0;
|
virtual void init(GraphicsInitializer initializer) = 0;
|
||||||
virtual void beginFrame() = 0;
|
virtual void beginFrame(void* windowHandle) = 0;
|
||||||
virtual void endFrame() = 0;
|
virtual void endFrame(void* windowHandle) = 0;
|
||||||
virtual void* createWindow(const WindowCreateInfo& createInfo) = 0;
|
virtual void* createWindow(const WindowCreateInfo& createInfo) = 0;
|
||||||
|
protected:
|
||||||
//Singleton
|
|
||||||
private:
|
|
||||||
Graphics();
|
Graphics();
|
||||||
~Graphics();
|
~Graphics();
|
||||||
friend class Window;
|
friend class Window;
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
#include "MinimalEngine.h"
|
||||||
namespace Seele
|
namespace Seele
|
||||||
{
|
{
|
||||||
struct GraphicsInitializer
|
struct GraphicsInitializer
|
||||||
|
|||||||
@@ -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()
|
||||||
|
{
|
||||||
|
}
|
||||||
@@ -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,3 +4,7 @@ Seele::RenderPath::RenderPath(Graphics* graphics)
|
|||||||
: graphics(graphics)
|
: graphics(graphics)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Seele::RenderPath::~RenderPath()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|||||||
@@ -8,12 +8,14 @@ namespace Seele
|
|||||||
public:
|
public:
|
||||||
RenderPath(Graphics* graphics);
|
RenderPath(Graphics* graphics);
|
||||||
virtual ~RenderPath();
|
virtual ~RenderPath();
|
||||||
|
virtual void applyArea(Rect area) = 0;
|
||||||
virtual void init() = 0;
|
virtual void init() = 0;
|
||||||
virtual void beginFrame() = 0;
|
virtual void beginFrame() = 0;
|
||||||
virtual void render() = 0;
|
virtual void render() = 0;
|
||||||
virtual void endFrame() = 0;
|
virtual void endFrame() = 0;
|
||||||
protected:
|
protected:
|
||||||
Graphics* graphics;
|
Graphics* graphics;
|
||||||
|
Rect area;
|
||||||
};
|
};
|
||||||
DECLARE_REF(RenderPath);
|
DECLARE_REF(RenderPath);
|
||||||
}
|
}
|
||||||
@@ -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;
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
#include "SceneView.h"
|
||||||
|
#include "SceneRenderPath.h"
|
||||||
|
|
||||||
|
Seele::SceneView::SceneView()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
Seele::SceneView::~SceneView()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void Seele::SceneView::initRenderer()
|
||||||
|
{
|
||||||
|
renderer = new SceneRenderPath();
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
#pragma once
|
||||||
|
#include "View.h"
|
||||||
|
namespace Seele
|
||||||
|
{
|
||||||
|
class SceneView : public View
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
SceneView();
|
||||||
|
~SceneView();
|
||||||
|
virtual void initRenderer() override;
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -1,10 +1,24 @@
|
|||||||
#include "View.h"
|
#include "View.h"
|
||||||
|
|
||||||
Seele::View::View(PSection owner)
|
Seele::View::View()
|
||||||
: 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);
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "Window.h"
|
|
||||||
#include "RenderPath.h"
|
#include "RenderPath.h"
|
||||||
namespace Seele
|
namespace Seele
|
||||||
{
|
{
|
||||||
@@ -7,11 +6,14 @@ namespace Seele
|
|||||||
class View
|
class View
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
View(PSection owner);
|
View();
|
||||||
~View();
|
virtual ~View();
|
||||||
private:
|
virtual void initRenderer() = 0;
|
||||||
|
void beginFrame();
|
||||||
|
void endFrame();
|
||||||
|
void applyArea(Rect area);
|
||||||
|
protected:
|
||||||
PRenderPath renderer;
|
PRenderPath renderer;
|
||||||
PSection owner;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
DECLARE_REF(View)
|
DECLARE_REF(View)
|
||||||
|
|||||||
@@ -1,18 +1,35 @@
|
|||||||
#include "VulkanGraphics.h"
|
#include "VulkanGraphics.h"
|
||||||
|
#include <GLFW/glfw3.h>
|
||||||
|
|
||||||
void Seele::VulkanGraphics::init(GraphicsInitializer initializer)
|
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)
|
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();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,8 +7,12 @@ namespace Seele
|
|||||||
public:
|
public:
|
||||||
// Inherited via Graphics
|
// Inherited via Graphics
|
||||||
virtual void init(GraphicsInitializer initializer) override;
|
virtual void init(GraphicsInitializer initializer) override;
|
||||||
virtual void beginFrame() override;
|
virtual void beginFrame(void* windowHandle) override;
|
||||||
virtual void endFrame() override;
|
virtual void endFrame(void* windowHandle) override;
|
||||||
virtual void* createWindow(const WindowCreateInfo& createInfo) override;
|
virtual void* createWindow(const WindowCreateInfo& createInfo) override;
|
||||||
|
protected:
|
||||||
|
VulkanGraphics();
|
||||||
|
virtual ~VulkanGraphics();
|
||||||
|
friend class Window;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -1,14 +1,29 @@
|
|||||||
#include "Window.h"
|
#include "Window.h"
|
||||||
#include "Vulkan/VulkanGraphics.h"
|
#include "Vulkan/VulkanGraphics.h"
|
||||||
|
#include "SceneView.h"
|
||||||
|
|
||||||
Seele::Window::Window(const WindowCreateInfo& createInfo)
|
Seele::Window::Window(const WindowCreateInfo& createInfo)
|
||||||
: width(createInfo.width)
|
: width(createInfo.width)
|
||||||
, height(createInfo.height)
|
, height(createInfo.height)
|
||||||
, windowHandle(nullptr)
|
|
||||||
{
|
{
|
||||||
|
center = new Section();
|
||||||
|
center->resizeArea(Rect(1, 1, 0, 0));
|
||||||
|
center->addView(new SceneView());
|
||||||
graphics = new VulkanGraphics();
|
graphics = new VulkanGraphics();
|
||||||
|
windowHandle = graphics->createWindow(createInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
Seele::Window::~Window()
|
Seele::Window::~Window()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Seele::Window::beginFrame()
|
||||||
|
{
|
||||||
|
graphics->beginFrame(windowHandle);
|
||||||
|
center->beginFrame();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Seele::Window::endFrame()
|
||||||
|
{
|
||||||
|
graphics->endFrame(windowHandle);
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "MinimalEngine.h"
|
#include "GraphicsResources.h"
|
||||||
|
#include "View.h"
|
||||||
namespace Seele {
|
namespace Seele {
|
||||||
|
|
||||||
// A window is divided into 5 sections, using a border layout
|
// A window is divided into 5 sections, using a border layout
|
||||||
@@ -13,23 +14,52 @@ namespace Seele {
|
|||||||
// +-------------BOTTOM----------------+
|
// +-------------BOTTOM----------------+
|
||||||
// In every section, there can be any number
|
// In every section, there can be any number
|
||||||
// of views, when there are multiple, they stack to tabs
|
// 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)
|
DECLARE_REF(Section)
|
||||||
|
class Graphics;
|
||||||
class Window
|
class Window
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Window(const WindowCreateInfo& createInfo);
|
Window(const WindowCreateInfo& createInfo);
|
||||||
~Window();
|
~Window();
|
||||||
|
void beginFrame();
|
||||||
|
void endFrame();
|
||||||
private:
|
private:
|
||||||
void* windowHandle;
|
void* windowHandle;
|
||||||
Section top;
|
PSection center;
|
||||||
Section bot;
|
|
||||||
Section left;
|
|
||||||
Section right;
|
|
||||||
Section center;
|
|
||||||
uint32 width;
|
uint32 width;
|
||||||
uint32 height;
|
uint32 height;
|
||||||
Graphics* graphics;
|
Graphics* graphics;
|
||||||
|
|||||||
@@ -1,16 +1,31 @@
|
|||||||
#include "WindowManager.h"
|
#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()
|
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -8,9 +8,13 @@ namespace Seele
|
|||||||
class WindowManager
|
class WindowManager
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
WindowManager(GraphicsInitializer initializer);
|
WindowManager();
|
||||||
~WindowManager();
|
~WindowManager();
|
||||||
|
void addWindow(const WindowCreateInfo& createInfo);
|
||||||
|
void beginFrame();
|
||||||
|
void endFrame();
|
||||||
private:
|
private:
|
||||||
Array<PWindow> windows;
|
Array<PWindow> windows;
|
||||||
};
|
};
|
||||||
|
DECLARE_REF(WindowManager);
|
||||||
}
|
}
|
||||||
@@ -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;
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -1,12 +1,14 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <array>
|
#include <assert.h>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <atomic>
|
#include <atomic>
|
||||||
|
#include "Math/Math.h"
|
||||||
|
|
||||||
#define DECLARE_REF(x) class x; \
|
#define DECLARE_REF(x) class x; \
|
||||||
typedef RefPtr<x> P##x; \
|
typedef RefPtr<x> P##x; \
|
||||||
typedef UniquePtr<x> UP##x;
|
typedef UniquePtr<x> UP##x; \
|
||||||
|
typedef WeakPtr<x> W##x;
|
||||||
|
|
||||||
namespace Seele
|
namespace Seele
|
||||||
{
|
{
|
||||||
@@ -24,6 +26,10 @@ namespace Seele
|
|||||||
class RefPtr
|
class RefPtr
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
RefPtr()
|
||||||
|
{
|
||||||
|
object = nullptr;
|
||||||
|
}
|
||||||
RefPtr(T* ptr)
|
RefPtr(T* ptr)
|
||||||
{
|
{
|
||||||
object = new RefObject(ptr);
|
object = new RefObject(ptr);
|
||||||
@@ -36,8 +42,11 @@ namespace Seele
|
|||||||
RefPtr& operator=(const RefPtr& other)
|
RefPtr& operator=(const RefPtr& other)
|
||||||
{
|
{
|
||||||
if (this != &other)
|
if (this != &other)
|
||||||
|
{
|
||||||
|
if (object != nullptr)
|
||||||
{
|
{
|
||||||
object->removeRef();
|
object->removeRef();
|
||||||
|
}
|
||||||
object = other.object;
|
object = other.object;
|
||||||
object->addRef();
|
object->addRef();
|
||||||
}
|
}
|
||||||
@@ -47,11 +56,17 @@ namespace Seele
|
|||||||
{
|
{
|
||||||
object->removeRef();
|
object->removeRef();
|
||||||
}
|
}
|
||||||
|
bool operator==(const RefPtr& other) const
|
||||||
|
{
|
||||||
|
return object == other.object;
|
||||||
|
}
|
||||||
T* operator->()
|
T* operator->()
|
||||||
{
|
{
|
||||||
|
assert(object != nullptr);
|
||||||
return object->getHandle();
|
return object->getHandle();
|
||||||
}
|
}
|
||||||
private:
|
private:
|
||||||
|
|
||||||
class RefObject
|
class RefObject
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@@ -68,7 +83,10 @@ namespace Seele
|
|||||||
}
|
}
|
||||||
~RefObject()
|
~RefObject()
|
||||||
{}
|
{}
|
||||||
|
bool operator==(const RefObject& other) const
|
||||||
|
{
|
||||||
|
return handle == other.handle && refCount == other.refCount;
|
||||||
|
}
|
||||||
void addRef()
|
void addRef()
|
||||||
{
|
{
|
||||||
refCount++;
|
refCount++;
|
||||||
@@ -92,8 +110,37 @@ namespace Seele
|
|||||||
std::atomic_uint64_t refCount;
|
std::atomic_uint64_t refCount;
|
||||||
};
|
};
|
||||||
RefObject* object;
|
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>
|
template<typename T>
|
||||||
class UniquePtr
|
class UniquePtr
|
||||||
{
|
{
|
||||||
|
|||||||
+7
-71
@@ -1,74 +1,10 @@
|
|||||||
#include <fstream>
|
#include "Graphics/RenderCore.h"
|
||||||
|
using namespace Seele;
|
||||||
// include headers that implement a archive in simple text format
|
int main()
|
||||||
#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
|
|
||||||
{
|
{
|
||||||
private:
|
RenderCore core;
|
||||||
friend class boost::serialization::access;
|
core.init();
|
||||||
// When the class Archive corresponds to an output archive, the
|
core.renderLoop();
|
||||||
// & operator is defined similar to <<. Likewise, when the class Archive
|
core.shutdown();
|
||||||
// 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;
|
return 0;
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user