Carna
Version 3.3.2
|
Manages the OpenGL render state. More...
#include <RenderState.h>
Public Types | |
enum | CullFace { cullNone, cullBack, cullFront } |
Lists supported face culling modes. More... | |
Public Member Functions | |
RenderState () | |
Derives new render state from the current one of the current OpenGL context. | |
~RenderState () | |
Restores previous render state. | |
void | setDepthTest (bool dt) |
Enables or disables depth testing. | |
void | setDepthWrite (bool dw) |
Enables or disables depth writing. | |
void | setDepthTestFunction (int dtf) |
Configures how the depth test is to be performed. Depth test only applies if it is activated.. More... | |
void | setBlend (bool b) |
Enables or disables alpha blending. Alpha blending is configured through setBlendFunction and setBlendEquation. | |
void | setBlendFunction (const BlendFunction &bf) |
Configures how alpha blending is to be done. Alpha blending only applies if it is activated.. More... | |
void | setBlendEquation (int be) |
Sets glBlendEquation to be. | |
void | setCullFace (CullFace cf) |
Configures face culling. Also see setFrontFace. | |
void | setFrontFace (bool ccw) |
Sets whether front faces are winded contra-clockwise. Also see setCullFace. | |
void | setPointSize (float pointSize) |
Sets glPointSize to pointSize if point size is non-negative. Enables GL_PROGRAM_POINT_SIZE and leaves glPointSize unchanged otherwise. This enables support for gl_PointSize in shaders. | |
Protected Member Functions | |
RenderState (GLContext &glContext) | |
Creates the root instance of glContext. For internal usage only. | |
void | commit () const |
Commits the full state. For internal usage only. | |
Friends | |
class | GLContext |
Manages the OpenGL render state.
Each OpenGL context has a so-called render state. This describes things like whether alpha blending is to be used for rendering primitives or not. The purpose of this class is to reduce the state transitions, that can be quite expansive, and make it easy to enforce a fully-defined state.
The mechanism behind this class exploits the fact that the current OpenGL context is a thread-local variable as described here. This allows us to utilize the execution stack to track the render state:
The constructor derives a new render state, that immediately becomes the current one and equals the previous state. The method render
disables depth testing and enables alpha blending. Whether state transitions actually happen here depends on how the previous state was configured. When render1
turns off depth testing again, nothing happens, because it already was disabled within the previous state. Same is true for render2
. The updated blend function of render1
does not affect render2
. Note that it is forbidden to modify a render state that is not the current one.
Definition at line 85 of file RenderState.h.
Lists supported face culling modes.
Enumerator | |
---|---|
cullNone | All polygons will pass the cull test. |
cullBack | Polygons recognized as back-faces will be discarded. |
cullFront | Polygons recognized as front-faces will be discarded. |
Definition at line 112 of file RenderState.h.
void Carna::base::RenderState::setBlendFunction | ( | const BlendFunction & | bf | ) |
Configures how alpha blending is to be done. Alpha blending only applies if it is activated..
This is the equivalent of glBlendFunc
.
void Carna::base::RenderState::setDepthTestFunction | ( | int | dtf | ) |
Configures how the depth test is to be performed. Depth test only applies if it is activated..
This is the equivalent of glDepthFunc
.
Documentation generated by Doxygen