Attention: iDevGames forum has a new home at http://www.idevgames.com/forums.
Please update your bookmarks and linkage.
This forum has been locked and will be available for archival purposes only.
iDevGames - Mac, iPhone, iPad & iPod Game Developers Forum  


iPhone, iPad & iPod Game Development Game programming topics devoted to the Apple iPhone, iPad & iPod.

 
 
Thread Tools Display Modes
Old
  (#1)
godexsoft
Member
 
Posts: 80
Join Date: 2008.11
Location: St.Petersburg, Russia
glBindTexture ID cache/shadow - 2010.01.21, 01:15 AM

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!
   
Old
  (#2)
godexsoft
Member
 
Posts: 80
Join Date: 2008.11
Location: St.Petersburg, Russia
2010.01.25, 02:52 AM

nothing to say about this?


TapMania - iPhone StepMania // Human knowledge belongs to the world!
   
Old
  (#3)
Frank C.
Member
 
Posts: 392
Join Date: 2002.09
Location: Toronto
2010.01.25, 04:59 AM

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.
   
Old
  (#4)
godexsoft
Member
 
Posts: 80
Join Date: 2008.11
Location: St.Petersburg, Russia
2010.01.25, 07:08 AM

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!
   
Old
  (#5)
Zwilnik
Moderator
 
Posts: 417
Join Date: 2002.04
Location: Newcastle, UK
2010.01.25, 07:41 AM

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.
   
Old
  (#6)
godexsoft
Member
 
Posts: 80
Join Date: 2008.11
Location: St.Petersburg, Russia
2010.01.25, 07:48 AM

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!
   
Old
  (#7)
godexsoft
Member
 
Posts: 80
Join Date: 2008.11
Location: St.Petersburg, Russia
2010.01.25, 08:14 AM

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!
   
Old
  (#8)
warmi
Member
 
Posts: 147
Join Date: 2009.04
Location: USA
2010.01.25, 07:42 AM

You shouldn't really need to change your current context when using FBOs ...
   
 


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump



Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
vBulletin Skin developed by: vBStyles.com
DevServe Network: iDevApps | uDevGames | iDevGames