Game Development Reference
In-Depth Information
vertex Vertex;
Vertex.Kueken = PartDynamicBuffer.Kueken[BufferOffset];
Vertex.Ovtsa = PartStaticBuffer.Vertex[BufferOffset].Ovtsa;
Vertex.Varken = PartStaticBuffer.Vertex[BufferOffset].Varken;
return Vertex;
}
// The fetch function gathers the vertex data from a single static buffer
vertex vertexFetchStatic(in intDrawOffset , in intVertexID)
{
intBufferOffset = DrawOffset + VertexID;
return StaticBuffer.Vertex[BufferOffset];
}
// Select the right fetch function per draw according to the vertex format
vertex vertexFetch(in intDrawID, in intVertexID)
{
intDrawOffset = extractDrawOffset(DrawID);
intDrawFormatID = extractDrawFormat(DrawID);
if (DrawFormatID== PARTIALLY_DYNAMIC)
return vertexFetchPartiallyDynamic(DrawOffset, gl_VertexID);
else if (DrawFormatID== FULLY_STATIC)
return vertexFetchStatic(DrawOffset, gl_VertexID);
else // ERROR , unknown vertex format
return vertex();
}
void main()
{
vertex Vertex = vertexFetch(DrawID, gl_VertexID);
...
}
Listing 2.4. Code sample of programmable vertex fetching.
Here are a few comments regarding the usage of programmable vertex fetching.
Many applications rely on uber-shaders where all the resources are declared
but not necessarily used. When using programmable vertex fetching we
can declare a large user-defined vertex structure where only the vertex
attributes used by the program pipeline would be filled.
The DrawID is used to index GPU resources; hence, it must be a dynami-
cally uniform expression.
Themorebitsweuseforvertexformat IDs, the less vertices we can store
in each shader storage buffer.
We don't have to create a dedicated buffer for the DrawIDs. We can encode
it inside a variable in a custom draw indirect structure ( Listing 2.5 ) . This
 
 
Search Nedrilad ::




Custom Search