| Mathias Agopian | 3f84483 | 2013-08-07 21:24:32 -0700 | [diff] [blame] | 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> | 
| Peiyong Lin | 833074a | 2018-08-28 11:53:54 -0700 | [diff] [blame] | 23 | #include <renderengine/private/Description.h> | 
|  | 24 | #include "ProgramCache.h" | 
| Mathias Agopian | 3f84483 | 2013-08-07 21:24:32 -0700 | [diff] [blame] | 25 |  | 
|  | 26 | namespace android { | 
|  | 27 |  | 
|  | 28 | class String8; | 
|  | 29 |  | 
| Peiyong Lin | 833074a | 2018-08-28 11:53:54 -0700 | [diff] [blame] | 30 | namespace renderengine { | 
|  | 31 | namespace gl { | 
|  | 32 |  | 
| Mathias Agopian | 3f84483 | 2013-08-07 21:24:32 -0700 | [diff] [blame] | 33 | /* | 
|  | 34 | * Abstracts a GLSL program comprising a vertex and fragment shader | 
|  | 35 | */ | 
|  | 36 | class Program { | 
|  | 37 | public: | 
|  | 38 | // known locations for position and texture coordinates | 
| Chia-I Wu | b027f80 | 2017-11-29 14:00:52 -0800 | [diff] [blame] | 39 | enum { position = 0, texCoords = 1 }; | 
| Mathias Agopian | 3f84483 | 2013-08-07 21:24:32 -0700 | [diff] [blame] | 40 |  | 
|  | 41 | Program(const ProgramCache::Key& needs, const char* vertex, const char* fragment); | 
|  | 42 | ~Program(); | 
|  | 43 |  | 
|  | 44 | /* whether this object is usable */ | 
|  | 45 | bool isValid() const; | 
|  | 46 |  | 
|  | 47 | /* Binds this program to the GLES context */ | 
|  | 48 | void use(); | 
|  | 49 |  | 
|  | 50 | /* Returns the location of the specified attribute */ | 
|  | 51 | GLuint getAttrib(const char* name) const; | 
|  | 52 |  | 
|  | 53 | /* Returns the location of the specified uniform */ | 
|  | 54 | GLint getUniform(const char* name) const; | 
|  | 55 |  | 
|  | 56 | /* set-up uniforms from the description */ | 
|  | 57 | void setUniforms(const Description& desc); | 
|  | 58 |  | 
| Mathias Agopian | 3f84483 | 2013-08-07 21:24:32 -0700 | [diff] [blame] | 59 | private: | 
|  | 60 | GLuint buildShader(const char* source, GLenum type); | 
|  | 61 | String8& dumpShader(String8& result, GLenum type); | 
|  | 62 |  | 
|  | 63 | // whether the initialization succeeded | 
|  | 64 | bool mInitialized; | 
|  | 65 |  | 
|  | 66 | // Name of the OpenGL program and shaders | 
|  | 67 | GLuint mProgram; | 
|  | 68 | GLuint mVertexShader; | 
|  | 69 | GLuint mFragmentShader; | 
|  | 70 |  | 
|  | 71 | /* location of the projection matrix uniform */ | 
|  | 72 | GLint mProjectionMatrixLoc; | 
|  | 73 |  | 
| Mathias Agopian | 3f84483 | 2013-08-07 21:24:32 -0700 | [diff] [blame] | 74 | /* location of the texture matrix uniform */ | 
|  | 75 | GLint mTextureMatrixLoc; | 
|  | 76 |  | 
|  | 77 | /* location of the sampler uniform */ | 
|  | 78 | GLint mSamplerLoc; | 
|  | 79 |  | 
| Mathias Agopian | 3f84483 | 2013-08-07 21:24:32 -0700 | [diff] [blame] | 80 | /* location of the color uniform */ | 
|  | 81 | GLint mColorLoc; | 
| Peiyong Lin | fb06930 | 2018-04-25 14:34:31 -0700 | [diff] [blame] | 82 |  | 
|  | 83 | /* location of display luminance uniform */ | 
|  | 84 | GLint mDisplayMaxLuminanceLoc; | 
| Peiyong Lin | a296b0c | 2018-04-30 16:55:29 -0700 | [diff] [blame] | 85 |  | 
|  | 86 | /* location of transform matrix */ | 
|  | 87 | GLint mInputTransformMatrixLoc; | 
|  | 88 | GLint mOutputTransformMatrixLoc; | 
| Mathias Agopian | 3f84483 | 2013-08-07 21:24:32 -0700 | [diff] [blame] | 89 | }; | 
|  | 90 |  | 
| Peiyong Lin | 833074a | 2018-08-28 11:53:54 -0700 | [diff] [blame] | 91 | }  // namespace gl | 
|  | 92 | }  // namespace renderengine | 
|  | 93 | }  // namespace android | 
| Mathias Agopian | 3f84483 | 2013-08-07 21:24:32 -0700 | [diff] [blame] | 94 |  | 
|  | 95 | #endif /* SF_RENDER_ENGINE_PROGRAM_H */ |