格式化代码

This commit is contained in:
Nanako 2024-02-19 01:33:18 +08:00
parent e50fcb1992
commit 87ad4d5eb9
23 changed files with 153 additions and 156 deletions

View File

@ -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<spdlog::async_factory>("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<texture> application::load_texture(const std::string &path) const {
std::shared_ptr<texture> 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<texture> application::load_texture(const std::string &path) cons
}
std::shared_ptr<texture>
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();

View File

@ -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<texture> load_texture(const std::string &path) const;
[[nodiscard]] std::shared_ptr<texture> load_texture(const std::string& path) const;
std::shared_ptr<texture> create_texture(const unsigned char *data, int width, int height) const;
std::shared_ptr<texture> create_texture(const unsigned char* data, int width, int height) const;
[[nodiscard]] std::shared_ptr<render_target> create_render_target(int width, int height,
texture_format format) const;
[[nodiscard]] std::shared_ptr<pixel_shader_drawer> 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<spdlog::logger> async_spdlog_;
private:

View File

@ -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";

View File

@ -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<std::string, std::string> args_; // key-value pairs

View File

@ -6,20 +6,20 @@
*/
template<typename ReferencedType>
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 &copy) {
ref_count_ptr(const ref_count_ptr& copy) {
reference_ = copy.reference_;
if (reference_) {
reference_->AddRef();
@ -27,21 +27,21 @@ public:
}
template<typename CopyReferencedType>
explicit ref_count_ptr(const ref_count_ptr<CopyReferencedType> &copy) {
reference_ = static_cast<ReferencedType *>(copy.get_reference());
explicit ref_count_ptr(const ref_count_ptr<CopyReferencedType>& copy) {
reference_ = static_cast<ReferencedType*>(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<typename MoveReferencedType>
explicit ref_count_ptr(ref_count_ptr<MoveReferencedType> &&move) {
reference_ = static_cast<ReferencedType *>(move.get_reference());
explicit ref_count_ptr(ref_count_ptr<MoveReferencedType>&& move) {
reference_ = static_cast<ReferencedType*>(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<typename CopyReferencedType>
ref_count_ptr &operator=(const ref_count_ptr<CopyReferencedType> &in_ptr) {
ref_count_ptr& operator=(const ref_count_ptr<CopyReferencedType>& 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<typename MoveReferencedType>
ref_count_ptr &operator=(ref_count_ptr<MoveReferencedType> &&in_ptr) {
ref_count_ptr& operator=(ref_count_ptr<MoveReferencedType>&& 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<typename OtherType>
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;
}
};

View File

@ -10,18 +10,18 @@ namespace scope_exit_support {
*/
template<typename FuncType>
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<typename FuncType>
scope_guard<FuncType> operator+(FuncType &&in_func) {
return scope_guard<FuncType>((FuncType &&) in_func);
scope_guard<FuncType> operator+(FuncType&& in_func) {
return scope_guard<FuncType>((FuncType&&) in_func);
}
};
}

View File

@ -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<pixel_shader_drawer_opengl *>(cmd->UserCallbackData);
const std::shared_ptr<render_target_opengl> &rt = data->rt;
void ps_opengl_compute_callback(const ImDrawList* parent_list, const ImDrawCmd* cmd) {
const auto data = static_cast<pixel_shader_drawer_opengl*>(cmd->UserCallbackData);
const std::shared_ptr<render_target_opengl>& 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);

View File

@ -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:

View File

@ -8,12 +8,12 @@ public:
~render_target_opengl() override;
ImTextureID get_texture_id() override { return (void *) static_cast<intptr_t>(texture_); }
ImTextureID get_texture_id() override { return (void*) static_cast<intptr_t>(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;
};

View File

@ -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<shader> renderer_opengl::load_shader(const std::string &entry_name) {
std::shared_ptr<shader> renderer_opengl::load_shader(const std::string& entry_name) {
return nullptr;
}
@ -80,14 +80,14 @@ std::shared_ptr<pixel_shader_drawer> renderer_opengl::create_pixel_shader_drawer
return std::make_shared<pixel_shader_drawer_opengl>();
}
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<texture> renderer_opengl::create_texture(const unsigned char *data, int width, int height) {
std::shared_ptr<texture> renderer_opengl::create_texture(const unsigned char* data, int width, int height) {
auto out = std::make_shared<texture_opengl>();
if (!out->init_data(data, width, height)) {
out = nullptr;

View File

@ -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<shader> load_shader(const std::string &entry_name) override;
std::shared_ptr<shader> load_shader(const std::string& entry_name) override;
std::shared_ptr<pixel_shader_drawer> 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<texture> create_texture(const unsigned char *data, int width, int height) override;
std::shared_ptr<texture> create_texture(const unsigned char* data, int width, int height) override;
std::shared_ptr<render_target> create_render_target(int width, int height, texture_format format) override;

View File

@ -42,22 +42,22 @@ void shader_opengl::set_using_program(std::shared_ptr<shader_program_opengl> 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<render_target> in_render_target) {
void shader_opengl::set_render_target(const char* name, std::shared_ptr<render_target> 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<texture> in_texture) {
void shader_opengl::set_texture(const char* name, std::shared_ptr<texture> in_texture) {
if (const auto program = using_program_.lock())
program->set_texture(name, in_texture);
}

View File

@ -36,20 +36,20 @@ public:
void set_using_program(std::shared_ptr<shader_program_opengl> 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<render_target> in_render_target) override;
void set_render_target(const char* name, std::shared_ptr<render_target> in_render_target) override;
void set_texture(const char *name, std::shared_ptr<texture> in_texture) override;
void set_texture(const char* name, std::shared_ptr<texture> in_texture) override;
[[nodiscard]] virtual GLenum get_shader_type() const = 0;
[[nodiscard]] GLuint get_shader_id() const { return shader_id_; }
[[nodiscard]] const std::map<std::string, opengl_uniform_data> &get_uniform_map() const { return uniform_map_; }
[[nodiscard]] const std::map<std::string, opengl_texture_data> &get_texture_map() const { return texture_map_; }
[[nodiscard]] const std::map<std::string, opengl_uniform_data>& get_uniform_map() const { return uniform_map_; }
[[nodiscard]] const std::map<std::string, opengl_texture_data>& get_texture_map() const { return texture_map_; }
protected:
GLuint shader_id_;

View File

@ -105,7 +105,7 @@ bool shader_program_opengl::create_program(std::shared_ptr<shader_opengl> 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<render_target> in_render_target) {
const auto &texture_name = texture_map_.find(name);
void shader_program_opengl::set_render_target(const char* name, std::shared_ptr<render_target> in_render_target) {
const auto& texture_name = texture_map_.find(name);
if (texture_name == texture_map_.end())
return;
std::shared_ptr<render_target_opengl> rt = std::static_pointer_cast<render_target_opengl>(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<texture> in_texture) {
const auto &texture_name = texture_map_.find(name);
void shader_program_opengl::set_texture(const char* name, std::shared_ptr<texture> in_texture) {
const auto& texture_name = texture_map_.find(name);
if (texture_name == texture_map_.end())
return;
std::shared_ptr<texture_opengl> t = std::static_pointer_cast<texture_opengl>(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<shader_opengl> 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());

View File

@ -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<render_target> in_render_target);
void set_render_target(const char* name, std::shared_ptr<render_target> in_render_target);
void set_texture(const char *name, std::shared_ptr<texture> in_texture);
void set_texture(const char* name, std::shared_ptr<texture> in_texture);
template<typename T>
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<typename T>
void set_uniform(const char *name, const std::vector<T> &buffer) {
set_uniform(name, (void *) buffer.data(), sizeof(T) * buffer.size());
void set_uniform(const char* name, const std::vector<T>& buffer) {
set_uniform(name, (void*) buffer.data(), sizeof(T) * buffer.size());
}
template<typename T>
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<typename T>
void set_ssbo(const char *name, const std::vector<T> &buffer) {
set_ssbo(name, (void *) buffer.data(), sizeof(T) * buffer.size(), sizeof(T));
void set_ssbo(const char* name, const std::vector<T>& buffer) {
set_ssbo(name, (void*) buffer.data(), sizeof(T) * buffer.size(), sizeof(T));
}
[[nodiscard]] bool is_initialized() const { return program_id_ != 0; }

View File

@ -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;

View File

@ -6,10 +6,10 @@ class texture_opengl : public texture {
public:
~texture_opengl() override;
ImTextureID get_texture_id() override { return (void *) static_cast<intptr_t>(texture_id_); }
ImTextureID get_texture_id() override { return (void*) static_cast<intptr_t>(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; }

View File

@ -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;

View File

@ -2,13 +2,11 @@
#include "application/application.h"
void renderer::shutdown()
{
void renderer::shutdown() {
default_vs_ = nullptr;
}
std::shared_ptr<shader> renderer::get_pixel_shader_render_default_vs()
{
std::shared_ptr<shader> 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_;

View File

@ -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<shader> load_shader(const std::string &entry_name) = 0;
virtual std::shared_ptr<shader> load_shader(const std::string& entry_name) = 0;
virtual std::shared_ptr<shader> get_pixel_shader_render_default_vs();
virtual std::shared_ptr<pixel_shader_drawer> 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<texture> create_texture(const unsigned char *data, int width, int height) = 0;
virtual std::shared_ptr<texture> create_texture(const unsigned char* data, int width, int height) = 0;
virtual std::shared_ptr<render_target> create_render_target(int width, int height, texture_format format) = 0;

View File

@ -1,7 +1,6 @@
#pragma once
enum class texture_format
{
enum class texture_format {
RGBA8,
RGBA16_FLOAT,
RGBA32_FLOAT,

View File

@ -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<texture> in_texture) = 0;
virtual void set_texture(const char* name, std::shared_ptr<texture> in_texture) = 0;
virtual void set_render_target(const char *name, std::shared_ptr<render_target> in_render_target) = 0;
virtual void set_render_target(const char* name, std::shared_ptr<render_target> in_render_target) = 0;
template<typename T>
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<typename T>
void set_cbuffer(const char *name, const std::vector<T> &buffer) {
set_cbuffer(name, (void *) buffer.data(), sizeof(T) * buffer.size());
void set_cbuffer(const char* name, const std::vector<T>& buffer) {
set_cbuffer(name, (void*) buffer.data(), sizeof(T) * buffer.size());
}
template<typename T>
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<typename T>
void set_uav_buffer(const char *name, const std::vector<T> &buffer) {
set_uav_buffer(name, (void *) buffer.data(), buffer.size(), sizeof(T));
void set_uav_buffer(const char* name, const std::vector<T>& 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<void(const shader_draw_data &, shader &)> on_begin_draw;
void begin_draw(const shader_draw_data& in_data) { if (on_begin_draw) on_begin_draw(in_data, *this); }
std::function<void(const shader_draw_data&, shader&)> on_begin_draw;
};

View File

@ -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;