how to organize rendering

Posted by Irbis on Game Development See other posts from Game Development or by Irbis
Published on 2012-12-15T16:49:04Z Indexed on 2012/12/15 17:18 UTC
Read the original article Hit count: 235

Filed under:
|
|

I use a deferred rendering. During g-buffer stage my rendering loop for a sponza model (obj format) looks like this:

int i = 0;
int sum  = 0;
map<string, mtlItem *>::const_iterator itrEnd = mtl.getIteratorEnd();
for(map<string, mtlItem *>::const_iterator itr = mtl.getIteratorBegin(); itr != itrEnd; ++itr)
{
   glActiveTexture(GL_TEXTURE0 + 0);
   glBindTexture(GL_TEXTURE_2D, itr->second->map_KdId);
   glDrawElements(GL_TRIANGLES, indicesCount[i], GL_UNSIGNED_INT, (GLvoid*)(sum * 4));
   sum += indicesCount[i];
   ++i;
   glBindTexture(GL_TEXTURE_2D, 0);
}

I sorted faces based on materials. I switch only a diffuse texture but I can place there more material properties. Is it a good approach ? I also wonder how to handle a different kind of materials, for example: some material use a normal map, other doesn't use. Should I have a different shaders for them ?

© Game Development or respective owner

Related posts about opengl

Related posts about glsl