Support Forum       Library Source       SourceForge Page       G3D Web Page     
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Classes | Public Types | Public Member Functions | Static Public Attributes | Protected Attributes | Friends | List of all members
G3D::RenderDevice Class Reference

Abstraction of a graphics rendering context (GPU). More...

Classes

class  Stats
 Reports measured GPU performance and throughput. More...
 
class  VARState
 

Public Types

enum  { MAX_LIGHTS = 2 }
 Maximum fixed-function lights supported. More...
 
enum  { MAX_TRACKED_TEXTURE_UNITS = 2 }
 Maximum number of fixed-function texture units RenderDevice can use or track with pushed/popped render states. More...
 
enum  { MAX_TRACKED_TEXTURE_IMAGE_UNITS = 2 }
 Maximum number of programmable pipeline texture image units RenderDevice can use or track with pushed/popped states. More...
 
enum  AlphaTest {
  ALPHA_GREATER = GL_GREATER,
  ALPHA_LESS = GL_LESS,
  ALPHA_GEQUAL = GL_GEQUAL,
  ALPHA_LEQUAL = GL_LEQUAL,
  ALPHA_NOTEQUAL = GL_NOTEQUAL,
  ALPHA_EQUAL = GL_EQUAL,
  ALPHA_ALWAYS_PASS = GL_ALWAYS,
  ALPHA_NEVER_PASS = GL_NEVER,
  ALPHA_CURRENT
}
 
enum  BlendEq {
  BLENDEQ_MIN = GL_MIN,
  BLENDEQ_MAX = GL_MAX,
  BLENDEQ_ADD = GL_FUNC_ADD,
  BLENDEQ_SUBTRACT = GL_FUNC_SUBTRACT,
  BLENDEQ_REVERSE_SUBTRACT = GL_FUNC_REVERSE_SUBTRACT,
  BLENDEQ_CURRENT
}
 
enum  BlendFunc {
  BLEND_SRC_ALPHA = GL_SRC_ALPHA,
  BLEND_ONE_MINUS_SRC_ALPHA = GL_ONE_MINUS_SRC_ALPHA,
  BLEND_ONE = GL_ONE,
  BLEND_ZERO = GL_ZERO,
  BLEND_SRC_COLOR = GL_SRC_COLOR,
  BLEND_DST_COLOR = GL_DST_COLOR,
  BLEND_ONE_MINUS_SRC_COLOR = GL_ONE_MINUS_SRC_COLOR,
  BLEND_ONE_MINUS_DST_COLOR = GL_ONE_MINUS_DST_COLOR,
  BLEND_CURRENT
}
 
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
}
 Arguments to setTextureCombineMode. More...
 
enum  DepthTest {
  DEPTH_GREATER = GL_GREATER,
  DEPTH_LESS = GL_LESS,
  DEPTH_GEQUAL = GL_GEQUAL,
  DEPTH_LEQUAL = GL_LEQUAL,
  DEPTH_NOTEQUAL = GL_NOTEQUAL,
  DEPTH_EQUAL = GL_EQUAL,
  DEPTH_ALWAYS_PASS = GL_ALWAYS,
  DEPTH_NEVER_PASS = GL_NEVER,
  DEPTH_CURRENT
}
 
enum  DrawBuffer {
  DRAW_NONE = GL_NONE,
  DRAW_FRONT_LEFT = GL_FRONT_LEFT,
  DRAW_FRONT_RIGHT = GL_FRONT_RIGHT,
  DRAW_BACK_LEFT = GL_BACK_LEFT,
  DRAW_BACK_RIGHT = GL_BACK_RIGHT,
  DRAW_FRONT = GL_FRONT,
  DRAW_BACK = GL_BACK,
  DRAW_LEFT = GL_LEFT,
  DRAW_RIGHT = GL_RIGHT,
  DRAW_FRONT_AND_BACK = GL_FRONT_AND_BACK,
  DRAW_AUX0 = GL_AUX0,
  DRAW_AUX1 = GL_AUX1,
  DRAW_AUX2 = GL_AUX2,
  DRAW_AUX3 = GL_AUX3,
  DRAW_COLOR0 = GL_COLOR_ATTACHMENT0,
  DRAW_COLOR1 = GL_COLOR_ATTACHMENT1,
  DRAW_COLOR2 = GL_COLOR_ATTACHMENT2,
  DRAW_COLOR3 = GL_COLOR_ATTACHMENT3,
  DRAW_COLOR4 = GL_COLOR_ATTACHMENT4,
  DRAW_COLOR5 = GL_COLOR_ATTACHMENT5,
  DRAW_COLOR6 = GL_COLOR_ATTACHMENT6,
  DRAW_COLOR7 = GL_COLOR_ATTACHMENT7,
  DRAW_COLOR8 = GL_COLOR_ATTACHMENT8,
  DRAW_COLOR9 = GL_COLOR_ATTACHMENT9,
  DRAW_COLOR10 = GL_COLOR_ATTACHMENT10,
  DRAW_COLOR11 = GL_COLOR_ATTACHMENT11,
  DRAW_COLOR12 = GL_COLOR_ATTACHMENT12,
  DRAW_COLOR13 = GL_COLOR_ATTACHMENT13,
  DRAW_COLOR14 = GL_COLOR_ATTACHMENT14,
  DRAW_COLOR15 = GL_COLOR_ATTACHMENT15,
  DRAW_CURRENT
}
 
enum  LogicOp {
  LOGIC_CLEAR = GL_CLEAR,
  LOGIC_AND = GL_AND,
  LOGIC_AND_REVERSE = GL_AND_REVERSE,
  LOGIC_COPY = GL_COPY,
  LOGIC_AND_INVERTED = GL_AND_INVERTED,
  LOGIC_NOOP = GL_NOOP,
  LOGIC_XOR = GL_XOR,
  LOGIC_OR = GL_OR,
  LOGIC_NOR = GL_NOR,
  LOGIC_EQUIV = GL_EQUIV,
  LOGIC_INVERT = GL_INVERT,
  LOGIC_OR_REVERSE = GL_OR_REVERSE,
  LOGIC_COPY_INVERTED = GL_COPY_INVERTED,
  LOGIC_OR_INVERTED = GL_OR_INVERTED,
  LOGIC_NAND = GL_NAND,
  LOGIC_SET = GL_SET,
  LOGICOP_CURRENT
}
 
enum  ReadBuffer {
  READ_FRONT_LEFT = GL_FRONT_LEFT,
  READ_FRONT_RIGHT = GL_FRONT_RIGHT,
  READ_BACK_LEFT = GL_BACK_LEFT,
  READ_BACK_RIGHT = GL_BACK_RIGHT,
  READ_FRONT = GL_FRONT,
  READ_BACK = GL_BACK,
  READ_LEFT = GL_LEFT,
  READ_RIGHT = GL_RIGHT,
  READ_COLOR0 = GL_COLOR_ATTACHMENT0,
  READ_COLOR1 = GL_COLOR_ATTACHMENT1,
  READ_COLOR2 = GL_COLOR_ATTACHMENT2,
  READ_COLOR3 = GL_COLOR_ATTACHMENT3,
  READ_COLOR4 = GL_COLOR_ATTACHMENT4,
  READ_COLOR5 = GL_COLOR_ATTACHMENT5,
  READ_COLOR6 = GL_COLOR_ATTACHMENT6,
  READ_COLOR7 = GL_COLOR_ATTACHMENT7,
  READ_COLOR8 = GL_COLOR_ATTACHMENT8,
  READ_COLOR9 = GL_COLOR_ATTACHMENT9,
  READ_COLOR10 = GL_COLOR_ATTACHMENT10,
  READ_COLOR11 = GL_COLOR_ATTACHMENT11,
  READ_COLOR12 = GL_COLOR_ATTACHMENT12,
  READ_COLOR13 = GL_COLOR_ATTACHMENT13,
  READ_COLOR14 = GL_COLOR_ATTACHMENT14,
  READ_COLOR15 = GL_COLOR_ATTACHMENT15,
  READ_DEPTH = GL_DEPTH_ATTACHMENT,
  READ_STENCIL = GL_STENCIL_ATTACHMENT,
  READ_CURRENT
}
 The constants that correspond to DrawBuffer have the same value, so that you can safely cast between them. More...
 
enum  RenderMode {
  RENDER_SOLID,
  RENDER_WIREFRAME,
  RENDER_POINTS,
  RENDER_CURRENT
}
 
enum  ShadeMode {
  SHADE_FLAT = GL_FLAT,
  SHADE_SMOOTH = GL_SMOOTH,
  SHADE_CURRENT
}
 
enum  StencilOp {
  STENCIL_INCR_WRAP = GL_INCR_WRAP,
  STENCIL_DECR_WRAP = GL_DECR_WRAP,
  STENCIL_KEEP = GL_KEEP,
  STENCIL_INCR = GL_INCR,
  STENCIL_DECR = GL_DECR,
  STENCIL_REPLACE = GL_REPLACE,
  STENCIL_ZERO = GL_ZERO,
  STENCIL_INVERT = GL_INVERT,
  STENCILOP_CURRENT
}
 
enum  StencilTest {
  STENCIL_GREATER = GL_GREATER,
  STENCIL_LESS = GL_LESS,
  STENCIL_GEQUAL = GL_GEQUAL,
  STENCIL_LEQUAL = GL_LEQUAL,
  STENCIL_NOTEQUAL = GL_NOTEQUAL,
  STENCIL_EQUAL = GL_EQUAL,
  STENCIL_ALWAYS_PASS = GL_ALWAYS,
  STENCIL_NEVER_PASS = GL_NEVER,
  STENCIL_CURRENT
}
 

Public Member Functions

 RenderDevice ()
 
 ~RenderDevice ()
 
void afterPrimitive ()
 Automatically called immediately after a primitive group.
 
AlphaTest alphaTest () const
 
float alphaTestReference () const
 
bool alphaWrite () const
 Returns true if alphaWrite is enabled.
 
void apply (const shared_ptr< class Shader > &s, const Args &args=Args())
 
void applyRect (const shared_ptr< class Shader > &s, const Args &args=Args(), float z=-1.0)
 Assumes push2D mode is already active.
 
void applyRect (const shared_ptr< class Shader > &s, const Args &args, float z, const Rect2D &rect)
 
void beforePrimitive ()
 Automatically called immediately before a primitive group.
 
void beginFrame ()
 Call to begin the rendering frame.
 
void beginIndexedPrimitives ()
 
void beginOpenGL ()
 Begin a section of raw OpenGL calls.
 
void G3D_DEPRECATED beginPrimitive (PrimitiveType p)
 Analogous to glBegin.
 
const CoordinateFramecameraToWorldMatrix () const
 
void cleanup ()
 Shuts down the rendering context.
 
void clear (bool clearColor, bool clearDepth, bool clearStencil)
 To clear the alpha portion of the color buffer, remember to enable alpha write.
 
void clear ()
 Clears color, depth, and stencil.
 
Rect2D clip2D () const
 If enabled, returns the current clip region, othrwise the viewport.
 
const Color4color () const
 
const ImageFormatcolorFormat () const
 Returns the format of the backbuffer/COLOR0 buffer (NULL if there isn't such a buffer).
 
bool colorWrite () const
 Returns true if colorWrite is enabled.
 
void configureReflectionMap (int textureUnit, shared_ptr< Texture > reflectionTexture)
 Call within RenderDevice::pushState()...popState() so that you can restore the texture coordinate generation.
 
void configureShadowMap (int textureUnit, const Matrix4 &lightMVP, const shared_ptr< Texture > &shadowMap)
 Call within RenderDevice::pushState()...popState() so that you can restore the texture coordinate generation that will be configured on the unit as a result of this call.
 
void configureShadowMap (int unit, const shared_ptr< class ShadowMap > &shadowMap)
 
void copyTextureFromScreen (const shared_ptr< Texture > &texture, const Rect2D &rect, const ImageFormat *format=NULL, int mipLevel=0, CubeFace face=CubeFace::POS_X)
 See glStencilMaskSeparate.
 
CullFace cullFace () const
 
bool currentDrawFramebufferComplete (std::string &whyIncomplete=dummyString) const
 Checks to ensure that the currently bound drawing framebuffer is complete and error free.
 
bool currentReadFramebufferComplete (std::string &whyIncomplete=dummyString) const
 
bool depthWrite () const
 Returns true if depthWrite is enabled.
 
void describeSystem (TextOutput &t)
 Prints a human-readable description of this machine to the text output stream.
 
void describeSystem (std::string &s)
 
DrawBuffer drawBuffer () const
 
shared_ptr< FramebufferdrawFramebuffer () const
 Returns the framebuffer currently bound for drawing.
 
void endFrame ()
 Call to end the current frame and schedules a OSWindow::swapGLBuffers call to occur some time before beginFrame.
 
void endIndexedPrimitives ()
 
void endOpenGL ()
 The state of the previous beginOpenGL is restored.
 
void G3D_DEPRECATED endPrimitive ()
 Analogous to glEnd.
 
shared_ptr< Framebufferframebuffer () const
 
void getBlendFunc (BlendFunc &src, BlendFunc &dst, BlendEq &eq)
 
const std::stringgetCardDescription () const
 Description of the graphics card and driver version.
 
double getDepthBufferValue (int x, int y) const
 Reads a depth buffer value (1 @ far plane, 0 @ near plane) from the given screen coordinates (x, y) where (0,0) is the top left corner of the width x height screen.
 
Matrix4 getTextureMatrix (int textureUnit)
 
HDC getWindowHDC () const
 
int height () const
 Pixel dimensions of the OpenGL window interior.
 
void init (const OSWindow::Settings &settings=OSWindow::Settings())
 Automatically constructs a Win32Window (on Win32), X11Window (on Linux) or GLFWWindow (OS X) then calls the other init routine (provided for backwards compatibility).
 
void init (OSWindow *window)
 The renderDevice will not delete the window on cleanup.
 
bool initialized () const
 Returns true after RenderDevice::init has been called.
 
bool invertY () const
 True if the Y-axis has been flipped from the G3D convention, which occurs when the framebuffer is NULL.
 
const Matrix4invertYMatrix () const
 If G3D::RenderDevice::invertY() is true, this is the matrix is applied after the projection matrix to flip the y-axis.
 
void majGLStateChange (int inc=1)
 State change to OpenGL (possibly because of a state change to RenderDevice).
 
void majStateChange (int inc=1)
 State change to RenderDevice.
 
void minGLStateChange (int inc=1)
 State change to OpenGL (possibly because of a state change to RenderDevice).
 
float minLineWidth () const
 
void minStateChange (int inc=1)
 State change to RenderDevice.
 
CoordinateFrame modelViewMatrix () const
 cameraToWorldMatrix().inverse() * objectToWorldMatrix()
 
Matrix4 modelViewProjectionMatrix () const
 projectionMatrix() * cameraToWorldMatrix().inverse() * objectToWorldMatrix().
 
int G3D_DEPRECATED numTextureCoords () const
 Returns the number of texture coordinates allowed.
 
int numTextures () const
 Returns the number of textures available.
 
int numTextureUnits () const
 Returns the number of texture units (texture coord + reg combiner + matrix) available.
 
const CoordinateFrameobjectToWorldMatrix () const
 
void pop2D ()
 
void popState ()
 Restores all state to whatever was pushed previously.
 
Vector4 project (const Vector4 &v) const
 Multiplies v by the current object to world and world to camera matrices, then by the projection matrix to obtain a 2D point and z-value.
 
Vector4 project (const Vector3 &v) const
 
Matrix4 projectionMatrix () const
 The G3D projection matrix.
 
void push2D ()
 
void push2D (const shared_ptr< Framebuffer > &drawFramebuffer)
 Pushes all state, switches to the new framebuffer, and resizes the viewport and projection matrix accordingly.
 
void push2D (const Rect2D &viewport)
 Set up for traditional 2D rendering (origin = upper left, y increases downwards).
 
void pushState ()
 Checkmarks all RenderDevice state (anything that can be set using RenderDevice methods) except for the currently bound vertex arrays.
 
void pushState (const shared_ptr< Framebuffer > &fb)
 Pushes the current state, then set the specified frame buffer and matches the viewport to it.
 
ReadBuffer readBuffer () const
 
shared_ptr< FramebufferreadFramebuffer () const
 Returns the framebuffer currently bound for reading.
 
RenderMode renderMode () const
 
void resetState ()
 Sets all state to a clean rendering environment.
 
void resetTextureUnit (int textureUnit)
 Resets the matrix, texture, combine op, and constant for a texture unit.
 
std::string screenshot (const std::string &filepath="./") const
 Takes a JPG screenshot of the front buffer and saves it to a file.
 
Image::Ref screenshotPic (bool getAlpha=false, bool invertY=true) const
 Takes a screenshot.
 
template<class T >
void sendIndices (PrimitiveType primitive, int numIndices, const T *index)
 Draws the specified kind of primitive from the current vertex array.
 
void sendIndices (PrimitiveType primitive, const IndexStream &indexStream)
 Send indices from an index buffer stored inside a vertex buffer.
 
template<class T >
void sendIndices (PrimitiveType primitive, const Array< T > &index)
 Draws the specified kind of primitive from the current vertex array.
 
void sendIndicesInstanced (PrimitiveType primitive, const IndexStream &indexStream, int numInstances)
 Send indices from an index buffer stored inside a vertex buffer.
 
void sendSequentialIndices (PrimitiveType primitive, int numVertices, int startVertex=0)
 Renders sequential vertices from the current vertex array.
 
void sendSequentialIndicesInstanced (PrimitiveType primitive, int numVertices, int numInstances)
 Renders sequential vertices from the current vertex array for multiple instances.
 
void G3D_DEPRECATED sendVertex (const Vector2 &vertex)
 Vertices are "sent" rather than "set" because they cause action.
 
void G3D_DEPRECATED sendVertex (const Vector3 &vertex)
 
void G3D_DEPRECATED sendVertex (const Vector4 &vertex)
 
void setAlphaTest (AlphaTest test, float reference)
 If the alpha test is ALPHA_CURRENT, the reference is ignored.
 
void setAlphaWrite (bool b)
 The frame buffer may optionally have an alpha channel for each pixel, depending on how the G3D::OSWindow was initialized (see G3D::RenderDevice::init, and G3D::OSWindow::Settings).
 
void setBlendFunc (BlendFunc src, BlendFunc dst, BlendEq eq=BLENDEQ_ADD)
 Equivalent to glBlendFunc and glBlendEquation.
 
void setCameraToWorldMatrix (const CoordinateFrame &cFrame)
 See RenderDevice::setObjectToWorldMatrix.
 
void setClip2D (const Rect2D &clip)
 Sets a 2D clipping region (OpenGL scissor region) relative to the current window dimensions (not the viewport).
 
void setColor (const Color4 &color)
 Set the vertex color (equivalent to glColor).
 
void setColor (const Color3 &color)
 
void setColorArray (const class AttributeArray &v)
 
void setColorClearValue (const Color4 &c)
 
void setColorWrite (bool b)
 Color writing is on by default.
 
void setCullFace (CullFace f)
 Equivalent to glCullFace.
 
void setDepthClearValue (float d)
 
void setDepthRange (float low, float high)
 
void setDepthTest (DepthTest test)
 Use ALWAYS_PASS to shut off testing.
 
void setDepthWrite (bool b)
 Defaults to true.
 
void setDrawBuffer (DrawBuffer drawBuffer)
 Sets the frame buffer that is written to.
 
void setDrawFramebuffer (const shared_ptr< Framebuffer > &fbo)
 Sets the framebuffer to render to.
 
void setFramebuffer (const shared_ptr< Framebuffer > &fbo)
 Sets both the draw and read framebuffers.
 
void setGlossyCoefficient (float s)
 Sets the current specular coefficient used in the lighting equation.
 
void setGlossyCoefficient (const Color3 &c)
 
void setInvertY (bool i)
 Override the invertY() flag, which is normally set automatically by calls to setFramebuffer.
 
void setLineWidth (float width)
 Equivalent to glLineWidth.
 
void setLogicOp (const LogicOp op)
 Equivalent to glLogicOp call.
 
void setMinLineWidth (float W)
 Forces setLineWidth to max against this value.
 
void G3D_DEPRECATED setNormal (const Vector3 &normal)
 Equivalent to glNormal.
 
void setNormalArray (const class AttributeArray &v)
 
void setObjectToWorldMatrix (const CoordinateFrame &cFrame)
 This is not the OpenGL MODELVIEW matrix: it is a matrix that maps object space to world space.
 
void setPointSize (float diameter)
 Equivalent to glPointSize.
 
void setPolygonOffset (float offset)
 Equivalent to glPolygonOffset.
 
void setProjectionAndCameraMatrix (const Projection &p, const CFrame &c)
 Setting both simultaneously minimizes OpenGL state changes.
 
void setProjectionMatrix (const Matrix4 &P)
 To set a typical 3D perspective matrix, use either.
 
void setProjectionMatrix (const class Projection &P)
 
void setReadBuffer (ReadBuffer readBuffer)
 
void setReadFramebuffer (const shared_ptr< Framebuffer > &fbo)
 
void setRenderMode (RenderMode mode)
 
void setShadeMode (ShadeMode s)
 Equivalent to glShadeModel.
 
void setShininess (float s)
 Sets the current shininess exponent used in the lighting equation.
 
void setSRGBConversion (bool b)
 By default, opengl does not covert writes to an sRGB texture into sRGB color space.
 
void setStencilClearValue (int s)
 
void setStencilConstant (int reference)
 Sets the constant used in the stencil test and operation (if op == STENCIL_REPLACE)
 
void setStencilOp (StencilOp fail, StencilOp zfail, StencilOp zpass)
 If wrapping is not supported on the device, the nearest mode is selected.
 
void setStencilOp (StencilOp frontStencilFail, StencilOp frontZFail, StencilOp frontZPass, StencilOp backStencilFail, StencilOp backZFail, StencilOp backZPass)
 When GLCaps::GL_ARB_stencil_two_side is true, separate stencil operations can be used for front and back faces.
 
void setStencilTest (StencilTest test)
 
void setSwapBuffersAutomatically (bool b)
 By default, OSWindow::swapGLBuffers is invoked automatically between RenderDevice::endFrame and the following RenderDevice::beginFrame to update the front buffer (what the user sees) from the back buffer (where rendering commands occur).
 
void G3D_DEPRECATED setTexCoord (int textureUnit, const Vector4 &texCoord)
 Equivalent to glTexCoord.
 
void G3D_DEPRECATED setTexCoord (int textureUnit, const Vector3 &texCoord)
 
void G3D_DEPRECATED setTexCoord (int textureUnit, const Vector3int16 &texCoord)
 
void G3D_DEPRECATED setTexCoord (int textureUnit, const Vector2 &texCoord)
 
void G3D_DEPRECATED setTexCoord (int textureUnit, const Vector2int16 &texCoord)
 
void G3D_DEPRECATED setTexCoord (int textureUnit, double texCoord)
 
void setTexCoordArray (unsigned int unit, const class AttributeArray &v)
 
void setTexture (int textureUnit, const shared_ptr< Texture > &texture)
 
void setTextureCombineMode (int textureUnit, const CombineMode texCombine)
 The combine mode specifies how to combine the result of a texture lookup with the accumulated fragment value (e.g.
 
void setTextureLODBias (int unit, float bias)
 A bias affects which MIP-map level is used.
 
void setTextureMatrix (int textureUnit, const float *m)
 m is a 16-element matrix in row major order for multiplying texture coordinates:
 
void setTextureMatrix (int textureUnit, const double *m)
 
void setTextureMatrix (int textureUnit, const Matrix4 &m)
 
void setTextureMatrix (int textureUnit, const CoordinateFrame &c)
 
void setVARs (const class AttributeArray &vertex, const class AttributeArray &normal, const class AttributeArray &color, const Array< AttributeArray > &texCoord)
 Set a series of vertex arrays.
 
void setVARs (const class AttributeArray &vertex, const class AttributeArray &normal=AttributeArray(), const class AttributeArray &texCoord0=AttributeArray(), const class AttributeArray &texCoord1=AttributeArray())
 Set a series of vertex arrays simultaneously.
 
void setVertexArray (const class AttributeArray &v)
 The vertex, normal, color, and tex coord arrays need not come from the same VertexBuffer.
 
void setVertexAttribArray (unsigned int attribNum, const class AttributeArray &v)
 Vertex attributes are a generalization of the various per-vertex attributes that relaxes the format restrictions.
 
void setViewport (const Rect2D &v)
 (0, 0) is the upper-left corner of the screen.
 
ShadeMode shadeMode () const
 
bool sRGBConversion () const
 
const Statsstats ()
 
StencilTest stencilTest () const
 
void swapBuffers ()
 Manually swap the front and back buffers.
 
bool swapBuffersAutomatically () const
 
const StopwatchswapBufferTimer () const
 Measures the amount of time spent in swapBuffers.
 
const Rect2Dviewport () const
 
int width () const
 Pixel dimensions of the OpenGL window interior.
 
OSWindowwindow () const
 Returns the OSWindow used by this RenderDevice.
 

Static Public Attributes

static RenderDevicelastRenderDeviceCreated
 Allows the UserInput to find the RenderDevice.
 

Protected Attributes

RealTime m_lastTime
 Time at which the previous endFrame() was called.
 
Stats m_stats
 
Stopwatch m_swapTimer
 Times swapbuffers.
 
Array< AttributeArraym_tempVAR
 Storage for setVARs.
 
VARState m_varState
 Note: note backed up by push/pop, since push/pop can't be called inside indexed primitives.
 

Friends

class AttributeArray
 
class Milestone
 
class UserInput
 
class VertexBuffer
 

Detailed Description

Abstraction of a graphics rendering context (GPU).

Implemented with an OpenGL context, but designed so that it can support other APIs (e.g., OpenGL ES, DirectX) as back ends.

Unlike OpenGL, in release mode, no RenderDevice call will trigger a pipeline flush, and all redundant state calls are automatically detected and optimized out. This includes queries: reading any RenderDevice state is instantaneous and does not flush the GPU (unlike glGet*).

In future releases, fixed function state will either be removed or isolated in RenderDevice. Wherever possible, structure your code to use Framebuffer, AttributeArray, and Shader instead of fixed-function.

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

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.

Fixed-function code is currently being phased out of the G3D API as it is deprecated in OpenGL. Shader and VertexArray code is the preferred rendering path.

Example

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

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

Stereo Rendering

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

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

   void onGraphics(...) {
       rd->setDrawBuffer(RenderDevice::DRAW_LEFT); 
       for (int count = 0; count < 2; ++count) {
          ... (put your normal rendering code here)
          rd->setDrawBuffer(RenderDevice::DRAW_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

Maximum fixed-function lights supported.

Deprecated:
Use a Shader
Enumerator:
MAX_LIGHTS 
anonymous enum

Maximum number of fixed-function texture units RenderDevice can use or track with pushed/popped render states.

This affects texture combine, matrix and LOD bias as well.

The maximum number of tracked units may be lower than hardware limits due to the cost of tracking and restoring the state. Most users will not use more, but increasing this value is the only necessary change.

Deprecated:
Enumerator:
MAX_TRACKED_TEXTURE_UNITS 
anonymous enum

Maximum number of programmable pipeline texture image units RenderDevice can use or track with pushed/popped states.

These are typically more than the fixed-function units.

The maximum number of tracked units may be lower than hardware limits due to the cost of tracking and restoring the state. Most users will not use more, but increasing this value is the only necessary change.

Enumerator:
MAX_TRACKED_TEXTURE_IMAGE_UNITS 
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_ONE_MINUS_DST_COLOR 
BLEND_CURRENT 

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:
DEPTH_GREATER 
DEPTH_LESS 
DEPTH_GEQUAL 
DEPTH_LEQUAL 
DEPTH_NOTEQUAL 
DEPTH_EQUAL 
DEPTH_ALWAYS_PASS 
DEPTH_NEVER_PASS 
DEPTH_CURRENT 
See Also
drawBuffer()
Enumerator:
DRAW_NONE 
DRAW_FRONT_LEFT 
DRAW_FRONT_RIGHT 
DRAW_BACK_LEFT 
DRAW_BACK_RIGHT 
DRAW_FRONT 
DRAW_BACK 
DRAW_LEFT 
DRAW_RIGHT 
DRAW_FRONT_AND_BACK 
DRAW_AUX0 
DRAW_AUX1 
DRAW_AUX2 
DRAW_AUX3 
DRAW_COLOR0 
DRAW_COLOR1 
DRAW_COLOR2 
DRAW_COLOR3 
DRAW_COLOR4 
DRAW_COLOR5 
DRAW_COLOR6 
DRAW_COLOR7 
DRAW_COLOR8 
DRAW_COLOR9 
DRAW_COLOR10 
DRAW_COLOR11 
DRAW_COLOR12 
DRAW_COLOR13 
DRAW_COLOR14 
DRAW_COLOR15 
DRAW_CURRENT 
Enumerator:
LOGIC_CLEAR 
LOGIC_AND 
LOGIC_AND_REVERSE 
LOGIC_COPY 
LOGIC_AND_INVERTED 
LOGIC_NOOP 
LOGIC_XOR 
LOGIC_OR 
LOGIC_NOR 
LOGIC_EQUIV 
LOGIC_INVERT 
LOGIC_OR_REVERSE 
LOGIC_COPY_INVERTED 
LOGIC_OR_INVERTED 
LOGIC_NAND 
LOGIC_SET 
LOGICOP_CURRENT 

The constants that correspond to DrawBuffer have the same value, so that you can safely cast between them.

All have the corresponding OpenGL constant.

See Also
readBuffer()
Enumerator:
READ_FRONT_LEFT 
READ_FRONT_RIGHT 
READ_BACK_LEFT 
READ_BACK_RIGHT 
READ_FRONT 
READ_BACK 
READ_LEFT 
READ_RIGHT 
READ_COLOR0 
READ_COLOR1 
READ_COLOR2 
READ_COLOR3 
READ_COLOR4 
READ_COLOR5 
READ_COLOR6 
READ_COLOR7 
READ_COLOR8 
READ_COLOR9 
READ_COLOR10 
READ_COLOR11 
READ_COLOR12 
READ_COLOR13 
READ_COLOR14 
READ_COLOR15 
READ_DEPTH 
READ_STENCIL 
READ_CURRENT 
See Also
RenderDevice::setRenderMode
Enumerator:
RENDER_SOLID 
RENDER_WIREFRAME 
RENDER_POINTS 
RENDER_CURRENT 

preserve whatever the render mode is currently set to.

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
float G3D::RenderDevice::alphaTestReference ( ) const
bool G3D::RenderDevice::alphaWrite ( ) const

Returns true if alphaWrite is enabled.

void G3D::RenderDevice::apply ( const shared_ptr< class Shader > &  s,
const Args args = Args() 
)
void G3D::RenderDevice::applyRect ( const shared_ptr< class Shader > &  s,
const Args args = Args(),
float  z = -1.0 
)

Assumes push2D mode is already active.

Uses the viewport as the rectangle

void G3D::RenderDevice::applyRect ( const shared_ptr< class Shader > &  s,
const Args args,
float  z,
const Rect2D rect 
)
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::beginOpenGL ( )

Begin a section of raw OpenGL calls.

All RenderDevice state is synchronized with OpenGL and backed up.

You can always make raw OpenGL calls with G3D, however in some cases RenderDevice makes lazy state changes and you'll be surprised by the outcome. This lets you switch to a pure OpenGL mode. Do not make other RenderDevice calls while in beginOpenGL...endOpenGL.

void G3D_DEPRECATED G3D::RenderDevice::beginPrimitive ( PrimitiveType  p)

Analogous to glBegin.

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

Deprecated:
Use apply()
const CoordinateFrame& G3D::RenderDevice::cameraToWorldMatrix ( ) const
void G3D::RenderDevice::cleanup ( )

Shuts down the rendering context.

This should be the last call you make.

void G3D::RenderDevice::clear ( bool  clearColor,
bool  clearDepth,
bool  clearStencil 
)

To clear the alpha portion of the color buffer, remember to enable alpha write.

void G3D::RenderDevice::clear ( )
inline

Clears color, depth, and stencil.

Rect2D G3D::RenderDevice::clip2D ( ) const

If enabled, returns the current clip region, othrwise the viewport.

const Color4& G3D::RenderDevice::color ( ) const
inline

Referenced by setColor().

const ImageFormat* G3D::RenderDevice::colorFormat ( ) const

Returns the format of the backbuffer/COLOR0 buffer (NULL if there isn't such a buffer).

bool G3D::RenderDevice::colorWrite ( ) const

Returns true if colorWrite is enabled.

void G3D::RenderDevice::configureReflectionMap ( int  textureUnit,
shared_ptr< Texture reflectionTexture 
)

Call within RenderDevice::pushState()...popState() so that you can restore the texture coordinate generation.

Note that you can obtain the reflection texture (aka environment map) from G3D::Sky or by loading it with G3D:Texture::fromFile.

Parameters
textureUnitThe texture unit to use for shadowing. 0...RenderDevice::numTextureUnits() That unit cannot be used for texturing at the same time.
Deprecated:
void G3D::RenderDevice::configureShadowMap ( int  textureUnit,
const Matrix4 lightMVP,
const shared_ptr< Texture > &  shadowMap 
)

Call within RenderDevice::pushState()...popState() so that you can restore the texture coordinate generation that will be configured on the unit as a result of this call.

Parameters
lightMVPThe modelview projection matrix that was used to render the shadow map originally (you can get this from RenderDevice::getModelViewProjectionMatrix() while rendering the shadow map).
textureUnitThe texture unit to use for shadowing. 0...RenderDevice::numTextureUnits() That unit cannot be used for texturing at the same time.
void G3D::RenderDevice::configureShadowMap ( int  unit,
const shared_ptr< class ShadowMap > &  shadowMap 
)
void G3D::RenderDevice::copyTextureFromScreen ( const shared_ptr< Texture > &  texture,
const Rect2D rect,
const ImageFormat format = NULL,
int  mipLevel = 0,
CubeFace  face = CubeFace::POS_X 
)

See glStencilMaskSeparate.

Parameters
formatIf NULL, defaults to texture->format()
CullFace G3D::RenderDevice::cullFace ( ) const
inline
bool G3D::RenderDevice::currentDrawFramebufferComplete ( std::string whyIncomplete = dummyString) const
inline

Checks to ensure that the currently bound drawing framebuffer is complete and error free.

Returns
false On Incomplete Framebuffer Error
true On Complete Framebuffer

Referenced by sendIndices().

bool G3D::RenderDevice::currentReadFramebufferComplete ( std::string whyIncomplete = dummyString) const
inline
bool G3D::RenderDevice::depthWrite ( ) const

Returns true if depthWrite is enabled.

void G3D::RenderDevice::describeSystem ( TextOutput t)

Prints a human-readable description of this machine to the text output stream.

Either argument may be NULL.

void G3D::RenderDevice::describeSystem ( std::string s)
DrawBuffer G3D::RenderDevice::drawBuffer ( ) const
inline
shared_ptr<Framebuffer> G3D::RenderDevice::drawFramebuffer ( ) const
inline

Returns the framebuffer currently bound for drawing.

void G3D::RenderDevice::endFrame ( )

Call to end the current frame and schedules a OSWindow::swapGLBuffers call to occur some time before beginFrame.

Because that swapGLBuffers might not actually occur until the next beginFrame, there is up to one frame of latency on the image displayed. This allows the CPU to execute while the GPU is still rendering, providing net higher performance.

void G3D::RenderDevice::endIndexedPrimitives ( )
void G3D::RenderDevice::endOpenGL ( )

The state of the previous beginOpenGL is restored.

void G3D_DEPRECATED G3D::RenderDevice::endPrimitive ( )

Analogous to glEnd.

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

Deprecated:
Use apply()
shared_ptr<Framebuffer> G3D::RenderDevice::framebuffer ( ) const
inline
void G3D::RenderDevice::getBlendFunc ( BlendFunc src,
BlendFunc dst,
BlendEq eq 
)
inline
const std::string& G3D::RenderDevice::getCardDescription ( ) const

Description of the graphics card and driver version.

double G3D::RenderDevice::getDepthBufferValue ( int  x,
int  y 
) const

Reads a depth buffer value (1 @ far plane, 0 @ near plane) from the given screen coordinates (x, y) where (0,0) is the top left corner of the width x height screen.

Result is undefined for x, y not on screen.

The result is sensitive to the projection and camera to world matrices.

If you need to read back the entire depth buffer, use OpenGL glReadPixels calls instead of many calls to getDepthBufferValue.

Matrix4 G3D::RenderDevice::getTextureMatrix ( int  textureUnit)
HDC G3D::RenderDevice::getWindowHDC ( ) const
int G3D::RenderDevice::height ( ) const

Pixel dimensions of the OpenGL window interior.

void G3D::RenderDevice::init ( const OSWindow::Settings settings = OSWindow::Settings())

Automatically constructs a Win32Window (on Win32), X11Window (on Linux) or GLFWWindow (OS X) then calls the other init routine (provided for backwards compatibility).

The constructed window is deleted on shutdown.

void G3D::RenderDevice::init ( OSWindow window)

The renderDevice will not delete the window on cleanup.

bool G3D::RenderDevice::initialized ( ) const

Returns true after RenderDevice::init has been called.

bool G3D::RenderDevice::invertY ( ) const

True if the Y-axis has been flipped from the G3D convention, which occurs when the framebuffer is NULL.

By default, RenderDevice conventions assume that you are rendering to a G3D::Texture in a G3D::Framebuffer, so it configures the projection matrix and polygon winding direction so that the upper-left corner of the framebuffer is texel (0, 0).

When rendering directly to the screen, the opposite convention is needed. In this case, G3D applies an extra invertYMatrix() that flips the Y axis and internally inverts the winding conventions.

const Matrix4& G3D::RenderDevice::invertYMatrix ( ) const

If G3D::RenderDevice::invertY() is true, this is the matrix is applied after the projection matrix to flip the y-axis.

Otherwise it is the identity matrix.

void G3D::RenderDevice::majGLStateChange ( int  inc = 1)
inline

State change to OpenGL (possibly because of a state change to RenderDevice).

Use to update the state change statistics when raw OpenGL calls are made.

void G3D::RenderDevice::majStateChange ( int  inc = 1)
inline

State change to RenderDevice.

Use to update the state change statistics when raw OpenGL calls are made.

Referenced by setDepthRange().

void G3D::RenderDevice::minGLStateChange ( int  inc = 1)
inline

State change to OpenGL (possibly because of a state change to RenderDevice).

Use to update the state change statistics when raw OpenGL calls are made.

Referenced by setAlphaWrite(), setColorWrite(), setDepthRange(), setDepthWrite(), and setShadeMode().

float G3D::RenderDevice::minLineWidth ( ) const
inline
void G3D::RenderDevice::minStateChange ( int  inc = 1)
inline

State change to RenderDevice.

Use to update the state change statistics when raw OpenGL calls are made.

Referenced by setAlphaWrite(), setColorWrite(), setDepthWrite(), and setShadeMode().

CoordinateFrame G3D::RenderDevice::modelViewMatrix ( ) const
Matrix4 G3D::RenderDevice::modelViewProjectionMatrix ( ) const

projectionMatrix() * cameraToWorldMatrix().inverse() * objectToWorldMatrix().

Note that the full gl_ModelViewProjectionMatrix also includes the RenderDevice::invertY() matrix.

int G3D_DEPRECATED G3D::RenderDevice::numTextureCoords ( ) const
inline

Returns the number of texture coordinates allowed.

This may be greater than the number of texture matrices.

Deprecated:
int G3D::RenderDevice::numTextures ( ) const
inline

Returns the number of textures available.

May be higher than the number of texture units if the programmable pipeline provides more textures than the fixed function pipeline.

int G3D::RenderDevice::numTextureUnits ( ) const
inline

Returns the number of texture units (texture coord + reg combiner + matrix) available.

This only applies to the fixed function pipeline.

const CoordinateFrame& G3D::RenderDevice::objectToWorldMatrix ( ) const
void G3D::RenderDevice::pop2D ( )
void G3D::RenderDevice::popState ( )

Restores all state to whatever was pushed previously.

Push and pop must be used in matching pairs.

Vector4 G3D::RenderDevice::project ( const Vector4 v) const

Multiplies v by the current object to world and world to camera matrices, then by the projection matrix to obtain a 2D point and z-value.

The result is the 2D position to which the 3D point v corresponds. You can use this to make results rendered with push2D() line up with those rendered with a 3D transformation.

The value returned is relative to the current viewport.

See G3D::glToScreen

Vector4 G3D::RenderDevice::project ( const Vector3 v) const
Matrix4 G3D::RenderDevice::projectionMatrix ( ) const

The G3D projection matrix.

Does not include the invertYMatrix(). Note that this is not equal to the GLSL gl_ProjectionMatrix.

See Also
G3D::Projection
void G3D::RenderDevice::push2D ( )
void G3D::RenderDevice::push2D ( const shared_ptr< Framebuffer > &  drawFramebuffer)

Pushes all state, switches to the new framebuffer, and resizes the viewport and projection matrix accordingly.

void G3D::RenderDevice::push2D ( const Rect2D viewport)

Set up for traditional 2D rendering (origin = upper left, y increases downwards).

Note: the viewport will range up to the number of pixels (e.g., (0,0)-(640,480)), as recommended in http://msdn.microsoft.com/library/default.asp?url=/library/en-us/opengl/apptips_7wqb.asp . Push2D also translates (sets the cameraToWorldMatrix) by (0.375, 0.375, 0) as recommended in the OpenGL manual. This helps avoid rasterization holes due to float-to-int roundoff.

void G3D::RenderDevice::pushState ( )

Checkmarks all RenderDevice state (anything that can be set using RenderDevice methods) except for the currently bound vertex arrays.

If you are using some other OpenGL state that is not covered by any of the above (e.g., the glReadBuffer and other buffer options), you can call glPushAttrib(GL_ALL_ATTRIB_BITS) immediately before pushState to ensure that it is pushed as well.

void G3D::RenderDevice::pushState ( const shared_ptr< Framebuffer > &  fb)

Pushes the current state, then set the specified frame buffer and matches the viewport to it.

ReadBuffer G3D::RenderDevice::readBuffer ( ) const
inline
shared_ptr<Framebuffer> G3D::RenderDevice::readFramebuffer ( ) const
inline

Returns the framebuffer currently bound for reading.

RenderMode G3D::RenderDevice::renderMode ( ) const
void G3D::RenderDevice::resetState ( )

Sets all state to a clean rendering environment.

void G3D::RenderDevice::resetTextureUnit ( int  textureUnit)

Resets the matrix, texture, combine op, and constant for a texture unit.

std::string G3D::RenderDevice::screenshot ( const std::string filepath = "./") const

Takes a JPG screenshot of the front buffer and saves it to a file.

Returns the name of the file that was written. Example: renderDevice->screenshot("screens/");

Pressing the "movie" icon in the GApp developer HUD or pressing F4 also allows direct screenshot capture.

Image::Ref G3D::RenderDevice::screenshotPic ( bool  getAlpha = false,
bool  invertY = true 
) const

Takes a screenshot.

Reads from the current read buffer; use setReadBuffer(RenderDevice::READ_FRONT) to explicitly read from the front buffer, which is substantially faster than reading from the back buffer.

Parameters
getAlphaIf true, the alpha channel of the frame buffer is also read back.
invertYIt is faster to read back images upside down because that is how OpenGL stores them. Set invertY=false for this fast but upsidedown result.
template<class T >
void G3D::RenderDevice::sendIndices ( PrimitiveType  primitive,
int  numIndices,
const T *  index 
)
inline

Draws the specified kind of primitive from the current vertex array.

Deprecated:
Use sendIndices(PrimitiveType, const AttributeArray&)

Referenced by sendIndices().

void G3D::RenderDevice::sendIndices ( PrimitiveType  primitive,
const IndexStream indexStream 
)

Send indices from an index buffer stored inside a vertex buffer.

This is faster than sending from main memory on most GPUs.

template<class T >
void G3D::RenderDevice::sendIndices ( PrimitiveType  primitive,
const Array< T > &  index 
)
inline

Draws the specified kind of primitive from the current vertex array.

Deprecated:
Use sendIndices(PrimitiveType, const AttributeArray&)
void G3D::RenderDevice::sendIndicesInstanced ( PrimitiveType  primitive,
const IndexStream indexStream,
int  numInstances 
)

Send indices from an index buffer stored inside a vertex buffer.

This is faster than sending from main memory on most GPUs.

Inside the vertex shader, gl_InstanceID is bound to the number of the instance. The first instance is 0, the last is numInstances - 1.

(Equivalent to glDrawElementsInstanced)

Parameters
numInstancesnumber of instances of these indices to send
void G3D::RenderDevice::sendSequentialIndices ( PrimitiveType  primitive,
int  numVertices,
int  startVertex = 0 
)

Renders sequential vertices from the current vertex array.

(Equivalent to glDrawArrays)

void G3D::RenderDevice::sendSequentialIndicesInstanced ( PrimitiveType  primitive,
int  numVertices,
int  numInstances 
)

Renders sequential vertices from the current vertex array for multiple instances.

Inside the vertex shader, gl_InstanceID is bound to the number of the instance. The first instance is 0, the last is numInstances - 1.

(Equivalent to glDrawArraysInstanced)

Parameters
numInstancesnumber of instances of these indices to send
void G3D_DEPRECATED G3D::RenderDevice::sendVertex ( const Vector2 vertex)

Vertices are "sent" rather than "set" because they cause action.

Deprecated:
Use apply()
void G3D_DEPRECATED G3D::RenderDevice::sendVertex ( const Vector3 vertex)
void G3D_DEPRECATED G3D::RenderDevice::sendVertex ( const Vector4 vertex)
void G3D::RenderDevice::setAlphaTest ( AlphaTest  test,
float  reference 
)

If the alpha test is ALPHA_CURRENT, the reference is ignored.

void G3D::RenderDevice::setAlphaWrite ( bool  b)
inline

The frame buffer may optionally have an alpha channel for each pixel, depending on how the G3D::OSWindow was initialized (see G3D::RenderDevice::init, and G3D::OSWindow::Settings).

When the alpha channel is present, rendering to the screen also renders to the alpha channel by default. Alpha writing is used for render-to-texture and deferred lighting effects.

Rendering to the alpha channel does not produce transparency effects–this is an alpha output, not an alpha input. See RenderDevice::setBlendFunc for a discussion of blending.

void G3D::RenderDevice::setBlendFunc ( BlendFunc  src,
BlendFunc  dst,
BlendEq  eq = BLENDEQ_ADD 
)

Equivalent to glBlendFunc and glBlendEquation.

Use setBlendFunc(RenderDevice::BLEND_ONE, RenderDevice::BLEND_ZERO, RenderDevice::BLENDEQ_ADD) to shut off blending.

Use setBlendFunc(RenderDevice::BLEND_SRC_ALPHA, RenderDevice::BLEND_ONE_MINUS_SRC_ALPHA, RenderDevice::BLENDEQ_ADD) for unmultiplied alpha blending and setBlendFunc(RenderDevice::BLEND_ONE, RenderDevice::BLEND_ONE_MINUS_SRC_ALPHA, RenderDevice::BLENDEQ_ADD) for premultiplied alpha.

Draw your objects from back to front, objects with alpha last. Objects with alpha only get drawn properly if the things they're occluding have been drawn before the alpha'd objects.

Generally, turn alpha on, draw your alpha-blended things, then turn alpha off.

void G3D::RenderDevice::setCameraToWorldMatrix ( const CoordinateFrame cFrame)
void G3D::RenderDevice::setClip2D ( const Rect2D clip)

Sets a 2D clipping region (OpenGL scissor region) relative to the current window dimensions (not the viewport).

Prevents rendering outside the clip region.

Set to Rect2D::inf() to disable. Default is disabled.

Note that the clip uses G3D 2D coordinates, where the upper-left of the window is (0, 0).

void G3D::RenderDevice::setColor ( const Color4 color)
inline

Set the vertex color (equivalent to glColor).

Deprecated:
Use apply()
void G3D::RenderDevice::setColor ( const Color3 color)
inline
void G3D::RenderDevice::setColorArray ( const class AttributeArray v)
void G3D::RenderDevice::setColorClearValue ( const Color4 c)
void G3D::RenderDevice::setColorWrite ( bool  b)
inline

Color writing is on by default.

Disabling color write allows a program to render to the depth and stencil buffers without creating a visible image in the frame buffer. This is useful for occlusion culling, shadow rendering, and some computational solid geometry algorithms. Rendering may be significantly accelerated when color write is disabled.

void G3D::RenderDevice::setCullFace ( CullFace  f)

Equivalent to glCullFace.

RenderDevice will internally swap the OpenGL cull direction when rendering to a Framebuffer in order to be consistent with the inverted Y axis.

void G3D::RenderDevice::setDepthClearValue ( float  d)
void G3D::RenderDevice::setDepthRange ( float  low,
float  high 
)
inline
void G3D::RenderDevice::setDepthTest ( DepthTest  test)

Use ALWAYS_PASS to shut off testing.

Referenced by setDepthWrite().

void G3D::RenderDevice::setDepthWrite ( bool  b)
inline

Defaults to true.

void G3D::RenderDevice::setDrawBuffer ( DrawBuffer  drawBuffer)

Sets the frame buffer that is written to.

Used to intentionally draw to the front buffer and for stereo rendering. Its operation is sensitive to the current framebuffer being written to. If the framebuffer is the primary display then only visible buffers may be specified. If framebuffer() is non-NULL then the drawBuffer is stored for later use but the actual draw buffers remain the ones specified by the framebuffer.

When using a G3D::Framebuffer it is not necessary to explicitly set the draw buffer; that is handled automatically by beforePrimitive().

void G3D::RenderDevice::setDrawFramebuffer ( const shared_ptr< Framebuffer > &  fbo)

Sets the framebuffer to render to.

Use NULL to set the desired rendering target to the windowing system display.

Note that if the new framebuffer has different dimensions than the current one the projectionMatrix and viewport will likely be incorrect. Call RenderDevice::setProjectionAndCamera matrix again to update them.

See RenderDevice::pushState and push2D for a way to set the frame buffer and viewport simultaneously.

Parameters
fboFramebuffer to render to.

Referenced by setFramebuffer().

void G3D::RenderDevice::setFramebuffer ( const shared_ptr< Framebuffer > &  fbo)
inline

Sets both the draw and read framebuffers.

void G3D::RenderDevice::setGlossyCoefficient ( float  s)

Sets the current specular coefficient used in the lighting equation.

Should be on the range 0 (perfectly diffuse) to 1 (bright specular highlight).

void G3D::RenderDevice::setGlossyCoefficient ( const Color3 c)
void G3D::RenderDevice::setInvertY ( bool  i)
inline

Override the invertY() flag, which is normally set automatically by calls to setFramebuffer.

BETA API Likely to receive incompatible changes in future releases.
void G3D::RenderDevice::setLineWidth ( float  width)

Equivalent to glLineWidth.

void G3D::RenderDevice::setLogicOp ( const LogicOp  op)

Equivalent to glLogicOp call.

void G3D::RenderDevice::setMinLineWidth ( float  W)
inline

Forces setLineWidth to max against this value.

Default is 0

void G3D_DEPRECATED G3D::RenderDevice::setNormal ( const Vector3 normal)

Equivalent to glNormal.

Deprecated:
Use apply()
void G3D::RenderDevice::setNormalArray ( const class AttributeArray v)
void G3D::RenderDevice::setObjectToWorldMatrix ( const CoordinateFrame cFrame)

This is not the OpenGL MODELVIEW matrix: it is a matrix that maps object space to world space.

The actual MODELVIEW matrix is cameraToWorld.inverse() * objectToWorld. You can retrieve it with getModelViewMatrix.

void G3D::RenderDevice::setPointSize ( float  diameter)

Equivalent to glPointSize.

void G3D::RenderDevice::setPolygonOffset ( float  offset)

Equivalent to glPolygonOffset.

void G3D::RenderDevice::setProjectionAndCameraMatrix ( const Projection p,
const CFrame c 
)

Setting both simultaneously minimizes OpenGL state changes.

void G3D::RenderDevice::setProjectionMatrix ( const Matrix4 P)

To set a typical 3D perspective matrix, use either.

renderDevice->setProjectionMatrix(Matrix4::perspectiveProjection(...))

or call setProjectionAndCameraMatrix.

void G3D::RenderDevice::setProjectionMatrix ( const class Projection P)
void G3D::RenderDevice::setReadBuffer ( ReadBuffer  readBuffer)
void G3D::RenderDevice::setReadFramebuffer ( const shared_ptr< Framebuffer > &  fbo)

Referenced by setFramebuffer().

void G3D::RenderDevice::setRenderMode ( RenderMode  mode)
void G3D::RenderDevice::setShadeMode ( ShadeMode  s)
inline

Equivalent to glShadeModel.

void G3D::RenderDevice::setShininess ( float  s)

Sets the current shininess exponent used in the lighting equation.

On the range 0 (large highlight) to 255 (tiny, focussed highlight).

Deprecated:
void G3D::RenderDevice::setSRGBConversion ( bool  b)

By default, opengl does not covert writes to an sRGB texture into sRGB color space.

Set this to true to force such a conversion.

void G3D::RenderDevice::setStencilClearValue ( int  s)
void G3D::RenderDevice::setStencilConstant ( int  reference)

Sets the constant used in the stencil test and operation (if op == STENCIL_REPLACE)

void G3D::RenderDevice::setStencilOp ( StencilOp  fail,
StencilOp  zfail,
StencilOp  zpass 
)

If wrapping is not supported on the device, the nearest mode is selected.

Unlike OpenGL, stencil writing and testing are independent. You do not need to enable the stencil test to use the stencil op.

Use KEEP, KEEP, KEEP to disable stencil writing. Equivalent to a combination of glStencilTest, glStencilFunc, and glStencilOp.

If there is no depth buffer, the depth test always passes. If there is no stencil buffer, the stencil test always passes.

void G3D::RenderDevice::setStencilOp ( StencilOp  frontStencilFail,
StencilOp  frontZFail,
StencilOp  frontZPass,
StencilOp  backStencilFail,
StencilOp  backZFail,
StencilOp  backZPass 
)

When GLCaps::GL_ARB_stencil_two_side is true, separate stencil operations can be used for front and back faces.

This is useful for rendering shadow volumes.

void G3D::RenderDevice::setStencilTest ( StencilTest  test)
void G3D::RenderDevice::setSwapBuffersAutomatically ( bool  b)

By default, OSWindow::swapGLBuffers is invoked automatically between RenderDevice::endFrame and the following RenderDevice::beginFrame to update the front buffer (what the user sees) from the back buffer (where rendering commands occur).

You may want to suppress this behavior, for example, in order to render to the back buffer and capture the result in a texture.

The state of swapBuffersAutomatically is not stored by RenderDevice::pushState because it is usually invoked outside of RenderDevice::beginFrame / endFrame.

void G3D_DEPRECATED G3D::RenderDevice::setTexCoord ( int  textureUnit,
const Vector4 texCoord 
)

Equivalent to glTexCoord.

Deprecated:
Use apply()
void G3D_DEPRECATED G3D::RenderDevice::setTexCoord ( int  textureUnit,
const Vector3 texCoord 
)
void G3D_DEPRECATED G3D::RenderDevice::setTexCoord ( int  textureUnit,
const Vector3int16 texCoord 
)
void G3D_DEPRECATED G3D::RenderDevice::setTexCoord ( int  textureUnit,
const Vector2 texCoord 
)
void G3D_DEPRECATED G3D::RenderDevice::setTexCoord ( int  textureUnit,
const Vector2int16 texCoord 
)
void G3D_DEPRECATED G3D::RenderDevice::setTexCoord ( int  textureUnit,
double  texCoord 
)
void G3D::RenderDevice::setTexCoordArray ( unsigned int  unit,
const class AttributeArray v 
)
void G3D::RenderDevice::setTexture ( int  textureUnit,
const shared_ptr< Texture > &  texture 
)
Parameters
textureUnit>= 0
textureSet to NULL to disable the unit
void G3D::RenderDevice::setTextureCombineMode ( int  textureUnit,
const CombineMode  texCombine 
)

The combine mode specifies how to combine the result of a texture lookup with the accumulated fragment value (e.g.

the output of the previous combine or the constant color for the first texture unit).

Consider using shaders on newer cards instead of texture combiners; they are much easier to use. See also http://oss.sgi.com/projects/ogl-sample/registry/ARB/texture_env_crossbar.txt http://oss.sgi.com/projects/ogl-sample/registry/ARB/texture_env_dot3.txt

The initial combine op is TEX_MODULATE Equivalent to glTexEnv.

void G3D::RenderDevice::setTextureLODBias ( int  unit,
float  bias 
)

A bias affects which MIP-map level is used.

bias = 0 uses the MIP-map level automatically computed. Bias > 0 selects a blurrier mipmap (avoids aliasing artifacts). Bias < 0 selects a sharper mipmap (avoids blur). Integer values correspond to a whole mip-level shift. Default is 0.

See also http://oss.sgi.com/projects/ogl-sample/registry/EXT/texture_lod_bias.txt.

void G3D::RenderDevice::setTextureMatrix ( int  textureUnit,
const float *  m 
)

m is a 16-element matrix in row major order for multiplying texture coordinates:

v' = M v

Matrix is column major.

All texture operations check textureUnit against the number of available texture units when in debug mode.

Equivalent to glMatrixMode(GL_TEXTURE); glLoadMatrix(...); on a transposed matrix.

void G3D::RenderDevice::setTextureMatrix ( int  textureUnit,
const double *  m 
)
void G3D::RenderDevice::setTextureMatrix ( int  textureUnit,
const Matrix4 m 
)
void G3D::RenderDevice::setTextureMatrix ( int  textureUnit,
const CoordinateFrame c 
)
void G3D::RenderDevice::setVARs ( const class AttributeArray vertex,
const class AttributeArray normal,
const class AttributeArray color,
const Array< AttributeArray > &  texCoord 
)

Set a series of vertex arrays.

void G3D::RenderDevice::setVARs ( const class AttributeArray vertex,
const class AttributeArray normal = AttributeArray(),
const class AttributeArray texCoord0 = AttributeArray(),
const class AttributeArray texCoord1 = AttributeArray() 
)

Set a series of vertex arrays simultaneously.

This call allows you to change the VertexBuffer that the VARs are in within a single beginIndexedPrimitives() call, saving some state changes.

void G3D::RenderDevice::setVertexArray ( const class AttributeArray v)

The vertex, normal, color, and tex coord arrays need not come from the same VertexBuffer.

  The format of a AttributeArray array is restricted depending on its use.  The
  following table (from http://oss.sgi.com/projects/ogl-sample/registry/ARB/vertex_program.txt)
  shows the underlying OpenGL restrictions:
                              Normal    

Command Sizes ized? Types


VertexPointer 2,3,4 no short, int, float, double NormalPointer 3 yes byte, short, int, float, double ColorPointer 3,4 yes byte, ubyte, short, ushort, int, uint, float, double IndexPointer 1 no ubyte, short, int, float, double TexCoordPointer 1,2,3,4 no short, int, float, double EdgeFlagPointer 1 no boolean VertexAttribPointerARB 1,2,3,4 flag byte, ubyte, short, ushort, int, uint, float, double WeightPointerARB >=1 yes byte, ubyte, short, ushort, int, uint, float, double VertexWeightPointerEXT 1 n/a float SecondaryColor- 3 yes byte, ubyte, short, ushort, PointerEXT int, uint, float, double FogCoordPointerEXT 1 n/a float, double MatrixIndexPointerARB >=1 no ubyte, ushort, uint
    Table 2.4: Vertex array sizes (values per vertex) and data types.  The
    "normalized" column indicates whether fixed-point types are accepted
    directly or normalized to [0,1] (for unsigned types) or [-1,1] (for
    singed types). For generic vertex attributes, fixed-point data are
    normalized if and only if the <normalized> flag is set.
 
void G3D::RenderDevice::setVertexAttribArray ( unsigned int  attribNum,
const class AttributeArray v 
)

Vertex attributes are a generalization of the various per-vertex attributes that relaxes the format restrictions.

There are at least 16 attributes on any card (some allow more). These attributes have special meaning under the fixed function pipeline, as follows:

Generic
Attribute   Conventional Attribute       Conventional Attribute Command

0 vertex position Vertex 1 vertex weights 0-3 WeightARB, VertexWeightEXT 2 normal Normal 3 primary color Color 4 secondary color SecondaryColorEXT 5 fog coordinate FogCoordEXT 6 - - 7 - - 8 texture coordinate set 0 MultiTexCoord(TEXTURE0, ...) 9 texture coordinate set 1 MultiTexCoord(TEXTURE1, ...) 10 texture coordinate set 2 MultiTexCoord(TEXTURE2, ...) 11 texture coordinate set 3 MultiTexCoord(TEXTURE3, ...) 12 texture coordinate set 4 MultiTexCoord(TEXTURE4, ...) 13 texture coordinate set 5 MultiTexCoord(TEXTURE5, ...) 14 texture coordinate set 6 MultiTexCoord(TEXTURE6, ...) 15 texture coordinate set 7 MultiTexCoord(TEXTURE7, ...) 8+n texture coordinate set n MultiTexCoord(TEXTURE0+n, ...)
void G3D::RenderDevice::setViewport ( const Rect2D v)

(0, 0) is the upper-left corner of the screen.

ShadeMode G3D::RenderDevice::shadeMode ( ) const
inline
bool G3D::RenderDevice::sRGBConversion ( ) const
inline
const Stats& G3D::RenderDevice::stats ( )
inline
StencilTest G3D::RenderDevice::stencilTest ( ) const
void G3D::RenderDevice::swapBuffers ( )

Manually swap the front and back buffers.

Using swapBuffersAutomatically() is recommended instead of manually swapping because it has higher performance.

bool G3D::RenderDevice::swapBuffersAutomatically ( ) const
inline
const Stopwatch& G3D::RenderDevice::swapBufferTimer ( ) const
inline

Measures the amount of time spent in swapBuffers.

If high, indicates that the CPU and GPU are not working in parallel

const Rect2D& G3D::RenderDevice::viewport ( ) const
int G3D::RenderDevice::width ( ) const

Pixel dimensions of the OpenGL window interior.

OSWindow* G3D::RenderDevice::window ( ) const

Returns the OSWindow used by this RenderDevice.

Friends And Related Function Documentation

friend class AttributeArray
friend
friend class Milestone
friend
friend class UserInput
friend
friend class VertexBuffer
friend

Member Data Documentation

RenderDevice* G3D::RenderDevice::lastRenderDeviceCreated
static

Allows the UserInput to find the RenderDevice.

Deprecated:
RealTime G3D::RenderDevice::m_lastTime
protected

Time at which the previous endFrame() was called.

Stats G3D::RenderDevice::m_stats
protected
Stopwatch G3D::RenderDevice::m_swapTimer
protected

Times swapbuffers.

Referenced by swapBufferTimer().

Array<AttributeArray> G3D::RenderDevice::m_tempVAR
protected

Storage for setVARs.

Cleared by endIndexedPrimitives.

VARState G3D::RenderDevice::m_varState
protected

Note: note backed up by push/pop, since push/pop can't be called inside indexed primitives.


documentation generated on Sat Jan 12 2013 22:49:56 using doxygen 1.8.2