I’ve implemented a batcher for the fixed pipeline. The batcher will sort according to the states a batch requires and then, after setting relevant states, will call into a rendering function like the one below for the skybox. I also use VBO caching like Photon suggested.
My questions:
- should I make the static const variables member variables for better perf or some other concern (no threads here, nor will there ever be),
- maybe there should be no render functions at all? Here a batch is a block of states, without including the various vertex attribute pointers, as these almost always change from batch to batch. Also I didn’t want to issue too many batches in situations, where I render many identical batches (I can’t instance). In other words, I don’t include everything necessary for a glDraw* call in a batch, but maybe I should?
All the rendering code looks like the one below. Some pointers are set, the modelview matrix, … maybe some other states… and then glDrawElements() follows.
//////////////////////////////////////////////////////////////////////////////
void Skyboxb::render_skyboxa()
{
static GLsizei const strideaa(get_packed_stride((*vaa_ptr)[0]));
static GLsizei const offseta(get_packed_offset((*vaa_ptr)[0], 2));
static GLsizei const counta((*vaa_ptr)[1].array_size /
GVA_to_size(ArrayElementType((*vaa_ptr)[1].attribute_infos[0].type)));
get_vbo_handler().load_resource_range(
(*vaa_ptr)[0].vbo_index,
(*vaa_ptr)[1].vbo_index + 1);
glVertexPointer(
(*vaa_ptr)[0].attribute_infos[0].size + 1,
GVA_to_GL(ArrayElementType((*vaa_ptr)[0].attribute_infos[0].type)),
strideaa,
get_vbo_handler().get_vbo_ptr((*vaa_ptr)[0].vbo_index));
glTexCoordPointer(
(*vaa_ptr)[0].attribute_infos[2].size + 1,
GVA_to_GL(ArrayElementType((*vaa_ptr)[0].attribute_infos[2].type)),
strideaa,
get_vbo_handler().get_vbo_ptr((*vaa_ptr)[0].vbo_index) + offseta);
glLoadMatrixf(model_matrix.data());
glDrawElements(
GL_TRIANGLES,
counta,
GVA_to_GL(ArrayElementType((*vaa_ptr)[1].attribute_infos[0].type)),
get_vbo_handler().get_vbo_ptr((*vaa_ptr)[1].vbo_index));
GL_DEBUG();
}