diff options
Diffstat (limited to 'src')
26 files changed, 184 insertions, 173 deletions
diff --git a/src/core/application.h b/src/core/application.h index 713ecba..e5a983a 100644 --- a/src/core/application.h +++ b/src/core/application.h @@ -6,14 +6,11 @@ #include <memory> #include <functional> -namespace Donut -{ - class VertexArray; - class VertexBuffer; - class IndexBuffer; - class Shader; - class Texture2D; -}; +#include "rendering/vertex_array.h" +#include "rendering/vertex_buffer.h" +#include "rendering/index_buffer.h" +#include "rendering/shader.h" +#include "rendering/texture.h" namespace Donut { @@ -41,29 +38,29 @@ namespace Donut bool m_running; bool m_minimized; - std::shared_ptr<VertexArray> m_vertex_array; + 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; + std::shared_ptr<IndexBuffer> m_index_buffer; + std::shared_ptr<Shader> m_shader; + std::shared_ptr<Texture2D> m_texture; - std::shared_ptr<Shader> m_compute_shader; + std::shared_ptr<Shader> m_compute_shader; std::shared_ptr<Texture2D> m_processed_texture; float m_compute_brightness; float m_compute_contrast; float m_compute_saturation; - bool m_use_compute_shader; + bool m_use_compute_shader; std::unique_ptr<Camera> m_camera; - bool m_keys[1024] = { false }; - bool m_first_mouse = true; - float m_last_x = 0.0f; - float m_last_y = 0.0f; - float m_delta_time = 0.0f; - float m_last_frame = 0.0f; - bool m_mouse_dragging = false; - float m_texture_time = 0.0f; + bool m_keys[1024] = { false }; + bool m_first_mouse = true; + float m_last_x = 0.0f; + float m_last_y = 0.0f; + float m_delta_time = 0.0f; + float m_last_frame = 0.0f; + bool m_mouse_dragging = false; + float m_texture_time = 0.0f; static Application* s_instance; }; diff --git a/src/core/camera.cpp b/src/core/camera.cpp index bad2919..06866e4 100644 --- a/src/core/camera.cpp +++ b/src/core/camera.cpp @@ -28,27 +28,27 @@ namespace Donut void Camera::recalculate_view_matrix() { float pitch = glm::radians(m_rotation.x); - float yaw = glm::radians(m_rotation.y); - float roll = glm::radians(m_rotation.z); + float yaw = glm::radians(m_rotation.y); + float roll = glm::radians(m_rotation.z); glm::vec3 direction; direction.x = cos(yaw) * cos(pitch); direction.y = sin(pitch); direction.z = sin(yaw) * cos(pitch); - glm::vec3 front = glm::normalize(direction); glm::vec3 world_up(0.0f, 1.0f, 0.0f); + glm::vec3 front = glm::normalize(direction); glm::vec3 right = glm::normalize(glm::cross(front, world_up)); - glm::vec3 up = glm::normalize(glm::cross(right, front)); + glm::vec3 up = glm::normalize(glm::cross(right, front)); - m_view_matrix = glm::lookAt(m_position, m_position + front, up); + m_view_matrix = glm::lookAt(m_position, m_position + front, up); m_view_projection_matrix = m_projection_matrix * m_view_matrix; } glm::vec3 Camera::get_forward_direction() const { float pitch = glm::radians(m_rotation.x); - float yaw = glm::radians(m_rotation.y); + float yaw = glm::radians(m_rotation.y); glm::vec3 direction; direction.x = cos(yaw) * cos(pitch); @@ -69,10 +69,6 @@ namespace Donut return glm::normalize(glm::cross(get_right_direction(), get_forward_direction())); } - void Camera::on_update(float delta_time) - { - } - void Camera::on_mouse_move(float x_offset, float y_offset, bool constrain_pitch) { x_offset *= m_mouse_sensitivity; diff --git a/src/core/camera.h b/src/core/camera.h index 200c4b0..25f7e2a 100644 --- a/src/core/camera.h +++ b/src/core/camera.h @@ -27,8 +27,6 @@ namespace Donut const glm::mat4& get_view_projection_matrix() const { return m_view_projection_matrix; } void set_projection(float fov, float aspect_ratio, float near_plane, float far_plane); - - void on_update(float delta_time); void on_mouse_move(float x_offset, float y_offset, bool constrain_pitch = true); void move_forward(float delta_time); @@ -39,10 +37,10 @@ namespace Donut void move_down(float delta_time); void set_mouse_sensitivity(float sensitivity) { m_mouse_sensitivity = sensitivity; } - float get_mouse_sensitivity() const { return m_mouse_sensitivity; } + float get_mouse_sensitivity() const { return m_mouse_sensitivity; } - void set_movement_speed(float speed) { m_movement_speed = speed; } - float get_movement_speed() const { return m_movement_speed; } + void set_movement_speed(float speed) { m_movement_speed = speed; } + float get_movement_speed() const { return m_movement_speed; } private: void recalculate_view_matrix(); @@ -55,15 +53,15 @@ namespace Donut glm::vec3 m_position = { 0.0f, 0.0f, 3.0f }; glm::vec3 m_rotation = { 0.0f, 0.0f, 0.0f }; - float m_fov = 45.0f; + float m_fov = 45.0f; float m_aspect_ratio = 16.0f / 9.0f; - float m_near_plane = 0.1f; - float m_far_plane = 100.0f; + float m_near_plane = 0.1f; + float m_far_plane = 100.0f; float m_mouse_sensitivity = 0.1f; - float m_movement_speed = 5.0f; - bool m_first_mouse = true; - float m_last_x = 0.0f; - float m_last_y = 0.0f; + float m_movement_speed = 5.0f; + bool m_first_mouse = true; + float m_last_x = 0.0f; + float m_last_y = 0.0f; }; } diff --git a/src/core/event.h b/src/core/event.h index e4d1be1..a1e30e9 100644 --- a/src/core/event.h +++ b/src/core/event.h @@ -156,7 +156,8 @@ namespace Donut EventCategoryInput; } protected: - KeyEvent(int keycode) : m_key_code(keycode) { } + KeyEvent(int keycode) + : m_key_code(keycode) { } int m_key_code; }; @@ -185,7 +186,8 @@ namespace Donut : public KeyEvent { public: - KeyReleasedEvent(int keycode) : KeyEvent(keycode) { } + KeyReleasedEvent(int keycode) + : KeyEvent(keycode) { } std::string to_string() const override { @@ -199,7 +201,8 @@ namespace Donut : public KeyEvent { public: - KeyTypedEvent(int keycode) : KeyEvent(keycode) { } + KeyTypedEvent(int keycode) + : KeyEvent(keycode) { } std::string to_string() const override { @@ -262,7 +265,8 @@ namespace Donut EventCategoryInput; } protected: - MouseButtonEvent(int button) : m_button(button) { } + MouseButtonEvent(int button) + : m_button(button) { } int m_button; }; @@ -270,7 +274,8 @@ namespace Donut : public MouseButtonEvent { public: - MouseButtonPressedEvent(int button) : MouseButtonEvent(button) { } + MouseButtonPressedEvent(int button) + : MouseButtonEvent(button) { } std::string to_string() const override { @@ -284,7 +289,8 @@ namespace Donut : public MouseButtonEvent { public: - MouseButtonReleasedEvent(int button) : MouseButtonEvent(button) { } + MouseButtonReleasedEvent(int button) + : MouseButtonEvent(button) { } std::string to_string() const override { @@ -297,7 +303,8 @@ namespace Donut class EventDispatcher { public: - EventDispatcher(Event& event) : m_event(event) { } + EventDispatcher(Event& event) + : m_event(event) { } template<typename T, typename F> bool dispatch(const F& func) @@ -322,7 +329,10 @@ namespace Donut EventHandler() = default; ~EventHandler() = default; - void set_event_callback(const EventCallbackFn& callback) { m_event_callback = callback; } + void set_event_callback(const EventCallbackFn& callback) + { + m_event_callback = callback; + } void on_event(Event& event) { diff --git a/src/core/window.cpp b/src/core/window.cpp index 26c134c..9605f8c 100644 --- a/src/core/window.cpp +++ b/src/core/window.cpp @@ -1,11 +1,10 @@ #include "window.h" #include <cstdint> #include <iostream> -#include <glad/glad.h> namespace Donut { - static bool s_glfw_initialized = false; + static bool s_glfw_initialized = false; static uint32_t s_glfw_window_count = 0; Window::Window(const std::string& title, int width, int height) @@ -43,26 +42,18 @@ namespace Donut } glfwMakeContextCurrent(m_window); - - if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress)) - { - std::cout << "Failed to initialize GLAD!" << std::endl; - glfwTerminate(); - return; - } - glfwSetWindowUserPointer(m_window, this); glfwSetErrorCallback(glfw_error_callback); glfwSetWindowCloseCallback(m_window, glfw_window_close_callback); - glfwSetWindowSizeCallback(m_window, glfw_window_size_callback); + glfwSetWindowSizeCallback(m_window, glfw_window_size_callback); glfwSetWindowFocusCallback(m_window, glfw_window_focus_callback); - glfwSetWindowPosCallback(m_window, glfw_window_pos_callback); - glfwSetKeyCallback(m_window, glfw_key_callback); - glfwSetCharCallback(m_window, glfw_char_callback); + glfwSetWindowPosCallback(m_window, glfw_window_pos_callback); + glfwSetKeyCallback(m_window, glfw_key_callback); + glfwSetCharCallback(m_window, glfw_char_callback); glfwSetMouseButtonCallback(m_window, glfw_mouse_button_callback); - glfwSetScrollCallback(m_window, glfw_mouse_scroll_callback); - glfwSetCursorPosCallback(m_window, glfw_cursor_pos_callback); + glfwSetScrollCallback(m_window, glfw_mouse_scroll_callback); + glfwSetCursorPosCallback(m_window, glfw_cursor_pos_callback); s_glfw_window_count++; } @@ -93,19 +84,15 @@ namespace Donut void Window::set_cursor_locked(bool locked) { m_cursor_locked = locked; - if (locked) - glfwSetInputMode(m_window, GLFW_CURSOR, GLFW_CURSOR_DISABLED); - else - glfwSetInputMode(m_window, GLFW_CURSOR, GLFW_CURSOR_NORMAL); + glfwSetInputMode(m_window, GLFW_CURSOR, locked ? + GLFW_CURSOR_DISABLED : GLFW_CURSOR_NORMAL); } void Window::set_cursor_visible(bool visible) { m_cursor_visible = visible; - if (visible) - glfwSetInputMode(m_window, GLFW_CURSOR, GLFW_CURSOR_NORMAL); - else - glfwSetInputMode(m_window, GLFW_CURSOR, GLFW_CURSOR_HIDDEN); + glfwSetInputMode(m_window, GLFW_CURSOR, visible ? + GLFW_CURSOR_NORMAL : GLFW_CURSOR_HIDDEN); } void Window::glfw_error_callback(int error, const char* description) @@ -153,7 +140,8 @@ namespace Donut win->m_event_handler.on_event(event); } - void Window::glfw_key_callback(GLFWwindow* window, int key, int scancode, int action, int mods) + void Window::glfw_key_callback(GLFWwindow* window, int key, int scancode, + int action, int mods) { Window* win = static_cast<Window*>(glfwGetWindowUserPointer(window)); @@ -184,7 +172,8 @@ namespace Donut win->m_event_handler.on_event(event); } - void Window::glfw_mouse_button_callback(GLFWwindow* window, int button, int action, int mods) + void Window::glfw_mouse_button_callback(GLFWwindow* window, int button, + int action, int mods) { Window* win = static_cast<Window*>(glfwGetWindowUserPointer(window)); @@ -199,8 +188,7 @@ namespace Donut { MouseButtonReleasedEvent event(button); win->m_event_handler.on_event(event); - break; - } + } break; } } diff --git a/src/core/window.h b/src/core/window.h index d541b54..cf80cac 100644 --- a/src/core/window.h +++ b/src/core/window.h @@ -24,14 +24,14 @@ namespace Donut EventHandler& get_event_handler() { return m_event_handler; } - unsigned int get_width() const { return m_width; } + unsigned int get_width() const { return m_width; } unsigned int get_height() const { return m_height; } - void* get_native_window() const { return m_window; } + void* get_native_window() const { return m_window; } void set_cursor_locked(bool locked); void set_cursor_visible(bool visible); - bool is_cursor_locked() const { return m_cursor_locked; } + bool is_cursor_locked() const { return m_cursor_locked; } bool is_cursor_visible() const { return m_cursor_visible; } private: void init(); @@ -48,10 +48,10 @@ namespace Donut static void glfw_mouse_scroll_callback(GLFWwindow* window, double x_offset, double y_offset); static void glfw_cursor_pos_callback(GLFWwindow* window, double x_pos, double y_pos); private: - GLFWwindow* m_window; + GLFWwindow* m_window; EventHandler m_event_handler; - std::string m_title; + std::string m_title; unsigned int m_width; unsigned int m_height; bool m_is_closed; diff --git a/src/main.cpp b/src/main.cpp index 2578eb2..1833b66 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2,8 +2,7 @@ int main() { - Donut::Application* app = new Donut::Application() ; + Donut::Application* app = new Donut::Application("Donut", 1280, 720); app->run(); delete app; - return 0; } diff --git a/src/platform/opengl/opengl_index_buffer.h b/src/platform/opengl/opengl_index_buffer.h index b0498b4..43a9d86 100644 --- a/src/platform/opengl/opengl_index_buffer.h +++ b/src/platform/opengl/opengl_index_buffer.h @@ -11,8 +11,8 @@ namespace Donut OpenGLIndexBuffer(const uint32_t* indices, uint32_t count); virtual ~OpenGLIndexBuffer(); - virtual void bind() const override; - virtual void unbind() const override; + virtual void bind() const override; + virtual void unbind() const override; virtual uint32_t get_count() const override { return m_count; } private: diff --git a/src/platform/opengl/opengl_renderer_api.cpp b/src/platform/opengl/opengl_renderer_api.cpp index 3a147b9..1d41735 100644 --- a/src/platform/opengl/opengl_renderer_api.cpp +++ b/src/platform/opengl/opengl_renderer_api.cpp @@ -1,10 +1,24 @@ #include "opengl_renderer_api.h" #include <glad/glad.h> +#include <GLFW/glfw3.h> +#include <iostream> namespace Donut { void OpenGLRendererAPI::init() { + if (!glfwGetCurrentContext()) + { + std::cout << "No OpenGL context is current! Cannot initialize GLAD." << std::endl; + return; + } + + if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress)) + { + std::cout << "Failed to initialize GLAD!" << std::endl; + return; + } + glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glEnable(GL_DEPTH_TEST); diff --git a/src/platform/opengl/opengl_renderer_api.h b/src/platform/opengl/opengl_renderer_api.h index f28567c..15984d5 100644 --- a/src/platform/opengl/opengl_renderer_api.h +++ b/src/platform/opengl/opengl_renderer_api.h @@ -9,13 +9,15 @@ namespace Donut : public RendererAPI { public: - virtual void init() override; - virtual void set_viewport(uint32_t x, uint32_t y, uint32_t width, uint32_t height) override; - virtual void set_clear_color(const glm::vec4& color) override; - virtual void clear() override; - virtual void enable_depth_test() override; - virtual void set_face_culling(bool enabled) override; + virtual void init() override; + virtual void set_viewport(uint32_t x, uint32_t y, + uint32_t width, uint32_t height) override; + virtual void set_clear_color(const glm::vec4& color) override; + virtual void clear() override; + 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, uint32_t index_count = 0) override; + virtual void draw_indexed(const std::shared_ptr<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 10da3de..f4b99bc 100644 --- a/src/platform/opengl/opengl_shader.cpp +++ b/src/platform/opengl/opengl_shader.cpp @@ -55,11 +55,15 @@ namespace Donut std::string OpenGLShader::read_file(const std::string& filepath) { std::string result; - std::ifstream in(filepath, std::ios::in | std::ios::binary); - if (in) { + std::ifstream in(filepath, std::ios::in | + std::ios::binary); + + if (in) + { in.seekg(0, std::ios::end); size_t size = in.tellg(); - if (size != -1) { + if (size != -1) + { result.resize(size); in.seekg(0, std::ios::beg); in.read(&result[0], size); @@ -75,6 +79,7 @@ namespace Donut const char* type_token = "#type"; size_t type_token_length = strlen(type_token); size_t pos = source.find(type_token, 0); + while (pos != std::string::npos) { size_t eol = source.find_first_of("\r\n", pos); diff --git a/src/platform/opengl/opengl_shader.h b/src/platform/opengl/opengl_shader.h index 1a79461..5870bda 100644 --- a/src/platform/opengl/opengl_shader.h +++ b/src/platform/opengl/opengl_shader.h @@ -18,36 +18,35 @@ namespace Donut virtual void bind() const override; virtual void unbind() const override; - virtual void set_int(const std::string& name, int value) override; + virtual void set_int( const std::string& name, int value) override; virtual void set_int_array(const std::string& name, int* values, uint32_t count) override; - virtual void set_float(const std::string& name, float value) override; - virtual void set_float2(const std::string& name, const glm::vec2& value) override; - virtual void set_float3(const std::string& name, const glm::vec3& value) override; - virtual void set_float4(const std::string& name, const glm::vec4& value) override; - virtual void set_mat4(const std::string& name, const glm::mat4& value) override; + virtual void set_float( const std::string& name, float value) override; + virtual void set_float2( const std::string& name, const glm::vec2& value) override; + virtual void set_float3( const std::string& name, const glm::vec3& value) override; + virtual void set_float4( const std::string& name, const glm::vec4& value) override; + virtual void set_mat4( const std::string& name, const glm::mat4& value) override; virtual void dispatch(uint32_t x, uint32_t y = 1, uint32_t z = 1) override; - virtual void dispatch_indirect(uint32_t offset = 0) override; - virtual void memory_barrier(uint32_t barriers) override; + virtual void dispatch_indirect(uint32_t offset = 0) override; + virtual void memory_barrier(uint32_t barriers) override; virtual const std::string& get_name() const override { return m_name; } - void upload_uniform_int(const std::string& name, int value); + void upload_uniform_int( const std::string& name, int value); void upload_uniform_int_array(const std::string& name, int* values, uint32_t count); - void upload_uniform_float(const std::string& name, float value); - void upload_uniform_float2(const std::string& name, const glm::vec2& value); - void upload_uniform_float3(const std::string& name, const glm::vec3& value); - void upload_uniform_float4(const std::string& name, const glm::vec4& value); - void upload_uniform_mat3(const std::string& name, const glm::mat3& matrix); - void upload_uniform_mat4(const std::string& name, const glm::mat4& matrix); + void upload_uniform_float( const std::string& name, float value); + void upload_uniform_float2( const std::string& name, const glm::vec2& value); + void upload_uniform_float3( const std::string& name, const glm::vec3& value); + void upload_uniform_float4( const std::string& name, const glm::vec4& value); + void upload_uniform_mat3( const std::string& name, const glm::mat3& matrix); + void upload_uniform_mat4( const std::string& name, const glm::mat4& matrix); private: std::string read_file(const std::string& filepath); std::unordered_map<uint32_t, std::string> pre_process(const std::string& source); void compile(const std::unordered_map<uint32_t, std::string>& shader_sources); - private: - uint32_t m_renderer_id; + uint32_t m_renderer_id; std::string m_name; }; }; diff --git a/src/platform/opengl/opengl_texture.cpp b/src/platform/opengl/opengl_texture.cpp index 100909f..53ed06c 100644 --- a/src/platform/opengl/opengl_texture.cpp +++ b/src/platform/opengl/opengl_texture.cpp @@ -7,9 +7,9 @@ namespace Donut : m_width(width), m_height(height) { m_internal_format = GL_RGBA8; - m_data_format = GL_RGBA; + m_data_format = GL_RGBA; - glCreateTextures(GL_TEXTURE_2D, 1, &m_renderer_id); + glCreateTextures(GL_TEXTURE_2D, 1, &m_renderer_id); glTextureStorage2D(m_renderer_id, 1, m_internal_format, m_width, m_height); glTextureParameteri(m_renderer_id, GL_TEXTURE_MIN_FILTER, GL_LINEAR); @@ -22,12 +22,12 @@ namespace Donut OpenGLTexture2D::OpenGLTexture2D(const std::string& path) : m_path(path) { - m_width = 1; - m_height = 1; + m_width = 1; + m_height = 1; m_internal_format = GL_RGBA8; - m_data_format = GL_RGBA; + m_data_format = GL_RGBA; - glCreateTextures(GL_TEXTURE_2D, 1, &m_renderer_id); + glCreateTextures(GL_TEXTURE_2D, 1, &m_renderer_id); glTextureStorage2D(m_renderer_id, 1, m_internal_format, m_width, m_height); glTextureParameteri(m_renderer_id, GL_TEXTURE_MIN_FILTER, GL_LINEAR); diff --git a/src/platform/opengl/opengl_texture.h b/src/platform/opengl/opengl_texture.h index ddd4f39..41b352a 100644 --- a/src/platform/opengl/opengl_texture.h +++ b/src/platform/opengl/opengl_texture.h @@ -13,12 +13,12 @@ namespace Donut OpenGLTexture2D(const std::string& path); virtual ~OpenGLTexture2D(); - virtual uint32_t get_width() const override { return m_width; } - virtual uint32_t get_height() const override { return m_height; } + virtual uint32_t get_width() const override { return m_width; } + virtual uint32_t get_height() const override { return m_height; } virtual uint32_t get_renderer_id() const override { return m_renderer_id; } - virtual void set_data(void* data, uint32_t size) override; - virtual void bind(uint32_t slot = 0) const override; + virtual void set_data(void* data, uint32_t size) override; + virtual void bind(uint32_t slot = 0) const override; virtual void bind_as_image(uint32_t slot = 0, bool read_only = false) const override; virtual bool operator==(const Texture& other) const override @@ -28,8 +28,8 @@ namespace Donut private: std::string m_path; - uint32_t m_width, m_height; - uint32_t m_renderer_id; - GLenum m_internal_format, m_data_format; + uint32_t m_width, m_height; + uint32_t m_renderer_id; + GLenum m_internal_format, m_data_format; }; } diff --git a/src/platform/opengl/opengl_vertex_array.h b/src/platform/opengl/opengl_vertex_array.h index e1a02f6..d6986db 100644 --- a/src/platform/opengl/opengl_vertex_array.h +++ b/src/platform/opengl/opengl_vertex_array.h @@ -1,14 +1,14 @@ #pragma once #include "rendering/vertex_array.h" +#include "rendering/vertex_buffer.h" +#include "rendering/index_buffer.h" + #include <vector> #include <memory> namespace Donut { - class VertexBuffer; - class IndexBuffer; - class OpenGLVertexArray : public VertexArray { @@ -35,6 +35,6 @@ namespace Donut 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::shared_ptr<IndexBuffer> m_index_buffer; }; }; diff --git a/src/platform/opengl/opengl_vertex_buffer.cpp b/src/platform/opengl/opengl_vertex_buffer.cpp index 76b620a..543a7d6 100644 --- a/src/platform/opengl/opengl_vertex_buffer.cpp +++ b/src/platform/opengl/opengl_vertex_buffer.cpp @@ -1,5 +1,6 @@ #include "opengl_vertex_buffer.h" #include "rendering/vertex_buffer.h" + #include <glad/glad.h> namespace Donut diff --git a/src/platform/opengl/opengl_vertex_buffer.h b/src/platform/opengl/opengl_vertex_buffer.h index bdc0645..678f0e0 100644 --- a/src/platform/opengl/opengl_vertex_buffer.h +++ b/src/platform/opengl/opengl_vertex_buffer.h @@ -11,15 +11,15 @@ namespace Donut OpenGLVertexBuffer(const void* data, uint32_t size); virtual ~OpenGLVertexBuffer(); - virtual void bind() const override; - virtual void unbind() const override; + virtual void bind() const override; + virtual void unbind() const override; virtual void set_data(const void* data, uint32_t size) override; - virtual const VertexBufferLayout& get_layout() const override { return m_layout; } + virtual const VertexBufferLayout& get_layout() const override { return m_layout; } virtual void set_layout(const VertexBufferLayout& layout) override { m_layout = layout; } private: - uint32_t m_renderer_id; + uint32_t m_renderer_id; VertexBufferLayout m_layout; }; }; diff --git a/src/platform/vulkan/.gitkeep b/src/platform/vulkan/.gitkeep new file mode 100644 index 0000000..cb7e3af --- /dev/null +++ b/src/platform/vulkan/.gitkeep @@ -0,0 +1 @@ +Kill me
\ No newline at end of file diff --git a/src/rendering/index_buffer.cpp b/src/rendering/index_buffer.cpp index d4bd9c0..4e38b36 100644 --- a/src/rendering/index_buffer.cpp +++ b/src/rendering/index_buffer.cpp @@ -1,5 +1,6 @@ #include "index_buffer.h" #include "renderer.h" + #include "platform/opengl/opengl_index_buffer.h" namespace Donut diff --git a/src/rendering/index_buffer.h b/src/rendering/index_buffer.h index 3003676..856559a 100644 --- a/src/rendering/index_buffer.h +++ b/src/rendering/index_buffer.h @@ -9,8 +9,8 @@ namespace Donut public: virtual ~IndexBuffer() = default; - virtual void bind() const = 0; - virtual void unbind() const = 0; + virtual void bind() const = 0; + virtual void unbind() const = 0; virtual uint32_t get_count() const = 0; static IndexBuffer* create(const uint32_t* indices, uint32_t count); diff --git a/src/rendering/renderer.cpp b/src/rendering/renderer.cpp index 19917a6..bd921eb 100644 --- a/src/rendering/renderer.cpp +++ b/src/rendering/renderer.cpp @@ -34,9 +34,9 @@ namespace Donut } void Renderer::submit(const std::shared_ptr<Shader>& shader, - const std::shared_ptr<VertexArray>& vertex_array, - const glm::mat4& transform, - const glm::mat4& view_projection) + const std::shared_ptr<VertexArray>& vertex_array, + const glm::mat4& transform, + const glm::mat4& view_projection) { shader->bind(); shader->set_mat4("u_ViewProjection", view_projection); diff --git a/src/rendering/renderer.h b/src/rendering/renderer.h index 7bbdd4b..c7ace3c 100644 --- a/src/rendering/renderer.h +++ b/src/rendering/renderer.h @@ -21,26 +21,26 @@ namespace Donut public: enum class API { - None = 0, + None = 0, OpenGL = 1, Vulkan = 2, }; - public: virtual ~RendererAPI() = default; - virtual void init() = 0; - virtual void set_viewport(uint32_t x, uint32_t y, uint32_t width, uint32_t height) = 0; - virtual void set_clear_color(const glm::vec4& color) = 0; - virtual void clear() = 0; - virtual void enable_depth_test() = 0; - virtual void set_face_culling(bool enabled) = 0; + virtual void init() = 0; + virtual void set_viewport(uint32_t x, uint32_t y, + uint32_t width, uint32_t height) = 0; + virtual void set_clear_color(const glm::vec4& color) = 0; + virtual void clear() = 0; + 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, uint32_t index_count = 0) = 0; + virtual void draw_indexed(const std::shared_ptr<VertexArray>& vertex_array, + uint32_t index_count = 0) = 0; inline static API get_api() { return s_api; } static Scope<RendererAPI> create(); - private: static API s_api; }; diff --git a/src/rendering/shader.h b/src/rendering/shader.h index fe869ba..f490f3c 100644 --- a/src/rendering/shader.h +++ b/src/rendering/shader.h @@ -20,17 +20,17 @@ namespace Donut virtual void bind() const = 0; virtual void unbind() const = 0; - virtual void set_int(const std::string& name, int value) = 0; + virtual void set_int( const std::string& name, int value) = 0; virtual void set_int_array(const std::string& name, int* values, uint32_t count) = 0; - virtual void set_float(const std::string& name, float value) = 0; - virtual void set_float2(const std::string& name, const glm::vec2& value) = 0; - virtual void set_float3(const std::string& name, const glm::vec3& value) = 0; - virtual void set_float4(const std::string& name, const glm::vec4& value) = 0; - virtual void set_mat4(const std::string& name, const glm::mat4& value) = 0; + virtual void set_float( const std::string& name, float value) = 0; + virtual void set_float2( const std::string& name, const glm::vec2& value) = 0; + virtual void set_float3( const std::string& name, const glm::vec3& value) = 0; + virtual void set_float4( const std::string& name, const glm::vec4& value) = 0; + virtual void set_mat4( const std::string& name, const glm::mat4& value) = 0; virtual void dispatch(uint32_t x, uint32_t y = 1, uint32_t z = 1) = 0; - virtual void dispatch_indirect(uint32_t offset = 0) = 0; - virtual void memory_barrier(uint32_t barriers) = 0; + virtual void dispatch_indirect(uint32_t offset = 0) = 0; + virtual void memory_barrier(uint32_t barriers) = 0; virtual const std::string& get_name() const = 0; @@ -50,7 +50,6 @@ namespace Donut std::shared_ptr<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; }; diff --git a/src/rendering/texture.h b/src/rendering/texture.h index 68866b5..e9f369f 100644 --- a/src/rendering/texture.h +++ b/src/rendering/texture.h @@ -11,15 +11,16 @@ namespace Donut public: virtual ~Texture() = default; - virtual uint32_t get_width() const = 0; - virtual uint32_t get_height() const = 0; + virtual uint32_t get_width() const = 0; + virtual uint32_t get_height() const = 0; virtual uint32_t get_renderer_id() const = 0; - virtual void set_data(void* data, uint32_t size) = 0; - virtual void bind(uint32_t slot = 0) const = 0; - virtual void bind_as_image(uint32_t slot = 0, bool read_only = false) const = 0; + virtual void set_data(void* data, uint32_t size) = 0; + virtual void bind(uint32_t slot = 0) const = 0; + virtual void bind_as_image(uint32_t slot = 0, + bool read_only = false) const = 0; - virtual bool operator==(const Texture& other) const = 0; + virtual bool operator==(const Texture& other) const = 0; }; class Texture2D diff --git a/src/rendering/vertex_array.h b/src/rendering/vertex_array.h index b51db84..946f273 100644 --- a/src/rendering/vertex_array.h +++ b/src/rendering/vertex_array.h @@ -12,14 +12,14 @@ namespace Donut public: virtual ~VertexArray() = default; - virtual void bind() const = 0; + 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 set_index_buffer(const std::shared_ptr<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::shared_ptr<IndexBuffer>& get_index_buffer() const = 0; static VertexArray* create(); }; diff --git a/src/rendering/vertex_buffer.h b/src/rendering/vertex_buffer.h index 1d0b621..77a76c9 100644 --- a/src/rendering/vertex_buffer.h +++ b/src/rendering/vertex_buffer.h @@ -61,11 +61,11 @@ namespace Donut public: virtual ~VertexBuffer() = default; - virtual void bind() const = 0; - virtual void unbind() const = 0; + virtual void bind() const = 0; + virtual void unbind() const = 0; virtual void set_data(const void* data, uint32_t size) = 0; - virtual const VertexBufferLayout& get_layout() const = 0; + virtual const VertexBufferLayout& get_layout() const = 0; virtual void set_layout(const VertexBufferLayout& layout) = 0; static VertexBuffer* create(const void* data, uint32_t size); |
