Stability Fixes, adapted to new Interfaces, Rendering concept rewritten
[profile/ivi/layer-management.git] / LayerManagerPlugins / Renderers / Platform / BeagleRenderer / include / ShaderProgramBeagle.h
1 /***************************************************************************
2 *
3 * Copyright 2010,2011 BMW Car IT GmbH
4 *
5 *
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
9 *
10 *               http://www.apache.org/licenses/LICENSE-2.0
11 *
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.
17 *
18 ****************************************************************************/
19
20 #ifndef BEAGLESHADERPROGRAM_H_
21 #define BEAGLESHADERPROGRAM_H_
22
23 #include <ShaderProgram.h>
24 #include <GLES2/gl2.h>
25
26
27 /// pointer to shader program creator function
28 typedef ShaderProgram* (*PfnShaderProgramCreator)(const std::string&, const std::string&);
29
30 /**
31  * Factory for creating platform specific shader programs.
32  */
33 class ShaderProgramBeagle : public ShaderProgram
34 {
35 public:
36         /**
37          * Create a new shader program.
38          *
39          * @param vertName   File name of vertex shader.
40          * @param fragName   File name of fragment shader.
41          * @return new Program instance, NULL if program could not be created.
42          */
43         static ShaderProgram* createProgram(const std::string& vertName, const std::string& fragName);
44
45         /**
46          * Destructor
47          */
48         virtual ~ShaderProgramBeagle(void);
49
50         /**
51          * Start using the shader program for rendering.
52          */
53         virtual void use(void) const;
54
55         virtual int getUniformLocation(const char* name) const
56         {
57                 return glGetUniformLocation(_progHandle, name);
58         }
59
60         virtual void uniform1iv(int location, int count, const int* v) const
61         {
62                 glUniform1iv(location, count, v);
63         }
64
65         virtual void uniform1fv(int location, int count, const float* v) const
66         {
67                 glUniform1fv(location, count, v);
68         }
69
70         virtual void uniform2fv(int location, int count, const float* v) const
71         {
72                 glUniform2fv(location, count, v);
73         }
74
75         virtual void uniform3fv(int location, int count, const float* v) const
76         {
77                 glUniform3fv(location, count, v);
78         }
79
80         virtual void uniform4fv(int location, int count, const float* v) const
81         {
82                 glUniform4fv(location, count, v);
83         }
84
85         virtual void uniformMatrix2fv(int location, int count, bool transpose, const float* v) const
86         {
87                 glUniformMatrix2fv(location, count, transpose, v);
88         }
89
90         virtual void uniformMatrix3fv(int location, int count, bool transpose, const float* v) const
91         {
92                 glUniformMatrix3fv(location, count, transpose, v);
93         }
94
95         virtual void uniformMatrix4fv(int location, int count, bool transpose, const float* v) const
96         {
97                 glUniformMatrix4fv(location, count, transpose, v);
98         }
99
100 protected:
101         /**
102          * Protected constructor.
103          * New instances of this class are supposed to be created by ShaderProgramBeagle::createProgram.
104          *
105          * @param vertName    File name of vertex shader.
106          * @param fragName    File name of fragment shader.
107          */
108         ShaderProgramBeagle(const std::string& vertName, const std::string& fragName, GLuint handle);
109
110 private:
111         /// OpenGL ES program handle
112         GLuint _progHandle;
113 };
114
115 #endif /* BEAGLESHADERPROGRAM_H_ */