Open CASCADE Technology 7.8.0
Public Member Functions | Static Public Member Functions | Static Public Attributes | Protected Member Functions | Protected Attributes | Static Protected Attributes
OpenGl_ShaderProgram Class Reference

Wrapper for OpenGL program object. More...

#include <OpenGl_ShaderProgram.hxx>

Inheritance diagram for OpenGl_ShaderProgram:
Inheritance graph
[legend]

Public Member Functions

 OpenGl_ShaderProgram (const Handle< Graphic3d_ShaderProgram > &theProxy=NULL, const TCollection_AsciiString &theId="")
 Creates uninitialized shader program.
 
virtual ~OpenGl_ShaderProgram ()
 Releases resources of shader program.
 
Standard_Boolean Create (const Handle< OpenGl_Context > &theCtx)
 Creates new empty shader program of specified type.
 
virtual void Release (OpenGl_Context *theCtx) override
 Destroys shader program.
 
virtual Standard_Size EstimatedDataSize () const override
 Returns estimated GPU memory usage - cannot be easily estimated.
 
Standard_Boolean AttachShader (const Handle< OpenGl_Context > &theCtx, const Handle< OpenGl_ShaderObject > &theShader)
 Attaches shader object to the program object.
 
Standard_Boolean DetachShader (const Handle< OpenGl_Context > &theCtx, const Handle< OpenGl_ShaderObject > &theShader)
 Detaches shader object to the program object.
 
Standard_Boolean Initialize (const Handle< OpenGl_Context > &theCtx, const Graphic3d_ShaderObjectList &theShaders)
 Initializes program object with the list of shader objects.
 
Standard_Boolean Link (const Handle< OpenGl_Context > &theCtx, bool theIsVerbose=true)
 Links the program object.
 
Standard_Boolean FetchInfoLog (const Handle< OpenGl_Context > &theCtx, TCollection_AsciiString &theLog)
 Fetches information log of the last link operation.
 
Standard_Boolean ApplyVariables (const Handle< OpenGl_Context > &theCtx)
 Fetches uniform variables from proxy shader program.
 
const Handle< Graphic3d_ShaderProgram > & Proxy () const
 
bool IsValid () const
 
GLuint ProgramId () const
 
Standard_Boolean HasTessellationStage () const
 Return TRUE if program defines tessellation stage.
 
Standard_Integer NbLightsMax () const
 Return the length of array of light sources (THE_MAX_LIGHTS), to be used for initialization occLightSources (OpenGl_OCC_LIGHT_SOURCE_PARAMS).
 
Standard_Integer NbShadowMaps () const
 Return the length of array of shadow maps (THE_NB_SHADOWMAPS); 0 by default.
 
Standard_Integer NbClipPlanesMax () const
 Return the length of array of clipping planes (THE_MAX_CLIP_PLANES), to be used for initialization occClipPlaneEquations (OpenGl_OCC_CLIP_PLANE_EQUATIONS) and occClipPlaneChains (OpenGl_OCC_CLIP_PLANE_CHAINS).
 
Standard_Integer NbFragmentOutputs () const
 Return the length of array of Fragment Shader outputs (THE_NB_FRAG_OUTPUTS), to be used for initialization occFragColorArray/occFragColorN.
 
Standard_Boolean HasAlphaTest () const
 Return true if Fragment Shader should perform alpha test; FALSE by default.
 
Graphic3d_RenderTransparentMethod OitOutput () const
 Return if Fragment Shader color should output the OIT values; OFF by default.
 
Standard_Integer TextureSetBits () const
 Return texture units declared within the program,.
 
OpenGl_ShaderUniformLocation GetUniformLocation (const Handle< OpenGl_Context > &theCtx, const GLchar *theName) const
 Returns location of the specific uniform variable.
 
GLint GetAttributeLocation (const Handle< OpenGl_Context > &theCtx, const GLchar *theName) const
 Returns index of the generic vertex attribute by variable name.
 
const OpenGl_ShaderUniformLocationGetStateLocation (OpenGl_StateVariable theVariable) const
 Returns location of the OCCT state uniform variable.
 
template<typename ValueType >
bool GetUniform (const Handle< OpenGl_Context > &theCtx, const GLchar *theName, ValueType &theValue) const
 Returns the value of the uniform variable from given name.
 
Standard_Boolean GetUniform (const Handle< OpenGl_Context > &theCtx, GLint theLocation, OpenGl_Vec4i &theValue) const
 Returns the value of the integer uniform variable. Wrapper for glGetUniformiv()
 
Standard_Boolean GetUniform (const Handle< OpenGl_Context > &theCtx, GLint theLocation, OpenGl_Vec4 &theValue) const
 Returns the value of the float uniform variable. Wrapper for glGetUniformfv()
 
template<typename ValueType >
bool GetAttribute (const Handle< OpenGl_Context > &theCtx, const GLchar *theName, ValueType &theValue) const
 Returns the vertex attribute from given name.
 
Standard_Boolean GetAttribute (const Handle< OpenGl_Context > &theCtx, GLint theIndex, OpenGl_Vec4i &theValue) const
 Returns the integer vertex attribute. Wrapper for glGetVertexAttribiv()
 
Standard_Boolean GetAttribute (const Handle< OpenGl_Context > &theCtx, GLint theIndex, OpenGl_Vec4 &theValue) const
 Returns the float vertex attribute. Wrapper for glGetVertexAttribfv()
 
Standard_Boolean SetAttributeName (const Handle< OpenGl_Context > &theCtx, GLint theIndex, const GLchar *theName)
 Wrapper for glBindAttribLocation()
 
template<typename ValueType >
bool SetAttribute (const Handle< OpenGl_Context > &theCtx, const GLchar *theName, const ValueType &theValue)
 Wrapper for glVertexAttrib*() for attribute with the given name.
 
Standard_Boolean SetAttribute (const Handle< OpenGl_Context > &theCtx, GLint theIndex, GLfloat theValue)
 Wrapper for glVertexAttrib1f()
 
Standard_Boolean SetAttribute (const Handle< OpenGl_Context > &theCtx, GLint theIndex, const OpenGl_Vec2 &theValue)
 Wrapper for glVertexAttrib2fv()
 
Standard_Boolean SetAttribute (const Handle< OpenGl_Context > &theCtx, GLint theIndex, const OpenGl_Vec3 &theValue)
 Wrapper for glVertexAttrib3fv()
 
Standard_Boolean SetAttribute (const Handle< OpenGl_Context > &theCtx, GLint theIndex, const OpenGl_Vec4 &theValue)
 Wrapper for glVertexAttrib4fv()
 
template<typename ValueType >
bool SetUniform (const Handle< OpenGl_Context > &theCtx, const GLchar *theName, const ValueType &theValue)
 Specifies the value of the uniform variable with given name.
 
Standard_Boolean SetUniform (const Handle< OpenGl_Context > &theCtx, GLint theLocation, GLint theValue)
 Specifies the value of the integer uniform variable. Wrapper for glUniform1i()
 
Standard_Boolean SetUniform (const Handle< OpenGl_Context > &theCtx, GLint theLocation, const OpenGl_Vec2i &theValue)
 Specifies the value of the integer uniform 2D vector. Wrapper for glUniform2iv()
 
Standard_Boolean SetUniform (const Handle< OpenGl_Context > &theCtx, GLint theLocation, const OpenGl_Vec3i &theValue)
 Specifies the value of the integer uniform 3D vector. Wrapper for glUniform3iv()
 
Standard_Boolean SetUniform (const Handle< OpenGl_Context > &theCtx, GLint theLocation, const OpenGl_Vec4i &theValue)
 Specifies the value of the integer uniform 4D vector. Wrapper for glUniform4iv()
 
Standard_Boolean SetUniform (const Handle< OpenGl_Context > &theCtx, GLint theLocation, const OpenGl_Vec2u &theValue)
 Specifies the value of the unsigned integer uniform 2D vector (uvec2). Wrapper for glUniform2uiv()
 
Standard_Boolean SetUniform (const Handle< OpenGl_Context > &theCtx, const GLchar *theName, const GLsizei theCount, const OpenGl_Vec2u *theValue)
 Specifies the value of the uvec2 uniform array Wrapper for glUniform2uiv()
 
Standard_Boolean SetUniform (const Handle< OpenGl_Context > &theCtx, GLint theLocation, const GLsizei theCount, const OpenGl_Vec2u *theValue)
 Specifies the value of the uvec2 uniform array Wrapper for glUniform2uiv()
 
Standard_Boolean SetUniform (const Handle< OpenGl_Context > &theCtx, GLint theLocation, GLfloat theValue)
 Specifies the value of the float uniform variable. Wrapper for glUniform1f()
 
Standard_Boolean SetUniform (const Handle< OpenGl_Context > &theCtx, GLint theLocation, const OpenGl_Vec2 &theValue)
 Specifies the value of the float uniform 2D vector. Wrapper for glUniform2fv()
 
Standard_Boolean SetUniform (const Handle< OpenGl_Context > &theCtx, GLint theLocation, const OpenGl_Vec3 &theValue)
 Specifies the value of the float uniform 3D vector. Wrapper for glUniform3fv()
 
Standard_Boolean SetUniform (const Handle< OpenGl_Context > &theCtx, GLint theLocation, const OpenGl_Vec4 &theValue)
 Specifies the value of the float uniform 4D vector. Wrapper for glUniform4fv()
 
Standard_Boolean SetUniform (const Handle< OpenGl_Context > &theCtx, GLint theLocation, GLuint theCount, const NCollection_Mat3< float > *theData)
 Specifies the value of the array of float uniform 3x3 matrices. Wrapper over glUniformMatrix3fv().
 
bool SetUniform (const Handle< OpenGl_Context > &theCtx, const GLchar *theName, const OpenGl_Mat4 &theValue, GLboolean theTranspose=GL_FALSE)
 Specifies the value of the float uniform 4x4 matrix. Wrapper for glUniformMatrix4fv()
 
Standard_Boolean SetUniform (const Handle< OpenGl_Context > &theCtx, GLint theLocation, const OpenGl_Mat4 &theValue, GLboolean theTranspose=GL_FALSE)
 Specifies the value of the float uniform 4x4 matrix. Wrapper for glUniformMatrix4fv()
 
Standard_Boolean SetUniform (const Handle< OpenGl_Context > &theCtx, GLint theLocation, GLuint theCount, const OpenGl_Mat4 *theData)
 Specifies the value of the array of float uniform 4x4 matrices. Wrapper over glUniformMatrix4fv().
 
Standard_Boolean SetUniform (const Handle< OpenGl_Context > &theCtx, GLint theLocation, GLuint theCount, const Standard_ShortReal *theData)
 Specifies the value of the float uniform array Wrapper over glUniform1fv()
 
Standard_Boolean SetUniform (const Handle< OpenGl_Context > &theCtx, GLint theLocation, GLuint theCount, const OpenGl_Vec2 *theData)
 Specifies the value of the float2 uniform array Wrapper over glUniform2fv()
 
Standard_Boolean SetUniform (const Handle< OpenGl_Context > &theCtx, GLint theLocation, GLuint theCount, const OpenGl_Vec3 *theData)
 Specifies the value of the float3 uniform array Wrapper over glUniform3fv()
 
Standard_Boolean SetUniform (const Handle< OpenGl_Context > &theCtx, GLint theLocation, GLuint theCount, const OpenGl_Vec4 *theData)
 Specifies the value of the float4 uniform array Wrapper over glUniform4fv()
 
Standard_Boolean SetUniform (const Handle< OpenGl_Context > &theCtx, GLint theLocation, GLuint theCount, const Standard_Integer *theData)
 Specifies the value of the integer uniform array Wrapper over glUniform1iv()
 
Standard_Boolean SetUniform (const Handle< OpenGl_Context > &theCtx, GLint theLocation, GLuint theCount, const OpenGl_Vec2i *theData)
 Specifies the value of the int2 uniform array Wrapper over glUniform2iv()
 
Standard_Boolean SetUniform (const Handle< OpenGl_Context > &theCtx, GLint theLocation, GLuint theCount, const OpenGl_Vec3i *theData)
 Specifies the value of the int3 uniform array Wrapper over glUniform3iv()
 
Standard_Boolean SetUniform (const Handle< OpenGl_Context > &theCtx, GLint theLocation, GLuint theCount, const OpenGl_Vec4i *theData)
 Specifies the value of the int4 uniform array Wrapper over glUniform4iv()
 
bool SetSampler (const Handle< OpenGl_Context > &theCtx, const GLchar *theName, const Graphic3d_TextureUnit theTextureUnit)
 Specifies the value of the sampler uniform variable.
 
Standard_Boolean SetSampler (const Handle< OpenGl_Context > &theCtx, GLint theLocation, const Graphic3d_TextureUnit theTextureUnit)
 Specifies the value of the sampler uniform variable.
 
Standard_Boolean UpdateDebugDump (const Handle< OpenGl_Context > &theCtx, const TCollection_AsciiString &theFolder="", Standard_Boolean theToBeautify=Standard_False, Standard_Boolean theToReset=Standard_False)
 Update the shader program from external files (per shader stage) in the following way: 1) If external file does not exist, then it will be created (current source code will be dumped, no recompilation) and FALSE will be returned. 2) If external file exists and it has the same timestamp as myDumpDate, nothing will be done and FALSE will be returned. 3) If external file exists and it has newer timestamp than myDumpDate, shader will be recompiled and relinked and TRUE will be returned.
 
- Public Member Functions inherited from OpenGl_NamedResource
 OpenGl_NamedResource (const TCollection_AsciiString &theId)
 Empty constructor.
 
const TCollection_AsciiStringResourceId () const
 Return resource name.
 
- Public Member Functions inherited from OpenGl_Resource
 OpenGl_Resource ()
 Empty constructor.
 
virtual ~OpenGl_Resource ()
 Destructor. Inheritors should call Clean (NULL) within it.
 
virtual void DumpJson (Standard_OStream &theOStream, Standard_Integer theDepth=-1) const
 Dumps the content of me into the stream.
 
- 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 ()
 Destructor must be virtual.
 
virtual const opencascade::handle< Standard_Type > & DynamicType () const
 Returns a type descriptor about this object.
 
Standard_Boolean IsInstance (const opencascade::handle< Standard_Type > &theType) const
 Returns a true value if this is an instance of Type.
 
Standard_Boolean IsInstance (const Standard_CString theTypeName) const
 Returns a true value if this is an instance of TypeName.
 
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.
 
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.
 
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.
 
Standard_Integer GetRefCount () const noexcept
 Get the reference counter of this object.
 
void IncrementRefCounter () noexcept
 Increments the reference counter of this object.
 
Standard_Integer DecrementRefCounter () noexcept
 Decrements the reference counter of this object; returns the decremented value.
 
virtual void Delete () const
 Memory deallocator for transient classes.
 

Static Public Member Functions

static bool compileShaderVerbose (const Handle< OpenGl_Context > &theCtx, const Handle< OpenGl_ShaderObject > &theShader, const TCollection_AsciiString &theSource, bool theToPrintSource=true)
 Wrapper for compiling shader object with verbose printing on error.
 
- 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 GLuint NO_PROGRAM = 0
 Non-valid shader name.
 
static const GLint INVALID_LOCATION = -1
 Invalid location of uniform/attribute variable.
 
static Standard_CString PredefinedKeywords [OpenGl_OCCT_NUMBER_OF_STATE_VARIABLES]
 List of pre-defined OCCT state uniform variables.
 

Protected Member Functions

bool Share ()
 Increments counter of users. Used by OpenGl_ShaderManager.
 
bool UnShare ()
 Decrements counter of users. Used by OpenGl_ShaderManager.
 
Standard_Boolean link (const Handle< OpenGl_Context > &theCtx)
 Links the program object.
 

Protected Attributes

GLuint myProgramID
 Handle of OpenGL shader program.
 
OpenGl_ShaderList myShaderObjects
 List of attached shader objects.
 
Handle< Graphic3d_ShaderProgrammyProxy
 Proxy shader program (from application layer)
 
Standard_Integer myShareCount
 program users count, initialized with 1 (already shared by one user)
 
Standard_Integer myNbLightsMax
 length of array of light sources (THE_MAX_LIGHTS)
 
Standard_Integer myNbShadowMaps
 length of array of shadow maps (THE_NB_SHADOWMAPS)
 
Standard_Integer myNbClipPlanesMax
 length of array of clipping planes (THE_MAX_CLIP_PLANES)
 
Standard_Integer myNbFragOutputs
 length of array of Fragment Shader outputs (THE_NB_FRAG_OUTPUTS)
 
Standard_Integer myTextureSetBits
 texture units declared within the program,
 
Graphic3d_RenderTransparentMethod myOitOutput
 flag indicating that Fragment Shader includes OIT outputs
 
Standard_Boolean myHasAlphaTest
 flag indicating that Fragment Shader should perform alpha-test
 
Standard_Boolean myHasTessShader
 flag indicating that program defines tessellation stage
 
Standard_Size myCurrentState [OpenGl_UniformStateType_NB]
 defines last modification for variables of each state type
 
OpenGl_ShaderUniformLocation myStateLocations [OpenGl_OCCT_NUMBER_OF_STATE_VARIABLES]
 Stores locations of OCCT state uniform variables.
 
- Protected Attributes inherited from OpenGl_NamedResource
TCollection_AsciiString myResourceId
 resource name
 

Static Protected Attributes

static OpenGl_VariableSetterSelector mySetterSelector
 

Additional Inherited Members

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

Detailed Description

Wrapper for OpenGL program object.

Constructor & Destructor Documentation

◆ OpenGl_ShaderProgram()

OpenGl_ShaderProgram::OpenGl_ShaderProgram ( const Handle< Graphic3d_ShaderProgram > &  theProxy = NULL,
const TCollection_AsciiString theId = "" 
)

Creates uninitialized shader program.

WARNING! This constructor is not intended to be called anywhere but from OpenGl_ShaderManager::Create(). Manager has been designed to synchronize camera position, lights definition and other aspects of the program implicitly, as well as sharing same program across rendering groups.

Program created outside the manager will be left detached from these routines, and them should be performed manually by caller.

This constructor has been made public to provide more flexibility to re-use OCCT OpenGL classes without OCCT Viewer itself. If this is not the case - create the program using shared OpenGl_ShaderManager instance instead.

◆ ~OpenGl_ShaderProgram()

virtual OpenGl_ShaderProgram::~OpenGl_ShaderProgram ( )
virtual

Releases resources of shader program.

Member Function Documentation

◆ ApplyVariables()

Standard_Boolean OpenGl_ShaderProgram::ApplyVariables ( const Handle< OpenGl_Context > &  theCtx)

Fetches uniform variables from proxy shader program.

◆ AttachShader()

Standard_Boolean OpenGl_ShaderProgram::AttachShader ( const Handle< OpenGl_Context > &  theCtx,
const Handle< OpenGl_ShaderObject > &  theShader 
)

Attaches shader object to the program object.

◆ compileShaderVerbose()

static bool OpenGl_ShaderProgram::compileShaderVerbose ( const Handle< OpenGl_Context > &  theCtx,
const Handle< OpenGl_ShaderObject > &  theShader,
const TCollection_AsciiString theSource,
bool  theToPrintSource = true 
)
static

Wrapper for compiling shader object with verbose printing on error.

◆ Create()

Standard_Boolean OpenGl_ShaderProgram::Create ( const Handle< OpenGl_Context > &  theCtx)

Creates new empty shader program of specified type.

◆ DetachShader()

Standard_Boolean OpenGl_ShaderProgram::DetachShader ( const Handle< OpenGl_Context > &  theCtx,
const Handle< OpenGl_ShaderObject > &  theShader 
)

Detaches shader object to the program object.

◆ EstimatedDataSize()

virtual Standard_Size OpenGl_ShaderProgram::EstimatedDataSize ( ) const
inlineoverridevirtual

Returns estimated GPU memory usage - cannot be easily estimated.

Implements OpenGl_Resource.

◆ FetchInfoLog()

Standard_Boolean OpenGl_ShaderProgram::FetchInfoLog ( const Handle< OpenGl_Context > &  theCtx,
TCollection_AsciiString theLog 
)

Fetches information log of the last link operation.

◆ GetAttribute() [1/3]

template<typename ValueType >
bool OpenGl_ShaderProgram::GetAttribute ( const Handle< OpenGl_Context > &  theCtx,
const GLchar theName,
ValueType &  theValue 
) const
inline

Returns the vertex attribute from given name.

◆ GetAttribute() [2/3]

Standard_Boolean OpenGl_ShaderProgram::GetAttribute ( const Handle< OpenGl_Context > &  theCtx,
GLint  theIndex,
OpenGl_Vec4 theValue 
) const

Returns the float vertex attribute. Wrapper for glGetVertexAttribfv()

◆ GetAttribute() [3/3]

Standard_Boolean OpenGl_ShaderProgram::GetAttribute ( const Handle< OpenGl_Context > &  theCtx,
GLint  theIndex,
OpenGl_Vec4i theValue 
) const

Returns the integer vertex attribute. Wrapper for glGetVertexAttribiv()

◆ GetAttributeLocation()

GLint OpenGl_ShaderProgram::GetAttributeLocation ( const Handle< OpenGl_Context > &  theCtx,
const GLchar theName 
) const

Returns index of the generic vertex attribute by variable name.

◆ GetStateLocation()

const OpenGl_ShaderUniformLocation & OpenGl_ShaderProgram::GetStateLocation ( OpenGl_StateVariable  theVariable) const
inline

Returns location of the OCCT state uniform variable.

◆ GetUniform() [1/3]

template<typename ValueType >
bool OpenGl_ShaderProgram::GetUniform ( const Handle< OpenGl_Context > &  theCtx,
const GLchar theName,
ValueType &  theValue 
) const
inline

Returns the value of the uniform variable from given name.

◆ GetUniform() [2/3]

Standard_Boolean OpenGl_ShaderProgram::GetUniform ( const Handle< OpenGl_Context > &  theCtx,
GLint  theLocation,
OpenGl_Vec4 theValue 
) const

Returns the value of the float uniform variable. Wrapper for glGetUniformfv()

◆ GetUniform() [3/3]

Standard_Boolean OpenGl_ShaderProgram::GetUniform ( const Handle< OpenGl_Context > &  theCtx,
GLint  theLocation,
OpenGl_Vec4i theValue 
) const

Returns the value of the integer uniform variable. Wrapper for glGetUniformiv()

◆ GetUniformLocation()

OpenGl_ShaderUniformLocation OpenGl_ShaderProgram::GetUniformLocation ( const Handle< OpenGl_Context > &  theCtx,
const GLchar theName 
) const

Returns location of the specific uniform variable.

◆ HasAlphaTest()

Standard_Boolean OpenGl_ShaderProgram::HasAlphaTest ( ) const
inline

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

◆ HasTessellationStage()

Standard_Boolean OpenGl_ShaderProgram::HasTessellationStage ( ) const
inline

Return TRUE if program defines tessellation stage.

◆ Initialize()

Standard_Boolean OpenGl_ShaderProgram::Initialize ( const Handle< OpenGl_Context > &  theCtx,
const Graphic3d_ShaderObjectList theShaders 
)

Initializes program object with the list of shader objects.

◆ IsValid()

bool OpenGl_ShaderProgram::IsValid ( ) const
inline
Returns
true if current object was initialized

◆ link()

Standard_Boolean OpenGl_ShaderProgram::link ( const Handle< OpenGl_Context > &  theCtx)
protected

Links the program object.

◆ Link()

Standard_Boolean OpenGl_ShaderProgram::Link ( const Handle< OpenGl_Context > &  theCtx,
bool  theIsVerbose = true 
)

Links the program object.

Parameters
theCtxbound OpenGL context
theIsVerboseflag to print log on error

◆ NbClipPlanesMax()

Standard_Integer OpenGl_ShaderProgram::NbClipPlanesMax ( ) const
inline

Return the length of array of clipping planes (THE_MAX_CLIP_PLANES), to be used for initialization occClipPlaneEquations (OpenGl_OCC_CLIP_PLANE_EQUATIONS) and occClipPlaneChains (OpenGl_OCC_CLIP_PLANE_CHAINS).

◆ NbFragmentOutputs()

Standard_Integer OpenGl_ShaderProgram::NbFragmentOutputs ( ) const
inline

Return the length of array of Fragment Shader outputs (THE_NB_FRAG_OUTPUTS), to be used for initialization occFragColorArray/occFragColorN.

◆ NbLightsMax()

Standard_Integer OpenGl_ShaderProgram::NbLightsMax ( ) const
inline

Return the length of array of light sources (THE_MAX_LIGHTS), to be used for initialization occLightSources (OpenGl_OCC_LIGHT_SOURCE_PARAMS).

◆ NbShadowMaps()

Standard_Integer OpenGl_ShaderProgram::NbShadowMaps ( ) const
inline

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

◆ OitOutput()

Graphic3d_RenderTransparentMethod OpenGl_ShaderProgram::OitOutput ( ) const
inline

Return if Fragment Shader color should output the OIT values; OFF by default.

◆ ProgramId()

GLuint OpenGl_ShaderProgram::ProgramId ( ) const
inline
Returns
program ID

◆ Proxy()

const Handle< Graphic3d_ShaderProgram > & OpenGl_ShaderProgram::Proxy ( ) const
inline
Returns
proxy shader program.

◆ Release()

virtual void OpenGl_ShaderProgram::Release ( OpenGl_Context theCtx)
overridevirtual

Destroys shader program.

Implements OpenGl_Resource.

◆ SetAttribute() [1/5]

template<typename ValueType >
bool OpenGl_ShaderProgram::SetAttribute ( const Handle< OpenGl_Context > &  theCtx,
const GLchar theName,
const ValueType &  theValue 
)
inline

Wrapper for glVertexAttrib*() for attribute with the given name.

◆ SetAttribute() [2/5]

Standard_Boolean OpenGl_ShaderProgram::SetAttribute ( const Handle< OpenGl_Context > &  theCtx,
GLint  theIndex,
const OpenGl_Vec2 theValue 
)

Wrapper for glVertexAttrib2fv()

◆ SetAttribute() [3/5]

Standard_Boolean OpenGl_ShaderProgram::SetAttribute ( const Handle< OpenGl_Context > &  theCtx,
GLint  theIndex,
const OpenGl_Vec3 theValue 
)

Wrapper for glVertexAttrib3fv()

◆ SetAttribute() [4/5]

Standard_Boolean OpenGl_ShaderProgram::SetAttribute ( const Handle< OpenGl_Context > &  theCtx,
GLint  theIndex,
const OpenGl_Vec4 theValue 
)

Wrapper for glVertexAttrib4fv()

◆ SetAttribute() [5/5]

Standard_Boolean OpenGl_ShaderProgram::SetAttribute ( const Handle< OpenGl_Context > &  theCtx,
GLint  theIndex,
GLfloat  theValue 
)

Wrapper for glVertexAttrib1f()

◆ SetAttributeName()

Standard_Boolean OpenGl_ShaderProgram::SetAttributeName ( const Handle< OpenGl_Context > &  theCtx,
GLint  theIndex,
const GLchar theName 
)

Wrapper for glBindAttribLocation()

◆ SetSampler() [1/2]

bool OpenGl_ShaderProgram::SetSampler ( const Handle< OpenGl_Context > &  theCtx,
const GLchar theName,
const Graphic3d_TextureUnit  theTextureUnit 
)
inline

Specifies the value of the sampler uniform variable.

◆ SetSampler() [2/2]

Standard_Boolean OpenGl_ShaderProgram::SetSampler ( const Handle< OpenGl_Context > &  theCtx,
GLint  theLocation,
const Graphic3d_TextureUnit  theTextureUnit 
)

Specifies the value of the sampler uniform variable.

◆ SetUniform() [1/24]

Standard_Boolean OpenGl_ShaderProgram::SetUniform ( const Handle< OpenGl_Context > &  theCtx,
const GLchar theName,
const GLsizei  theCount,
const OpenGl_Vec2u theValue 
)

Specifies the value of the uvec2 uniform array Wrapper for glUniform2uiv()

◆ SetUniform() [2/24]

bool OpenGl_ShaderProgram::SetUniform ( const Handle< OpenGl_Context > &  theCtx,
const GLchar theName,
const OpenGl_Mat4 theValue,
GLboolean  theTranspose = GL_FALSE 
)
inline

Specifies the value of the float uniform 4x4 matrix. Wrapper for glUniformMatrix4fv()

◆ SetUniform() [3/24]

template<typename ValueType >
bool OpenGl_ShaderProgram::SetUniform ( const Handle< OpenGl_Context > &  theCtx,
const GLchar theName,
const ValueType &  theValue 
)
inline

Specifies the value of the uniform variable with given name.

◆ SetUniform() [4/24]

Standard_Boolean OpenGl_ShaderProgram::SetUniform ( const Handle< OpenGl_Context > &  theCtx,
GLint  theLocation,
const GLsizei  theCount,
const OpenGl_Vec2u theValue 
)

Specifies the value of the uvec2 uniform array Wrapper for glUniform2uiv()

◆ SetUniform() [5/24]

Standard_Boolean OpenGl_ShaderProgram::SetUniform ( const Handle< OpenGl_Context > &  theCtx,
GLint  theLocation,
const OpenGl_Mat4 theValue,
GLboolean  theTranspose = GL_FALSE 
)

Specifies the value of the float uniform 4x4 matrix. Wrapper for glUniformMatrix4fv()

◆ SetUniform() [6/24]

Standard_Boolean OpenGl_ShaderProgram::SetUniform ( const Handle< OpenGl_Context > &  theCtx,
GLint  theLocation,
const OpenGl_Vec2 theValue 
)

Specifies the value of the float uniform 2D vector. Wrapper for glUniform2fv()

◆ SetUniform() [7/24]

Standard_Boolean OpenGl_ShaderProgram::SetUniform ( const Handle< OpenGl_Context > &  theCtx,
GLint  theLocation,
const OpenGl_Vec2i theValue 
)

Specifies the value of the integer uniform 2D vector. Wrapper for glUniform2iv()

◆ SetUniform() [8/24]

Standard_Boolean OpenGl_ShaderProgram::SetUniform ( const Handle< OpenGl_Context > &  theCtx,
GLint  theLocation,
const OpenGl_Vec2u theValue 
)

Specifies the value of the unsigned integer uniform 2D vector (uvec2). Wrapper for glUniform2uiv()

◆ SetUniform() [9/24]

Standard_Boolean OpenGl_ShaderProgram::SetUniform ( const Handle< OpenGl_Context > &  theCtx,
GLint  theLocation,
const OpenGl_Vec3 theValue 
)

Specifies the value of the float uniform 3D vector. Wrapper for glUniform3fv()

◆ SetUniform() [10/24]

Standard_Boolean OpenGl_ShaderProgram::SetUniform ( const Handle< OpenGl_Context > &  theCtx,
GLint  theLocation,
const OpenGl_Vec3i theValue 
)

Specifies the value of the integer uniform 3D vector. Wrapper for glUniform3iv()

◆ SetUniform() [11/24]

Standard_Boolean OpenGl_ShaderProgram::SetUniform ( const Handle< OpenGl_Context > &  theCtx,
GLint  theLocation,
const OpenGl_Vec4 theValue 
)

Specifies the value of the float uniform 4D vector. Wrapper for glUniform4fv()

◆ SetUniform() [12/24]

Standard_Boolean OpenGl_ShaderProgram::SetUniform ( const Handle< OpenGl_Context > &  theCtx,
GLint  theLocation,
const OpenGl_Vec4i theValue 
)

Specifies the value of the integer uniform 4D vector. Wrapper for glUniform4iv()

◆ SetUniform() [13/24]

Standard_Boolean OpenGl_ShaderProgram::SetUniform ( const Handle< OpenGl_Context > &  theCtx,
GLint  theLocation,
GLfloat  theValue 
)

Specifies the value of the float uniform variable. Wrapper for glUniform1f()

◆ SetUniform() [14/24]

Standard_Boolean OpenGl_ShaderProgram::SetUniform ( const Handle< OpenGl_Context > &  theCtx,
GLint  theLocation,
GLint  theValue 
)

Specifies the value of the integer uniform variable. Wrapper for glUniform1i()

◆ SetUniform() [15/24]

Standard_Boolean OpenGl_ShaderProgram::SetUniform ( const Handle< OpenGl_Context > &  theCtx,
GLint  theLocation,
GLuint  theCount,
const NCollection_Mat3< float > *  theData 
)

Specifies the value of the array of float uniform 3x3 matrices. Wrapper over glUniformMatrix3fv().

◆ SetUniform() [16/24]

Standard_Boolean OpenGl_ShaderProgram::SetUniform ( const Handle< OpenGl_Context > &  theCtx,
GLint  theLocation,
GLuint  theCount,
const OpenGl_Mat4 theData 
)

Specifies the value of the array of float uniform 4x4 matrices. Wrapper over glUniformMatrix4fv().

◆ SetUniform() [17/24]

Standard_Boolean OpenGl_ShaderProgram::SetUniform ( const Handle< OpenGl_Context > &  theCtx,
GLint  theLocation,
GLuint  theCount,
const OpenGl_Vec2 theData 
)

Specifies the value of the float2 uniform array Wrapper over glUniform2fv()

◆ SetUniform() [18/24]

Standard_Boolean OpenGl_ShaderProgram::SetUniform ( const Handle< OpenGl_Context > &  theCtx,
GLint  theLocation,
GLuint  theCount,
const OpenGl_Vec2i theData 
)

Specifies the value of the int2 uniform array Wrapper over glUniform2iv()

◆ SetUniform() [19/24]

Standard_Boolean OpenGl_ShaderProgram::SetUniform ( const Handle< OpenGl_Context > &  theCtx,
GLint  theLocation,
GLuint  theCount,
const OpenGl_Vec3 theData 
)

Specifies the value of the float3 uniform array Wrapper over glUniform3fv()

◆ SetUniform() [20/24]

Standard_Boolean OpenGl_ShaderProgram::SetUniform ( const Handle< OpenGl_Context > &  theCtx,
GLint  theLocation,
GLuint  theCount,
const OpenGl_Vec3i theData 
)

Specifies the value of the int3 uniform array Wrapper over glUniform3iv()

◆ SetUniform() [21/24]

Standard_Boolean OpenGl_ShaderProgram::SetUniform ( const Handle< OpenGl_Context > &  theCtx,
GLint  theLocation,
GLuint  theCount,
const OpenGl_Vec4 theData 
)

Specifies the value of the float4 uniform array Wrapper over glUniform4fv()

◆ SetUniform() [22/24]

Standard_Boolean OpenGl_ShaderProgram::SetUniform ( const Handle< OpenGl_Context > &  theCtx,
GLint  theLocation,
GLuint  theCount,
const OpenGl_Vec4i theData 
)

Specifies the value of the int4 uniform array Wrapper over glUniform4iv()

◆ SetUniform() [23/24]

Standard_Boolean OpenGl_ShaderProgram::SetUniform ( const Handle< OpenGl_Context > &  theCtx,
GLint  theLocation,
GLuint  theCount,
const Standard_Integer theData 
)

Specifies the value of the integer uniform array Wrapper over glUniform1iv()

◆ SetUniform() [24/24]

Standard_Boolean OpenGl_ShaderProgram::SetUniform ( const Handle< OpenGl_Context > &  theCtx,
GLint  theLocation,
GLuint  theCount,
const Standard_ShortReal theData 
)

Specifies the value of the float uniform array Wrapper over glUniform1fv()

◆ Share()

bool OpenGl_ShaderProgram::Share ( )
inlineprotected

Increments counter of users. Used by OpenGl_ShaderManager.

Returns
true when resource has been restored from delayed release queue

◆ TextureSetBits()

Standard_Integer OpenGl_ShaderProgram::TextureSetBits ( ) const
inline

Return texture units declared within the program,.

See also
Graphic3d_TextureSetBits.

◆ UnShare()

bool OpenGl_ShaderProgram::UnShare ( )
inlineprotected

Decrements counter of users. Used by OpenGl_ShaderManager.

Returns
true when there are no more users of this program has been left

◆ UpdateDebugDump()

Standard_Boolean OpenGl_ShaderProgram::UpdateDebugDump ( const Handle< OpenGl_Context > &  theCtx,
const TCollection_AsciiString theFolder = "",
Standard_Boolean  theToBeautify = Standard_False,
Standard_Boolean  theToReset = Standard_False 
)

Update the shader program from external files (per shader stage) in the following way: 1) If external file does not exist, then it will be created (current source code will be dumped, no recompilation) and FALSE will be returned. 2) If external file exists and it has the same timestamp as myDumpDate, nothing will be done and FALSE will be returned. 3) If external file exists and it has newer timestamp than myDumpDate, shader will be recompiled and relinked and TRUE will be returned.

Parameters
theCtxOpenGL context bound to this working thread
theFolderfolder to store files; when unspecified, $CSF_ShadersDirectoryDump or current folder will be used instead
theToBeautifyflag improving formatting (add extra newlines)
theToResetwhen TRUE, existing dumps will be overridden

Field Documentation

◆ INVALID_LOCATION

const GLint OpenGl_ShaderProgram::INVALID_LOCATION = -1
static

Invalid location of uniform/attribute variable.

◆ myCurrentState

Standard_Size OpenGl_ShaderProgram::myCurrentState[OpenGl_UniformStateType_NB]
protected

defines last modification for variables of each state type

◆ myHasAlphaTest

Standard_Boolean OpenGl_ShaderProgram::myHasAlphaTest
protected

flag indicating that Fragment Shader should perform alpha-test

◆ myHasTessShader

Standard_Boolean OpenGl_ShaderProgram::myHasTessShader
protected

flag indicating that program defines tessellation stage

◆ myNbClipPlanesMax

Standard_Integer OpenGl_ShaderProgram::myNbClipPlanesMax
protected

length of array of clipping planes (THE_MAX_CLIP_PLANES)

◆ myNbFragOutputs

Standard_Integer OpenGl_ShaderProgram::myNbFragOutputs
protected

length of array of Fragment Shader outputs (THE_NB_FRAG_OUTPUTS)

◆ myNbLightsMax

Standard_Integer OpenGl_ShaderProgram::myNbLightsMax
protected

length of array of light sources (THE_MAX_LIGHTS)

◆ myNbShadowMaps

Standard_Integer OpenGl_ShaderProgram::myNbShadowMaps
protected

length of array of shadow maps (THE_NB_SHADOWMAPS)

◆ myOitOutput

Graphic3d_RenderTransparentMethod OpenGl_ShaderProgram::myOitOutput
protected

flag indicating that Fragment Shader includes OIT outputs

◆ myProgramID

GLuint OpenGl_ShaderProgram::myProgramID
protected

Handle of OpenGL shader program.

◆ myProxy

Handle< Graphic3d_ShaderProgram > OpenGl_ShaderProgram::myProxy
protected

Proxy shader program (from application layer)

◆ mySetterSelector

OpenGl_VariableSetterSelector OpenGl_ShaderProgram::mySetterSelector
staticprotected

◆ myShaderObjects

OpenGl_ShaderList OpenGl_ShaderProgram::myShaderObjects
protected

List of attached shader objects.

◆ myShareCount

Standard_Integer OpenGl_ShaderProgram::myShareCount
protected

program users count, initialized with 1 (already shared by one user)

◆ myStateLocations

OpenGl_ShaderUniformLocation OpenGl_ShaderProgram::myStateLocations[OpenGl_OCCT_NUMBER_OF_STATE_VARIABLES]
protected

Stores locations of OCCT state uniform variables.

◆ myTextureSetBits

Standard_Integer OpenGl_ShaderProgram::myTextureSetBits
protected

texture units declared within the program,

See also
Graphic3d_TextureSetBits

◆ NO_PROGRAM

const GLuint OpenGl_ShaderProgram::NO_PROGRAM = 0
static

Non-valid shader name.

◆ PredefinedKeywords

Standard_CString OpenGl_ShaderProgram::PredefinedKeywords[OpenGl_OCCT_NUMBER_OF_STATE_VARIABLES]
static

List of pre-defined OCCT state uniform variables.


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