com.threerings.opengl.renderer
Class TextureRenderer

java.lang.Object
  extended by com.threerings.opengl.renderer.TextureRenderer

public class TextureRenderer
extends Object

Provides render-to-texture functionality using various methods according to the abilities of the driver.


Nested Class Summary
protected static class TextureRenderer.InstanceKey
          Identifies a shared texture renderer instance.
 
Field Summary
protected  Texture _color
          The color and/or depth textures to which we render.
protected  GlContext _ctx
          The renderer context.
protected  Texture _depth
          The color and/or depth textures to which we render.
protected  Framebuffer _framebuffer
          The frame buffer object, if supported.
protected  int _height
          The width and height of the render surface.
protected static SoftCache<TextureRenderer.InstanceKey,TextureRenderer> _instances
          The shared texture renderer instances.
protected  int _level
          The mipmap level.
protected  boolean _matchTextureDimensions
          If true, change the render surface dimensions to match the texture dimensions.
protected  Framebuffer _obuffer
          The originally bound frame buffer.
protected  int _odraw
          The original draw and read buffers.
protected  int _oread
          The original draw and read buffers.
protected  Renderer _orenderer
          The original context renderer.
protected  Rectangle _oviewport
          The original viewport.
protected  int _param
          The cube map face index or z offset, as appropriate.
protected  Pbuffer _pbuffer
          The pbuffer object, if supported.
protected  PixelFormat _pformat
          The requested pixel format.
protected  int _pheight
          The dimensions of the Pbuffer.
protected  int _pwidth
          The dimensions of the Pbuffer.
protected  Renderer _renderer
          The renderer with which we render.
protected  RenderTexture _rtex
          The render-to-texture configuration.
protected  int _width
          The width and height of the render surface.
 
Constructor Summary
TextureRenderer(GlContext ctx, Texture color, Texture depth, int width, int height, PixelFormat pformat)
          Creates a new texture renderer to render into the specified texture(s).
 
Method Summary
protected  void bindTextures()
          Binds the texture(s) to the pbuffer.
 void commitRender()
          Stops rendering to the texture (and makes it available for use).
protected  void copyTexture(Texture texture)
          Copies a single texture from the buffer.
protected  void copyTextures()
          Copies the textures from the buffer.
protected static void deleteFramebuffer(Framebuffer framebuffer)
          Deletes the specified frame buffer and its render buffer attachments.
 void dispose()
          Disposes of this texture renderer, rendering it unusable.
protected  void finalize()
           
 Texture getColor()
          Returns a reference to the color texture (if any).
 Texture getDepth()
          Returns a reference to the depth texture (if any).
protected static int getDepthFormat(int bits)
          Returns the depth format with the specified number of bits.
 int getHeight()
          Returns the configured height of the renderer.
static TextureRenderer getInstance(GlContext ctx, Texture color, Texture depth, int width, int height, PixelFormat pformat)
          Retrieves the shared texture renderer instance for the supplied textures.
static TextureRenderer getInstance(GlContext ctx, Texture color, Texture depth, PixelFormat pformat)
          Retrieves the shared texture renderer instance for the supplied textures.
protected static int getRenderTextureTarget(int target)
          Returns the render texture target corresponding to the specified texture target.
protected static int getStencilFormat(int bits)
          Returns the stencil format with the specified number of bits.
 int getWidth()
          Returns the configured width of the renderer.
protected  void initPbuffer()
          (Re)initializes the pbuffer.
protected static void maybeDeleteAttachment(Object attachment)
          Deletes the supplied attachment if it is a Renderbuffer.
protected  void releaseTextures()
          Releases the texture(s) from the pbuffer.
protected  void resize(int width, int height)
          Resizes the texture render state to match the supplied dimensions.
 void startRender()
          Starts rendering to the texture.
 void startRender(int level, int param)
          Starts rendering to the texture.
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_ctx

protected GlContext _ctx
The renderer context.


_renderer

protected Renderer _renderer
The renderer with which we render.


_width

protected int _width
The width and height of the render surface.


_height

protected int _height
The width and height of the render surface.


_matchTextureDimensions

protected boolean _matchTextureDimensions
If true, change the render surface dimensions to match the texture dimensions.


_pformat

protected PixelFormat _pformat
The requested pixel format.


_color

protected Texture _color
The color and/or depth textures to which we render.


_depth

protected Texture _depth
The color and/or depth textures to which we render.


_framebuffer

protected Framebuffer _framebuffer
The frame buffer object, if supported.


_pwidth

protected int _pwidth
The dimensions of the Pbuffer.


_pheight

protected int _pheight
The dimensions of the Pbuffer.


_rtex

protected RenderTexture _rtex
The render-to-texture configuration.


_pbuffer

protected Pbuffer _pbuffer
The pbuffer object, if supported.


_level

protected int _level
The mipmap level.


_param

protected int _param
The cube map face index or z offset, as appropriate.


_oviewport

protected Rectangle _oviewport
The original viewport.


_obuffer

protected Framebuffer _obuffer
The originally bound frame buffer.


_orenderer

protected Renderer _orenderer
The original context renderer.


_odraw

protected int _odraw
The original draw and read buffers.


_oread

protected int _oread
The original draw and read buffers.


_instances

protected static SoftCache<TextureRenderer.InstanceKey,TextureRenderer> _instances
The shared texture renderer instances.

Constructor Detail

TextureRenderer

public TextureRenderer(GlContext ctx,
                       Texture color,
                       Texture depth,
                       int width,
                       int height,
                       PixelFormat pformat)
Creates a new texture renderer to render into the specified texture(s).

Parameters:
width - the width of the render surface, or -1 to match the texture dimensions.
height - the height of the render surface, or -1.
Method Detail

getInstance

public static TextureRenderer getInstance(GlContext ctx,
                                          Texture color,
                                          Texture depth,
                                          PixelFormat pformat)
Retrieves the shared texture renderer instance for the supplied textures.


getInstance

public static TextureRenderer getInstance(GlContext ctx,
                                          Texture color,
                                          Texture depth,
                                          int width,
                                          int height,
                                          PixelFormat pformat)
Retrieves the shared texture renderer instance for the supplied textures.

Parameters:
width - the width of the render surface, or -1 to match the texture dimensions.
height - the height of the render surface, or -1.

getWidth

public int getWidth()
Returns the configured width of the renderer.


getHeight

public int getHeight()
Returns the configured height of the renderer.


getColor

public Texture getColor()
Returns a reference to the color texture (if any).


getDepth

public Texture getDepth()
Returns a reference to the depth texture (if any).


startRender

public void startRender()
Starts rendering to the texture.


startRender

public void startRender(int level,
                        int param)
Starts rendering to the texture.

Parameters:
level - the mipmap level.
param - the cube map face index or z offset, as appropriate.

commitRender

public void commitRender()
Stops rendering to the texture (and makes it available for use).


dispose

public void dispose()
Disposes of this texture renderer, rendering it unusable.


finalize

protected void finalize()
                 throws Throwable
Overrides:
finalize in class Object
Throws:
Throwable

resize

protected void resize(int width,
                      int height)
Resizes the texture render state to match the supplied dimensions.


initPbuffer

protected void initPbuffer()
(Re)initializes the pbuffer.


bindTextures

protected void bindTextures()
Binds the texture(s) to the pbuffer.


releaseTextures

protected void releaseTextures()
Releases the texture(s) from the pbuffer.


copyTextures

protected void copyTextures()
Copies the textures from the buffer.


copyTexture

protected void copyTexture(Texture texture)
Copies a single texture from the buffer.


getDepthFormat

protected static int getDepthFormat(int bits)
Returns the depth format with the specified number of bits.


getStencilFormat

protected static int getStencilFormat(int bits)
Returns the stencil format with the specified number of bits.


getRenderTextureTarget

protected static int getRenderTextureTarget(int target)
Returns the render texture target corresponding to the specified texture target.


deleteFramebuffer

protected static void deleteFramebuffer(Framebuffer framebuffer)
Deletes the specified frame buffer and its render buffer attachments.


maybeDeleteAttachment

protected static void maybeDeleteAttachment(Object attachment)
Deletes the supplied attachment if it is a Renderbuffer.