blob: b1ce8cf6c18b159c44b866cddb49c263ef1044b3 [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
Chia-I Wub027f802017-11-29 14:00:52 -080039 enum { position = 0, texCoords = 1 };
Mathias Agopian3f844832013-08-07 21:24:32 -070040
41 Program(const ProgramCache::Key& needs, const char* vertex, const char* fragment);
Chia-I Wud3b13cb2018-09-13 13:31:26 -070042 ~Program() = default;
Mathias Agopian3f844832013-08-07 21:24:32 -070043
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 Agopian3f844832013-08-07 21:24:32 -070059private:
60 GLuint buildShader(const char* source, GLenum type);
Mathias Agopian3f844832013-08-07 21:24:32 -070061
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
Mathias Agopian3f844832013-08-07 21:24:32 -070073 /* location of the texture matrix uniform */
74 GLint mTextureMatrixLoc;
75
76 /* location of the sampler uniform */
77 GLint mSamplerLoc;
78
Mathias Agopian3f844832013-08-07 21:24:32 -070079 /* location of the color uniform */
80 GLint mColorLoc;
Peiyong Linfb069302018-04-25 14:34:31 -070081
82 /* location of display luminance uniform */
83 GLint mDisplayMaxLuminanceLoc;
Peiyong Lina296b0c2018-04-30 16:55:29 -070084
85 /* location of transform matrix */
86 GLint mInputTransformMatrixLoc;
87 GLint mOutputTransformMatrixLoc;
Mathias Agopian3f844832013-08-07 21:24:32 -070088};
89
Peiyong Lin833074a2018-08-28 11:53:54 -070090} // namespace gl
91} // namespace renderengine
92} // namespace android
Mathias Agopian3f844832013-08-07 21:24:32 -070093
94#endif /* SF_RENDER_ENGINE_PROGRAM_H */