Open CASCADE Technology Reference Manual 8.0.0
Loading...
Searching...
No Matches
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.
 
 ~Graphic3d_ShaderManager () override
 Releases resources of shader manager.
 
bool IsGapiGreaterEqual (int theVerMajor, int theVerMinor) const
 
int GapiVersionMajor () const
 Return GAPI version major number.
 
int GapiVersionMinor () const
 Return GAPI version minor number.
 
void SetGapiVersion (int theVerMajor, int theVerMinor)
 Return GAPI version major number.
 
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).
 
void SetUseRedAlpha (bool theUseRedAlpha)
 Set if RED channel should be used instead of ALPHA for single-channel textures.
 
bool HasFlatShading () const
 Return flag indicating flat shading usage; TRUE by default.
 
bool ToReverseDFdxSign () const
 Return flag indicating flat shading should reverse normal flag; FALSE by default.
 
void SetFlatShading (bool theToUse, bool theToReverseSign)
 Set flag indicating flat shading usage.
 
bool ToEmulateDepthClamp () const
 Return TRUE if depth clamping should be emulated by GLSL program; TRUE by default.
 
void SetEmulateDepthClamp (bool theToEmulate)
 Set if depth clamping should be emulated by GLSL program.
 
bool HasGlslExtension (Graphic3d_GlslExtension theExt) const
 Return TRUE if specified extension is available.
 
void EnableGlslExtension (Graphic3d_GlslExtension theExt, bool theToEnable=true)
 Set if specified extension is available or not.
 
- Public Member Functions inherited from Standard_Transient
 Standard_Transient ()
 Empty constructor.
 
 Standard_Transient (const Standard_Transient &)
 Copy constructor – does nothing.
 
Standard_Transientoperator= (const Standard_Transient &)
 Assignment operator, needed to avoid copying reference counter.
 
virtual ~Standard_Transient ()=default
 Destructor must be virtual.
 
virtual const opencascade::handle< Standard_Type > & DynamicType () const
 Returns a type descriptor about this object.
 
bool IsInstance (const opencascade::handle< Standard_Type > &theType) const
 Returns a true value if this is an instance of Type.
 
bool IsInstance (const char *const theTypeName) const
 Returns a true value if this is an instance of TypeName.
 
bool 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.
 
bool IsKind (const char *const 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.
 
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.
 
int GetRefCount () const noexcept
 Get the reference counter of this object.
 
void IncrementRefCounter () noexcept
 Increments the reference counter of this object. Uses relaxed memory ordering since incrementing only requires atomicity, not synchronization with other memory operations.
 
int DecrementRefCounter () noexcept
 Decrements the reference counter of this object; returns the decremented value. Uses release ordering for the decrement to ensure all writes to the object are visible before the count reaches zero. An acquire fence is added only when the count reaches zero, ensuring proper synchronization before deletion. This is more efficient than using acq_rel for every decrement.
 
virtual void Delete () const
 Memory deallocator for transient classes.
 

Protected Member Functions

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

Protected Attributes

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

Additional Inherited Members

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

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()

Graphic3d_ShaderManager::~Graphic3d_ShaderManager ( )
override

Releases resources of shader manager.

Member Function Documentation

◆ defaultGlslVersion()

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

Prepare GLSL version header.

Parameters
[in]

out] theProgram program to set version header

Parameters
[in]theNameprogram id suffix
[in]theBitsprogram bits
[in]theUsesDerivatesprogram uses standard derivatives functions or not
Returns
filtered program bits with unsupported features disabled

◆ defaultOitGlslVersion()

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

Prepare GLSL version header for OIT composition programs.

Parameters
[in]

out] theProgram program to set version header

Parameters
[in]theNameprogram id suffix
[in]theMsaamultisampling flag

◆ EnableGlslExtension()

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

Set if specified extension is available or not.

◆ GapiVersionMajor()

int Graphic3d_ShaderManager::GapiVersionMajor ( ) const
inline

Return GAPI version major number.

◆ GapiVersionMinor()

int Graphic3d_ShaderManager::GapiVersionMinor ( ) const
inline

Return GAPI version minor number.

◆ genLightKey()

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

Generate map key for light sources configuration.

Parameters
[in]theLightslist of light sources
[in]theHasShadowMapflag indicating shadow maps usage

◆ getBgCubeMapProgram()

occ::handle< Graphic3d_ShaderProgram > Graphic3d_ShaderManager::getBgCubeMapProgram ( ) const
protected

Generates shader program to render environment cubemap as background.

◆ getBgSkydomeProgram()

occ::handle< Graphic3d_ShaderProgram > Graphic3d_ShaderManager::getBgSkydomeProgram ( ) const
protected

Generates shader program to render skydome background.

◆ getColoredQuadProgram()

occ::handle< Graphic3d_ShaderProgram > Graphic3d_ShaderManager::getColoredQuadProgram ( ) const
protected

Generates shader program to render correctly colored quad.

◆ getGridProgram()

occ::handle< Graphic3d_ShaderProgram > Graphic3d_ShaderManager::getGridProgram ( ) const
protected

Generates shader program to render a GPU grid on an arbitrary plane. Uses a screen-space triangle unprojected to world rays and ray-plane intersection driven by uniforms uPlaneOrigin / uPlaneX / uPlaneY / uPlaneN.

◆ getPBREnvBakingProgram()

occ::handle< Graphic3d_ShaderProgram > Graphic3d_ShaderManager::getPBREnvBakingProgram ( int theIndex) const
protected

Prepare GLSL source for IBL generation used in PBR pipeline.

◆ getStdProgramBoundBox()

occ::handle< Graphic3d_ShaderProgram > Graphic3d_ShaderManager::getStdProgramBoundBox ( ) const
protected

Prepare standard GLSL program for bounding box.

◆ getStdProgramFboBlit()

occ::handle< Graphic3d_ShaderProgram > Graphic3d_ShaderManager::getStdProgramFboBlit ( int theNbSamples,
bool theIsFallback_sRGB ) const
protected

Prepare standard GLSL program for FBO blit operation.

◆ getStdProgramFont()

occ::handle< Graphic3d_ShaderProgram > Graphic3d_ShaderManager::getStdProgramFont ( ) const
protected

Prepare standard GLSL program for textured font.

◆ getStdProgramGouraud()

occ::handle< Graphic3d_ShaderProgram > Graphic3d_ShaderManager::getStdProgramGouraud ( const occ::handle< Graphic3d_LightSet > & theLights,
int theBits ) const
protected

Prepare standard GLSL program with per-vertex lighting.

Parameters
[in]theLightslist of light sources
[in]theBitsprogram bits

◆ getStdProgramOitCompositing()

occ::handle< Graphic3d_ShaderProgram > Graphic3d_ShaderManager::getStdProgramOitCompositing ( bool theMsaa) const
protected

Prepare standard GLSL programs for OIT compositing operation.

◆ getStdProgramOitDepthPeelingBlend()

occ::handle< Graphic3d_ShaderProgram > Graphic3d_ShaderManager::getStdProgramOitDepthPeelingBlend ( bool theMsaa) const
protected

Prepare standard GLSL programs for OIT Depth Peeling blend operation.

◆ getStdProgramOitDepthPeelingFlush()

occ::handle< Graphic3d_ShaderProgram > Graphic3d_ShaderManager::getStdProgramOitDepthPeelingFlush ( bool theMsaa) const
protected

Prepare standard GLSL programs for OIT Depth Peeling flush operation.

◆ getStdProgramPhong()

occ::handle< Graphic3d_ShaderProgram > Graphic3d_ShaderManager::getStdProgramPhong ( const occ::handle< Graphic3d_LightSet > & theLights,
const int theBits,
const bool theIsFlatNormal,
const bool theIsPBR,
const int theNbShadowMaps ) const
protected

Prepare standard GLSL program with per-pixel lighting.

Parameters
[in]theLightslist of light sources
[in]theBitsprogram bits
[in]theIsFlatNormalwhen TRUE, the Vertex normals will be ignored and Face normal will be computed instead
[in]theIsPBRwhen TRUE, the PBR pipeline will be activated
[in]theNbShadowMapsnumber of shadow maps

◆ getStdProgramStereo()

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

Prepare standard GLSL program for stereoscopic image.

◆ getStdProgramUnlit()

occ::handle< Graphic3d_ShaderProgram > Graphic3d_ShaderManager::getStdProgramUnlit ( int theBits,
bool theIsOutline = false ) const
protected

Prepare standard GLSL program without lighting.

Parameters
[in]theBitsprogram bits
[in]theIsOutlinedraw 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 ( int theVerMajor,
int theVerMinor ) const
inline
Returns
true if detected GL version is greater or equal to requested one.

◆ pointSpriteAlphaSrc()

TCollection_AsciiString Graphic3d_ShaderManager::pointSpriteAlphaSrc ( int theBits) const
protected

Prepare standard GLSL program for accessing point sprite alpha.

◆ pointSpriteShadingSrc()

TCollection_AsciiString Graphic3d_ShaderManager::pointSpriteShadingSrc ( const TCollection_AsciiString & theBaseColorSrc,
int 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 ( int theVerMajor,
int 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 ( int & theNbLights,
const occ::handle< Graphic3d_LightSet > & theLights,
bool theHasVertColor,
bool theIsPBR,
bool theHasTexColor,
int theNbShadowMaps ) const
protected

Define computeLighting GLSL function depending on current lights configuration.

Parameters
[out]theNbLightsnumber of defined light sources
[in]theLightslight sources list
[in]theHasVertColorflag to use getVertColor() instead of Ambient and Diffuse components of active material
[in]theIsPBRflag to activate PBR pipeline
[in]theHasTexColorflag to include color texturing
[in]theNbShadowMapsflag 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

NCollection_Vec2<int> Graphic3d_ShaderManager::myGapiVersion
protected

GAPI version major/minor number pair.

◆ myGlslExtensions

bool Graphic3d_ShaderManager::myGlslExtensions[Graphic3d_GlslExtension_NB]
protected

◆ myHasFlatShading

bool Graphic3d_ShaderManager::myHasFlatShading
protected

flag indicating flat shading usage

◆ mySetPointSize

bool Graphic3d_ShaderManager::mySetPointSize
protected

always set gl_PointSize variable

◆ mySRgbState

bool Graphic3d_ShaderManager::mySRgbState
protected

track sRGB state

◆ myToEmulateDepthClamp

bool Graphic3d_ShaderManager::myToEmulateDepthClamp
protected

emulate depth clamping in GLSL program

◆ myToReverseDFdxSign

bool Graphic3d_ShaderManager::myToReverseDFdxSign
protected

flag to reverse flat shading normal (workaround)

◆ myUseRedAlpha

bool 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: