SLProject 4.0.000
|
Singleton class holding all OpenGL states. More...
#include <SLGLState.h>
Public Member Functions | |
void | onInitialize (const SLCol4f &clearColor) |
On init GL. More... | |
void | initAll () |
bool | hasMultiSampling () const |
void | unbindAnythingAndFlush () |
finishes all GL commands More... | |
SLbool | pixelFormatIsSupported (SLint pixelFormat) |
Returns true if the according GL pixel format is valid in the GL context. More... | |
void | readPixels (void *buffer) |
Reads the front framebuffer pixels into the passed buffer. More... | |
void | depthTest (SLbool state) |
void | depthMask (SLbool state) |
void | depthFunc (SLenum func) |
void | cullFace (SLbool state) |
void | blend (SLbool state) |
void | blendFunc (SLenum blendFuncSFactor, SLenum blendFuncDFactor) |
Sets new blend function source and destination factors. More... | |
void | multiSample (SLbool state) |
void | polygonLine (SLbool state) |
void | polygonOffsetPoint (SLbool enabled, SLfloat factor=-1.0f, SLfloat units=-1.0f) |
void | polygonOffsetLine (SLbool enabled, SLfloat factor=-1.0f, SLfloat units=-1.0f) |
void | polygonOffsetFill (SLbool enabled, SLfloat factor=-1.0f, SLfloat units=-1.0f) |
void | viewport (SLint x, SLint y, SLsizei width, SLsizei height) |
void | colorMask (GLboolean r, GLboolean g, GLboolean b, GLboolean a) |
void | useProgram (SLuint progID) |
void | bindTexture (SLenum target, SLuint textureID) |
void | activeTexture (SLenum textureUnit) |
void | clearColor (const SLCol4f &c) |
void | currentMaterial (SLMaterial *mat) |
void | clearColorBuffer () |
void | clearDepthBuffer () |
void | clearColorDepthBuffer () |
SLbool | blend () const |
SLstring | glVersion () |
SLstring | glVersionNO () |
SLfloat | glVersionNOf () const |
SLstring | glVendor () |
SLstring | glRenderer () |
SLstring | glSLVersion () |
SLstring | glSLVersionNO () |
SLbool | glIsES () const |
SLbool | glIsES2 () const |
SLbool | glIsES3 () const |
SLint | glMaxTexUnits () const |
SLint | glMaxTexSize () const |
SLbool | glHasGeometryShaders () const |
SLbool | hasExtension (const SLstring &e) |
SLVec4i | viewport () |
SLMat4f | viewportMatrix () |
SLMaterial * | currentMaterial () |
SLstring | getGLVersionNO () |
Returns the OpenGL version number as a string. More... | |
SLstring | getSLVersionNO () |
Returns the OpenGL Shading Language version number as a string. More... | |
Static Public Member Functions | |
static SLGLState * | instance () |
Public static instance getter for singleton pattern. More... | |
static void | deleteInstance () |
global destruction More... | |
static void | getGLError (const char *file, int line, bool quit) |
Checks if an OpenGL error occurred. More... | |
Public Attributes | |
SLMat4f | modelMatrix |
Init all states. More... | |
SLMat4f | projectionMatrix |
matrix for projection transform More... | |
SLMat4f | viewMatrix |
matrix for the active cameras view transform More... | |
SLMat4f | textureMatrix |
matrix for the texture transform More... | |
Private Member Functions | |
SLGLState () | |
private onetime constructor More... | |
~SLGLState () | |
destruction in ~SLScene More... | |
Private Attributes | |
SLbool | _isInitialized |
flag for first init More... | |
SLstring | _glVersion |
OpenGL Version string. More... | |
SLstring | _glVersionNO |
OpenGL Version number string. More... | |
SLfloat | _glVersionNOf |
OpenGL Version number as float. More... | |
SLstring | _glVendor |
OpenGL Vendor string. More... | |
SLstring | _glRenderer |
OpenGL Renderer string. More... | |
SLstring | _glSLVersion |
GLSL Version string. More... | |
SLstring | _glSLVersionNO |
GLSL Version number string. More... | |
SLstring | _glExtensions |
OpenGL extensions string. More... | |
SLbool | _glIsES2 |
Flag if OpenGL ES2. More... | |
SLbool | _glIsES3 |
Flag if OpenGL ES3. More... | |
SLint | _glMaxTexUnits |
glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &_glMaxTexUnits); More... | |
SLint | _glMaxTexSize |
glGetIntegerv(GL_MAX_TEXTURE_SIZE, &_glMaxTexSize); More... | |
SLbool | _blend |
blending default false; More... | |
SLenum | _blendFuncSfactor |
blend function source factor enum More... | |
SLenum | _blendFuncDfactor |
blend function destination factor enum More... | |
SLbool | _depthTest |
GL_DEPTH_TEST state. More... | |
SLbool | _depthMask |
glDepthMask state More... | |
SLenum | _depthFunc |
depth buffer comparison function More... | |
SLbool | _cullFace |
Face culling state. More... | |
SLbool | _multisample |
Multisampling state. More... | |
SLint | _multiSampleSamples |
NO. of multisampling samples. More... | |
SLbool | _polygonLine |
Line polygon state. More... | |
SLbool | _polygonOffsetPointEnabled |
GL_POLYGON_OFFSET_POINT state enabled. More... | |
SLbool | _polygonOffsetLineEnabled |
GL_POLYGON_OFFSET_LINE state enabled. More... | |
SLbool | _polygonOffsetFillEnabled |
GL_POLYGON_OFFSET_FILL state enabled. More... | |
SLVec4i | _viewport |
viewport size (x,y,w,h) of the framebuffer More... | |
SLCol4f | _clearColor |
clear color More... | |
SLuint | _programID |
current shader program id More... | |
SLenum | _textureUnit |
current texture unit More... | |
SLenum | _textureTarget |
current texture target More... | |
SLuint | _textureID |
current texture id More... | |
GLboolean | _colorMaskR |
current color mask for R More... | |
GLboolean | _colorMaskG |
current color mask for G More... | |
GLboolean | _colorMaskB |
current color mask for B More... | |
GLboolean | _colorMaskA |
current color mask for A More... | |
SLVstring | errors |
vector for errors collected in getGLError More... | |
SLMaterial * | _currentMaterial |
Static Private Attributes | |
static SLGLState * | _instance = nullptr |
global singleton object More... | |
Singleton class holding all OpenGL states.
The main purpose of the SLGLState class is to replace all the OpenGL states and functionality that has been removed from the core profile of OpenGL. The core profile started from OpenGL version 3.0 has e.g. no more internal matrices, lighting or material states. It also has no more fixed function pipeline on the GPU witch means, that core profile OpenGL only works with custom shader programs written in OpenGL Shading Language (GLSL). The second purpose is to concentrate OpenGL functionality and to reduce redundant state changes.
|
private |
private onetime constructor
Private constructor should be called only once for a singleton class.
|
private |
destruction in ~SLScene
The destructor only empties the stacks
void SLGLState::activeTexture | ( | SLenum | textureUnit | ) |
SLGLState::activeTexture sets the current active texture unit
SLGLState::bindTexture sets the current active texture.
|
inline |
void SLGLState::blend | ( | SLbool | stateNew | ) |
SLGLState::blend enables or disables alpha blending but only if the state really changes.
Sets new blend function source and destination factors.
void SLGLState::clearColor | ( | const SLCol4f & | c | ) |
|
inline |
|
inline |
|
inline |
void SLGLState::colorMask | ( | GLboolean | r, |
GLboolean | g, | ||
GLboolean | b, | ||
GLboolean | a | ||
) |
SLGLState::colorMask sets the OpenGL colorMask for framebuffer masking
void SLGLState::cullFace | ( | SLbool | stateNew | ) |
SLGLState::cullFace sets the GL_CULL_FACE state but only if the state really changes. If face culling is turned on no back faces are processed.
|
inline |
|
inline |
|
static |
global destruction
Public static destruction.
void SLGLState::depthFunc | ( | SLenum | func | ) |
SLGLState::depthFunc specifies the depth comparison function. Symbolic constants GL_NEVER, GL_LESS, GL_EQUAL, GL_LEQUAL, GL_GREATER, GL_NOTEQUAL, GL_GEQUAL, and GL_ALWAYS are accepted. The initial value is GL_LESS.
void SLGLState::depthMask | ( | SLbool | stateNew | ) |
SLGLState::depthTest enables or disables depth buffer writing but only if the state really changes. Turning on depth masking freezes the depth test but keeps all values in the depth buffer.
void SLGLState::depthTest | ( | SLbool | stateNew | ) |
SLGLState::depthTest enables or disables depth testing but only if the state really changes. The depth test decides for each pixel in the depth buffer which polygon is the closest to the eye.
|
static |
Checks if an OpenGL error occurred.
SLstring SLGLState::getGLVersionNO | ( | ) |
Returns the OpenGL version number as a string.
The string returned by glGetString can contain additional vendor information such as the build number and the brand name. For the OpenGL version string "4.5.0 NVIDIA 347.68" the function returns "4.5"
SLstring SLGLState::getSLVersionNO | ( | ) |
Returns the OpenGL Shading Language version number as a string.
The string returned by glGetString can contain additional vendor information such as the build number and the brand name. For the shading language string "Nvidia GLSL 4.5" the function returns "450"
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
void SLGLState::initAll | ( | ) |
Initializes all states.
|
inlinestatic |
Public static instance getter for singleton pattern.
void SLGLState::multiSample | ( | SLbool | stateNew | ) |
SLGLState::multiSample enables or disables multisampling but only if the state really changes. Multisampling turns on fullscreen anti aliasing on the GPU witch produces smooth polygon edges, lines and points.
void SLGLState::onInitialize | ( | const SLCol4f & | clearColor | ) |
On init GL.
One time initialization
Returns true if the according GL pixel format is valid in the GL context.
void SLGLState::polygonLine | ( | SLbool | stateNew | ) |
SLGLState::polygonMode sets the polygonMode to GL_LINE but only if the state really changes. OpenGL ES doesn't support glPolygonMode. It has to be mimicked with GL_LINE_LOOP drawing.
SLGLState::polygonOffsetFill turns on/off polygon offset for filled polygons and sets the factor and unit for glPolygonOffset but only if the state really changes. Polygon offset is used to reduce z-fighting due to parallel planes or lines. See: http://www.zeuscmd.com/tutorials/opengl/15-PolygonOffset.php
SLGLState::polygonOffsetLine turns on/off polygon offset for lines and sets the factor and unit for glPolygonOffset but only if the state really changes. Polygon offset is used to reduce z-fighting due to parallel planes or lines. See: http://www.zeuscmd.com/tutorials/opengl/15-PolygonOffset.php
void SLGLState::polygonOffsetPoint | ( | SLbool | enabled, |
SLfloat | factor = -1.0f , |
||
SLfloat | units = -1.0f |
||
) |
SLGLState::polygonOffsetPoint turns on/off polygon offset for points and sets the factor and unit for glPolygonOffset but only if the state really changes. Polygon offset is used to reduce z-fighting due to parallel planes or lines. See: http://www.zeuscmd.com/tutorials/opengl/15-PolygonOffset.php
void SLGLState::readPixels | ( | void * | buffer | ) |
Reads the front framebuffer pixels into the passed buffer.
buffer | Pointer to a 4 byte aligned buffer with the correct size. |
void SLGLState::unbindAnythingAndFlush | ( | ) |
finishes all GL commands
SLGLState::unbindAnythingAndFlush unbinds all shaderprograms and buffers in use and calls glFinish. This should be the last call to GL before buffer swapping.
void SLGLState::useProgram | ( | SLuint | progID | ) |
SLGLState::useProgram sets the _rent active shader program
|
inline |
SLGLState::viewport sets the OpenGL viewport position and size
|
inline |
|
private |
blending default false;
|
private |
blend function destination factor enum
|
private |
blend function source factor enum
|
private |
clear color
|
private |
current color mask for A
|
private |
current color mask for B
|
private |
current color mask for G
|
private |
current color mask for R
|
private |
Face culling state.
|
private |
|
private |
depth buffer comparison function
|
private |
glDepthMask state
|
private |
GL_DEPTH_TEST state.
|
private |
OpenGL extensions string.
|
private |
Flag if OpenGL ES2.
|
private |
Flag if OpenGL ES3.
|
private |
glGetIntegerv(GL_MAX_TEXTURE_SIZE, &_glMaxTexSize);
|
private |
glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &_glMaxTexUnits);
|
private |
OpenGL Renderer string.
|
private |
GLSL Version string.
|
private |
GLSL Version number string.
|
private |
OpenGL Vendor string.
|
private |
OpenGL Version string.
|
private |
OpenGL Version number string.
|
private |
OpenGL Version number as float.
|
staticprivate |
global singleton object
|
private |
flag for first init
|
private |
Multisampling state.
|
private |
NO. of multisampling samples.
|
private |
Line polygon state.
|
private |
GL_POLYGON_OFFSET_FILL state enabled.
|
private |
GL_POLYGON_OFFSET_LINE state enabled.
|
private |
GL_POLYGON_OFFSET_POINT state enabled.
|
private |
current shader program id
|
private |
current texture id
|
private |
current texture target
|
private |
current texture unit
|
private |
viewport size (x,y,w,h) of the framebuffer
|
private |
vector for errors collected in getGLError
SLMat4f SLGLState::modelMatrix |
Init all states.
matrix for model to world transform
SLMat4f SLGLState::projectionMatrix |
matrix for projection transform
SLMat4f SLGLState::textureMatrix |
matrix for the texture transform
SLMat4f SLGLState::viewMatrix |
matrix for the active cameras view transform