Removed requirements for PoseableBatch-es to have a specified

number of rendered elements.

This was pretty easy since the elements were getting re-allocated
in the graphics card every frame. TODO would be to make the
re-allocation not happen every frame but rather only happen when
a re-allocation is nescessary and rather just not fully re-populate
the buffer if not every element is used or have some other sort of
automated way of handling the VRAM.
This commit is contained in:
elipzer 2018-11-12 11:23:38 -05:00
parent d25b5da9d2
commit 8061ffeef5
6 changed files with 23 additions and 27 deletions

View File

@ -10,7 +10,7 @@ MyBuiltinCubeScene::MyBuiltinCubeScene(Application& application)
: Scene(application), : Scene(application),
m_shape(meshgenerator::gen_cube_p<basic::Vertex, basic::Index>(DRAW_TRIANGLES, 2.0f, 2.0f, 2.0f), DrawMode::DRAW_TRIANGLES), m_shape(meshgenerator::gen_cube_p<basic::Vertex, basic::Index>(DRAW_TRIANGLES, 2.0f, 2.0f, 2.0f), DrawMode::DRAW_TRIANGLES),
m_camera((float)TAU_1_4, (float)m_screen_size.x / m_screen_size.y, 1.0f, 10.0f, vec3(0.0f, 0.0f, 5.0f)), m_camera((float)TAU_1_4, (float)m_screen_size.x / m_screen_size.y, 1.0f, 10.0f, vec3(0.0f, 0.0f, 5.0f)),
m_batch(&m_shape, 2) m_batch(&m_shape)
{ {
m_pipeline.add_batch(&m_batch); m_pipeline.add_batch(&m_batch);
m_pipeline.set_camera(&m_camera); m_pipeline.set_camera(&m_camera);

View File

@ -18,7 +18,7 @@ MyBuiltinLitScene::MyBuiltinLitScene(Application& application)
), DrawMode::DRAW_TRIANGLES ), DrawMode::DRAW_TRIANGLES
), ),
m_camera((float)TAU_1_4, (float)m_screen_size.x / m_screen_size.y, 1.0f, 10.0f, vec3(0.0f, 0.0f, 5.0f)), m_camera((float)TAU_1_4, (float)m_screen_size.x / m_screen_size.y, 1.0f, 10.0f, vec3(0.0f, 0.0f, 5.0f)),
m_batch(&m_shape, 2), m_batch(&m_shape),
m_light( m_light(
Position(0.0f, 2.0f, 2.0f), Position(0.0f, 2.0f, 2.0f),
PhongLight::Power(0.2f, 1.0f, 1.0f), PhongLight::Power(0.2f, 1.0f, 1.0f),

View File

@ -23,8 +23,8 @@ MyBuiltinTexturedScene::MyBuiltinTexturedScene(Application& application)
texturegenerator::gen_quick_sampler() texturegenerator::gen_quick_sampler()
), ),
m_camera((float)TAU_1_4, (float)m_screen_size.x / m_screen_size.y, 1.0f, 10.0f, vec3(0.0f, 0.0f, 5.0f), vec3(0.0f, 0.0f, -1.0f)), m_camera((float)TAU_1_4, (float)m_screen_size.x / m_screen_size.y, 1.0f, 10.0f, vec3(0.0f, 0.0f, 5.0f), vec3(0.0f, 0.0f, -1.0f)),
m_cube_batch(&m_cube, 2), m_cube_batch(&m_cube),
m_sprite_batch(&m_sprite, 1) m_sprite_batch(&m_sprite)
{ {
m_pipeline.add_batch(&m_cube_batch); m_pipeline.add_batch(&m_cube_batch);
m_pipeline.add_batch(&m_sprite_batch); m_pipeline.add_batch(&m_sprite_batch);

View File

@ -49,11 +49,11 @@ MyPongScene::MyPongScene(Application& application)
m_life(meshgenerator::gen_rect_p<basic::Vertex, basic::Index>(DRAW_TRIANGLES, LIFE_THICKNESS, LIFE_THICKNESS), DRAW_TRIANGLES), m_life(meshgenerator::gen_rect_p<basic::Vertex, basic::Index>(DRAW_TRIANGLES, LIFE_THICKNESS, LIFE_THICKNESS), DRAW_TRIANGLES),
m_paddle(meshgenerator::gen_rect_p<basic::Vertex, basic::Index>(DRAW_TRIANGLES, PADDLE_THICKNESS, PADDLE_HEIGHT), DRAW_TRIANGLES), m_paddle(meshgenerator::gen_rect_p<basic::Vertex, basic::Index>(DRAW_TRIANGLES, PADDLE_THICKNESS, PADDLE_HEIGHT), DRAW_TRIANGLES),
m_outline_column_batch(&m_outline_column, 2), m_outline_column_batch(&m_outline_column),
m_outline_row_batch(&m_outline_row, 2), m_outline_row_batch(&m_outline_row),
m_ball_batch(&m_ball, 1), m_ball_batch(&m_ball),
m_life_batch(&m_life, STARTING_LIVES * 2), m_life_batch(&m_life),
m_paddle_batch(&m_paddle, 2), m_paddle_batch(&m_paddle),
m_outline_top_pose(glm::vec3(0.0f, (m_screen_size.y - OUTLINE_THICKNESS) / 2.0f - OUTLINE_OFFSET, 0.0f)), m_outline_top_pose(glm::vec3(0.0f, (m_screen_size.y - OUTLINE_THICKNESS) / 2.0f - OUTLINE_OFFSET, 0.0f)),
m_outline_bottom_pose(glm::vec3(0.0f, -((m_screen_size.y - OUTLINE_THICKNESS) / 2.0f - OUTLINE_OFFSET), 0.0f)), m_outline_bottom_pose(glm::vec3(0.0f, -((m_screen_size.y - OUTLINE_THICKNESS) / 2.0f - OUTLINE_OFFSET), 0.0f)),

View File

@ -31,7 +31,7 @@ MyTextTestScene::MyTextTestScene(Application& application)
texturegenerator::gen_quick_sampler() texturegenerator::gen_quick_sampler()
), ),
m_camera(m_screen_size), m_camera(m_screen_size),
m_text_batch(&m_text, 1) m_text_batch(&m_text)
{ {
m_pipeline.set_camera(&m_camera); m_pipeline.set_camera(&m_camera);
m_pipeline.add_batch(&m_text_batch); m_pipeline.add_batch(&m_text_batch);

View File

@ -14,39 +14,35 @@ namespace charcoal
class PoseableBatch : public builtin::Batch<VertexType, IndexType, 1, RenderableType> class PoseableBatch : public builtin::Batch<VertexType, IndexType, 1, RenderableType>
{ {
public: public:
PoseableBatch( PoseableBatch(RenderableType* renderable)
RenderableType* renderable, : builtin::Batch<VertexType, IndexType, 1, RenderableType>(renderable, 0)
int element_count
) : PoseableBatch(renderable, element_count, element_count)
{}
PoseableBatch(
RenderableType* renderable,
int element_count,
int element_render_count
) : builtin::Batch<VertexType, IndexType, 1, RenderableType>(renderable, element_render_count), m_orientation_elements(element_count)
{} {}
virtual ~PoseableBatch() {} virtual ~PoseableBatch() {}
void reset_rendered() void reset_rendered()
{ {
// Also clear the matrix array? m_orientation_elements.clear();
charcoal::InstancedBatch<VertexType, IndexType, RenderableType>::set_render_count(0); charcoal::InstancedBatch<VertexType, IndexType, RenderableType>::set_render_count(0);
// Just thinking, maybe want to not make want set_render_count to be public... The end-developer
// could screw up things by using that function. Then again, it could allow for preventing of
// needing to resize the element buffers once that optimization is made.
} }
void add_rendered(const Poseable& poseable) void add_rendered(const Poseable& poseable)
{ {
// Maybe just push back and then increment the render count? m_orientation_elements.emplace_back(poseable.get_orientation_matrix());
m_orientation_elements[charcoal::InstancedBatch<VertexType, IndexType, RenderableType>::m_render_count++] = poseable.get_orientation_matrix(); charcoal::InstancedBatch<VertexType, IndexType, RenderableType>::m_render_count++;
} }
protected: protected:
void setup_element_buffers() override void setup_element_buffers() override
{ {
// This feels worthless because it is also done in update_element_buffers. // This is (was) worthless because it is also done in update_element_buffers.
glBindBuffer(GL_ARRAY_BUFFER, charcoal::ElementBatch<1>::m_element_buffers[0]); //glBindBuffer(GL_ARRAY_BUFFER, charcoal::ElementBatch<1>::m_element_buffers[0]);
glBufferData(GL_ARRAY_BUFFER, m_orientation_elements.size() * sizeof(mat4), NULL, GL_STREAM_DRAW); //glBufferData(GL_ARRAY_BUFFER, m_orientation_elements.size() * sizeof(mat4), NULL, GL_STREAM_DRAW);
// TODO: Find a way to not have to do a re-allocation every frame.
// While we're like this, I guess the adding and resetting of rendered can be changed though!
} }
void resize_element_buffers() override void resize_element_buffers() override