Ref, Scope

- Changed all std::unique_ptr/shared_ptr stuff to use Ref/Scope
- Fixed the Logger.h include in Base.h problem
This commit is contained in:
Light 2021-07-26 11:43:37 +04:30
parent 0360d094d2
commit 55869f6106
65 changed files with 261 additions and 234 deletions

View file

@ -1,14 +1,43 @@
#pragma once #pragma once
#ifndef LOGGER_H
#include "Debug/Logger.h"
#endif
#include "Debug/Exceptions.h"
#include "Utility/Stringifier.h"
#include <memory> #include <memory>
namespace Light {
// Ref (Ref)
template<typename T>
using Ref = std::shared_ptr<T>;
template<typename T, typename... Args>
constexpr Ref<T> CreateRef(Args&&... args)
{
return std::make_shared<T>(std::forward<Args>(args)...);
}
template<typename T>
constexpr Ref<T> MakeRef(T* rawPointer)
{
return std::shared_ptr<T>(T);
}
// Scope (std::unique_ptr)
template<typename T>
using Scope = std::unique_ptr<T>;
template<typename T, typename... Args>
constexpr std::unique_ptr<T> CreateScope(Args&&... args)
{
return std::make_unique<T>(std::forward<Args>(args)...);
}
template<typename T>
constexpr std::unique_ptr<T> MakeScope(T* rawPointer)
{
return std::unique_ptr<T>(rawPointer);
}
}
// platform // platform
#define LT_WIN(x) // windows #define LT_WIN(x) // windows
#define LT_LIN(x) // linux #define LT_LIN(x) // linux
@ -44,42 +73,6 @@
#define LT_CLIENT_ASSERT(x, ...) { if(!(x)) { LT_CLIENT_CRITICAL(__VA_ARGS__); LT_BREAK(); throw ::Light::FailedClientAssertion(__FILE__, __LINE__); } } #define LT_CLIENT_ASSERT(x, ...) { if(!(x)) { LT_CLIENT_CRITICAL(__VA_ARGS__); LT_BREAK(); throw ::Light::FailedClientAssertion(__FILE__, __LINE__); } }
#endif #endif
namespace Light {
// Ref (std::shared_ptr)
template<typename T>
using Ref = std::shared_ptr<T>;
template<typename T, typename... Args>
constexpr std::shared_ptr<T> CreateRef(Args... args)
{
return std::make_shared<T>(std::forward<Args>(args)...);
}
template<typename T>
constexpr std::shared_ptr<T> MakeRef(T* rawPointer)
{
return std::shared_ptr<T>(T);
}
// Scope (std::unique_ptr)
template<typename T>
using Scope = std::unique_ptr<T>;
template<typename T, typename... Args>
constexpr std::unique_ptr<T> CreateScope(Args... args)
{
return std::make_unique<T>(std::forward<Args>(args)...);
}
template<typename T>
constexpr std::unique_ptr<T> MakeScope(T* rawPointer)
{
return std::unique_ptr<T>(rawPointer);
}
}
///*** [ PORTABLES ] ***/// ///*** [ PORTABLES ] ***///
//** PORTABLE_DEBUG_BREAK **// //** PORTABLE_DEBUG_BREAK **//
// copied from: https://github.com/nemequ/portable-snippets/tree/master/debug-trap // copied from: https://github.com/nemequ/portable-snippets/tree/master/debug-trap
@ -157,3 +150,11 @@ namespace Light {
//** PORTABLE_DEBUG_BREAK **// //** PORTABLE_DEBUG_BREAK **//
///*** [ PORTABLES ] ***/// ///*** [ PORTABLES ] ***///
#ifndef LT_LOGGER_H
#include "Debug/Logger.h"
#define LT_LOGGER_H
#endif
#include "Debug/Exceptions.h"
#include "Utility/Stringifier.h"

View file

@ -22,10 +22,12 @@ namespace Light {
Application::Application() Application::Application()
{ {
Logger::Initialize(); Logger::Initialize();
m_Instrumentor = std::unique_ptr<Instrumentor>(Instrumentor::Create()); m_Instrumentor = Instrumentor::Create();
m_LayerStack = LayerStack::Create();
m_Input = Input::Create();
m_Instrumentor->BeginSession("Logs/ProfileResults_Startup.json"); m_Instrumentor->BeginSession("Logs/ProfileResults_Startup.json");
m_Window = std::unique_ptr<Light::Window>(Light::Window::Create(std::bind(&Light::Application::OnEvent, this, std::placeholders::_1))); m_Window = Window::Create(std::bind(&Application::OnEvent, this, std::placeholders::_1));
} }
Application::~Application() Application::~Application()
@ -59,7 +61,7 @@ namespace Light {
// update layers // update layers
LT_PROFILE_SCOPE("GameLoop::Update"); LT_PROFILE_SCOPE("GameLoop::Update");
for (auto it = m_LayerStack.begin(); it != m_LayerStack.end(); it++) for (auto it = m_LayerStack->begin(); it != m_LayerStack->end(); it++)
(*it)->OnUpdate(deltaTimer.GetDeltaTime()); (*it)->OnUpdate(deltaTimer.GetDeltaTime());
} }
@ -68,7 +70,7 @@ namespace Light {
LT_PROFILE_SCOPE("GameLoop::Render"); LT_PROFILE_SCOPE("GameLoop::Render");
m_Window->GetGfxContext()->GetRenderer()->BeginFrame(); m_Window->GetGfxContext()->GetRenderer()->BeginFrame();
for (auto it = m_LayerStack.begin(); it != m_LayerStack.end(); it++) for (auto it = m_LayerStack->begin(); it != m_LayerStack->end(); it++)
(*it)->OnRender(); (*it)->OnRender();
m_Window->GetGfxContext()->GetRenderer()->EndFrame(); m_Window->GetGfxContext()->GetRenderer()->EndFrame();
@ -79,7 +81,7 @@ namespace Light {
LT_PROFILE_SCOPE("GameLoop::UserInterface"); LT_PROFILE_SCOPE("GameLoop::UserInterface");
m_Window->GetGfxContext()->GetUserInterface()->Begin(); m_Window->GetGfxContext()->GetUserInterface()->Begin();
for (auto it = m_LayerStack.begin(); it != m_LayerStack.end(); it++) for (auto it = m_LayerStack->begin(); it != m_LayerStack->end(); it++)
(*it)->OnUserInterfaceUpdate(); (*it)->OnUserInterfaceUpdate();
m_Window->GetGfxContext()->GetUserInterface()->End(); m_Window->GetGfxContext()->GetUserInterface()->End();
@ -112,14 +114,14 @@ namespace Light {
// input // input
if (event.HasCategory(InputEventCategory)) if (event.HasCategory(InputEventCategory))
m_Input.OnEvent(event); m_Input->OnEvent(event);
// layers // layers
// return if the event is an input event and 'Input' has disabled the game events // return if the event is an input event and 'Input' has disabled the game events
if (event.HasCategory(InputEventCategory) && !m_Input.IsReceivingGameEvents()) if (event.HasCategory(InputEventCategory) && !m_Input->IsReceivingGameEvents())
return; return;
for (auto it = m_LayerStack.rbegin(); it != m_LayerStack.rend(); it++) for (auto it = m_LayerStack->rbegin(); it != m_LayerStack->rend(); it++)
if ((*it)->OnEvent(event)) return; if ((*it)->OnEvent(event)) return;
} }

View file

@ -18,12 +18,12 @@ namespace Light {
class Application class Application
{ {
private: private:
std::unique_ptr<Instrumentor> m_Instrumentor = nullptr; Scope<Instrumentor> m_Instrumentor = nullptr;
LayerStack m_LayerStack; Scope<LayerStack> m_LayerStack;
Input m_Input; Scope<Input> m_Input;
protected: protected:
std::unique_ptr<Window> m_Window = nullptr; Scope<Window> m_Window = nullptr;
public: public:
Application(const Application&) = delete; Application(const Application&) = delete;

View file

@ -19,12 +19,12 @@ namespace Light {
class Window class Window
{ {
protected: protected:
std::unique_ptr<GraphicsContext> m_GraphicsContext; Scope<GraphicsContext> m_GraphicsContext;
WindowProperties m_Properties = {}; WindowProperties m_Properties = {};
bool b_Closed = false; bool b_Closed = false;
public: public:
static Window* Create(std::function<void(Event&)> callback); static Scope<Window> Create(std::function<void(Event&)> callback);
Window(const Window&) = delete; Window(const Window&) = delete;
Window& operator=(const Window&) = delete; Window& operator=(const Window&) = delete;

View file

@ -5,9 +5,9 @@ namespace Light {
Instrumentor* Instrumentor::s_Context = nullptr; Instrumentor* Instrumentor::s_Context = nullptr;
Instrumentor* Instrumentor::Create() Scope<Instrumentor> Instrumentor::Create()
{ {
return new Instrumentor; return MakeScope<Instrumentor>(new Instrumentor);
} }
Instrumentor::Instrumentor() Instrumentor::Instrumentor()

View file

@ -28,7 +28,7 @@ namespace Light {
unsigned int m_CurrentSessionCount; unsigned int m_CurrentSessionCount;
public: public:
static Instrumentor* Create(); static Scope<Instrumentor> Create();
static inline void BeginSession(const std::string& outputPath) { s_Context->BeginSessionImpl(outputPath); } static inline void BeginSession(const std::string& outputPath) { s_Context->BeginSessionImpl(outputPath); }
static inline void EndSession() { s_Context->EndSessionImpl(); } static inline void EndSession() { s_Context->EndSessionImpl(); }

View file

@ -6,9 +6,9 @@
namespace Light { namespace Light {
std::shared_ptr<spdlog::logger> Logger::s_EngineLogger = nullptr; Ref<spdlog::logger> Logger::s_EngineLogger = nullptr;
std::shared_ptr<spdlog::logger> Logger::s_ClientLogger = nullptr; Ref<spdlog::logger> Logger::s_ClientLogger = nullptr;
std::shared_ptr<spdlog::logger> Logger::s_FileLogger = nullptr; Ref<spdlog::logger> Logger::s_FileLogger = nullptr;
std::string Logger::s_LogFilePath = LT_LOG_FILE_LOCATION; std::string Logger::s_LogFilePath = LT_LOG_FILE_LOCATION;

View file

@ -1,5 +1,6 @@
#pragma once #pragma once
#define LT_LOGGER_H
#include "Base.h" #include "Base.h"
#include <spdlog/spdlog.h> #include <spdlog/spdlog.h>
@ -47,7 +48,7 @@ namespace Light {
class Logger class Logger
{ {
private: private:
static std::shared_ptr<spdlog::logger> s_EngineLogger, s_ClientLogger, s_FileLogger; static Ref<spdlog::logger> s_EngineLogger, s_ClientLogger, s_FileLogger;
static std::string s_LogFilePath; static std::string s_LogFilePath;
public: public:
@ -55,11 +56,12 @@ namespace Light {
static void Initialize(); static void Initialize();
static inline std::shared_ptr<spdlog::logger> GetEngineLogger() { return s_EngineLogger; } static inline Ref<spdlog::logger> GetEngineLogger() { return s_EngineLogger; }
static inline std::shared_ptr<spdlog::logger> GetClientLogger() { return s_ClientLogger; } static inline Ref<spdlog::logger> GetClientLogger() { return s_ClientLogger; }
static inline std::shared_ptr<spdlog::logger> GetFileLogger() { return s_FileLogger; } static inline Ref<spdlog::logger> GetFileLogger() { return s_FileLogger; }
static void LogDebugData(); static void LogDebugData();
}; };
} }

View file

@ -12,15 +12,15 @@
namespace Light { namespace Light {
Blender* Blender::Create(std::shared_ptr<SharedContext> sharedContext) Scope<Blender> Blender::Create(Ref<SharedContext> sharedContext)
{ {
switch (GraphicsContext::GetGraphicsAPI()) switch (GraphicsContext::GetGraphicsAPI())
{ {
case GraphicsAPI::OpenGL: case GraphicsAPI::OpenGL:
return new glBlender(); return CreateScope<glBlender>();
case GraphicsAPI::DirectX: LT_WIN( case GraphicsAPI::DirectX: LT_WIN(
return new dxBlender(std::static_pointer_cast<dxSharedContext>(sharedContext));) return CreateScope<dxBlender>(std::static_pointer_cast<dxSharedContext>(sharedContext));)
default: default:
LT_ENGINE_ASSERT(false, "Blender::Create: invalid/unsupported 'GraphicsAPI' {}", GraphicsContext::GetGraphicsAPI()); LT_ENGINE_ASSERT(false, "Blender::Create: invalid/unsupported 'GraphicsAPI' {}", GraphicsContext::GetGraphicsAPI());

View file

@ -38,7 +38,7 @@ namespace Light {
private: private:
public: public:
static Blender* Create(std::shared_ptr<SharedContext> sharedContext); static Scope<Blender> Create(Ref<SharedContext> sharedContext);
virtual void Enable(BlendFactor srcFactor, BlendFactor dstFactor) = 0; virtual void Enable(BlendFactor srcFactor, BlendFactor dstFactor) = 0;
virtual void Disable() = 0; virtual void Disable() = 0;

View file

@ -14,32 +14,32 @@
namespace Light { namespace Light {
//* CONSTANT_BUFFER *// //* CONSTANT_BUFFER *//
ConstantBuffer* ConstantBuffer::Create(ConstantBufferIndex index, unsigned int size, std::shared_ptr<SharedContext> sharedContext) Scope<ConstantBuffer> ConstantBuffer::Create(ConstantBufferIndex index, unsigned int size, Ref<SharedContext> sharedContext)
{ {
switch (GraphicsContext::GetGraphicsAPI()) switch (GraphicsContext::GetGraphicsAPI())
{ {
case GraphicsAPI::OpenGL: case GraphicsAPI::OpenGL:
return new glConstantBuffer(index, size); return CreateScope<glConstantBuffer>(index, size);
case GraphicsAPI::DirectX: LT_WIN( case GraphicsAPI::DirectX: LT_WIN(
return new dxConstantBuffer(index, size, std::static_pointer_cast<dxSharedContext>(sharedContext));) return CreateScope<dxConstantBuffer>(index, size, std::static_pointer_cast<dxSharedContext>(sharedContext));)
default: default:
LT_ENGINE_ASSERT(false, "VertexBuffer::Create: invalid/unsupported 'GraphicsAPI' {}", GraphicsContext::GetGraphicsAPI()); LT_ENGINE_ASSERT(false, "ConstantBuffer::Create: invalid/unsupported 'GraphicsAPI' {}", GraphicsContext::GetGraphicsAPI());
return nullptr; return nullptr;
} }
} }
//* VERTEX_BUFFER *// //* VERTEX_BUFFER *//
VertexBuffer* VertexBuffer::Create(float* vertices, unsigned int stride, unsigned int count, std::shared_ptr<SharedContext> sharedContext) Ref<VertexBuffer> VertexBuffer::Create(float* vertices, unsigned int stride, unsigned int count, Ref<SharedContext> sharedContext)
{ {
switch (GraphicsContext::GetGraphicsAPI()) switch (GraphicsContext::GetGraphicsAPI())
{ {
case GraphicsAPI::OpenGL: case GraphicsAPI::OpenGL:
return new glVertexBuffer(vertices, count); return CreateRef<glVertexBuffer>(vertices, count);
case GraphicsAPI::DirectX: LT_WIN( case GraphicsAPI::DirectX: LT_WIN(
return new dxVertexBuffer(vertices, stride, count, std::static_pointer_cast<dxSharedContext>(sharedContext));) return CreateRef<dxVertexBuffer>(vertices, stride, count, std::static_pointer_cast<dxSharedContext>(sharedContext));)
default: default:
LT_ENGINE_ASSERT(false, "VertexBuffer::Create: invalid/unsupported 'GraphicsAPI' {}", GraphicsContext::GetGraphicsAPI()); LT_ENGINE_ASSERT(false, "VertexBuffer::Create: invalid/unsupported 'GraphicsAPI' {}", GraphicsContext::GetGraphicsAPI());
@ -48,15 +48,15 @@ namespace Light {
} }
//* INDEX_BUFFER *// //* INDEX_BUFFER *//
IndexBuffer* IndexBuffer::Create(unsigned int* indices, unsigned int count, std::shared_ptr<SharedContext> sharedContext) Ref<IndexBuffer> IndexBuffer::Create(unsigned int* indices, unsigned int count, Ref<SharedContext> sharedContext)
{ {
switch (GraphicsContext::GetGraphicsAPI()) switch (GraphicsContext::GetGraphicsAPI())
{ {
case GraphicsAPI::OpenGL: case GraphicsAPI::OpenGL:
return new glIndexBuffer(indices, count); return CreateRef<glIndexBuffer>(indices, count);
case GraphicsAPI::DirectX: LT_WIN( case GraphicsAPI::DirectX: LT_WIN(
return new dxIndexBuffer(indices, count, std::dynamic_pointer_cast<dxSharedContext>(sharedContext));) return CreateRef<dxIndexBuffer>(indices, count, std::dynamic_pointer_cast<dxSharedContext>(sharedContext));)
default: default:
LT_ENGINE_ASSERT(false, "IndexBuffer::Create: invalid/unsupported 'GraphicsAPI' {}", GraphicsContext::GetGraphicsAPI()); LT_ENGINE_ASSERT(false, "IndexBuffer::Create: invalid/unsupported 'GraphicsAPI' {}", GraphicsContext::GetGraphicsAPI());

View file

@ -15,19 +15,22 @@ namespace Light {
class ConstantBuffer class ConstantBuffer
{ {
public: public:
static ConstantBuffer* Create(ConstantBufferIndex index, unsigned int size, std::shared_ptr<SharedContext> sharedContext); static Scope<ConstantBuffer> Create(ConstantBufferIndex index, unsigned int size, Ref<SharedContext> sharedContext);
virtual void Bind() = 0; virtual void Bind() = 0;
virtual void* Map() = 0; virtual void* Map() = 0;
virtual void UnMap() = 0; virtual void UnMap() = 0;
protected:
ConstantBuffer() = default;
}; };
//* VERTEX_BUFFER *// //* VERTEX_BUFFER *//
class VertexBuffer class VertexBuffer
{ {
public: public:
static VertexBuffer* Create(float* vertices, unsigned int stride, unsigned int count, std::shared_ptr<SharedContext> sharedContext); static Ref<VertexBuffer> Create(float* vertices, unsigned int stride, unsigned int count, Ref<SharedContext> sharedContext);
virtual ~VertexBuffer() = default; virtual ~VertexBuffer() = default;
@ -45,7 +48,7 @@ namespace Light {
class IndexBuffer class IndexBuffer
{ {
public: public:
static IndexBuffer* Create(unsigned int* indices, unsigned int count, std::shared_ptr<SharedContext> sharedContext); static Ref<IndexBuffer> Create(unsigned int* indices, unsigned int count, Ref<SharedContext> sharedContext);
virtual ~IndexBuffer() = default; virtual ~IndexBuffer() = default;

View file

@ -11,15 +11,15 @@
namespace Light { namespace Light {
Framebuffer* Framebuffer::Create(const FramebufferSpecification& specification, std::shared_ptr<SharedContext> sharedContext) Ref<Framebuffer> Framebuffer::Create(const FramebufferSpecification& specification, Ref<SharedContext> sharedContext)
{ {
switch (GraphicsContext::GetGraphicsAPI()) switch (GraphicsContext::GetGraphicsAPI())
{ {
case GraphicsAPI::OpenGL: case GraphicsAPI::OpenGL:
return new glFramebuffer(specification); return CreateRef<glFramebuffer>(specification);
case GraphicsAPI::DirectX: LT_WIN( case GraphicsAPI::DirectX: LT_WIN(
return new dxFramebuffer(specification, std::static_pointer_cast<dxSharedContext>(sharedContext));) return CreateRef<dxFramebuffer>(specification, std::static_pointer_cast<dxSharedContext>(sharedContext));)
default: default:
LT_ENGINE_ASSERT(false, "Shader::Create: invalid/unsupported 'GraphicsAPI' {}", GraphicsContext::GetGraphicsAPI()); LT_ENGINE_ASSERT(false, "Shader::Create: invalid/unsupported 'GraphicsAPI' {}", GraphicsContext::GetGraphicsAPI());

View file

@ -21,7 +21,7 @@ namespace Light {
class Framebuffer class Framebuffer
{ {
public: public:
static Framebuffer* Create(const FramebufferSpecification& specification, std::shared_ptr<SharedContext> sharedContext); static Ref<Framebuffer> Create(const FramebufferSpecification& specification, Ref<SharedContext> sharedContext);
virtual void* GetColorAttachment() = 0; virtual void* GetColorAttachment() = 0;

View file

@ -19,7 +19,7 @@ namespace Light {
GraphicsContext::~GraphicsContext() {} GraphicsContext::~GraphicsContext() {}
GraphicsContext* GraphicsContext::Create(GraphicsAPI api, GLFWwindow* windowHandle) Scope<GraphicsContext> GraphicsContext::Create(GraphicsAPI api, GLFWwindow* windowHandle)
{ {
// terminate 'GraphicsContext' dependent classes // terminate 'GraphicsContext' dependent classes
if (s_Context) if (s_Context)
@ -43,14 +43,17 @@ namespace Light {
} }
// create gfx context // create gfx context
Scope<GraphicsContext> scopeGfx;
switch (api) switch (api)
{ {
case GraphicsAPI::OpenGL: case GraphicsAPI::OpenGL:
s_Context = new glGraphicsContext(windowHandle); scopeGfx = CreateScope<glGraphicsContext>(windowHandle);
s_Context = scopeGfx.get();
break; break;
case GraphicsAPI::DirectX: LT_WIN( case GraphicsAPI::DirectX: LT_WIN(
s_Context = new dxGraphicsContext(windowHandle); scopeGfx = CreateScope<dxGraphicsContext>(windowHandle);
s_Context = scopeGfx.get();
break;) break;)
default: default:
@ -59,16 +62,16 @@ namespace Light {
} }
// create 'GraphicsContext' dependent classes // create 'GraphicsContext' dependent classes
s_Context->m_ResourceManager = std::unique_ptr<ResourceManager>(ResourceManager::Create(s_Context->m_SharedContext)); s_Context->m_ResourceManager = ResourceManager::Create(s_Context->m_SharedContext);
s_Context->m_UserInterface = std::unique_ptr<UserInterface>(UserInterface::Create(windowHandle, s_Context->m_SharedContext)); s_Context->m_UserInterface = UserInterface::Create(windowHandle, s_Context->m_SharedContext);
s_Context->m_Renderer = std::unique_ptr<Renderer>(Renderer::Create(windowHandle, s_Context->m_SharedContext)); s_Context->m_Renderer = Renderer::Create(windowHandle, s_Context->m_SharedContext);
// check // check
LT_ENGINE_ASSERT(s_Context->m_ResourceManager, "GraphicsContext::Create: failed to create ResourceManager"); LT_ENGINE_ASSERT(s_Context->m_ResourceManager, "GraphicsContext::Create: failed to create ResourceManager");
LT_ENGINE_ASSERT(s_Context->m_UserInterface, "GraphicsContext::Create: failed to create UserInterface"); LT_ENGINE_ASSERT(s_Context->m_UserInterface, "GraphicsContext::Create: failed to create UserInterface");
LT_ENGINE_ASSERT(s_Context->m_Renderer, "GraphicsContext::Create: failed to create Renderer"); LT_ENGINE_ASSERT(s_Context->m_Renderer, "GraphicsContext::Create: failed to create Renderer");
return s_Context; return std::move(scopeGfx);
} }
} }

View file

@ -28,16 +28,16 @@ namespace Light {
private: private:
static GraphicsContext* s_Context; static GraphicsContext* s_Context;
std::unique_ptr<ResourceManager> m_ResourceManager; Scope<ResourceManager> m_ResourceManager;
std::unique_ptr<UserInterface> m_UserInterface; Scope<UserInterface> m_UserInterface;
std::unique_ptr<Renderer> m_Renderer; Scope<Renderer> m_Renderer;
protected: protected:
GraphicsAPI m_GraphicsAPI; GraphicsAPI m_GraphicsAPI;
std::shared_ptr<SharedContext> m_SharedContext = nullptr; Ref<SharedContext> m_SharedContext = nullptr;
public: public:
static GraphicsContext* Create(GraphicsAPI api, GLFWwindow* windowHandle); static Scope<GraphicsContext> Create(GraphicsAPI api, GLFWwindow* windowHandle);
GraphicsContext(const GraphicsContext&) = delete; GraphicsContext(const GraphicsContext&) = delete;
GraphicsContext& operator=(const GraphicsContext&) = delete; GraphicsContext& operator=(const GraphicsContext&) = delete;
@ -47,15 +47,13 @@ namespace Light {
virtual void LogDebugData() = 0; virtual void LogDebugData() = 0;
static inline GraphicsAPI GetGraphicsAPI() { return s_Context->m_GraphicsAPI; } static inline GraphicsAPI GetGraphicsAPI() { return s_Context->m_GraphicsAPI; }
static inline std::shared_ptr<SharedContext> GetSharedContext() { return s_Context->m_SharedContext; } static inline Ref<SharedContext> GetSharedContext() { return s_Context->m_SharedContext; }
inline Renderer* GetRenderer() { return m_Renderer.get(); } inline Renderer* GetRenderer() { return m_Renderer.get(); }
inline UserInterface* GetUserInterface() { return m_UserInterface.get(); } inline UserInterface* GetUserInterface() { return m_UserInterface.get(); }
protected: protected:
GraphicsContext() = default; GraphicsContext() = default;
}; };
} }

View file

@ -11,15 +11,15 @@
namespace Light { namespace Light {
RenderCommand* RenderCommand::Create(GLFWwindow* windowHandle, std::shared_ptr<SharedContext> sharedContext) Scope<RenderCommand> RenderCommand::Create(GLFWwindow* windowHandle, Ref<SharedContext> sharedContext)
{ {
switch (GraphicsContext::GetGraphicsAPI()) switch (GraphicsContext::GetGraphicsAPI())
{ {
case GraphicsAPI::OpenGL: case GraphicsAPI::OpenGL:
return new glRenderCommand(windowHandle); return CreateScope<glRenderCommand>(windowHandle);
case GraphicsAPI::DirectX: LT_WIN( case GraphicsAPI::DirectX: LT_WIN(
return new dxRenderCommand((std::static_pointer_cast<dxSharedContext>)(sharedContext));) return CreateScope<dxRenderCommand>((std::static_pointer_cast<dxSharedContext>)(sharedContext));)
default: default:
LT_ENGINE_ASSERT(false, "RenderCommand::Create: invalid/unsupported 'GraphicsAPI' {}", GraphicsContext::GetGraphicsAPI()); LT_ENGINE_ASSERT(false, "RenderCommand::Create: invalid/unsupported 'GraphicsAPI' {}", GraphicsContext::GetGraphicsAPI());

View file

@ -13,7 +13,7 @@ namespace Light {
class RenderCommand class RenderCommand
{ {
public: public:
static RenderCommand* Create(GLFWwindow* windowHandle, std::shared_ptr<SharedContext> sharedContext); static Scope<RenderCommand> Create(GLFWwindow* windowHandle, Ref<SharedContext> sharedContext);
RenderCommand(const RenderCommand&) = delete; RenderCommand(const RenderCommand&) = delete;
RenderCommand& operator=(const RenderCommand&) = delete; RenderCommand& operator=(const RenderCommand&) = delete;

View file

@ -19,24 +19,24 @@ namespace Light {
Renderer* Renderer::s_Context = nullptr; Renderer* Renderer::s_Context = nullptr;
Renderer::Renderer(GLFWwindow* windowHandle, std::shared_ptr<SharedContext> sharedContext) Renderer::Renderer(GLFWwindow* windowHandle, Ref<SharedContext> sharedContext)
: m_QuadRenderer(LT_MAX_QUAD_RENDERER_VERTICES, sharedContext), : m_QuadRenderer(LT_MAX_QUAD_RENDERER_VERTICES, sharedContext),
m_TextureRenderer(LT_MAX_TEXTURE_RENDERER_VERTICES, sharedContext) m_TextureRenderer(LT_MAX_TEXTURE_RENDERER_VERTICES, sharedContext)
{ {
LT_ENGINE_ASSERT(!s_Context, "Renderer::Renderer: an instance of 'Renderer' already exists, do not construct this class!"); LT_ENGINE_ASSERT(!s_Context, "Renderer::Renderer: an instance of 'Renderer' already exists, do not construct this class!");
s_Context = this; s_Context = this;
m_RenderCommand = std::unique_ptr<RenderCommand>(RenderCommand::Create(windowHandle, sharedContext)); m_RenderCommand = RenderCommand::Create(windowHandle, sharedContext);
m_ViewProjectionBuffer = std::unique_ptr<ConstantBuffer>(ConstantBuffer::Create(ConstantBufferIndex::ViewProjection, sizeof(glm::mat4), sharedContext)); m_ViewProjectionBuffer = ConstantBuffer::Create(ConstantBufferIndex::ViewProjection, sizeof(glm::mat4), sharedContext);
m_Blender = std::unique_ptr<Blender>(Blender::Create(sharedContext)); m_Blender = Blender::Create(sharedContext);
m_Blender->Enable(BlendFactor::SRC_ALPHA, BlendFactor::INVERSE_SRC_ALPHA); m_Blender->Enable(BlendFactor::SRC_ALPHA, BlendFactor::INVERSE_SRC_ALPHA);
} }
Renderer* Renderer::Create(GLFWwindow* windowHandle, std::shared_ptr<SharedContext> sharedContext) Scope<Renderer> Renderer::Create(GLFWwindow* windowHandle, Ref<SharedContext> sharedContext)
{ {
return new Renderer(windowHandle, sharedContext); return MakeScope<Renderer>(new Renderer(windowHandle, sharedContext));
} }
void Renderer::OnWindowResize(const WindowResizedEvent& event) void Renderer::OnWindowResize(const WindowResizedEvent& event)
@ -78,7 +78,7 @@ namespace Light {
} }
} }
void Renderer::DrawQuadImpl(const glm::vec3& position, const glm::vec2& size, std::shared_ptr<Texture> texture) void Renderer::DrawQuadImpl(const glm::vec3& position, const glm::vec2& size, Ref<Texture> texture)
{ {
// #todo: implement a proper binding // #todo: implement a proper binding
texture->Bind(); texture->Bind();
@ -125,7 +125,7 @@ namespace Light {
m_RenderCommand->ClearBackBuffer(m_Camera->GetClearColor()); m_RenderCommand->ClearBackBuffer(m_Camera->GetClearColor());
} }
void Renderer::BeginSceneImpl(const std::shared_ptr<Camera>& camera, const std::shared_ptr<Framebuffer>& targetFrameBuffer /* = nullptr */) void Renderer::BeginSceneImpl(const Ref<Camera>& camera, const Ref<Framebuffer>& targetFrameBuffer /* = nullptr */)
{ {
m_TargetFramebuffer = targetFrameBuffer; m_TargetFramebuffer = targetFrameBuffer;

View file

@ -39,24 +39,24 @@ namespace Light {
TextureRendererProgram m_TextureRenderer; TextureRendererProgram m_TextureRenderer;
// constant buffers // constant buffers
std::unique_ptr<ConstantBuffer> m_ViewProjectionBuffer; Scope<ConstantBuffer> m_ViewProjectionBuffer;
std::unique_ptr<RenderCommand> m_RenderCommand; Scope<RenderCommand> m_RenderCommand;
std::unique_ptr<Blender> m_Blender; Scope<Blender> m_Blender;
std::shared_ptr<Framebuffer> m_TargetFramebuffer; Ref<Framebuffer> m_TargetFramebuffer;
std::shared_ptr<Camera> m_Camera; Ref<Camera> m_Camera;
public: public:
static Renderer* Create(GLFWwindow* windowHandle, std::shared_ptr<SharedContext> sharedContext); static Scope<Renderer> Create(GLFWwindow* windowHandle, Ref<SharedContext> sharedContext);
static inline void SetTargetFramebuffer(std::shared_ptr<Framebuffer> framebuffer) { s_Context->SetTargetFramebufferImpl(framebuffer); } static inline void SetTargetFramebuffer(Ref<Framebuffer> framebuffer) { s_Context->SetTargetFramebufferImpl(framebuffer); }
static inline void DrawQuad(const glm::vec3& position, const glm::vec2& size, const glm::vec4& tint) { s_Context->DrawQuadImpl(position, size, tint); } static inline void DrawQuad(const glm::vec3& position, const glm::vec2& size, const glm::vec4& tint) { s_Context->DrawQuadImpl(position, size, tint); }
static inline void DrawQuad(const glm::vec3& position, const glm::vec2& size, std::shared_ptr<Texture> texture) { s_Context->DrawQuadImpl(position, size, texture); } static inline void DrawQuad(const glm::vec3& position, const glm::vec2& size, Ref<Texture> texture) { s_Context->DrawQuadImpl(position, size, texture); }
static inline void BeginScene(const std::shared_ptr<Camera>& camera, const std::shared_ptr<Framebuffer>& targetFrameBuffer = nullptr) { s_Context->BeginSceneImpl(camera, targetFrameBuffer); } static inline void BeginScene(const Ref<Camera>& camera, const Ref<Framebuffer>& targetFrameBuffer = nullptr) { s_Context->BeginSceneImpl(camera, targetFrameBuffer); }
static inline void EndScene() { s_Context->EndSceneImpl(); } static inline void EndScene() { s_Context->EndSceneImpl(); }
void OnWindowResize(const WindowResizedEvent& event); void OnWindowResize(const WindowResizedEvent& event);
@ -65,14 +65,14 @@ namespace Light {
void EndFrame(); void EndFrame();
private: private:
Renderer(GLFWwindow* windowHandle, std::shared_ptr<SharedContext> sharedContext); Renderer(GLFWwindow* windowHandle, Ref<SharedContext> sharedContext);
void SetTargetFramebufferImpl(std::shared_ptr<Framebuffer> framebuffer); void SetTargetFramebufferImpl(Ref<Framebuffer> framebuffer);
void DrawQuadImpl(const glm::vec3& position, const glm::vec2& size, const glm::vec4& tint); void DrawQuadImpl(const glm::vec3& position, const glm::vec2& size, const glm::vec4& tint);
void DrawQuadImpl(const glm::vec3& position, const glm::vec2& size, std::shared_ptr<Texture> texture); void DrawQuadImpl(const glm::vec3& position, const glm::vec2& size, Ref<Texture> texture);
void BeginSceneImpl(const std::shared_ptr<Camera>& camera, const std::shared_ptr<Framebuffer>& targetFrameBuffer = nullptr); void BeginSceneImpl(const Ref<Camera>& camera, const Ref<Framebuffer>& targetFrameBuffer = nullptr);
void FlushScene(); void FlushScene();
void EndSceneImpl(); void EndSceneImpl();
}; };

View file

@ -11,15 +11,15 @@
namespace Light { namespace Light {
QuadRendererProgram::QuadRendererProgram(unsigned int maxVertices, std::shared_ptr<SharedContext> sharedContext) QuadRendererProgram::QuadRendererProgram(unsigned int maxVertices, Ref<SharedContext> sharedContext)
: m_MaxVertices(maxVertices) : m_MaxVertices(maxVertices)
{ {
ResourceManager::LoadShader("LT_ENGINE_RESOURCES_QUAD_SHADER", "../Engine/res/Shaders/Quad/Quad_VS", "../Engine//res/Shaders/Quad/Quad_PS"); ResourceManager::LoadShader("LT_ENGINE_RESOURCES_QUAD_SHADER", "../Engine/res/Shaders/Quad/Quad_VS", "../Engine//res/Shaders/Quad/Quad_PS");
m_Shader = ResourceManager::GetShader("LT_ENGINE_RESOURCES_QUAD_SHADER"); m_Shader = ResourceManager::GetShader("LT_ENGINE_RESOURCES_QUAD_SHADER");
m_VertexBuffer = std::shared_ptr<VertexBuffer>(VertexBuffer::Create(nullptr, sizeof(QuadVertexData), maxVertices, sharedContext)); m_VertexBuffer = Ref<VertexBuffer>(VertexBuffer::Create(nullptr, sizeof(QuadVertexData), maxVertices, sharedContext));
m_IndexBuffer = std::shared_ptr<IndexBuffer>(IndexBuffer::Create(nullptr, (maxVertices / 4) * 6, sharedContext)); m_IndexBuffer = Ref<IndexBuffer>(IndexBuffer::Create(nullptr, (maxVertices / 4) * 6, sharedContext));
m_VertexLayout = std::shared_ptr<VertexLayout>(VertexLayout::Create(m_VertexBuffer, m_Shader, { { "POSITION", VertexElementType::Float3 }, m_VertexLayout = Ref<VertexLayout>(VertexLayout::Create(m_VertexBuffer, m_Shader, { { "POSITION", VertexElementType::Float3 },
{ "COLOR" , VertexElementType::Float4 }}, sharedContext)); { "COLOR" , VertexElementType::Float4 }}, sharedContext));
} }

View file

@ -26,10 +26,10 @@ namespace Light {
}; };
private: private:
std::shared_ptr<Shader> m_Shader; Ref<Shader> m_Shader;
std::shared_ptr<VertexBuffer> m_VertexBuffer; Ref<VertexBuffer> m_VertexBuffer;
std::shared_ptr<IndexBuffer> m_IndexBuffer; Ref<IndexBuffer> m_IndexBuffer;
std::shared_ptr<VertexLayout> m_VertexLayout; Ref<VertexLayout> m_VertexLayout;
QuadVertexData* m_MapCurrent = nullptr; QuadVertexData* m_MapCurrent = nullptr;
QuadVertexData* m_MapEnd = nullptr; QuadVertexData* m_MapEnd = nullptr;
@ -38,7 +38,7 @@ namespace Light {
unsigned int m_MaxVertices = 0u; unsigned int m_MaxVertices = 0u;
public: public:
QuadRendererProgram(unsigned int maxVertices, std::shared_ptr<SharedContext> sharedContext); QuadRendererProgram(unsigned int maxVertices, Ref<SharedContext> sharedContext);
bool Advance(); bool Advance();

View file

@ -11,15 +11,15 @@
namespace Light { namespace Light {
TextureRendererProgram::TextureRendererProgram(unsigned int maxVertices, std::shared_ptr<SharedContext> sharedContext) TextureRendererProgram::TextureRendererProgram(unsigned int maxVertices, Ref<SharedContext> sharedContext)
: m_MaxVertices(maxVertices) : m_MaxVertices(maxVertices)
{ {
ResourceManager::LoadShader("LT_ENGINE_RESOURCES_TEXTURE_SHADER", "../Engine/res/Shaders/Texture/Texture_VS", "../Engine/res/Shaders/Texture/Texture_PS"); ResourceManager::LoadShader("LT_ENGINE_RESOURCES_TEXTURE_SHADER", "../Engine/res/Shaders/Texture/Texture_VS", "../Engine/res/Shaders/Texture/Texture_PS");
m_Shader = ResourceManager::GetShader("LT_ENGINE_RESOURCES_TEXTURE_SHADER"); m_Shader = ResourceManager::GetShader("LT_ENGINE_RESOURCES_TEXTURE_SHADER");
m_VertexBuffer = std::shared_ptr<VertexBuffer>(VertexBuffer::Create(nullptr, sizeof(TextureVertexData), maxVertices, sharedContext)); m_VertexBuffer = Ref<VertexBuffer>(VertexBuffer::Create(nullptr, sizeof(TextureVertexData), maxVertices, sharedContext));
m_IndexBuffer = std::shared_ptr<IndexBuffer>(IndexBuffer::Create(nullptr, (maxVertices / 4) * 6, sharedContext)); m_IndexBuffer = Ref<IndexBuffer>(IndexBuffer::Create(nullptr, (maxVertices / 4) * 6, sharedContext));
m_VertexLayout = std::shared_ptr<VertexLayout>(VertexLayout::Create(m_VertexBuffer, m_Shader, { { "POSITION", VertexElementType::Float3 }, m_VertexLayout = Ref<VertexLayout>(VertexLayout::Create(m_VertexBuffer, m_Shader, { { "POSITION", VertexElementType::Float3 },
{ "TEXCOORD", VertexElementType::Float2 }}, sharedContext)); { "TEXCOORD", VertexElementType::Float2 }}, sharedContext));
} }

View file

@ -26,10 +26,10 @@ namespace Light {
}; };
private: private:
std::shared_ptr<Shader> m_Shader; Ref<Shader> m_Shader;
std::shared_ptr<VertexBuffer> m_VertexBuffer; Ref<VertexBuffer> m_VertexBuffer;
std::shared_ptr<IndexBuffer> m_IndexBuffer; Ref<IndexBuffer> m_IndexBuffer;
std::shared_ptr<VertexLayout> m_VertexLayout; Ref<VertexLayout> m_VertexLayout;
TextureVertexData* m_MapCurrent = nullptr; TextureVertexData* m_MapCurrent = nullptr;
TextureVertexData* m_MapEnd = nullptr; TextureVertexData* m_MapEnd = nullptr;
@ -38,7 +38,7 @@ namespace Light {
unsigned int m_MaxVertices = 0u; unsigned int m_MaxVertices = 0u;
public: public:
TextureRendererProgram(unsigned int maxVertices, std::shared_ptr<SharedContext> sharedContext); TextureRendererProgram(unsigned int maxVertices, Ref<SharedContext> sharedContext);
bool Advance(); bool Advance();

View file

@ -11,16 +11,16 @@
namespace Light { namespace Light {
Shader* Shader::Create(const std::string& vertexSource, const std::string& pixelSource, std::shared_ptr<SharedContext> sharedContext) Ref<Shader> Shader::Create(const std::string& vertexSource, const std::string& pixelSource, Ref<SharedContext> sharedContext)
{ {
// load shader source // load shader source
switch (GraphicsContext::GetGraphicsAPI()) switch (GraphicsContext::GetGraphicsAPI())
{ {
case GraphicsAPI::OpenGL: case GraphicsAPI::OpenGL:
return new glShader(vertexSource, pixelSource); return CreateRef<glShader>(vertexSource, pixelSource);
case GraphicsAPI::DirectX: LT_WIN( case GraphicsAPI::DirectX: LT_WIN(
return new dxShader(vertexSource, pixelSource, std::static_pointer_cast<dxSharedContext>(sharedContext));) return CreateRef<dxShader>(vertexSource, pixelSource, std::static_pointer_cast<dxSharedContext>(sharedContext));)
default: default:
LT_ENGINE_ASSERT(false, "Shader::Create: invalid/unsupported 'GraphicsAPI' {}", GraphicsContext::GetGraphicsAPI()); LT_ENGINE_ASSERT(false, "Shader::Create: invalid/unsupported 'GraphicsAPI' {}", GraphicsContext::GetGraphicsAPI());

View file

@ -11,14 +11,13 @@ namespace Light {
class Shader class Shader
{ {
public: public:
static Shader* Create(const std::string& vertexPath, const std::string& pixelPath, std::shared_ptr<SharedContext> sharedContext); static Ref<Shader> Create(const std::string& vertexPath, const std::string& pixelPath, Ref<SharedContext> sharedContext);
virtual ~Shader() = default; virtual ~Shader() = default;
virtual void Bind() = 0; virtual void Bind() = 0;
virtual void UnBind() = 0; virtual void UnBind() = 0;
//** #TEMP_SHADER_UNIFORMS_TEMP# **// //** #TEMP_SHADER_UNIFORMS_TEMP# **//
virtual void SetUniformMat4(const std::string& name, const glm::mat4& value) = 0; virtual void SetUniformMat4(const std::string& name, const glm::mat4& value) = 0;

View file

@ -11,15 +11,15 @@
namespace Light { namespace Light {
Texture* Texture::Create(unsigned int width, unsigned int height, unsigned int components, unsigned char* pixels, std::shared_ptr<SharedContext> sharedContext) Ref<Texture>Texture::Create(unsigned int width, unsigned int height, unsigned int components, unsigned char* pixels, Ref<SharedContext> sharedContext)
{ {
switch (GraphicsContext::GetGraphicsAPI()) switch (GraphicsContext::GetGraphicsAPI())
{ {
case GraphicsAPI::OpenGL: case GraphicsAPI::OpenGL:
return new glTexture(width, height, components, pixels); return CreateRef<glTexture>(width, height, components, pixels);
case GraphicsAPI::DirectX: LT_WIN( case GraphicsAPI::DirectX: LT_WIN(
return new dxTexture(width, height, components, pixels, std::static_pointer_cast<dxSharedContext>(sharedContext));) return CreateRef<dxTexture>(width, height, components, pixels, std::static_pointer_cast<dxSharedContext>(sharedContext));)
default: default:
LT_ENGINE_ASSERT(false, "Texture::Create: invalid/unsupported 'GraphicsAPI' {}", GraphicsContext::GetGraphicsAPI()); LT_ENGINE_ASSERT(false, "Texture::Create: invalid/unsupported 'GraphicsAPI' {}", GraphicsContext::GetGraphicsAPI());

View file

@ -10,7 +10,7 @@ namespace Light {
class Texture class Texture
{ {
public: public:
static Texture* Create(unsigned int width, unsigned int height, unsigned int components, unsigned char* pixels, std::shared_ptr<SharedContext> sharedContext); static Ref<Texture> Create(unsigned int width, unsigned int height, unsigned int components, unsigned char* pixels, Ref<SharedContext> sharedContext);
Texture(const Texture&) = delete; Texture(const Texture&) = delete;
Texture& operator=(const Texture&) = delete; Texture& operator=(const Texture&) = delete;

View file

@ -11,15 +11,15 @@
namespace Light { namespace Light {
VertexLayout* VertexLayout::Create(std::shared_ptr<VertexBuffer> vertexBuffer, std::shared_ptr<Shader> shader, const std::vector<std::pair<std::string, VertexElementType>>& elements, std::shared_ptr<SharedContext> sharedContext) Ref<VertexLayout> VertexLayout::Create(Ref<VertexBuffer> vertexBuffer, Ref<Shader> shader, const std::vector<std::pair<std::string, VertexElementType>>& elements, Ref<SharedContext> sharedContext)
{ {
switch (GraphicsContext::GetGraphicsAPI()) switch (GraphicsContext::GetGraphicsAPI())
{ {
case GraphicsAPI::OpenGL: case GraphicsAPI::OpenGL:
return new glVertexLayout(vertexBuffer, elements); return CreateRef<glVertexLayout>(vertexBuffer, elements);
case GraphicsAPI::DirectX: LT_WIN( case GraphicsAPI::DirectX: LT_WIN(
return new dxVertexLayout(shader, elements, std::static_pointer_cast<dxSharedContext>(sharedContext));) return CreateRef<dxVertexLayout>(shader, elements, std::static_pointer_cast<dxSharedContext>(sharedContext));)
default: default:
LT_ENGINE_ASSERT(false, "VertexLayout::Create: invalid/unsupported 'GraphicsAPI' {}", GraphicsContext::GetGraphicsAPI()); LT_ENGINE_ASSERT(false, "VertexLayout::Create: invalid/unsupported 'GraphicsAPI' {}", GraphicsContext::GetGraphicsAPI());

View file

@ -20,7 +20,7 @@ namespace Light {
class VertexLayout class VertexLayout
{ {
public: public:
static VertexLayout* Create(std::shared_ptr<VertexBuffer> vertexBuffer, std::shared_ptr<Shader> shader, const std::vector<std::pair<std::string, VertexElementType>>& elements, std::shared_ptr<SharedContext> sharedContext); static Ref<VertexLayout> Create(Ref<VertexBuffer> vertexBuffer, Ref<Shader> shader, const std::vector<std::pair<std::string, VertexElementType>>& elements, Ref<SharedContext> sharedContext);
virtual ~VertexLayout() = default;; virtual ~VertexLayout() = default;;

View file

@ -11,6 +11,11 @@ namespace Light {
Input* Input::s_Context = nullptr; Input* Input::s_Context = nullptr;
Scope<Input> Input::Create()
{
return MakeScope(new Input);
}
Input::Input() Input::Input()
{ {
LT_ENGINE_ASSERT(!s_Context, "Input::Input: an instance of 'Input' already exists, do not construct this class!"); LT_ENGINE_ASSERT(!s_Context, "Input::Input: an instance of 'Input' already exists, do not construct this class!");

View file

@ -23,7 +23,7 @@ namespace Light {
bool m_UserInterfaceEvents = true; bool m_UserInterfaceEvents = true;
bool m_GameEvents = true; bool m_GameEvents = true;
public: public:
Input(); static Scope<Input> Create();
static inline void ReceiveUserInterfaceEvents(bool receive, bool toggle = false) { s_Context->ReceiveUserInterfaceEventsImpl(receive, toggle); } static inline void ReceiveUserInterfaceEvents(bool receive, bool toggle = false) { s_Context->ReceiveUserInterfaceEventsImpl(receive, toggle); }
static inline void ReceiveGameEvents(bool receive, bool toggle = false) { s_Context->ReceieveGameEventsImpl(receive, toggle); } static inline void ReceiveGameEvents(bool receive, bool toggle = false) { s_Context->ReceieveGameEventsImpl(receive, toggle); }
@ -39,6 +39,8 @@ namespace Light {
inline bool IsReceivingGameEvents() const { return m_GameEvents; } inline bool IsReceivingGameEvents() const { return m_GameEvents; }
private: private:
Input();
void ReceiveUserInterfaceEventsImpl(bool receive, bool toggle = false); void ReceiveUserInterfaceEventsImpl(bool receive, bool toggle = false);
void ReceieveGameEventsImpl(bool receive, bool toggle = false); void ReceieveGameEventsImpl(bool receive, bool toggle = false);

View file

@ -22,14 +22,14 @@ namespace Light {
class Layer class Layer
{ {
private: protected:
std::string m_Name; std::string m_LayerName;
public: public:
Layer(const std::string& name): m_Name(name) {} Layer(const std::string& name): m_LayerName(name) {}
virtual ~Layer() = default; virtual ~Layer() = default;
inline const std::string& GetName() const { return m_Name; } inline const std::string& GetName() const { return m_LayerName; }
//** UPDATES // //** UPDATES //
virtual void OnUpdate(float deltaTime) {} virtual void OnUpdate(float deltaTime) {}

View file

@ -12,6 +12,11 @@ namespace Light {
LayerStack* LayerStack::s_Context = nullptr; LayerStack* LayerStack::s_Context = nullptr;
Scope<LayerStack> LayerStack::Create()
{
return MakeScope<LayerStack>(new LayerStack());
}
LayerStack::LayerStack() LayerStack::LayerStack()
{ {
LT_ENGINE_ASSERT(!s_Context, "LayerStack::LayerStack: an instance of 'LayerStack' already exists, do not construct this class!") LT_ENGINE_ASSERT(!s_Context, "LayerStack::LayerStack: an instance of 'LayerStack' already exists, do not construct this class!")

View file

@ -18,9 +18,14 @@ namespace Light {
std::vector<Layer*>::iterator m_End; std::vector<Layer*>::iterator m_End;
public: public:
LayerStack(); static Scope<LayerStack> Create();
~LayerStack(); ~LayerStack();
// #todo: should we keep this?
template<typename T, typename... Args>
static inline void AttachLayer(Args&&... args) { s_Context->AttachLayerImpl(new T((args)...)); }
static inline void AttachLayer(Layer* layer) { s_Context->AttachLayerImpl(layer); } static inline void AttachLayer(Layer* layer) { s_Context->AttachLayerImpl(layer); }
static inline void DetachLayer(Layer* layer) { s_Context->DetachLayerImpl(layer); } static inline void DetachLayer(Layer* layer) { s_Context->DetachLayerImpl(layer); }
@ -32,6 +37,8 @@ namespace Light {
std::vector<Layer*>::reverse_iterator rend() { return m_Layers.rend(); } std::vector<Layer*>::reverse_iterator rend() { return m_Layers.rend(); }
private: private:
LayerStack();
void AttachLayerImpl(Layer* layer); void AttachLayerImpl(Layer* layer);
void DetachLayerImpl(Layer* layer); void DetachLayerImpl(Layer* layer);
}; };

View file

@ -8,6 +8,7 @@ namespace Light {
class Texture; class Texture;
// #todo: store a mat4 for transform
struct TransformComponent struct TransformComponent
{ {
glm::vec2 position, size; glm::vec2 position, size;
@ -24,13 +25,13 @@ namespace Light {
struct SpriteRendererComponent struct SpriteRendererComponent
{ {
std::shared_ptr<Texture> texture; Ref<Texture> texture;
SpriteRendererComponent() = default; SpriteRendererComponent() = default;
SpriteRendererComponent(const SpriteRendererComponent&) = default; SpriteRendererComponent(const SpriteRendererComponent&) = default;
SpriteRendererComponent(std::shared_ptr<Texture> _texture) : texture(_texture) {} SpriteRendererComponent(Ref<Texture> _texture) : texture(_texture) {}
operator std::shared_ptr<Texture>() { return texture; } operator Ref<Texture>() { return texture; }
}; };
} }

View file

@ -17,15 +17,15 @@
namespace Light { namespace Light {
UserInterface* UserInterface::Create(GLFWwindow* windowHandle, std::shared_ptr<SharedContext> sharedContext) Scope<UserInterface> UserInterface::Create(GLFWwindow* windowHandle, Ref<SharedContext> sharedContext)
{ {
switch (GraphicsContext::GetGraphicsAPI()) switch (GraphicsContext::GetGraphicsAPI())
{ {
case GraphicsAPI::OpenGL: case GraphicsAPI::OpenGL:
return new glUserInterface(windowHandle); return CreateScope<glUserInterface>(windowHandle);
case GraphicsAPI::DirectX: LT_WIN( case GraphicsAPI::DirectX: LT_WIN(
return new dxUserInterface(windowHandle, std::dynamic_pointer_cast<dxSharedContext>(sharedContext));) return CreateScope<dxUserInterface>(windowHandle, std::dynamic_pointer_cast<dxSharedContext>(sharedContext));)
default: default:
LT_ENGINE_ASSERT(false, "UserInterface::Create: invalid/unsupported 'GraphicsAPI' {}", GraphicsContext::GetGraphicsAPI()); LT_ENGINE_ASSERT(false, "UserInterface::Create: invalid/unsupported 'GraphicsAPI' {}", GraphicsContext::GetGraphicsAPI());

View file

@ -12,7 +12,7 @@ namespace Light {
class UserInterface class UserInterface
{ {
public: public:
static UserInterface* Create(GLFWwindow* windowHandle, std::shared_ptr<SharedContext> sharedContext); static Scope<UserInterface> Create(GLFWwindow* windowHandle, Ref<SharedContext> sharedContext);
UserInterface(const UserInterface&) = delete; UserInterface(const UserInterface&) = delete;
UserInterface& operator=(const UserInterface&) = delete; UserInterface& operator=(const UserInterface&) = delete;

View file

@ -11,12 +11,12 @@ namespace Light {
ResourceManager* ResourceManager::s_Context = nullptr; ResourceManager* ResourceManager::s_Context = nullptr;
ResourceManager* ResourceManager::Create(std::shared_ptr<SharedContext> sharedContext) Scope<ResourceManager> ResourceManager::Create(Ref<SharedContext> sharedContext)
{ {
return new ResourceManager(sharedContext); return MakeScope(new ResourceManager(sharedContext));
} }
ResourceManager::ResourceManager(std::shared_ptr<SharedContext> sharedContext) ResourceManager::ResourceManager(Ref<SharedContext> sharedContext)
: m_SharedContext(sharedContext) : m_SharedContext(sharedContext)
{ {
LT_ENGINE_ASSERT(!s_Context, "ResourceManager::ResourceManager: an instance of 'ResourceManager' already exists, do not construct this class!"); LT_ENGINE_ASSERT(!s_Context, "ResourceManager::ResourceManager: an instance of 'ResourceManager' already exists, do not construct this class!");
@ -45,7 +45,7 @@ namespace Light {
ResourceManager::ExtractShaderSource(psSource, delim); ResourceManager::ExtractShaderSource(psSource, delim);
// create shader // create shader
m_Shaders[name] = std::shared_ptr<Shader>(Shader::Create(vsSource, psSource, m_SharedContext)); m_Shaders[name] = Ref<Shader>(Shader::Create(vsSource, psSource, m_SharedContext));
} }
void ResourceManager::LoadShaderImpl(const std::string& name, const std::string& vertexPath, const std::string& pixelPath) void ResourceManager::LoadShaderImpl(const std::string& name, const std::string& vertexPath, const std::string& pixelPath)
@ -70,7 +70,7 @@ namespace Light {
psSS << line << '\n'; psSS << line << '\n';
// create shader // create shader
m_Shaders[name] = std::shared_ptr<Shader>(Shader::Create(vsSS.str(), psSS.str(), m_SharedContext)); m_Shaders[name] = Ref<Shader>(Shader::Create(vsSS.str(), psSS.str(), m_SharedContext));
} }
void ResourceManager::LoadTextureImpl(const std::string& name, const std::string& path, unsigned int desiredComponents /* = 4u */) void ResourceManager::LoadTextureImpl(const std::string& name, const std::string& path, unsigned int desiredComponents /* = 4u */)
@ -88,7 +88,7 @@ namespace Light {
} }
// create texture // create texture
m_Textures[name] = std::shared_ptr<Texture>(Texture::Create(width, height, components, pixels, m_SharedContext)); m_Textures[name] = Ref<Texture>(Texture::Create(width, height, components, pixels, m_SharedContext));
} }
void ResourceManager::ExtractShaderSource(std::string& src, const std::string& delim) void ResourceManager::ExtractShaderSource(std::string& src, const std::string& delim)

View file

@ -15,13 +15,13 @@ namespace Light {
private: private:
static ResourceManager* s_Context; static ResourceManager* s_Context;
std::unordered_map<std::string, std::shared_ptr<Shader>> m_Shaders; std::unordered_map<std::string, Ref<Shader>> m_Shaders;
std::unordered_map<std::string, std::shared_ptr<Texture>> m_Textures; std::unordered_map<std::string, Ref<Texture>> m_Textures;
std::shared_ptr<SharedContext> m_SharedContext; Ref<SharedContext> m_SharedContext;
public: public:
static ResourceManager* Create(std::shared_ptr<SharedContext> sharedContext); static Scope<ResourceManager> Create(Ref<SharedContext> sharedContext);
// #todo: add geometry shader support // #todo: add geometry shader support
static inline void CreateShader(const std::string& name, const std::string& vertexSource, const std::string& pixelSource) { s_Context->CreateShaderImpl(name, vertexSource, pixelSource); } static inline void CreateShader(const std::string& name, const std::string& vertexSource, const std::string& pixelSource) { s_Context->CreateShaderImpl(name, vertexSource, pixelSource); }
@ -29,11 +29,11 @@ namespace Light {
static inline void LoadTexture(const std::string& name, const std::string& path, unsigned int desiredComponents = 4u) { s_Context->LoadTextureImpl(name, path, desiredComponents); } static inline void LoadTexture(const std::string& name, const std::string& path, unsigned int desiredComponents = 4u) { s_Context->LoadTextureImpl(name, path, desiredComponents); }
static inline std::shared_ptr<Shader> GetShader(const std::string& name) { return s_Context->m_Shaders[name]; } static inline Ref<Shader> GetShader(const std::string& name) { return s_Context->m_Shaders[name]; }
static inline std::shared_ptr<Texture> GetTexture(const std::string& name) { return s_Context->m_Textures[name]; } static inline Ref<Texture> GetTexture(const std::string& name) { return s_Context->m_Textures[name]; }
private: private:
ResourceManager(std::shared_ptr<SharedContext> sharedContext); ResourceManager(Ref<SharedContext> sharedContext);
void CreateShaderImpl(const std::string& name, const std::string& vertexSource, const std::string& pixelSource); void CreateShaderImpl(const std::string& name, const std::string& vertexSource, const std::string& pixelSource);
void LoadShaderImpl(const std::string& name, const std::string& vertexPath, const std::string& pixelPath); void LoadShaderImpl(const std::string& name, const std::string& vertexPath, const std::string& pixelPath);

View file

@ -5,7 +5,7 @@
namespace Light { namespace Light {
dxBlender::dxBlender(std::shared_ptr<dxSharedContext> sharedContext) dxBlender::dxBlender(Ref<dxSharedContext> sharedContext)
: m_Context(sharedContext) : m_Context(sharedContext)
{ {
// factor map // factor map

View file

@ -13,7 +13,7 @@ namespace Light {
class dxBlender : public Blender class dxBlender : public Blender
{ {
private: private:
std::shared_ptr<dxSharedContext> m_Context; Ref<dxSharedContext> m_Context;
std::unordered_map<BlendFactor, D3D11_BLEND> m_FactorMap; std::unordered_map<BlendFactor, D3D11_BLEND> m_FactorMap;
Microsoft::WRL::ComPtr<ID3D11BlendState> m_BlendState; Microsoft::WRL::ComPtr<ID3D11BlendState> m_BlendState;
@ -21,7 +21,7 @@ namespace Light {
D3D11_BLEND_DESC m_Desc; D3D11_BLEND_DESC m_Desc;
public: public:
dxBlender(std::shared_ptr<dxSharedContext> sharedContext); dxBlender(Ref<dxSharedContext> sharedContext);
void Enable(BlendFactor srcFactor, BlendFactor dstFactor) override; void Enable(BlendFactor srcFactor, BlendFactor dstFactor) override;
void Disable() override; void Disable() override;

View file

@ -5,7 +5,7 @@
namespace Light { namespace Light {
dxConstantBuffer::dxConstantBuffer(ConstantBufferIndex index, unsigned int size, std::shared_ptr<dxSharedContext> sharedContext) dxConstantBuffer::dxConstantBuffer(ConstantBufferIndex index, unsigned int size, Ref<dxSharedContext> sharedContext)
: m_Context(sharedContext), m_Index((int)index) : m_Context(sharedContext), m_Index((int)index)
{ {
D3D11_BUFFER_DESC bufferDesc = { }; D3D11_BUFFER_DESC bufferDesc = { };
@ -38,7 +38,7 @@ namespace Light {
} }
//* VERTEX_BUFFER *// //* VERTEX_BUFFER *//
dxVertexBuffer::dxVertexBuffer(float* vertices, unsigned int stride, unsigned int count, std::shared_ptr<dxSharedContext> sharedContext) dxVertexBuffer::dxVertexBuffer(float* vertices, unsigned int stride, unsigned int count, Ref<dxSharedContext> sharedContext)
: m_Stride(stride), m_Context(sharedContext) : m_Stride(stride), m_Context(sharedContext)
{ {
// buffer desc // buffer desc
@ -87,7 +87,7 @@ namespace Light {
} }
//* INDEX_BUFFER *// //* INDEX_BUFFER *//
dxIndexBuffer::dxIndexBuffer(unsigned int* indices, unsigned int count, std::shared_ptr<dxSharedContext> sharedContext) dxIndexBuffer::dxIndexBuffer(unsigned int* indices, unsigned int count, Ref<dxSharedContext> sharedContext)
: m_Context(sharedContext) : m_Context(sharedContext)
{ {
// generate indices if not provided // generate indices if not provided

View file

@ -14,7 +14,7 @@ namespace Light {
class dxConstantBuffer : public ConstantBuffer class dxConstantBuffer : public ConstantBuffer
{ {
private: private:
std::shared_ptr<dxSharedContext> m_Context; Ref<dxSharedContext> m_Context;
Microsoft::WRL::ComPtr<ID3D11Buffer> m_Buffer; Microsoft::WRL::ComPtr<ID3D11Buffer> m_Buffer;
D3D11_MAPPED_SUBRESOURCE m_Map; D3D11_MAPPED_SUBRESOURCE m_Map;
@ -22,7 +22,7 @@ namespace Light {
unsigned int m_Index; unsigned int m_Index;
public: public:
dxConstantBuffer(ConstantBufferIndex index, unsigned int size, std::shared_ptr<dxSharedContext> sharedContext); dxConstantBuffer(ConstantBufferIndex index, unsigned int size, Ref<dxSharedContext> sharedContext);
void Bind() override; void Bind() override;
@ -34,7 +34,7 @@ namespace Light {
class dxVertexBuffer : public VertexBuffer class dxVertexBuffer : public VertexBuffer
{ {
private: private:
std::shared_ptr<dxSharedContext> m_Context; Ref<dxSharedContext> m_Context;
Microsoft::WRL::ComPtr<ID3D11Buffer> m_Buffer; Microsoft::WRL::ComPtr<ID3D11Buffer> m_Buffer;
D3D11_MAPPED_SUBRESOURCE m_Map; D3D11_MAPPED_SUBRESOURCE m_Map;
@ -42,7 +42,7 @@ namespace Light {
unsigned int m_Stride; unsigned int m_Stride;
public: public:
dxVertexBuffer(float* vertices, unsigned int stride, unsigned int count, std::shared_ptr<dxSharedContext> sharedContext); dxVertexBuffer(float* vertices, unsigned int stride, unsigned int count, Ref<dxSharedContext> sharedContext);
~dxVertexBuffer(); ~dxVertexBuffer();
void* Map() override; void* Map() override;
@ -56,12 +56,12 @@ namespace Light {
class dxIndexBuffer : public IndexBuffer class dxIndexBuffer : public IndexBuffer
{ {
private: private:
std::shared_ptr<dxSharedContext> m_Context; Ref<dxSharedContext> m_Context;
Microsoft::WRL::ComPtr<ID3D11Buffer> m_Buffer; Microsoft::WRL::ComPtr<ID3D11Buffer> m_Buffer;
public: public:
dxIndexBuffer(unsigned int* indices, unsigned int count, std::shared_ptr<dxSharedContext> sharedContext); dxIndexBuffer(unsigned int* indices, unsigned int count, Ref<dxSharedContext> sharedContext);
~dxIndexBuffer(); ~dxIndexBuffer();
void Bind() override; void Bind() override;

View file

@ -4,7 +4,7 @@
namespace Light { namespace Light {
dxFramebuffer::dxFramebuffer(const FramebufferSpecification& specification, std::shared_ptr<dxSharedContext> sharedContext) dxFramebuffer::dxFramebuffer(const FramebufferSpecification& specification, Ref<dxSharedContext> sharedContext)
: m_Specification(specification), m_Context(sharedContext) : m_Specification(specification), m_Context(sharedContext)
{ {
HRESULT hr; HRESULT hr;

View file

@ -13,7 +13,7 @@ namespace Light {
class dxFramebuffer : public Framebuffer class dxFramebuffer : public Framebuffer
{ {
private: private:
std::shared_ptr<dxSharedContext> m_Context; Ref<dxSharedContext> m_Context;
FramebufferSpecification m_Specification; FramebufferSpecification m_Specification;
@ -24,7 +24,7 @@ namespace Light {
Microsoft::WRL::ComPtr<ID3D11DepthStencilView> m_DepthStencilView; Microsoft::WRL::ComPtr<ID3D11DepthStencilView> m_DepthStencilView;
public: public:
dxFramebuffer(const FramebufferSpecification& specification, std::shared_ptr<dxSharedContext> sharedContext); dxFramebuffer(const FramebufferSpecification& specification, Ref<dxSharedContext> sharedContext);
inline void* GetColorAttachment() override { return (void*)m_ResourceView.Get(); } inline void* GetColorAttachment() override { return (void*)m_ResourceView.Get(); }

View file

@ -32,7 +32,7 @@ namespace Light {
void dxGraphicsContext::SetupDeviceAndSwapChain(GLFWwindow* windowHandle) void dxGraphicsContext::SetupDeviceAndSwapChain(GLFWwindow* windowHandle)
{ {
std::shared_ptr<dxSharedContext> context = std::static_pointer_cast<dxSharedContext>(m_SharedContext); Ref<dxSharedContext> context = std::static_pointer_cast<dxSharedContext>(m_SharedContext);
// swap chain desc // swap chain desc
DXGI_SWAP_CHAIN_DESC sd = { 0 }; DXGI_SWAP_CHAIN_DESC sd = { 0 };
@ -87,7 +87,7 @@ namespace Light {
void dxGraphicsContext::SetupRenderTargets() void dxGraphicsContext::SetupRenderTargets()
{ {
std::shared_ptr<dxSharedContext> context = std::static_pointer_cast<dxSharedContext>(m_SharedContext); Ref<dxSharedContext> context = std::static_pointer_cast<dxSharedContext>(m_SharedContext);
// set primitive topology // set primitive topology
context->GetDeviceContext()->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST); context->GetDeviceContext()->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
@ -106,7 +106,7 @@ namespace Light {
void dxGraphicsContext::SetupDebugInterface() void dxGraphicsContext::SetupDebugInterface()
{ {
#ifdef LIGHT_DEBUG #ifdef LIGHT_DEBUG
std::shared_ptr<dxSharedContext> context = std::static_pointer_cast<dxSharedContext>(m_SharedContext); Ref<dxSharedContext> context = std::static_pointer_cast<dxSharedContext>(m_SharedContext);
HRESULT hr; HRESULT hr;
Microsoft::WRL::ComPtr<ID3D11Debug> debugInterface = nullptr; Microsoft::WRL::ComPtr<ID3D11Debug> debugInterface = nullptr;
@ -134,7 +134,7 @@ namespace Light {
void dxGraphicsContext::LogDebugData() void dxGraphicsContext::LogDebugData()
{ {
std::shared_ptr<dxSharedContext> context = std::static_pointer_cast<dxSharedContext>(m_SharedContext); Ref<dxSharedContext> context = std::static_pointer_cast<dxSharedContext>(m_SharedContext);
// locals // locals
IDXGIDevice* DXGIDevice; IDXGIDevice* DXGIDevice;

View file

@ -4,7 +4,7 @@
namespace Light { namespace Light {
dxRenderCommand::dxRenderCommand(std::shared_ptr<dxSharedContext> sharedContext) dxRenderCommand::dxRenderCommand(Ref<dxSharedContext> sharedContext)
: m_Context(sharedContext) : m_Context(sharedContext)
{ } { }

View file

@ -13,10 +13,10 @@ namespace Light {
class dxRenderCommand : public RenderCommand class dxRenderCommand : public RenderCommand
{ {
private: private:
std::shared_ptr<dxSharedContext> m_Context; Ref<dxSharedContext> m_Context;
public: public:
dxRenderCommand(std::shared_ptr<dxSharedContext> sharedContext); dxRenderCommand(Ref<dxSharedContext> sharedContext);
virtual void SwapBuffers() override; virtual void SwapBuffers() override;
virtual void ClearBackBuffer(const glm::vec4& clearColor) override; virtual void ClearBackBuffer(const glm::vec4& clearColor) override;

View file

@ -6,7 +6,7 @@
namespace Light { namespace Light {
dxShader::dxShader(const std::string& vertexSource, const std::string& pixelSource, std::shared_ptr<dxSharedContext> sharedContext) dxShader::dxShader(const std::string& vertexSource, const std::string& pixelSource, Ref<dxSharedContext> sharedContext)
: m_Context(sharedContext) : m_Context(sharedContext)
{ {
Microsoft::WRL::ComPtr<ID3DBlob> ps = nullptr, vsErr = nullptr, psErr = nullptr; Microsoft::WRL::ComPtr<ID3DBlob> ps = nullptr, vsErr = nullptr, psErr = nullptr;

View file

@ -15,7 +15,7 @@ namespace Light {
class dxShader : public Shader class dxShader : public Shader
{ {
private: private:
std::shared_ptr<dxSharedContext> m_Context; Ref<dxSharedContext> m_Context;
Microsoft::WRL::ComPtr<ID3D11VertexShader> m_VertexShader; Microsoft::WRL::ComPtr<ID3D11VertexShader> m_VertexShader;
Microsoft::WRL::ComPtr<ID3D11PixelShader> m_PixelShader; Microsoft::WRL::ComPtr<ID3D11PixelShader> m_PixelShader;
@ -23,7 +23,7 @@ namespace Light {
Microsoft::WRL::ComPtr<ID3DBlob> m_VertexBlob; Microsoft::WRL::ComPtr<ID3DBlob> m_VertexBlob;
public: public:
dxShader(const std::string& vertexSource, const std::string& pixelSource, std::shared_ptr<dxSharedContext> sharedContext); dxShader(const std::string& vertexSource, const std::string& pixelSource, Ref<dxSharedContext> sharedContext);
~dxShader(); ~dxShader();
void Bind() override; void Bind() override;

View file

@ -4,7 +4,7 @@
namespace Light { namespace Light {
dxTexture::dxTexture(unsigned int width, unsigned int height, unsigned int components, unsigned char* pixels, std::shared_ptr<dxSharedContext> sharedContext) dxTexture::dxTexture(unsigned int width, unsigned int height, unsigned int components, unsigned char* pixels, Ref<dxSharedContext> sharedContext)
: m_Context(sharedContext) : m_Context(sharedContext)
{ {
// texture desc // texture desc

View file

@ -13,14 +13,14 @@ namespace Light {
class dxTexture : public Texture class dxTexture : public Texture
{ {
private: private:
std::shared_ptr<dxSharedContext> m_Context; Ref<dxSharedContext> m_Context;
Microsoft::WRL::ComPtr<ID3D11Texture2D> m_Texture; Microsoft::WRL::ComPtr<ID3D11Texture2D> m_Texture;
Microsoft::WRL::ComPtr<ID3D11ShaderResourceView> m_ResourceView; Microsoft::WRL::ComPtr<ID3D11ShaderResourceView> m_ResourceView;
Microsoft::WRL::ComPtr<ID3D11SamplerState> m_SamplerState; Microsoft::WRL::ComPtr<ID3D11SamplerState> m_SamplerState;
public: public:
dxTexture(unsigned int width, unsigned int height, unsigned int components, unsigned char* pixels, std::shared_ptr<dxSharedContext> sharedContext); dxTexture(unsigned int width, unsigned int height, unsigned int components, unsigned char* pixels, Ref<dxSharedContext> sharedContext);
void Bind(unsigned int slot = 0u) override; void Bind(unsigned int slot = 0u) override;
}; };

View file

@ -12,7 +12,7 @@
namespace Light { namespace Light {
dxUserInterface::dxUserInterface(GLFWwindow* windowHandle, std::shared_ptr<dxSharedContext> sharedContext) dxUserInterface::dxUserInterface(GLFWwindow* windowHandle, Ref<dxSharedContext> sharedContext)
{ {
// create context // create context
IMGUI_CHECKVERSION(); IMGUI_CHECKVERSION();

View file

@ -15,7 +15,7 @@ namespace Light {
class dxUserInterface : public UserInterface class dxUserInterface : public UserInterface
{ {
public: public:
dxUserInterface(GLFWwindow* windowHandle, std::shared_ptr<dxSharedContext> sharedContext); dxUserInterface(GLFWwindow* windowHandle, Ref<dxSharedContext> sharedContext);
~dxUserInterface(); ~dxUserInterface();
void Begin() override; void Begin() override;

View file

@ -6,7 +6,7 @@
namespace Light { namespace Light {
dxVertexLayout::dxVertexLayout(std::shared_ptr<Shader> shader, const std::vector<std::pair<std::string, VertexElementType>>& elements, std::shared_ptr<dxSharedContext> sharedContext) dxVertexLayout::dxVertexLayout(Ref<Shader> shader, const std::vector<std::pair<std::string, VertexElementType>>& elements, Ref<dxSharedContext> sharedContext)
: m_Context(sharedContext) : m_Context(sharedContext)
{ {
// occupy space for input elements // occupy space for input elements
@ -26,7 +26,7 @@ namespace Light {
0u }); 0u });
} }
std::shared_ptr<dxShader> dxpShader = std::dynamic_pointer_cast<dxShader>(shader); Ref<dxShader> dxpShader = std::dynamic_pointer_cast<dxShader>(shader);
LT_ENGINE_ASSERT(dxpShader, "dxVertexLayout::dxVertexLayout: failed to cast 'Shader' to 'dxShader'"); LT_ENGINE_ASSERT(dxpShader, "dxVertexLayout::dxVertexLayout: failed to cast 'Shader' to 'dxShader'");
// create input layout (vertex layout) // create input layout (vertex layout)

View file

@ -14,12 +14,12 @@ namespace Light {
class dxVertexLayout : public VertexLayout class dxVertexLayout : public VertexLayout
{ {
private: private:
std::shared_ptr<dxSharedContext> m_Context; Ref<dxSharedContext> m_Context;
Microsoft::WRL::ComPtr<ID3D11InputLayout> m_InputLayout; Microsoft::WRL::ComPtr<ID3D11InputLayout> m_InputLayout;
public: public:
dxVertexLayout(std::shared_ptr<Shader> shader, const std::vector<std::pair<std::string, VertexElementType>>& elements, std::shared_ptr<dxSharedContext> sharedContext); dxVertexLayout(Ref<Shader> shader, const std::vector<std::pair<std::string, VertexElementType>>& elements, Ref<dxSharedContext> sharedContext);
~dxVertexLayout(); ~dxVertexLayout();
void Bind() override; void Bind() override;

View file

@ -7,7 +7,7 @@
namespace Light { namespace Light {
glVertexLayout::glVertexLayout(std::shared_ptr<VertexBuffer> buffer, const std::vector<std::pair<std::string, VertexElementType>>& elements) glVertexLayout::glVertexLayout(Ref<VertexBuffer> buffer, const std::vector<std::pair<std::string, VertexElementType>>& elements)
{ {
// check // check
LT_ENGINE_ASSERT(std::dynamic_pointer_cast<glVertexBuffer>(buffer), "glVertexLayout::glVertexLayout: failed to cast 'VertexBuffer' to 'glVertexBuffer'"); LT_ENGINE_ASSERT(std::dynamic_pointer_cast<glVertexBuffer>(buffer), "glVertexLayout::glVertexLayout: failed to cast 'VertexBuffer' to 'glVertexBuffer'");

View file

@ -19,7 +19,7 @@ namespace Light {
unsigned int m_ArrayID; unsigned int m_ArrayID;
public: public:
glVertexLayout(std::shared_ptr<VertexBuffer> buffer, const std::vector<std::pair<std::string, VertexElementType>>& elements); glVertexLayout(Ref<VertexBuffer> buffer, const std::vector<std::pair<std::string, VertexElementType>>& elements);
~glVertexLayout(); ~glVertexLayout();
void Bind() override; void Bind() override;

View file

@ -12,9 +12,9 @@
namespace Light { namespace Light {
Window* Window::Create(std::function<void(Event&)> callback) Scope<Window> Window::Create(std::function<void(Event&)> callback)
{ {
return new lWindow(callback); return CreateScope<lWindow>(callback);
} }
lWindow::lWindow(std::function<void(Event&)> callback) lWindow::lWindow(std::function<void(Event&)> callback)
@ -37,7 +37,7 @@ namespace Light {
BindGlfwEvents(); BindGlfwEvents();
// create graphics contextG // create graphics contextG
m_GraphicsContext = std::unique_ptr<GraphicsContext>(GraphicsContext::Create(GraphicsAPI::OpenGL, m_Handle)); m_GraphicsContext = GraphicsContext::Create(GraphicsAPI::OpenGL, m_Handle);
LT_ENGINE_ASSERT(m_GraphicsContext, "lWindow::lWindow: failed to create 'GraphicsContext'"); LT_ENGINE_ASSERT(m_GraphicsContext, "lWindow::lWindow: failed to create 'GraphicsContext'");
} }

View file

@ -12,9 +12,9 @@
namespace Light { namespace Light {
Window* Window::Create(std::function<void(Event&)> callback) Scope<Window> Window::Create(std::function<void(Event&)> callback)
{ {
return new wWindow(callback); return CreateScope<wWindow>(callback);
} }
wWindow::wWindow(std::function<void(Event&)> callback) wWindow::wWindow(std::function<void(Event&)> callback)
@ -37,7 +37,7 @@ namespace Light {
BindGlfwEvents(); BindGlfwEvents();
// create graphics context // create graphics context
m_GraphicsContext = std::unique_ptr<GraphicsContext>(GraphicsContext::Create(GraphicsAPI::DirectX, m_Handle)); m_GraphicsContext = GraphicsContext::Create(GraphicsAPI::DirectX, m_Handle);
LT_ENGINE_ASSERT(m_GraphicsContext, "wWindow::wWindow: failed to create 'GraphicsContext'"); LT_ENGINE_ASSERT(m_GraphicsContext, "wWindow::wWindow: failed to create 'GraphicsContext'");
} }

View file

@ -13,7 +13,6 @@ namespace Light {
class wWindow : public Window class wWindow : public Window
{ {
private: private:
// #todo: don't handle Windows's window with glfw, create an HWND
GLFWwindow* m_Handle = nullptr; GLFWwindow* m_Handle = nullptr;
std::function<void(Event&)> m_EventCallback; std::function<void(Event&)> m_EventCallback;

View file

@ -22,7 +22,7 @@ namespace Light {
m_Window->SetProperties(properties); m_Window->SetProperties(properties);
// Attach the sandbox layer // Attach the sandbox layer
LayerStack::AttachLayer(new MirrorLayer("MirrorLayer")); LayerStack::AttachLayer<MirrorLayer>(("MirrorLayer"));
} }
~Mirror() ~Mirror()

View file

@ -13,9 +13,9 @@ namespace Light {
glm::vec2 m_Direction; glm::vec2 m_Direction;
float m_Speed = 1000.0f; float m_Speed = 1000.0f;
std::shared_ptr<Camera> m_Camera; Ref<Camera> m_Camera;
std::shared_ptr<Framebuffer> m_Framebuffer; Ref<Framebuffer> m_Framebuffer;
Scene m_Scene; Scene m_Scene;

View file

@ -11,7 +11,7 @@ private:
glm::vec2 m_Direction; glm::vec2 m_Direction;
float m_Speed = 1.2f; float m_Speed = 1.2f;
std::shared_ptr<Light::Camera> m_Camera; Light::Ref<Light::Camera> m_Camera;
public: public:
SandboxLayer(const std::string& name) SandboxLayer(const std::string& name)