Jan Sebechlebsky | 5cb3996 | 2023-11-22 17:33:07 +0100 | [diff] [blame] | 1 | /* |
| 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 Sebechlebsky | 99492e3 | 2023-12-20 09:49:45 +0100 | [diff] [blame^] | 20 | #include <array> |
| 21 | |
Jan Sebechlebsky | 5cb3996 | 2023-11-22 17:33:07 +0100 | [diff] [blame] | 22 | #include "GLES/gl.h" |
| 23 | |
| 24 | namespace android { |
| 25 | namespace companion { |
| 26 | namespace virtualcamera { |
| 27 | |
| 28 | // Base class for EGL Shader programs representation. |
| 29 | class 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. |
| 45 | class EglTestPatternProgram : public EglProgram { |
| 46 | public: |
| 47 | EglTestPatternProgram(); |
| 48 | |
| 49 | bool draw(int width, int height, int frameNumber); |
| 50 | }; |
| 51 | |
| 52 | // Shader program to draw texture. |
| 53 | // |
| 54 | // Shader stretches the texture over the viewport (if the texture is not same |
| 55 | // aspect ratio as viewport, it will be deformed). |
| 56 | // |
| 57 | // TODO(b/301023410) Add support for translation / cropping. |
| 58 | class EglTextureProgram : public EglProgram { |
| 59 | public: |
Jan Sebechlebsky | 042d1fb | 2023-12-12 16:37:00 +0100 | [diff] [blame] | 60 | enum class TextureFormat { RGBA, YUV }; |
| 61 | |
| 62 | EglTextureProgram(TextureFormat textureFormat = TextureFormat::YUV); |
Jan Sebechlebsky | 5cb3996 | 2023-11-22 17:33:07 +0100 | [diff] [blame] | 63 | |
Jan Sebechlebsky | 99492e3 | 2023-12-20 09:49:45 +0100 | [diff] [blame^] | 64 | // Draw texture over whole viewport, applying transformMatrix to texture |
| 65 | // coordinates. |
| 66 | // |
| 67 | // Transform matrix is 4x4 matrix represented in column-major order and is |
| 68 | // applied to texture coordinates in (s,t,0,1), s,t from <0,1> range prior to |
| 69 | // sampling: |
| 70 | // |
| 71 | // textureCoord = transformMatrix * vec4(s,t,0,1).xy |
| 72 | bool draw(GLuint textureId, const std::array<float, 16>& transformMatrix); |
Jan Sebechlebsky | 5cb3996 | 2023-11-22 17:33:07 +0100 | [diff] [blame] | 73 | }; |
| 74 | |
| 75 | } // namespace virtualcamera |
| 76 | } // namespace companion |
| 77 | } // namespace android |
| 78 | |
| 79 | #endif // ANDROID_COMPANION_VIRTUALCAMERA_EGLPROGRAM_H |