Game Development Community

Small regenStates bug

by ghuval · in Torque Game Engine Advanced · 06/29/2006 (5:27 pm) · 0 replies

I just noticed that regenStates in gfxD3DDevice.regen-states.cpp doesn't take into account that some of the direct3d values can't be applied directly to torque functions. Kindof a minor bug, but if you do regen your states and use pushState() and popState() some bugs with alpha and other things start to show up.

For example, after using regenStates() this line changed on me:

...
   initRenderState( 75, 1 );
...

After looking it up, this is setting the default for GFXBlendOp to GFXBlendOpSubtract (which is incorrect). However, it won't show up as incorrect until you do a GFX->pushState() GFX->popState() setup with GFX->setBlendOp().

I was having a lot of render issues with transparency, and of course this bug doesn't effect just the GFXBlendOp, but any render state that is set with an enum that doesn't line up with the D3D values (This one happens because GFXBlendOp starts at zero, while the D3D enum starts at one).

Since the code takes up a lot of space I'll just explain what I did:

Using the switch statements that were in GFXD3DDevice::setRenderState(), setTextureStageState(), and setSamplerState() I filter the values that are returned from mD3DDevice->GetRenderState, GetTextureStageState, and GetSamplerState. Here's part of what I changed:

Con::printf("");
   Con::printf("   // Texture Stage states");

   for(U32 tStage = 0; tStage < TEXTURE_STAGE_COUNT; tStage++) 
   {
      for(U32 tState = GFXTSS_FIRST; tState < GFXTSS_COUNT; tState++) 
      {
         tD3DVar = 0;
         mD3DDevice->GetTextureStageState(tStage, GFXD3DTextureStageState[tState], &tD3DVar);

         switch (tState)
         {
         case GFXTSSColorOp:
         case GFXTSSAlphaOp:
            for (tTorqueVar = GFXTOP_FIRST;
                 tTorqueVar < GFXTOP_COUNT && GFXD3DTextureOp[tTorqueVar] != tD3DVar;
                 tTorqueVar++);
            break;

         default:
            tTorqueVar = tD3DVar;
            break;
         }

         Con::printf("   initTextureState(%d, %d, %d);", tStage, tState, tTorqueVar);
      }
   }

Some variable names have changed, so you can't cut and paste this, just an example. Again, I know it's minor, but it caused me a lot of issues after running regenStates about three months ago, and I just now caught it.