Open CASCADE Technology Reference Manual 8.0.0
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | Static Public Attributes
Graphic3d_ShaderProgram Class Reference

List of shader objects. More...

#include <Graphic3d_ShaderProgram.hxx>

Inheritance diagram for Graphic3d_ShaderProgram:
Inheritance graph
[legend]

Public Member Functions

 Graphic3d_ShaderProgram ()
 Creates new empty program object.
 
 ~Graphic3d_ShaderProgram () override
 Releases resources of program object.
 
virtual bool IsDone () const
 Checks if the program object is valid or not.
 
const TCollection_AsciiStringGetId () const
 Returns unique ID used to manage resource in graphic driver.
 
void SetId (const TCollection_AsciiString &theId)
 Sets unique ID used to manage resource in graphic driver. WARNING! Graphic3d_ShaderProgram constructor generates a unique id for proper resource management; however if application overrides it, it is responsibility of application to avoid name collisions.
 
const TCollection_AsciiStringHeader () const
 Returns GLSL header (version code and extensions).
 
void SetHeader (const TCollection_AsciiString &theHeader)
 Setup GLSL header containing language version code and used extensions. Will be prepended to the very beginning of the source code. Example:
 
void AppendToHeader (const TCollection_AsciiString &theHeaderLine)
 Append line to GLSL header.
 
int NbLightsMax () const
 Return the length of array of light sources (THE_MAX_LIGHTS), to be used for initialization occLightSources. Default value is THE_MAX_LIGHTS_DEFAULT.
 
void SetNbLightsMax (int theNbLights)
 Specify the length of array of light sources (THE_MAX_LIGHTS).
 
int NbShadowMaps () const
 Return the length of array of shadow maps (THE_NB_SHADOWMAPS); 0 by default.
 
void SetNbShadowMaps (int theNbMaps)
 Specify the length of array of shadow maps (THE_NB_SHADOWMAPS).
 
int NbClipPlanesMax () const
 Return the length of array of clipping planes (THE_MAX_CLIP_PLANES), to be used for initialization occClipPlaneEquations. Default value is THE_MAX_CLIP_PLANES_DEFAULT.
 
void SetNbClipPlanesMax (int theNbPlanes)
 Specify the length of array of clipping planes (THE_MAX_CLIP_PLANES).
 
bool AttachShader (const occ::handle< Graphic3d_ShaderObject > &theShader)
 Attaches shader object to the program object.
 
bool DetachShader (const occ::handle< Graphic3d_ShaderObject > &theShader)
 Detaches shader object from the program object.
 
const NCollection_Sequence< occ::handle< Graphic3d_ShaderObject > > & ShaderObjects () const
 Returns list of attached shader objects.
 
const NCollection_Sequence< occ::handle< Graphic3d_ShaderVariable > > & Variables () const
 The list of currently pushed but not applied custom uniform variables. This list is automatically cleared after applying to GLSL program.
 
const NCollection_Sequence< occ::handle< Graphic3d_ShaderAttribute > > & VertexAttributes () const
 Return the list of custom vertex attributes.
 
void SetVertexAttributes (const NCollection_Sequence< occ::handle< Graphic3d_ShaderAttribute > > &theAttributes)
 Assign the list of custom vertex attributes. Should be done before GLSL program initialization.
 
int NbFragmentOutputs () const
 Returns the number (1+) of Fragment Shader outputs to be written to (more than 1 can be in case of multiple draw buffers); 1 by default.
 
void SetNbFragmentOutputs (const int theNbOutputs)
 Sets the number of Fragment Shader outputs to be written to. Should be done before GLSL program initialization.
 
bool HasAlphaTest () const
 Return true if Fragment Shader should perform alpha test; FALSE by default.
 
void SetAlphaTest (bool theAlphaTest)
 Set if Fragment Shader should perform alpha test. Note that this flag is designed for usage with - custom shader program may discard fragment regardless this flag.
 
bool HasDefaultSampler () const
 Return TRUE if standard program header should define default texture sampler occSampler0; TRUE by default for compatibility.
 
void SetDefaultSampler (bool theHasDefSampler)
 Set if standard program header should define default texture sampler occSampler0.
 
Graphic3d_RenderTransparentMethod OitOutput () const
 Return if Fragment Shader color should output to OIT buffers; OFF by default.
 
void SetOitOutput (Graphic3d_RenderTransparentMethod theOutput)
 Set if Fragment Shader color should output to OIT buffers. Note that weighted OIT also requires at least 2 Fragment Outputs (color + coverage), and Depth Peeling requires at least 3 Fragment Outputs (depth + front color + back color),.
 
bool IsPBR () const
 Return TRUE if standard program header should define functions and variables used in PBR pipeline. FALSE by default.
 
void SetPBR (bool theIsPBR)
 Sets whether standard program header should define functions and variables used in PBR pipeline.
 
int TextureSetBits () const
 Return texture units declared within the program,.
 
void SetTextureSetBits (int theBits)
 Set texture units declared within the program.
 
template<class T >
bool PushVariable (const TCollection_AsciiString &theName, const T &theValue)
 Pushes custom uniform variable to the program. The list of pushed variables is automatically cleared after applying to GLSL program. Thus after program recreation even unchanged uniforms should be pushed anew.
 
void ClearVariables ()
 Removes all custom uniform variables from the program.
 
bool PushVariableFloat (const TCollection_AsciiString &theName, const float theValue)
 Pushes float uniform.
 
bool PushVariableVec2 (const TCollection_AsciiString &theName, const NCollection_Vec2< float > &theValue)
 Pushes vec2 uniform.
 
bool PushVariableVec3 (const TCollection_AsciiString &theName, const NCollection_Vec3< float > &theValue)
 Pushes vec3 uniform.
 
bool PushVariableVec4 (const TCollection_AsciiString &theName, const NCollection_Vec4< float > &theValue)
 Pushes vec4 uniform.
 
bool PushVariableInt (const TCollection_AsciiString &theName, const int theValue)
 Pushes int uniform.
 
bool PushVariableVec2i (const TCollection_AsciiString &theName, const NCollection_Vec2< int > &theValue)
 Pushes vec2i uniform.
 
bool PushVariableVec3i (const TCollection_AsciiString &theName, const NCollection_Vec3< int > &theValue)
 Pushes vec3i uniform.
 
bool PushVariableVec4i (const TCollection_AsciiString &theName, const NCollection_Vec4< int > &theValue)
 Pushes vec4i uniform.
 
bool PushVariableMat3 (const TCollection_AsciiString &theName, const NCollection_Mat3< float > &theValue)
 Pushes mat3 uniform.
 
bool PushVariableMat4 (const TCollection_AsciiString &theName, const NCollection_Mat4< float > &theValue)
 Pushes mat4 uniform.
 
- 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.
 

Static Public Member Functions

static const TCollection_AsciiStringShadersFolder ()
 The path to GLSL programs determined from CSF_ShadersDirectory or CASROOT environment variables.
 
- 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.
 

Static Public Attributes

static const int THE_MAX_LIGHTS_DEFAULT = 8
 Default value of THE_MAX_LIGHTS macros within GLSL program (see Declarations.glsl).
 
static const int THE_MAX_CLIP_PLANES_DEFAULT = 8
 Default value of THE_MAX_CLIP_PLANES macros within GLSL program (see Declarations.glsl).
 
static const int THE_NB_FRAG_OUTPUTS = 1
 Default value of THE_NB_FRAG_OUTPUTS macros within GLSL program (see Declarations.glsl).
 

Additional Inherited Members

- Public Types inherited from Standard_Transient
typedef void base_type
 Returns a type descriptor about this object.
 

Detailed Description

List of shader objects.

List of custom uniform shader variables. List of custom vertex shader attributes This class is responsible for managing shader programs.

Constructor & Destructor Documentation

◆ Graphic3d_ShaderProgram()

Graphic3d_ShaderProgram::Graphic3d_ShaderProgram ( )

Creates new empty program object.

◆ ~Graphic3d_ShaderProgram()

Graphic3d_ShaderProgram::~Graphic3d_ShaderProgram ( )
override

Releases resources of program object.

Member Function Documentation

◆ AppendToHeader()

void Graphic3d_ShaderProgram::AppendToHeader ( const TCollection_AsciiString & theHeaderLine)
inline

Append line to GLSL header.

◆ AttachShader()

bool Graphic3d_ShaderProgram::AttachShader ( const occ::handle< Graphic3d_ShaderObject > & theShader)

Attaches shader object to the program object.

◆ ClearVariables()

void Graphic3d_ShaderProgram::ClearVariables ( )

Removes all custom uniform variables from the program.

◆ DetachShader()

bool Graphic3d_ShaderProgram::DetachShader ( const occ::handle< Graphic3d_ShaderObject > & theShader)

Detaches shader object from the program object.

◆ GetId()

const TCollection_AsciiString & Graphic3d_ShaderProgram::GetId ( ) const
inline

Returns unique ID used to manage resource in graphic driver.

◆ HasAlphaTest()

bool Graphic3d_ShaderProgram::HasAlphaTest ( ) const
inline

Return true if Fragment Shader should perform alpha test; FALSE by default.

◆ HasDefaultSampler()

bool Graphic3d_ShaderProgram::HasDefaultSampler ( ) const
inline

Return TRUE if standard program header should define default texture sampler occSampler0; TRUE by default for compatibility.

◆ Header()

const TCollection_AsciiString & Graphic3d_ShaderProgram::Header ( ) const
inline

Returns GLSL header (version code and extensions).

◆ IsDone()

virtual bool Graphic3d_ShaderProgram::IsDone ( ) const
virtual

Checks if the program object is valid or not.

◆ IsPBR()

bool Graphic3d_ShaderProgram::IsPBR ( ) const
inline

Return TRUE if standard program header should define functions and variables used in PBR pipeline. FALSE by default.

◆ NbClipPlanesMax()

int Graphic3d_ShaderProgram::NbClipPlanesMax ( ) const
inline

Return the length of array of clipping planes (THE_MAX_CLIP_PLANES), to be used for initialization occClipPlaneEquations. Default value is THE_MAX_CLIP_PLANES_DEFAULT.

◆ NbFragmentOutputs()

int Graphic3d_ShaderProgram::NbFragmentOutputs ( ) const
inline

Returns the number (1+) of Fragment Shader outputs to be written to (more than 1 can be in case of multiple draw buffers); 1 by default.

◆ NbLightsMax()

int Graphic3d_ShaderProgram::NbLightsMax ( ) const
inline

Return the length of array of light sources (THE_MAX_LIGHTS), to be used for initialization occLightSources. Default value is THE_MAX_LIGHTS_DEFAULT.

◆ NbShadowMaps()

int Graphic3d_ShaderProgram::NbShadowMaps ( ) const
inline

Return the length of array of shadow maps (THE_NB_SHADOWMAPS); 0 by default.

◆ OitOutput()

Graphic3d_RenderTransparentMethod Graphic3d_ShaderProgram::OitOutput ( ) const
inline

Return if Fragment Shader color should output to OIT buffers; OFF by default.

◆ PushVariable()

template<class T >
bool Graphic3d_ShaderProgram::PushVariable ( const TCollection_AsciiString & theName,
const T & theValue )
inline

Pushes custom uniform variable to the program. The list of pushed variables is automatically cleared after applying to GLSL program. Thus after program recreation even unchanged uniforms should be pushed anew.

◆ PushVariableFloat()

bool Graphic3d_ShaderProgram::PushVariableFloat ( const TCollection_AsciiString & theName,
const float theValue )
inline

Pushes float uniform.

◆ PushVariableInt()

bool Graphic3d_ShaderProgram::PushVariableInt ( const TCollection_AsciiString & theName,
const int theValue )
inline

Pushes int uniform.

◆ PushVariableMat3()

bool Graphic3d_ShaderProgram::PushVariableMat3 ( const TCollection_AsciiString & theName,
const NCollection_Mat3< float > & theValue )
inline

Pushes mat3 uniform.

◆ PushVariableMat4()

bool Graphic3d_ShaderProgram::PushVariableMat4 ( const TCollection_AsciiString & theName,
const NCollection_Mat4< float > & theValue )
inline

Pushes mat4 uniform.

◆ PushVariableVec2()

bool Graphic3d_ShaderProgram::PushVariableVec2 ( const TCollection_AsciiString & theName,
const NCollection_Vec2< float > & theValue )
inline

Pushes vec2 uniform.

◆ PushVariableVec2i()

bool Graphic3d_ShaderProgram::PushVariableVec2i ( const TCollection_AsciiString & theName,
const NCollection_Vec2< int > & theValue )
inline

Pushes vec2i uniform.

◆ PushVariableVec3()

bool Graphic3d_ShaderProgram::PushVariableVec3 ( const TCollection_AsciiString & theName,
const NCollection_Vec3< float > & theValue )
inline

Pushes vec3 uniform.

◆ PushVariableVec3i()

bool Graphic3d_ShaderProgram::PushVariableVec3i ( const TCollection_AsciiString & theName,
const NCollection_Vec3< int > & theValue )
inline

Pushes vec3i uniform.

◆ PushVariableVec4()

bool Graphic3d_ShaderProgram::PushVariableVec4 ( const TCollection_AsciiString & theName,
const NCollection_Vec4< float > & theValue )
inline

Pushes vec4 uniform.

◆ PushVariableVec4i()

bool Graphic3d_ShaderProgram::PushVariableVec4i ( const TCollection_AsciiString & theName,
const NCollection_Vec4< int > & theValue )
inline

Pushes vec4i uniform.

◆ SetAlphaTest()

void Graphic3d_ShaderProgram::SetAlphaTest ( bool theAlphaTest)
inline

Set if Fragment Shader should perform alpha test. Note that this flag is designed for usage with - custom shader program may discard fragment regardless this flag.

◆ SetDefaultSampler()

void Graphic3d_ShaderProgram::SetDefaultSampler ( bool theHasDefSampler)
inline

Set if standard program header should define default texture sampler occSampler0.

◆ SetHeader()

void Graphic3d_ShaderProgram::SetHeader ( const TCollection_AsciiString & theHeader)
inline

Setup GLSL header containing language version code and used extensions. Will be prepended to the very beginning of the source code. Example:

#version 300 es
#extension GL_ARB_bindless_texture : require

◆ SetId()

void Graphic3d_ShaderProgram::SetId ( const TCollection_AsciiString & theId)
inline

Sets unique ID used to manage resource in graphic driver. WARNING! Graphic3d_ShaderProgram constructor generates a unique id for proper resource management; however if application overrides it, it is responsibility of application to avoid name collisions.

◆ SetNbClipPlanesMax()

void Graphic3d_ShaderProgram::SetNbClipPlanesMax ( int theNbPlanes)
inline

Specify the length of array of clipping planes (THE_MAX_CLIP_PLANES).

◆ SetNbFragmentOutputs()

void Graphic3d_ShaderProgram::SetNbFragmentOutputs ( const int theNbOutputs)
inline

Sets the number of Fragment Shader outputs to be written to. Should be done before GLSL program initialization.

◆ SetNbLightsMax()

void Graphic3d_ShaderProgram::SetNbLightsMax ( int theNbLights)
inline

Specify the length of array of light sources (THE_MAX_LIGHTS).

◆ SetNbShadowMaps()

void Graphic3d_ShaderProgram::SetNbShadowMaps ( int theNbMaps)
inline

Specify the length of array of shadow maps (THE_NB_SHADOWMAPS).

◆ SetOitOutput()

void Graphic3d_ShaderProgram::SetOitOutput ( Graphic3d_RenderTransparentMethod theOutput)
inline

Set if Fragment Shader color should output to OIT buffers. Note that weighted OIT also requires at least 2 Fragment Outputs (color + coverage), and Depth Peeling requires at least 3 Fragment Outputs (depth + front color + back color),.

◆ SetPBR()

void Graphic3d_ShaderProgram::SetPBR ( bool theIsPBR)
inline

Sets whether standard program header should define functions and variables used in PBR pipeline.

◆ SetTextureSetBits()

void Graphic3d_ShaderProgram::SetTextureSetBits ( int theBits)
inline

Set texture units declared within the program.

◆ SetVertexAttributes()

void Graphic3d_ShaderProgram::SetVertexAttributes ( const NCollection_Sequence< occ::handle< Graphic3d_ShaderAttribute > > & theAttributes)

Assign the list of custom vertex attributes. Should be done before GLSL program initialization.

◆ ShaderObjects()

const NCollection_Sequence< occ::handle< Graphic3d_ShaderObject > > & Graphic3d_ShaderProgram::ShaderObjects ( ) const
inline

Returns list of attached shader objects.

◆ ShadersFolder()

static const TCollection_AsciiString & Graphic3d_ShaderProgram::ShadersFolder ( )
static

The path to GLSL programs determined from CSF_ShadersDirectory or CASROOT environment variables.

Returns
the root folder with default GLSL programs.

◆ TextureSetBits()

int Graphic3d_ShaderProgram::TextureSetBits ( ) const
inline

Return texture units declared within the program,.

See also
Graphic3d_TextureSetBits.

◆ Variables()

const NCollection_Sequence< occ::handle< Graphic3d_ShaderVariable > > & Graphic3d_ShaderProgram::Variables ( ) const
inline

The list of currently pushed but not applied custom uniform variables. This list is automatically cleared after applying to GLSL program.

◆ VertexAttributes()

const NCollection_Sequence< occ::handle< Graphic3d_ShaderAttribute > > & Graphic3d_ShaderProgram::VertexAttributes ( ) const
inline

Return the list of custom vertex attributes.

Field Documentation

◆ THE_MAX_CLIP_PLANES_DEFAULT

const int Graphic3d_ShaderProgram::THE_MAX_CLIP_PLANES_DEFAULT = 8
static

Default value of THE_MAX_CLIP_PLANES macros within GLSL program (see Declarations.glsl).

◆ THE_MAX_LIGHTS_DEFAULT

const int Graphic3d_ShaderProgram::THE_MAX_LIGHTS_DEFAULT = 8
static

Default value of THE_MAX_LIGHTS macros within GLSL program (see Declarations.glsl).

◆ THE_NB_FRAG_OUTPUTS

const int Graphic3d_ShaderProgram::THE_NB_FRAG_OUTPUTS = 1
static

Default value of THE_NB_FRAG_OUTPUTS macros within GLSL program (see Declarations.glsl).


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