You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The idea is to get rid of all ...Array interfaces as well as Set...Array functions in the CommandBuffer interface. Instead, the new ResourceHeap interface should be used, which complies with the new rendering APIs. The SetVertexBufferArray function should be refactored to the following:
For all renderers (except OpenGL) this can be trivially implemented by using an uninitialized local C-style array that is passed to the native renderer API like this:
voidD3D11CommandBuffer::SetVertexBuffers(
std::uint32_t numVertexBuffers,
Buffer* const* vertexBuffers)
{
/* Uninitialized local arrays are trivially constructed on the stack */
ID3D11Buffer* buffers[g_maxVertexBuffers];
UINT strides[g_maxVertexBuffers];
UINT offsets[g_maxVertexBuffers];
/* Convert vertex buffer array to native parameters */
numVertexBuffers = std::min(numVertexBuffers, g_maxVertexBuffers);
for (std::uint32_t i = 0; i < numVertexBuffers; ++i)
{
auto vertexBufferD3D = LLGL_CAST(D3D11VertexBuffer*, vertexBuffers[i]);
buffers[i] = vertexBufferD3D->GetNative();
strides[i] = vertexBufferD3D->GetStride();
offsets[i] = 0;
}
/* Pass local arrays to native API */
context_->IASetVertexBuffers(0, numVertexBuffers, buffers, strides, offsets);
}
This works analogous to the SetViewports and SetScissors functions.
For OpenGL, however, this requires a little more effort. The idea is to convert the GLVertexArrayObject member variable in GLVertexBuffer into shared pointer. Then all vertex buffers used in a call to SetVertexBuffers refer to the same VAO. When these buffers are used in the SetVertexBuffers function for the first time, this VAO is created 'on the fly'. When they are used together once more, this VAO can be reused. This allows to dynamically change the vertex buffers without letting the client programmer manage a BufferArray object.
Caveat:
To make a buffer usable for multiple sets of vertex buffers, each GLVertexBuffer must hold a container of shared pointers. Otherwise, some VAOs could be created and deleted every frame :-(
So either each GLVertexBuffer needs this list, which must be iterated for each buffer used in the SetVertexBuffers function, or some sort of hash map must be involved to quickly find the correct VAO for a set of buffers.
Alternative 1:
Get rid of all ...Array interfaces except of BufferArray (but only for vertex buffer arrays).
Alternative 2:
Both SetVertexBufferArray and SetVertexBuffers are supported. The former one is supported for optimization purposes and the latter one is supported for flexibility purposes.
LukasBanana
changed the title
Add "SetVertexBuffers" to dynamically set multiple vertex buffers
Refactore "SetVertexBufferArray" to "SetVertexBuffers"
Jun 21, 2018
LukasBanana
changed the title
Refactore "SetVertexBufferArray" to "SetVertexBuffers"
Refactor "SetVertexBufferArray" to "SetVertexBuffers"
Jun 21, 2018
The idea is to get rid of all
...Array
interfaces as well asSet...Array
functions in theCommandBuffer
interface. Instead, the newResourceHeap
interface should be used, which complies with the new rendering APIs. TheSetVertexBufferArray
function should be refactored to the following:For all renderers (except OpenGL) this can be trivially implemented by using an uninitialized local C-style array that is passed to the native renderer API like this:
This works analogous to the
SetViewports
andSetScissors
functions.For OpenGL, however, this requires a little more effort. The idea is to convert the
GLVertexArrayObject
member variable inGLVertexBuffer
into shared pointer. Then all vertex buffers used in a call toSetVertexBuffers
refer to the same VAO. When these buffers are used in theSetVertexBuffers
function for the first time, this VAO is created 'on the fly'. When they are used together once more, this VAO can be reused. This allows to dynamically change the vertex buffers without letting the client programmer manage aBufferArray
object.Caveat:
To make a buffer usable for multiple sets of vertex buffers, each
GLVertexBuffer
must hold a container of shared pointers. Otherwise, some VAOs could be created and deleted every frame :-(So either each
GLVertexBuffer
needs this list, which must be iterated for each buffer used in theSetVertexBuffers
function, or some sort of hash map must be involved to quickly find the correct VAO for a set of buffers.Alternative 1:
Get rid of all
...Array
interfaces except ofBufferArray
(but only for vertex buffer arrays).Alternative 2:
Both
SetVertexBufferArray
andSetVertexBuffers
are supported. The former one is supported for optimization purposes and the latter one is supported for flexibility purposes.Update (12/07/2018):
Maybe the GL_ARB_vertex_attrib_binding extension can help here.
The text was updated successfully, but these errors were encountered: