Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

glPopAttrib & GL_INVALID_OPERATION

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.

like image 452
fogbit Avatar asked Dec 14 '11 13:12

fogbit


1 Answers

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.

like image 199
Danny Ruijters Avatar answered Oct 19 '22 12:10

Danny Ruijters