RenderTexture Class Reference

Mark Harris's RenderTexture pbuffer class. More...

#include <RenderTexture.h>

List of all members.

Public Member Functions

 RenderTexture (const char *strMode="rgb tex2D")
 Constructor.
 ~RenderTexture ()
 Destructor.
bool Initialize (int width, int height, bool shareObjects=true, bool copyContext=false)
 Initializes the RenderTexture, sharing display lists and textures if specified.
bool Reset (const char *strMode,...)
 Change the render texture format.
bool Resize (int width, int height)
 Change the size of the render texture.
bool BeginCapture ()
 Begin drawing to the texture. (i.e. use as "output" texture).
bool BeginCapture (RenderTexture *current)
 Ends drawing to 'current', begins drawing to this RenderTexture.
bool EndCapture ()
 End drawing to the texture.
void Bind () const
 Bind the texture to the active texture unit for use as an "input" texture.
void BindDepth () const
 Bind the depth texture to the active texture unit for use as an "input" texture.
bool BindBuffer (int iBuffer)
 Associate the RTT texture with 'iBuffer' (default is WGL_FRONT_LEFT_ARB).
void EnableTextureTarget () const
 Enables the texture target appropriate for this render texture.
void DisableTextureTarget () const
 Disables the texture target appropriate for this render texture.
unsigned int GetTextureID () const
 Returns the texture ID. Useful in Cg applications.
unsigned int GetDepthTextureID () const
 Returns the depth texture ID. Useful in Cg applications.
unsigned int GetTextureTarget () const
 Returns the texture target this texture is bound to.
 operator unsigned int () const
 Conversion operator allows RenderTexture to be passed to GL calls.
int GetWidth () const
 Returns the width of the offscreen buffer.
int GetHeight () const
 Returns the width of the offscreen buffer.
int GetMaxS () const
 Returns the maximum S texture coordinate.
int GetMaxT () const
 Returns the maximum T texture coordinate.
int GetRedBits () const
 Returns the number of red bits allocated.
int GetGreenBits () const
 Returns the number of green bits allocated.
int GetBlueBits () const
 Returns the number of blue bits allocated.
int GetAlphaBits () const
 Returns the number of alpha bits allocated.
int GetDepthBits () const
 Returns the number of depth bits allocated.
int GetStencilBits () const
 Returns the number of stencil bits allocated.
bool IsInitialized () const
 True if this RenderTexture has been properly initialized.
bool IsTexture () const
 True if this is a texture and not just an offscreen buffer.
bool IsDepthTexture () const
 True if this is a depth texture and not just an offscreen buffer.
bool IsFloatTexture () const
 True if this is a floating point buffer / texture.
bool IsDoubleBuffered () const
 True if this is a double-buffered pbuffer.
bool IsRectangleTexture () const
 True if this texture has non-power-of-two dimensions.
bool HasDepth () const
bool HasStencil () const
 True if this pbuffer has a stencil buffer.
bool IsMipmapped () const
 True if this texture has mipmaps.
 RenderTexture (int width, int height, bool bIsTexture=true, bool bIsDepthTexture=false)
 Constructor.
bool Reset (int iWidth, int iHeight)
 Resets the resolution of the offscreen buffer.

Static Public Member Functions

static bool IsPowerOfTwo (int n)
 Returns true if /param n is an integer power of 2.

Protected Member Functions

bool _Invalidate ()
 Returns the pbuffer memory to the graphics device.
void _ParseModeString (const char *modeString, std::vector< int > &pixelFormatAttribs, std::vector< int > &pbufferAttribs)
 Parses the user-specified mode string for RenderTexture parameters.
bool _VerifyExtensions ()
 Checks that the necessary extensions are available based on RT mode.
bool _InitializeTextures ()
 Initializes the state of textures used by the RenderTexture.
void _MaybeCopyBuffer ()
 Does the actual copying for RenderTextures with RT_COPY_TO_TEXTURE.
bool _ReleaseBoundBuffers ()
 Releases buffer bindings on RenderTextures with RT_RENDER_TO_TEXTURE.
bool _MakeCurrent ()
 Makes the RenderTexture's context current.
bool _BindDepthBuffer () const
 Associate the RTT depth texture id with the depth buffer.


Detailed Description

Mark Harris's RenderTexture pbuffer class.

This class provides an abstraction of the pbuffer functionality for off-screen rendering useful in GPGPU applications.

The pixel format for the pbuffer is controlled by the mode string passed into the PBuffer constructor. This string can have the following attributes

To specify the pixel format, use the following syntax. [channels]=[bits] [channels] must match one of the following.

r - r pixel format (for float buffer). rg - rg pixel format (for float buffer). rgb - rgb pixel format. 8 bit or 16,32 bit in float buffer mode rgba - same as "rgb alpha" string

[bits] can either be a scalar, meaning the same bit depth for each channel- or a 2-, 3-, 4-component vector matching the specified number of channels. Vector components should be comma separated. An optional 'f' suffix on the bit depth specifies float components. In this case [bits] must be either "32f" or "16f". If [bits] is empty, the default 8 bits per channel will be used. r=32f rg=16f rgb=8 rgb=5,6,5

The following other attributes are supported.

depth=n - must have n-bit depth buffer, omit n for default (24 bits) stencil=n - must have n-bit stencil buffer, omit n for default (8 bits) samples=n - must support n-sample antialiasing (n can be 2 or 4) aux=n - must have n AUX buffers doublebuffer - must support double buffered rendering

tex2D texRECT texCUBE - must support binding pbuffer as texture to specified target

rtt ctt - These mutually exclusive options specify the update method used for render textures that support texture binding. "rtt" indicates that render to texture will be used to update the texture. "ctt" indicates that copy to texture will be used (i.e. glCopyTexSubImage2D()). "rtt" is the default if neither is specified, and one of the "tex*" options above is.

---------------------------------------------------------------------------

USAGE NOTES:

* Texture Parameters: The default texture wrap mode is GL_CLAMP_TO_EDGE for all textures, and the default texture filtering modes (min and mag) are GL_NEAREST. To change these parameters, simply bind the RenderTexture (using the Bind() method), and set them the way you would for any GL texture object. The same goes for depth textures.

* Enabling Mipmapping: This is similar to the texture parameters above. When "rtt" is specified in the mode string, "mipmap" must also be specified in order to enable a mipmapped pbuffer. Then, the mipmaps must be created by enabling the GL_SGIS_GENERATE_MIPMAP texture parameter in the same way as above, and the min filter mode must be set to a mipmap filter mode, as with any mipmapped texture object.

* Enabling Anisotropic Filtering As with the texture parameters above, except as in the following code: glGetFloatv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, max); glTexParameterf(target, GL_TEXTURE_MAX_ANISOTROPY_EXT, <value < max>);


Member Function Documentation

bool RenderTexture::BeginCapture RenderTexture current  ) 
 

Ends drawing to 'current', begins drawing to this RenderTexture.

When performing a series of operations where you modify one texture after another, it is more efficient to use this method instead of the equivalent 'EndCapture'/'BeginCapture' pair. This method switches directly to the new context rather than changing to the default context, and then to the new context.

RenderTexture doesn't have any mechanism for determining if 'current' really is currently active, so no error will be thrown if it is not.

bool RenderTexture::HasDepth  )  const [inline]
 

True if this texture has non-power-of-two dimensions. True if this pbuffer has a depth buffer.

bool RenderTexture::Initialize int  width,
int  height,
bool  shareObjects = true,
bool  copyContext = false
 

Initializes the RenderTexture, sharing display lists and textures if specified.

Call this once before use. Set bShare to true to share lists, textures, and program objects between the render texture context and the current active GL context.

RenderTexture::IsPowerOfTwo int  n  )  [inline, static]
 

Returns true if /param n is an integer power of 2.

Taken from Steve Baker's Cute Code Collection. http://www.sjbaker.org/steve/software/cute_code.html

bool RenderTexture::Reset int  iWidth,
int  iHeight
 

Resets the resolution of the offscreen buffer.

Causes the buffer to delete itself. User must call Initialize() again before use.

bool RenderTexture::Reset const char *  strMode,
  ...
 

Change the render texture format.

Causes the buffer to delete itself. User must call Initialize() again before use.

bool RenderTexture::Resize int  iWidth,
int  iHeight
 

Change the size of the render texture.

Like Reset() this causes the buffer to delete itself. But unlike Reset(), this call re-initializes the RenderTexture. Note that Resize() will not work after calling Reset(), or before calling Initialize() the first time.


The documentation for this class was generated from the following files:
Generated on Sat Apr 15 00:50:15 2006 for GpuVis by  doxygen 1.4.6-NO