8 #ifndef META_OCEAN_RENDERING_GLES_SHADER_PROGRAM_H
9 #define META_OCEAN_RENDERING_GLES_SHADER_PROGRAM_H
23 #include <unordered_map>
31 namespace GLESceneGraph
35 class GLESShaderProgram;
38 class GLESFramebuffer;
81 typedef std::unordered_map<std::string, T>
ValueMap;
90 void setValue(
const std::string& name, T&& value);
97 void setValue(
const std::string& name,
const T& value);
114 typedef std::unordered_map<SamplerIndex, TextureRef>
SamplerMap;
132 inline GLuint id()
const;
151 bool link(
const ProgramType programType,
const std::vector<GLESShaderRef>& shaders, std::string& message);
161 bool compileAndLink(
const ProgramType programType,
const std::vector<const char*>& vertexShaderCode,
const std::vector<const char*>& fragmentShaderCode, std::string& message);
213 bool setShader(
const ShaderLanguage shaderLanguage,
const std::string& vertexShaderCode,
const std::string& fragmentShaderCode, std::string& errorMessage)
override;
219 bool setShader(
const ShaderLanguage shaderLanguage,
const std::vector<const char*>& vertexShaderCode,
const std::vector<const char*>& fragmentShaderCode, std::string& errorMessage)
override;
267 bool setParameter(
const std::string& name,
const double value)
override;
273 bool setParameter(
const std::string& name,
const float value)
override;
279 bool setParameter(
const std::string& name,
const float* value,
const unsigned int elements)
override;
291 bool setParameter(
const std::string& name,
const unsigned int value)
override;
412 template <
typename T>
415 valueMap_[name] = value;
418 template <
typename T>
421 valueMap_.emplace(name, std::move(value));
427 for (
typename ValueMap::const_iterator i = valueMap_.cbegin(); i != valueMap_.cend(); ++i)
429 const std::string& name = i->first;
430 const std::vector<float>& value = i->second;
432 const GLint locationId = glGetUniformLocation(
id, name.c_str());
433 if (locationId != -1)
435 setUniform(locationId, value.data(), value.size());
440 template <
typename T>
443 for (
typename ValueMap::const_iterator i = valueMap_.cbegin(); i != valueMap_.cend(); ++i)
445 const std::string& name = i->first;
446 const T& value = i->second;
448 const GLint locationId = glGetUniformLocation(
id, name.c_str());
449 if (locationId != -1)
451 setUniform(locationId, value);
This template class implements a object reference with an internal reference counter.
Definition: base/ObjectRef.h:58
This class wraps a GLESceneGraph attribute object.
Definition: GLESAttribute.h:36
ProgramType
Definition of different shader functionalities.
Definition: GLESAttribute.h:43
This class implements a base for all GLESceneGraph framebuffers.
Definition: rendering/glescenegraph/GLESFramebuffer.h:34
This class implements a temporary store for shader parameters.
Definition: GLESShaderProgram.h:75
std::unordered_map< std::string, T > ValueMap
Definition of a map mapping parameter names to parameter values.
Definition: GLESShaderProgram.h:81
void setValue(const std::string &name, const T &value)
Setting the value of a parameter.
Definition: GLESShaderProgram.h:413
void setValue(const std::string &name, T &&value)
Setting the value of a parameter.
Definition: GLESShaderProgram.h:419
ValueMap valueMap_
All values.
Definition: GLESShaderProgram.h:108
void bindValues(const GLuint id) const
Binds all parameters to a shader program.
Definition: GLESShaderProgram.h:441
This class implements a container for an OpenGL ES shader program.
Definition: GLESShaderProgram.h:53
std::vector< GLESShaderRef > shaders_
The shaders.
Definition: GLESShaderProgram.h:370
bool setParameter(const std::string &name, const SquareMatrices3 &value) override
Sets a parameter by a given parameter name.
ParameterType parameterType(const std::string &name) const override
Returns the type of a specific parameter.
bool setParameter(const std::string &name, const float value) override
Sets a parameter by a given parameter name.
void bind(const SquareMatrix4 &projection, const HomogenousMatrix4 &camera_T_model, const HomogenousMatrix4 &camera_T_world, const SquareMatrix3 &normalMatrix) const
Uses the shader and binds the given projection and model matrices as OpenGL uniforms.
bool setParameter(const std::string &name, const int value) override
Sets a parameter by a given parameter name.
Parameters< Vector2 > parametersVector2_
The map of Vector2 values.
Definition: GLESShaderProgram.h:397
bool setParameter(const std::string &name, const Vector2 &value) override
Sets a parameter by a given parameter name.
bool setShader(const ShaderLanguage shaderLanguage, const std::string &vertexShaderCode, const std::string &fragmentShaderCode, std::string &errorMessage) override
Sets the shading code (a custom shader, not a shader from GLESProgramManager).
bool isCompiled() const override
Returns whether this program holds a valid and successfully compiled and linked shader code.
GLuint id() const
Returns the OpenGL ES shader program id.
Definition: GLESShaderProgram.h:456
Parameters< float > parametersFloat_
The map for floating point values.
Definition: GLESShaderProgram.h:376
SamplerMap samplers_
The map of texture samplers.
Definition: GLESShaderProgram.h:373
bool setParameter(const std::string &name, const double value) override
Sets a parameter by a given parameter name.
Parameters< Vector3 > parametersVector3_
The map of Vector3 values.
Definition: GLESShaderProgram.h:400
void bindAttribute(const GLESFramebuffer &framebuffer, GLESShaderProgram &shaderProgram) override
Binds all (custom) attributes of this shader program.
std::pair< GLenum, std::vector< const char * > > ShaderCodePair
Definition of a pair combining a GL shader type and shader code parts.
Definition: GLESShaderProgram.h:59
bool setShader(const ShaderLanguage shaderLanguage, const FilenamePairs &filenamePairs, std::string &errorMessage) override
Sets the shading code (a custom shader, not a shader from GLESProgramManager).
void release()
Releases the shader program.
Parameters< unsigned int > parametersUnsignedInt_
The map of integer values.
Definition: GLESShaderProgram.h:385
bool setParameter(const std::string &name, const unsigned int value) override
Sets a parameter by a given parameter name.
bool setParameter(const std::string &name, const float *value, const unsigned int elements) override
Sets a parameter by a given parameter name.
std::vector< ShaderCodePair > ShaderCodePairs
Definition of a vector holding shader code pairs.
Definition: GLESShaderProgram.h:64
bool setShader(const ShaderLanguage shaderLanguage, const std::vector< const char * > &vertexShaderCode, const std::vector< const char * > &fragmentShaderCode, std::string &errorMessage) override
Sets the shading code.
bool link(const ProgramType programType, const std::vector< GLESShaderRef > &shaders, std::string &message)
Links several shaders.
Parameters< int > parametersInt_
The map of integer values.
Definition: GLESShaderProgram.h:382
Parameters< HomogenousMatrix4 > parametersHomogenousMatrix4_
The map of HomogenousMatrix4 values.
Definition: GLESShaderProgram.h:388
bool setParameter(const std::string &name, const SquareMatrix3 &value) override
Sets a parameter by a given parameter name.
bool setParameter(const std::string &name, const HomogenousMatrices4 &value) override
Sets a parameter by a given parameter name.
~GLESShaderProgram() override
Destructs an OpenGL ES shader program container.
GLuint id_
OpenGL ES shader program id.
Definition: GLESShaderProgram.h:364
bool setParameter(const std::string &name, const SquareMatrix4 &value) override
Sets a parameter by a given parameter name.
bool existParameter(const std::string &name) const override
Returns whether this shader program has a specific parameter.
void bind(const GLESFramebuffer &framebuffer, const SquareMatrix4 &projection, const HomogenousMatrix4 &camera_T_model, const HomogenousMatrix4 &camera_T_world, const SquareMatrix3 &normalMatrix)
Uses the shader and binds the given projection and model matrices as OpenGL uniforms.
unsigned int parameterElements(const std::string &name) const override
Returns the number of elements of a specific parameter.
bool setShader(const ShaderLanguage shaderLanguage, const CodePairs &codePairs, std::string &errorMessage) override
Sets the shader code.
bool setParameter(const std::string &name, const Vector3 &value) override
Sets a parameter by a given parameter name.
Parameters< SquareMatrices3 > parametersSquareMatrices3_
The map of SquareMatrices3 values.
Definition: GLESShaderProgram.h:409
bool compileAndLink(const ProgramType programType, const std::vector< const char * > &vertexShaderCode, const std::vector< const char * > &fragmentShaderCode, std::string &message)
Compiles and links a vertex and a fragment shader.
unsigned int samplerNumber() const override
Returns the number of sampler parameters.
bool setParameter(const std::string &name, const HomogenousMatrix4 &value) override
Sets a parameter by a given parameter name.
static std::string translateShaderType(const GLenum shaderType)
Translates the OpenGL shader type to a readable string.
Parameters< Vector4 > parametersVector4_
The map of Vector4 values.
Definition: GLESShaderProgram.h:403
bool link(const ProgramType programType, const GLESShaderRef &vertexShader, const GLESShaderRef &fragmentShader, std::string &message)
Links a vertex and a fragment shader.
bool setParameter(const std::string &name, const Vector4 &value) override
Sets a parameter by a given parameter name.
Parameters< std::vector< float > > parametersFloats_
The map for arrays of floating point value.
Definition: GLESShaderProgram.h:379
Parameters< SquareMatrix4 > parametersSquareMatrix4_
The map of SquareMatrix4 values.
Definition: GLESShaderProgram.h:394
Parameters< SquareMatrix3 > parametersSquareMatrix3_
The map of SquareMatrix3 values.
Definition: GLESShaderProgram.h:391
bool setSampler(const SamplerIndex index, const TextureRef &texture) override
Sets the texture of a specified sampler.
ProgramType necessaryShader() const override
Returns the shader type necessary to render an object with this attribute.
std::unordered_map< SamplerIndex, TextureRef > SamplerMap
Definition of a map mapping sampler indices to textures.
Definition: GLESShaderProgram.h:114
GLESShaderProgram()
Creates a new OpenGL ES shader program container.
Parameters< HomogenousMatrices4 > parametersHomogenousMatrices4_
The map of HomogenousMatrices4 values.
Definition: GLESShaderProgram.h:406
bool compileAndLink(const ProgramType programType, const ShaderCodePairs &shaderCodePairs, std::string &message)
Compiles and links shaders.
ProgramType programType_
The type of the shader program.
Definition: GLESShaderProgram.h:367
SamplerIndex samplerIndex(const TextureRef &sampler) const override
Returns the index of a registered texture sample object.
This class implements a shader program attribute.
Definition: rendering/ShaderProgram.h:44
unsigned int SamplerIndex
Definition of a sampler index.
Definition: rendering/ShaderProgram.h:141
ShaderLanguage
Definition of individual shader languages.
Definition: rendering/ShaderProgram.h:51
ParameterType
Definition of a parameter types.
Definition: rendering/ShaderProgram.h:107
std::vector< FilenamePair > FilenamePairs
Definition of a vector holding pairs combining filenames with shader types.
Definition: rendering/ShaderProgram.h:91
std::vector< CodePair > CodePairs
Definition of a vector holding pairs combining shader codes with shader types.
Definition: rendering/ShaderProgram.h:101
This class implements a vector with four elements.
Definition: Vector4.h:97
std::vector< HomogenousMatrix4 > HomogenousMatrices4
Definition of a vector holding HomogenousMatrix4 objects.
Definition: HomogenousMatrix4.h:73
std::vector< SquareMatrix3 > SquareMatrices3
Definition of a vector holding SquareMatrix3 objects.
Definition: SquareMatrix3.h:71
SmartObjectRef< GLESShaderProgram > GLESShaderProgramRef
Definition of an object reference for shader program containers.
Definition: GLESShaderProgram.h:38
The namespace covering the entire Ocean framework.
Definition: Accessor.h:15