GL Studio SCECpp Runtime Library
Public Member Functions | Static Public Member Functions | Static Public Attributes | Protected Member Functions | Protected Attributes | List of all members
GlsStateManager Class Reference

#include <gls_state_manager.h>

Public Member Functions

void ResetOpenGLState (void)
 
void Begin (const GLenum mode)
 
void End (void)
 
void BindTexture2D (const GLuint textureIndex)
 
void LineWidth (const GLfloat lineWidth)
 
void AlphaFunc (const GLenum func, const GLclampf ref)
 
void Color (const GlsColor &color)
 
void BlendFunc (const GLenum sfactor, const GLenum dfactor)
 
void ShadeModel (const GLenum mode)
 
void DepthFunc (const GLenum func)
 
void EnableAlphaTest (const GlsBool enable)
 
void EnableBlend (const GlsBool enable)
 
void EnableCullFace (const GlsBool enable)
 
void EnableDepthTest (const GlsBool enable)
 
void EnableLineSmooth (const GlsBool enable)
 
void EnableTexture2D (const GlsBool enable)
 
void TexParameteri2D (const GLenum pname, const GLint param)
 
void TexEnvi (const GLint param)
 

Static Public Member Functions

static GlsStateManagerGetStateManager (void)
 

Static Public Attributes

static const GLuint INVALID_GL_TEXTURE_INDEX = 0u
 

Protected Member Functions

 GlsStateManager (void)
 
virtual ~GlsStateManager ()
 

Protected Attributes

GLenum _alphaFunc
 
GLclampf _alphaRef
 
GlsBool _alphaTest
 
GlsBool _alphaBlend
 
GLenum _alphaBlendSFactor
 
GLenum _alphaBlendDFactor
 
GlsBool _depthTest
 
GLenum _depthFunc
 
GlsBool _lineSmooth
 
GlsBool _cullFace
 
GLenum _shadeModel
 
GlsColor _color
 
GlsBool _texture2D
 
GLuint _textureIndex2D
 
GLfloat _lineWidth
 
GLenum _polygonMode
 

Detailed Description

This class manages OpenGL context state and allows for minimizing calls to OpenGL.

Invariant
GlsGLAlphaFuncIsValid( _alphaFunc ), ( 0.0f <= _alphaRef ) && ( _alphaRef <= 1.0f ), GlsGLBlendFuncSFactorIsValid( _alphaBlendSFactor ), GlsGLBlendFuncDFactorIsValid( _alphaBlendDFactor ), GlsGLDepthFuncIsValid( _depthFunc ), GlsGLShadeModelIsValid( _shadeModel ), _color.IsValid(), ( ( GlsStateManager::LINE_WIDTH_MIN <= _lineWidth ) && ( _lineWidth <= GlsStateManager::LINE_WIDTH_MAX ) ), GlsGLPolygonModeIsValid( _polygonMode ) ), ( ( 0 == _glBeginCount ) || ( 1 == _glBeginCount ) ), ( 1 == _numInstCreated ), OpenGL state is synchronized with the state manager

Constructor & Destructor Documentation

GlsStateManager::GlsStateManager ( void  )
protected

Constructor - create an instance

Precondition
not within a begin/end pair, glGetError() == GL_NO_ERROR, no other state manager has been created
Postcondition
instance created, OpenGL state is synchronized with state manager
virtual GlsStateManager::~GlsStateManager ( )
protectedvirtual

Destructor - shall never be called

Precondition
none
Postcondition
none

Member Function Documentation

void GlsStateManager::AlphaFunc ( const GLenum  func,
const GLclampf  ref 
)

equivalent to glAlphaFunc() call

Parameters
funcGL alpha comparison mode
refGL alpha reference value
Precondition
GlsGLAlphaFuncIsValid( func ), 0.0f <= ref <= 1.0f, not within a begin/end pair
Postcondition
new GL alpha mode and reference are set
void GlsStateManager::Begin ( const GLenum  mode)

equivalent to glBegin() call

Parameters
modeprimitive mode to begin
Precondition
must not be within a begin/end pair, mode is a valid GL primitive mode
Postcondition
a new primitive is started
void GlsStateManager::BindTexture2D ( const GLuint  textureIndex)

equivalent to glBindTexture( GL_TEXTURE_2D, .. ) call

Parameters
textureIndexGL texture index of texture to bind ( >0 )
Precondition
textureIndex > 0, textureIndex is a valid GL texture index, not within a begin/end pair
Postcondition
desired 2D texture is bound to GL
void GlsStateManager::BlendFunc ( const GLenum  sfactor,
const GLenum  dfactor 
)

equivalent to glBlendFunc() call

Parameters
sfactoralpha source mode
dfactoralpha destination mode
Precondition
GlsGLBlendFuncSFactorIsValid( sfactor ), GlsGLBlendFuncDFactorIsValid( dfactor ), not within a begin/end pair
Postcondition
new GL alpha blend mode is set
void GlsStateManager::Color ( const GlsColor color)

equivalent to glColor() call

Parameters
colornew color
Precondition
color.IsValid()
Postcondition
new GL color is set
void GlsStateManager::DepthFunc ( const GLenum  func)

equivalent to glDepthFunc() call

Parameters
funcnew GL depth function
Precondition
GlsGLDepthFuncIsValid( func ), not within a begin/end pair
Postcondition
new GL depth function is set
void GlsStateManager::EnableAlphaTest ( const GlsBool  enable)

equivalent to glEnable(GL_ALPHA_TEST)/glDisable(GL_ALPHA_TEST) call

Parameters
enableGLS_TRUE to enable else GLS_FALSE
Precondition
not within a begin/end pair
Postcondition
GL_ALPHA_TEST is enabled if enable == GLS_TRUE else, GL_ALPHA_TEST is disabled
void GlsStateManager::EnableBlend ( const GlsBool  enable)

equivalent to glEnable(GL_BLEND)/glDisable(GL_BLEND) call

Parameters
enableGLS_TRUE to enable else GLS_FALSE
Precondition
not within a begin/end pair
Postcondition
GL_BLEND is enabled if enable == GLS_TRUE else, GL_BLEND is disabled
void GlsStateManager::EnableCullFace ( const GlsBool  enable)

equivalent to glEnable(GL_CULL_FACE)/glDisable(GL_CULL_FACE) call

Parameters
enableGLS_TRUE to enable else GLS_FALSE
Precondition
not within a begin/end pair
Postcondition
GL_CULL_FACE is enabled if enable == GLS_TRUE else, GL_CULL_FACE is disabled
void GlsStateManager::EnableDepthTest ( const GlsBool  enable)

equivalent to glEnable(GL_DEPTH_TEST)/glDisable(GL_DEPTH_TEST) call

Parameters
enableGLS_TRUE to enable else GLS_FALSE
Precondition
not within a begin/end pair
Postcondition
GL_DEPTH_TEST is enabled if enable == GLS_TRUE else, GL_DEPTH_TEST is disabled
void GlsStateManager::EnableLineSmooth ( const GlsBool  enable)

equivalent to glEnable(GL_LINE_SMOOTH)/glDisable(GL_LINE_SMOOTH) call

Parameters
enableGLS_TRUE to enable else GLS_FALSE
Precondition
not within a begin/end pair
Postcondition
GL_LINE_SMOOTH is enabled if enable == GLS_TRUE else, GL_LINE_SMOOTH is disabled
void GlsStateManager::EnableTexture2D ( const GlsBool  enable)

equivalent to glEnable(GL_TEXTURE_2D)/glDisable(GL_TEXTURE_2D) call

Parameters
enableGLS_TRUE to enable else GLS_FALSE
Precondition
not within a begin/end pair
Postcondition
GL_TEXTURE_2D is enabled if enable == GLS_TRUE else, GL_TEXTURE_2D is disabled
void GlsStateManager::End ( void  )

equivalent to glEnd() call

Precondition
must be called within a begin/end pair
Postcondition
primitive is ended
static GlsStateManager& GlsStateManager::GetStateManager ( void  )
static

Get the singleton GlsStateManager instance

Precondition
precondition for constructor must hold first time this method is called
Postcondition
postcondition for constructor holds after the first time this method is called
Returns
the singleton GlsStateManager instance
void GlsStateManager::LineWidth ( const GLfloat  lineWidth)

equivalent to glLineWidth() call

Parameters
lineWidthnew line width ( GlsStateManager::LINE_WIDTH_MIN <= width <= GlsStateManager::LINE_WIDTH_MAX )
Precondition
GlsStateManager::LINE_WIDTH_MIN <= width <= GlsStateManager::LINE_WIDTH_MAX, not within a begin/end pair
Postcondition
GL has new line width
void GlsStateManager::ResetOpenGLState ( void  )

Reset the cached GL state variables and set them into the GL state

Precondition
none
Postcondition
cached GL state variables are set to default values and GL is synchronized with state manager
void GlsStateManager::ShadeModel ( const GLenum  mode)

equivalent to glShadeModel() call

Parameters
modenew GL shade mode
Precondition
GlsGLShadeModelIsValid( mode ), not within a begin/end pair
Postcondition
new GL shade model is set
void GlsStateManager::TexEnvi ( const GLint  param)

equivalent to glTexEnvi(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,...) call

Parameters
paramnew value for texture environment mode
Precondition
GlsGLTetxureEnvModeIsValid( param ), not within a begin/end pair
Postcondition
GL texture environment mode is set to new value
void GlsStateManager::TexParameteri2D ( const GLenum  pname,
const GLint  param 
)

equivalent to glTexParameteri(GL_TEXTURE_2D,...) call

Parameters
pnameGL texture parameter name
paramnew value for indicated parameter
Precondition
GlsGLTextureParameterIsValid( pname ), pname == GL_TEXTURE_MIN_FILTER -> GlsGLTextureMinFilterIsValid( param ), pname == GL_TEXTURE_MAG_FITLER -> GlsGLTextureMagFilterIsValid( param ), pname == GL_TEXTURE_WRAP_S -> GlsGLTextureWrapIsValid( param ), pname == GL_TEXTURE_WRAP_T -> GlsGLTextureWrapIsValid( param ), not within a begin/end pair
Postcondition
given GL texture parameter is set to new value

Member Data Documentation

GlsBool GlsStateManager::_alphaBlend
protected

current GL Alpha Blending state

GLenum GlsStateManager::_alphaBlendDFactor
protected

current GL Alpha Blending destination factor

GLenum GlsStateManager::_alphaBlendSFactor
protected

current GL Alpha Blending source factor

GLenum GlsStateManager::_alphaFunc
protected

current GL alpha function

GLclampf GlsStateManager::_alphaRef
protected

current GL alpha reference value

GlsBool GlsStateManager::_alphaTest
protected

current GL Alpha Testing state (Screen door transparency)

GlsColor GlsStateManager::_color
protected

current GL Drawing color

GlsBool GlsStateManager::_cullFace
protected

current GL Backface culling state

GLenum GlsStateManager::_depthFunc
protected

current GL Depth Testing function

GlsBool GlsStateManager::_depthTest
protected

current GL Depth Testing state

GlsBool GlsStateManager::_lineSmooth
protected

current GL Line anti-aliasing

GLfloat GlsStateManager::_lineWidth
protected

current GL Line width

GLenum GlsStateManager::_polygonMode
protected

current GL Polygon Draw Mode

GLenum GlsStateManager::_shadeModel
protected

current GL shading model

GlsBool GlsStateManager::_texture2D
protected

current GL 2D texture state

GLuint GlsStateManager::_textureIndex2D
protected

current index of GL 2D bound texture else GlsStateManager::INVALID_GL_TEXTURE_INDEX if no texture is bound

const GLuint GlsStateManager::INVALID_GL_TEXTURE_INDEX = 0u
static

invalid GL texture index