Open Inventor Release 2024.2.1
 
Loading...
Searching...
No Matches
SoShaderObject Class Referenceabstract

VSG extension Abstract node class which defines a shader object. More...

#include <Inventor/nodes/SoShaderObject.h>

+ Inheritance diagram for SoShaderObject:

Public Types

enum  SourceType {
  ARB_PROGRAM ,
  CG_PROGRAM ,
  GLSL_PROGRAM ,
  FILENAME
}
 Shader Object source type possible values. More...
 
enum  ShaderType {
  VERTEX_SHADER = SbEnums::SHADER_TYPE_VERTEX ,
  GEOMETRY_SHADER = SbEnums::SHADER_TYPE_GEOMETRY ,
  FRAGMENT_SHADER = SbEnums::SHADER_TYPE_FRAGMENT ,
  TESSELLATION_CONTROL_SHADER = SbEnums::SHADER_TYPE_TESS_CTRL ,
  TESSELLATION_EVALUATION_SHADER = SbEnums::SHADER_TYPE_TESS_EVAL ,
  COMPUTE_SHADER = SbEnums::SHADER_TYPE_COMPUTE
}
 Type of the shader. More...
 

Public Member Functions

virtual SoType getTypeId () const
 Returns the type identifier for this specific instance.
 
template<typename UniformParamType , typename ParamValueType >
UniformParamType * addShaderParameter (const SbString &name, ParamValueType val)
 Convenience method to create an SoShaderUniformParameter with the specified name and value and add it to the given shader object.
 
virtual ShaderType getShaderType () const =0
 Must be redefined by derived class.
 
template<typename UniformParamType , typename ParamValueType >
void setShaderParameter (const SbString &name, ParamValueType val)
 UniformParamType is the type of parameter to set.
 
- Public Member Functions inherited from SoNode
virtual void setOverride (const SbBool state)
 Turns the override flag on or off.
 
virtual SbBool isOverride () const
 Returns the state of the override flag.
 
virtual SoNodecopy (SbBool copyConnections=FALSE) const
 Creates and returns an exact copy of the node.
 
virtual SbBool affectsState () const
 Returns TRUE if a node has an effect on the state during traversal.
 
virtual void touch ()
 Marks an instance as modified, simulating a change to it.
 
- Public Member Functions inherited from SoFieldContainer
void setToDefaults ()
 Sets all fields in this object to their default values.
 
SbBool hasDefaultValues () const
 Returns TRUE if all of the object's fields have their default values.
 
SbBool fieldsAreEqual (const SoFieldContainer *fc) const
 Returns TRUE if this object's fields are exactly equal to fc's fields.
 
void copyFieldValues (const SoFieldContainer *fc, SbBool copyConnections=FALSE)
 Copies the contents of fc's fields into this object's fields.
 
SoNONUNICODE SbBool set (const char *fieldDataString)
 Sets one or more fields in this object to the values specified in the given string, which should be a string in the Open Inventor file format.
 
SbBool set (const SbString &fieldDataString)
 Sets one or more fields in this object to the values specified in the given string, which should be a string in the Open Inventor file format.
 
void get (SbString &fieldDataString)
 Returns the values of the fields of this object in the Open Inventor ASCII file format in the given string.
 
virtual int getFields (SoFieldList &list) const
 Appends references to all of this object's fields to resultList, and returns the number of fields appended.
 
virtual int getAllFields (SoFieldList &list) const
 Returns a list of fields, including the eventIn's and eventOut's.
 
virtual SoFieldgetField (const SbName &fieldName) const
 Returns a the field of this object whose name is fieldName.
 
virtual SoFieldgetEventIn (const SbName &fieldName) const
 Returns a the eventIn with the given name.
 
virtual SoFieldgetEventOut (const SbName &fieldName) const
 Returns the eventOut with the given name.
 
SbBool getFieldName (const SoField *field, SbName &fieldName) const
 Returns the name of the given field in the fieldName argument.
 
SbBool enableNotify (SbBool flag)
 Notification at this Field Container is enabled (if flag == TRUE) or disabled (if flag == FALSE).
 
SbBool isNotifyEnabled () const
 Notification is the process of telling interested objects that this object has changed.
 
virtual void setUserData (void *data)
 Sets application data.
 
void * getUserData (void) const
 Gets user application data.
 
- Public Member Functions inherited from SoBase
virtual SbName getName () const
 Returns the name of an instance.
 
virtual void setName (const SbName &name)
 Sets the name of an instance.
 
void setSynchronizable (const bool b)
 Sets this to be a ScaleViz synchronizable object.
 
bool isSynchronizable () const
 Gets the ScaleViz synchronizable state of this object.
 
- Public Member Functions inherited from SoRefCounter
void ref () const
 Adds a reference to an instance.
 
void unref () const
 Removes a reference from an instance.
 
void unrefNoDelete () const
 unrefNoDelete() should be called when it is desired to decrement the reference count, but not delete the instance if this brings the reference count to zero.
 
int getRefCount () const
 Returns current reference count.
 
void lock () const
 lock this instance.
 
void unlock () const
 unlock this instance.
 
- Public Member Functions inherited from SoTypedObject
SbBool isOfType (const SoType &type) const
 Returns TRUE if this object is of the type specified in type or is derived from that type.
 
template<typename TypedObjectClass >
SbBool isOfType () const
 Returns TRUE if this object is of the type of class TypedObjectClass or is derived from that class.
 

Static Public Member Functions

static SoType getClassTypeId ()
 Returns the type identifier for this class.
 
- Static Public Member Functions inherited from SoNode
static SoType getClassTypeId ()
 Returns the type identifier for this class.
 
static SoNodegetByName (const SbName &name)
 A node's name can be set using SoBase::setName().
 
static int getByName (const SbName &name, SoNodeList &list)
 A node's name can be set using SoBase::setName().
 
- Static Public Member Functions inherited from SoFieldContainer
static SoType getClassTypeId ()
 Returns the type of this class.
 
- Static Public Member Functions inherited from SoBase
static SoType getClassTypeId ()
 Returns type identifier for this class.
 
- Static Public Member Functions inherited from SoTypedObject
static SoType getClassTypeId ()
 Returns the type identifier for this class.
 

Public Attributes

SoSFBool isActive
 Specifies if the shader object is active or not.
 
SoSFEnum sourceType
 Specifies the shader object's source type.
 
SoSFFilePathString sourceProgram
 Contains the shader object's source program, specified by a filename (sourceType set to FILENAME) or by the string containing the program (sourceType set to GLSL_PROGRAM).
 
SoMFUniformShaderParameter parameter
 Contains the shader's uniform parameters.
 

Friends

class SoShaderProgram
 

Detailed Description

VSG extension Abstract node class which defines a shader object.

This abstract class is the parent of classes that define a programmable graphics pipeline stage that composes a shader program.

There are five types of shader objects that can be added to a shader program. Any of these stages can be user defined.

  • Vertex shader
    The vertex shader is executed once for each vertex (usually in parallel). The main purpose is to transform each vertex's 3D position from model space to projection space. Vertex shaders can manipulate properties such as position, color and texture coordinate, but cannot create new vertices.
  • Tessellation control shader
    This shader accepts a list of vertices defined as a patch to control the amount of tessellation applied to the patch. Following the execution of this shader, a tessellator computes a set of triangles in a parametric space.
  • Tessellation evaluation shader
    This shader is executed at least once for each vertex that was created by the tesselator in the parametric space. The TES takes the parametric coordinate and the patch data output by the TCS to generate a final position for the surface.
  • Geometry shader
    The geometry shader acts on a complete primitive (triangle or line): it can modify existing primitives, it can insert (create) new primitives, it can remove (destroy) existing primitives.
  • Fragment shader
    Fragment shaders compute color and other attributes of each fragment.

Note: Compute shaders are not part of the rendering pipeline. They represent a shader stage used entirely for computing arbitrary information.

Shader object nodes cannot be inserted directly in a scene graph. They must be added to the field shaderObject of an SoShaderProgram node.

A shader object is defined by the following properties:

  • Source program, which is the shader's source code (see sourceProgram field),
  • Uniform parameters set by the application (see parameter field),
  • State (active or not) (see isActive field).

The source program can be specified either by a string containing the program source code, or by a filename which contains the program source code. How the sourceProgram field is interpreted depends on the field sourceType.

The supported shading language of the program source is OpenGL Shader Language (GLSL) . Furthermore, the Open Inventor shader API or VolumeViz shader API must be used to write any GLSL shader program. See Shaders for detail.

Uniform parameters can be set through the parameter field. Uniform means, in the case of a vertex or geometry program, a value which is the same for all vertices in a primitive, and, in the case of a fragment program, a value which is the same for all fragments created by a primitive. Each uniform parameter is represented by an instance of a specific subclass of SoUniformShaderParameter. For example, an SoShaderParameter1i holds a single integer value. A uniform parameter has no effect if it is not valid, that is, if there is no corresponding name (identifier) in the GLSL source program. An SoShaderParameter1i must be used for each texture sampler in order to specify the texture unit and texture sampler uniform parameter name pair.

A vertex shader can also use vertex parameters, which are per-vertex data passed from the application to the vertex shader. Vertex parameters are represented by an instance of a specific subclass of SoVertexShaderParameter. For example, an SoVertexShaderParameter1f holds a set of floating point values and an SoVertexShaderParameter3f holds a set of SbVec3f values. Vertex parameter nodes are property nodes (similar to materials or normals) and should be added directly in the scene graph, not in the shader object.

Tips:

  • Set the environment variable OIV_GLSL_DEBUG to get the GLSL compile/link output in the console.
  • If you set the environment variable OIV_SHADER_CHECK_INTERVAL, the shader source file is checked for a change every n seconds, where n is the value specified by the variable. This allows you to edit a shader source file without needing to restart your application after each shader modification.

FILE FORMAT/DEFAULT

    This is an abstract class. See the reference page of a derived class for the format and default values.

EXAMPLE

SEE ALSO

Shaders, SoVertexShader, SoGeometryShader, SoFragmentShader, SoShaderProgram, SoShaderParameter, SoUniformShaderParameter, SoVertexShaderParameter, SoTessellationControlShader, SoTessellationEvaluationShader

Definition at line 204 of file SoShaderObject.h.

Member Enumeration Documentation

◆ ShaderType

Type of the shader.

Enumerator
VERTEX_SHADER 

The shader is a vertex shader.

GEOMETRY_SHADER 

The shader is a geometry shader.

FRAGMENT_SHADER 

The shader is a fragment shader.

TESSELLATION_CONTROL_SHADER 

The shader is a tessellation control shader.

TESSELLATION_EVALUATION_SHADER 

The shader is a tessellation evaluation shader.

COMPUTE_SHADER 

The shader is a compute shader.

Definition at line 295 of file SoShaderObject.h.

◆ SourceType

Shader Object source type possible values.

Enumerator
ARB_PROGRAM 

The source is an ARB vertex or fragment program.

CG_PROGRAM 

The source is a CG program.

GLSL_PROGRAM 

The source is an OpenGL Shading Language program.

FILENAME 

Only the name of the file containing the source is given (default).

Definition at line 212 of file SoShaderObject.h.

Member Function Documentation

◆ addShaderParameter()

template<typename UniformParamType , typename ParamValueType >
UniformParamType * SoShaderObject::addShaderParameter ( const SbString name,
ParamValueType  val 
)

Convenience method to create an SoShaderUniformParameter with the specified name and value and add it to the given shader object.

UniformParamType is the type of parameter to add. This function also generates the following helper methods not visible in the documentation:

  • UniformParamType* addShaderParameter{1,2,3,4}i(const SbString&, ParamValueType)
  • UniformParamType* addShaderParameter{1,2,3,4}f(const SbString&, ParamValueType)
  • UniformParamType* addShaderParameterArray{1,2,3,4}i(const SbString&, ParamValueType)
  • UniformParamType* addShaderParameterArray{1,2,3,4}f(const SbString&, ParamValueType)
  • UniformParamType* addShaderParameterMatrix

These are template methods, so ParamValueType must have an operator= compatible with the field value of the corresponding SoShaderParameter (for example, addShaderParameter2f can take an SbVec2f as ParamValueType)

Definition at line 601 of file SoShaderObject.h.

◆ getClassTypeId()

static SoType SoShaderObject::getClassTypeId ( )
static

Returns the type identifier for this class.


◆ getShaderType()

virtual ShaderType SoShaderObject::getShaderType ( ) const
pure virtual

◆ getTypeId()

virtual SoType SoShaderObject::getTypeId ( ) const
virtual

Returns the type identifier for this specific instance.

Reimplemented from SoNode.

Reimplemented in SoComputeShader, SoFragmentShader, SoGeometryShader, SoTessellationControlShader, SoTessellationEvaluationShader, and SoVertexShader.

◆ setShaderParameter()

template<typename UniformParamType , typename ParamValueType >
void SoShaderObject::setShaderParameter ( const SbString name,
ParamValueType  val 
)

UniformParamType is the type of parameter to set.

This function also generates the following helper methods not visible in the documentation:

  • void setShaderParameter{1,2,3,4}i(const SbString&, ParamValueType)
  • void setShaderParameter{1,2,3,4}f(const SbString&, ParamValueType)
  • void setShaderParameterArray{1,2,3,4}i(const SbString&, ParamValueType)
  • void setShaderParameterArray{1,2,3,4}f(const SbString&, ParamValueType)
  • void setShaderParameterParameterMatrix

These are template methods, so ParamValueType must have an operator= compatible with the field value of the corresponding SoShaderParameter (for example, setShaderParameter2f can take an SbVec2f as ParamValueType).

Definition at line 623 of file SoShaderObject.h.

Friends And Related Symbol Documentation

◆ SoShaderProgram

friend class SoShaderProgram
friend

Definition at line 486 of file SoShaderObject.h.

Member Data Documentation

◆ isActive

SoSFBool SoShaderObject::isActive

Specifies if the shader object is active or not.

Definition at line 240 of file SoShaderObject.h.

◆ parameter

SoMFUniformShaderParameter SoShaderObject::parameter

Contains the shader's uniform parameters.

Definition at line 273 of file SoShaderObject.h.

◆ sourceProgram

SoSFFilePathString SoShaderObject::sourceProgram

Contains the shader object's source program, specified by a filename (sourceType set to FILENAME) or by the string containing the program (sourceType set to GLSL_PROGRAM).

If the filename is not an absolute path name, the list of directories maintained by SoInput is searched. If the source program is not found in any of those directories, then the file is searched for relative to the directory from which the SoShaderObject node was read.

NOTE: The source type (sourceType) must be specified before the source program is specified.

Definition at line 267 of file SoShaderObject.h.

◆ sourceType

SoSFEnum SoShaderObject::sourceType

Specifies the shader object's source type.

The type of source can be either a filename containing the program (FILENAME), or a string containing the source program (GLSL_PROGRAM). Use enum SourceType. Default is FILENAME.

NOTE: The source type must be specified before the source program (sourceProgram) is specified.

Definition at line 251 of file SoShaderObject.h.


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