diff options
| -rw-r--r-- | src/core/application.cpp | 149 | ||||
| -rw-r--r-- | src/core/application.h | 11 | ||||
| -rw-r--r-- | src/core/camera.cpp | 132 | ||||
| -rw-r--r-- | src/core/camera.h | 69 | ||||
| -rw-r--r-- | src/core/window.cpp | 18 | ||||
| -rw-r--r-- | src/core/window.h | 17 | ||||
| -rw-r--r-- | src/platform/opengl/opengl_renderer_api.cpp | 5 | ||||
| -rw-r--r-- | src/platform/opengl/opengl_renderer_api.h | 1 | ||||
| -rw-r--r-- | src/platform/opengl/opengl_shader.cpp | 3 | ||||
| -rw-r--r-- | src/platform/opengl/opengl_vertex_array.cpp | 2 | ||||
| -rw-r--r-- | src/rendering/renderer.cpp | 45 | ||||
| -rw-r--r-- | src/rendering/renderer.h | 34 |
12 files changed, 426 insertions, 60 deletions
diff --git a/src/core/application.cpp b/src/core/application.cpp index 92bf211..b80ad84 100644 --- a/src/core/application.cpp +++ b/src/core/application.cpp @@ -9,6 +9,7 @@ #include <iostream> #include <glm/glm.hpp> #include <glm/gtc/matrix_transform.hpp> +#include <GLFW/glfw3.h> namespace Donut { @@ -70,14 +71,78 @@ namespace Donut else m_minimized = false; + if (m_camera) + m_camera->set_projection(45.0f, (float)e.get_width() / (float)e.get_height(), 0.1f, 100.0f); + + event.handled = true; + return true; + }); + + dispatcher.dispatch<WindowFocusEvent>([this, &event](WindowFocusEvent& e) + { + m_first_mouse = true; + m_mouse_dragging = false; + event.handled = true; + return true; + }); + + dispatcher.dispatch<WindowLostFocusEvent>([this, &event](WindowLostFocusEvent& e) + { + m_mouse_dragging = false; event.handled = true; return true; }); dispatcher.dispatch<KeyPressedEvent>([this, &event](KeyPressedEvent& e) { - if (e.get_key_code() == 256) - close(); + m_keys[e.get_key_code()] = true; + return true; + }); + + dispatcher.dispatch<KeyReleasedEvent>([this, &event](KeyReleasedEvent& e) + { + m_keys[e.get_key_code()] = false; + return true; + }); + + dispatcher.dispatch<MouseMovedEvent>([this, &event](MouseMovedEvent& e) + { + if (!m_mouse_dragging) + return true; + + if (m_first_mouse) + { + m_last_x = e.get_x(); + m_last_y = e.get_y(); + m_first_mouse = false; + } + + float x_offset = m_last_x - e.get_x(); + float y_offset = e.get_y() - m_last_y; + + m_last_x = e.get_x(); + m_last_y = e.get_y(); + + if (m_camera) + m_camera->on_mouse_move(x_offset, y_offset); + + return true; + }); + + dispatcher.dispatch<MouseButtonPressedEvent>([this, &event](MouseButtonPressedEvent& e) + { + if (e.get_mouse_button() == GLFW_MOUSE_BUTTON_LEFT) + { + m_mouse_dragging = true; + m_first_mouse = true; + } + return true; + }); + + dispatcher.dispatch<MouseButtonReleasedEvent>([this, &event](MouseButtonReleasedEvent& e) + { + if (e.get_mouse_button() == GLFW_MOUSE_BUTTON_LEFT) + m_mouse_dragging = false; return true; }); } @@ -86,14 +151,32 @@ namespace Donut { Renderer::init(); - float vertices[3 * 7] = + m_camera = std::make_unique<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); + + float vertices[] = { - -0.5f, -0.5f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, - 0.5f, -0.5f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, - 0.0f, 0.5f, 0.0f, 0.0f, 0.0f, 1.0f, 1.0f + -0.5f, -0.5f, -0.5f, 1.0f, 0.0f, 0.0f, 1.0f, + 0.5f, -0.5f, -0.5f, 0.0f, 1.0f, 0.0f, 1.0f, + 0.5f, 0.5f, -0.5f, 0.0f, 0.0f, 1.0f, 1.0f, + -0.5f, 0.5f, -0.5f, 1.0f, 1.0f, 0.0f, 1.0f, + -0.5f, -0.5f, 0.5f, 1.0f, 0.0f, 1.0f, 1.0f, + 0.5f, -0.5f, 0.5f, 0.0f, 1.0f, 1.0f, 1.0f, + 0.5f, 0.5f, 0.5f, 0.5f, 0.5f, 0.5f, 1.0f, + -0.5f, 0.5f, 0.5f, 1.0f, 1.0f, 1.0f, 1.0f }; - uint32_t indices[3] = { 0, 1, 2 }; + uint32_t indices[] = + { + 0, 1, 2, 2, 3, 0, + 1, 5, 6, 6, 2, 1, + 5, 4, 7, 7, 6, 5, + 4, 0, 3, 3, 7, 4, + 3, 2, 6, 6, 7, 3, + 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))); @@ -105,7 +188,7 @@ namespace Donut m_vertex_array->add_vertex_buffer(m_vertex_buffer); - m_index_buffer = std::shared_ptr<IndexBuffer>(IndexBuffer::create(indices, 3)); + m_index_buffer = std::shared_ptr<IndexBuffer>(IndexBuffer::create(indices, 36)); m_vertex_array->set_index_buffer(m_index_buffer); m_shader = std::shared_ptr<Shader>(Shader::create("assets/basic.glsl")); @@ -118,19 +201,55 @@ namespace Donut void Application::on_update() { + float current_frame = (float)glfwGetTime(); + m_delta_time = current_frame - m_last_frame; + m_last_frame = current_frame; + + if (m_camera) + { + if (m_keys[GLFW_KEY_W]) + m_camera->move_forward(m_delta_time); + if (m_keys[GLFW_KEY_S]) + m_camera->move_backward(m_delta_time); + if (m_keys[GLFW_KEY_A]) + m_camera->move_left(m_delta_time); + if (m_keys[GLFW_KEY_D]) + m_camera->move_right(m_delta_time); + if (m_keys[GLFW_KEY_SPACE]) + m_camera->move_up(m_delta_time); + if (m_keys[GLFW_KEY_LEFT_SHIFT]) + m_camera->move_down(m_delta_time); + } } void Application::on_render() { - Renderer::set_clear_color({ 0.1f, 0.1f, 0.1f, 1.0f }); + Renderer::set_clear_color({ 0.0f, 0.0f, 0.0f, 1.0f }); Renderer::clear(); - Renderer::begin_scene(); - - glm::mat4 view_projection = glm::ortho(-1.0f, 1.0f, -1.0f, 1.0f, -1.0f, 1.0f); + glm::mat4 view_projection = m_camera ? m_camera->get_view_projection_matrix() : glm::mat4(1.0f); - Renderer::submit(m_shader, m_vertex_array, glm::mat4(1.0f)); - - Renderer::end_scene(); + glm::vec3 center_pos(0.0f, 0.0f, 0.0f); + glm::vec3 right_pos(2.0f, 0.0f, 0.0f); + glm::vec3 left_pos(-2.0f, 0.0f, 0.0f); + glm::vec3 up_pos(0.0f, 2.0f, 0.0f); + glm::vec3 down_pos(0.0f, -2.0f, 0.0f); + glm::vec3 forward_pos(0.0f, 0.0f, 2.0f); + glm::vec3 back_pos(0.0f, 0.0f, -2.0f); + + glm::mat4 transform = glm::translate(glm::mat4(1.0f), center_pos); + Renderer::submit(m_shader, m_vertex_array, transform, view_projection); + transform = glm::translate(glm::mat4(1.0f), right_pos); + Renderer::submit(m_shader, m_vertex_array, transform, view_projection); + transform = glm::translate(glm::mat4(1.0f), left_pos); + Renderer::submit(m_shader, m_vertex_array, transform, view_projection); + transform = glm::translate(glm::mat4(1.0f), up_pos); + Renderer::submit(m_shader, m_vertex_array, transform, view_projection); + transform = glm::translate(glm::mat4(1.0f), down_pos); + Renderer::submit(m_shader, m_vertex_array, transform, view_projection); + transform = glm::translate(glm::mat4(1.0f), forward_pos); + Renderer::submit(m_shader, m_vertex_array, transform, view_projection); + transform = glm::translate(glm::mat4(1.0f), back_pos); + Renderer::submit(m_shader, m_vertex_array, transform, view_projection); } } diff --git a/src/core/application.h b/src/core/application.h index a860e1c..f78f107 100644 --- a/src/core/application.h +++ b/src/core/application.h @@ -2,6 +2,7 @@ #include "window.h" #include "event.h" +#include "camera.h" #include <memory> #include <functional> @@ -42,6 +43,16 @@ namespace Donut std::shared_ptr<VertexBuffer> m_vertex_buffer; std::shared_ptr<IndexBuffer> m_index_buffer; std::shared_ptr<Shader> m_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; static Application* s_instance; }; diff --git a/src/core/camera.cpp b/src/core/camera.cpp new file mode 100644 index 0000000..bad2919 --- /dev/null +++ b/src/core/camera.cpp @@ -0,0 +1,132 @@ +#include "camera.h" +#include <glm/gtc/quaternion.hpp> + +namespace Donut +{ + Camera::Camera(float fov, float aspect_ratio, float near_plane, float far_plane) + : m_fov(fov), m_aspect_ratio(aspect_ratio), m_near_plane(near_plane), m_far_plane(far_plane) + { + recalculate_projection_matrix(); + recalculate_view_matrix(); + } + + void Camera::set_projection(float fov, float aspect_ratio, float near_plane, float far_plane) + { + m_fov = fov; + m_aspect_ratio = aspect_ratio; + m_near_plane = near_plane; + m_far_plane = far_plane; + recalculate_projection_matrix(); + } + + void Camera::recalculate_projection_matrix() + { + m_projection_matrix = glm::perspective(glm::radians(m_fov), m_aspect_ratio, m_near_plane, m_far_plane); + m_view_projection_matrix = m_projection_matrix * m_view_matrix; + } + + 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); + + 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 right = glm::normalize(glm::cross(front, world_up)); + glm::vec3 up = glm::normalize(glm::cross(right, front)); + + 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); + + glm::vec3 direction; + direction.x = cos(yaw) * cos(pitch); + direction.y = sin(pitch); + direction.z = sin(yaw) * cos(pitch); + + return glm::normalize(direction); + } + + glm::vec3 Camera::get_right_direction() const + { + glm::vec3 world_up(0.0f, 1.0f, 0.0f); + return glm::normalize(glm::cross(get_forward_direction(), world_up)); + } + + glm::vec3 Camera::get_up_direction() const + { + 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; + y_offset *= m_mouse_sensitivity; + + m_rotation.y += x_offset; + m_rotation.x += y_offset; + + if (constrain_pitch) + { + if (m_rotation.x > 89.0f) + m_rotation.x = 89.0f; + if (m_rotation.x < -89.0f) + m_rotation.x = -89.0f; + } + + recalculate_view_matrix(); + } + + void Camera::move_forward(float delta_time) + { + m_position += get_forward_direction() * m_movement_speed * delta_time; + recalculate_view_matrix(); + } + + void Camera::move_backward(float delta_time) + { + m_position -= get_forward_direction() * m_movement_speed * delta_time; + recalculate_view_matrix(); + } + + void Camera::move_right(float delta_time) + { + m_position += get_right_direction() * m_movement_speed * delta_time; + recalculate_view_matrix(); + } + + void Camera::move_left(float delta_time) + { + m_position -= get_right_direction() * m_movement_speed * delta_time; + recalculate_view_matrix(); + } + + void Camera::move_up(float delta_time) + { + glm::vec3 world_up(0.0f, 1.0f, 0.0f); + m_position += world_up * m_movement_speed * delta_time; + recalculate_view_matrix(); + } + + void Camera::move_down(float delta_time) + { + glm::vec3 world_up(0.0f, 1.0f, 0.0f); + m_position -= world_up * m_movement_speed * delta_time; + recalculate_view_matrix(); + } +} diff --git a/src/core/camera.h b/src/core/camera.h new file mode 100644 index 0000000..200c4b0 --- /dev/null +++ b/src/core/camera.h @@ -0,0 +1,69 @@ +#pragma once + +#include <glm/glm.hpp> +#include <glm/gtc/matrix_transform.hpp> + +namespace Donut +{ + class Camera + { + public: + Camera(float fov = 45.0f, float aspect_ratio = 16.0f / 9.0f, + float near_plane = 0.1f, float far_plane = 100.0f); + ~Camera() = default; + + void set_position(const glm::vec3& position) { m_position = position; recalculate_view_matrix(); } + void set_rotation(const glm::vec3& rotation) { m_rotation = rotation; recalculate_view_matrix(); } + + const glm::vec3& get_position() const { return m_position; } + const glm::vec3& get_rotation() const { return m_rotation; } + + glm::vec3 get_forward_direction() const; + glm::vec3 get_right_direction() const; + glm::vec3 get_up_direction() const; + + const glm::mat4& get_projection_matrix() const { return m_projection_matrix; } + const glm::mat4& get_view_matrix() const { return m_view_matrix; } + 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); + void move_backward(float delta_time); + void move_right(float delta_time); + void move_left(float delta_time); + void move_up(float delta_time); + 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; } + + void set_movement_speed(float speed) { m_movement_speed = speed; } + float get_movement_speed() const { return m_movement_speed; } + + private: + void recalculate_view_matrix(); + void recalculate_projection_matrix(); + private: + glm::mat4 m_projection_matrix; + glm::mat4 m_view_matrix; + glm::mat4 m_view_projection_matrix; + + 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_aspect_ratio = 16.0f / 9.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; + }; +} diff --git a/src/core/window.cpp b/src/core/window.cpp index 77ef885..26c134c 100644 --- a/src/core/window.cpp +++ b/src/core/window.cpp @@ -90,6 +90,24 @@ namespace Donut return glfwWindowShouldClose(m_window) || m_is_closed; } + 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); + } + + 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); + } + void Window::glfw_error_callback(int error, const char* description) { std::cout << "GLFW Error (" << error << "): " << description << std::endl; diff --git a/src/core/window.h b/src/core/window.h index 8e9778e..d541b54 100644 --- a/src/core/window.h +++ b/src/core/window.h @@ -15,16 +15,24 @@ namespace Donut ~Window(); bool should_close() const; - void on_update() const; + void on_update() const; + + void set_event_callback(const EventCallbackFn& callback) + { + m_event_handler.set_event_callback(callback); + } - void set_event_callback(const EventCallbackFn& callback) { m_event_handler.set_event_callback(callback); } 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 set_cursor_locked(bool locked); + void set_cursor_visible(bool visible); + bool is_cursor_locked() const { return m_cursor_locked; } + bool is_cursor_visible() const { return m_cursor_visible; } private: void init(); void shutdown(); @@ -39,7 +47,6 @@ namespace Donut static void glfw_mouse_button_callback(GLFWwindow* window, int button, int action, int mods); 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; EventHandler m_event_handler; @@ -48,5 +55,7 @@ namespace Donut unsigned int m_width; unsigned int m_height; bool m_is_closed; + bool m_cursor_locked = false; + bool m_cursor_visible = true; }; } diff --git a/src/platform/opengl/opengl_renderer_api.cpp b/src/platform/opengl/opengl_renderer_api.cpp index 9fb911a..49b4e53 100644 --- a/src/platform/opengl/opengl_renderer_api.cpp +++ b/src/platform/opengl/opengl_renderer_api.cpp @@ -25,6 +25,11 @@ namespace Donut glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); } + void OpenGLRendererAPI::enable_depth_test() + { + glEnable(GL_DEPTH_TEST); + } + void OpenGLRendererAPI::draw_indexed(const std::shared_ptr<VertexArray>& vertex_array, uint32_t index_count) { uint32_t count = index_count ? index_count : vertex_array->get_index_buffer()->get_count(); diff --git a/src/platform/opengl/opengl_renderer_api.h b/src/platform/opengl/opengl_renderer_api.h index 26e779a..30be426 100644 --- a/src/platform/opengl/opengl_renderer_api.h +++ b/src/platform/opengl/opengl_renderer_api.h @@ -13,6 +13,7 @@ namespace Donut 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 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 e2e6279..39e582a 100644 --- a/src/platform/opengl/opengl_shader.cpp +++ b/src/platform/opengl/opengl_shader.cpp @@ -65,7 +65,8 @@ 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) { + while (pos != std::string::npos) + { size_t eol = source.find_first_of("\r\n", pos); size_t begin = pos + type_token_length + 1; std::string type = source.substr(begin, eol - begin); diff --git a/src/platform/opengl/opengl_vertex_array.cpp b/src/platform/opengl/opengl_vertex_array.cpp index 14d4e63..c57479b 100644 --- a/src/platform/opengl/opengl_vertex_array.cpp +++ b/src/platform/opengl/opengl_vertex_array.cpp @@ -39,7 +39,7 @@ namespace Donut element.type, element.normalized ? GL_TRUE : GL_FALSE, layout.get_stride(), - (const void*)element.offset); + reinterpret_cast<const void*>(static_cast<uintptr_t>(element.offset))); m_vertex_buffer_index++; } diff --git a/src/rendering/renderer.cpp b/src/rendering/renderer.cpp index 1da5034..19917a6 100644 --- a/src/rendering/renderer.cpp +++ b/src/rendering/renderer.cpp @@ -3,10 +3,12 @@ #include <memory> #include <glm/gtc/matrix_transform.hpp> -namespace Donut { - - Scope<RendererAPI> RendererAPI::create() { - switch (s_api) { +namespace Donut +{ + Scope<RendererAPI> RendererAPI::create() + { + switch (s_api) + { case API::OpenGL: return std::make_unique<OpenGLRendererAPI>(); default: @@ -16,32 +18,28 @@ namespace Donut { RendererAPI::API RendererAPI::s_api = RendererAPI::API::OpenGL; - Renderer::SceneData* Renderer::s_scene_data = new Renderer::SceneData; - - void Renderer::init() { + void Renderer::init() + { RenderCommand::init(); + RenderCommand::enable_depth_test(); } - void Renderer::shutdown() { - delete s_scene_data; + void Renderer::shutdown() + { } - void Renderer::on_window_resize(uint32_t width, uint32_t height) { + void Renderer::on_window_resize(uint32_t width, uint32_t height) + { RenderCommand::set_viewport(0, 0, width, height); } - void Renderer::begin_scene() { - s_scene_data->ViewProjectionMatrix = glm::ortho(-1.0f, 1.0f, -1.0f, 1.0f, -1.0f, 1.0f); - } - - void Renderer::end_scene() { - } - void Renderer::submit(const std::shared_ptr<Shader>& shader, const std::shared_ptr<VertexArray>& vertex_array, - const glm::mat4& transform) { + const glm::mat4& transform, + const glm::mat4& view_projection) + { shader->bind(); - shader->set_mat4("u_ViewProjection", s_scene_data->ViewProjectionMatrix); + shader->set_mat4("u_ViewProjection", view_projection); shader->set_mat4("u_Transform", transform); vertex_array->bind(); @@ -50,12 +48,13 @@ namespace Donut { Scope<RendererAPI> RenderCommand::s_renderer_api = RendererAPI::create(); - void Renderer::set_clear_color(const glm::vec4& color) { + void Renderer::set_clear_color(const glm::vec4& color) + { RenderCommand::set_clear_color(color); } - void Renderer::clear() { + void Renderer::clear() + { RenderCommand::clear(); } - -} +}; diff --git a/src/rendering/renderer.h b/src/rendering/renderer.h index fd61914..09e9521 100644 --- a/src/rendering/renderer.h +++ b/src/rendering/renderer.h @@ -33,6 +33,7 @@ namespace Donut 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 draw_indexed(const std::shared_ptr<VertexArray>& vertex_array, uint32_t index_count = 0) = 0; @@ -46,23 +47,33 @@ namespace Donut class RenderCommand { public: - inline static void init() { + inline static void init() + { s_renderer_api->init(); } - inline static void set_viewport(uint32_t x, uint32_t y, uint32_t width, uint32_t height) { + inline static void set_viewport(uint32_t x, uint32_t y, uint32_t width, uint32_t height) + { s_renderer_api->set_viewport(x, y, width, height); } - inline static void set_clear_color(const glm::vec4& color) { + inline static void set_clear_color(const glm::vec4& color) + { s_renderer_api->set_clear_color(color); } - inline static void clear() { + inline static void clear() + { s_renderer_api->clear(); } - inline static void draw_indexed(const std::shared_ptr<VertexArray>& vertex_array, uint32_t index_count = 0) { + inline static void enable_depth_test() + { + s_renderer_api->enable_depth_test(); + } + + inline static void draw_indexed(const std::shared_ptr<VertexArray>& vertex_array, uint32_t index_count = 0) + { s_renderer_api->draw_indexed(vertex_array, index_count); } @@ -78,23 +89,14 @@ namespace Donut static void on_window_resize(uint32_t width, uint32_t height); - static void begin_scene(); - static void end_scene(); - static void submit(const std::shared_ptr<Shader>& shader, const std::shared_ptr<VertexArray>& vertex_array, - const glm::mat4& transform = glm::mat4(1.0f)); + const glm::mat4& transform, + const glm::mat4& view_projection); static void set_clear_color(const glm::vec4& color); static void clear(); inline static RendererAPI::API get_api() { return RendererAPI::get_api(); } - private: - struct SceneData - { - glm::mat4 ViewProjectionMatrix; - }; - - static SceneData* s_scene_data; }; }; |
