Contents User Forum Source Index APIs by Task APIs by Level Data


G3D::RenderDevice Class Reference

You must call RenderDevice::init() before using the RenderDevice. More...

#include <RenderDevice.h>

List of all members.

Public Types

enum  { MAX_LIGHTS = 8 }
enum  AlphaTest {
  ALPHA_GREATER, ALPHA_LESS, ALPHA_GEQUAL, ALPHA_LEQUAL,
  ALPHA_NOTEQUAL, ALPHA_EQUAL, ALPHA_ALWAYS_PASS, ALPHA_NEVER_PASS,
  ALPHA_CURRENT
}
enum  BlendEq {
  BLENDEQ_MIN, BLENDEQ_MAX, BLENDEQ_ADD, BLENDEQ_SUBTRACT,
  BLENDEQ_REVERSE_SUBTRACT, BLENDEQ_CURRENT
}
enum  BlendFunc {
  BLEND_SRC_ALPHA, BLEND_ONE_MINUS_SRC_ALPHA, BLEND_ONE, BLEND_ZERO,
  BLEND_SRC_COLOR, BLEND_DST_COLOR, BLEND_ONE_MINUS_SRC_COLOR, BLEND_CURRENT
}
enum  Buffer {
  BUFFER_NONE, BUFFER_FRONT_LEFT, BUFFER_FRONT_RIGHT, BUFFER_BACK_LEFT,
  BUFFER_BACK_RIGHT, BUFFER_FRONT, BUFFER_BACK, BUFFER_LEFT,
  BUFFER_RIGHT, BUFFER_FRONT_AND_BACK, BUFFER_CURRENT, BUFFER_COLOR0,
  BUFFER_COLOR1, BUFFER_COLOR2, BUFFER_COLOR3, BUFFER_COLOR4,
  BUFFER_COLOR5, BUFFER_COLOR6, BUFFER_COLOR7, BUFFER_COLOR8,
  BUFFER_COLOR9, BUFFER_COLOR10, BUFFER_COLOR11, BUFFER_COLOR12,
  BUFFER_COLOR13, BUFFER_COLOR14, BUFFER_COLOR15
}
enum  CombineMode {
  TEX_REPLACE, TEX_BLEND, TEX_INTERPOLATE, TEX_ADD,
  TEX_MODULATE, TEX_ADD_SIGNED, TEX_SUBTRACT, TEX_DOT3_RGB,
  TEX_DOT3_RGBA, TEX_CURRENT
}
enum  CullFace { CULL_FRONT, CULL_BACK, CULL_NONE, CULL_CURRENT }
enum  DepthTest {
  DEPTH_GREATER, DEPTH_LESS, DEPTH_GEQUAL, DEPTH_LEQUAL,
  DEPTH_NOTEQUAL, DEPTH_EQUAL, DEPTH_ALWAYS_PASS, DEPTH_NEVER_PASS,
  DEPTH_CURRENT
}
enum  Primitive {
  LINES = MeshAlg::LINES, LINE_STRIP = MeshAlg::LINE_STRIP, TRIANGLES = MeshAlg::TRIANGLES, TRIANGLE_STRIP = MeshAlg::TRIANGLE_STRIP,
  TRIANGLE_FAN = MeshAlg::TRIANGLE_FAN, QUADS = MeshAlg::QUADS, QUAD_STRIP = MeshAlg::QUAD_STRIP, POINTS = MeshAlg::POINTS
}
enum  RenderMode { RENDER_SOLID, RENDER_WIREFRAME, RENDER_POINTS, RENDER_CURRENT }
enum  ShadeMode { SHADE_FLAT, SHADE_SMOOTH, SHADE_CURRENT }
enum  StencilOp {
  STENCIL_INCR_WRAP, STENCIL_DECR_WRAP, STENCIL_KEEP, STENCIL_INCR,
  STENCIL_DECR, STENCIL_REPLACE, STENCIL_ZERO, STENCIL_INVERT,
  STENCILOP_CURRENT
}
enum  StencilTest {
  STENCIL_GREATER, STENCIL_LESS, STENCIL_GEQUAL, STENCIL_LEQUAL,
  STENCIL_NOTEQUAL, STENCIL_EQUAL, STENCIL_ALWAYS_PASS, STENCIL_NEVER_PASS,
  STENCIL_CURRENT
}

Public Member Functions

void afterPrimitive ()
AlphaTest alphaTest () const
double alphaTestReference () const
bool alphaWrite () const
const Color4ambientLightColor () const
void beforePrimitive ()
void beginFrame ()
void beginIndexedPrimitives ()
void beginPrimitive (Primitive p)
void cleanup ()
void clear ()
void clear (bool clearColor, bool clearDepth, bool clearStencil)
Rect2D clip2D () const
const Color4color () const
bool colorWrite () const
void configureReflectionMap (uint textureUnit, Texture::Ref reflectionTexture)
void configureShadowMap (uint textureUnit, const Matrix4 &lightMVP, const Texture::Ref &shadowMap)
MilestoneRef createMilestone (const std::string &name)
bool currentFramebufferComplete (std::string &whyIncomplete=dummyString) const
uint32 debugNumMajorOpenGLStateChanges () const
uint32 debugNumMajorStateChanges () const
uint32 debugNumMinorOpenGLStateChanges () const
uint32 debugNumMinorStateChanges () const
uint32 debugNumPushStateCalls () const
bool depthWrite () const
void describeSystem (std::string &s)
void describeSystem (TextOutput &t)
void disableClip2D ()
void disableLighting ()
void disableTwoSidedLighting ()
Buffer drawBuffer () const
void enableClip2D (const Rect2D &clip)
void enableLighting ()
void enableTwoSidedLighting ()
void endFrame ()
void endIndexedPrimitives ()
void endPrimitive ()
double frameRate () const
const CoordinateFramegetCameraToWorldMatrix () const
std::string getCardDescription () const
double getDepthBufferValue (int x, int y) const
void getFixedFunctionLighting (const LightingRef &lighting) const
CoordinateFrame getModelViewMatrix () const
Matrix4 getModelViewProjectionMatrix () const
const CoordinateFramegetObjectToWorldMatrix () const
Matrix4 getProjectionMatrix () const
Matrix4 getTextureMatrix (uint textureUnit)
HDC getWindowHDC () const
int height () const
void init (GWindow *window, class Log *log=NULL)
void init (const GWindow::Settings &settings=GWindow::Settings(), class Log *log=NULL)
bool initialized () const
void majGLStateChange (int inc=1)
void majStateChange (int inc=1)
void minGLStateChange (int inc=1)
void minStateChange (int inc=1)
void notifyResize (int w, int h)
uint numTextureCoords () const
uint numTextures () const
uint numTextureUnits () const
void pop2D ()
void popState ()
Vector4 project (const Vector3 &v) const
Vector4 project (const Vector4 &v) const
void push2D (const Rect2D &viewport)
void push2D (const FramebufferRef &fb)
void push2D ()
void pushState (const FramebufferRef &fb)
void pushState ()
 RenderDevice ()
RenderMode renderMode () const
void resetState ()
void resetTextureUnit (uint textureUnit)
std::string screenshot (const std::string &filepath) const
void screenshotPic (GImage &dest, bool useBackBuffer=false, bool getAlpha=false) const
template<class T>
void sendIndices (RenderDevice::Primitive primitive, const Array< T > &index)
template<class T>
void sendIndices (RenderDevice::Primitive primitive, int numIndices, const T *index)
void sendSequentialIndices (RenderDevice::Primitive primitive, int numVertices)
void sendVertex (const Vector4 &vertex)
void sendVertex (const Vector3 &vertex)
void sendVertex (const Vector2 &vertex)
void setAlphaTest (AlphaTest test, double reference)
void setAlphaWrite (bool b)
void setAmbientLightColor (const Color4 &color)
void setAmbientLightColor (const Color3 &color)
void setBlendFunc (BlendFunc src, BlendFunc dst, BlendEq eq=BLENDEQ_ADD)
void setCameraToWorldMatrix (const CoordinateFrame &cFrame)
void setColor (const Color3 &color)
void setColor (const Color4 &color)
void setColorArray (const class VAR &v)
void setColorClearValue (const Color4 &c)
void setColorWrite (bool b)
void setCullFace (CullFace f)
void setDepthClearValue (double d)
void setDepthRange (double low, double high)
void setDepthTest (DepthTest test)
void setDepthWrite (bool b)
void setDrawBuffer (Buffer drawBuffer)
void setFramebuffer (const FramebufferRef &fbo)
void setLight (int num, void *)
void setLight (int num, const GLight &light)
void setLineWidth (double width)
void setMilestone (const MilestoneRef &m)
void setNormal (const Vector3 &normal)
void setNormalArray (const class VAR &v)
void setObjectToWorldMatrix (const CoordinateFrame &cFrame)
void setPixelProgram (const PixelProgramRef &pp, const GPUProgram::ArgList &args)
void setPixelProgram (const PixelProgramRef &pp)
void setPointSize (double diameter)
void setPolygonOffset (double offset)
void setProjectionAndCameraMatrix (const class GCamera &camera)
void setProjectionMatrix (const Matrix4 &P)
void setRenderMode (RenderMode mode)
void setShadeMode (ShadeMode s)
void setShader (const ShaderRef &s)
void setShininess (float s)
void setSpecularCoefficient (const Color3 &c)
void setSpecularCoefficient (float s)
void setStencilClearValue (int s)
void setStencilConstant (int reference)
void setStencilOp (StencilOp frontStencilFail, StencilOp frontZFail, StencilOp frontZPass, StencilOp backStencilFail, StencilOp backZFail, StencilOp backZPass)
void setStencilOp (StencilOp fail, StencilOp zfail, StencilOp zpass)
void setStencilTest (StencilTest test)
void setSwapBuffersAutomatically (bool b)
void setTexCoord (uint textureUnit, double texCoord)
void setTexCoord (uint textureUnit, const Vector2int16 &texCoord)
void setTexCoord (uint textureUnit, const Vector2 &texCoord)
void setTexCoord (uint textureUnit, const Vector3int16 &texCoord)
void setTexCoord (uint textureUnit, const Vector3 &texCoord)
void setTexCoord (uint textureUnit, const Vector4 &texCoord)
void setTexCoordArray (unsigned int unit, const class VAR &v)
void setTexture (uint textureUnit, Texture::Ref texture)
void setTextureCombineMode (uint textureUnit, const CombineMode texCombine)
void setTextureLODBias (uint unit, float bias)
void setTextureMatrix (uint textureUnit, const CoordinateFrame &c)
void setTextureMatrix (uint textureUnit, const Matrix4 &m)
void setTextureMatrix (uint textureUnit, const double *m)
void setTextureMatrix (uint textureUnit, const float *m)
void setVertexAndPixelShader (const VertexAndPixelShaderRef &s, const VertexAndPixelShader::ArgList &args)
void setVertexAndPixelShader (const VertexAndPixelShaderRef &s)
void setVertexArray (const class VAR &v)
void setVertexAttribArray (unsigned int attribNum, const class VAR &v, bool normalize)
void setVertexProgram (const VertexProgramRef &vp, const GPUProgram::ArgList &args)
void setVertexProgram (const VertexProgramRef &vp)
void setViewport (const Rect2D &v)
ShadeMode shadeMode () const
bool supportsOpenGLExtension (const std::string &extension) const
bool supportsPixelProgram () const
bool supportsTextureRectangle () const
bool supportsTwoSidedStencil () const
bool supportsVertexBufferObject () const
bool supportsVertexProgram () const
bool supportsVertexProgramNV2 () const
void swapBuffers ()
bool swapBuffersAutomatically () const
const StopwatchswapBufferTimer () const
int triangleCount () const
double triangleRate () const
double trianglesPerFrame () const
Rect2D viewport () const
void waitForMilestone (const MilestoneRef &m)
int width () const
GWindowwindow () const
 ~RenderDevice ()

Public Attributes

GLenum BufferToGL [27]
Stopwatch m_swapTimer

Static Public Attributes

static RenderDevicelastRenderDeviceCreated

Friends

class Milestone
class UserInput
class VAR
class VARArea
class VertexAndPixelShader

Classes

class  DebugSettings
class  RenderState
 Snapshot of the state maintained by the render device.
class  StatusInfo


Detailed Description

You must call RenderDevice::init() before using the RenderDevice.

Rendering interface that abstracts OpenGL. OpenGL is a basically good API with some rough spots. Three of these are addressed by RenderDevice. First, OpenGL state management is both tricky and potentially slow. Second, OpenGL functions are difficult to use because many extensions have led to an evolutionary rather than designed API. For type safety, new enums are introduced for values instead of the traditional OpenGL GLenum's, which are just ints. Third, OpenGL intialization is complicated. This interface simplifies it significantly.

NICEST line and point smoothing is enabled by default (however, you need to set your alpha blending mode to see it).

glEnable(GL_NORMALIZE) is set by default. glEnable(GL_COLOR_MATERIAL) is enabled by default. You may be able to get a slight speed increase by disabling GL_NORMALIZE or using GL_SCALE_NORMAL instead.

For stereo rendering, set GWindow::Settings::stereo = true and use RenderDevice::setDrawBuffer to switch which eye is being rendered. Only use RenderDevice::beginFrame/RenderDeviceendFrame once per frame, but do clear both buffers separately.

The only OpenGL calls NOT abstracted by RenderDevice are fog and texture coordinate generation. For everything else, use RenderDevice.

Example

   RenderDevice renderDevice = new RenderDevice();
   renderDevice->init(GWindow::Settings());
  

Example 2 (textured quad)

    RenderDevice* renderDevice = new RenderDevice();
    renderDevice->init(640, 480);

    Texture::Ref sprite = new Texture("Grass Texture", "image.jpg");

    renderDevice->beginFrame();
    renderDevice->pushState();
    renderDevice->clear(true, true, true);
    renderDevice->setCullFace(RenderDevice::CULL_NONE);
    renderDevice->setProjectionMatrix(Matrix4::perspectiveProjection(-.2, .2, -.15, .15, .2, 200));
    renderDevice->setTexture(0, sprite);
    renderDevice->setColor(Color3::white());
    renderDevice->beginPrimitive(RenderDevice::QUADS);
        renderDevice->setTexCoord(0,  Vector2(0, 1));
        renderDevice->sendVertex(Vector3(-3, -3, -5));

        renderDevice->setTexCoord(0,  Vector2(1, 1));
        renderDevice->sendVertex(Vector3( 3, -3, -5));

        renderDevice->setTexCoord(0,  Vector2(1, 0));
        renderDevice->sendVertex(Vector3( 3,  3, -5));

        renderDevice->setTexCoord(0,  Vector2(0, 0));
        renderDevice->sendVertex(Vector3(-3,  3, -5));
    renderDevice->endPrimitive();
    renderDevice->popState();

    renderDevice->endFrame();

    while (true);

    renderDevice->cleanup();
    

G3D::RenderDevice supports "X_CURRENT" as an option for most settings.

Stereo Rendering You can render in stereo (on a stereo capable card) by rendering twice, once for each eye's buffer:

    void doGraphics() {
        glDrawBuffer(GL_BACK_LEFT); 
        for (int count = 0; count < 2; ++count) {
           ... (put your normal rendering code here)
           glDrawBuffer(GL_BACK_RIGHT);
        }
    }
  

Multiple displays If you are using multiple synchronized displays (e.g. the CAVE), see: http://www.nvidia.com/object/IO_10753.html and http://www.cs.unc.edu/Research/stc/FAQs/nVidia/FrameLock-V1.0C.pdf

GLCaps loads the relevant extensions for you, but you must make the synchronizing calls yourself (typically, immediately before you call swap buffers).

Raw OpenGL Calls RenderDevice allows you to mix your own OpenGL calls with RenderDevice calls. It assumes that you restored the OpenGL state after your OpenGL calls, however. It is not safe to mix arbitrary OpenGL calls with Shaders, however. The G3D::Shader API supports more features than OpenGL shaders and does not work well with low-level OpenGL. You may find that the "wrong" shader is bound when you execute OpenGL calls.


Member Enumeration Documentation

anonymous enum

Enumerator:
MAX_LIGHTS 

Enumerator:
ALPHA_GREATER 
ALPHA_LESS 
ALPHA_GEQUAL 
ALPHA_LEQUAL 
ALPHA_NOTEQUAL 
ALPHA_EQUAL 
ALPHA_ALWAYS_PASS 
ALPHA_NEVER_PASS 
ALPHA_CURRENT 

Enumerator:
BLENDEQ_MIN 
BLENDEQ_MAX 
BLENDEQ_ADD 
BLENDEQ_SUBTRACT 
BLENDEQ_REVERSE_SUBTRACT 
BLENDEQ_CURRENT 

Enumerator:
BLEND_SRC_ALPHA 
BLEND_ONE_MINUS_SRC_ALPHA 
BLEND_ONE 
BLEND_ZERO 
BLEND_SRC_COLOR 
BLEND_DST_COLOR 
BLEND_ONE_MINUS_SRC_COLOR 
BLEND_CURRENT 

Enumerator:
BUFFER_NONE 
BUFFER_FRONT_LEFT 
BUFFER_FRONT_RIGHT 
BUFFER_BACK_LEFT 
BUFFER_BACK_RIGHT 
BUFFER_FRONT 
BUFFER_BACK 
BUFFER_LEFT 
BUFFER_RIGHT 
BUFFER_FRONT_AND_BACK 
BUFFER_CURRENT 
BUFFER_COLOR0 
BUFFER_COLOR1 
BUFFER_COLOR2 
BUFFER_COLOR3 
BUFFER_COLOR4 
BUFFER_COLOR5 
BUFFER_COLOR6 
BUFFER_COLOR7 
BUFFER_COLOR8 
BUFFER_COLOR9 
BUFFER_COLOR10 
BUFFER_COLOR11 
BUFFER_COLOR12 
BUFFER_COLOR13 
BUFFER_COLOR14 
BUFFER_COLOR15 

Arguments to setTextureCombineMode.

TEX_INTERPOLATE = GL_DECAL (blend between previous and current texture based on current alpha)

Note: GL_INTERPOLATE_ARB is not supported because it takes two arguments. You can access it yourself using glTexEnvi.

TEX_BLEND = GL_BLEND (for luminance textures, blend against a constant)

TEX_ADD is only present if GLCaps::supports("GL_EXT_texture_env_add") See http://oss.sgi.com/projects/ogl-sample/registry/ARB/texture_env_add.txt

TEX_ADD_SIGNED and TEX_SUBTRACT are only present if GLCaps::supports("GL_ARB_texture_env_combine") See http://oss.sgi.com/projects/ogl-sample/registry/ARB/texture_env_combine.txt

TEX_DOT3_RGB and TEX_DOT3_RGBA are only present if GLCaps::supports("GL_ARB_texture_env_dot3") http://oss.sgi.com/projects/ogl-sample/registry/ARB/texture_env_dot3.txt

Enumerator:
TEX_REPLACE 
TEX_BLEND 
TEX_INTERPOLATE 
TEX_ADD 
TEX_MODULATE 
TEX_ADD_SIGNED 
TEX_SUBTRACT 
TEX_DOT3_RGB 
TEX_DOT3_RGBA 
TEX_CURRENT 

Enumerator:
CULL_FRONT 
CULL_BACK 
CULL_NONE 
CULL_CURRENT 

Enumerator:
DEPTH_GREATER 
DEPTH_LESS 
DEPTH_GEQUAL 
DEPTH_LEQUAL 
DEPTH_NOTEQUAL 
DEPTH_EQUAL 
DEPTH_ALWAYS_PASS 
DEPTH_NEVER_PASS 
DEPTH_CURRENT 

Enumerator:
LINES 
LINE_STRIP 
TRIANGLES 
TRIANGLE_STRIP 
TRIANGLE_FAN 
QUADS 
QUAD_STRIP 
POINTS 

RENDER_CURRENT = preserve whatever the render mode is currently set to.

Enumerator:
RENDER_SOLID 
RENDER_WIREFRAME 
RENDER_POINTS 
RENDER_CURRENT 

Enumerator:
SHADE_FLAT 
SHADE_SMOOTH 
SHADE_CURRENT 

Enumerator:
STENCIL_INCR_WRAP 
STENCIL_DECR_WRAP 
STENCIL_KEEP 
STENCIL_INCR 
STENCIL_DECR 
STENCIL_REPLACE 
STENCIL_ZERO 
STENCIL_INVERT 
STENCILOP_CURRENT 

Enumerator:
STENCIL_GREATER 
STENCIL_LESS 
STENCIL_GEQUAL 
STENCIL_LEQUAL 
STENCIL_NOTEQUAL 
STENCIL_EQUAL 
STENCIL_ALWAYS_PASS 
STENCIL_NEVER_PASS 
STENCIL_CURRENT 


Constructor & Destructor Documentation

G3D::RenderDevice::RenderDevice (  ) 

G3D::RenderDevice::~RenderDevice (  ) 


Member Function Documentation

void G3D::RenderDevice::afterPrimitive (  ) 

Automatically called immediately after a primitive group.

See also beforePrimitive.

AlphaTest G3D::RenderDevice::alphaTest (  )  const

double G3D::RenderDevice::alphaTestReference (  )  const

bool G3D::RenderDevice::alphaWrite (  )  const

Returns true if alphaWrite is enabled.

const Color4& G3D::RenderDevice::ambientLightColor (  )  const [inline]

void G3D::RenderDevice::beforePrimitive (  ) 

Automatically called immediately before a primitive group.

User code should only call this if making raw OpenGL calls (i.e., "glBegin"), in which case it should be called immediately before the glBegin and afterPrimitve should be called immediately after the glEnd.

void G3D::RenderDevice::beginFrame (  ) 

Call to begin the rendering frame.

void G3D::RenderDevice::beginIndexedPrimitives (  ) 

void G3D::RenderDevice::beginPrimitive ( Primitive  p  ) 

Analogous to glBegin.

See the example in the detailed description section of this page.

void G3D::RenderDevice::cleanup (  ) 

Shuts down the system.

This should be the