glBindTexture ID cache/shadow

Member
Posts: 93
Joined: 2008.11
Post: #1
Hi all,

On another (locked) thread I read about caching of currently bound texture for less interfacing with the gpu. There was a snippet like this:

Code:
void BindTexture(GLuint id){
  static GLuint currentId=0;
  if(currentId!=id) glBindTexture(GL_TEXTURE_2D,currentId=id);
}

This works great on the simulator but appears to be broken on the device. Not for every texture/font but for some of them I get a blank background (as if I would disable blending). Any ideas why this could happen? I removed the "if" condition and everything worked fine (without caching thus).

Regards,
Alex

TapMania - iPhone StepMania // Human knowledge belongs to the world!
Quote this message in a reply
Member
Posts: 93
Joined: 2008.11
Post: #2
nothing to say about this?

TapMania - iPhone StepMania // Human knowledge belongs to the world!
Quote this message in a reply
Member
Posts: 440
Joined: 2002.09
Post: #3
It should work - the paranoid programmer in me wouldn't use an assignment in a function call though.

The blank texture could be something failing to load on the device for some reason (missing resource, wrong path, case sensitivity errors, etc.) or you might be loading non-power-of-2 textures, or not properly mipmaping, or some other GL state is getting messed up... Also, if you're using multitexture keep in mind that you need to track the current texture for each unit. Some of these situations should fail on the simulator too, but in general it's normal to run into differences between the simulator vs. the device, so debug on the device as often as possible.
Quote this message in a reply
Member
Posts: 93
Joined: 2008.11
Post: #4
Hi Frank,

Thanks for the suggestion. I don't really know whether I use multitexturing or not.. what I definitely do is using the FBO extension and switching Framebuffers to generate textures.. As the problem (blank texture) occurs only on generated textures I think the problem is in the context..
Somewhere on the docs there was a note that glBindTexture affects only the current context.. so if you change the context you probably want to drop the current cache, right? So I'm going to try that now :-)

Alex

TapMania - iPhone StepMania // Human knowledge belongs to the world!
Quote this message in a reply
Moderator
Posts: 335
Joined: 2002.04
Post: #5
Are you called glBindTexture anywhere else in your render path? If you are then it will end up out of sync with your currentId value which will not indicate it needs to be changed to the new texture the next time you call your BindTexture function.

Also check that you're not disabling TEXTURE2D anywhere in that render path.
Quote this message in a reply
Member
Posts: 166
Joined: 2009.04
Post: #6
You shouldn't really need to change your current context when using FBOs ...
Quote this message in a reply
Member
Posts: 93
Joined: 2008.11
Post: #7
Hi,

Well, I checked like 10 times for the first suggestion.. i changed every line of glBindTexture to my custom shadowing version.. that's for sure.

But now when I look through my code I see that I disable/re-enable GL_TEXTURE_2D in my transition code (fading between screens etc.). This definitely may be the problem!

Will try to fix this now and let you know. Thanks!

Alex

TapMania - iPhone StepMania // Human knowledge belongs to the world!
Quote this message in a reply
Member
Posts: 93
Joined: 2008.11
Post: #8
Ok, so Zwilnik was right. Just added a BindTexture(0) to drop cache in the transition code and it works fine now.
However, in one and only one toggler in the game it still reproduces. Kinda stumped.

Thanks Zwilnik!

Alex

TapMania - iPhone StepMania // Human knowledge belongs to the world!
Quote this message in a reply
Post Reply