Playing a bit with Python context managers for PyOpenGL. Considering adding them pervasively, likely with a configuration flag. (idea is from Florian's gletools)...
- OpenGL.arrays.VBO -- make a context manager itself (this is already implemented)
- OpenGL.GL.compileShader -- make the shader int returned a context manager (implemented)
Those two I consider non-controversial, as they are already non-standard entry points, and the "thing" really is a context manager, you want to do things "with" it. More pause-inducing:
- glEnable*/glDisable* -- return context manager reversing the boolean logic, including e.g. glEnableClient* glEnableVertexAttrib*, etc.
- glPush* -- return context manager doing a pop of the same
- glBegin* -- return context manager doing glEnd*, glBeginQuery and the like included
- glEnable*Pointer -- essentially just glEnableVertexAttrib, really
Those operations would (necessarily) become slower, since they'd wind up in Python (or I guess I could code a Cython accelerator)... they're going to be more complex no matter how I handle it.
Then there's a whole suite of operations that are state-setters where you normally want to work with the context and then reset to default or some application-specific value:
The thing is, at least for *my* code I can't really see myself using the contexts for any but the lowest-level of operations. The scenegraph winds up with e.g. the texture, shader and VBO enabling in totally different modules, where they are all independent of one another. When I consider adding this intrusive a feature with the thought "but I'll likely seldom use it myself" I start to wonder if I really want to add it, or if it should be in a higher-level library.
Pingbacks are closed.