| 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 | 
| Lucas Dupin | 1b6531c | 2018-07-05 17:18:21 -0700 | [diff] [blame] | 39 | enum { | 
|  | 40 | /* position of each vertex for vertex shader */ | 
|  | 41 | position = 0, | 
|  | 42 |  | 
|  | 43 | /* UV coordinates for texture mapping */ | 
|  | 44 | texCoords = 1, | 
|  | 45 |  | 
|  | 46 | /* Crop coordinates, in pixels */ | 
| Vishnu Nair | 440992f | 2019-12-09 19:53:19 -0800 | [diff] [blame] | 47 | cropCoords = 2, | 
|  | 48 |  | 
|  | 49 | /* Shadow color */ | 
|  | 50 | shadowColor = 3, | 
|  | 51 |  | 
|  | 52 | /* Shadow params */ | 
|  | 53 | shadowParams = 4, | 
| Lucas Dupin | 1b6531c | 2018-07-05 17:18:21 -0700 | [diff] [blame] | 54 | }; | 
| Mathias Agopian | 3f84483 | 2013-08-07 21:24:32 -0700 | [diff] [blame] | 55 |  | 
|  | 56 | Program(const ProgramCache::Key& needs, const char* vertex, const char* fragment); | 
| Alec Mouri | 2725c09 | 2020-11-25 09:53:56 -0800 | [diff] [blame] | 57 | ~Program(); | 
| Mathias Agopian | 3f84483 | 2013-08-07 21:24:32 -0700 | [diff] [blame] | 58 |  | 
|  | 59 | /* whether this object is usable */ | 
|  | 60 | bool isValid() const; | 
|  | 61 |  | 
|  | 62 | /* Binds this program to the GLES context */ | 
|  | 63 | void use(); | 
|  | 64 |  | 
|  | 65 | /* Returns the location of the specified attribute */ | 
|  | 66 | GLuint getAttrib(const char* name) const; | 
|  | 67 |  | 
|  | 68 | /* Returns the location of the specified uniform */ | 
|  | 69 | GLint getUniform(const char* name) const; | 
|  | 70 |  | 
|  | 71 | /* set-up uniforms from the description */ | 
|  | 72 | void setUniforms(const Description& desc); | 
|  | 73 |  | 
| Mathias Agopian | 3f84483 | 2013-08-07 21:24:32 -0700 | [diff] [blame] | 74 | private: | 
|  | 75 | GLuint buildShader(const char* source, GLenum type); | 
| Mathias Agopian | 3f84483 | 2013-08-07 21:24:32 -0700 | [diff] [blame] | 76 |  | 
|  | 77 | // whether the initialization succeeded | 
|  | 78 | bool mInitialized; | 
|  | 79 |  | 
|  | 80 | // Name of the OpenGL program and shaders | 
|  | 81 | GLuint mProgram; | 
|  | 82 | GLuint mVertexShader; | 
|  | 83 | GLuint mFragmentShader; | 
|  | 84 |  | 
|  | 85 | /* location of the projection matrix uniform */ | 
|  | 86 | GLint mProjectionMatrixLoc; | 
|  | 87 |  | 
| Mathias Agopian | 3f84483 | 2013-08-07 21:24:32 -0700 | [diff] [blame] | 88 | /* location of the texture matrix uniform */ | 
|  | 89 | GLint mTextureMatrixLoc; | 
|  | 90 |  | 
|  | 91 | /* location of the sampler uniform */ | 
|  | 92 | GLint mSamplerLoc; | 
|  | 93 |  | 
| Mathias Agopian | 3f84483 | 2013-08-07 21:24:32 -0700 | [diff] [blame] | 94 | /* location of the color uniform */ | 
|  | 95 | GLint mColorLoc; | 
| Peiyong Lin | fb06930 | 2018-04-25 14:34:31 -0700 | [diff] [blame] | 96 |  | 
|  | 97 | /* location of display luminance uniform */ | 
|  | 98 | GLint mDisplayMaxLuminanceLoc; | 
| Peiyong Lin | 1a70eca | 2019-11-15 09:33:33 -0800 | [diff] [blame] | 99 | /* location of max mastering luminance uniform */ | 
|  | 100 | GLint mMaxMasteringLuminanceLoc; | 
|  | 101 | /* location of max content luminance uniform */ | 
|  | 102 | GLint mMaxContentLuminanceLoc; | 
| Peiyong Lin | a296b0c | 2018-04-30 16:55:29 -0700 | [diff] [blame] | 103 |  | 
|  | 104 | /* location of transform matrix */ | 
|  | 105 | GLint mInputTransformMatrixLoc; | 
|  | 106 | GLint mOutputTransformMatrixLoc; | 
| KaiChieh Chuang | 436fc19 | 2020-09-07 13:48:42 +0800 | [diff] [blame] | 107 | GLint mDisplayColorMatrixLoc; | 
| Lucas Dupin | 1b6531c | 2018-07-05 17:18:21 -0700 | [diff] [blame] | 108 |  | 
|  | 109 | /* location of corner radius uniform */ | 
|  | 110 | GLint mCornerRadiusLoc; | 
|  | 111 |  | 
|  | 112 | /* location of surface crop origin uniform, for rounded corner clipping */ | 
|  | 113 | GLint mCropCenterLoc; | 
| Mathias Agopian | 3f84483 | 2013-08-07 21:24:32 -0700 | [diff] [blame] | 114 | }; | 
|  | 115 |  | 
| Peiyong Lin | 46080ef | 2018-10-26 18:43:14 -0700 | [diff] [blame] | 116 | } // namespace gl | 
|  | 117 | } // namespace renderengine | 
|  | 118 | } // namespace android | 
| Mathias Agopian | 3f84483 | 2013-08-07 21:24:32 -0700 | [diff] [blame] | 119 |  | 
|  | 120 | #endif /* SF_RENDER_ENGINE_PROGRAM_H */ |