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 ****************************************************************************/
20 #include "ShaderProgramGLES.h"
21 #include <GLES2/gl2ext.h>
22 #include <RenderUtil.h>
25 static const char defaultVertShaderBinary[] = {
26 #include "renderer_vert.cghex"
28 static const char defaultFragShaderBinary[] = {
29 #include "renderer_frag.cghex"
32 ShaderProgram* ShaderProgramGLES::createProgram(const std::string& vertName, const std::string& fragName)
35 ShaderProgramGLES* program = 0;
37 if (vertName=="default" && fragName=="default")
39 // load default shader from binary data
40 progHandle = RenderUtilLoadShaderSources("renderer_vert.glslv", "renderer_frag.glslf", GL_TRUE);
44 // load shader sources from file, compile and link them:
45 progHandle = RenderUtilLoadShaderSources(vertName.c_str(), fragName.c_str(), GL_FALSE);
50 // bind attrib locations for vertex positions and texture coordinates
51 glBindAttribLocation(progHandle, 0, "aPosition");
52 glBindAttribLocation(progHandle, 1, "aTexCoords");
54 // re-link the program as we have changed the attrib bindings
55 glLinkProgram(progHandle);
57 program = new ShaderProgramGLES(vertName, fragName, progHandle);
61 LOG_ERROR("ShaderProgramGLES", "Failed to create and link shader program");
67 ShaderProgramGLES::ShaderProgramGLES(const std::string& vertName, const std::string& fragName, GLuint handle)
68 : ShaderProgram(vertName, fragName)
71 // Update the uniform locations.
72 // Don't move this call to the base class constructor as we need
73 // to set the OpenGL program handle first.
74 updateCommonUniformLocations();
77 ShaderProgramGLES::~ShaderProgramGLES(void)
81 glDeleteProgram(_progHandle);
85 void ShaderProgramGLES::use(void) const
87 glUseProgram(_progHandle);