I would like to develop a SciPy toolkit for GPU-accelerated
computation. Tristam MacDonald recently posted a neat Shader class
exposing GLSL, which provided me with a good starting point. I have a
couple of further questions, and would be glad for any help:
1) How do I implement offscreen rendering? It seems like Framebuffer
Objects provide the best cross-"platform" solution, but Pyglet does
not explicitly provide an API to access those.
2) How do I render a single frame and grab it (instead of rendering 60
fps until I'm reasonably sure the computation is done).
3) Are double-precision buffers available, or can I only do
single-precision fixed-point processing in GLSL?
Thank you for all your hard work on exposing OpenGL to the masses.
Pyglet is great!
Kind regards,
Stéfan
1) How do I implement offscreen rendering? It seems like Framebuffer
Objects provide the best cross-"platform" solution, but Pyglet does
not explicitly provide an API to access those.
2) How do I render a single frame and grab it (instead of rendering 60
fps until I'm reasonably sure the computation is done).
3) Are double-precision buffers available, or can I only do
single-precision fixed-point processing in GLSL?
Indeed. Here's some code from my old wydget toolkit in pyglet contrib:
# create our frame buffer
fbo = gl.GLuint()
gl.glGenFramebuffersEXT(1, ctypes.byref(fbo))
gl.glBindFramebufferEXT(gl.GL_FRAMEBUFFER_EXT, fbo)
# allocate a texture and add to the frame buffer
tex = image.Texture.create_for_size(gl.GL_TEXTURE_2D, w, h,
gl.GL_RGBA)
gl.glBindTexture(gl.GL_TEXTURE_2D, tex.id)
gl.glFramebufferTexture2DEXT(gl.GL_FRAMEBUFFER_EXT,
gl.GL_COLOR_ATTACHMENT0_EXT, gl.GL_TEXTURE_2D, tex.id, 0)
status = gl.glCheckFramebufferStatusEXT(gl.GL_FRAMEBUFFER_EXT)
assert status == gl.GL_FRAMEBUFFER_COMPLETE_EXT
# now render
gl.glBindFramebufferEXT(gl.GL_FRAMEBUFFER_EXT, fbo)
function()
gl.glBindFramebufferEXT(gl.GL_FRAMEBUFFER_EXT, 0)
# clean up
gl.glDeleteFramebuffersEXT(1, ctypes.byref(fbo))
where function, w and h are things you need to provide.
> However, frame buffer objects still need a valid opengl context to operate
> (as do all opengl features). Your best bet would be to create a window with
> visible=False, and leave it invisible while rendering into your FBO. I
> can't guarantee this to work, as I haven't tried it, but the theory is
> sound.
pyglet creates a context at startup so that shouldn't be necessary.
Richard
Thank you, Tristam and Richard, for your thoughtful answers. These
should get me up and running quickly!
Regards
Stéfan