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 27namespace android { 28 29class String8; 30 31/* 32 * Abstracts a GLSL program comprising a vertex and fragment shader 33 */ 34class Program { 35public: 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 58private: 59 GLuint buildShader(const char* source, GLenum type); 60 String8& dumpShader(String8& result, GLenum type); 61 62 // whether the initialization succeeded 63 bool mInitialized; 64 65 // Name of the OpenGL program and shaders 66 GLuint mProgram; 67 GLuint mVertexShader; 68 GLuint mFragmentShader; 69 70 /* location of the projection matrix uniform */ 71 GLint mProjectionMatrixLoc; 72 73 /* location of the color matrix uniform */ 74 GLint mColorMatrixLoc; 75 76 /* location of the texture matrix uniform */ 77 GLint mTextureMatrixLoc; 78 79 /* location of the sampler uniform */ 80 GLint mSamplerLoc; 81 82 /* location of the alpha plane uniform */ 83 GLint mAlphaPlaneLoc; 84 85 /* location of the color uniform */ 86 GLint mColorLoc; 87}; 88 89 90} /* namespace android */ 91 92#endif /* SF_RENDER_ENGINE_PROGRAM_H */ 93