Large number of texture swaps causing big performance drop

You can dump all of the shaders by (temporarily) putting “dump-generated-shaders 1” in your Config.prc file, then you can choose the appropriate shaders from the result and load them as shader files directly.

But you also can solve this problem by simply holding onto the RenderState that corresponds to the previous state, which will allow it to re-use the previous shader when you return to that state.

One way to do this is instead of calling setTexture() on the fly, walk through all of your textures at init time, and save the RenderState for each pair. Like this, at init time:

#loop through 96 textures:

  t1 = textureOn
  dict[key]['node'].setTexture(defaultTS,t1, 1)
  dict[key]['tex_on_state'] = dict[key]['node].getState()

  t1 = textureOff
  dict[key]['node'].setTexture(defaultTS,t1, 1)
  dict[key]['tex_off_state'] = dict[key]['node].getState()

And then do this at run time:

#loop through 96 textures:

if not textureBlink:
  state = dict[key]['tex_on_state']
  dict[key]['node'].setState(state)
  textureBlink = True

else:
  state = dict[key]['tex_off_state']
  dict[key]['node'].setState(state)
  textureBlink = False

#endloop 

David