G3D::RenderDevice Class Reference#include <RenderDevice.h>
List of all members.
|
Public Types |
| 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 | { MAX_LIGHTS = 8
} |
| enum | DepthTest {
DEPTH_GREATER,
DEPTH_LESS,
DEPTH_GEQUAL,
DEPTH_LEQUAL,
DEPTH_NOTEQUAL,
DEPTH_EQUAL,
DEPTH_ALWAYS_PASS,
DEPTH_NEVER_PASS,
DEPTH_CURRENT
} |
| enum | AlphaTest {
ALPHA_GREATER,
ALPHA_LESS,
ALPHA_GEQUAL,
ALPHA_LEQUAL,
ALPHA_NOTEQUAL,
ALPHA_EQUAL,
ALPHA_ALWAYS_PASS,
ALPHA_NEVER_PASS,
ALPHA_CURRENT
} |
| enum | StencilTest {
STENCIL_GREATER,
STENCIL_LESS,
STENCIL_GEQUAL,
STENCIL_LEQUAL,
STENCIL_NOTEQUAL,
STENCIL_EQUAL,
STENCIL_ALWAYS_PASS,
STENCIL_NEVER_PASS,
STENCIL_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 | BlendEq {
BLENDEQ_MIN,
BLENDEQ_MAX,
BLENDEQ_ADD,
BLENDEQ_SUBTRACT,
BLENDEQ_REVERSE_SUBTRACT,
BLENDEQ_CURRENT
} |
| enum | StencilOp {
STENCIL_INCR_WRAP,
STENCIL_DECR_WRAP,
STENCIL_KEEP,
STENCIL_INCR,
STENCIL_DECR,
STENCIL_REPLACE,
STENCIL_ZERO,
STENCIL_INVERT,
STENCILOP_CURRENT
} |
| enum | CullFace { CULL_FRONT,
CULL_BACK,
CULL_NONE,
CULL_CURRENT
} |
| enum | ShadeMode { SHADE_FLAT,
SHADE_SMOOTH,
SHADE_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
} |
| 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
} |
Public Member Functions |
| void | majStateChange (int inc=1) |
| void | minStateChange (int inc=1) |
| void | majGLStateChange (int inc=1) |
| void | minGLStateChange (int inc=1) |
| uint32 | debugNumMajorOpenGLStateChanges () const |
| uint32 | debugNumMinorOpenGLStateChanges () const |
| uint32 | debugNumMajorStateChanges () const |
| uint32 | debugNumMinorStateChanges () const |
| uint32 | debugNumPushStateCalls () const |
| | RenderDevice () |
| | ~RenderDevice () |
| void | describeSystem (TextOutput &t) |
| void | describeSystem (std::string &s) |
| void | pushState () |
| void | resetState () |
| void | popState () |
| void | clear (bool clearColor, bool clearDepth, bool clearStencil) |
| void | clear () |
| void | beginFrame () |
| void | endFrame () |
| bool | swapBuffersAutomatically () const |
| void | swapBuffers () |
| void | setSwapBuffersAutomatically (bool b) |
| double | getFrameRate () const |
| double | getTriangleRate () const |
| double | getTrianglesPerFrame () const |
| int | getTriangleCount () const |
| void | setDepthTest (DepthTest test) |
| void | setStencilTest (StencilTest test) |
| void | setRenderMode (RenderMode mode) |
| RenderMode | renderMode () const |
| void | setStencilConstant (int reference) |
| void | setAlphaTest (AlphaTest test, double reference) |
| AlphaTest | alphaTest () const |
| double | alphaTestReference () const |
| void | setDrawBuffer (Buffer drawBuffer) |
| Buffer | drawBuffer () const |
| void | setDepthRange (double low, double high) |
| void | enableColorWrite () |
| void | disableColorWrite () |
| void | setColorWrite (bool b) |
| bool | colorWrite () const |
| void | enableAlphaWrite () |
| void | disableAlphaWrite () |
| void | setAlphaWrite (bool b) |
| void | enableDepthWrite () |
| void | disableDepthWrite () |
| void | setDepthWrite (bool b) |
| bool | depthWrite () const |
| bool | alphaWrite () const |
| void | setShadeMode (ShadeMode s) |
| void | setStencilOp (StencilOp fail, StencilOp zfail, StencilOp zpass) |
| void | setStencilOp (StencilOp frontStencilFail, StencilOp frontZFail, StencilOp frontZPass, StencilOp backStencilFail, StencilOp backZFail, StencilOp backZPass) |
| void | setBlendFunc (BlendFunc src, BlendFunc dst, BlendEq eq=BLENDEQ_ADD) |
| void | enableClip2D (const Rect2D &clip) |
| void | disableClip2D () |
| void | setLineWidth (double width) |
| void | setPointSize (double diameter) |
| void | setObjectToWorldMatrix (const CoordinateFrame &cFrame) |
| const CoordinateFrame & | getObjectToWorldMatrix () const |
| void | setCameraToWorldMatrix (const CoordinateFrame &cFrame) |
| const CoordinateFrame & | getCameraToWorldMatrix () const |
| Matrix4 | getProjectionMatrix () const |
| CoordinateFrame | getModelViewMatrix () const |
| Matrix4 | getModelViewProjectionMatrix () const |
| void | setProjectionMatrix (const Matrix4 &P) |
| void | setTextureMatrix (uint textureUnit, const float *m) |
| void | setTextureMatrix (uint textureUnit, const double *m) |
| void | setTextureMatrix (uint textureUnit, const Matrix4 &m) |
| void | setTextureMatrix (uint textureUnit, const CoordinateFrame &c) |
| void | setTextureLODBias (uint unit, float bias) |
| Matrix4 | getTextureMatrix (uint textureUnit) |
| void | setTextureCombineMode (uint textureUnit, const CombineMode texCombine) |
| void | resetTextureUnit (uint textureUnit) |
| void | setPolygonOffset (double offset) |
| void | setColor (const Color4 &color) |
| void | setColor (const Color3 &color) |
| void | setNormal (const Vector3 &normal) |
| void | setTexCoord (uint textureUnit, const Vector4 &texCoord) |
| void | setTexCoord (uint textureUnit, const Vector3 &texCoord) |
| void | setTexCoord (uint textureUnit, const Vector3int16 &texCoord) |
| void | setTexCoord (uint textureUnit, const Vector2 &texCoord) |
| void | setTexCoord (uint textureUnit, const Vector2int16 &texCoord) |
| void | setTexCoord (uint textureUnit, double texCoord) |
| void | setCullFace (CullFace f) |
| double | getBrightScale () const |
| void | setViewport (const Rect2D &v) |
| Rect2D | getViewport () const |
| void | sendVertex (const Vector2 &vertex) |
| void | sendVertex (const Vector3 &vertex) |
| void | sendVertex (const Vector4 &vertex) |
| void | setProjectionAndCameraMatrix (const class GCamera &camera) |
| void | beginPrimitive (Primitive p) |
| void | endPrimitive () |
| void | beginIndexedPrimitives () |
| void | endIndexedPrimitives () |
| void | setVertexArray (const class VAR &v) |
| void | setNormalArray (const class VAR &v) |
| void | setColorArray (const class VAR &v) |
| void | setTexCoordArray (unsigned int unit, const class VAR &v) |
| GWindow * | window () const |
| void | setVertexAttribArray (unsigned int attribNum, const class VAR &v, bool normalize) |
| template<class T> |
| void | sendIndices (RenderDevice::Primitive primitive, int numIndices, const T *index) |
| void | sendSequentialIndices (RenderDevice::Primitive primitive, int numVertices) |
| template<class T> |
| void | sendIndices (RenderDevice::Primitive primitive, const Array< T > &index) |
| void | setStencilClearValue (int s) |
| void | setDepthClearValue (double d) |
| void | setColorClearValue (const Color4 &c) |
| void | setTexture (uint textureUnit, TextureRef texture) |
| uint | numTextures () const |
| uint | numTextureUnits () const |
| uint | numTextureCoords () const |
| void | setVertexAndPixelShader (const VertexAndPixelShaderRef &s) |
| void | setVertexAndPixelShader (const VertexAndPixelShaderRef &s, const VertexAndPixelShader::ArgList &args) |
| void | setObjectShader (const ObjectShaderRef &s) |
| void | setShader (const ShaderRef &s) |
| void | setVertexProgram (const VertexProgramRef &vp) |
| void | setVertexProgram (const VertexProgramRef &vp, const GPUProgram::ArgList &args) |
| void | setPixelProgram (const PixelProgramRef &pp) |
| void | setPixelProgram (const PixelProgramRef &pp, const GPUProgram::ArgList &args) |
| double | getDepthBufferValue (int x, int y) const |
| std::string | getCardDescription () const |
| void | enableTwoSidedLighting () |
| void | disableTwoSidedLighting () |
| void | beforePrimitive () |
| void | afterPrimitive () |
| bool | supportsOpenGLExtension (const std::string &extension) const |
| bool | supportsTextureFormat (const TextureFormat *fmt) |
| bool | supportsTwoSidedStencil () const |
| bool | supportsTextureRectangle () const |
| bool | supportsVertexProgram () const |
| bool | supportsVertexProgramNV2 () const |
| bool | supportsPixelProgram () const |
| bool | supportsVertexBufferObject () const |
| double | getLightSaturation () const |
| void | setFramebuffer (const FramebufferRef &fbo) |
| bool | currentFramebufferComplete (std::string &whyIncomplete=dummyString) const |
| void | push2D () |
| void | push2D (const FramebufferRef &fb) |
| void | push2D (const Rect2D &viewport) |
| void | pop2D () |
| bool | init (const GWindow::Settings &settings=GWindow::Settings(), class Log *log=NULL) |
| bool | init (GWindow *window, class Log *log=NULL) |
| bool | initialized () const |
| const Color4 & | color () const |
| ShadeMode | shadeMode () const |
| void | cleanup () |
| void | setCaption (const std::string &caption) |
| std::string | screenshot (const std::string &filepath) const |
| void | notifyResize (int w, int h) |
| void | screenshotPic (GImage &dest, bool useBackBuffer=false, bool getAlpha=false) const |
| int G3D_DEPRECATED | getWidth () const |
| int | width () const |
| int G3D_DEPRECATED | getHeight () const |
| int | height () const |
| int | getStencilBitDepth () const |
| int | getZBufferBitDepth () const |
| void | setLight (int num, const GLight &light) |
| void | setLight (int num, void *) |
| void | setSpecularCoefficient (float s) |
| void | setSpecularCoefficient (const Color3 &c) |
| void | setShininess (float s) |
| void | setAmbientLightColor (const Color3 &color) |
| void | setAmbientLightColor (const Color4 &color) |
| void | enableLighting () |
| void | disableLighting () |
| Vector4 | project (const Vector4 &v) const |
| Vector4 | project (const Vector3 &v) const |
| MilestoneRef | createMilestone (const std::string &name) |
| void | setMilestone (const MilestoneRef &m) |
| void | waitForMilestone (const MilestoneRef &m) |
| void | configureShadowMap (uint textureUnit, const Matrix4 &lightMVP, const TextureRef &shadowMap) |
| void | configureReflectionMap (uint textureUnit, TextureRef reflectionTexture) |
Public Attributes |
| GLenum | BufferToGL [MAX_BUFFER_SIZE] |
Static Public Attributes |
| static RenderDevice * | lastRenderDeviceCreated |
Friends |
| class | VAR |
| class | VARArea |
| class | Milestone |
| class | UserInput |
| class | VertexAndPixelShader |
Classes |
| class | DebugSettings |
| class | RenderState |
| 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);
TextureRef 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
|
|
- 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 |
|
|
|
|
- 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 |
|