Game Development Reference
In-Depth Information
Instead, we propose to no longer rely on the VAO and build the vertices
ourselves in the vertex shader stage so that we don't need to sort draws per
vertex format. We can group all the meshes into a single set of shader storage
buffers, regardless of their vertex format. This allows us to rely on GPU indexing
to fetch vertex data, avoiding the CPU overhead of resource switching.
Unfortunately, OpenGL 4.3 doesn't provide a built-in variable gl_DrawID that
would allow us to identify each draw. One approach that might be considered
but is not successful would be to use the expression gl_VertexID == 0 to detect
that a new draw is invocated and to increment an atomic counter each time this
case happens. However, the OpenGL specification doesn't specify the order of
execution of the atomic operations so we can't identify which DrawID corresponds
to which draw.
To generate the DrawID, the proposed solution is to store it in a 32-bit integer
vertex attribute. Using baseInstance and an attribute equal to one, this attribute
is shared with all vertex invocations of a draw. This DrawID is a bit-field where
some bits are used to encode the vertex format ID and the rest of the bits are
used to index the first vertex of a draw. (See Listing 2.4. )
layout(binding = PART_DYNAMIC) buffer partDynamicBuffer
{
vec4 Kueken[];
} PartDynamicBuffer;
structpartStaticStorage
{
vec2 Ovtsa;
vec2 Varken;
};
layout(binding = PART_STATIC) buffer partStaticBuffer
{
partStaticStorageVertex[];
} PartStaticBuffer;
struct vertex
{
vec4 Kueken;
vec2 Ovtsa;
vec2 Varken;
};
layout(binding = FULL_STATIC) buffer staticBuffer
{
vertex Vertex[];
} StaticBuffer;
// Only vertex attribute
layout(location = DRAW_OFFSET) in intDrawID;
// The fetch function gathers the vertex data from multiple buffers
vertex vertexFetchPartiallyDynamic(in intDrawOffset , in intVertexID)
{
intBufferOffset = DrawOffset + VertexID;
 
Search Nedrilad ::




Custom Search