1. Reverts 4e96eb77e0
(PR #1789) to bring the C++ OpenGL GPU Pipeline back.
2. Fixes the "initHybrid JNI not found" error by loading the native JNI/C++ library in `VideoPipeline.kt`.
This PR has two downsides:
1. `pixelFormat="yuv"` does not work on Android. OpenGL only works in RGB
2. OpenGL rendering is fast, but it has an overhead. I think for Camera -> Video Recording we shouldn't be using an entire OpenGL rendering pipeline.
The original plan was to use something similar to how it works on iOS by just passing GPU buffers around, but the android.media APIs just aren't as advanced yet. `ImageReader`/`ImageWriter` is way too buggy and doesn't really work with `MediaRecorder`/`MediaCodec`.
This sucks, I hope in the future we can use something like `AHardwareBuffer`s.
85 lines
1.9 KiB
C++
85 lines
1.9 KiB
C++
//
|
|
// Created by Marc Rousavy on 28.08.23.
|
|
//
|
|
|
|
#pragma once
|
|
|
|
#include <EGL/egl.h>
|
|
#include <GLES2/gl2.h>
|
|
|
|
#include "OpenGLTexture.h"
|
|
|
|
namespace vision {
|
|
|
|
#define NO_SHADER 0
|
|
#define NO_POSITION 0
|
|
#define NO_BUFFER 0
|
|
|
|
struct Vertex {
|
|
GLfloat position[2];
|
|
GLfloat texCoord[2];
|
|
};
|
|
|
|
class PassThroughShader {
|
|
public:
|
|
PassThroughShader() = default;
|
|
~PassThroughShader();
|
|
|
|
/**
|
|
* Draw the texture using this shader.
|
|
* Note: At the moment, only EXTERNAL textures are supported by the Shader.
|
|
*/
|
|
void draw(const OpenGLTexture& texture, float* transformMatrix);
|
|
|
|
private:
|
|
// Loading
|
|
static GLuint loadShader(GLenum shaderType, const char* shaderCode);
|
|
static GLuint createProgram();
|
|
|
|
private:
|
|
// Parameters
|
|
GLuint _programId = NO_SHADER;
|
|
GLuint _vertexBuffer = NO_BUFFER;
|
|
struct VertexParameters {
|
|
GLint aPosition = NO_POSITION;
|
|
GLint aTexCoord = NO_POSITION;
|
|
GLint uTransformMatrix = NO_POSITION;
|
|
} _vertexParameters;
|
|
struct FragmentParameters {
|
|
GLint uTexture = NO_POSITION;
|
|
} _fragmentParameters;
|
|
|
|
private:
|
|
// Statics
|
|
static constexpr Vertex VERTICES[] = {
|
|
{{-1.0f, -1.0f}, {0.0f, 0.0f}}, // bottom-left
|
|
{{1.0f, -1.0f}, {1.0f, 0.0f}}, // bottom-right
|
|
{{-1.0f, 1.0f}, {0.0f, 1.0f}}, // top-left
|
|
{{1.0f, 1.0f}, {1.0f, 1.0f}} // top-right
|
|
};
|
|
|
|
static constexpr char VERTEX_SHADER[] = R"(
|
|
attribute vec4 aPosition;
|
|
attribute vec2 aTexCoord;
|
|
uniform mat4 uTransformMatrix;
|
|
varying vec2 vTexCoord;
|
|
|
|
void main() {
|
|
gl_Position = aPosition;
|
|
vTexCoord = (uTransformMatrix * vec4(aTexCoord, 0.0, 1.0)).xy;
|
|
}
|
|
)";
|
|
static constexpr char FRAGMENT_SHADER[] = R"(
|
|
#extension GL_OES_EGL_image_external : require
|
|
precision mediump float;
|
|
varying vec2 vTexCoord;
|
|
uniform samplerExternalOES uTexture;
|
|
|
|
void main() {
|
|
gl_FragColor = texture2D(uTexture, vTexCoord);
|
|
}
|
|
)";
|
|
};
|
|
|
|
} // namespace vision
|