I want to write a general purpose utility function that will use an OpenGL Framebuffer Object to create a texture that can be used by some OpenGL program for whatever purpose a third party programmer would like.
Lets say for argument stake the function looks like
void createSpecialTexture(GLuint textureID)
{
MyOpenGLState state;
saveOpenGLState(state);
setStateToDefault();
doMyDrawing();
restoreOpenGLState(state);
}
What should MyOpenGLState
, saveOpenGLState(state)
, setStateToDefault()
and restoreOpenGLState(state)
look like to ensure that doMyDrawing
will behave correctly and that nothing that I do in doMyDrawing
will affect anything else that a third party developer might be doing?
The problem that has been biting me is that OpenGL has a lot of implicit state and I am not sure I am capturing it all.
Update: My main concern is OpenGL ES 2.0 but I thought I would ask the question more generally
Don't use a framebuffer object to render your texture. Rather create a new EGLContext and EGLSurface. You can then use eglBindTexImage
to turn your EGLSurface into a texture. This way you are guaranteed that state from doMyDrawing
will not pollute the main gl Context and visa versa.
As for saving and restoring, glPushAttrib
and glPopAttrib
will get you very far.
You cannot, however, restore GL to a default state. However, since doMyDrawing()
uses and/or modifies only state that should be known to you, you can just set that to values that you need.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With