OpenGL state recovery

I want to write a universal utility function that will use an OpenBl Framebuffer object to create a texture that can be used by any OpenGL program for any purpose that a third-party programmer would like to request.

Assume that for an argument rate, the function looks like

void createSpecialTexture(GLuint textureID)
{
    MyOpenGLState state;
    saveOpenGLState(state);
    setStateToDefault();
    doMyDrawing();
    restoreOpenGLState(state);
}

What should be MyOpenGLState, saveOpenGLState(state), setStateToDefault()and restoreOpenGLState(state)look to ensure that doMyDrawingwill behave correctly and that there is nothing that I do in doMyDrawingnot affect anything else that a third party can be?

The problem that bites me is that OpenGL has a lot of implicit state, and I'm not sure if this all captured.

Update . My main problem is OpenGL ES 2.0, but I thought that I would ask the question as a whole

+5
source share
3 answers

Do not use the framebuffer object to render your texture. Rather, create a new EGLContext and EGLSurface. Then you can use eglBindTexImageto turn the EGLSurface into a texture. This way, you are guaranteed that the state of doMyDrawingwill not pollute the main context and vice versa.

+1
source

As for the preservation and restoration, glPushAttriband they will glPopAttribtake you very far.

GL . , doMyDrawing() / , , , .

0

, doMyDrawing();, ( ), . , doMyDrawing();, , .

doMyDrawing(), GL_PROJECTION GL_MODELVIEW glPushMatrix glPopMatrix. , , push pop, glPushAttrib . , FBO, PBO .., doMyDrawing();

0

All Articles