1 /* 2 * Copyright 2013 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #ifndef SF_RENDER_ENGINE_PROGRAM_H 18 #define SF_RENDER_ENGINE_PROGRAM_H 19 20 #include <stdint.h> 21 22 #include <GLES2/gl2.h> 23 24 #include "Description.h" 25 #include "ProgramCache.h" 26 27 namespace android { 28 29 class String8; 30 31 /* 32 * Abstracts a GLSL program comprising a vertex and fragment shader 33 */ 34 class Program { 35 public: 36 // known locations for position and texture coordinates 37 enum { position = 0, texCoords = 1 }; 38 39 Program(const ProgramCache::Key& needs, const char* vertex, const char* fragment); 40 ~Program(); 41 42 /* whether this object is usable */ 43 bool isValid() const; 44 45 /* Binds this program to the GLES context */ 46 void use(); 47 48 /* Returns the location of the specified attribute */ 49 GLuint getAttrib(const char* name) const; 50 51 /* Returns the location of the specified uniform */ 52 GLint getUniform(const char* name) const; 53 54 /* set-up uniforms from the description */ 55 void setUniforms(const Description& desc); 56 57 private: 58 GLuint buildShader(const char* source, GLenum type); 59 String8& dumpShader(String8& result, GLenum type); 60 61 // whether the initialization succeeded 62 bool mInitialized; 63 64 // Name of the OpenGL program and shaders 65 GLuint mProgram; 66 GLuint mVertexShader; 67 GLuint mFragmentShader; 68 69 /* location of the projection matrix uniform */ 70 GLint mProjectionMatrixLoc; 71 72 /* location of the texture matrix uniform */ 73 GLint mTextureMatrixLoc; 74 75 /* location of the sampler uniform */ 76 GLint mSamplerLoc; 77 78 /* location of the color uniform */ 79 GLint mColorLoc; 80 81 /* location of display luminance uniform */ 82 GLint mDisplayMaxLuminanceLoc; 83 84 /* location of transform matrix */ 85 GLint mInputTransformMatrixLoc; 86 GLint mOutputTransformMatrixLoc; 87 }; 88 89 } /* namespace android */ 90 91 #endif /* SF_RENDER_ENGINE_PROGRAM_H */ 92