Skip to content

Commit

Permalink
Extend vertex buffer to support drawables directly. Use it for screen…
Browse files Browse the repository at this point in the history
… quad.
  • Loading branch information
logzero committed Dec 1, 2023
1 parent 2b39758 commit 2e53589
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 19 deletions.
9 changes: 1 addition & 8 deletions src/graphics/graphics_gl2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -367,14 +367,7 @@ void GraphicsGL2::Deinit()

void GraphicsGL2::BindDynamicVertexData(std::vector<SceneNode*> nodes)
{
// TODO: This doesn't look very efficient...
SceneNode quad_node;
SceneNode::DrawableHandle d = quad_node.GetDrawList().twodim.insert(screen_quad);
nodes.push_back(&quad_node);

vertex_buffer.SetDynamicVertexData(nodes.data(), nodes.size());

screen_quad = quad_node.GetDrawList().twodim.get(d);
vertex_buffer.SetDynamicVertexData(nodes.data(), nodes.size(), &screen_quad, 1);
}

void GraphicsGL2::BindStaticVertexData(std::vector<SceneNode*> nodes)
Expand Down
9 changes: 1 addition & 8 deletions src/graphics/graphics_gl3v.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,14 +147,7 @@ void GraphicsGL3::Deinit()

void GraphicsGL3::BindDynamicVertexData(std::vector<SceneNode*> nodes)
{
// TODO: This doesn't look very efficient...
SceneNode quad_node;
SceneNode::DrawableHandle d = quad_node.GetDrawList().twodim.insert(fullscreenquad);
nodes.push_back(&quad_node);

vertex_buffer.SetDynamicVertexData(nodes.data(), nodes.size());

fullscreenquad = quad_node.GetDrawList().twodim.get(d);
vertex_buffer.SetDynamicVertexData(nodes.data(), nodes.size(), &fullscreenquad, 1);
}

void GraphicsGL3::BindStaticVertexData(std::vector<SceneNode*> nodes)
Expand Down
9 changes: 7 additions & 2 deletions src/graphics/vertexbuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ void VertexBuffer::Clear()
}
}

void VertexBuffer::SetDynamicVertexData(SceneNode * nodes[], unsigned int count)
void VertexBuffer::SetDynamicVertexData(SceneNode * nodes[], unsigned int ncount, Drawable drawables[], unsigned int dcount)
{
use_vao = GLC_ARB_vertex_array_object && good_vao;

Expand All @@ -278,12 +278,17 @@ void VertexBuffer::SetDynamicVertexData(SceneNode * nodes[], unsigned int count)
InitDynamicBufferObjects();

BindDynamicVertexData bind_data(*this);
for (unsigned int i = 0; i < count; ++i)
for (unsigned int i = 0; i < ncount; ++i)
{
assert(nodes[i]);
nodes[i]->ApplyDrawableFunctor(Wrapper<BindDynamicVertexData>(bind_data));
}

for (unsigned int i = 0; i < dcount; ++i)
{
bind_data(drawables[i]);
}

for (unsigned int i = 0; i <= VertexFormat::LastFormat; ++i)
{
UploadDynamicVertexData(objects[i], staging_index_buffer[i], staging_vertex_buffer[i]);
Expand Down
3 changes: 2 additions & 1 deletion src/graphics/vertexbuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "vertexformat.h"
#include <vector>

class Drawable;
class SceneNode;
class VertexArray;

Expand All @@ -44,7 +45,7 @@ class VertexBuffer
/// \brief Bind dynamic scene node drawables vertex data and upload it to gpu
/// \param nodes is the node pointer array to be processed
/// \param count is the size of the node array
void SetDynamicVertexData(SceneNode * nodes[], unsigned int count);
void SetDynamicVertexData(SceneNode * nodes[], unsigned int ncount, Drawable drawables[] = 0, unsigned int dcount = 0);

/// \brief Bind static scene node drawables vertex data and upload it to gpu
/// \param nodes is the node pointer array to be processed
Expand Down

0 comments on commit 2e53589

Please sign in to comment.