nehz
nehz

Reputation: 2182

OpenGL ES glPushClientAttrib

I am looking at porting some OpenGL code to OpenGL ES and was wondering what does this code do exactly:

glPushClientAttrib(GL_CLIENT_VERTEX_ARRAY_BIT)

as glPushClientAttrib does not exist in OpenGL ES. I am aware it saves the states of the OpenGL state machine, but I can't seem to find the exact mechanics of the GL_CLIENT_VERTEX_ARRAY_BIT flag.

I am guessing it saves the last vertex array pointer ?

Further investigation shows VBO (vertex buffer objects) are commonly used. This changes the pointer field for glVertexPointer to a offset. How does glPushClientAttrib(GL_CLIENT_VERTEX_ARRAY_BIT) behave with this (and related functions glBindBuffer, glBufferData) ?

EDIT: Just to clarify:

gl*Pointer() #1
glPushClientAttrib(*)
gl*Pointer() #2
glPopClientAttrib() <-- this is effectively calling #1 again or resetting to whatever #1 was 

Upvotes: 2

Views: 1330

Answers (1)

Maurice Gilden
Maurice Gilden

Reputation: 1954

glPushClientAttrib(GL_CLIENT_VERTEX_ARRAY_BIT) saves all the client side states for all vertex array attributes. So everything you set with the glEnableClientState/glDisableClientState and gl*Pointer functions. It won't copy the actual data. It also won't save anything set with glBindBuffer/glBufferData because those would be server side states. There's probably an enum for glPushAttrib for that in normal OpenGL (no glPushAttrib in OpenGL ES either).

I'm guessing that the difference between VBO and vertex array here is that VBOs have their actual data in graphics memory, while vertex arrays have to be streamed to the graphics card when you draw them. Pointers and enabled flags will still be saved with glPushClientAttrib when you are using VBOs, though.

For OpenGL ES you have to keep track of the states yourself if you want to return to the last state. Or better, set everything to default values after you are finished with it (calling glDisableClient for all enabled vertex arrays should be enough).

Upvotes: 5

Related Questions