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
#ifndef LOGGER_H
#include "Debug/Logger.h"
#endif
#include "Debug/Exceptions.h"
#include "Utility/Stringifier.h"
#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
#define LT_WIN(x) // windows
#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__); } }
#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 ] ***///
//** PORTABLE_DEBUG_BREAK **//
// copied from: https://github.com/nemequ/portable-snippets/tree/master/debug-trap
@ -157,3 +150,11 @@ namespace Light {
//** PORTABLE_DEBUG_BREAK **//
///*** [ 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()
{
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_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()
@ -59,7 +61,7 @@ namespace Light {
// update layers
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());
}
@ -68,7 +70,7 @@ namespace Light {
LT_PROFILE_SCOPE("GameLoop::Render");
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();
m_Window->GetGfxContext()->GetRenderer()->EndFrame();
@ -79,7 +81,7 @@ namespace Light {
LT_PROFILE_SCOPE("GameLoop::UserInterface");
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();
m_Window->GetGfxContext()->GetUserInterface()->End();
@ -112,14 +114,14 @@ namespace Light {
// input
if (event.HasCategory(InputEventCategory))
m_Input.OnEvent(event);
m_Input->OnEvent(event);
// layers
// 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;
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;
}

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -38,7 +38,7 @@ namespace Light {
private:
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 Disable() = 0;

View file

@ -14,32 +14,32 @@
namespace Light {
//* 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())
{
case GraphicsAPI::OpenGL:
return new glConstantBuffer(index, size);
return CreateScope<glConstantBuffer>(index, size);
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:
LT_ENGINE_ASSERT(false, "VertexBuffer::Create: invalid/unsupported 'GraphicsAPI' {}", GraphicsContext::GetGraphicsAPI());
LT_ENGINE_ASSERT(false, "ConstantBuffer::Create: invalid/unsupported 'GraphicsAPI' {}", GraphicsContext::GetGraphicsAPI());
return nullptr;
}
}
//* 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())
{
case GraphicsAPI::OpenGL:
return new glVertexBuffer(vertices, count);
return CreateRef<glVertexBuffer>(vertices, count);
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:
LT_ENGINE_ASSERT(false, "VertexBuffer::Create: invalid/unsupported 'GraphicsAPI' {}", GraphicsContext::GetGraphicsAPI());
@ -48,15 +48,15 @@ namespace Light {
}
//* 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())
{
case GraphicsAPI::OpenGL:
return new glIndexBuffer(indices, count);
return CreateRef<glIndexBuffer>(indices, count);
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:
LT_ENGINE_ASSERT(false, "IndexBuffer::Create: invalid/unsupported 'GraphicsAPI' {}", GraphicsContext::GetGraphicsAPI());

View file

@ -15,19 +15,22 @@ namespace Light {
class ConstantBuffer
{
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* Map() = 0;
virtual void UnMap() = 0;
protected:
ConstantBuffer() = default;
};
//* VERTEX_BUFFER *//
class VertexBuffer
{
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;
@ -45,7 +48,7 @@ namespace Light {
class IndexBuffer
{
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;

View file

@ -11,15 +11,15 @@
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())
{
case GraphicsAPI::OpenGL:
return new glFramebuffer(specification);
return CreateRef<glFramebuffer>(specification);
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:
LT_ENGINE_ASSERT(false, "Shader::Create: invalid/unsupported 'GraphicsAPI' {}", GraphicsContext::GetGraphicsAPI());

View file

@ -21,7 +21,7 @@ namespace Light {
class Framebuffer
{
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;

View file

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

View file

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

View file

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

View file

@ -13,7 +13,7 @@ namespace Light {
class RenderCommand
{
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& operator=(const RenderCommand&) = delete;

View file

@ -19,24 +19,24 @@ namespace Light {
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_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!");
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);
}
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)
@ -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
texture->Bind();
@ -125,7 +125,7 @@ namespace Light {
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;

View file

@ -39,24 +39,24 @@ namespace Light {
TextureRendererProgram m_TextureRenderer;
// constant buffers
std::unique_ptr<ConstantBuffer> m_ViewProjectionBuffer;
Scope<ConstantBuffer> m_ViewProjectionBuffer;
std::unique_ptr<RenderCommand> m_RenderCommand;
std::unique_ptr<Blender> m_Blender;
Scope<RenderCommand> m_RenderCommand;
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:
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, 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(); }
void OnWindowResize(const WindowResizedEvent& event);
@ -65,14 +65,14 @@ namespace Light {
void EndFrame();
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, 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 EndSceneImpl();
};

View file

@ -11,15 +11,15 @@
namespace Light {
QuadRendererProgram::QuadRendererProgram(unsigned int maxVertices, std::shared_ptr<SharedContext> sharedContext)
QuadRendererProgram::QuadRendererProgram(unsigned int maxVertices, Ref<SharedContext> sharedContext)
: m_MaxVertices(maxVertices)
{
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_VertexBuffer = std::shared_ptr<VertexBuffer>(VertexBuffer::Create(nullptr, sizeof(QuadVertexData), maxVertices, sharedContext));
m_IndexBuffer = std::shared_ptr<IndexBuffer>(IndexBuffer::Create(nullptr, (maxVertices / 4) * 6, sharedContext));
m_VertexLayout = std::shared_ptr<VertexLayout>(VertexLayout::Create(m_VertexBuffer, m_Shader, { { "POSITION", VertexElementType::Float3 },
m_VertexBuffer = Ref<VertexBuffer>(VertexBuffer::Create(nullptr, sizeof(QuadVertexData), maxVertices, sharedContext));
m_IndexBuffer = Ref<IndexBuffer>(IndexBuffer::Create(nullptr, (maxVertices / 4) * 6, sharedContext));
m_VertexLayout = Ref<VertexLayout>(VertexLayout::Create(m_VertexBuffer, m_Shader, { { "POSITION", VertexElementType::Float3 },
{ "COLOR" , VertexElementType::Float4 }}, sharedContext));
}

View file

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

View file

@ -11,15 +11,15 @@
namespace Light {
TextureRendererProgram::TextureRendererProgram(unsigned int maxVertices, std::shared_ptr<SharedContext> sharedContext)
TextureRendererProgram::TextureRendererProgram(unsigned int maxVertices, Ref<SharedContext> sharedContext)
: m_MaxVertices(maxVertices)
{
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_VertexBuffer = std::shared_ptr<VertexBuffer>(VertexBuffer::Create(nullptr, sizeof(TextureVertexData), maxVertices, sharedContext));
m_IndexBuffer = std::shared_ptr<IndexBuffer>(IndexBuffer::Create(nullptr, (maxVertices / 4) * 6, sharedContext));
m_VertexLayout = std::shared_ptr<VertexLayout>(VertexLayout::Create(m_VertexBuffer, m_Shader, { { "POSITION", VertexElementType::Float3 },
m_VertexBuffer = Ref<VertexBuffer>(VertexBuffer::Create(nullptr, sizeof(TextureVertexData), maxVertices, sharedContext));
m_IndexBuffer = Ref<IndexBuffer>(IndexBuffer::Create(nullptr, (maxVertices / 4) * 6, sharedContext));
m_VertexLayout = Ref<VertexLayout>(VertexLayout::Create(m_VertexBuffer, m_Shader, { { "POSITION", VertexElementType::Float3 },
{ "TEXCOORD", VertexElementType::Float2 }}, sharedContext));
}

View file

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

View file

@ -11,16 +11,16 @@
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
switch (GraphicsContext::GetGraphicsAPI())
{
case GraphicsAPI::OpenGL:
return new glShader(vertexSource, pixelSource);
return CreateRef<glShader>(vertexSource, pixelSource);
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:
LT_ENGINE_ASSERT(false, "Shader::Create: invalid/unsupported 'GraphicsAPI' {}", GraphicsContext::GetGraphicsAPI());

View file

@ -11,14 +11,13 @@ namespace Light {
class Shader
{
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 void Bind() = 0;
virtual void UnBind() = 0;
//** #TEMP_SHADER_UNIFORMS_TEMP# **//
virtual void SetUniformMat4(const std::string& name, const glm::mat4& value) = 0;

View file

@ -11,15 +11,15 @@
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())
{
case GraphicsAPI::OpenGL:
return new glTexture(width, height, components, pixels);
return CreateRef<glTexture>(width, height, components, pixels);
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:
LT_ENGINE_ASSERT(false, "Texture::Create: invalid/unsupported 'GraphicsAPI' {}", GraphicsContext::GetGraphicsAPI());

View file

@ -10,7 +10,7 @@ namespace Light {
class Texture
{
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& operator=(const Texture&) = delete;

View file

@ -11,15 +11,15 @@
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())
{
case GraphicsAPI::OpenGL:
return new glVertexLayout(vertexBuffer, elements);
return CreateRef<glVertexLayout>(vertexBuffer, elements);
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:
LT_ENGINE_ASSERT(false, "VertexLayout::Create: invalid/unsupported 'GraphicsAPI' {}", GraphicsContext::GetGraphicsAPI());

View file

@ -20,7 +20,7 @@ namespace Light {
class VertexLayout
{
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;;

View file

@ -11,6 +11,11 @@ namespace Light {
Input* Input::s_Context = nullptr;
Scope<Input> Input::Create()
{
return MakeScope(new Input);
}
Input::Input()
{
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_GameEvents = true;
public:
Input();
static Scope<Input> Create();
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); }
@ -39,6 +39,8 @@ namespace Light {
inline bool IsReceivingGameEvents() const { return m_GameEvents; }
private:
Input();
void ReceiveUserInterfaceEventsImpl(bool receive, bool toggle = false);
void ReceieveGameEventsImpl(bool receive, bool toggle = false);

View file

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

View file

@ -12,6 +12,11 @@ namespace Light {
LayerStack* LayerStack::s_Context = nullptr;
Scope<LayerStack> LayerStack::Create()
{
return MakeScope<LayerStack>(new LayerStack());
}
LayerStack::LayerStack()
{
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;
public:
LayerStack();
static Scope<LayerStack> Create();
~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 DetachLayer(Layer* layer) { s_Context->DetachLayerImpl(layer); }
@ -32,6 +37,8 @@ namespace Light {
std::vector<Layer*>::reverse_iterator rend() { return m_Layers.rend(); }
private:
LayerStack();
void AttachLayerImpl(Layer* layer);
void DetachLayerImpl(Layer* layer);
};

View file

@ -8,6 +8,7 @@ namespace Light {
class Texture;
// #todo: store a mat4 for transform
struct TransformComponent
{
glm::vec2 position, size;
@ -24,13 +25,13 @@ namespace Light {
struct SpriteRendererComponent
{
std::shared_ptr<Texture> texture;
Ref<Texture> texture;
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 {
UserInterface* UserInterface::Create(GLFWwindow* windowHandle, std::shared_ptr<SharedContext> sharedContext)
Scope<UserInterface> UserInterface::Create(GLFWwindow* windowHandle, Ref<SharedContext> sharedContext)
{
switch (GraphicsContext::GetGraphicsAPI())
{
case GraphicsAPI::OpenGL:
return new glUserInterface(windowHandle);
return CreateScope<glUserInterface>(windowHandle);
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:
LT_ENGINE_ASSERT(false, "UserInterface::Create: invalid/unsupported 'GraphicsAPI' {}", GraphicsContext::GetGraphicsAPI());

View file

@ -12,7 +12,7 @@ namespace Light {
class UserInterface
{
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& operator=(const UserInterface&) = delete;

View file

@ -11,12 +11,12 @@ namespace Light {
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)
{
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);
// 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)
@ -70,7 +70,7 @@ namespace Light {
psSS << line << '\n';
// 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 */)
@ -88,7 +88,7 @@ namespace Light {
}
// 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)

View file

@ -15,13 +15,13 @@ namespace Light {
private:
static ResourceManager* s_Context;
std::unordered_map<std::string, std::shared_ptr<Shader>> m_Shaders;
std::unordered_map<std::string, std::shared_ptr<Texture>> m_Textures;
std::unordered_map<std::string, Ref<Shader>> m_Shaders;
std::unordered_map<std::string, Ref<Texture>> m_Textures;
std::shared_ptr<SharedContext> m_SharedContext;
Ref<SharedContext> m_SharedContext;
public:
static ResourceManager* Create(std::shared_ptr<SharedContext> sharedContext);
static Scope<ResourceManager> Create(Ref<SharedContext> sharedContext);
// #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); }
@ -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 std::shared_ptr<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<Shader> GetShader(const std::string& name) { return s_Context->m_Shaders[name]; }
static inline Ref<Texture> GetTexture(const std::string& name) { return s_Context->m_Textures[name]; }
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 LoadShaderImpl(const std::string& name, const std::string& vertexPath, const std::string& pixelPath);

View file

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

View file

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

View file

@ -5,7 +5,7 @@
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)
{
D3D11_BUFFER_DESC bufferDesc = { };
@ -38,7 +38,7 @@ namespace Light {
}
//* 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)
{
// buffer desc
@ -87,7 +87,7 @@ namespace Light {
}
//* 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)
{
// generate indices if not provided

View file

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

View file

@ -4,7 +4,7 @@
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)
{
HRESULT hr;

View file

@ -13,7 +13,7 @@ namespace Light {
class dxFramebuffer : public Framebuffer
{
private:
std::shared_ptr<dxSharedContext> m_Context;
Ref<dxSharedContext> m_Context;
FramebufferSpecification m_Specification;
@ -24,7 +24,7 @@ namespace Light {
Microsoft::WRL::ComPtr<ID3D11DepthStencilView> m_DepthStencilView;
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(); }

View file

@ -32,7 +32,7 @@ namespace Light {
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
DXGI_SWAP_CHAIN_DESC sd = { 0 };
@ -87,7 +87,7 @@ namespace Light {
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
context->GetDeviceContext()->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
@ -106,7 +106,7 @@ namespace Light {
void dxGraphicsContext::SetupDebugInterface()
{
#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;
Microsoft::WRL::ComPtr<ID3D11Debug> debugInterface = nullptr;
@ -134,7 +134,7 @@ namespace Light {
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
IDXGIDevice* DXGIDevice;

View file

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

View file

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

View file

@ -6,7 +6,7 @@
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)
{
Microsoft::WRL::ComPtr<ID3DBlob> ps = nullptr, vsErr = nullptr, psErr = nullptr;

View file

@ -15,7 +15,7 @@ namespace Light {
class dxShader : public Shader
{
private:
std::shared_ptr<dxSharedContext> m_Context;
Ref<dxSharedContext> m_Context;
Microsoft::WRL::ComPtr<ID3D11VertexShader> m_VertexShader;
Microsoft::WRL::ComPtr<ID3D11PixelShader> m_PixelShader;
@ -23,7 +23,7 @@ namespace Light {
Microsoft::WRL::ComPtr<ID3DBlob> m_VertexBlob;
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();
void Bind() override;

View file

@ -4,7 +4,7 @@
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)
{
// texture desc

View file

@ -13,14 +13,14 @@ namespace Light {
class dxTexture : public Texture
{
private:
std::shared_ptr<dxSharedContext> m_Context;
Ref<dxSharedContext> m_Context;
Microsoft::WRL::ComPtr<ID3D11Texture2D> m_Texture;
Microsoft::WRL::ComPtr<ID3D11ShaderResourceView> m_ResourceView;
Microsoft::WRL::ComPtr<ID3D11SamplerState> m_SamplerState;
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;
};

View file

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

View file

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

View file

@ -6,7 +6,7 @@
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)
{
// occupy space for input elements
@ -26,7 +26,7 @@ namespace Light {
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'");
// create input layout (vertex layout)

View file

@ -14,12 +14,12 @@ namespace Light {
class dxVertexLayout : public VertexLayout
{
private:
std::shared_ptr<dxSharedContext> m_Context;
Ref<dxSharedContext> m_Context;
Microsoft::WRL::ComPtr<ID3D11InputLayout> m_InputLayout;
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();
void Bind() override;

View file

@ -7,7 +7,7 @@
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
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;
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();
void Bind() override;

View file

@ -12,9 +12,9 @@
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)
@ -37,7 +37,7 @@ namespace Light {
BindGlfwEvents();
// 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'");
}

View file

@ -12,9 +12,9 @@
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)
@ -37,7 +37,7 @@ namespace Light {
BindGlfwEvents();
// 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'");
}

View file

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

View file

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

View file

@ -13,9 +13,9 @@ namespace Light {
glm::vec2 m_Direction;
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;

View file

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