Ocean
Ocean::Rendering::ShaderProgram Class Reference

This class implements a shader program attribute. More...

Inheritance diagram for Ocean::Rendering::ShaderProgram:

Public Types

enum  ShaderLanguage : uint32_t { SL_INVALID = 0u , SL_GLSL , SL_CG }
 Definition of individual shader languages. More...
 
enum  ShaderType : uint32_t {
  ST_INVALID = 0u , ST_COMPUTE , ST_FRAGMENT , ST_GEOMETRY ,
  ST_TESSELLATION_CONTROL , ST_TESSELLATION_EVALUATION , ST_VERTEX , ST_UNIFIED
}
 Definition of individual shader types. More...
 
enum  ParameterType : uint32_t {
  TYPE_INVALID = 0u , TYPE_UNSUPPORTED , TYPE_BOOL , TYPE_FLOAT ,
  TYPE_INTEGER , TYPE_MATRIX3 , TYPE_MATRIX4 , TYPE_SAMPLE1 ,
  TYPE_SAMPLE2 , TYPE_SAMPLE3 , TYPE_STRUCT , TYPE_VECTOR2 ,
  TYPE_VECTOR3 , TYPE_VECTOR4
}
 Definition of a parameter types. More...
 
typedef std::pair< std::string, ShaderTypeFilenamePair
 Definition of a pair combining a filename with a shader type with. More...
 
typedef std::vector< FilenamePairFilenamePairs
 Definition of a vector holding pairs combining filenames with shader types. More...
 
typedef std::pair< std::vector< const char * >, ShaderTypeCodePair
 Definition of a pair combining shader code parts with a shader type with. More...
 
typedef std::vector< CodePairCodePairs
 Definition of a vector holding pairs combining shader codes with shader types. More...
 
typedef unsigned int SamplerIndex
 Definition of a sampler index. More...
 
- Public Types inherited from Ocean::Rendering::Object
enum  ObjectType {
  TYPE_UNKNOWN , TYPE_ABSOLUTE_TRANSFORM , TYPE_ATTRIBUTE , TYPE_ATTRIBUTE_SET ,
  TYPE_BACKGROUND , TYPE_BILLBOARD , TYPE_BITMAP_FRAMEBUFFER , TYPE_BLEND_ATTRIBUTE ,
  TYPE_BOX , TYPE_CONE , TYPE_CYLINDER , TYPE_DEPTH_ATTRIBUTE ,
  TYPE_DIRECTIONAL_LIGHT , TYPE_FRAMEBUFFER , TYPE_FRAME_TEXTURE_2D , TYPE_GEOMETRY ,
  TYPE_GROUP , TYPE_INDEPENDENT_PRIMITIVE , TYPE_LIGHT_SOURCE , TYPE_LINES ,
  TYPE_LINE_STRIPS , TYPE_LOD , TYPE_MATERIAL , TYPE_NODE ,
  TYPE_OBJECT , TYPE_PARALLEL_VIEW , TYPE_PERSPECTIVE_VIEW , TYPE_PHANTOM_ATTRIBUTE ,
  TYPE_POINT_LIGHT , TYPE_POINTS , TYPE_PRIMITIVE , TYPE_PRIMITIVE_ATTRIBUTE ,
  TYPE_QUAD_STRIPS , TYPE_QUADS , TYPE_RENDERABLE , TYPE_SCENE ,
  TYPE_SHADER_PROGRAM , TYPE_SHAPE , TYPE_SKY_BACKGROUND , TYPE_SPHERE ,
  TYPE_SPOT_LIGHT , TYPE_STEREO_ATTRIBUTE , TYPE_STEREO_VIEW , TYPE_STRIP_PRIMITIVE ,
  TYPE_SWITCH , TYPE_TEXT , TYPE_TEXTURE , TYPE_TEXTURE_2D ,
  TYPE_MEDIA_TEXTURE_2D , TYPE_TEXTURE_FRAMEBUFFER , TYPE_TEXTURES , TYPE_TRANSFORM ,
  TYPE_TRIANGLE_FANS , TYPE_TRIANGLES , TYPE_TRIANGLE_STRIPS , TYPE_UNDISTORTED_BACKGROUND ,
  TYPE_VERTEX_SET , TYPE_VIEW , TYPE_WINDOW_FRAMEBUFFER
}
 Definition of different object type. More...
 
typedef std::unordered_map< ObjectId, unsigned int > ObjectIdMap
 Definition of a map holding object ids to reference counters. More...
 

Public Member Functions

virtual bool setShader (const ShaderLanguage shaderLanguage, const FilenamePairs &filenamePairs, std::string &errorMessage)
 Sets the shader code. More...
 
virtual bool setShader (const ShaderLanguage shaderLanguage, const std::string &vertexShaderCode, const std::string &fragmentShaderCode, std::string &errorMessage)
 Sets the shader code. More...
 
virtual bool setShader (const ShaderLanguage shaderLanguage, const std::vector< const char * > &vertexShaderCode, const std::vector< const char * > &fragmentShaderCode, std::string &errorMessage)
 Sets the shader code. More...
 
virtual bool setShader (const ShaderLanguage shaderLanguage, const CodePairs &codePairs, std::string &errorMessage)
 Sets the shader code. More...
 
virtual bool existParameter (const std::string &name) const
 Returns whether this shader program has a specific parameter. More...
 
virtual ParameterType parameterType (const std::string &name) const
 Returns the type of a specific parameter. More...
 
virtual unsigned int samplerNumber () const
 Returns the number of sampler parameters. More...
 
virtual SamplerIndex samplerIndex (const TextureRef &sampler) const
 Returns the index of a registered texture sample object. More...
 
virtual unsigned int parameterElements (const std::string &name) const
 Returns the number of elements of a specific parameter. More...
 
virtual bool setSampler (const SamplerIndex index, const TextureRef &texture)
 Sets the texture of a specified sampler. More...
 
virtual bool setParameter (const std::string &name, const double value)
 Sets a parameter by a given parameter name. More...
 
virtual bool setParameter (const std::string &name, const float value)
 Sets a parameter by a given parameter name. More...
 
virtual bool setParameter (const std::string &name, const float *value, const unsigned int elements)
 Sets a parameter by a given parameter name. More...
 
virtual bool setParameter (const std::string &name, const int value)
 Sets a parameter by a given parameter name. More...
 
virtual bool setParameter (const std::string &name, const unsigned int value)
 Sets a parameter by a given parameter name. More...
 
virtual bool setParameter (const std::string &name, const HomogenousMatrix4 &value)
 Sets a parameter by a given parameter name. More...
 
virtual bool setParameter (const std::string &name, const SquareMatrix3 &value)
 Sets a parameter by a given parameter name. More...
 
virtual bool setParameter (const std::string &name, const SquareMatrix4 &value)
 Sets a parameter by a given parameter name. More...
 
virtual bool setParameter (const std::string &name, const Vector2 &value)
 Sets a parameter by a given parameter name. More...
 
virtual bool setParameter (const std::string &name, const Vector3 &value)
 Sets a parameter by a given parameter name. More...
 
virtual bool setParameter (const std::string &name, const Vector4 &value)
 Sets a parameter by a given parameter name. More...
 
virtual bool setParameter (const std::string &name, const HomogenousMatrices4 &value)
 Sets a parameter by a given parameter name. More...
 
virtual bool setParameter (const std::string &name, const SquareMatrices3 &value)
 Sets a parameter by a given parameter name. More...
 
virtual bool isCompiled () const
 Returns whether this program holds a valid and successfully compiled and linked shader code. More...
 
ObjectType type () const override
 Returns the type of this object. More...
 
- Public Member Functions inherited from Ocean::Rendering::Object
ObjectId id () const
 Returns the unique object id of this object. More...
 
const std::string & name () const
 Returns the name of this object. More...
 
virtual void setName (const std::string &name)
 Sets or changes the name of this object. More...
 
virtual const std::string & engineName () const =0
 Returns the name of the owner engine. More...
 
ObjectRefs parentObjects () const
 Returns all parent objects. More...
 
ObjectRefSet parentNodes () const
 Returns all parent nodes. More...
 
virtual std::string descriptiveInformation () const
 Returns descriptive information about the object as string. More...
 

Static Public Attributes

static constexpr SamplerIndex invalidSamplerIndex = SamplerIndex(-1)
 Definition of an invalid sampler index. More...
 

Protected Types

typedef std::vector< TextureRefTextures
 Definition of a vector holding sample objects. More...
 

Protected Member Functions

 ShaderProgram ()
 Creates a new shader program object. More...
 
 ~ShaderProgram () override
 Destructs a shader program object. More...
 
- Protected Member Functions inherited from Ocean::Rendering::Attribute
 Attribute ()
 Creates a new attribute object. More...
 
 ~Attribute () override
 Destructs an attribute object. More...
 
- Protected Member Functions inherited from Ocean::Rendering::Object
 Object ()
 Creates a new object. More...
 
 Object (const Object &object)=delete
 Disabled copy constructor. More...
 
virtual ~Object ()
 Destructs an object. More...
 
Engineengine () const
 Returns the render engine which is owner of this object. More...
 
void registerParent (const ObjectId parentId)
 Registers a parent node for this (child) node. More...
 
void unregisterParent (const ObjectId parentId)
 Unregisters a parent node for this (child) node. More...
 
void registerThisObjectAsParent (const ObjectRef &child)
 Registers this object at a child as parent object. More...
 
void unregisterThisObjectAsParent (const ObjectRef &child)
 Unregisters this object from a child as parent. More...
 
Objectoperator= (const Object &object)=delete
 Disabled copy operator. More...
 

Protected Attributes

Textures shaderProgramTextures
 Vector holding all registered texture samples. More...
 
- Protected Attributes inherited from Ocean::Rendering::Object
Lock objectLock
 Lock for the object. More...
 

Additional Inherited Members

- Static Public Member Functions inherited from Ocean::Rendering::Object
static std::string translateObjectType (const ObjectType objectType)
 Translates an object type to a readable string. More...
 

Detailed Description

This class implements a shader program attribute.

Member Typedef Documentation

◆ CodePair

typedef std::pair<std::vector<const char*>, ShaderType> Ocean::Rendering::ShaderProgram::CodePair

Definition of a pair combining shader code parts with a shader type with.

◆ CodePairs

Definition of a vector holding pairs combining shader codes with shader types.

◆ FilenamePair

Definition of a pair combining a filename with a shader type with.

◆ FilenamePairs

Definition of a vector holding pairs combining filenames with shader types.

◆ SamplerIndex

Definition of a sampler index.

◆ Textures

typedef std::vector<TextureRef> Ocean::Rendering::ShaderProgram::Textures
protected

Definition of a vector holding sample objects.

Member Enumeration Documentation

◆ ParameterType

Definition of a parameter types.

Enumerator
TYPE_INVALID 

Invalid parameter.

TYPE_UNSUPPORTED 

Unsupported parameter.

TYPE_BOOL 

Boolean parameter.

TYPE_FLOAT 

Float parameter.

TYPE_INTEGER 

Integer parameter.

TYPE_MATRIX3 

3x3 matrix parameter.

TYPE_MATRIX4 

4x4 matrix parameter.

TYPE_SAMPLE1 

1D sample parameter.

TYPE_SAMPLE2 

2D sample parameter.

TYPE_SAMPLE3 

3D sample parameter.

TYPE_STRUCT 

Struct parameter.

TYPE_VECTOR2 

2D vector parameter.

TYPE_VECTOR3 

3D vector parameter.

TYPE_VECTOR4 

4D vector parameter.

◆ ShaderLanguage

Definition of individual shader languages.

Enumerator
SL_INVALID 

An invalid shader language.

SL_GLSL 

The GLSL shader language (e.g., used by OpenGL and OpenGL ES).

SL_CG 

The Cg shader language (e.g., used by NVIDIA).

◆ ShaderType

Definition of individual shader types.

Enumerator
ST_INVALID 

An invalid shader type.

ST_COMPUTE 

A compute shader.

ST_FRAGMENT 

A fragment shader.

ST_GEOMETRY 

A geometry shader.

ST_TESSELLATION_CONTROL 

A Tessellation control shader.

ST_TESSELLATION_EVALUATION 

A Tessellation evaluation shader.

ST_VERTEX 

A vertex shader.

ST_UNIFIED 

Constructor & Destructor Documentation

◆ ShaderProgram()

Ocean::Rendering::ShaderProgram::ShaderProgram ( )
protected

Creates a new shader program object.

◆ ~ShaderProgram()

Ocean::Rendering::ShaderProgram::~ShaderProgram ( )
overrideprotected

Destructs a shader program object.

Member Function Documentation

◆ existParameter()

virtual bool Ocean::Rendering::ShaderProgram::existParameter ( const std::string &  name) const
virtual

Returns whether this shader program has a specific parameter.

Parameters
nameThe name of the parameter to check
Returns
True, if so

Reimplemented in Ocean::Rendering::GLESceneGraph::GLESShaderProgram.

◆ isCompiled()

virtual bool Ocean::Rendering::ShaderProgram::isCompiled ( ) const
virtual

Returns whether this program holds a valid and successfully compiled and linked shader code.

Returns
True, if so

Reimplemented in Ocean::Rendering::GLESceneGraph::GLESShaderProgram.

◆ parameterElements()

virtual unsigned int Ocean::Rendering::ShaderProgram::parameterElements ( const std::string &  name) const
virtual

Returns the number of elements of a specific parameter.

Parameters
nameThe name of the parameter to return the number of elements for
Returns
Number of elements

Reimplemented in Ocean::Rendering::GLESceneGraph::GLESShaderProgram.

◆ parameterType()

virtual ParameterType Ocean::Rendering::ShaderProgram::parameterType ( const std::string &  name) const
virtual

Returns the type of a specific parameter.

Parameters
nameThe name of the parameter to return the type for
Returns
Parameter type

Reimplemented in Ocean::Rendering::GLESceneGraph::GLESShaderProgram.

◆ samplerIndex()

virtual SamplerIndex Ocean::Rendering::ShaderProgram::samplerIndex ( const TextureRef sampler) const
virtual

Returns the index of a registered texture sample object.

Parameters
samplerThe sampler to return the index for
Returns
Index of the specified sampler, an invalid index is returned if the sampler is not registered

Reimplemented in Ocean::Rendering::GLESceneGraph::GLESShaderProgram.

◆ samplerNumber()

virtual unsigned int Ocean::Rendering::ShaderProgram::samplerNumber ( ) const
virtual

Returns the number of sampler parameters.

Returns
Number of samplers

Reimplemented in Ocean::Rendering::GLESceneGraph::GLESShaderProgram.

◆ setParameter() [1/13]

virtual bool Ocean::Rendering::ShaderProgram::setParameter ( const std::string &  name,
const double  value 
)
virtual

Sets a parameter by a given parameter name.

Parameters
nameThe name of the parameter to set
valueThe value to set
Returns
True, if succeeded

Reimplemented in Ocean::Rendering::GLESceneGraph::GLESShaderProgram.

◆ setParameter() [2/13]

virtual bool Ocean::Rendering::ShaderProgram::setParameter ( const std::string &  name,
const float *  value,
const unsigned int  elements 
)
virtual

Sets a parameter by a given parameter name.

Parameters
nameThe name of the parameter to set
valueArray value to set
elementsNumber of elements in the array
Returns
True, if succeeded

Reimplemented in Ocean::Rendering::GLESceneGraph::GLESShaderProgram.

◆ setParameter() [3/13]

virtual bool Ocean::Rendering::ShaderProgram::setParameter ( const std::string &  name,
const float  value 
)
virtual

Sets a parameter by a given parameter name.

Parameters
nameThe name of the parameter to set
valueThe value to set
Returns
True, if succeeded

Reimplemented in Ocean::Rendering::GLESceneGraph::GLESShaderProgram.

◆ setParameter() [4/13]

virtual bool Ocean::Rendering::ShaderProgram::setParameter ( const std::string &  name,
const HomogenousMatrices4 value 
)
virtual

Sets a parameter by a given parameter name.

Parameters
nameThe name of the parameter to set
valueThe value to set
Returns
True, if succeeded

Reimplemented in Ocean::Rendering::GLESceneGraph::GLESShaderProgram.

◆ setParameter() [5/13]

virtual bool Ocean::Rendering::ShaderProgram::setParameter ( const std::string &  name,
const HomogenousMatrix4 value 
)
virtual

Sets a parameter by a given parameter name.

Parameters
nameThe name of the parameter to set
valueThe value to set
Returns
True, if succeeded

Reimplemented in Ocean::Rendering::GLESceneGraph::GLESShaderProgram.

◆ setParameter() [6/13]

virtual bool Ocean::Rendering::ShaderProgram::setParameter ( const std::string &  name,
const int  value 
)
virtual

Sets a parameter by a given parameter name.

Parameters
nameThe name of the parameter to set
valueThe value to set
Returns
True, if succeeded

Reimplemented in Ocean::Rendering::GLESceneGraph::GLESShaderProgram.

◆ setParameter() [7/13]

virtual bool Ocean::Rendering::ShaderProgram::setParameter ( const std::string &  name,
const SquareMatrices3 value 
)
virtual

Sets a parameter by a given parameter name.

Parameters
nameThe name of the parameter to set
valueThe value to set
Returns
True, if succeeded

Reimplemented in Ocean::Rendering::GLESceneGraph::GLESShaderProgram.

◆ setParameter() [8/13]

virtual bool Ocean::Rendering::ShaderProgram::setParameter ( const std::string &  name,
const SquareMatrix3 value 
)
virtual

Sets a parameter by a given parameter name.

Parameters
nameThe name of the parameter to set
valueThe value to set
Returns
True, if succeeded

Reimplemented in Ocean::Rendering::GLESceneGraph::GLESShaderProgram.

◆ setParameter() [9/13]

virtual bool Ocean::Rendering::ShaderProgram::setParameter ( const std::string &  name,
const SquareMatrix4 value 
)
virtual

Sets a parameter by a given parameter name.

Parameters
nameThe name of the parameter to set
valueThe value to set
Returns
True, if succeeded

Reimplemented in Ocean::Rendering::GLESceneGraph::GLESShaderProgram.

◆ setParameter() [10/13]

virtual bool Ocean::Rendering::ShaderProgram::setParameter ( const std::string &  name,
const unsigned int  value 
)
virtual

Sets a parameter by a given parameter name.

Parameters
nameThe name of the parameter to set
valueThe value to set
Returns
True, if succeeded

Reimplemented in Ocean::Rendering::GLESceneGraph::GLESShaderProgram.

◆ setParameter() [11/13]

virtual bool Ocean::Rendering::ShaderProgram::setParameter ( const std::string &  name,
const Vector2 value 
)
virtual

Sets a parameter by a given parameter name.

Parameters
nameThe name of the parameter to set
valueThe value to set
Returns
True, if succeeded

Reimplemented in Ocean::Rendering::GLESceneGraph::GLESShaderProgram.

◆ setParameter() [12/13]

virtual bool Ocean::Rendering::ShaderProgram::setParameter ( const std::string &  name,
const Vector3 value 
)
virtual

Sets a parameter by a given parameter name.

Parameters
nameThe name of the parameter to set
valueThe value to set
Returns
True, if succeeded

Reimplemented in Ocean::Rendering::GLESceneGraph::GLESShaderProgram.

◆ setParameter() [13/13]

virtual bool Ocean::Rendering::ShaderProgram::setParameter ( const std::string &  name,
const Vector4 value 
)
virtual

Sets a parameter by a given parameter name.

Parameters
nameThe name of the parameter to set
valueThe value to set
Returns
True, if succeeded

Reimplemented in Ocean::Rendering::GLESceneGraph::GLESShaderProgram.

◆ setSampler()

virtual bool Ocean::Rendering::ShaderProgram::setSampler ( const SamplerIndex  index,
const TextureRef texture 
)
virtual

Sets the texture of a specified sampler.

Parameters
indexThe index of the shader sampler to set
textureThe texture object to set
Returns
True, if succeeded

Reimplemented in Ocean::Rendering::GLESceneGraph::GLESShaderProgram.

◆ setShader() [1/4]

virtual bool Ocean::Rendering::ShaderProgram::setShader ( const ShaderLanguage  shaderLanguage,
const CodePairs codePairs,
std::string &  errorMessage 
)
virtual

Sets the shader code.

Parameters
shaderLanguageThe language of the given shaders.
codePairsThe codes of the shader, each shader can be composed of several individual code blocks
errorMessageReturning error message if the code is not valid
Returns
True, if the shader could be compiled successfully

Reimplemented in Ocean::Rendering::GLESceneGraph::GLESShaderProgram.

◆ setShader() [2/4]

virtual bool Ocean::Rendering::ShaderProgram::setShader ( const ShaderLanguage  shaderLanguage,
const FilenamePairs filenamePairs,
std::string &  errorMessage 
)
virtual

Sets the shader code.

Parameters
shaderLanguageThe language of the given shaders.
filenamePairsThe pairs of filenames and shader types which are necessary to defined the shader, at least one
errorMessageReturning error message if the code is not valid
Returns
True, if the shader could be compiled successfully

Reimplemented in Ocean::Rendering::GLESceneGraph::GLESShaderProgram.

◆ setShader() [3/4]

virtual bool Ocean::Rendering::ShaderProgram::setShader ( const ShaderLanguage  shaderLanguage,
const std::string &  vertexShaderCode,
const std::string &  fragmentShaderCode,
std::string &  errorMessage 
)
virtual

Sets the shader code.

Parameters
shaderLanguageThe language of the given shaders.
vertexShaderCodeThe code of the vertex shader, must be valid
fragmentShaderCodeThe code of the fragment shader, must be valid
errorMessageReturning error message if the code is not valid
Returns
True, if the shader could be compiled successfully

Reimplemented in Ocean::Rendering::GLESceneGraph::GLESShaderProgram.

◆ setShader() [4/4]

virtual bool Ocean::Rendering::ShaderProgram::setShader ( const ShaderLanguage  shaderLanguage,
const std::vector< const char * > &  vertexShaderCode,
const std::vector< const char * > &  fragmentShaderCode,
std::string &  errorMessage 
)
virtual

Sets the shader code.

Parameters
shaderLanguageThe language of the given shaders.
vertexShaderCodeThe code of the vertex shader, can be composed of several individual code blocks
fragmentShaderCodeThe code of the fragment shader, can be composed of several individual code blocks
errorMessageReturning error message if the code is not valid
Returns
True, if the shader could be compiled successfully

Reimplemented in Ocean::Rendering::GLESceneGraph::GLESShaderProgram.

◆ type()

ObjectType Ocean::Rendering::ShaderProgram::type ( ) const
overridevirtual

Returns the type of this object.

See also
Object::type().

Reimplemented from Ocean::Rendering::Attribute.

Field Documentation

◆ invalidSamplerIndex

constexpr SamplerIndex Ocean::Rendering::ShaderProgram::invalidSamplerIndex = SamplerIndex(-1)
staticconstexpr

Definition of an invalid sampler index.

◆ shaderProgramTextures

Textures Ocean::Rendering::ShaderProgram::shaderProgramTextures
protected

Vector holding all registered texture samples.


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