Changing wrap mode on the fly

I need to change the wrap mode from GL_CLAMP to GL_REPEAT depending on my shader texture modes:

glBindTexture(GL_TEXTURE_2D, shader.tex[i].glTex;
if (shader.tex[i].clamped) {
glTexParameter(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);

} else {
glTexParameter(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);

}

I have two questions:

  1. will this work (can you modify the wrap mode after creation?
  2. What is the performance hit expected?

I can (and will) try it, but any guidance would be helpful!

Yes there is no reason why you can not change the wrap mode of any currently bound texture with

glTexParameteri (…)

I rebind quite a few texture parameters for every texture I bind so that my sandbox editor can change texture properties dynamically and I can see the effect immediately.

No real noticable performance hit, if at all.

Thanks, that helps a lot!

I can tell you that this is not true. Tested on a Geforce 8600 it’s definitely faster if you have 2 textures with different clamping modes than changing the mode repeatedly.

Of course you’ll only see the hit if your program really stresses the graphics hardware.

Thanks! I was wondering. The quake3 source does just as you say (two separate textures with different clamp params). Was trying to figure out if I should do the same. Sound like I probably should.