Graphics Reference
In-Depth Information
glUseProgram ( shader )
for ( i =0, i < length ( q ), i ++):
// Only for weights that have changed . . .
if ( abs ( dw [ i ]) != 0):
// Set the weight uniform
glUniform1f (... , dw [ i ])
// Bind the output VBO to TBO
glBindBufferBase ( GL_TRANSFORM_FEEDBACK_BUFFER ,0, vbo [1])
// Bind the inputs to vertex shader
glBindBuffer ( GL_ARRAY_BUFFER , vbo [0])
glVertexAttribPointer ( ATTRIBUTE_STREAM_0 ,...)
glBindBuffer ( GL_ARRAY_BUFFER , q [ i ])
glVertexAttribPointer ( ATTRIBUTE_STREAM_1 ,...)
// Draw call performs per vertex accumulation in vertex
// shader .
glEnableTransformFeedback ()
glDrawArrays (...)
glDisableTransformFeedback ()
// Vertices for rendering are referenced with vbo[0]
swap ( vbo [0] , vbo [1])
4.4.2 Batching
For eciency, further improvements can be made. In this version, updates are
batched together into fewer passes. Instead of passing in the attributes and weight
uniform for one pose at a time, we can instead use a vertex shader that processes
multiple key-poses per update pass. We then perform the update with as few
passes as possible.
// Inputs :
// q[] : difference mesh VBOs, where corresponding dw != 0
// vbo[] : array of vertex buffer objects for storing current
// pose
// dw[] : delta weight vector
// shader [] : shader programs for each batch size up to b
// b : max batch size
// Per Frame Batched Pose Update:
// ... Similar setup as before ...
for ( i =0, i < length ( q ), ):
k = min ( length ( q ), i + b )
i
glUseProgram ( shader [ k ])
glBindBufferBase ( GL_TRANSFORM_FEEDBACK_BUFFER ,0, vbo [1])
// Bind attributes for pass
for ( j =0, j < b , j ++) :
if ( j < k ):
glEnableVertexAttribArray ( ATTRIBUTE_STREAM_1 + j )
glBindBuffer ( GL_ARRAY_BUFFER , q [ i + j ])
glVertexAttribPointer ( ATTRIBUTE_STREAM_1 + j ,...)
else :
glDisableVertexAttribArray ( ATTRIBUTE_STREAM_1 + j )
// Set the delta weights
glUniform1fv (...)
// Bind current pose as input and draw
glEnableVertexAttribArray ( ATTRIBUTE_STREAM_0 )
glBindBuffer ( GL_ARRAY_BUFFER , vbo [0])
Search WWH ::




Custom Search