Sharing vertex arrays with multiple index buffers (each with a different pipeline/shader)? #940
-
I've been using the As an example, I have quad corners as vertices and two triangles per quad described in the index buffer. I would like to additionally render the edges of the quad (not the triangles) by reusing the same corner vertex data, and only transferring a new set of indices (with a different shader) to the GPU, avoiding the need to transfer the vertex data twice which can be quite large. It's not obvious to me if VSG's |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 1 reply
-
For your use case, which uses a different pipeline with the different index arrays, the simplest thing to do is to use |
Beta Was this translation helpful? Give feedback.
-
Just to be clear, do you mean one |
Beta Was this translation helpful? Give feedback.
-
I found that using the To share the vertex array between two different sets of indices and pipelines, I had to break out the vsg::DataList vertexArrays{{vertices, colors}};
auto vertexBuffer = vsg::BindVertexBuffers::create(shadeGPC->baseAttributeBinding, vertexArrays);
auto shadeDrawCommands = vsg::Commands::create();
shadeDrawCommands->addChild(vertexBuffer);
shadeDrawCommands->addChild(vsg::BindIndexBuffer::create(indices));
shadeDrawCommands->addChild(vsg::DrawIndexed::create(static_cast<uint32_t>(indices->size()), 1, 0, 0, 0));
shadeStateGroup->addChild(shadeDrawCommands);
auto meshDrawCommands = vsg::Commands::create();
meshDrawCommands->addChild(vertexBuffer); // shared vertex buffer
meshDrawCommands->addChild(vsg::BindIndexBuffer::create(meshIndices)); // different indices
meshDrawCommands->addChild(vsg::DrawIndexed::create(static_cast<uint32_t>(meshIndices->size()), 1, 0, 0, 0));
meshStateGroup->addChild(meshDrawCommands); // different pipeline To conclude with a use case, we are drawing a CAD-like mesh which consists of non-triangle primitives (quads mostly, but also many-sided polygons) and we want to show the surface panels using a triangle list and the polygon edges (not the triangle edges) using the same vertex data but with different connectivity (the indices) as a line list. |
Beta Was this translation helpful? Give feedback.
I found that using the
VertexIndexDraw
objects withGraphicsPipelineConfigurator::assignArray()
andref_ptr
's to arrays always transfers the data and does not attempt to use an already-bound vertex buffer. You can see this by looking atVertexIndexDraw::record()
which callsvkCmdBindVertexBuffers
without checking to see if the data has already been bound.To share the vertex array between two different sets of indices and pipelines, I had to break out the
VertexIndexDraw
into theBindIndexBuffer
andDrawIndexed
objects: