Prevent 3rd party lib from messing up gl

Member
Posts: 306
Joined: 2009.03
Post: #1
I have to call some lib, in there they set a bunch of gl params disabled. I need to save the state and then restore it so my app can proceed normally afterwords.
I have taken to recording the current values of all the setEnabled states in open gl and then putting them back after this lib is done. I have 3 questions:
1) there doesn't appear to be a isClientStateEnabled to undo their client state changes. I can handle this manually by just knowing what changes this caused and fixing it. But might there be a way to record the actual value?

2)glTexEnvi is being called with (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE). I have never called this and can't find any documentation on the net that says what this is by default. What should I put it back to?

3)Is there a better way to do this? glPushEverything glPopEverything or some such?

Oh and and whats the client texture\active texture(I have always just used glBindTexture) and why would they set the texture twice in a row as below
Code:
    glActiveTexture(GL_TEXTURE1);//not sure why they set this and then overwrite it below
    glClientActiveTexture(GL_TEXTURE1);//not sure why they set this and then overwrite it below
    glDisableClientState(GL_TEXTURE_COORD_ARRAY);//not sure why they set this and then overwrite it below
    glDisable(GL_TEXTURE_2D);//not sure why they set this and then overwrite it below
    glActiveTexture(GL_TEXTURE0);
    glClientActiveTexture(GL_TEXTURE0);
    glEnableClientState(GL_TEXTURE_COORD_ARRAY);
    glEnable(GL_TEXTURE_2D);

Thanks!
Quote this message in a reply
Member
Posts: 446
Joined: 2002.09
Post: #2
You can use glPush/PopAttrib to push and pop various states but it seems every time it's mentioned it's followed by "don't use it" so YMMV. You seem to have the source to the library you're calling into so glPush/PopAttrib might be overkill...

AFAIK the texture environment mode defaults to GL_MODULATE so that should be fine.

The glActiveTexture sets the active texture unit. That code snippet is disabling texturing for the second unit and enabling it for the first. Functions that affect texturing only work on the active texture unit, which is why things are being called twice - there's no overriding going on.

For the client state it's probably easiest to just enable/disable everything as needed, just to be sure - there's only 5 or 6 caps.
Quote this message in a reply
Moderator
Posts: 3,577
Joined: 2003.06
Post: #3
I wouldn't be afraid of using glPush/PopAttrib if you're only calling it twice per frame to save you the grief of getting setting attibs because of a third party lib. That said... yeah, it's standard practice to avoid glPush/PopAttibs for performance.

Yes, GL_MODULATE is default.
Quote this message in a reply
Member
Posts: 306
Joined: 2009.03
Post: #4
So i thought this was all working but I noticed a strange side effect. Texture2d fails the first time after storing and resetting these variables with:
OpenGL error 0x0500 in -[Texture2D

I googled that and it sounded like something related to this:
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);

If i don't do this 3rd party lib the problem goes away. So if that is the default, any other ideas why this might happen. The 2nd time the texture2d works so it probably fixes itself but I end up with 1 missing texture.
Quote this message in a reply
Member
Posts: 446
Joined: 2002.09
Post: #5
0x0500 is a "GL_INVALID_ENUM" error so the fact that it only happens once suggests the problem function call is only executed once. Regardless, you need to check glGetError after each call to GL to find out exactly where the error originates. Just knowing that you got an error isn't all that helpful.
Quote this message in a reply
Member
Posts: 306
Joined: 2009.03
Post: #6
This was happening because i was using GL_MAX_CLIP_PLANES to store all the clip planes, but that value is not 6 as I expected but some big number Wink
Quote this message in a reply
Member
Posts: 306
Joined: 2009.03
Post: #7
There library was also doing:glDisableClientState(GL_MATRIX_INDEX_ARRAY_OES); which causes the problem too... I set it back to enabled but doesn't seem to matter. Luckily I was able to just comment that out and didn't seem to effect their render code.. Smile
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Help! Came Center is messing up my view! Jamie W 1 3,201 May 7, 2012 10:45 AM
Last Post: Jamie W
  How to prevent my app from closing the user's currently playing music? AdrianM 4 4,911 Aug 5, 2009 03:21 AM
Last Post: AdrianM
  Prevent screen from dimming during game npatrick6 3 3,677 May 22, 2009 10:22 PM
Last Post: AnotherJake
  Prevent iPhone SnapShot? Graphic Ace 5 3,746 Mar 29, 2009 08:49 AM
Last Post: Graphic Ace
  Override Incoming Phone Call Event with 3rd Party App happymondays 7 5,518 Jan 8, 2009 12:51 AM
Last Post: Nick