main
Brett 2024-05-13 13:15:01 -04:00
parent 7c82253251
commit 2c29dba90f
9 changed files with 30 additions and 49 deletions

View File

@ -1,6 +1,6 @@
cmake_minimum_required(VERSION 3.25) 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) set(BLT_GRAPHICS_TEST_VERSION 0.0.1)
project(BLT_WITH_GRAPHICS VERSION ${BLT_GRAPHICS_VERSION}) project(BLT_WITH_GRAPHICS VERSION ${BLT_GRAPHICS_VERSION})

View File

@ -188,7 +188,7 @@ namespace blt::gfx
* @param offset offset into the data structure to where the data is stored * @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 * @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. // 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); 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); 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_t_owner>(vbo); return std::make_shared<vbo_t_owner>(vbo);
} }

View File

@ -169,10 +169,10 @@ namespace blt::gfx
using object_container = hashmap_t<std::string, std::vector<std::pair<render_info_t, T>>>; using object_container = hashmap_t<std::string, std::vector<std::pair<render_info_t, T>>>;
private: private:
vertex_array_t* square_vao = nullptr; std::unique_ptr<vertex_array_t> square_vao = nullptr;
vertex_array_t* line_vao = nullptr; std::unique_ptr<vertex_array_t> line_vao = nullptr;
shader_t* square_shader = nullptr; std::unique_ptr<shader_t> square_shader = nullptr;
shader_t* point_shader = nullptr; std::unique_ptr<shader_t> point_shader = nullptr;
resource_manager& resources; resource_manager& resources;
matrix_state_manager& state; matrix_state_manager& state;
// texture name -> draw info // texture name -> draw info
@ -212,13 +212,7 @@ namespace blt::gfx
public: public:
explicit batch_renderer_2d(resource_manager& resources, matrix_state_manager& state): resources(resources), state(state) 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<pp_outline_target_t>(), engine = pp_engine_t::make_multi_pp(std::make_unique<pp_render_target_t>());
std::make_unique<pp_blur_step_inplace_t>(state, frame_buffer_t::attachment_t::COLOR1),
std::make_unique<pp_multiplier_step_inplace_t>(frame_buffer_t::attachment_t::COLOR1,
vec4{4, 4, 4, 1}),
std::make_unique<pp_overlay_blur_step_t>(frame_buffer_t::attachment_t::COLOR1, 2, 2),
std::make_unique<pp_outline_step_t>(state)
);
} }
void create(); void create();

@ -1 +1 @@
Subproject commit 231cbee0fc4f59dbe5b8b853a11b08dc84e57c65 Subproject commit a1b06823fe2d964a62fda99385499b218cf5cea5

@ -1 +1 @@
Subproject commit 111397c71a5f1c2c88e05da9c84edfdba2e472a4 Subproject commit 6675317107257c2cc16c947b359d557821d85bf2

View File

@ -130,12 +130,10 @@ namespace blt::gfx
glDeleteVertexArrays(1, &vaoID); 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, void vertex_array_t::bindVBO(const vertex_buffer_t& vbo, int attribute_number, int coordinate_size, GLenum type, int stride, long offset)
long offset)
{ {
handle_vbo(vbo, attribute_number, coordinate_size, type, stride, offset); handle_vbo(vbo, attribute_number, coordinate_size, type, stride, offset);
VBOs[attribute_number] = createSharedVBO(vbo); VBOs[attribute_number] = make_vbo(vbo);
return VBOs[attribute_number];
} }
void vertex_array_t::bindVBO(const static_dynamic_array::vbo_type& vbo, int attribute_number, int coordinate_size, GLenum type, int stride, long offset) void vertex_array_t::bindVBO(const static_dynamic_array::vbo_type& vbo, int attribute_number, int coordinate_size, GLenum type, int stride, long offset)

View File

@ -60,9 +60,10 @@ namespace blt::gfx
vertices_vbo.allocate(sizeof(square_vertices), square_vertices); vertices_vbo.allocate(sizeof(square_vertices), square_vertices);
indices_vbo.allocate(sizeof(square_indices), square_indices); indices_vbo.allocate(sizeof(square_indices), square_indices);
square_vao = new vertex_array_t(); square_vao = std::make_unique<vertex_array_t>();
const auto tb = square_vao->bindVBO(vertices_vbo, 0, 3, GL_FLOAT, 5 * sizeof(float), 0); auto vb = vertex_array_t::make_vbo(vertices_vbo);
square_vao->bindVBO(tb, 1, 2, GL_FLOAT, 5 * sizeof(float), 3 * sizeof(float)); 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); square_vao->bindElement(indices_vbo);
} }
{ {
@ -75,36 +76,22 @@ namespace blt::gfx
vertices_vbo.allocate(sizeof(line_vertices), line_vertices, GL_DYNAMIC_DRAW); vertices_vbo.allocate(sizeof(line_vertices), line_vertices, GL_DYNAMIC_DRAW);
indices_vbo.allocate(sizeof(square_indices), square_indices, GL_DYNAMIC_DRAW); indices_vbo.allocate(sizeof(square_indices), square_indices, GL_DYNAMIC_DRAW);
line_vao = new vertex_array_t(); line_vao = std::make_unique<vertex_array_t>();
auto tb = line_vao->bindVBO(vertices_vbo, 0, 3, GL_FLOAT, 5 * sizeof(float), 0); auto vb = vertex_array_t::make_vbo(vertices_vbo);
line_vao->bindVBO(tb, 1, 2, GL_FLOAT, 5 * sizeof(float), 3 * sizeof(float)); 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); 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(0, "vertex");
square_shader->bindAttribute(1, "uv_in"); 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(0, "vertex");
point_shader->bindAttribute(1, "uv_in"); point_shader->bindAttribute(1, "uv_in");
engine->create(); 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) 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->cleanup();
engine = nullptr; engine = nullptr;
delete square_vao; square_vao = nullptr;
delete square_shader; line_vao = nullptr;
delete point_shader; square_shader = nullptr;
point_shader = nullptr;
} }
void batch_renderer_2d::render(i32, i32, const bool transparency) void batch_renderer_2d::render(i32, i32, const bool transparency)

View File

@ -62,8 +62,9 @@ namespace blt::gfx
indices_vbo.allocate(sizeof(full_screen_indices), full_screen_indices); indices_vbo.allocate(sizeof(full_screen_indices), full_screen_indices);
screen_vao = std::make_unique<vertex_array_t>(); screen_vao = std::make_unique<vertex_array_t>();
const auto tb = screen_vao->bindVBO(vertices_vbo, 0, 3, GL_FLOAT, 5 * sizeof(float), 0); auto vb = vertex_array_t::make_vbo(vertices_vbo);
screen_vao->bindVBO(tb, 1, 2, GL_FLOAT, 5 * sizeof(float), 3 * sizeof(float)); 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); screen_vao->bindElement(indices_vbo);
} }
#ifdef __EMSCRIPTEN__ #ifdef __EMSCRIPTEN__

View File

@ -63,7 +63,7 @@ void init()
vertex_buffer_t vertices_vbo; vertex_buffer_t vertices_vbo;
vertices_vbo.create(); vertices_vbo.create();
vertices_vbo.allocate(static_cast<long>(object.vertex_data().size() * sizeof(blt::parse::constructed_vertex_t)), object.vertex_data().data()); vertices_vbo.allocate(static_cast<long>(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()) for (auto obj : object.objects())
{ {