Game Development Community

Performance Updates

by Scott Doerrfeld · in Torque Game Engine · 05/01/2007 (11:07 am) · 4 replies

This thread continues a discussion about the performance aspects of using Constructor. The link to that discussion is here:

http://www.garagegames.com/mg/forums/result.thread.php?qt=61490

#1
05/01/2007 (11:14 am)
John kabus wrote:
Quote:Hi Scott,

There are a number of performance updates in head that should go out in the next release. One of them is related to static meshes and gl state changes (this doesn't address visibility culling, which still needs to go in, but should help a lot).

very interesting. any notion when visibility culling will be going out ?
we're planning on using the DTS-placing features of Constructor for hundreds and hundreds of objects,
but i wasn't aware of the performance hit. As well we need to port the TGE-side code into our codebase, so it'd be nice to do that after visibility culling etc is in there.
#2
05/01/2007 (11:44 am)
Hi guys,

I'm not sure when visibility culling will make it into the engine - one of the GG guys will have to comment on that one.

Here's the optimization to reduce state changes - I had to alter it for 1.5.1, so let me know if there are any problems.


In ConstructorSimpleMesh::render line 157 - replace the render loop with:

U32 diffuseid = -1;
   U32 lightmapid = -1;

   for(S32 i=0; i<primitives.size(); i++)
   {
      primitive &draw = primitives[i];

      if(draw.alpha != transparent)
         continue;

      if(texture)
      {
         U32 id = materialList->getMaterial(draw.diffuseIndex).getGLName();
         if(diffuseid != id)
         {
            diffuseid = id;

            glBindTexture(GL_TEXTURE_2D, diffuseid);
            glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, draw.texS);
            glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, draw.texT);
         }
      }

      if(lightmap)
      {
         U32 id = gInteriorLMManager.getHandle(interiorlmhandle, instancelmhandle, draw.lightMapIndex)->getGLName();
         if(lightmapid != id)
         {
            lightmapid = id;
            glActiveTextureARB(GL_TEXTURE1_ARB);

            glBindTexture(GL_TEXTURE_2D, lightmapid);

            glActiveTextureARB(GL_TEXTURE0_ARB);
         }
      }

      glDrawElements(GL_TRIANGLE_STRIP, draw.count, GL_UNSIGNED_SHORT,
         &indices[draw.start]);
   }


The code in head is even more efficient because the light maps are on texture unit 0, which avoids frequent active texture changes (I guess you could do that here too - by assuming the default is unit 1). I would have supplied both optimizations, but the code affects too many areas to easily break out into a separate update, but this one should help a good bit.
#3
05/01/2007 (12:32 pm)
Thanks John.
#4
05/04/2007 (5:38 pm)
Any luck guys? I was wondering what some real-world performance stats looked like before and after.