From 2c29dba90fc8de8fe8cbacd035c50d13a4f5aa70 Mon Sep 17 00:00:00 2001 From: Brett Date: Mon, 13 May 2024 13:15:01 -0400 Subject: [PATCH] silly --- CMakeLists.txt | 2 +- include/blt/gfx/model.h | 4 +- include/blt/gfx/renderer/batch_2d_renderer.h | 16 +++----- libraries/imgui | 2 +- libraries/openal-soft | 2 +- src/blt/gfx/model.cpp | 6 +-- src/blt/gfx/renderer/batch_2d_renderer.cpp | 40 +++++++------------- src/blt/gfx/renderer/postprocess.cpp | 5 ++- tests/src/main.cpp | 2 +- 9 files changed, 30 insertions(+), 49 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5cb3c3e..8ed8e77 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,6 @@ cmake_minimum_required(VERSION 3.25) -set(BLT_GRAPHICS_VERSION 0.13.13) +set(BLT_GRAPHICS_VERSION 0.13.14) set(BLT_GRAPHICS_TEST_VERSION 0.0.1) project(BLT_WITH_GRAPHICS VERSION ${BLT_GRAPHICS_VERSION}) diff --git a/include/blt/gfx/model.h b/include/blt/gfx/model.h index 9e41194..9bd30de 100644 --- a/include/blt/gfx/model.h +++ b/include/blt/gfx/model.h @@ -188,7 +188,7 @@ namespace blt::gfx * @param offset offset into the data structure to where the data is stored * @return a shared pointer to the stored vbo. used for chaining VAOs with multiple shared VBOs */ - static_dynamic_array::vbo_type bindVBO(const vertex_buffer_t& vbo, int attribute_number, int coordinate_size, GLenum type, int stride, long offset); + void bindVBO(const vertex_buffer_t& vbo, int attribute_number, int coordinate_size, GLenum type, int stride, long offset); // same as the other bind method except you provide the shared reference. void bindVBO(const static_dynamic_array::vbo_type& vbo, int attribute_number, int coordinate_size, GLenum type, int stride, long offset); @@ -230,7 +230,7 @@ namespace blt::gfx glBindVertexArray(0); } - static inline static_dynamic_array::vbo_type createSharedVBO(const vertex_buffer_t& vbo) + static inline static_dynamic_array::vbo_type make_vbo(const vertex_buffer_t& vbo) { return std::make_shared(vbo); } diff --git a/include/blt/gfx/renderer/batch_2d_renderer.h b/include/blt/gfx/renderer/batch_2d_renderer.h index 473b1f2..8661ad7 100644 --- a/include/blt/gfx/renderer/batch_2d_renderer.h +++ b/include/blt/gfx/renderer/batch_2d_renderer.h @@ -169,10 +169,10 @@ namespace blt::gfx using object_container = hashmap_t>>; private: - vertex_array_t* square_vao = nullptr; - vertex_array_t* line_vao = nullptr; - shader_t* square_shader = nullptr; - shader_t* point_shader = nullptr; + std::unique_ptr square_vao = nullptr; + std::unique_ptr line_vao = nullptr; + std::unique_ptr square_shader = nullptr; + std::unique_ptr point_shader = nullptr; resource_manager& resources; matrix_state_manager& state; // texture name -> draw info @@ -212,13 +212,7 @@ namespace blt::gfx public: explicit batch_renderer_2d(resource_manager& resources, matrix_state_manager& state): resources(resources), state(state) { - engine = pp_engine_t::make_multi_pp(std::make_unique(), - std::make_unique(state, frame_buffer_t::attachment_t::COLOR1), - std::make_unique(frame_buffer_t::attachment_t::COLOR1, - vec4{4, 4, 4, 1}), - std::make_unique(frame_buffer_t::attachment_t::COLOR1, 2, 2), - std::make_unique(state) - ); + engine = pp_engine_t::make_multi_pp(std::make_unique()); } void create(); diff --git a/libraries/imgui b/libraries/imgui index 231cbee..a1b0682 160000 --- a/libraries/imgui +++ b/libraries/imgui @@ -1 +1 @@ -Subproject commit 231cbee0fc4f59dbe5b8b853a11b08dc84e57c65 +Subproject commit a1b06823fe2d964a62fda99385499b218cf5cea5 diff --git a/libraries/openal-soft b/libraries/openal-soft index 111397c..6675317 160000 --- a/libraries/openal-soft +++ b/libraries/openal-soft @@ -1 +1 @@ -Subproject commit 111397c71a5f1c2c88e05da9c84edfdba2e472a4 +Subproject commit 6675317107257c2cc16c947b359d557821d85bf2 diff --git a/src/blt/gfx/model.cpp b/src/blt/gfx/model.cpp index 3ec121d..5914cdf 100644 --- a/src/blt/gfx/model.cpp +++ b/src/blt/gfx/model.cpp @@ -130,12 +130,10 @@ namespace blt::gfx glDeleteVertexArrays(1, &vaoID); } - static_dynamic_array::vbo_type vertex_array_t::bindVBO(const vertex_buffer_t& vbo, int attribute_number, int coordinate_size, GLenum type, int stride, - long offset) + void vertex_array_t::bindVBO(const vertex_buffer_t& vbo, int attribute_number, int coordinate_size, GLenum type, int stride, long offset) { handle_vbo(vbo, attribute_number, coordinate_size, type, stride, offset); - VBOs[attribute_number] = createSharedVBO(vbo); - return VBOs[attribute_number]; + VBOs[attribute_number] = make_vbo(vbo); } void vertex_array_t::bindVBO(const static_dynamic_array::vbo_type& vbo, int attribute_number, int coordinate_size, GLenum type, int stride, long offset) diff --git a/src/blt/gfx/renderer/batch_2d_renderer.cpp b/src/blt/gfx/renderer/batch_2d_renderer.cpp index 3b64853..3e0c7b0 100644 --- a/src/blt/gfx/renderer/batch_2d_renderer.cpp +++ b/src/blt/gfx/renderer/batch_2d_renderer.cpp @@ -60,9 +60,10 @@ namespace blt::gfx vertices_vbo.allocate(sizeof(square_vertices), square_vertices); indices_vbo.allocate(sizeof(square_indices), square_indices); - square_vao = new vertex_array_t(); - const auto tb = square_vao->bindVBO(vertices_vbo, 0, 3, GL_FLOAT, 5 * sizeof(float), 0); - square_vao->bindVBO(tb, 1, 2, GL_FLOAT, 5 * sizeof(float), 3 * sizeof(float)); + square_vao = std::make_unique(); + auto vb = vertex_array_t::make_vbo(vertices_vbo); + square_vao->bindVBO(vb, 0, 3, GL_FLOAT, 5 * sizeof(float), 0); + square_vao->bindVBO(vb, 1, 2, GL_FLOAT, 5 * sizeof(float), 3 * sizeof(float)); square_vao->bindElement(indices_vbo); } { @@ -75,36 +76,22 @@ namespace blt::gfx vertices_vbo.allocate(sizeof(line_vertices), line_vertices, GL_DYNAMIC_DRAW); indices_vbo.allocate(sizeof(square_indices), square_indices, GL_DYNAMIC_DRAW); - line_vao = new vertex_array_t(); - auto tb = line_vao->bindVBO(vertices_vbo, 0, 3, GL_FLOAT, 5 * sizeof(float), 0); - line_vao->bindVBO(tb, 1, 2, GL_FLOAT, 5 * sizeof(float), 3 * sizeof(float)); + line_vao = std::make_unique(); + auto vb = vertex_array_t::make_vbo(vertices_vbo); + line_vao->bindVBO(vb, 0, 3, GL_FLOAT, 5 * sizeof(float), 0); + line_vao->bindVBO(vb, 1, 2, GL_FLOAT, 5 * sizeof(float), 3 * sizeof(float)); line_vao->bindElement(indices_vbo); } - square_shader = shader_t::make(shader_2d_textured_vert, shader_2d_textured_frag); + square_shader = shader_t::make_unique(shader_2d_textured_vert, shader_2d_textured_frag); square_shader->bindAttribute(0, "vertex"); square_shader->bindAttribute(1, "uv_in"); - point_shader = shader_t::make(shader_2d_textured_vert, shader_2d_textured_cirlce_frag); + point_shader = shader_t::make_unique(shader_2d_textured_vert, shader_2d_textured_cirlce_frag); point_shader->bindAttribute(0, "vertex"); point_shader->bindAttribute(1, "uv_in"); engine->create(); - -// draw_buffer.create(); -// draw_buffer.bind(); -// -// auto* texture = new texture_gl2D(1440, 720); -// draw_buffer.attachTexture(texture, frame_buffer_t::attachment_t::COLOR0); -// auto* mask = new texture_gl2D(1440, 720); -// draw_buffer.attachTexture(mask, frame_buffer_t::attachment_t::COLOR1); -// -// render_buffer_t depth_rbo = render_buffer_t::make_render_buffer(GL_DEPTH24_STENCIL8, 1440, 720); -// draw_buffer.attachRenderBuffer(depth_rbo, frame_buffer_t::attachment_t::DEPTH_STENCIL); -// -// if (!frame_buffer_t::validate()) -// BLT_ERROR("Failed to create render framebuffer!"); -// frame_buffer_t::unbind(); } void batch_renderer_2d::drawRectangleInternal(const std::string_view texture, const rectangle2d_t& rectangle, const f32 z_index) @@ -165,9 +152,10 @@ namespace blt::gfx { engine->cleanup(); engine = nullptr; - delete square_vao; - delete square_shader; - delete point_shader; + square_vao = nullptr; + line_vao = nullptr; + square_shader = nullptr; + point_shader = nullptr; } void batch_renderer_2d::render(i32, i32, const bool transparency) diff --git a/src/blt/gfx/renderer/postprocess.cpp b/src/blt/gfx/renderer/postprocess.cpp index 568b61e..e31a507 100644 --- a/src/blt/gfx/renderer/postprocess.cpp +++ b/src/blt/gfx/renderer/postprocess.cpp @@ -62,8 +62,9 @@ namespace blt::gfx indices_vbo.allocate(sizeof(full_screen_indices), full_screen_indices); screen_vao = std::make_unique(); - const auto tb = screen_vao->bindVBO(vertices_vbo, 0, 3, GL_FLOAT, 5 * sizeof(float), 0); - screen_vao->bindVBO(tb, 1, 2, GL_FLOAT, 5 * sizeof(float), 3 * sizeof(float)); + auto vb = vertex_array_t::make_vbo(vertices_vbo); + screen_vao->bindVBO(vb, 0, 3, GL_FLOAT, 5 * sizeof(float), 0); + screen_vao->bindVBO(vb, 1, 2, GL_FLOAT, 5 * sizeof(float), 3 * sizeof(float)); screen_vao->bindElement(indices_vbo); } #ifdef __EMSCRIPTEN__ diff --git a/tests/src/main.cpp b/tests/src/main.cpp index e028d9d..a1da057 100644 --- a/tests/src/main.cpp +++ b/tests/src/main.cpp @@ -63,7 +63,7 @@ void init() vertex_buffer_t vertices_vbo; vertices_vbo.create(); vertices_vbo.allocate(static_cast(object.vertex_data().size() * sizeof(blt::parse::constructed_vertex_t)), object.vertex_data().data()); - auto ptr = vertex_array_t::createSharedVBO(vertices_vbo); + auto ptr = vertex_array_t::make_vbo(vertices_vbo); for (auto obj : object.objects()) {