blob: ae796c5852f827117bb8fb00d731eb9ac9c0444b [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>
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
Chia-I Wub027f802017-11-29 14:00:52 -080037 enum { position = 0, texCoords = 1 };
Mathias Agopian3f844832013-08-07 21:24:32 -070038
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
Mathias Agopian3f844832013-08-07 21:24:32 -070057private:
58 GLuint buildShader(const char* source, GLenum type);
59 String8& dumpShader(String8& result, GLenum type);
60
61 // whether the initialization succeeded
62 bool mInitialized;
63
64 // Name of the OpenGL program and shaders
65 GLuint mProgram;
66 GLuint mVertexShader;
67 GLuint mFragmentShader;
68
69 /* location of the projection matrix uniform */
70 GLint mProjectionMatrixLoc;
71
Mathias Agopian3f844832013-08-07 21:24:32 -070072 /* location of the texture matrix uniform */
73 GLint mTextureMatrixLoc;
74
75 /* location of the sampler uniform */
76 GLint mSamplerLoc;
77
Mathias Agopian3f844832013-08-07 21:24:32 -070078 /* location of the color uniform */
79 GLint mColorLoc;
Peiyong Linfb069302018-04-25 14:34:31 -070080
81 /* location of display luminance uniform */
82 GLint mDisplayMaxLuminanceLoc;
Peiyong Lina296b0c2018-04-30 16:55:29 -070083
84 /* location of transform matrix */
85 GLint mInputTransformMatrixLoc;
86 GLint mOutputTransformMatrixLoc;
Mathias Agopian3f844832013-08-07 21:24:32 -070087};
88
Mathias Agopian3f844832013-08-07 21:24:32 -070089} /* namespace android */
90
91#endif /* SF_RENDER_ENGINE_PROGRAM_H */