Affects Version/s: current
Fix Version/s: milestone 1
Operating System: All
The current render-to-texture functionality makes use of the
WGL_ARB_render_texture extension to allow a Pbuffer's colour buffer to be bound
to a texture. It would also be useful to be able to use the
WGL_NV_render_depth_texture extension to allow binding of the Pbuffer's depth
buffer to a depth texture. The implementation of such a feature (on Windows)
could parallel the already present render-to-texture functionality. An example
of such an implementation is available at
The implementation makes the following modifications to the JOGL code base:
- Add a boolean field offscreenRenderToDepthTexture (similar to
offscreenRenderToTexture) that indicates whether the created Pbuffer should
- Add accessors (getOffscreenRenderToDepthTexture(),
setOffscreenRenderToDepthTexture(boolean onOrOff) for the above field.
- Add a method bindDepthTexture() (similar to bindTexture()) that calls for
the Pbuffer's depth buffer to be bound to GL_TEXTURE_2D or
- Add a method releaseDepthTexture() that parallel's depthTexture().
- Implement the added GLPbuffer interface methods (above) by calling the
corresponding methods on the context (below)
- Add an abstract method bindPbufferToDepthTexture() (similar to
- Add an abstract method releasePbufferFromDepthTexture() (similar to
- Implement the added GLContext abstract methods (above) with versions that
throw exceptions indicating that they should not be called.
- Add a field rtdt (similar to rtt) indicating whether render-to-depth-texture
- Add a field hasRTDT (similar to RTDT) indicating whether the
render-to-depth-texture extension is available.
- Add a field depthTexture (similar to texture) that holds the texture object
ID of the depth texture.
- Modify the constructor's DEBUG output to include rtdt.
- Implement bindPbufferToDepthTexture() in a manner similar to
bindPbufferToTexture(), except that the wglBindTexImageARB() call binds to
WGL_DEPTH_COMPONENT_NV instead of WGL_FRONT_LEFT_ARB.
- Implement releasePbufferFromDepthTexture() (with the same relationship to
- Modify createPbuffer(long, long):
- Initialize rtdt from the capabilities.
- On many of the tests that check whether rtt == true, modify to check
whether (rtt || rtdt) == true.
- If rtdt, add to the iattributes array the pair:
WGL_BIND_TO_TEXTURE_DEPTH_NV (depending on rect) and GL_TRUE (to enable
binding of the depth buffer to a texture).
- In the NVidia work-around loop, if rtdt, add the
WGL_DEPTH_TEXTURE_FORMAT_NV and WGL_TEXTURE_DEPTH_COMPONENT_NV pair to the
- Modify makeCurrent(Runnable):
- Initialize rtdt from the capabilities.
- Determine the render-to-texture-rectangle settings if rtt or rtdt is true.
- If rtdt:
- Determine whether the render-to-depth-texture extension is available.
- Generate a texture to be bound to the depth buffer.
- Bind the generated texture to the texture target.
- Configure the texture lookup parameters.
- Choose the internal format of the texture (one of the depth formats)
- Create the texture with null contents.
- Modify swapBuffers():
- If render-to-depth-texture is enabled (rtdt), but the extension is not
available (!hasRTDT), copy the depth buffer to the depth texture.
- In both the new copying case and the existing colour buffer copy, bind the
appropriate texture to the texture target before copying.
- Not yet implemented (methods added with comments/exceptions to that effect)
- By paralleling render-to-depth-texture alongside render-to-texture, it is
possible to bind both the colour buffer and the depth buffer of a Pbuffer to
- For simplicity, the existing render-to-texture-rect settings are made to
apply to both the colour and depth textures. It should be possible to allow
(eg.) the colour buffer to be bound to GL_TEXTURE_RECTANGLE_NV, and the
depth buffer to be bound to GL_TEXTURE_2D, but it doesn't seem that useful.
- The example patch was created against the latest source from CVS as of
June 4, 2005.
- As well as implementing the described render-to-depth-texture functionality,
the example patch implements the exposure of the texture target (i.e.
allowing the API programmer to determine whether the buffers are bound to
GL_TEXTURE_2D or GL_TEXTURE_RECTANGLE_NV.
- Also included in the source archive is and example application
(RenderToTexture.java) that demonstrates the combined use of
render-to-texture and render-to-depth-texture.