SLProject 4.0.000
SLGLState Class Reference

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 ()
 
SLMaterialcurrentMaterial ()
 
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 SLGLStateinstance ()
 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...
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ SLGLState()

SLGLState::SLGLState ( )
private

private onetime constructor

Private constructor should be called only once for a singleton class.

◆ ~SLGLState()

SLGLState::~SLGLState ( )
private

destruction in ~SLScene

The destructor only empties the stacks

Member Function Documentation

◆ activeTexture()

void SLGLState::activeTexture ( SLenum  textureUnit)

SLGLState::activeTexture sets the current active texture unit

◆ bindTexture()

void SLGLState::bindTexture ( SLenum  target,
SLuint  textureID 
)

SLGLState::bindTexture sets the current active texture.

◆ blend() [1/2]

SLbool SLGLState::blend ( ) const
inline

◆ blend() [2/2]

void SLGLState::blend ( SLbool  stateNew)

SLGLState::blend enables or disables alpha blending but only if the state really changes.

◆ blendFunc()

void SLGLState::blendFunc ( SLenum  blendFuncSFactor,
SLenum  blendFuncDFactor 
)

Sets new blend function source and destination factors.

◆ clearColor()

void SLGLState::clearColor ( const SLCol4f c)

◆ clearColorBuffer()

void SLGLState::clearColorBuffer ( )
inline

◆ clearColorDepthBuffer()

void SLGLState::clearColorDepthBuffer ( )
inline

◆ clearDepthBuffer()

void SLGLState::clearDepthBuffer ( )
inline

◆ colorMask()

void SLGLState::colorMask ( GLboolean  r,
GLboolean  g,
GLboolean  b,
GLboolean  a 
)

SLGLState::colorMask sets the OpenGL colorMask for framebuffer masking

◆ cullFace()

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.

◆ currentMaterial() [1/2]

SLMaterial * SLGLState::currentMaterial ( )
inline

◆ currentMaterial() [2/2]

void SLGLState::currentMaterial ( SLMaterial mat)
inline

◆ deleteInstance()

void SLGLState::deleteInstance ( )
static

global destruction

Public static destruction.

◆ depthFunc()

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.

◆ depthMask()

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.

◆ depthTest()

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.

◆ getGLError()

void SLGLState::getGLError ( const char *  file,
int  line,
bool  quit 
)
static

Checks if an OpenGL error occurred.

◆ getGLVersionNO()

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"

◆ getSLVersionNO()

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"

◆ glHasGeometryShaders()

SLbool SLGLState::glHasGeometryShaders ( ) const
inline

◆ glIsES()

SLbool SLGLState::glIsES ( ) const
inline

◆ glIsES2()

SLbool SLGLState::glIsES2 ( ) const
inline

◆ glIsES3()

SLbool SLGLState::glIsES3 ( ) const
inline

◆ glMaxTexSize()

SLint SLGLState::glMaxTexSize ( ) const
inline

◆ glMaxTexUnits()

SLint SLGLState::glMaxTexUnits ( ) const
inline

◆ glRenderer()

SLstring SLGLState::glRenderer ( )
inline

◆ glSLVersion()

SLstring SLGLState::glSLVersion ( )
inline

◆ glSLVersionNO()

SLstring SLGLState::glSLVersionNO ( )
inline

◆ glVendor()

SLstring SLGLState::glVendor ( )
inline

◆ glVersion()

SLstring SLGLState::glVersion ( )
inline

◆ glVersionNO()

SLstring SLGLState::glVersionNO ( )
inline

◆ glVersionNOf()

SLfloat SLGLState::glVersionNOf ( ) const
inline

◆ hasExtension()

SLbool SLGLState::hasExtension ( const SLstring e)
inline

◆ hasMultiSampling()

bool SLGLState::hasMultiSampling ( ) const
inline

◆ initAll()

void SLGLState::initAll ( )

Initializes all states.

◆ instance()

static SLGLState * SLGLState::instance ( )
inlinestatic

Public static instance getter for singleton pattern.

◆ multiSample()

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.

◆ onInitialize()

void SLGLState::onInitialize ( const SLCol4f clearColor)

On init GL.

One time initialization

◆ pixelFormatIsSupported()

SLbool SLGLState::pixelFormatIsSupported ( SLint  pixelFormat)

Returns true if the according GL pixel format is valid in the GL context.

◆ polygonLine()

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.

◆ polygonOffsetFill()

void SLGLState::polygonOffsetFill ( SLbool  enabled,
SLfloat  factor = -1.0f,
SLfloat  units = -1.0f 
)

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

◆ polygonOffsetLine()

void SLGLState::polygonOffsetLine ( SLbool  enabled,
SLfloat  factor = -1.0f,
SLfloat  units = -1.0f 
)

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

◆ polygonOffsetPoint()

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

◆ readPixels()

void SLGLState::readPixels ( void *  buffer)

Reads the front framebuffer pixels into the passed buffer.

Parameters
bufferPointer to a 4 byte aligned buffer with the correct size.

◆ unbindAnythingAndFlush()

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.

◆ useProgram()

void SLGLState::useProgram ( SLuint  progID)

SLGLState::useProgram sets the _rent active shader program

◆ viewport() [1/2]

SLVec4i SLGLState::viewport ( )
inline

◆ viewport() [2/2]

void SLGLState::viewport ( SLint  x,
SLint  y,
SLsizei  width,
SLsizei  height 
)

SLGLState::viewport sets the OpenGL viewport position and size

◆ viewportMatrix()

SLMat4f SLGLState::viewportMatrix ( )
inline

Member Data Documentation

◆ _blend

SLbool SLGLState::_blend
private

blending default false;

◆ _blendFuncDfactor

SLenum SLGLState::_blendFuncDfactor
private

blend function destination factor enum

◆ _blendFuncSfactor

SLenum SLGLState::_blendFuncSfactor
private

blend function source factor enum

◆ _clearColor

SLCol4f SLGLState::_clearColor
private

clear color

◆ _colorMaskA

GLboolean SLGLState::_colorMaskA
private

current color mask for A

◆ _colorMaskB

GLboolean SLGLState::_colorMaskB
private

current color mask for B

◆ _colorMaskG

GLboolean SLGLState::_colorMaskG
private

current color mask for G

◆ _colorMaskR

GLboolean SLGLState::_colorMaskR
private

current color mask for R

◆ _cullFace

SLbool SLGLState::_cullFace
private

Face culling state.

◆ _currentMaterial

SLMaterial* SLGLState::_currentMaterial
private

◆ _depthFunc

SLenum SLGLState::_depthFunc
private

depth buffer comparison function

◆ _depthMask

SLbool SLGLState::_depthMask
private

glDepthMask state

◆ _depthTest

SLbool SLGLState::_depthTest
private

GL_DEPTH_TEST state.

◆ _glExtensions

SLstring SLGLState::_glExtensions
private

OpenGL extensions string.

◆ _glIsES2

SLbool SLGLState::_glIsES2
private

Flag if OpenGL ES2.

◆ _glIsES3

SLbool SLGLState::_glIsES3
private

Flag if OpenGL ES3.

◆ _glMaxTexSize

SLint SLGLState::_glMaxTexSize
private

glGetIntegerv(GL_MAX_TEXTURE_SIZE, &_glMaxTexSize);

◆ _glMaxTexUnits

SLint SLGLState::_glMaxTexUnits
private

glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &_glMaxTexUnits);

◆ _glRenderer

SLstring SLGLState::_glRenderer
private

OpenGL Renderer string.

◆ _glSLVersion

SLstring SLGLState::_glSLVersion
private

GLSL Version string.

◆ _glSLVersionNO

SLstring SLGLState::_glSLVersionNO
private

GLSL Version number string.

◆ _glVendor

SLstring SLGLState::_glVendor
private

OpenGL Vendor string.

◆ _glVersion

SLstring SLGLState::_glVersion
private

OpenGL Version string.

◆ _glVersionNO

SLstring SLGLState::_glVersionNO
private

OpenGL Version number string.

◆ _glVersionNOf

SLfloat SLGLState::_glVersionNOf
private

OpenGL Version number as float.

◆ _instance

SLGLState * SLGLState::_instance = nullptr
staticprivate

global singleton object

◆ _isInitialized

SLbool SLGLState::_isInitialized
private

flag for first init

◆ _multisample

SLbool SLGLState::_multisample
private

Multisampling state.

◆ _multiSampleSamples

SLint SLGLState::_multiSampleSamples
private

NO. of multisampling samples.

◆ _polygonLine

SLbool SLGLState::_polygonLine
private

Line polygon state.

◆ _polygonOffsetFillEnabled

SLbool SLGLState::_polygonOffsetFillEnabled
private

GL_POLYGON_OFFSET_FILL state enabled.

◆ _polygonOffsetLineEnabled

SLbool SLGLState::_polygonOffsetLineEnabled
private

GL_POLYGON_OFFSET_LINE state enabled.

◆ _polygonOffsetPointEnabled

SLbool SLGLState::_polygonOffsetPointEnabled
private

GL_POLYGON_OFFSET_POINT state enabled.

◆ _programID

SLuint SLGLState::_programID
private

current shader program id

◆ _textureID

SLuint SLGLState::_textureID
private

current texture id

◆ _textureTarget

SLenum SLGLState::_textureTarget
private

current texture target

◆ _textureUnit

SLenum SLGLState::_textureUnit
private

current texture unit

◆ _viewport

SLVec4i SLGLState::_viewport
private

viewport size (x,y,w,h) of the framebuffer

◆ errors

SLVstring SLGLState::errors
private

vector for errors collected in getGLError

◆ modelMatrix

SLMat4f SLGLState::modelMatrix

Init all states.

matrix for model to world transform

◆ projectionMatrix

SLMat4f SLGLState::projectionMatrix

matrix for projection transform

◆ textureMatrix

SLMat4f SLGLState::textureMatrix

matrix for the texture transform

◆ viewMatrix

SLMat4f SLGLState::viewMatrix

matrix for the active cameras view transform


The documentation for this class was generated from the following files: