diff --git a/sandbox/main.cpp b/sandbox/main.cpp index 23135f5..65990cb 100644 --- a/sandbox/main.cpp +++ b/sandbox/main.cpp @@ -4,22 +4,17 @@ #include "../src/renderer/renderer.hpp" #include "../src/renderer/buffer.hpp" #include "../src/renderer/texture.hpp" - #include "../src/renderer/ui.hpp" #include "../src/input.hpp" #include "../src/camera.hpp" #include "../src/entity.hpp" #include "../src/model.hpp" - #include "../src/events/event.hpp" #include "../src/events/event_dispatcher.hpp" #include "../src/events/window_event.hpp" #include "../src/events/key_event.hpp" #include "../src/events/mouse_event.hpp" - #include "../src/utility.hpp" - - #include "../src/vertex.hpp" // Application specific header files @@ -60,12 +55,6 @@ static void handle_input(camera_t& camera, float deltaTime) { // camera.roll += camera.roll_speed * deltaTime; } -//VkRenderPass geometry_pass = nullptr; -//std::vector geometry_framebuffers; - - - - VkSampler sampler; image_buffer_t albedo_image{}; image_buffer_t depth_image{}; @@ -78,9 +67,9 @@ VkRenderPass ui_pass = nullptr; std::vector ui_framebuffers; -Pipeline basicPipeline{}; -Pipeline skyspherePipeline{}; -Pipeline wireframePipeline{}; +pipeline_t basicPipeline{}; +pipeline_t skyspherePipeline{}; +pipeline_t wireframePipeline{}; // This is a global descriptor set that will be used for all draw calls and // will contain descriptors such as a projection view matrix, global scene @@ -101,6 +90,7 @@ static buffer_t g_scene_buffer; camera_t camera{}; +// // Global scene information that will be accessed by the shaders to perform // various computations. The order of the variables cannot be changed! This // is because the shaders themselves directly replicate this structs order. @@ -120,8 +110,7 @@ struct engine_scene { }; -static void event_callback(Event& event); - +static void event_callback(event& e); #define APPLICATION_NAME "Vulkan 3D Model Viewer and Exporter" @@ -137,7 +126,7 @@ int main(int argc, char** argv) { window_t* window = create_window(APPLICATION_NAME, APPLICATION_WIDTH, APPLICATION_HEIGHT); window->event_callback = event_callback; - renderer_context_t* renderer = create_renderer(window, BufferMode::Double, VSyncMode::Enabled); + renderer_context_t* renderer = create_renderer(window, buffer_mode::Double, vsync_mode::Enabled); sampler = create_sampler(VK_FILTER_NEAREST, 16); @@ -452,8 +441,6 @@ int main(int argc, char** argv) { } ImGui::End(); -// - const ImGuiWindowFlags docking_flags = ImGuiWindowFlags_None; const ImGuiWindowFlags viewport_flags = ImGuiWindowFlags_None; static bool open = true; @@ -540,13 +527,6 @@ int main(int argc, char** argv) { destroy_sampler(sampler); - - - - - //destroy_framebuffers(geometry_framebuffers); - //destroy_render_pass(geometry_pass); - destroy_framebuffers(ui_framebuffers); destroy_render_pass(ui_pass); @@ -560,38 +540,32 @@ int main(int argc, char** argv) { return 0; } - - - - - - // TODO: Event system stuff -static bool Press(KeyPressedEvent& event) { +static bool press(key_pressed_event& e) { return true; } -static bool ButtonPress(MouseButtonPressedEvent& event) { +static bool mouse_button_press(mouse_button_pressed_event& e) { return true; } -static bool ButtonRelease(MouseButtonReleasedEvent& event) { +static bool mouse_button_release(mouse_button_released_event& e) { return true; } -static bool MouseMove(MouseMovedEvent& event) { +static bool mouse_moved(mouse_moved_event& e) { //update_camera_view(camera, event.GetX(), event.GetY()); return true; } -static bool Resize(WindowResizedEvent& event) { - set_camera_projection(camera, event.get_width(), event.get_height()); +static bool resize(window_resized_event& e) { + set_camera_projection(camera, e.get_width(), e.get_height()); - VkExtent2D extent = {event.get_width(), event.get_height()}; + VkExtent2D extent = {e.get_width(), e.get_height()}; destroy_image(albedo_image); destroy_image(depth_image); @@ -610,19 +584,19 @@ static bool Resize(WindowResizedEvent& event) { return true; } -static bool Close(WindowClosedEvent& event) { +static bool close(window_closed_event& ) { running = false; return true; } -static void event_callback(Event& event) { - EventDispatcher dispatcher(event); +static void event_callback(event& e) { + event_dispatcher dispatcher(e); - dispatcher.Dispatch(Press); - dispatcher.Dispatch(ButtonPress); - dispatcher.Dispatch(ButtonRelease); - dispatcher.Dispatch(MouseMove); - dispatcher.Dispatch(Resize); - dispatcher.Dispatch(Close); + dispatcher.dispatch(press); + dispatcher.dispatch(mouse_button_press); + dispatcher.dispatch(mouse_button_release); + dispatcher.dispatch(mouse_moved); + dispatcher.dispatch(resize); + dispatcher.dispatch(close); } diff --git a/src/events/event.hpp b/src/events/event.hpp index 5addbde..c984938 100644 --- a/src/events/event.hpp +++ b/src/events/event.hpp @@ -2,40 +2,38 @@ #define MYENGINE_EVENT_HPP enum class event_type { - None = 0, + none = 0, - KeyPressedEvent, - KeyReleasedEvent, + key_pressed, + key_released, - MouseButtonPressedEvent, - MouseButtonReleasedEvent, - MouseMovedEvent, - MouseEnteredEvent, - MouseLeftEvent, - MouseScrolledUpEvent, - MouseScrolledDownEvent, + mouse_button_pressed, + mouse_button_released, + mouse_moved, + mouse_entered, + mouse_left, + mouse_scrolled_up, + mouse_scrolled_down, - WindowClosedEvent, - WindowResizedEvent, + window_closed, + window_resized, }; -#define EVENT_CLASS_TYPE(type) static event_type GetStaticType() { return event_type::type; } \ -event_type GetType() const override { return GetStaticType(); } \ -const char* GetName() const override { return #type; } +#define EVENT_CLASS_TYPE(type) static event_type get_static_type() { return event_type::type; } \ +event_type get_type() const override { return get_static_type(); } \ +const char* get_name() const override { return #type; } -class Event { -public: - virtual event_type GetType() const = 0; - virtual const char* GetName() const = 0; +struct event { + virtual event_type get_type() const = 0; + virtual const char* get_name() const = 0; -public: bool Handled = false; }; -using event_func = std::function; +using event_func = std::function; #define BIND_EVENT(x) std::bind(&x, this, std::placeholders::_1) diff --git a/src/events/event_dispatcher.hpp b/src/events/event_dispatcher.hpp index d43f93f..fd58191 100644 --- a/src/events/event_dispatcher.hpp +++ b/src/events/event_dispatcher.hpp @@ -3,15 +3,14 @@ #include "event.hpp" -class EventDispatcher { -public: - EventDispatcher(Event& e) +struct event_dispatcher { + event_dispatcher(event& e) : m_Event(e) {} template - bool Dispatch(std::function func) { - if (m_Event.GetType() != T::GetStaticType()) + bool dispatch(std::function func) { + if (m_Event.get_type() != T::get_static_type()) return false; m_Event.Handled = func(*(T*)&m_Event); @@ -20,7 +19,7 @@ class EventDispatcher { } private: - Event& m_Event; + event& m_Event; }; #endif \ No newline at end of file diff --git a/src/events/key_event.hpp b/src/events/key_event.hpp index b735059..04d7a9e 100644 --- a/src/events/key_event.hpp +++ b/src/events/key_event.hpp @@ -3,12 +3,11 @@ #include "event.hpp" -class KeyEvent : public Event { -public: - int GetKeyCode() const { return m_KeyCode; } +struct key_event : public event { + int get_key_code() const { return m_KeyCode; } protected: - KeyEvent(int keycode) + key_event(int keycode) : m_KeyCode(keycode) {} @@ -16,23 +15,20 @@ class KeyEvent : public Event { int m_KeyCode; }; - -class KeyPressedEvent : public KeyEvent { -public: - KeyPressedEvent(int keycode) - : KeyEvent(keycode) +struct key_pressed_event : public key_event { + key_pressed_event(int keycode) + : key_event(keycode) {} - EVENT_CLASS_TYPE(KeyPressedEvent); + EVENT_CLASS_TYPE(key_pressed); }; -class KeyReleasedEvent : public KeyEvent { -public: - KeyReleasedEvent(int keycode) - : KeyEvent(keycode) +struct key_released_event : public key_event { + key_released_event(int keycode) + : key_event(keycode) {} - EVENT_CLASS_TYPE(KeyReleasedEvent); + EVENT_CLASS_TYPE(key_released); }; #endif \ No newline at end of file diff --git a/src/events/mouse_event.hpp b/src/events/mouse_event.hpp index 3affddd..6a4348c 100644 --- a/src/events/mouse_event.hpp +++ b/src/events/mouse_event.hpp @@ -3,12 +3,11 @@ #include "event.hpp" -class MouseButtonEvent : public Event { -public: - int GetButtonCode() const { return m_ButtonCode; } +struct mouse_button_event : public event { + int get_button_code() const { return m_ButtonCode; } protected: - MouseButtonEvent(int buttonCode) + mouse_button_event(int buttonCode) : m_ButtonCode(buttonCode) {} @@ -16,58 +15,52 @@ class MouseButtonEvent : public Event { int m_ButtonCode; }; -class MouseButtonPressedEvent : public MouseButtonEvent { -public: - MouseButtonPressedEvent(int buttonCode) - : MouseButtonEvent(buttonCode) +struct mouse_button_pressed_event : public mouse_button_event { + mouse_button_pressed_event(int buttonCode) + : mouse_button_event(buttonCode) {} - EVENT_CLASS_TYPE(MouseButtonPressedEvent); + EVENT_CLASS_TYPE(mouse_button_pressed); }; -class MouseButtonReleasedEvent : public MouseButtonEvent { -public: - MouseButtonReleasedEvent(int buttonCode) - : MouseButtonEvent(buttonCode) +struct mouse_button_released_event : public mouse_button_event { + mouse_button_released_event(int buttonCode) + : mouse_button_event(buttonCode) {} - EVENT_CLASS_TYPE(MouseButtonReleasedEvent); + EVENT_CLASS_TYPE(mouse_button_released); }; -class MouseMovedEvent : public Event { -public: - MouseMovedEvent(double x, double y) +struct mouse_moved_event : public event { + mouse_moved_event(double x, double y) : m_XPos(x), m_YPos(y) {} - double GetX() const { return m_XPos; } - double GetY() const { return m_YPos; } + double get_x() const { return m_XPos; } + double get_y() const { return m_YPos; } + + EVENT_CLASS_TYPE(mouse_moved); - EVENT_CLASS_TYPE(MouseMovedEvent); private: double m_XPos; double m_YPos; }; -class MouseEnteredEvent : public Event { -public: - EVENT_CLASS_TYPE(MouseEnteredEvent); +struct mouse_entered_event : public event { + EVENT_CLASS_TYPE(mouse_entered); }; -class MouseLeftEvent : public Event { -public: - EVENT_CLASS_TYPE(MouseLeftEvent); +struct mouse_left_event : public event { + EVENT_CLASS_TYPE(mouse_left); }; -class MouseScrolledUpEvent : public Event { -public: - EVENT_CLASS_TYPE(MouseScrolledUpEvent); +struct mouse_scrolled_up_event : public event { + EVENT_CLASS_TYPE(mouse_scrolled_up); }; -class MouseScrolledDownEvent : public Event { -public: - EVENT_CLASS_TYPE(MouseScrolledDownEvent); +struct mouse_scrolled_down_event : public event { + EVENT_CLASS_TYPE(mouse_scrolled_down); }; #endif \ No newline at end of file diff --git a/src/events/window_event.hpp b/src/events/window_event.hpp index 4a86027..1026663 100644 --- a/src/events/window_event.hpp +++ b/src/events/window_event.hpp @@ -3,21 +3,19 @@ #include "event.hpp" -class WindowClosedEvent : public Event { -public: - EVENT_CLASS_TYPE(WindowClosedEvent); +struct window_closed_event : public event { + EVENT_CLASS_TYPE(window_closed); }; -class WindowResizedEvent : public Event { -public: - WindowResizedEvent(uint32_t width, uint32_t height) +struct window_resized_event : public event { + window_resized_event(uint32_t width, uint32_t height) : m_Width(width), m_Height(height) {} uint32_t get_width() const { return m_Width; } uint32_t get_height() const { return m_Height; } - EVENT_CLASS_TYPE(WindowResizedEvent); + EVENT_CLASS_TYPE(window_resized); private: uint32_t m_Width; uint32_t m_Height; diff --git a/src/input.cpp b/src/input.cpp index d08bbec..8b645d3 100644 --- a/src/input.cpp +++ b/src/input.cpp @@ -15,8 +15,7 @@ bool is_mouse_button_down(int buttoncode) { return false; } -glm::vec2 get_mouse_position() -{ +glm::vec2 get_mouse_position() { // HACK: The renderer has a pointer to the window which we can use for now. const renderer_context_t* rc = get_renderer_context(); diff --git a/src/renderer/renderer.cpp b/src/renderer/renderer.cpp index b830467..e510802 100644 --- a/src/renderer/renderer.cpp +++ b/src/renderer/renderer.cpp @@ -3,10 +3,11 @@ #include "common.hpp" static renderer_context_t* g_rc = nullptr; -static BufferMode g_buffering{}; -static VSyncMode g_vsync{}; -static Swapchain g_swapchain{}; +static buffer_mode g_buffering{}; +static vsync_mode g_vsync{}; + +static swapchain_t g_swapchain{}; //static std::vector g_frames; VkCommandPool cmd_pool; @@ -51,14 +52,11 @@ static VkExtent2D get_surface_size(const VkSurfaceCapabilitiesKHR& surface) { // like to be created. It's important to remember that this is a request // and not guaranteed as the hardware may not support that number // of images. -static Swapchain CreateSwapchain() { - Swapchain swapchain{}; +static swapchain_t CreateSwapchain() { + swapchain_t swapchain{}; - // get surface properties - VkSurfaceCapabilitiesKHR surface_properties {}; - vk_check(vkGetPhysicalDeviceSurfaceCapabilitiesKHR(g_rc->device.gpu, - g_rc->surface, - &surface_properties)); + VkSurfaceCapabilitiesKHR surface_properties{}; + vk_check(vkGetPhysicalDeviceSurfaceCapabilitiesKHR(g_rc->device.gpu, g_rc->surface, &surface_properties)); VkSwapchainCreateInfoKHR swapchain_info { VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR }; swapchain_info.surface = g_rc->surface; @@ -114,33 +112,24 @@ static Swapchain CreateSwapchain() { image_buffer_t& image = swapchain.images[i]; image.handle = color_images[i]; - image.view = create_image_view(image.handle, - swapchain_info.imageFormat, - VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT); + image.view = create_image_view(image.handle, swapchain_info.imageFormat, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT); image.format = swapchain_info.imageFormat; image.extent = swapchain_info.imageExtent; } - // create depth buffer image -// swapchain.depth_image = create_image(VK_FORMAT_D32_SFLOAT, -// swapchain_info.imageExtent, -// VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT); - return swapchain; } -static void DestroySwapchain(Swapchain& swapchain) { -// destroy_image(swapchain.depth_image); - - for (auto& image : swapchain.images) { +static void DestroySwapchain(swapchain_t& swapchain) { + for (auto& image : swapchain.images) vkDestroyImageView(g_rc->device.device, image.view, nullptr); - } + swapchain.images.clear(); vkDestroySwapchainKHR(g_rc->device.device, swapchain.handle, nullptr); } -static void RebuildSwapchain(Swapchain& swapchain) { +static void RebuildSwapchain(swapchain_t& swapchain) { // Check if the window is minimized and if so then wait here. int width = 0, height = 0; glfwGetFramebufferSize(g_rc->window->handle, &width, &height); @@ -166,43 +155,12 @@ static void CreateFrameBarriers() { vk_check(vkCreateFence(g_rc->device.device, &fence_info, nullptr, &g_frame.submit_fence)); vk_check(vkCreateSemaphore(g_rc->device.device, &semaphore_info, nullptr, &g_frame.acquired_semaphore)); vk_check(vkCreateSemaphore(g_rc->device.device, &semaphore_info, nullptr, &g_frame.released_semaphore)); - -// g_frames.resize(g_swapchain.images.size()); -// for (auto& gFrame : g_frames) { -// // create rendering command pool and buffers -// vk_check(vkCreateCommandPool(g_rc->device.device, &pool_info, nullptr, -// &gFrame.cmd_pool)); -// -// VkCommandBufferAllocateInfo allocate_info{ VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO }; -// allocate_info.commandPool = gFrame.cmd_pool; -// allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; -// allocate_info.commandBufferCount = 1; -// vk_check(vkAllocateCommandBuffers(g_rc->device.device, &allocate_info, -// &gFrame.cmd_buffer)); -// -// -// // create sync objects -// vk_check(vkCreateFence(g_rc->device.device, &fence_info, nullptr, -// &gFrame.submit_fence)); -// vk_check( -// vkCreateSemaphore(g_rc->device.device, &semaphore_info, nullptr, -// &gFrame.acquired_semaphore)); -// vk_check( -// vkCreateSemaphore(g_rc->device.device, &semaphore_info, nullptr, -// &gFrame.released_semaphore)); -// } } static void DestroyFrameBarriers() { vkDestroySemaphore(g_rc->device.device, g_frame.released_semaphore, nullptr); vkDestroySemaphore(g_rc->device.device, g_frame.acquired_semaphore, nullptr); vkDestroyFence(g_rc->device.device, g_frame.submit_fence, nullptr); - -// for (auto& gFrame : g_frames) { -// -// vkFreeCommandBuffers(g_rc->device.device, gFrame.cmd_pool, 1, &gFrame.cmd_buffer); -// vkDestroyCommandPool(g_rc->device.device, gFrame.cmd_pool, nullptr); -// } } @@ -448,7 +406,7 @@ void destroy_descriptor_set_layout(VkDescriptorSetLayout layout) { vkDestroyDescriptorSetLayout(g_rc->device.device, layout, nullptr); } -std::vector allocate_descriptor_sets(VkDescriptorSetLayout layout, uint32_t frames) { +std::vector allocate_descriptor_set(VkDescriptorSetLayout layout, uint32_t frames) { std::vector descriptor_sets(frames); for (auto& descriptor_set : descriptor_sets) { @@ -479,8 +437,8 @@ VkDescriptorSet allocate_descriptor_set(VkDescriptorSetLayout layout) { return descriptor_set; } -Pipeline create_pipeline(PipelineInfo& pipelineInfo, VkRenderPass render_pass) { - Pipeline pipeline{}; +pipeline_t create_pipeline(PipelineInfo& pipelineInfo, VkRenderPass render_pass) { + pipeline_t pipeline{}; // push constant VkPushConstantRange push_constant{}; @@ -638,13 +596,13 @@ Pipeline create_pipeline(PipelineInfo& pipelineInfo, VkRenderPass render_pass) { } -void destroy_pipeline(Pipeline& pipeline) { +void destroy_pipeline(pipeline_t& pipeline) { vkDestroyPipeline(g_rc->device.device, pipeline.handle, nullptr); vkDestroyPipelineLayout(g_rc->device.device, pipeline.layout, nullptr); } -renderer_context_t* create_renderer(const window_t* window, BufferMode buffering_mode, VSyncMode sync_mode) { +renderer_context_t* create_renderer(const window_t* window, buffer_mode buffering_mode, vsync_mode sync_mode) { const std::vector layers { "VK_LAYER_KHRONOS_validation", #if defined(_WIN32) @@ -859,12 +817,12 @@ void end_render_pass(VkCommandBuffer buffer) { vk_check(vkEndCommandBuffer(buffer)); } -void bind_pipeline(VkCommandBuffer cmd_buffer, Pipeline& pipeline, VkDescriptorSet descriptorSets) { +void bind_pipeline(VkCommandBuffer cmd_buffer, pipeline_t& pipeline, VkDescriptorSet descriptorSets) { vkCmdBindPipeline(cmd_buffer, VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline.handle); vkCmdBindDescriptorSets(cmd_buffer, VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline.layout, 0, 1, &descriptorSets, 0, nullptr); } -void render(VkCommandBuffer cmd_buffer, instance_t& instance, Pipeline& pipeline) { +void render(VkCommandBuffer cmd_buffer, instance_t& instance, pipeline_t& pipeline) { vkCmdBindDescriptorSets(cmd_buffer, VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline.layout, 1, 1, &instance.descriptorSet, 0, nullptr); vkCmdPushConstants(cmd_buffer, pipeline.layout, VK_SHADER_STAGE_VERTEX_BIT, 0, sizeof(glm::mat4), &instance.matrix); vkCmdDrawIndexed(cmd_buffer, instance.model->index_count, 1, 0, 0, 0); diff --git a/src/renderer/renderer.hpp b/src/renderer/renderer.hpp index 169be89..2ca045e 100644 --- a/src/renderer/renderer.hpp +++ b/src/renderer/renderer.hpp @@ -14,18 +14,18 @@ static uint32_t currentImage = 0; -enum class BufferMode { +enum class buffer_mode { Double = 2, //Triple = 3 }; -enum class VSyncMode { +enum class vsync_mode { Disabled = VK_PRESENT_MODE_IMMEDIATE_KHR, Enabled = VK_PRESENT_MODE_FIFO_KHR }; -struct Swapchain { +struct swapchain_t { VkSwapchainKHR handle; std::vector images; @@ -62,7 +62,7 @@ struct PipelineInfo { VkCullModeFlags cull_mode; }; -struct Pipeline { +struct pipeline_t { VkPipelineLayout layout; VkPipeline handle; }; @@ -70,25 +70,21 @@ struct Pipeline { -renderer_context_t* create_renderer(const window_t* window, BufferMode buffering_mode, VSyncMode sync_mode); +renderer_context_t* create_renderer(const window_t* window, buffer_mode buffering_mode, vsync_mode sync_mode); void destroy_renderer(renderer_context_t* context); renderer_context_t* get_renderer_context(); VkDescriptorSetLayout create_descriptor_set_layout(const std::vector& bindings); void destroy_descriptor_set_layout(VkDescriptorSetLayout layout); -std::vector allocate_descriptor_sets(VkDescriptorSetLayout layout, uint32_t frames); -VkDescriptorSet allocate_descriptor_set(VkDescriptorSetLayout layout); -//void update_renderer_size(VulkanRenderer& renderer, uint32_t width, uint32_t height); +std::vector allocate_descriptor_set(VkDescriptorSetLayout layout, uint32_t frames); +VkDescriptorSet allocate_descriptor_set(VkDescriptorSetLayout layout); -// TEMP CODE VkRenderPass create_ui_render_pass(); std::vector create_ui_framebuffers(VkRenderPass render_pass, VkExtent2D extent); - - VkRenderPass create_render_pass(); std::vector create_framebuffers(VkRenderPass render_pass, image_buffer_t& images, @@ -103,8 +99,8 @@ void resize_framebuffers_color_and_depth(VkRenderPass render_pass, std::vector& framebuffers, VkExtent2D extent); -Pipeline create_pipeline(PipelineInfo& pipelineInfo, VkRenderPass render_pass); -void destroy_pipeline(Pipeline& pipeline); +pipeline_t create_pipeline(PipelineInfo& pipelineInfo, VkRenderPass render_pass); +void destroy_pipeline(pipeline_t& pipeline); bool begin_frame(); void end_frame(); @@ -115,7 +111,7 @@ VkCommandBuffer begin_viewport_render_pass(VkRenderPass render_pass, const std:: VkCommandBuffer begin_ui_render_pass(VkRenderPass render_pass, const std::vector& framebuffers); void end_render_pass(VkCommandBuffer cmd_buffer); -void bind_pipeline(VkCommandBuffer cmd_buffer, Pipeline& pipeline, VkDescriptorSet descriptorSets); -void render(VkCommandBuffer cmd_buffer, instance_t& instance, Pipeline& pipeline); +void bind_pipeline(VkCommandBuffer cmd_buffer, pipeline_t& pipeline, VkDescriptorSet descriptorSets); +void render(VkCommandBuffer cmd_buffer, instance_t& instance, pipeline_t& pipeline); #endif diff --git a/src/renderer/renderer_context.cpp b/src/renderer/renderer_context.cpp index 56633c0..6643cdb 100644 --- a/src/renderer/renderer_context.cpp +++ b/src/renderer/renderer_context.cpp @@ -269,7 +269,7 @@ static VkDescriptorPool create_descriptor_pool(device_t& device, const std::vect renderer_context_t* create_renderer_context(uint32_t version, const std::vector& requested_layers, const std::vector& requested_extensions, - const VkPhysicalDeviceFeatures requested_gpu_features, + const VkPhysicalDeviceFeatures& requested_gpu_features, const window_t* window) { auto context = (renderer_context_t*)malloc(sizeof(renderer_context_t)); diff --git a/src/renderer/renderer_context.hpp b/src/renderer/renderer_context.hpp index ee63e41..f64f987 100644 --- a/src/renderer/renderer_context.hpp +++ b/src/renderer/renderer_context.hpp @@ -39,7 +39,7 @@ struct renderer_context_t { renderer_context_t* create_renderer_context(uint32_t version, const std::vector& requested_layers, const std::vector& requested_extensions, - const VkPhysicalDeviceFeatures requested_gpu_features, + const VkPhysicalDeviceFeatures& requested_gpu_features, const window_t* window); void destroy_renderer_context(renderer_context_t* rc); diff --git a/src/renderer/texture.cpp b/src/renderer/texture.cpp index 6f3ceb9..ad37f09 100644 --- a/src/renderer/texture.cpp +++ b/src/renderer/texture.cpp @@ -20,7 +20,7 @@ TextureBuffer load_texture(const char* path, VkFormat format) { } // Store texture data into GPU memory. - buffer = CreateTextureBuffer(texture, width, height, format); + buffer = create_texture_buffer(texture, width, height, format); buffer.sampler = create_sampler(VK_FILTER_LINEAR, 16); buffer.descriptor.sampler = buffer.sampler; @@ -35,7 +35,7 @@ TextureBuffer load_texture(const char* path, VkFormat format) { } -TextureBuffer CreateTextureBuffer(unsigned char* texture, uint32_t width, uint32_t height, VkFormat format) { +TextureBuffer create_texture_buffer(unsigned char* texture, uint32_t width, uint32_t height, VkFormat format) { TextureBuffer buffer{}; const renderer_context_t* rc = get_renderer_context(); diff --git a/src/renderer/texture.hpp b/src/renderer/texture.hpp index b0bedcd..f015d4e 100644 --- a/src/renderer/texture.hpp +++ b/src/renderer/texture.hpp @@ -15,7 +15,7 @@ struct TextureBuffer { TextureBuffer load_texture(const char* path, VkFormat format); -TextureBuffer CreateTextureBuffer(unsigned char* texture, uint32_t width, uint32_t height, VkFormat format); +TextureBuffer create_texture_buffer(unsigned char* texture, uint32_t width, uint32_t height, VkFormat format); void destroy_texture_buffer(TextureBuffer& texture); VkSampler create_sampler(VkFilter filtering, uint32_t anisotropic_level); diff --git a/src/renderer/ui.cpp b/src/renderer/ui.cpp index 22ff877..39af054 100644 --- a/src/renderer/ui.cpp +++ b/src/renderer/ui.cpp @@ -102,8 +102,7 @@ ImGuiContext* create_user_interface(VkRenderPass renderPass) { // Submit ImGui fonts to the GPU in order to be used during rendering. - submit_to_gpu( - [&] { ImGui_ImplVulkan_CreateFontsTexture(rc->submit.CmdBuffer); }); + submit_to_gpu([&] { ImGui_ImplVulkan_CreateFontsTexture(rc->submit.CmdBuffer); }); ImGui_ImplVulkan_DestroyFontUploadObjects(); diff --git a/src/renderer/vertex_array.cpp b/src/renderer/vertex_array.cpp index c532185..71f9487 100644 --- a/src/renderer/vertex_array.cpp +++ b/src/renderer/vertex_array.cpp @@ -14,10 +14,8 @@ vertex_array_t create_vertex_array(void* v, int vs, void* i, int is) { buffer_t vertexStagingBuffer = create_staging_buffer(v, vs); buffer_t indexStagingBuffer = create_staging_buffer(i, is); - vertexArray.vertex_buffer = create_gpu_buffer(vs, - VK_BUFFER_USAGE_VERTEX_BUFFER_BIT); - vertexArray.index_buffer = create_gpu_buffer(is, - VK_BUFFER_USAGE_INDEX_BUFFER_BIT); + vertexArray.vertex_buffer = create_gpu_buffer(vs, VK_BUFFER_USAGE_VERTEX_BUFFER_BIT); + vertexArray.index_buffer = create_gpu_buffer(is, VK_BUFFER_USAGE_INDEX_BUFFER_BIT); vertexArray.index_count = is / sizeof(uint32_t); // todo: Maybe be unsafe for a hard coded type. // Upload data to the GPU diff --git a/src/window.cpp b/src/window.cpp index 2b51a45..a90aef4 100644 --- a/src/window.cpp +++ b/src/window.cpp @@ -5,91 +5,89 @@ #include "events/mouse_event.hpp" - - -static void GLFWErrorCallback(int code, const char* description) { +static void glfw_error_callback(int code, const char* description) { printf("(%d) %s\n", code, description); } -static void WindowCloseCallback(GLFWwindow* window) { +static void window_close_callback(GLFWwindow* window) { window_t* ptr = (window_t*)glfwGetWindowUserPointer(window); - WindowClosedEvent e; + window_closed_event e; ptr->event_callback(e); } -static void WindowResizeCallback(GLFWwindow* window, int width, int height) { +static void window_resize_callback(GLFWwindow* window, int width, int height) { // todo: window resizing is done within the framebuffer callback since that // todo: returns the actual pixel count of the display. This ensures that // todo: for monitors with a high DPI we return the real pixels. } -static void WindowFramebufferResizeCallback(GLFWwindow* window, int width, int height) { +static void window_framebuffer_resize_callback(GLFWwindow* window, int width, int height) { window_t* ptr = (window_t*)glfwGetWindowUserPointer(window); ptr->width = width; ptr->height = height; - WindowResizedEvent e(width, height); + window_resized_event e(width, height); ptr->event_callback(e); } -static void WindowKeyCallback(GLFWwindow* window, int key, int scancode, int action, int mods) { +static void window_key_callback(GLFWwindow* window, int key, int scancode, int action, int mods) { window_t* ptr = (window_t*)glfwGetWindowUserPointer(window); if (action == GLFW_PRESS) { - KeyPressedEvent e(key); + key_pressed_event e(key); ptr->event_callback(e); } else if (action == GLFW_REPEAT) { - KeyPressedEvent e(key); + key_released_event e(key); ptr->event_callback(e); } else if (action == GLFW_RELEASE) { - KeyReleasedEvent e(key); + key_released_event e(key); ptr->event_callback(e); } } -static void WindowMouseButtonCallback(GLFWwindow* window, int button, int action, int mods) { +static void window_mouse_button_callback(GLFWwindow* window, int button, int action, int mods) { window_t* ptr = (window_t*)glfwGetWindowUserPointer(window); if (action == GLFW_PRESS) { - MouseButtonPressedEvent e(button); + mouse_button_pressed_event e(button); ptr->event_callback(e); } else if (action == GLFW_REPEAT) { - MouseButtonPressedEvent e(button); + mouse_button_pressed_event e(button); ptr->event_callback(e); } else if (action == GLFW_RELEASE) { - MouseButtonReleasedEvent e(button); + mouse_button_released_event e(button); ptr->event_callback(e); } } -static void WindowMouseScrollCallback(GLFWwindow* window, double xoffset, double yoffset) { +static void window_mouse_scroll_callback(GLFWwindow* window, double xoffset, double yoffset) { window_t* ptr = (window_t*)glfwGetWindowUserPointer(window); if (yoffset == 1.0) { - MouseScrolledUpEvent e; + mouse_scrolled_up_event e; ptr->event_callback(e); } else if (yoffset == -1.0) { - MouseScrolledDownEvent e; + mouse_scrolled_down_event e; ptr->event_callback(e); } } -static void WindowCursorPosCallback(GLFWwindow* window, double xpos, double ypos) { +static void window_cursor_pos_callback(GLFWwindow* window, double xpos, double ypos) { window_t* ptr = (window_t*)glfwGetWindowUserPointer(window); - MouseMovedEvent e(xpos, ypos); + mouse_moved_event e(xpos, ypos); ptr->event_callback(e); } -static void WindowCursorEnterCallback(GLFWwindow* window, int entered) { +static void window_cursor_enter_callback(GLFWwindow* window, int entered) { window_t* ptr = (window_t*)glfwGetWindowUserPointer(window); if (entered) { - MouseEnteredEvent e; + mouse_entered_event e; ptr->event_callback(e); } else { - MouseLeftEvent e; + mouse_left_event e; ptr->event_callback(e); } } @@ -99,7 +97,7 @@ static void WindowCursorEnterCallback(GLFWwindow* window, int entered) { window_t* create_window(const char* name, uint32_t width, uint32_t height) { window_t* window = new window_t(); - glfwSetErrorCallback(GLFWErrorCallback); + glfwSetErrorCallback(glfw_error_callback); if (!glfwInit()) return nullptr; @@ -119,16 +117,16 @@ window_t* create_window(const char* name, uint32_t width, uint32_t height) { // window callbacks glfwSetWindowUserPointer(window->handle, window); - glfwSetWindowCloseCallback(window->handle, WindowCloseCallback); - glfwSetWindowSizeCallback(window->handle, WindowResizeCallback); - glfwSetFramebufferSizeCallback(window->handle, WindowFramebufferResizeCallback); + glfwSetWindowCloseCallback(window->handle, window_close_callback); + glfwSetWindowSizeCallback(window->handle, window_resize_callback); + glfwSetFramebufferSizeCallback(window->handle, window_framebuffer_resize_callback); // input callbacks - glfwSetKeyCallback(window->handle, WindowKeyCallback); - glfwSetMouseButtonCallback(window->handle, WindowMouseButtonCallback); - glfwSetScrollCallback(window->handle, WindowMouseScrollCallback); - glfwSetCursorPosCallback(window->handle, WindowCursorPosCallback); - glfwSetCursorEnterCallback(window->handle, WindowCursorEnterCallback); + glfwSetKeyCallback(window->handle, window_key_callback); + glfwSetMouseButtonCallback(window->handle, window_mouse_button_callback); + glfwSetScrollCallback(window->handle, window_mouse_scroll_callback); + glfwSetCursorPosCallback(window->handle, window_cursor_pos_callback); + glfwSetCursorEnterCallback(window->handle, window_cursor_enter_callback); return window; }