Open CASCADE Technology  7.7.0
Public Member Functions | Protected Member Functions | Protected Attributes

Graphic3d_ShaderManager Class Reference

This class is responsible for generation of shader programs. More...

#include <Graphic3d_ShaderManager.hxx>

Inheritance diagram for Graphic3d_ShaderManager:
Inheritance graph
[legend]

Public Member Functions

 Graphic3d_ShaderManager (Aspect_GraphicsLibrary theGapi)
 Creates new empty shader manager. More...
 
virtual ~Graphic3d_ShaderManager ()
 Releases resources of shader manager. More...
 
bool IsGapiGreaterEqual (Standard_Integer theVerMajor, Standard_Integer theVerMinor) const
 
Standard_Integer GapiVersionMajor () const
 Return GAPI version major number. More...
 
Standard_Integer GapiVersionMinor () const
 Return GAPI version minor number. More...
 
void SetGapiVersion (Standard_Integer theVerMajor, Standard_Integer theVerMinor)
 Return GAPI version major number. More...
 
bool UseRedAlpha () const
 Return TRUE if RED channel should be used instead of ALPHA for single-channel textures (e.g. GAPI supports only GL_RED textures and not GL_ALPHA). More...
 
void SetUseRedAlpha (bool theUseRedAlpha)
 Set if RED channel should be used instead of ALPHA for single-channel textures. More...
 
bool HasFlatShading () const
 Return flag indicating flat shading usage; TRUE by default. More...
 
bool ToReverseDFdxSign () const
 Return flag indicating flat shading should reverse normal flag; FALSE by default. More...
 
void SetFlatShading (bool theToUse, bool theToReverseSign)
 Set flag indicating flat shading usage. More...
 
bool ToEmulateDepthClamp () const
 Return TRUE if depth clamping should be emulated by GLSL program; TRUE by default. More...
 
void SetEmulateDepthClamp (bool theToEmulate)
 Set if depth clamping should be emulated by GLSL program. More...
 
bool HasGlslExtension (Graphic3d_GlslExtension theExt) const
 Return TRUE if specified extension is available. More...
 
void EnableGlslExtension (Graphic3d_GlslExtension theExt, bool theToEnable=true)
 Set if specified extension is available or not. 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

TCollection_AsciiString genLightKey (const Handle< Graphic3d_LightSet > &theLights, const bool theHasShadowMap) const
 Generate map key for light sources configuration. More...
 
Handle< Graphic3d_ShaderProgramgetStdProgramFont () const
 Prepare standard GLSL program for textured font. More...
 
Handle< Graphic3d_ShaderProgramgetStdProgramUnlit (Standard_Integer theBits, Standard_Boolean theIsOutline=false) const
 Prepare standard GLSL program without lighting. More...
 
Handle< Graphic3d_ShaderProgramgetStdProgramGouraud (const Handle< Graphic3d_LightSet > &theLights, Standard_Integer theBits) const
 Prepare standard GLSL program with per-vertex lighting. More...
 
Handle< Graphic3d_ShaderProgramgetStdProgramPhong (const Handle< Graphic3d_LightSet > &theLights, const Standard_Integer theBits, const Standard_Boolean theIsFlatNormal, const Standard_Boolean theIsPBR, const Standard_Integer theNbShadowMaps) const
 Prepare standard GLSL program with per-pixel lighting. More...
 
Handle< Graphic3d_ShaderProgramgetStdProgramBoundBox () const
 Prepare standard GLSL program for bounding box. More...
 
Handle< Graphic3d_ShaderProgramgetBgCubeMapProgram () const
 Generates shader program to render environment cubemap as background. More...
 
Handle< Graphic3d_ShaderProgramgetBgSkydomeProgram () const
 Generates shader program to render skydome background. More...
 
Handle< Graphic3d_ShaderProgramgetColoredQuadProgram () const
 Generates shader program to render correctly colored quad. More...
 
Handle< Graphic3d_ShaderProgramgetPBREnvBakingProgram (Standard_Integer theIndex) const
 Prepare GLSL source for IBL generation used in PBR pipeline. More...
 
Handle< Graphic3d_ShaderProgramgetStdProgramFboBlit (Standard_Integer theNbSamples, Standard_Boolean theIsFallback_sRGB) const
 Prepare standard GLSL program for FBO blit operation. More...
 
Handle< Graphic3d_ShaderProgramgetStdProgramStereo (Graphic3d_StereoMode theStereoMode) const
 Prepare standard GLSL program for stereoscopic image. More...
 
Handle< Graphic3d_ShaderProgramgetStdProgramOitCompositing (Standard_Boolean theMsaa) const
 Prepare standard GLSL programs for OIT compositing operation. More...
 
Handle< Graphic3d_ShaderProgramgetStdProgramOitDepthPeelingBlend (Standard_Boolean theMsaa) const
 Prepare standard GLSL programs for OIT Depth Peeling blend operation. More...
 
Handle< Graphic3d_ShaderProgramgetStdProgramOitDepthPeelingFlush (Standard_Boolean theMsaa) const
 Prepare standard GLSL programs for OIT Depth Peeling flush operation. More...
 
bool hasGlslBitwiseOps () const
 Return TRUE if bitwise operations can be used in GLSL program. More...
 
Standard_Integer defaultGlslVersion (const Handle< Graphic3d_ShaderProgram > &theProgram, const TCollection_AsciiString &theName, Standard_Integer theBits, bool theUsesDerivates=false) const
 Prepare GLSL version header. More...
 
void defaultOitGlslVersion (const Handle< Graphic3d_ShaderProgram > &theProgram, const TCollection_AsciiString &theName, bool theMsaa) const
 Prepare GLSL version header for OIT composition programs. More...
 
TCollection_AsciiString pointSpriteAlphaSrc (Standard_Integer theBits) const
 Prepare standard GLSL program for accessing point sprite alpha. More...
 
TCollection_AsciiString pointSpriteShadingSrc (const TCollection_AsciiString &theBaseColorSrc, Standard_Integer theBits) const
 Prepare standard GLSL program for computing point sprite shading. More...
 
TCollection_AsciiString stdComputeLighting (Standard_Integer &theNbLights, const Handle< Graphic3d_LightSet > &theLights, Standard_Boolean theHasVertColor, Standard_Boolean theIsPBR, Standard_Boolean theHasTexColor, Standard_Integer theNbShadowMaps) const
 Define computeLighting GLSL function depending on current lights configuration. More...
 

Protected Attributes

Aspect_GraphicsLibrary myGapi
 GAPI name. More...
 
Graphic3d_Vec2i myGapiVersion
 GAPI version major/minor number pair. More...
 
Standard_Boolean myGlslExtensions [Graphic3d_GlslExtension_NB]
 
Standard_Boolean myHasFlatShading
 flag indicating flat shading usage More...
 
Standard_Boolean myToReverseDFdxSign
 flag to reverse flat shading normal (workaround) More...
 
Standard_Boolean mySetPointSize
 always set gl_PointSize variable More...
 
Standard_Boolean myUseRedAlpha
 use RED channel instead of ALPHA (e.g. GAPI supports only GL_RED textures and not GL_ALPHA) More...
 
Standard_Boolean myToEmulateDepthClamp
 emulate depth clamping in GLSL program More...
 
Standard_Boolean mySRgbState
 track sRGB state More...
 

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 generation of shader programs.

Constructor & Destructor Documentation

◆ Graphic3d_ShaderManager()

Graphic3d_ShaderManager::Graphic3d_ShaderManager ( Aspect_GraphicsLibrary  theGapi)

Creates new empty shader manager.

◆ ~Graphic3d_ShaderManager()

virtual Graphic3d_ShaderManager::~Graphic3d_ShaderManager ( )
virtual

Releases resources of shader manager.

Member Function Documentation

◆ defaultGlslVersion()

Standard_Integer Graphic3d_ShaderManager::defaultGlslVersion ( const Handle< Graphic3d_ShaderProgram > &  theProgram,
const TCollection_AsciiString theName,
Standard_Integer  theBits,
bool  theUsesDerivates = false 
) const
protected

Prepare GLSL version header.

Parameters
theProgram[in] [out] program to set version header
theName[in] program id suffix
theBits[in] program bits
theUsesDerivates[in] program uses standard derivatives functions or not
Returns
filtered program bits with unsupported features disabled

◆ defaultOitGlslVersion()

void Graphic3d_ShaderManager::defaultOitGlslVersion ( const Handle< Graphic3d_ShaderProgram > &  theProgram,
const TCollection_AsciiString theName,
bool  theMsaa 
) const
protected

Prepare GLSL version header for OIT composition programs.

Parameters
theProgram[in] [out] program to set version header
theName[in] program id suffix
theMsaa[in] multisampling flag

◆ EnableGlslExtension()

void Graphic3d_ShaderManager::EnableGlslExtension ( Graphic3d_GlslExtension  theExt,
bool  theToEnable = true 
)
inline

Set if specified extension is available or not.

◆ GapiVersionMajor()

Standard_Integer Graphic3d_ShaderManager::GapiVersionMajor ( ) const
inline

Return GAPI version major number.

◆ GapiVersionMinor()

Standard_Integer Graphic3d_ShaderManager::GapiVersionMinor ( ) const
inline

Return GAPI version minor number.

◆ genLightKey()

TCollection_AsciiString Graphic3d_ShaderManager::genLightKey ( const Handle< Graphic3d_LightSet > &  theLights,
const bool  theHasShadowMap 
) const
protected

Generate map key for light sources configuration.

Parameters
theLights[in] list of light sources
theHasShadowMap[in] flag indicating shadow maps usage

◆ getBgCubeMapProgram()

Handle< Graphic3d_ShaderProgram > Graphic3d_ShaderManager::getBgCubeMapProgram ( ) const
protected

Generates shader program to render environment cubemap as background.

◆ getBgSkydomeProgram()

Handle< Graphic3d_ShaderProgram > Graphic3d_ShaderManager::getBgSkydomeProgram ( ) const
protected

Generates shader program to render skydome background.

◆ getColoredQuadProgram()

Handle< Graphic3d_ShaderProgram > Graphic3d_ShaderManager::getColoredQuadProgram ( ) const
protected

Generates shader program to render correctly colored quad.

◆ getPBREnvBakingProgram()

Handle< Graphic3d_ShaderProgram > Graphic3d_ShaderManager::getPBREnvBakingProgram ( Standard_Integer  theIndex) const
protected

Prepare GLSL source for IBL generation used in PBR pipeline.

◆ getStdProgramBoundBox()

Handle< Graphic3d_ShaderProgram > Graphic3d_ShaderManager::getStdProgramBoundBox ( ) const
protected

Prepare standard GLSL program for bounding box.

◆ getStdProgramFboBlit()

Handle< Graphic3d_ShaderProgram > Graphic3d_ShaderManager::getStdProgramFboBlit ( Standard_Integer  theNbSamples,
Standard_Boolean  theIsFallback_sRGB 
) const
protected

Prepare standard GLSL program for FBO blit operation.

◆ getStdProgramFont()

Handle< Graphic3d_ShaderProgram > Graphic3d_ShaderManager::getStdProgramFont ( ) const
protected

Prepare standard GLSL program for textured font.

◆ getStdProgramGouraud()

Handle< Graphic3d_ShaderProgram > Graphic3d_ShaderManager::getStdProgramGouraud ( const Handle< Graphic3d_LightSet > &  theLights,
Standard_Integer  theBits 
) const
protected

Prepare standard GLSL program with per-vertex lighting.

Parameters
theLights[in] list of light sources
theBits[in] program bits

◆ getStdProgramOitCompositing()

Handle< Graphic3d_ShaderProgram > Graphic3d_ShaderManager::getStdProgramOitCompositing ( Standard_Boolean  theMsaa) const
protected

Prepare standard GLSL programs for OIT compositing operation.

◆ getStdProgramOitDepthPeelingBlend()

Handle< Graphic3d_ShaderProgram > Graphic3d_ShaderManager::getStdProgramOitDepthPeelingBlend ( Standard_Boolean  theMsaa) const
protected

Prepare standard GLSL programs for OIT Depth Peeling blend operation.

◆ getStdProgramOitDepthPeelingFlush()

Handle< Graphic3d_ShaderProgram > Graphic3d_ShaderManager::getStdProgramOitDepthPeelingFlush ( Standard_Boolean  theMsaa) const
protected

Prepare standard GLSL programs for OIT Depth Peeling flush operation.

◆ getStdProgramPhong()

Handle< Graphic3d_ShaderProgram > Graphic3d_ShaderManager::getStdProgramPhong ( const Handle< Graphic3d_LightSet > &  theLights,
const Standard_Integer  theBits,
const Standard_Boolean  theIsFlatNormal,
const Standard_Boolean  theIsPBR,
const Standard_Integer  theNbShadowMaps 
) const
protected

Prepare standard GLSL program with per-pixel lighting.

Parameters
theLights[in] list of light sources
theBits[in] program bits
theIsFlatNormal[in] when TRUE, the Vertex normals will be ignored and Face normal will be computed instead
theIsPBR[in] when TRUE, the PBR pipeline will be activated
theNbShadowMaps[in] number of shadow maps

◆ getStdProgramStereo()

Handle< Graphic3d_ShaderProgram > Graphic3d_ShaderManager::getStdProgramStereo ( Graphic3d_StereoMode  theStereoMode) const
protected

Prepare standard GLSL program for stereoscopic image.

◆ getStdProgramUnlit()

Handle< Graphic3d_ShaderProgram > Graphic3d_ShaderManager::getStdProgramUnlit ( Standard_Integer  theBits,
Standard_Boolean  theIsOutline = false 
) const
protected

Prepare standard GLSL program without lighting.

Parameters
theBits[in] program bits
theIsOutline[in] draw silhouette

◆ HasFlatShading()

bool Graphic3d_ShaderManager::HasFlatShading ( ) const
inline

Return flag indicating flat shading usage; TRUE by default.

◆ hasGlslBitwiseOps()

bool Graphic3d_ShaderManager::hasGlslBitwiseOps ( ) const
protected

Return TRUE if bitwise operations can be used in GLSL program.

◆ HasGlslExtension()

bool Graphic3d_ShaderManager::HasGlslExtension ( Graphic3d_GlslExtension  theExt) const
inline

Return TRUE if specified extension is available.

◆ IsGapiGreaterEqual()

bool Graphic3d_ShaderManager::IsGapiGreaterEqual ( Standard_Integer  theVerMajor,
Standard_Integer  theVerMinor 
) const
inline
Returns
true if detected GL version is greater or equal to requested one.

◆ pointSpriteAlphaSrc()

TCollection_AsciiString Graphic3d_ShaderManager::pointSpriteAlphaSrc ( Standard_Integer  theBits) const
protected

Prepare standard GLSL program for accessing point sprite alpha.

◆ pointSpriteShadingSrc()

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

Prepare standard GLSL program for computing point sprite shading.

◆ SetEmulateDepthClamp()

void Graphic3d_ShaderManager::SetEmulateDepthClamp ( bool  theToEmulate)
inline

Set if depth clamping should be emulated by GLSL program.

◆ SetFlatShading()

void Graphic3d_ShaderManager::SetFlatShading ( bool  theToUse,
bool  theToReverseSign 
)
inline

Set flag indicating flat shading usage.

◆ SetGapiVersion()

void Graphic3d_ShaderManager::SetGapiVersion ( Standard_Integer  theVerMajor,
Standard_Integer  theVerMinor 
)
inline

Return GAPI version major number.

◆ SetUseRedAlpha()

void Graphic3d_ShaderManager::SetUseRedAlpha ( bool  theUseRedAlpha)
inline

Set if RED channel should be used instead of ALPHA for single-channel textures.

◆ stdComputeLighting()

TCollection_AsciiString Graphic3d_ShaderManager::stdComputeLighting ( Standard_Integer theNbLights,
const Handle< Graphic3d_LightSet > &  theLights,
Standard_Boolean  theHasVertColor,
Standard_Boolean  theIsPBR,
Standard_Boolean  theHasTexColor,
Standard_Integer  theNbShadowMaps 
) const
protected

Define computeLighting GLSL function depending on current lights configuration.

Parameters
theNbLights[out] number of defined light sources
theLights[in] light sources list
theHasVertColor[in] flag to use getVertColor() instead of Ambient and Diffuse components of active material
theIsPBR[in] flag to activate PBR pipeline
theHasTexColor[in] flag to include color texturing
theNbShadowMaps[in] flag to include shadow map

◆ ToEmulateDepthClamp()

bool Graphic3d_ShaderManager::ToEmulateDepthClamp ( ) const
inline

Return TRUE if depth clamping should be emulated by GLSL program; TRUE by default.

◆ ToReverseDFdxSign()

bool Graphic3d_ShaderManager::ToReverseDFdxSign ( ) const
inline

Return flag indicating flat shading should reverse normal flag; FALSE by default.

◆ UseRedAlpha()

bool Graphic3d_ShaderManager::UseRedAlpha ( ) const
inline

Return TRUE if RED channel should be used instead of ALPHA for single-channel textures (e.g. GAPI supports only GL_RED textures and not GL_ALPHA).

Field Documentation

◆ myGapi

Aspect_GraphicsLibrary Graphic3d_ShaderManager::myGapi
protected

GAPI name.

◆ myGapiVersion

Graphic3d_Vec2i Graphic3d_ShaderManager::myGapiVersion
protected

GAPI version major/minor number pair.

◆ myGlslExtensions

Standard_Boolean Graphic3d_ShaderManager::myGlslExtensions[Graphic3d_GlslExtension_NB]
protected

◆ myHasFlatShading

Standard_Boolean Graphic3d_ShaderManager::myHasFlatShading
protected

flag indicating flat shading usage

◆ mySetPointSize

Standard_Boolean Graphic3d_ShaderManager::mySetPointSize
protected

always set gl_PointSize variable

◆ mySRgbState

Standard_Boolean Graphic3d_ShaderManager::mySRgbState
protected

track sRGB state

◆ myToEmulateDepthClamp

Standard_Boolean Graphic3d_ShaderManager::myToEmulateDepthClamp
protected

emulate depth clamping in GLSL program

◆ myToReverseDFdxSign

Standard_Boolean Graphic3d_ShaderManager::myToReverseDFdxSign
protected

flag to reverse flat shading normal (workaround)

◆ myUseRedAlpha

Standard_Boolean Graphic3d_ShaderManager::myUseRedAlpha
protected

use RED channel instead of ALPHA (e.g. GAPI supports only GL_RED textures and not GL_ALPHA)


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