1 /***************************************************************************
3 * Copyright 2010 BMW Car IT GmbH
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
18 ****************************************************************************/
23 #include <ShaderProgram.h>
24 #include <ShaderUniform.h>
29 * Represents a shader instance.
31 * It stores a set of uniform parameters and refers to an OpenGL program object.
32 * Some uniform variables are pre-defined, like surface position and size,
33 * opacity, etc... Additionally, there may be user-defined uniforms.
39 * Creates a new shader instance by vertex and fragment shader name.
40 * @param vertName File name of vertex shader.
41 * @param fragName File name of fragment shader.
42 * @return new Shader instance, NULL if shader could not be loaded, compiled or linked.
44 static Shader* createShader(const std::string& vertName, const std::string& fragName);
52 * @return Unique ID of this instance
60 * Start using this shader for rendering.
70 void setUniform(const ShaderUniform& uniform);
73 * Update uniform values.
74 * Please note that this method doesn't update the standard uniforms
75 * used for position, size, etc... They need to be set separately
76 * by loadCommonUniforms().
78 void loadUniforms(void) const;
81 * Load uniform values for common surface properties, like position,
82 * size, opacity, etc...
84 * @param uniforms Uniform values
86 void loadCommonUniforms(const ShaderProgram::CommonUniforms& uniforms) const
88 _program.loadCommonUniforms(uniforms);
93 * Private constructor.
94 * New instances of this class are supposed to be created by createShader(...).
96 * @param program Program object to be used
98 Shader(ShaderProgram& program);
104 /// reference to OpenGL program object used by this shader instance
105 ShaderProgram& _program;
107 /// a map of user-defined uniforms
108 std::map<std::string,ShaderUniform> _uniformMap;
114 #endif /* _SHADER_H_ */