Reputation: 2063
I'm working on some graphical application and i got an GL_INVALID_OPERATION
after glPopAttrib()
. Predicting the answer "It seems you call glPopAttrib()
within glBegin/glEnd
block" please see this log i've made with GLIntercept.
/* tons of wglGetProcAddress* */
wglGetProcAddress("glEndOcclusionQueryNV")=087C9B10
wglGetProcAddress("glBeginTransformFeedbackN...")=087C9ED0
wglGetProcAddress("glEndTransformFeedbackNV")=087C9F00
glPushAttrib(GL_VIEWPORT_BIT)
glPushAttrib(GL_COLOR_BUFFER_BIT)
glPushAttrib(GL_COLOR_BUFFER_BIT)
glPopAttrib()
glPopAttrib() glGetError() = GL_INVALID_OPERATION # <---- THIS
glPopAttrib()
glPushAttrib(GL_VIEWPORT_BIT)
glPushAttrib(GL_COLOR_BUFFER_BIT)
glPushAttrib(GL_COLOR_BUFFER_BIT)
glPopAttrib()
glPushAttrib(GL_POINT_BIT | GL_LINE_BIT | GL_COLOR_BUFFER_BIT)
glPopAttrib()
glPopAttrib()
glPopAttrib()
glPushAttrib(GL_VIEWPORT_BIT)
glPushAttrib(GL_COLOR_BUFFER_BIT)
glPushAttrib(GL_COLOR_BUFFER_BIT)
glPopAttrib()
glPopAttrib()
glPopAttrib()
/* and so on */
No glBegin/glEnd
callings are made before error-causeing glPopAttrib()
. (I used findstr commad to filter the log).
The error appears only once, no such (or others) error appers again during the code execution. I have an suspicion that i should call some function before glPushAttrib(GL_VIEWPORT_BIT)
or something.
Upvotes: 10
Views: 1277
Reputation: 3420
I was having the same problem, and finally figured out the cause:
When you call a glBindFramebuffer
between a glPushAttrib(GL_COLOR_BUFFER_BIT)
and a glPopAttrib
, a GL_INVALID_OPERATION
is caused on the glPopAttrib call.
This even happens when you restore the original frame buffer binding before calling glPopAttrib.
The only solution seems to be either avoid all glBindFramebuffer calls between the glPushAttrib and glPopAttrib, or avoid using glPushAttrib and glPopAttrib by storing and restoring all relevant color buffer state manually.
Upvotes: 3
Reputation: 1420
Interesting problem. Got me thinking ..
What could be happening is that some of the state variables associated with the COLOR_BUFFER_BIT
were not initialized with proper values when the OpenGL context was got from the window system. When you did a glPushAttrib
, those (probably) incorrect values were saved, and when the attrib was popped, the incorrect values were restored - causing a invalid operation ? Does that sound logical ?
Upvotes: 2