Open CASCADE Technology  7.1.0.beta
Data Structures | Public Member Functions | Protected Member Functions | Protected Attributes
OpenGl_ShaderManager Class Reference

This class is responsible for managing shader programs. More...

#include <OpenGl_ShaderManager.hxx>

Inheritance diagram for OpenGl_ShaderManager:
Inheritance graph
[legend]

Data Structures

struct  OpenGl_ShaderLightParameters
 Packed properties of light source. More...
 
struct  OpenGl_ShaderLightType
 Packed light source type information. More...
 

Public Member Functions

 OpenGl_ShaderManager (OpenGl_Context *theContext)
 Creates new empty shader manager. More...
 
virtual ~OpenGl_ShaderManager ()
 Releases resources of shader manager. More...
 
void clear ()
 Release all resources. More...
 
const gp_XYZLocalOrigin () const
 Return local camera transformation. More...
 
void SetLocalOrigin (const gp_XYZ &theOrigin)
 Setup local camera transformation for compensating float precision issues. More...
 
Standard_Boolean Create (const Handle< Graphic3d_ShaderProgram > &theProxy, TCollection_AsciiString &theShareKey, Handle< OpenGl_ShaderProgram > &theProgram)
 Creates new shader program or re-use shared instance. More...
 
void Unregister (TCollection_AsciiString &theShareKey, Handle< OpenGl_ShaderProgram > &theProgram)
 Unregisters specified shader program. More...
 
const OpenGl_ShaderProgramListShaderPrograms () const
 Returns list of registered shader programs. More...
 
Standard_Boolean IsEmpty () const
 Returns true if no program objects are registered in the manager. More...
 
Standard_Boolean BindFaceProgram (const Handle< OpenGl_Texture > &theTexture, const Standard_Boolean theToLightOn, const Standard_Boolean theHasVertColor, const Standard_Boolean theEnableEnvMap, const Handle< OpenGl_ShaderProgram > &theCustomProgram)
 Bind program for filled primitives rendering. More...
 
Standard_Boolean BindLineProgram (const Handle< OpenGl_Texture > &theTexture, const Standard_Boolean theStipple, const Standard_Boolean theToLightOn, const Standard_Boolean theHasVertColor, const Handle< OpenGl_ShaderProgram > &theCustomProgram)
 Bind program for line rendering. More...
 
Standard_Boolean BindMarkerProgram (const Handle< OpenGl_Texture > &theTexture, const Standard_Boolean theToLightOn, const Standard_Boolean theHasVertColor, const Handle< OpenGl_ShaderProgram > &theCustomProgram)
 Bind program for point rendering. More...
 
Standard_Boolean BindFontProgram (const Handle< OpenGl_ShaderProgram > &theCustomProgram)
 Bind program for rendering alpha-textured font. More...
 
Standard_Boolean BindFboBlitProgram ()
 Bind program for FBO blit operation. More...
 
Standard_Boolean BindStereoProgram (const Graphic3d_StereoMode theStereoMode)
 Bind program for rendering stereoscopic image. More...
 
const OpenGl_LightSourceStateLightSourceState () const
 Returns current state of OCCT light sources. More...
 
void UpdateLightSourceStateTo (const OpenGl_ListOfLight *theLights)
 Updates state of OCCT light sources. More...
 
void UpdateLightSourceState ()
 Invalidate state of OCCT light sources. More...
 
void PushLightSourceState (const Handle< OpenGl_ShaderProgram > &theProgram) const
 Pushes current state of OCCT light sources to specified program. More...
 
const OpenGl_ProjectionStateProjectionState () const
 Returns current state of OCCT projection transform. More...
 
void UpdateProjectionStateTo (const OpenGl_Mat4 &theProjectionMatrix)
 Updates state of OCCT projection transform. More...
 
void PushProjectionState (const Handle< OpenGl_ShaderProgram > &theProgram) const
 Pushes current state of OCCT projection transform to specified program. More...
 
const OpenGl_ModelWorldStateModelWorldState () const
 Returns current state of OCCT model-world transform. More...
 
void UpdateModelWorldStateTo (const OpenGl_Mat4 &theModelWorldMatrix)
 Updates state of OCCT model-world transform. More...
 
void PushModelWorldState (const Handle< OpenGl_ShaderProgram > &theProgram) const
 Pushes current state of OCCT model-world transform to specified program. More...
 
const OpenGl_WorldViewStateWorldViewState () const
 Returns current state of OCCT world-view transform. More...
 
void UpdateWorldViewStateTo (const OpenGl_Mat4 &theWorldViewMatrix)
 Updates state of OCCT world-view transform. More...
 
void PushWorldViewState (const Handle< OpenGl_ShaderProgram > &theProgram) const
 Pushes current state of OCCT world-view transform to specified program. More...
 
void UpdateClippingState ()
 Updates state of OCCT clipping planes. More...
 
void RevertClippingState ()
 Reverts state of OCCT clipping planes. More...
 
void PushClippingState (const Handle< OpenGl_ShaderProgram > &theProgram) const
 Pushes current state of OCCT clipping planes to specified program. More...
 
void PushState (const Handle< OpenGl_ShaderProgram > &theProgram) const
 Pushes current state of OCCT graphics parameters to specified program. More...
 
void SetContext (OpenGl_Context *theCtx)
 Overwrites context. More...
 
bool IsSameContext (OpenGl_Context *theCtx) const
 Returns true when provided context is the same as used one by shader manager. More...
 
void SetShadingModel (const Graphic3d_TypeOfShadingModel theModel)
 Sets shading model. More...
 
void SetLastView (const OpenGl_View *theLastView)
 Sets last view manger used with. Helps to handle matrix states in multi-view configurations. More...
 
bool IsSameView (const OpenGl_View *theView) const
 Returns true when provided view is the same as cached one. More...
 
- Public Member Functions inherited from Standard_Transient
 Standard_Transient ()
 Empty constructor. More...
 
 Standard_Transient (const Standard_Transient &)
 Copy constructor – does nothing. More...
 
Standard_Transientoperator= (const Standard_Transient &)
 Assignment operator, needed to avoid copying reference counter. More...
 
virtual ~Standard_Transient ()
 Destructor must be virtual. More...
 
virtual void Delete () const
 Memory deallocator for transient classes. More...
 
virtual const opencascade::handle< Standard_Type > & DynamicType () const
 Returns a type descriptor about this object. More...
 
Standard_Boolean IsInstance (const opencascade::handle< Standard_Type > &theType) const
 Returns a true value if this is an instance of Type. More...
 
Standard_Boolean IsInstance (const Standard_CString theTypeName) const
 Returns a true value if this is an instance of TypeName. More...
 
Standard_Boolean IsKind (const opencascade::handle< Standard_Type > &theType) const
 Returns true if this is an instance of Type or an instance of any class that inherits from Type. Note that multiple inheritance is not supported by OCCT RTTI mechanism. More...
 
Standard_Boolean IsKind (const Standard_CString theTypeName) const
 Returns true if this is an instance of TypeName or an instance of any class that inherits from TypeName. Note that multiple inheritance is not supported by OCCT RTTI mechanism. More...
 
Standard_TransientThis () const
 Returns non-const pointer to this object (like const_cast). For protection against creating handle to objects allocated in stack or call from constructor, it will raise exception Standard_ProgramError if reference counter is zero. More...
 
Standard_Integer GetRefCount () const
 Get the reference counter of this object. More...
 
void IncrementRefCounter () const
 Increments the reference counter of this object. More...
 
Standard_Integer DecrementRefCounter () const
 Decrements the reference counter of this object; returns the decremented value. More...
 

Protected Member Functions

Standard_Integer getProgramBits (const Handle< OpenGl_Texture > &theTexture, const Standard_Boolean theHasVertColor, const Standard_Boolean theEnableEnvMap=Standard_False)
 Define program bits. More...
 
Handle< OpenGl_ShaderProgram > & getStdProgram (const Standard_Boolean theToLightOn, const Standard_Integer theBits)
 Prepare standard GLSL program. More...
 
TCollection_AsciiString pointSpriteAlphaSrc (const Standard_Integer theBits)
 Prepare standard GLSL program for accessing point sprite alpha. More...
 
TCollection_AsciiString pointSpriteShadingSrc (const TCollection_AsciiString theBaseColorSrc, const Standard_Integer theBits)
 Prepare standard GLSL program for computing point sprite shading. More...
 
Standard_Boolean prepareStdProgramFont ()
 Prepare standard GLSL program for textured font. More...
 
Standard_Boolean prepareStdProgramFboBlit ()
 Prepare standard GLSL program for FBO blit operation. More...
 
Standard_Boolean prepareStdProgramFlat (Handle< OpenGl_ShaderProgram > &theProgram, const Standard_Integer theBits)
 Prepare standard GLSL program without lighting. More...
 
Standard_Boolean prepareStdProgramLight (Handle< OpenGl_ShaderProgram > &theProgram, const Standard_Integer theBits)
 Prepare standard GLSL program with lighting. More...
 
Standard_Boolean prepareStdProgramGouraud (Handle< OpenGl_ShaderProgram > &theProgram, const Standard_Integer theBits)
 Prepare standard GLSL program with per-vertex lighting. More...
 
Standard_Boolean prepareStdProgramPhong (Handle< OpenGl_ShaderProgram > &theProgram, const Standard_Integer theBits)
 Prepare standard GLSL program with per-pixel lighting. More...
 
TCollection_AsciiString stdComputeLighting (const Standard_Boolean theHasVertColor)
 Define computeLighting GLSL function depending on current lights configuration. More...
 
Standard_Boolean bindProgramWithState (const Handle< OpenGl_ShaderProgram > &theProgram)
 Bind specified program to current context and apply state. More...
 
void switchLightPrograms ()
 Set pointer myLightPrograms to active lighting programs set from myMapOfLightPrograms. More...
 
Standard_Boolean prepareStdProgramStereo (Handle< OpenGl_ShaderProgram > &theProgram, const Graphic3d_StereoMode theStereoMode)
 Prepare standard GLSL program for stereoscopic image. More...
 

Protected Attributes

Graphic3d_TypeOfShadingModel myShadingModel
 lighting shading model More...
 
OpenGl_ShaderProgramList myProgramList
 The list of shader programs. More...
 
Handle< OpenGl_SetOfShaderProgramsmyLightPrograms
 pointer to active lighting programs matrix More...
 
OpenGl_SetOfShaderPrograms myFlatPrograms
 programs matrix without lighting More...
 
Handle< OpenGl_ShaderProgrammyFontProgram
 standard program for textured text More...
 
Handle< OpenGl_ShaderProgrammyBlitProgram
 standard program for FBO blit emulation More...
 
OpenGl_MapOfShaderPrograms myMapOfLightPrograms
 map of lighting programs depending on shading model and lights configuration More...
 
Handle< OpenGl_ShaderProgrammyStereoPrograms [Graphic3d_StereoMode_NB]
 standard stereo programs More...
 
OpenGl_ContextmyContext
 OpenGL context. More...
 
OpenGl_ProjectionState myProjectionState
 State of OCCT projection transformation. More...
 
OpenGl_ModelWorldState myModelWorldState
 State of OCCT model-world transformation. More...
 
OpenGl_WorldViewState myWorldViewState
 State of OCCT world-view transformation. More...
 
OpenGl_ClippingState myClippingState
 State of OCCT clipping planes. More...
 
OpenGl_LightSourceState myLightSourceState
 State of OCCT light sources. More...
 
gp_XYZ myLocalOrigin
 local camera transformation More...
 
Standard_Boolean myHasLocalOrigin
 flag indicating that local camera transformation has been set More...
 
OpenGl_ShaderLightType myLightTypeArray [OpenGLMaxLights]
 
OpenGl_ShaderLightParameters myLightParamsArray [OpenGLMaxLights]
 

Additional Inherited Members

- Public Types inherited from Standard_Transient
typedef void base_type
 Returns a type descriptor about this object. More...
 
- Static Public Member Functions inherited from Standard_Transient
static const char * get_type_name ()
 Returns a type descriptor about this object. More...
 
static const opencascade::handle< Standard_Type > & get_type_descriptor ()
 Returns type descriptor of Standard_Transient class. More...
 

Detailed Description

This class is responsible for managing shader programs.

Constructor & Destructor Documentation

OpenGl_ShaderManager::OpenGl_ShaderManager ( OpenGl_Context theContext)

Creates new empty shader manager.

virtual OpenGl_ShaderManager::~OpenGl_ShaderManager ( )
virtual

Releases resources of shader manager.

Member Function Documentation

Standard_Boolean OpenGl_ShaderManager::BindFaceProgram ( const Handle< OpenGl_Texture > &  theTexture,
const Standard_Boolean  theToLightOn,
const Standard_Boolean  theHasVertColor,
const Standard_Boolean  theEnableEnvMap,
const Handle< OpenGl_ShaderProgram > &  theCustomProgram 
)
inline

Bind program for filled primitives rendering.

Standard_Boolean OpenGl_ShaderManager::BindFboBlitProgram ( )
inline

Bind program for FBO blit operation.

Standard_Boolean OpenGl_ShaderManager::BindFontProgram ( const Handle< OpenGl_ShaderProgram > &  theCustomProgram)
inline

Bind program for rendering alpha-textured font.

Standard_Boolean OpenGl_ShaderManager::BindLineProgram ( const Handle< OpenGl_Texture > &  theTexture,
const Standard_Boolean  theStipple,
const Standard_Boolean  theToLightOn,
const Standard_Boolean  theHasVertColor,
const Handle< OpenGl_ShaderProgram > &  theCustomProgram 
)
inline

Bind program for line rendering.

Standard_Boolean OpenGl_ShaderManager::BindMarkerProgram ( const Handle< OpenGl_Texture > &  theTexture,
const Standard_Boolean  theToLightOn,
const Standard_Boolean  theHasVertColor,
const Handle< OpenGl_ShaderProgram > &  theCustomProgram 
)
inline

Bind program for point rendering.

Standard_Boolean OpenGl_ShaderManager::bindProgramWithState ( const Handle< OpenGl_ShaderProgram > &  theProgram)
protected

Bind specified program to current context and apply state.

Standard_Boolean OpenGl_ShaderManager::BindStereoProgram ( const Graphic3d_StereoMode  theStereoMode)
inline

Bind program for rendering stereoscopic image.

void OpenGl_ShaderManager::clear ( )

Release all resources.

Standard_Boolean OpenGl_ShaderManager::Create ( const Handle< Graphic3d_ShaderProgram > &  theProxy,
TCollection_AsciiString theShareKey,
Handle< OpenGl_ShaderProgram > &  theProgram 
)

Creates new shader program or re-use shared instance.

Parameters
theProxy[IN] program definition
theShareKey[OUT] sharing key
theProgram[OUT] OpenGL program
Returns
true on success
Standard_Integer OpenGl_ShaderManager::getProgramBits ( const Handle< OpenGl_Texture > &  theTexture,
const Standard_Boolean  theHasVertColor,
const Standard_Boolean  theEnableEnvMap = Standard_False 
)
inlineprotected

Define program bits.

Handle< OpenGl_ShaderProgram >& OpenGl_ShaderManager::getStdProgram ( const Standard_Boolean  theToLightOn,
const Standard_Integer  theBits 
)
inlineprotected

Prepare standard GLSL program.

Standard_Boolean OpenGl_ShaderManager::IsEmpty ( ) const

Returns true if no program objects are registered in the manager.

bool OpenGl_ShaderManager::IsSameContext ( OpenGl_Context theCtx) const
inline

Returns true when provided context is the same as used one by shader manager.

bool OpenGl_ShaderManager::IsSameView ( const OpenGl_View theView) const
inline

Returns true when provided view is the same as cached one.

const OpenGl_LightSourceState& OpenGl_ShaderManager::LightSourceState ( ) const

Returns current state of OCCT light sources.

const gp_XYZ& OpenGl_ShaderManager::LocalOrigin ( ) const
inline

Return local camera transformation.

const OpenGl_ModelWorldState& OpenGl_ShaderManager::ModelWorldState ( ) const

Returns current state of OCCT model-world transform.

TCollection_AsciiString OpenGl_ShaderManager::pointSpriteAlphaSrc ( const Standard_Integer  theBits)
protected

Prepare standard GLSL program for accessing point sprite alpha.

TCollection_AsciiString OpenGl_ShaderManager::pointSpriteShadingSrc ( const TCollection_AsciiString  theBaseColorSrc,
const Standard_Integer  theBits 
)
protected

Prepare standard GLSL program for computing point sprite shading.

Standard_Boolean OpenGl_ShaderManager::prepareStdProgramFboBlit ( )
protected

Prepare standard GLSL program for FBO blit operation.

Standard_Boolean OpenGl_ShaderManager::prepareStdProgramFlat ( Handle< OpenGl_ShaderProgram > &  theProgram,
const Standard_Integer  theBits 
)
protected

Prepare standard GLSL program without lighting.

Standard_Boolean OpenGl_ShaderManager::prepareStdProgramFont ( )
protected

Prepare standard GLSL program for textured font.

Standard_Boolean OpenGl_ShaderManager::prepareStdProgramGouraud ( Handle< OpenGl_ShaderProgram > &  theProgram,
const Standard_Integer  theBits 
)
protected

Prepare standard GLSL program with per-vertex lighting.

Standard_Boolean OpenGl_ShaderManager::prepareStdProgramLight ( Handle< OpenGl_ShaderProgram > &  theProgram,
const Standard_Integer  theBits 
)
inlineprotected

Prepare standard GLSL program with lighting.

Standard_Boolean OpenGl_ShaderManager::prepareStdProgramPhong ( Handle< OpenGl_ShaderProgram > &  theProgram,
const Standard_Integer  theBits 
)
protected

Prepare standard GLSL program with per-pixel lighting.

Standard_Boolean OpenGl_ShaderManager::prepareStdProgramStereo ( Handle< OpenGl_ShaderProgram > &  theProgram,
const Graphic3d_StereoMode  theStereoMode 
)
protected

Prepare standard GLSL program for stereoscopic image.

const OpenGl_ProjectionState& OpenGl_ShaderManager::ProjectionState ( ) const

Returns current state of OCCT projection transform.

void OpenGl_ShaderManager::PushClippingState ( const Handle< OpenGl_ShaderProgram > &  theProgram) const

Pushes current state of OCCT clipping planes to specified program.

void OpenGl_ShaderManager::PushLightSourceState ( const Handle< OpenGl_ShaderProgram > &  theProgram) const

Pushes current state of OCCT light sources to specified program.

void OpenGl_ShaderManager::PushModelWorldState ( const Handle< OpenGl_ShaderProgram > &  theProgram) const

Pushes current state of OCCT model-world transform to specified program.

void OpenGl_ShaderManager::PushProjectionState ( const Handle< OpenGl_ShaderProgram > &  theProgram) const

Pushes current state of OCCT projection transform to specified program.

void OpenGl_ShaderManager::PushState ( const Handle< OpenGl_ShaderProgram > &  theProgram) const

Pushes current state of OCCT graphics parameters to specified program.

void OpenGl_ShaderManager::PushWorldViewState ( const Handle< OpenGl_ShaderProgram > &  theProgram) const

Pushes current state of OCCT world-view transform to specified program.

void OpenGl_ShaderManager::RevertClippingState ( )

Reverts state of OCCT clipping planes.

void OpenGl_ShaderManager::SetContext ( OpenGl_Context theCtx)
inline

Overwrites context.

void OpenGl_ShaderManager::SetLastView ( const OpenGl_View theLastView)
inline

Sets last view manger used with. Helps to handle matrix states in multi-view configurations.

void OpenGl_ShaderManager::SetLocalOrigin ( const gp_XYZ theOrigin)
inline

Setup local camera transformation for compensating float precision issues.

void OpenGl_ShaderManager::SetShadingModel ( const Graphic3d_TypeOfShadingModel  theModel)

Sets shading model.

const OpenGl_ShaderProgramList& OpenGl_ShaderManager::ShaderPrograms ( ) const

Returns list of registered shader programs.

TCollection_AsciiString OpenGl_ShaderManager::stdComputeLighting ( const Standard_Boolean  theHasVertColor)
protected

Define computeLighting GLSL function depending on current lights configuration.

Parameters
theHasVertColorflag to use getVertColor() instead of Ambient and Diffuse components of active material
void OpenGl_ShaderManager::switchLightPrograms ( )
protected

Set pointer myLightPrograms to active lighting programs set from myMapOfLightPrograms.

void OpenGl_ShaderManager::Unregister ( TCollection_AsciiString theShareKey,
Handle< OpenGl_ShaderProgram > &  theProgram 
)

Unregisters specified shader program.

void OpenGl_ShaderManager::UpdateClippingState ( )

Updates state of OCCT clipping planes.

void OpenGl_ShaderManager::UpdateLightSourceState ( )

Invalidate state of OCCT light sources.

void OpenGl_ShaderManager::UpdateLightSourceStateTo ( const OpenGl_ListOfLight theLights)

Updates state of OCCT light sources.

void OpenGl_ShaderManager::UpdateModelWorldStateTo ( const OpenGl_Mat4 theModelWorldMatrix)

Updates state of OCCT model-world transform.

void OpenGl_ShaderManager::UpdateProjectionStateTo ( const OpenGl_Mat4 theProjectionMatrix)

Updates state of OCCT projection transform.

void OpenGl_ShaderManager::UpdateWorldViewStateTo ( const OpenGl_Mat4 theWorldViewMatrix)

Updates state of OCCT world-view transform.

const OpenGl_WorldViewState& OpenGl_ShaderManager::WorldViewState ( ) const

Returns current state of OCCT world-view transform.

Field Documentation

Handle< OpenGl_ShaderProgram > OpenGl_ShaderManager::myBlitProgram
protected

standard program for FBO blit emulation

OpenGl_ClippingState OpenGl_ShaderManager::myClippingState
protected

State of OCCT clipping planes.

OpenGl_Context* OpenGl_ShaderManager::myContext
protected

OpenGL context.

OpenGl_SetOfShaderPrograms OpenGl_ShaderManager::myFlatPrograms
protected

programs matrix without lighting

Handle< OpenGl_ShaderProgram > OpenGl_ShaderManager::myFontProgram
protected

standard program for textured text

Standard_Boolean OpenGl_ShaderManager::myHasLocalOrigin
protected

flag indicating that local camera transformation has been set

OpenGl_ShaderLightParameters OpenGl_ShaderManager::myLightParamsArray[OpenGLMaxLights]
mutableprotected
Handle< OpenGl_SetOfShaderPrograms > OpenGl_ShaderManager::myLightPrograms
protected

pointer to active lighting programs matrix

OpenGl_LightSourceState OpenGl_ShaderManager::myLightSourceState
protected

State of OCCT light sources.

OpenGl_ShaderLightType OpenGl_ShaderManager::myLightTypeArray[OpenGLMaxLights]
mutableprotected
gp_XYZ OpenGl_ShaderManager::myLocalOrigin
protected

local camera transformation

OpenGl_MapOfShaderPrograms OpenGl_ShaderManager::myMapOfLightPrograms
protected

map of lighting programs depending on shading model and lights configuration

OpenGl_ModelWorldState OpenGl_ShaderManager::myModelWorldState
protected

State of OCCT model-world transformation.

OpenGl_ShaderProgramList OpenGl_ShaderManager::myProgramList
protected

The list of shader programs.

OpenGl_ProjectionState OpenGl_ShaderManager::myProjectionState
protected

State of OCCT projection transformation.

Graphic3d_TypeOfShadingModel OpenGl_ShaderManager::myShadingModel
protected

lighting shading model

Handle< OpenGl_ShaderProgram > OpenGl_ShaderManager::myStereoPrograms[Graphic3d_StereoMode_NB]
protected

standard stereo programs

OpenGl_WorldViewState OpenGl_ShaderManager::myWorldViewState
protected

State of OCCT world-view transformation.


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