blob: d09f11e2e4aa64d9b3dbe9d7a806d51a32d03258 [file] [log] [blame]
Jan Sebechlebsky5cb39962023-11-22 17:33:07 +01001/*
2 * Copyright (C) 2023 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 ANDROID_COMPANION_VIRTUALCAMERA_EGLPROGRAM_H
18#define ANDROID_COMPANION_VIRTUALCAMERA_EGLPROGRAM_H
19
Jan Sebechlebsky99492e32023-12-20 09:49:45 +010020#include <array>
21
Jan Sebechlebsky5cb39962023-11-22 17:33:07 +010022#include "GLES/gl.h"
23
24namespace android {
25namespace companion {
26namespace virtualcamera {
27
28// Base class for EGL Shader programs representation.
29class EglProgram {
30 public:
31 virtual ~EglProgram();
32
33 // Returns whether the EGL Program was successfully compiled and linked.
34 bool isInitialized() const;
35
36 protected:
37 // Compile & link program from the vertex & fragment shader source.
38 bool initialize(const char* vertexShaderSrc, const char* fragmentShaderSrc);
39 GLuint mProgram;
40 // Whether the EGL Program was successfully compiled and linked.
41 bool mIsInitialized = false;
42};
43
44// Shader program to draw Julia Set test pattern.
45class EglTestPatternProgram : public EglProgram {
46 public:
47 EglTestPatternProgram();
48
Jan Sebechlebsky288900f2024-05-24 14:47:54 +020049 bool draw(int frameNumber);
50
51 private:
52 int mPositionHandle = -1;
53 int mTextureCoordHandle = -1;
54 int mCHandle = -1;
Jan Sebechlebsky5cb39962023-11-22 17:33:07 +010055};
56
57// Shader program to draw texture.
58//
59// Shader stretches the texture over the viewport (if the texture is not same
60// aspect ratio as viewport, it will be deformed).
61//
62// TODO(b/301023410) Add support for translation / cropping.
63class EglTextureProgram : public EglProgram {
64 public:
Jan Sebechlebsky042d1fb2023-12-12 16:37:00 +010065 enum class TextureFormat { RGBA, YUV };
66
67 EglTextureProgram(TextureFormat textureFormat = TextureFormat::YUV);
Jan Sebechlebskyca2d7972023-12-22 13:02:51 +010068 virtual ~EglTextureProgram();
Jan Sebechlebsky5cb39962023-11-22 17:33:07 +010069
Jan Sebechlebsky99492e32023-12-20 09:49:45 +010070 // Draw texture over whole viewport, applying transformMatrix to texture
71 // coordinates.
72 //
73 // Transform matrix is 4x4 matrix represented in column-major order and is
74 // applied to texture coordinates in (s,t,0,1), s,t from <0,1> range prior to
75 // sampling:
76 //
77 // textureCoord = transformMatrix * vec4(s,t,0,1).xy
78 bool draw(GLuint textureId, const std::array<float, 16>& transformMatrix);
Jan Sebechlebskyca2d7972023-12-22 13:02:51 +010079
80 private:
81 int mPositionHandle = -1;
82 int mTextureCoordHandle = -1;
83 int mTransformMatrixHandle = -1;
84 int mTextureHandle = -1;
Jan Sebechlebsky5cb39962023-11-22 17:33:07 +010085};
86
87} // namespace virtualcamera
88} // namespace companion
89} // namespace android
90
91#endif // ANDROID_COMPANION_VIRTUALCAMERA_EGLPROGRAM_H