hachem.wtf
aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorhachem <im@hachem.wtf>2025-08-14 00:42:05 +0200
committerhachem <im@hachem.wtf>2025-08-14 00:42:05 +0200
commit0d8b874c0048ca088bb9e353a5f7c62e1f8cd0e8 (patch)
tree2c0f3b13161489e4e91994882f8f2ed67a20bc0e /src
parent9671d5e54484b8bce261207d08ff15053ae24e48 (diff)
feat: custom memory managers and fix includes
Diffstat (limited to 'src')
-rw-r--r--src/core/application.cpp8
-rw-r--r--src/core/application.h10
-rw-r--r--src/core/camera.cpp1
-rw-r--r--src/core/log.cpp7
-rw-r--r--src/core/log.h7
-rw-r--r--src/core/memory.h24
-rw-r--r--src/core/state_manager.cpp2
-rw-r--r--src/core/state_manager.h10
-rw-r--r--src/core/window.cpp2
-rw-r--r--src/core/window.h5
-rw-r--r--src/platform/opengl/opengl_renderer_api.cpp8
-rw-r--r--src/platform/opengl/opengl_renderer_api.h6
-rw-r--r--src/platform/opengl/opengl_shader.cpp2
-rw-r--r--src/platform/opengl/opengl_shader.h1
-rw-r--r--src/platform/opengl/opengl_texture.cpp5
-rw-r--r--src/platform/opengl/opengl_texture.h2
-rw-r--r--src/platform/opengl/opengl_vertex_array.cpp5
-rw-r--r--src/platform/opengl/opengl_vertex_array.h15
-rw-r--r--src/platform/vulkan/vulkan_renderer_api.cpp2
-rw-r--r--src/platform/vulkan/vulkan_renderer_api.h3
-rw-r--r--src/platform/vulkan/vulkan_vertex_array.cpp4
-rw-r--r--src/platform/vulkan/vulkan_vertex_array.h13
-rw-r--r--src/rendering/renderer.cpp13
-rw-r--r--src/rendering/renderer.h14
-rw-r--r--src/rendering/shader.cpp16
-rw-r--r--src/rendering/shader.h15
-rw-r--r--src/rendering/texture.cpp17
-rw-r--r--src/rendering/texture.h7
-rw-r--r--src/rendering/vertex_array.cpp1
-rw-r--r--src/rendering/vertex_array.h12
-rw-r--r--src/rendering/vertex_buffer.cpp1
-rw-r--r--src/states/simulation_state.cpp13
-rw-r--r--src/states/simulation_state.h17
33 files changed, 156 insertions, 112 deletions
diff --git a/src/core/application.cpp b/src/core/application.cpp
index b05e2b5..f2284cd 100644
--- a/src/core/application.cpp
+++ b/src/core/application.cpp
@@ -16,7 +16,7 @@ namespace Donut
{
s_instance = this;
- m_window = std::make_unique<Window>(name, width, height);
+ m_window = create_scope<Window>(name, width, height);
m_window->set_event_callback([this](Event& event)
{
on_event(event);
@@ -109,9 +109,9 @@ namespace Donut
Renderer::on_window_resize(1280, 720);
RenderCommand::set_face_culling(false);
- m_state_manager = std::make_unique<StateManager>();
- m_state_manager->register_state("Config", std::make_unique<ConfigState>());
- m_state_manager->register_state("Simulation", std::make_unique<SimulationState>());
+ m_state_manager = create_scope<StateManager>();
+ m_state_manager->register_state("Config", create_scope<ConfigState>());
+ m_state_manager->register_state("Simulation", create_scope<SimulationState>());
m_state_manager->switch_to_state("Config");
}
diff --git a/src/core/application.h b/src/core/application.h
index 326e541..048503b 100644
--- a/src/core/application.h
+++ b/src/core/application.h
@@ -1,12 +1,10 @@
#pragma once
-#include <memory>
-#include <functional>
-
+#include "memory.h"
#include "window.h"
#include "event.h"
-#include "state_manager.h"
#include "log.h"
+#include "state_manager.h"
namespace Donut
{
@@ -29,8 +27,8 @@ namespace Donut
void on_render();
void on_event(Event& event);
private:
- std::unique_ptr<StateManager> m_state_manager;
- std::unique_ptr<Window> m_window;
+ Scope<StateManager> m_state_manager;
+ Scope<Window> m_window;
bool m_running;
bool m_minimized;
diff --git a/src/core/camera.cpp b/src/core/camera.cpp
index 06866e4..f580191 100644
--- a/src/core/camera.cpp
+++ b/src/core/camera.cpp
@@ -1,4 +1,5 @@
#include "camera.h"
+
#include <glm/gtc/quaternion.hpp>
namespace Donut
diff --git a/src/core/log.cpp b/src/core/log.cpp
index ec031a5..0411e20 100644
--- a/src/core/log.cpp
+++ b/src/core/log.cpp
@@ -1,4 +1,5 @@
#include "log.h"
+
#include <filesystem>
#if defined(DONUT_WINDOWS)
@@ -7,11 +8,11 @@
namespace Donut
{
- std::shared_ptr<Logger> Logger::s_logger;
+ Ref<Logger> Logger::s_logger;
void Logger::init()
{
- s_logger = std::make_shared<Logger>();
+ s_logger = create_ref<Logger>();
s_logger->set_log_level(LogLevel::Info);
s_logger->enable_console_output(true);
s_logger->enable_file_output(true);
@@ -27,7 +28,7 @@ namespace Donut
s_logger.reset();
}
- std::shared_ptr<Logger> Logger::get_logger()
+ Ref<Logger> Logger::get_logger()
{
return s_logger;
}
diff --git a/src/core/log.h b/src/core/log.h
index 77324f5..1477226 100644
--- a/src/core/log.h
+++ b/src/core/log.h
@@ -1,7 +1,8 @@
#pragma once
+#include "core/memory.h"
+
#include <string>
-#include <memory>
#include <vector>
#include <sstream>
#include <iostream>
@@ -28,7 +29,7 @@ namespace Donut
static void init();
static void shutdown();
- static std::shared_ptr<Logger> get_logger();
+ static Ref<Logger> get_logger();
template<typename... Args>
static void trace(const std::string_view& format, const Args&... args)
@@ -135,7 +136,7 @@ namespace Donut
std::ofstream m_log_file;
std::mutex m_mutex;
- static std::shared_ptr<Logger> s_logger;
+ static Ref<Logger> s_logger;
};
}
diff --git a/src/core/memory.h b/src/core/memory.h
new file mode 100644
index 0000000..cbfbe82
--- /dev/null
+++ b/src/core/memory.h
@@ -0,0 +1,24 @@
+#pragma once
+
+#include <memory>
+
+namespace Donut
+{
+ template<typename T>
+ using Ref = std::shared_ptr<T>;
+
+ template<typename T>
+ using Scope = std::unique_ptr<T>;
+
+ template<typename T, typename ... Args>
+ constexpr Scope<T> create_scope(Args&& ... args)
+ {
+ return std::make_unique<T>(std::forward<Args>(args)...);
+ }
+
+ template<typename T, typename ... Args>
+ constexpr Ref<T> create_ref(Args&& ... args)
+ {
+ return std::make_shared<T>(std::forward<Args>(args)...);
+ }
+};
diff --git a/src/core/state_manager.cpp b/src/core/state_manager.cpp
index 5da601c..728df15 100644
--- a/src/core/state_manager.cpp
+++ b/src/core/state_manager.cpp
@@ -19,7 +19,7 @@ namespace Donut
m_current_state_name = "";
}
- void StateManager::register_state(const std::string& state_name, std::unique_ptr<State> state)
+ void StateManager::register_state(const std::string& state_name, Scope<State> state)
{
if (m_states.find(state_name) != m_states.end())
DONUT_WARN("State '{}' already exists, overwriting", state_name);
diff --git a/src/core/state_manager.h b/src/core/state_manager.h
index 7d5e734..469c48f 100644
--- a/src/core/state_manager.h
+++ b/src/core/state_manager.h
@@ -1,11 +1,11 @@
#pragma once
-#include <memory>
+#include "memory.h"
+#include "state.h"
+
#include <string>
#include <unordered_map>
-#include "state.h"
-
namespace Donut
{
class StateManager
@@ -18,7 +18,7 @@ namespace Donut
void render();
void on_event(Event& event);
- void register_state(const std::string& state_name, std::unique_ptr<State> state);
+ void register_state(const std::string& state_name, Scope<State> state);
void switch_to_state(const std::string& state_name);
std::string get_current_state_name() const { return m_current_state_name; }
@@ -34,6 +34,6 @@ namespace Donut
State* m_current_state = nullptr;
std::string m_current_state_name = "";
- std::unordered_map<std::string, std::unique_ptr<State>> m_states;
+ std::unordered_map<std::string, Scope<State>> m_states;
};
}
diff --git a/src/core/window.cpp b/src/core/window.cpp
index a32dddb..f598357 100644
--- a/src/core/window.cpp
+++ b/src/core/window.cpp
@@ -1,6 +1,6 @@
#include "window.h"
+
#include <cstdint>
-#include <iostream>
namespace Donut
{
diff --git a/src/core/window.h b/src/core/window.h
index ae79b6d..256f708 100644
--- a/src/core/window.h
+++ b/src/core/window.h
@@ -1,10 +1,11 @@
#pragma once
-#include <GLFW/glfw3.h>
-#include <string>
#include "event.h"
#include "log.h"
+#include <GLFW/glfw3.h>
+#include <string>
+
namespace Donut
{
class Window
diff --git a/src/platform/opengl/opengl_renderer_api.cpp b/src/platform/opengl/opengl_renderer_api.cpp
index 1d41735..4542231 100644
--- a/src/platform/opengl/opengl_renderer_api.cpp
+++ b/src/platform/opengl/opengl_renderer_api.cpp
@@ -1,7 +1,7 @@
#include "opengl_renderer_api.h"
+
#include <glad/glad.h>
#include <GLFW/glfw3.h>
-#include <iostream>
namespace Donut
{
@@ -9,13 +9,13 @@ namespace Donut
{
if (!glfwGetCurrentContext())
{
- std::cout << "No OpenGL context is current! Cannot initialize GLAD." << std::endl;
+ DONUT_ERROR("No OpenGL context is current! Cannot initialize GLAD.");
return;
}
if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress))
{
- std::cout << "Failed to initialize GLAD!" << std::endl;
+ DONUT_ERROR("Failed to initialize GLAD!");
return;
}
@@ -61,7 +61,7 @@ namespace Donut
glDisable(GL_CULL_FACE);
}
- void OpenGLRendererAPI::draw_indexed(const std::shared_ptr<VertexArray>& vertex_array, uint32_t index_count)
+ void OpenGLRendererAPI::draw_indexed(const Ref<VertexArray>& vertex_array, uint32_t index_count)
{
uint32_t count = index_count ? index_count : vertex_array->get_index_buffer()->get_count();
glDrawElements(GL_TRIANGLES, count, GL_UNSIGNED_INT, nullptr);
diff --git a/src/platform/opengl/opengl_renderer_api.h b/src/platform/opengl/opengl_renderer_api.h
index 15984d5..25accbb 100644
--- a/src/platform/opengl/opengl_renderer_api.h
+++ b/src/platform/opengl/opengl_renderer_api.h
@@ -1,6 +1,10 @@
#pragma once
+#include "core/memory.h"
+#include "core/log.h"
+
#include "rendering/renderer.h"
+
#include <glad/glad.h>
namespace Donut
@@ -17,7 +21,7 @@ namespace Donut
virtual void enable_depth_test() override;
virtual void set_face_culling(bool enabled) override;
- virtual void draw_indexed(const std::shared_ptr<VertexArray>& vertex_array,
+ virtual void draw_indexed(const Ref<VertexArray>& vertex_array,
uint32_t index_count = 0) override;
};
};
diff --git a/src/platform/opengl/opengl_shader.cpp b/src/platform/opengl/opengl_shader.cpp
index f4b99bc..3b0108e 100644
--- a/src/platform/opengl/opengl_shader.cpp
+++ b/src/platform/opengl/opengl_shader.cpp
@@ -1,6 +1,8 @@
#include "opengl_shader.h"
+
#include <glad/glad.h>
#include <glm/gtc/type_ptr.hpp>
+
#include <fstream>
#include <iostream>
diff --git a/src/platform/opengl/opengl_shader.h b/src/platform/opengl/opengl_shader.h
index 5870bda..6b1ceec 100644
--- a/src/platform/opengl/opengl_shader.h
+++ b/src/platform/opengl/opengl_shader.h
@@ -1,6 +1,7 @@
#pragma once
#include "rendering/shader.h"
+
#include <unordered_map>
#include <glm/glm.hpp>
diff --git a/src/platform/opengl/opengl_texture.cpp b/src/platform/opengl/opengl_texture.cpp
index 53ed06c..5d05fb4 100644
--- a/src/platform/opengl/opengl_texture.cpp
+++ b/src/platform/opengl/opengl_texture.cpp
@@ -1,5 +1,4 @@
#include "opengl_texture.h"
-#include <iostream>
namespace Donut
{
@@ -39,7 +38,7 @@ namespace Donut
uint32_t white_pixel = 0xFFFFFFFF;
glTextureSubImage2D(m_renderer_id, 0, 0, 0, m_width, m_height, m_data_format, GL_UNSIGNED_BYTE, &white_pixel);
- std::cout << "Created default texture (stb_image not available for loading: " << path << ")" << std::endl;
+ DONUT_INFO("Created default texture (stb_image not available for loading: ", path, ")");
}
OpenGLTexture2D::~OpenGLTexture2D()
@@ -52,7 +51,7 @@ namespace Donut
uint32_t bpp = m_data_format == GL_RGBA ? 4 : 3;
if (size != m_width * m_height * bpp)
{
- std::cout << "Data must be entire texture!" << std::endl;
+ DONUT_ERROR("Data must be entire texture!");
return;
}
diff --git a/src/platform/opengl/opengl_texture.h b/src/platform/opengl/opengl_texture.h
index 41b352a..705d770 100644
--- a/src/platform/opengl/opengl_texture.h
+++ b/src/platform/opengl/opengl_texture.h
@@ -1,6 +1,8 @@
#pragma once
#include "rendering/texture.h"
+#include "core/log.h"
+
#include <glad/glad.h>
namespace Donut
diff --git a/src/platform/opengl/opengl_vertex_array.cpp b/src/platform/opengl/opengl_vertex_array.cpp
index c57479b..e2fb766 100644
--- a/src/platform/opengl/opengl_vertex_array.cpp
+++ b/src/platform/opengl/opengl_vertex_array.cpp
@@ -1,4 +1,5 @@
#include <glad/glad.h>
+
#include "opengl_vertex_array.h"
#include "rendering/vertex_buffer.h"
#include "rendering/index_buffer.h"
@@ -25,7 +26,7 @@ namespace Donut
glBindVertexArray(0);
}
- void OpenGLVertexArray::add_vertex_buffer(const std::shared_ptr<VertexBuffer>& vertex_buffer)
+ void OpenGLVertexArray::add_vertex_buffer(const Ref<VertexBuffer>& vertex_buffer)
{
glBindVertexArray(m_renderer_id);
vertex_buffer->bind();
@@ -46,7 +47,7 @@ namespace Donut
m_vertex_buffers.push_back(vertex_buffer);
}
- void OpenGLVertexArray::set_index_buffer(const std::shared_ptr<IndexBuffer>& index_buffer)
+ void OpenGLVertexArray::set_index_buffer(const Ref<IndexBuffer>& index_buffer)
{
glBindVertexArray(m_renderer_id);
index_buffer->bind();
diff --git a/src/platform/opengl/opengl_vertex_array.h b/src/platform/opengl/opengl_vertex_array.h
index d6986db..ff5cdd8 100644
--- a/src/platform/opengl/opengl_vertex_array.h
+++ b/src/platform/opengl/opengl_vertex_array.h
@@ -1,11 +1,12 @@
#pragma once
+#include "core/memory.h"
+
#include "rendering/vertex_array.h"
#include "rendering/vertex_buffer.h"
#include "rendering/index_buffer.h"
#include <vector>
-#include <memory>
namespace Donut
{
@@ -19,22 +20,22 @@ namespace Donut
virtual void bind() const override;
virtual void unbind() const override;
- virtual void add_vertex_buffer(const std::shared_ptr<VertexBuffer>& vertex_buffer) override;
- virtual void set_index_buffer(const std::shared_ptr<IndexBuffer>& index_buffer) override;
+ virtual void add_vertex_buffer(const Ref<VertexBuffer>& vertex_buffer) override;
+ virtual void set_index_buffer(const Ref<IndexBuffer>& index_buffer) override;
- virtual const std::vector<std::shared_ptr<VertexBuffer>>& get_vertex_buffers() const override
+ virtual const std::vector<Ref<VertexBuffer>>& get_vertex_buffers() const override
{
return m_vertex_buffers;
}
- virtual const std::shared_ptr<IndexBuffer>& get_index_buffer() const override
+ virtual const Ref<IndexBuffer>& get_index_buffer() const override
{
return m_index_buffer;
}
private:
uint32_t m_renderer_id;
uint32_t m_vertex_buffer_index = 0;
- std::vector<std::shared_ptr<VertexBuffer>> m_vertex_buffers;
- std::shared_ptr<IndexBuffer> m_index_buffer;
+ std::vector<Ref<VertexBuffer>> m_vertex_buffers;
+ Ref<IndexBuffer> m_index_buffer;
};
};
diff --git a/src/platform/vulkan/vulkan_renderer_api.cpp b/src/platform/vulkan/vulkan_renderer_api.cpp
index b934317..f91a0ea 100644
--- a/src/platform/vulkan/vulkan_renderer_api.cpp
+++ b/src/platform/vulkan/vulkan_renderer_api.cpp
@@ -26,7 +26,7 @@ namespace Donut
{
}
- void VulkanRendererAPI::draw_indexed(const std::shared_ptr<VertexArray>& vertex_array, uint32_t index_count)
+ void VulkanRendererAPI::draw_indexed(const Ref<VertexArray>& vertex_array, uint32_t index_count)
{
}
};
diff --git a/src/platform/vulkan/vulkan_renderer_api.h b/src/platform/vulkan/vulkan_renderer_api.h
index 0e1baf9..d1394b3 100644
--- a/src/platform/vulkan/vulkan_renderer_api.h
+++ b/src/platform/vulkan/vulkan_renderer_api.h
@@ -1,5 +1,6 @@
#pragma once
+#include "core/memory.h"
#include "rendering/renderer.h"
namespace Donut
@@ -16,7 +17,7 @@ namespace Donut
virtual void enable_depth_test() override;
virtual void set_face_culling(bool enabled) override;
- virtual void draw_indexed(const std::shared_ptr<VertexArray>& vertex_array,
+ virtual void draw_indexed(const Ref<VertexArray>& vertex_array,
uint32_t index_count = 0) override;
};
};
diff --git a/src/platform/vulkan/vulkan_vertex_array.cpp b/src/platform/vulkan/vulkan_vertex_array.cpp
index 31c2f74..8258696 100644
--- a/src/platform/vulkan/vulkan_vertex_array.cpp
+++ b/src/platform/vulkan/vulkan_vertex_array.cpp
@@ -18,12 +18,12 @@ namespace Donut
{
}
- void VulkanVertexArray::add_vertex_buffer(const std::shared_ptr<VertexBuffer>& vertex_buffer)
+ void VulkanVertexArray::add_vertex_buffer(const Ref<VertexBuffer>& vertex_buffer)
{
m_vertex_buffers.push_back(vertex_buffer);
}
- void VulkanVertexArray::set_index_buffer(const std::shared_ptr<IndexBuffer>& index_buffer)
+ void VulkanVertexArray::set_index_buffer(const Ref<IndexBuffer>& index_buffer)
{
m_index_buffer = index_buffer;
}
diff --git a/src/platform/vulkan/vulkan_vertex_array.h b/src/platform/vulkan/vulkan_vertex_array.h
index b36c421..f4356d9 100644
--- a/src/platform/vulkan/vulkan_vertex_array.h
+++ b/src/platform/vulkan/vulkan_vertex_array.h
@@ -1,6 +1,7 @@
#pragma once
#include "rendering/vertex_array.h"
+#include "core/memory.h"
namespace Donut
{
@@ -14,14 +15,14 @@ namespace Donut
virtual void bind() const override;
virtual void unbind() const override;
- virtual void add_vertex_buffer(const std::shared_ptr<VertexBuffer>& vertex_buffer) override;
- virtual void set_index_buffer(const std::shared_ptr<IndexBuffer>& index_buffer) override;
+ virtual void add_vertex_buffer(const Ref<VertexBuffer>& vertex_buffer) override;
+ virtual void set_index_buffer(const Ref<IndexBuffer>& index_buffer) override;
- virtual const std::vector<std::shared_ptr<VertexBuffer>>& get_vertex_buffers() const { return m_vertex_buffers; }
- virtual const std::shared_ptr<IndexBuffer>& get_index_buffer() const { return m_index_buffer; }
+ virtual const std::vector<Ref<VertexBuffer>>& get_vertex_buffers() const { return m_vertex_buffers; }
+ virtual const Ref<IndexBuffer>& get_index_buffer() const { return m_index_buffer; }
private:
uint32_t m_renderer_id;
- std::vector<std::shared_ptr<VertexBuffer>> m_vertex_buffers;
- std::shared_ptr<IndexBuffer> m_index_buffer;
+ std::vector<Ref<VertexBuffer>> m_vertex_buffers;
+ Ref<IndexBuffer> m_index_buffer;
};
};
diff --git a/src/rendering/renderer.cpp b/src/rendering/renderer.cpp
index 46dd690..5e4682c 100644
--- a/src/rendering/renderer.cpp
+++ b/src/rendering/renderer.cpp
@@ -3,19 +3,18 @@
#include "platform/opengl/opengl_renderer_api.h"
#include "platform/vulkan/vulkan_renderer_api.h"
-#include <memory>
#include <glm/gtc/matrix_transform.hpp>
namespace Donut
{
- std::unique_ptr<RendererAPI> RendererAPI::create()
+ Scope<RendererAPI> RendererAPI::create()
{
switch (s_api)
{
case API::OpenGL:
- return std::make_unique<OpenGLRendererAPI>();
+ return create_scope<OpenGLRendererAPI>();
case API::Vulkan:
- return std::make_unique<VulkanRendererAPI>();
+ return create_scope<VulkanRendererAPI>();
default:
return nullptr;
}
@@ -38,8 +37,8 @@ namespace Donut
RenderCommand::set_viewport(0, 0, width, height);
}
- void Renderer::submit(const std::shared_ptr<Shader>& shader,
- const std::shared_ptr<VertexArray>& vertex_array,
+ void Renderer::submit(const Ref<Shader>& shader,
+ const Ref<VertexArray>& vertex_array,
const glm::mat4& transform,
const glm::mat4& view_projection)
{
@@ -51,7 +50,7 @@ namespace Donut
RenderCommand::draw_indexed(vertex_array);
}
- std::unique_ptr<RendererAPI> RenderCommand::s_renderer_api = RendererAPI::create();
+ Scope<RendererAPI> RenderCommand::s_renderer_api = RendererAPI::create();
void Renderer::set_clear_color(const glm::vec4& color)
{
diff --git a/src/rendering/renderer.h b/src/rendering/renderer.h
index dd4c259..6212b21 100644
--- a/src/rendering/renderer.h
+++ b/src/rendering/renderer.h
@@ -1,10 +1,10 @@
#pragma once
+#include "core/memory.h"
#include "vertex_array.h"
#include "shader.h"
#include <glm/glm.hpp>
-#include <memory>
namespace Donut
{
@@ -28,12 +28,12 @@ namespace Donut
virtual void enable_depth_test() = 0;
virtual void set_face_culling(bool enabled) = 0;
- virtual void draw_indexed(const std::shared_ptr<VertexArray>& vertex_array,
+ virtual void draw_indexed(const Ref<VertexArray>& vertex_array,
uint32_t index_count = 0) = 0;
inline static API get_api() { return s_api; }
inline static void set_api(API api) { s_api = api; }
- static std::unique_ptr<RendererAPI> create();
+ static Scope<RendererAPI> create();
private:
static API s_api;
};
@@ -71,13 +71,13 @@ namespace Donut
s_renderer_api->set_face_culling(enabled);
}
- inline static void draw_indexed(const std::shared_ptr<VertexArray>& vertex_array, uint32_t index_count = 0)
+ inline static void draw_indexed(const Ref<VertexArray>& vertex_array, uint32_t index_count = 0)
{
s_renderer_api->draw_indexed(vertex_array, index_count);
}
private:
- static std::unique_ptr<RendererAPI> s_renderer_api;
+ static Scope<RendererAPI> s_renderer_api;
};
class Renderer
@@ -88,8 +88,8 @@ namespace Donut
static void on_window_resize(uint32_t width, uint32_t height);
- static void submit(const std::shared_ptr<Shader>& shader,
- const std::shared_ptr<VertexArray>& vertex_array,
+ static void submit(const Ref<Shader>& shader,
+ const Ref<VertexArray>& vertex_array,
const glm::mat4& transform,
const glm::mat4& view_projection);
diff --git a/src/rendering/shader.cpp b/src/rendering/shader.cpp
index 1e84125..1bbd0fc 100644
--- a/src/rendering/shader.cpp
+++ b/src/rendering/shader.cpp
@@ -1,8 +1,8 @@
#include "shader.h"
#include "renderer.h"
+
#include "platform/opengl/opengl_shader.h"
#include "platform/vulkan/vulkan_shader.h"
-#include <memory>
namespace Donut
{
@@ -45,32 +45,32 @@ namespace Donut
}
}
- void ShaderLibrary::add(const std::shared_ptr<Shader>& shader)
+ void ShaderLibrary::add(const Ref<Shader>& shader)
{
auto& name = shader->get_name();
add(name, shader);
}
- void ShaderLibrary::add(const std::string& name, const std::shared_ptr<Shader>& shader)
+ void ShaderLibrary::add(const std::string& name, const Ref<Shader>& shader)
{
m_shaders[name] = shader;
}
- std::shared_ptr<Shader> ShaderLibrary::load(const std::string& filepath)
+ Ref<Shader> ShaderLibrary::load(const std::string& filepath)
{
- auto shader = std::shared_ptr<Shader>(Shader::create(filepath));
+ auto shader = Ref<Shader>(Shader::create(filepath));
add(shader);
return shader;
}
- std::shared_ptr<Shader> ShaderLibrary::load(const std::string& name, const std::string& filepath)
+ Ref<Shader> ShaderLibrary::load(const std::string& name, const std::string& filepath)
{
- auto shader = std::shared_ptr<Shader>(Shader::create(filepath));
+ auto shader = Ref<Shader>(Shader::create(filepath));
add(name, shader);
return shader;
}
- std::shared_ptr<Shader> ShaderLibrary::get(const std::string& name)
+ Ref<Shader> ShaderLibrary::get(const std::string& name)
{
if (exists(name))
return m_shaders[name];
diff --git a/src/rendering/shader.h b/src/rendering/shader.h
index f490f3c..814f0cf 100644
--- a/src/rendering/shader.h
+++ b/src/rendering/shader.h
@@ -1,8 +1,9 @@
#pragma once
+#include "core/memory.h"
+
#include <string>
#include <unordered_map>
-#include <memory>
#include <glm/glm.hpp>
#define SHADER_STORAGE_BARRIER_BIT 0x00002000
@@ -42,15 +43,15 @@ namespace Donut
class ShaderLibrary
{
public:
- void add(const std::shared_ptr<Shader>& shader);
- void add(const std::string& name, const std::shared_ptr<Shader>& shader);
- std::shared_ptr<Shader> load(const std::string& filepath);
- std::shared_ptr<Shader> load(const std::string& name, const std::string& filepath);
+ void add(const Ref<Shader>& shader);
+ void add(const std::string& name, const Ref<Shader>& shader);
+ Ref<Shader> load(const std::string& filepath);
+ Ref<Shader> load(const std::string& name, const std::string& filepath);
- std::shared_ptr<Shader> get(const std::string& name);
+ Ref<Shader> get(const std::string& name);
bool exists(const std::string& name) const;
private:
- std::unordered_map<std::string, std::shared_ptr<Shader>> m_shaders;
+ std::unordered_map<std::string, Ref<Shader>> m_shaders;
};
};
diff --git a/src/rendering/texture.cpp b/src/rendering/texture.cpp
index 36189a3..e14c09c 100644
--- a/src/rendering/texture.cpp
+++ b/src/rendering/texture.cpp
@@ -1,18 +1,19 @@
#include "texture.h"
#include "renderer.h"
-#include "../platform/opengl/opengl_texture.h"
-#include "../platform/vulkan/vulkan_texture.h"
+
+#include "platform/opengl/opengl_texture.h"
+#include "platform/vulkan/vulkan_texture.h"
namespace Donut
{
- std::shared_ptr<Texture2D> Texture2D::create(uint32_t width, uint32_t height)
+ Ref<Texture2D> Texture2D::create(uint32_t width, uint32_t height)
{
switch (Renderer::get_api())
{
case RendererAPI::API::OpenGL:
- return std::make_shared<OpenGLTexture2D>(width, height);
+ return create_ref<OpenGLTexture2D>(width, height);
case RendererAPI::API::Vulkan:
- return std::make_shared<VulkanTexture2D>(width, height);
+ return create_ref<VulkanTexture2D>(width, height);
case RendererAPI::API::None:
return nullptr;
default:
@@ -20,14 +21,14 @@ namespace Donut
}
}
- std::shared_ptr<Texture2D> Texture2D::create(const std::string& path)
+ Ref<Texture2D> Texture2D::create(const std::string& path)
{
switch (Renderer::get_api())
{
case RendererAPI::API::OpenGL:
- return std::make_shared<OpenGLTexture2D>(path);
+ return create_ref<OpenGLTexture2D>(path);
case RendererAPI::API::Vulkan:
- return std::make_shared<VulkanTexture2D>(path);
+ return create_ref<VulkanTexture2D>(path);
case RendererAPI::API::None:
return nullptr;
default:
diff --git a/src/rendering/texture.h b/src/rendering/texture.h
index e9f369f..cc5c59e 100644
--- a/src/rendering/texture.h
+++ b/src/rendering/texture.h
@@ -1,6 +1,7 @@
#pragma once
-#include <memory>
+#include "core/memory.h"
+
#include <string>
#include <glm/glm.hpp>
@@ -27,7 +28,7 @@ namespace Donut
: public Texture
{
public:
- static std::shared_ptr<Texture2D> create(uint32_t width, uint32_t height);
- static std::shared_ptr<Texture2D> create(const std::string& path);
+ static Ref<Texture2D> create(uint32_t width, uint32_t height);
+ static Ref<Texture2D> create(const std::string& path);
};
};
diff --git a/src/rendering/vertex_array.cpp b/src/rendering/vertex_array.cpp
index 8057a3e..bb92ff3 100644
--- a/src/rendering/vertex_array.cpp
+++ b/src/rendering/vertex_array.cpp
@@ -1,5 +1,6 @@
#include "vertex_array.h"
#include "renderer.h"
+
#include "platform/opengl/opengl_vertex_array.h"
#include "platform/vulkan/vulkan_vertex_array.h"
diff --git a/src/rendering/vertex_array.h b/src/rendering/vertex_array.h
index 946f273..a39849f 100644
--- a/src/rendering/vertex_array.h
+++ b/src/rendering/vertex_array.h
@@ -1,8 +1,10 @@
#pragma once
+#include "core/memory.h"
+
#include "vertex_buffer.h"
#include "index_buffer.h"
-#include <memory>
+
#include <vector>
namespace Donut
@@ -15,11 +17,11 @@ namespace Donut
virtual void bind() const = 0;
virtual void unbind() const = 0;
- virtual void add_vertex_buffer(const std::shared_ptr<VertexBuffer>& vertex_buffer) = 0;
- virtual void set_index_buffer(const std::shared_ptr<IndexBuffer>& index_buffer) = 0;
+ virtual void add_vertex_buffer(const Ref<VertexBuffer>& vertex_buffer) = 0;
+ virtual void set_index_buffer(const Ref<IndexBuffer>& index_buffer) = 0;
- virtual const std::vector<std::shared_ptr<VertexBuffer>>& get_vertex_buffers() const = 0;
- virtual const std::shared_ptr<IndexBuffer>& get_index_buffer() const = 0;
+ virtual const std::vector<Ref<VertexBuffer>>& get_vertex_buffers() const = 0;
+ virtual const Ref<IndexBuffer>& get_index_buffer() const = 0;
static VertexArray* create();
};
diff --git a/src/rendering/vertex_buffer.cpp b/src/rendering/vertex_buffer.cpp
index 32ae10a..4929711 100644
--- a/src/rendering/vertex_buffer.cpp
+++ b/src/rendering/vertex_buffer.cpp
@@ -1,5 +1,6 @@
#include "vertex_buffer.h"
#include "renderer.h"
+
#include "platform/opengl/opengl_vertex_buffer.h"
#include "platform/vulkan/vulkan_vertex_buffer.h"
diff --git a/src/states/simulation_state.cpp b/src/states/simulation_state.cpp
index c925cd7..6a832cd 100644
--- a/src/states/simulation_state.cpp
+++ b/src/states/simulation_state.cpp
@@ -6,7 +6,6 @@
#include "rendering/shader.h"
#include "rendering/texture.h"
-#include <iostream>
#include <glm/glm.hpp>
#include <glm/gtc/matrix_transform.hpp>
#include <GLFW/glfw3.h>
@@ -15,7 +14,7 @@ namespace Donut
{
void SimulationState::on_enter()
{
- m_camera = std::make_unique<Camera>(45.0f, 1280.0f / 720.0f, 0.1f, 100.0f);
+ m_camera = create_scope<Camera>(45.0f, 1280.0f / 720.0f, 0.1f, 100.0f);
m_camera->set_position({ 0.0f, 0.0f, 3.0f });
m_camera->set_mouse_sensitivity(0.1f);
m_camera->set_movement_speed(5.0f);
@@ -42,8 +41,8 @@ namespace Donut
4, 5, 1, 1, 0, 4
};
- m_vertex_array = std::shared_ptr<VertexArray>(VertexArray::create());
- m_vertex_buffer = std::shared_ptr<VertexBuffer>(VertexBuffer::create(vertices, sizeof(vertices)));
+ m_vertex_array = Ref<VertexArray>(VertexArray::create());
+ m_vertex_buffer = Ref<VertexBuffer>(VertexBuffer::create(vertices, sizeof(vertices)));
VertexBufferLayout layout;
layout.push<float>(3);
@@ -53,10 +52,10 @@ namespace Donut
m_vertex_array->add_vertex_buffer(m_vertex_buffer);
- m_index_buffer = std::shared_ptr<IndexBuffer>(IndexBuffer::create(indices, 36));
+ m_index_buffer = Ref<IndexBuffer>(IndexBuffer::create(indices, 36));
m_vertex_array->set_index_buffer(m_index_buffer);
- m_shader = std::shared_ptr<Shader>(Shader::create("assets/textured.glsl"));
+ m_shader = Ref<Shader>(Shader::create("assets/textured.glsl"));
m_texture = Texture2D::create(256, 256);
uint32_t* pixel_data = new uint32_t[256 * 256];
@@ -82,7 +81,7 @@ namespace Donut
m_texture->set_data(pixel_data, 256 * 256 * 4);
delete[] pixel_data;
- m_compute_shader = std::shared_ptr<Shader>(Shader::create("assets/texture_processor.glsl"));
+ m_compute_shader = Ref<Shader>(Shader::create("assets/texture_processor.glsl"));
if (!m_compute_shader)
{
diff --git a/src/states/simulation_state.h b/src/states/simulation_state.h
index a0d9e73..051edf3 100644
--- a/src/states/simulation_state.h
+++ b/src/states/simulation_state.h
@@ -1,5 +1,6 @@
#pragma once
+#include "core/memory.h"
#include "core/state.h"
#include "core/event.h"
#include "core/camera.h"
@@ -28,16 +29,16 @@ namespace Donut
void handle_key_input(float delta_time);
void update_texture();
private:
- std::unique_ptr<Camera> m_camera;
+ Scope<Camera> m_camera;
- std::shared_ptr<VertexArray> m_vertex_array;
- std::shared_ptr<VertexBuffer> m_vertex_buffer;
- std::shared_ptr<IndexBuffer> m_index_buffer;
- std::shared_ptr<Shader> m_shader;
- std::shared_ptr<Texture2D> m_texture;
+ Ref<VertexArray> m_vertex_array;
+ Ref<VertexBuffer> m_vertex_buffer;
+ Ref<IndexBuffer> m_index_buffer;
+ Ref<Shader> m_shader;
+ Ref<Texture2D> m_texture;
- std::shared_ptr<Shader> m_compute_shader;
- std::shared_ptr<Texture2D> m_processed_texture;
+ Ref<Shader> m_compute_shader;
+ Ref<Texture2D> m_processed_texture;
float m_compute_brightness = 0.0f;
float m_compute_contrast = 1.0f;