blob: bc9cf08b8b10e542b2d510d2669fb8682c4b5e9a [file] [log] [blame]
Mathias Agopian3f844832013-08-07 21:24:32 -07001/*
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 Lin833074a2018-08-28 11:53:54 -070023#include <renderengine/private/Description.h>
24#include "ProgramCache.h"
Mathias Agopian3f844832013-08-07 21:24:32 -070025
26namespace android {
27
28class String8;
29
Peiyong Lin833074a2018-08-28 11:53:54 -070030namespace renderengine {
31namespace gl {
32
Mathias Agopian3f844832013-08-07 21:24:32 -070033/*
34 * Abstracts a GLSL program comprising a vertex and fragment shader
35 */
36class Program {
37public:
38 // known locations for position and texture coordinates
Lucas Dupin1b6531c2018-07-05 17:18:21 -070039 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 */
47 cropCoords = 2
48 };
Mathias Agopian3f844832013-08-07 21:24:32 -070049
50 Program(const ProgramCache::Key& needs, const char* vertex, const char* fragment);
Chia-I Wud3b13cb2018-09-13 13:31:26 -070051 ~Program() = default;
Mathias Agopian3f844832013-08-07 21:24:32 -070052
53 /* whether this object is usable */
54 bool isValid() const;
55
56 /* Binds this program to the GLES context */
57 void use();
58
59 /* Returns the location of the specified attribute */
60 GLuint getAttrib(const char* name) const;
61
62 /* Returns the location of the specified uniform */
63 GLint getUniform(const char* name) const;
64
65 /* set-up uniforms from the description */
66 void setUniforms(const Description& desc);
67
Mathias Agopian3f844832013-08-07 21:24:32 -070068private:
69 GLuint buildShader(const char* source, GLenum type);
Mathias Agopian3f844832013-08-07 21:24:32 -070070
71 // whether the initialization succeeded
72 bool mInitialized;
73
74 // Name of the OpenGL program and shaders
75 GLuint mProgram;
76 GLuint mVertexShader;
77 GLuint mFragmentShader;
78
79 /* location of the projection matrix uniform */
80 GLint mProjectionMatrixLoc;
81
Mathias Agopian3f844832013-08-07 21:24:32 -070082 /* location of the texture matrix uniform */
83 GLint mTextureMatrixLoc;
84
85 /* location of the sampler uniform */
86 GLint mSamplerLoc;
87
Mathias Agopian3f844832013-08-07 21:24:32 -070088 /* location of the color uniform */
89 GLint mColorLoc;
Peiyong Linfb069302018-04-25 14:34:31 -070090
91 /* location of display luminance uniform */
92 GLint mDisplayMaxLuminanceLoc;
Peiyong Lina296b0c2018-04-30 16:55:29 -070093
94 /* location of transform matrix */
95 GLint mInputTransformMatrixLoc;
96 GLint mOutputTransformMatrixLoc;
Lucas Dupin1b6531c2018-07-05 17:18:21 -070097
98 /* location of corner radius uniform */
99 GLint mCornerRadiusLoc;
100
101 /* location of surface crop origin uniform, for rounded corner clipping */
102 GLint mCropCenterLoc;
Mathias Agopian3f844832013-08-07 21:24:32 -0700103};
104
Peiyong Lin46080ef2018-10-26 18:43:14 -0700105} // namespace gl
106} // namespace renderengine
107} // namespace android
Mathias Agopian3f844832013-08-07 21:24:32 -0700108
109#endif /* SF_RENDER_ENGINE_PROGRAM_H */