From 87ad4d5eb9e95d67779184a209311ba6524a51d9 Mon Sep 17 00:00:00 2001 From: Nanako <469449812@qq.com> Date: Mon, 19 Feb 2024 01:33:18 +0800 Subject: [PATCH] =?UTF-8?q?=E6=A0=BC=E5=BC=8F=E5=8C=96=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/application/application.cpp | 18 +++---- core/application/application.h | 30 +++++------ core/application/command_line.cpp | 10 ++-- core/application/command_line.h | 12 ++--- core/misc/ref_counting.h | 50 +++++++++---------- core/misc/scope_exit.h | 16 +++--- .../rhi/opengl/pixel_shader_drawer_opengl.cpp | 14 +++--- core/rhi/opengl/render_target_opengl.cpp | 2 +- core/rhi/opengl/render_target_opengl.h | 6 +-- core/rhi/opengl/renderer_opengl.cpp | 10 ++-- core/rhi/opengl/renderer_opengl.h | 10 ++-- core/rhi/opengl/shader/shader_opengl.cpp | 8 +-- core/rhi/opengl/shader/shader_opengl.h | 12 ++--- .../opengl/shader/shader_program_opengl.cpp | 30 +++++------ .../rhi/opengl/shader/shader_program_opengl.h | 24 ++++----- core/rhi/opengl/texture_opengl.cpp | 2 +- core/rhi/opengl/texture_opengl.h | 4 +- core/rhi/render_target.h | 2 +- core/rhi/renderer.cpp | 6 +-- core/rhi/renderer.h | 10 ++-- core/rhi/rhi_defintion.h | 3 +- core/rhi/shader.h | 28 +++++------ core/rhi/texture.h | 2 +- 23 files changed, 153 insertions(+), 156 deletions(-) diff --git a/core/application/application.cpp b/core/application/application.cpp index d662401..8a3e6e7 100644 --- a/core/application/application.cpp +++ b/core/application/application.cpp @@ -14,16 +14,16 @@ bool g_is_running = true; bool g_exit_requested = false; -application *g_app_instance = nullptr; +application* g_app_instance = nullptr; -static void glfw_error_callback(int error, const char *description) { +static void glfw_error_callback(int error, const char* description) { spdlog::error("Glfw Error {}: {}", error, description); } -void application::init(window_params in_window_params, int argc, char **argv) { +void application::init(window_params in_window_params, int argc, char** argv) { try { async_spdlog_ = spdlog::basic_logger_mt("async_file_logger", "logs/log.txt"); - } catch (const spdlog::spdlog_ex &ex) { + } catch (const spdlog::spdlog_ex& ex) { std::cout << "Log init failed: " << ex.what() << std::endl; } @@ -35,7 +35,7 @@ void application::init(window_params in_window_params, int argc, char **argv) { renderer_->pre_init(); - // new SDL window + // new glfw window window_ = glfwCreateWindow(in_window_params.width, in_window_params.height, in_window_params.title.c_str(), nullptr, nullptr); if (!window_) { @@ -75,10 +75,10 @@ void application::shutdown() { destroy_glfw(); } -std::shared_ptr application::load_texture(const std::string &path) const { +std::shared_ptr application::load_texture(const std::string& path) const { int width = 0; int height = 0; - unsigned char *image_data = stbi_load(path.c_str(), &width, &height, nullptr, 4); + unsigned char* image_data = stbi_load(path.c_str(), &width, &height, nullptr, 4); if (!image_data) { spdlog::error("Failed to load texture: {}", path.c_str()); return nullptr; @@ -89,7 +89,7 @@ std::shared_ptr application::load_texture(const std::string &path) cons } std::shared_ptr -application::create_texture(const unsigned char *data, const int width, const int height) const { +application::create_texture(const unsigned char* data, const int width, const int height) const { return renderer_->create_texture(data, width, height); } @@ -114,7 +114,7 @@ void application::init_imgui() { // Setup Dear ImGui context IMGUI_CHECKVERSION(); init_imgui(ImGui::CreateContext()); - ImGuiIO &io = ImGui::GetIO(); + ImGuiIO& io = ImGui::GetIO(); io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; // Enable Keyboard Controls io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad; // Enable Gamepad Controls ImGui::StyleColorsDark(); diff --git a/core/application/application.h b/core/application/application.h index 2ec0047..378b24e 100644 --- a/core/application/application.h +++ b/core/application/application.h @@ -11,7 +11,7 @@ class application; extern bool g_is_running; extern bool g_exit_requested; -extern application *g_app_instance; +extern application* g_app_instance; struct window_params { std::string title; @@ -34,15 +34,15 @@ public: virtual ~application() = default; - application(const application &) = delete; + application(const application&) = delete; - application(application &&) = delete; + application(application&&) = delete; - static application *get() { + static application* get() { return g_app_instance; } - virtual void init(window_params in_window_params, int argc, char **argv); + virtual void init(window_params in_window_params, int argc, char** argv); virtual int run(); @@ -50,29 +50,29 @@ public: virtual void draw_gui() = 0; - virtual const char *get_shader_path() = 0; + virtual const char* get_shader_path() = 0; - virtual void init_imgui(ImGuiContext *in_context) = 0; + virtual void init_imgui(ImGuiContext* in_context) = 0; - [[nodiscard]] std::shared_ptr load_texture(const std::string &path) const; + [[nodiscard]] std::shared_ptr load_texture(const std::string& path) const; - std::shared_ptr create_texture(const unsigned char *data, int width, int height) const; + std::shared_ptr create_texture(const unsigned char* data, int width, int height) const; [[nodiscard]] std::shared_ptr create_render_target(int width, int height, texture_format format) const; [[nodiscard]] std::shared_ptr create_pixel_shader_drawer() const; - [[nodiscard]] virtual const char *get_entry_model() const = 0; + [[nodiscard]] virtual const char* get_entry_model() const = 0; - [[nodiscard]] virtual const char *get_draw_ps_vertex_shader_entry() const = 0; // Vertex Shader used for drawing ps + [[nodiscard]] virtual const char* get_draw_ps_vertex_shader_entry() const = 0; // Vertex Shader used for drawing ps - [[nodiscard]] renderer *get_renderer() const { return renderer_; } - [[nodiscard]] GLFWwindow *get_window() const { return window_; } + [[nodiscard]] renderer* get_renderer() const { return renderer_; } + [[nodiscard]] GLFWwindow* get_window() const { return window_; } protected: - renderer *renderer_ = nullptr; - GLFWwindow *window_ = nullptr; + renderer* renderer_ = nullptr; + GLFWwindow* window_ = nullptr; std::shared_ptr async_spdlog_; private: diff --git a/core/application/command_line.cpp b/core/application/command_line.cpp index 1d83925..cc05756 100644 --- a/core/application/command_line.cpp +++ b/core/application/command_line.cpp @@ -1,6 +1,6 @@ #include "command_line.h" -void command_line::init(int argc, char **argv) { +void command_line::init(int argc, char** argv) { // parser argv args_.clear(); for (int i = 0; i < argc; ++i) { @@ -20,7 +20,7 @@ void command_line::init(int argc, char **argv) { } } -void command_line::get_arg(const std::string &key, std::string &out) const { +void command_line::get_arg(const std::string& key, std::string& out) const { const auto it = args_.find(key); if (it != args_.end()) { out = it->second; @@ -29,7 +29,7 @@ void command_line::get_arg(const std::string &key, std::string &out) const { } } -void command_line::get_arg(const std::string &key, int &out) const { +void command_line::get_arg(const std::string& key, int& out) const { const auto it = args_.find(key); if (it != args_.end()) { out = std::stoi(it->second); @@ -38,7 +38,7 @@ void command_line::get_arg(const std::string &key, int &out) const { } } -void command_line::get_arg(const std::string &key, float &out) const { +void command_line::get_arg(const std::string& key, float& out) const { const auto it = args_.find(key); if (it != args_.end()) { out = std::stof(it->second); @@ -47,7 +47,7 @@ void command_line::get_arg(const std::string &key, float &out) const { } } -void command_line::get_arg(const std::string &key, bool &out) const { +void command_line::get_arg(const std::string& key, bool& out) const { const auto it = args_.find(key); if (it != args_.end()) { out = it->second != "false"; diff --git a/core/application/command_line.h b/core/application/command_line.h index 371bc0e..6b17ddf 100644 --- a/core/application/command_line.h +++ b/core/application/command_line.h @@ -4,20 +4,20 @@ class command_line { public: - static command_line &instance() { + static command_line& instance() { static command_line instance; return instance; } - void init(int argc, char **argv); + void init(int argc, char** argv); - void get_arg(const std::string &key, std::string &out) const; + void get_arg(const std::string& key, std::string& out) const; - void get_arg(const std::string &key, int &out) const; + void get_arg(const std::string& key, int& out) const; - void get_arg(const std::string &key, float &out) const; + void get_arg(const std::string& key, float& out) const; - void get_arg(const std::string &key, bool &out) const; + void get_arg(const std::string& key, bool& out) const; private: std::map args_; // key-value pairs diff --git a/core/misc/ref_counting.h b/core/misc/ref_counting.h index b64ae66..dd30ae8 100644 --- a/core/misc/ref_counting.h +++ b/core/misc/ref_counting.h @@ -6,20 +6,20 @@ */ template class ref_count_ptr { - typedef ReferencedType *reference_type; + typedef ReferencedType* reference_type; public: ref_count_ptr(): reference_(nullptr) { } - explicit ref_count_ptr(ReferencedType *in_reference, bool bAddRef = true) { + explicit ref_count_ptr(ReferencedType* in_reference, bool bAddRef = true) { reference_ = in_reference; if (reference_ && bAddRef) { reference_->AddRef(); } } - ref_count_ptr(const ref_count_ptr ©) { + ref_count_ptr(const ref_count_ptr& copy) { reference_ = copy.reference_; if (reference_) { reference_->AddRef(); @@ -27,21 +27,21 @@ public: } template - explicit ref_count_ptr(const ref_count_ptr ©) { - reference_ = static_cast(copy.get_reference()); + explicit ref_count_ptr(const ref_count_ptr& copy) { + reference_ = static_cast(copy.get_reference()); if (reference_) { reference_->AddRef(); } } - ref_count_ptr(ref_count_ptr &&move) noexcept { + ref_count_ptr(ref_count_ptr&& move) noexcept { reference_ = move.reference_; move.reference_ = nullptr; } template - explicit ref_count_ptr(ref_count_ptr &&move) { - reference_ = static_cast(move.get_reference()); + explicit ref_count_ptr(ref_count_ptr&& move) { + reference_ = static_cast(move.get_reference()); move.reference_ = nullptr; } @@ -51,10 +51,10 @@ public: } } - ref_count_ptr &operator=(ReferencedType *in_reference) { + ref_count_ptr& operator=(ReferencedType* in_reference) { if (reference_ != in_reference) { // Call AddRef before Release, in case the new reference is the same as the old reference. - ReferencedType *old_reference = reference_; + ReferencedType* old_reference = reference_; reference_ = in_reference; if (reference_) { reference_->AddRef(); @@ -66,18 +66,18 @@ public: return *this; } - ref_count_ptr &operator=(const ref_count_ptr &in_ptr) { + ref_count_ptr& operator=(const ref_count_ptr& in_ptr) { return *this = in_ptr.reference_; } template - ref_count_ptr &operator=(const ref_count_ptr &in_ptr) { + ref_count_ptr& operator=(const ref_count_ptr& in_ptr) { return *this = in_ptr.GetReference(); } - ref_count_ptr &operator=(ref_count_ptr &&in_ptr) noexcept { + ref_count_ptr& operator=(ref_count_ptr&& in_ptr) noexcept { if (this != &in_ptr) { - ReferencedType *old_reference = reference_; + ReferencedType* old_reference = reference_; reference_ = in_ptr.reference_; in_ptr.reference_ = nullptr; if (old_reference) { @@ -88,9 +88,9 @@ public: } template - ref_count_ptr &operator=(ref_count_ptr &&in_ptr) { + ref_count_ptr& operator=(ref_count_ptr&& in_ptr) { // InPtr is a different type (or we would have called the other operator), so we need not test &InPtr != this - ReferencedType *old_reference = reference_; + ReferencedType* old_reference = reference_; reference_ = in_ptr.reference_; in_ptr.reference_ = nullptr; if (old_reference) { @@ -99,7 +99,7 @@ public: return *this; } - ReferencedType *operator->() const { + ReferencedType* operator->() const { return reference_; } @@ -107,16 +107,16 @@ public: return reference_; } - ReferencedType **get_init_reference() { + ReferencedType** get_init_reference() { *this = nullptr; return &reference_; } - ReferencedType *get_reference() const { + ReferencedType* get_reference() const { return reference_; } - friend bool is_valid_ref(const ref_count_ptr &in_reference) { + friend bool is_valid_ref(const ref_count_ptr& in_reference) { return in_reference.reference_ != nullptr; } @@ -138,9 +138,9 @@ public: return result; } - void swap(ref_count_ptr &in_ptr) noexcept // this does not change the reference count, and so is faster + void swap(ref_count_ptr& in_ptr) noexcept // this does not change the reference count, and so is faster { - ReferencedType *old_reference = reference_; + ReferencedType* old_reference = reference_; reference_ = in_ptr.reference_; in_ptr.reference_ = old_reference; } @@ -156,17 +156,17 @@ public: // } private: - ReferencedType *reference_; + ReferencedType* reference_; template friend class ref_count_ptr; public: - bool operator==(const ref_count_ptr &b) const { + bool operator==(const ref_count_ptr& b) const { return get_reference() == b.get_reference(); } - bool operator==(ReferencedType *b) const { + bool operator==(ReferencedType* b) const { return get_reference() == b; } }; diff --git a/core/misc/scope_exit.h b/core/misc/scope_exit.h index 4a5c51a..e825e85 100644 --- a/core/misc/scope_exit.h +++ b/core/misc/scope_exit.h @@ -10,18 +10,18 @@ namespace scope_exit_support { */ template class scope_guard { - scope_guard(scope_guard &&) = delete; + scope_guard(scope_guard&&) = delete; - scope_guard(const scope_guard &) = delete; + scope_guard(const scope_guard&) = delete; - scope_guard &operator=(scope_guard &&) = delete; + scope_guard& operator=(scope_guard&&) = delete; - scope_guard &operator=(const scope_guard &) = delete; + scope_guard& operator=(const scope_guard&) = delete; public: // Given a lambda, constructs an RAII scope guard. - explicit scope_guard(FuncType &&InFunc) - : func_((FuncType &&) InFunc) { + explicit scope_guard(FuncType&& InFunc) + : func_((FuncType&&) InFunc) { } // Causes the lambda to be executed. @@ -36,8 +36,8 @@ namespace scope_exit_support { struct scope_guard_syntax_support { template - scope_guard operator+(FuncType &&in_func) { - return scope_guard((FuncType &&) in_func); + scope_guard operator+(FuncType&& in_func) { + return scope_guard((FuncType&&) in_func); } }; } diff --git a/core/rhi/opengl/pixel_shader_drawer_opengl.cpp b/core/rhi/opengl/pixel_shader_drawer_opengl.cpp index 9c3e264..a1c203c 100644 --- a/core/rhi/opengl/pixel_shader_drawer_opengl.cpp +++ b/core/rhi/opengl/pixel_shader_drawer_opengl.cpp @@ -5,9 +5,9 @@ #include "shader/shader_ps_opengl.h" #include "shader/shader_vs_opengl.h" -void ps_opengl_compute_callback(const ImDrawList *parent_list, const ImDrawCmd *cmd) { - const auto data = static_cast(cmd->UserCallbackData); - const std::shared_ptr &rt = data->rt; +void ps_opengl_compute_callback(const ImDrawList* parent_list, const ImDrawCmd* cmd) { + const auto data = static_cast(cmd->UserCallbackData); + const std::shared_ptr& rt = data->rt; const auto program = data->program; program->use_program(); @@ -37,10 +37,10 @@ void ps_opengl_compute_callback(const ImDrawList *parent_list, const ImDrawCmd * glScissor(0, 0, width, height); // glScissor((int)clip_min.x, (int)(0 - clip_max.y), (int)(clip_max.x - clip_min.x), (int)(clip_max.y - clip_min.y)); - ImDrawVert &vert1 = data->vtx_buffer[0]; - ImDrawVert &vert2 = data->vtx_buffer[1]; - ImDrawVert &vert3 = data->vtx_buffer[2]; - ImDrawVert &vert4 = data->vtx_buffer[3]; + ImDrawVert& vert1 = data->vtx_buffer[0]; + ImDrawVert& vert2 = data->vtx_buffer[1]; + ImDrawVert& vert3 = data->vtx_buffer[2]; + ImDrawVert& vert4 = data->vtx_buffer[3]; vert1.pos = ImVec2(0, 0); vert2.pos = ImVec2(width, 0); vert3.pos = ImVec2(width, height); diff --git a/core/rhi/opengl/render_target_opengl.cpp b/core/rhi/opengl/render_target_opengl.cpp index 8240060..fec7ae7 100644 --- a/core/rhi/opengl/render_target_opengl.cpp +++ b/core/rhi/opengl/render_target_opengl.cpp @@ -112,7 +112,7 @@ render_target_opengl::~render_target_opengl() { glDeleteTextures(1, &texture_); } -void *render_target_opengl::lock(lock_state state) { +void* render_target_opengl::lock(lock_state state) { locked_texture_ = malloc(width_ * height_ * 4); switch (state) { case lock_state::READ: diff --git a/core/rhi/opengl/render_target_opengl.h b/core/rhi/opengl/render_target_opengl.h index e10eceb..3a9ae48 100644 --- a/core/rhi/opengl/render_target_opengl.h +++ b/core/rhi/opengl/render_target_opengl.h @@ -8,12 +8,12 @@ public: ~render_target_opengl() override; - ImTextureID get_texture_id() override { return (void *) static_cast(texture_); } + ImTextureID get_texture_id() override { return (void*) static_cast(texture_); } [[nodiscard]] GLuint get_fbo() const { return fbo_; } [[nodiscard]] GLuint get_texture() const { return texture_; } [[nodiscard]] GLint get_internal_format() const { return internal_format_; } - void *lock(lock_state state) override; + void* lock(lock_state state) override; void unlock() override; @@ -24,5 +24,5 @@ private: GLuint fbo_ = 0; GLuint texture_ = 0; GLint internal_format_ = 0; - void *locked_texture_ = nullptr; + void* locked_texture_ = nullptr; }; diff --git a/core/rhi/opengl/renderer_opengl.cpp b/core/rhi/opengl/renderer_opengl.cpp index 4d3f528..18217c3 100644 --- a/core/rhi/opengl/renderer_opengl.cpp +++ b/core/rhi/opengl/renderer_opengl.cpp @@ -35,7 +35,7 @@ void renderer_opengl::pre_init() { #endif } -bool renderer_opengl::init(GLFWwindow *window_handle) { +bool renderer_opengl::init(GLFWwindow* window_handle) { if (has_initialized_) return true; @@ -72,7 +72,7 @@ void renderer_opengl::post_shutdown() { renderer::post_shutdown(); } -std::shared_ptr renderer_opengl::load_shader(const std::string &entry_name) { +std::shared_ptr renderer_opengl::load_shader(const std::string& entry_name) { return nullptr; } @@ -80,14 +80,14 @@ std::shared_ptr renderer_opengl::create_pixel_shader_drawer return std::make_shared(); } -void renderer_opengl::new_frame(GLFWwindow *window_handle) { +void renderer_opengl::new_frame(GLFWwindow* window_handle) { // Start the Dear ImGui frame ImGui_ImplOpenGL3_NewFrame(); ImGui_ImplGlfw_NewFrame(); ImGui::NewFrame(); } -void renderer_opengl::end_frame(GLFWwindow *window_handle) { +void renderer_opengl::end_frame(GLFWwindow* window_handle) { // Rendering ImGui::Render(); int display_w, display_h; @@ -104,7 +104,7 @@ void renderer_opengl::end_frame(GLFWwindow *window_handle) { void renderer_opengl::resize(int width, int height) { } -std::shared_ptr renderer_opengl::create_texture(const unsigned char *data, int width, int height) { +std::shared_ptr renderer_opengl::create_texture(const unsigned char* data, int width, int height) { auto out = std::make_shared(); if (!out->init_data(data, width, height)) { out = nullptr; diff --git a/core/rhi/opengl/renderer_opengl.h b/core/rhi/opengl/renderer_opengl.h index a014150..2216633 100644 --- a/core/rhi/opengl/renderer_opengl.h +++ b/core/rhi/opengl/renderer_opengl.h @@ -5,23 +5,23 @@ class renderer_opengl : public renderer { public: void pre_init() override; - bool init(GLFWwindow *window_handle) override; + bool init(GLFWwindow* window_handle) override; void shutdown() override; void post_shutdown() override; - std::shared_ptr load_shader(const std::string &entry_name) override; + std::shared_ptr load_shader(const std::string& entry_name) override; std::shared_ptr create_pixel_shader_drawer() override; - void new_frame(GLFWwindow *window_handle) override; + void new_frame(GLFWwindow* window_handle) override; - void end_frame(GLFWwindow *window_handle) override; + void end_frame(GLFWwindow* window_handle) override; void resize(int width, int height) override; - std::shared_ptr create_texture(const unsigned char *data, int width, int height) override; + std::shared_ptr create_texture(const unsigned char* data, int width, int height) override; std::shared_ptr create_render_target(int width, int height, texture_format format) override; diff --git a/core/rhi/opengl/shader/shader_opengl.cpp b/core/rhi/opengl/shader/shader_opengl.cpp index 4e33806..cb35396 100644 --- a/core/rhi/opengl/shader/shader_opengl.cpp +++ b/core/rhi/opengl/shader/shader_opengl.cpp @@ -42,22 +42,22 @@ void shader_opengl::set_using_program(std::shared_ptr in_ using_program_ = in_program; } -void shader_opengl::set_cbuffer(const char *name, void *buffer, int size) { +void shader_opengl::set_cbuffer(const char* name, void* buffer, int size) { if (const auto program = using_program_.lock()) program->set_uniform(name, buffer, size); } -void shader_opengl::set_uav_buffer(const char *name, void *buffer, int size, int element_size) { +void shader_opengl::set_uav_buffer(const char* name, void* buffer, int size, int element_size) { if (const auto program = using_program_.lock()) program->set_ssbo(name, buffer, size, element_size); } -void shader_opengl::set_render_target(const char *name, std::shared_ptr in_render_target) { +void shader_opengl::set_render_target(const char* name, std::shared_ptr in_render_target) { if (const auto program = using_program_.lock()) program->set_render_target(name, in_render_target); } -void shader_opengl::set_texture(const char *name, std::shared_ptr in_texture) { +void shader_opengl::set_texture(const char* name, std::shared_ptr in_texture) { if (const auto program = using_program_.lock()) program->set_texture(name, in_texture); } diff --git a/core/rhi/opengl/shader/shader_opengl.h b/core/rhi/opengl/shader/shader_opengl.h index e54d5d4..269b62f 100644 --- a/core/rhi/opengl/shader/shader_opengl.h +++ b/core/rhi/opengl/shader/shader_opengl.h @@ -36,20 +36,20 @@ public: void set_using_program(std::shared_ptr in_program); - void set_cbuffer(const char *name, void *buffer, int size) override; + void set_cbuffer(const char* name, void* buffer, int size) override; - void set_uav_buffer(const char *name, void *buffer, int size, int element_size) override; + void set_uav_buffer(const char* name, void* buffer, int size, int element_size) override; - void set_render_target(const char *name, std::shared_ptr in_render_target) override; + void set_render_target(const char* name, std::shared_ptr in_render_target) override; - void set_texture(const char *name, std::shared_ptr in_texture) override; + void set_texture(const char* name, std::shared_ptr in_texture) override; [[nodiscard]] virtual GLenum get_shader_type() const = 0; [[nodiscard]] GLuint get_shader_id() const { return shader_id_; } - [[nodiscard]] const std::map &get_uniform_map() const { return uniform_map_; } - [[nodiscard]] const std::map &get_texture_map() const { return texture_map_; } + [[nodiscard]] const std::map& get_uniform_map() const { return uniform_map_; } + [[nodiscard]] const std::map& get_texture_map() const { return texture_map_; } protected: GLuint shader_id_; diff --git a/core/rhi/opengl/shader/shader_program_opengl.cpp b/core/rhi/opengl/shader/shader_program_opengl.cpp index e800e9e..86ccbaa 100644 --- a/core/rhi/opengl/shader/shader_program_opengl.cpp +++ b/core/rhi/opengl/shader/shader_program_opengl.cpp @@ -105,7 +105,7 @@ bool shader_program_opengl::create_program(std::shared_ptr in_com } void shader_program_opengl::destroy_program() { - for (const auto &val: ubo_map_ | std::views::values) + for (const auto& val: ubo_map_ | std::views::values) glDeleteBuffers(1, &val); if (const auto shader = pixel_shader_.lock()) @@ -123,12 +123,12 @@ void shader_program_opengl::destroy_program() { texture_map_.clear(); } -void shader_program_opengl::set_uniform(const char *slang_name, void *buffer, int size) { - const auto &uniform_name = uniform_map_.find(slang_name); +void shader_program_opengl::set_uniform(const char* slang_name, void* buffer, int size) { + const auto& uniform_name = uniform_map_.find(slang_name); if (uniform_name == uniform_map_.end()) return; - const auto &uniform_data = uniform_name->second; + const auto& uniform_data = uniform_name->second; GLuint using_bind_point = uniform_data.binding; const auto find_ubo = ubo_map_.find(using_bind_point); if (find_ubo != ubo_map_.end()) { @@ -152,11 +152,11 @@ void shader_program_opengl::set_uniform(const char *slang_name, void *buffer, in ubo_map_.insert(std::pair(using_bind_point, ubo)); } -void shader_program_opengl::set_ssbo(const char *slang_name, void *buffer, int size, int element_size) { - const auto &uniform_name = uniform_map_.find(slang_name); +void shader_program_opengl::set_ssbo(const char* slang_name, void* buffer, int size, int element_size) { + const auto& uniform_name = uniform_map_.find(slang_name); if (uniform_name == uniform_map_.end()) return; - const auto &uniform_data = uniform_name->second; + const auto& uniform_data = uniform_name->second; const GLint location = glGetProgramResourceIndex(program_id_, GL_SHADER_STORAGE_BLOCK, uniform_data.name.c_str()); if (location == -1) { spdlog::error("Failed to find ssbo: {}", slang_name); @@ -164,32 +164,32 @@ void shader_program_opengl::set_ssbo(const char *slang_name, void *buffer, int s } } -void shader_program_opengl::set_render_target(const char *name, std::shared_ptr in_render_target) { - const auto &texture_name = texture_map_.find(name); +void shader_program_opengl::set_render_target(const char* name, std::shared_ptr in_render_target) { + const auto& texture_name = texture_map_.find(name); if (texture_name == texture_map_.end()) return; std::shared_ptr rt = std::static_pointer_cast(in_render_target); - const opengl_texture_data &texture_data = texture_name->second; + const opengl_texture_data& texture_data = texture_name->second; if (texture_data.format != rt->get_internal_format()) spdlog::error("Mismatched texture format: {}, need{}, yours {}", name, texture_data.format, rt->get_internal_format()); glBindImageTexture(texture_data.binding, rt->get_texture(), 0, GL_FALSE, 0, GL_WRITE_ONLY, GL_RGBA32F); } -void shader_program_opengl::set_texture(const char *name, std::shared_ptr in_texture) { - const auto &texture_name = texture_map_.find(name); +void shader_program_opengl::set_texture(const char* name, std::shared_ptr in_texture) { + const auto& texture_name = texture_map_.find(name); if (texture_name == texture_map_.end()) return; std::shared_ptr t = std::static_pointer_cast(in_texture); - const opengl_texture_data &texture_data = texture_name->second; + const opengl_texture_data& texture_data = texture_name->second; glBindImageTexture(texture_data.binding, t->get_texture(), 0, GL_FALSE, 0, GL_WRITE_ONLY, GL_RGBA32F); } void shader_program_opengl::update_param_map(std::shared_ptr in_shader) { - const auto &uniform_pairs = in_shader->get_uniform_map(); - const auto &texture_pairs = in_shader->get_texture_map(); + const auto& uniform_pairs = in_shader->get_uniform_map(); + const auto& texture_pairs = in_shader->get_texture_map(); uniform_map_.insert(uniform_pairs.begin(), uniform_pairs.end()); texture_map_.insert(texture_pairs.begin(), texture_pairs.end()); diff --git a/core/rhi/opengl/shader/shader_program_opengl.h b/core/rhi/opengl/shader/shader_program_opengl.h index 554d14e..c3f1196 100644 --- a/core/rhi/opengl/shader/shader_program_opengl.h +++ b/core/rhi/opengl/shader/shader_program_opengl.h @@ -35,32 +35,32 @@ public: void destroy_program(); - void set_uniform(const char *slang_name, void *buffer, int size); + void set_uniform(const char* slang_name, void* buffer, int size); - void set_ssbo(const char *slang_name, void *buffer, int size, int element_size); + void set_ssbo(const char* slang_name, void* buffer, int size, int element_size); - void set_render_target(const char *name, std::shared_ptr in_render_target); + void set_render_target(const char* name, std::shared_ptr in_render_target); - void set_texture(const char *name, std::shared_ptr in_texture); + void set_texture(const char* name, std::shared_ptr in_texture); template - void set_uniform(const char *name, const T &buffer) { - set_uniform(name, (void *) &buffer, sizeof(T)); + void set_uniform(const char* name, const T& buffer) { + set_uniform(name, (void*) &buffer, sizeof(T)); } template - void set_uniform(const char *name, const std::vector &buffer) { - set_uniform(name, (void *) buffer.data(), sizeof(T) * buffer.size()); + void set_uniform(const char* name, const std::vector& buffer) { + set_uniform(name, (void*) buffer.data(), sizeof(T) * buffer.size()); } template - void set_ssbo(const char *name, const T &buffer) { - set_ssbo(name, (void *) &buffer, sizeof(T), sizeof(T)); + void set_ssbo(const char* name, const T& buffer) { + set_ssbo(name, (void*) &buffer, sizeof(T), sizeof(T)); } template - void set_ssbo(const char *name, const std::vector &buffer) { - set_ssbo(name, (void *) buffer.data(), sizeof(T) * buffer.size(), sizeof(T)); + void set_ssbo(const char* name, const std::vector& buffer) { + set_ssbo(name, (void*) buffer.data(), sizeof(T) * buffer.size(), sizeof(T)); } [[nodiscard]] bool is_initialized() const { return program_id_ != 0; } diff --git a/core/rhi/opengl/texture_opengl.cpp b/core/rhi/opengl/texture_opengl.cpp index 8bf9e6b..22f3ece 100644 --- a/core/rhi/opengl/texture_opengl.cpp +++ b/core/rhi/opengl/texture_opengl.cpp @@ -8,7 +8,7 @@ texture_opengl::~texture_opengl() { } } -bool texture_opengl::init_data(const unsigned char *data, int width, int height) { +bool texture_opengl::init_data(const unsigned char* data, int width, int height) { width_ = width; height_ = height; diff --git a/core/rhi/opengl/texture_opengl.h b/core/rhi/opengl/texture_opengl.h index 828e6fa..d69c98e 100644 --- a/core/rhi/opengl/texture_opengl.h +++ b/core/rhi/opengl/texture_opengl.h @@ -6,10 +6,10 @@ class texture_opengl : public texture { public: ~texture_opengl() override; - ImTextureID get_texture_id() override { return (void *) static_cast(texture_id_); } + ImTextureID get_texture_id() override { return (void*) static_cast(texture_id_); } GLuint get_texture() const { return texture_id_; } - bool init_data(const unsigned char *data, int width, int height) override; + bool init_data(const unsigned char* data, int width, int height) override; [[nodiscard]] bool is_valid() const override { return texture_id_ != 0; } diff --git a/core/rhi/render_target.h b/core/rhi/render_target.h index ca3cf89..e04c31c 100644 --- a/core/rhi/render_target.h +++ b/core/rhi/render_target.h @@ -27,7 +27,7 @@ public: on_resize_callback(shared_from_this()); } - virtual void *lock(lock_state state) = 0; + virtual void* lock(lock_state state) = 0; virtual void unlock() = 0; diff --git a/core/rhi/renderer.cpp b/core/rhi/renderer.cpp index 957f891..f7ec2b2 100644 --- a/core/rhi/renderer.cpp +++ b/core/rhi/renderer.cpp @@ -2,13 +2,11 @@ #include "application/application.h" -void renderer::shutdown() -{ +void renderer::shutdown() { default_vs_ = nullptr; } -std::shared_ptr renderer::get_pixel_shader_render_default_vs() -{ +std::shared_ptr renderer::get_pixel_shader_render_default_vs() { if (!default_vs_) default_vs_ = load_shader(application::get()->get_draw_ps_vertex_shader_entry()); return default_vs_; diff --git a/core/rhi/renderer.h b/core/rhi/renderer.h index 4b5d67b..208a81f 100644 --- a/core/rhi/renderer.h +++ b/core/rhi/renderer.h @@ -19,26 +19,26 @@ public: virtual void pre_init() { } - virtual bool init(GLFWwindow *window_handle) = 0; + virtual bool init(GLFWwindow* window_handle) = 0; virtual void shutdown(); virtual void post_shutdown() { } - virtual std::shared_ptr load_shader(const std::string &entry_name) = 0; + virtual std::shared_ptr load_shader(const std::string& entry_name) = 0; virtual std::shared_ptr get_pixel_shader_render_default_vs(); virtual std::shared_ptr create_pixel_shader_drawer() = 0; - virtual void new_frame(GLFWwindow *window_handle) = 0; + virtual void new_frame(GLFWwindow* window_handle) = 0; - virtual void end_frame(GLFWwindow *window_handle) = 0; + virtual void end_frame(GLFWwindow* window_handle) = 0; virtual void resize(int width, int height) = 0; - virtual std::shared_ptr create_texture(const unsigned char *data, int width, int height) = 0; + virtual std::shared_ptr create_texture(const unsigned char* data, int width, int height) = 0; virtual std::shared_ptr create_render_target(int width, int height, texture_format format) = 0; diff --git a/core/rhi/rhi_defintion.h b/core/rhi/rhi_defintion.h index fa79b86..1c9cea3 100644 --- a/core/rhi/rhi_defintion.h +++ b/core/rhi/rhi_defintion.h @@ -1,7 +1,6 @@ #pragma once -enum class texture_format -{ +enum class texture_format { RGBA8, RGBA16_FLOAT, RGBA32_FLOAT, diff --git a/core/rhi/shader.h b/core/rhi/shader.h index 5f71b52..5cd5606 100644 --- a/core/rhi/shader.h +++ b/core/rhi/shader.h @@ -24,35 +24,35 @@ public: } // param setters - virtual void set_cbuffer(const char *name, void *buffer, int size) = 0; + virtual void set_cbuffer(const char* name, void* buffer, int size) = 0; - virtual void set_uav_buffer(const char *name, void *buffer, int count, int element_size) { + virtual void set_uav_buffer(const char* name, void* buffer, int count, int element_size) { } - virtual void set_texture(const char *name, std::shared_ptr in_texture) = 0; + virtual void set_texture(const char* name, std::shared_ptr in_texture) = 0; - virtual void set_render_target(const char *name, std::shared_ptr in_render_target) = 0; + virtual void set_render_target(const char* name, std::shared_ptr in_render_target) = 0; template - void set_cbuffer(const char *name, const T &buffer) { - set_cbuffer(name, (void *) &buffer, sizeof(T)); + void set_cbuffer(const char* name, const T& buffer) { + set_cbuffer(name, (void*) &buffer, sizeof(T)); } template - void set_cbuffer(const char *name, const std::vector &buffer) { - set_cbuffer(name, (void *) buffer.data(), sizeof(T) * buffer.size()); + void set_cbuffer(const char* name, const std::vector& buffer) { + set_cbuffer(name, (void*) buffer.data(), sizeof(T) * buffer.size()); } template - void set_uav_buffer(const char *name, const T &buffer) { - set_uav_buffer(name, (void *) &buffer, sizeof(buffer), sizeof(T)); + void set_uav_buffer(const char* name, const T& buffer) { + set_uav_buffer(name, (void*) &buffer, sizeof(buffer), sizeof(T)); } template - void set_uav_buffer(const char *name, const std::vector &buffer) { - set_uav_buffer(name, (void *) buffer.data(), buffer.size(), sizeof(T)); + void set_uav_buffer(const char* name, const std::vector& buffer) { + set_uav_buffer(name, (void*) buffer.data(), buffer.size(), sizeof(T)); } - void begin_draw(const shader_draw_data &in_data) { if (on_begin_draw) on_begin_draw(in_data, *this); } - std::function on_begin_draw; + void begin_draw(const shader_draw_data& in_data) { if (on_begin_draw) on_begin_draw(in_data, *this); } + std::function on_begin_draw; }; diff --git a/core/rhi/texture.h b/core/rhi/texture.h index 557163b..1e6d3c8 100644 --- a/core/rhi/texture.h +++ b/core/rhi/texture.h @@ -9,7 +9,7 @@ public: texture(): width_(0), height_(0) { } - virtual bool init_data(const unsigned char *data, int width, int height) = 0; + virtual bool init_data(const unsigned char* data, int width, int height) = 0; [[nodiscard]] virtual bool is_valid() const = 0;