1 /***************************************************************************
3 * Copyright 2010,2011 BMW Car IT GmbH
4 * Copyright (c) 2012, NVIDIA CORPORATION. All rights reserved.
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
19 ****************************************************************************/
26 #include "UniformMap.h"
27 #include "ShaderUniform.h"
28 #include "ShaderProgram.h"
31 * Represents a shader instance.
33 * It stores a set of uniform parameters and refers to an OpenGL program object.
34 * Some uniform variables are pre-defined, like surface position and size,
35 * opacity, etc... Additionally, there may be user-defined uniforms.
41 * Creates a new shader instance by vertex and fragment shader name.
42 * @param vertFileName File name of vertex shader.
43 * @param fragFileName File name of fragment shader.
44 * @return new Shader instance, NULL if shader could not be loaded, compiled or linked.
46 static Shader* createShader(const string& vertFileName, const string& fragFileName);
54 * @return Unique ID of this instance
58 return m_uniqueShaderId;
62 * Start using this shader for rendering.
72 void setUniform(const ShaderUniform& uniform);
75 * Update uniform values.
76 * Please note that this method doesn't update the standard uniforms
77 * used for position, size, etc... They need to be set separately
78 * by loadCommonUniforms().
80 void loadUniforms(void);
83 * Load uniform values for common surface properties, like position,
84 * size, opacity, etc...
86 * @param uniforms Uniform values
87 * @param texCount texture count
89 void loadCommonUniforms(const ShaderProgram::CommonUniforms& uniforms, const int texCount) const
91 m_program.loadCommonUniforms(uniforms, texCount);
96 * Private constructor.
97 * New instances of this class are supposed to be created by createShader(...).
99 * @param program Program object to be used
101 Shader(ShaderProgram& program);
105 const unsigned int m_uniqueShaderId;
107 /// reference to OpenGL program object used by this shader instance
108 ShaderProgram& m_program;
110 /// a map of user-defined uniforms
111 UniformMap m_uniformMap;
114 static unsigned int m_nextUniqueShaderId;
117 #endif /* _SHADER_H_ */