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.
62 lines
1.6 KiB
C++
62 lines
1.6 KiB
C++
//
|
|
// Created by Marc Rousavy on 29.08.23.
|
|
//
|
|
|
|
#pragma once
|
|
|
|
#include "PassThroughShader.h"
|
|
#include <EGL/egl.h>
|
|
#include <GLES2/gl2.h>
|
|
#include <android/native_window.h>
|
|
#include <memory>
|
|
|
|
#include "OpenGLContext.h"
|
|
#include "OpenGLTexture.h"
|
|
|
|
namespace vision {
|
|
|
|
class OpenGLRenderer {
|
|
public:
|
|
/**
|
|
* Create a new instance of the OpenGLRenderer that draws to an on-screen window surface.
|
|
* This will not perform any OpenGL operations yet, and is therefore safe to call from any Thread.
|
|
*
|
|
* Note: The `surface` is considered moved, and the OpenGL context will release it when it is
|
|
* being deleted.
|
|
*/
|
|
static std::unique_ptr<OpenGLRenderer> CreateWithWindowSurface(std::shared_ptr<OpenGLContext> context, ANativeWindow* surface);
|
|
/**
|
|
* Destroy the OpenGL Context. This needs to be called on the same thread that `use()` was called.
|
|
*/
|
|
~OpenGLRenderer();
|
|
|
|
/**
|
|
* Renders the given Texture to the Surface
|
|
*/
|
|
void renderTextureToSurface(const OpenGLTexture& texture, float* transformMatrix);
|
|
|
|
/**
|
|
* Destroys the OpenGL context. This needs to be called on the same thread that `use()` was
|
|
* called. After calling `destroy()`, it is legal to call `use()` again, which will re-construct
|
|
* everything.
|
|
*/
|
|
void destroy();
|
|
|
|
private:
|
|
explicit OpenGLRenderer(std::shared_ptr<OpenGLContext> context, ANativeWindow* surface);
|
|
|
|
private:
|
|
int _width = 0, _height = 0;
|
|
std::shared_ptr<OpenGLContext> _context;
|
|
ANativeWindow* _outputSurface;
|
|
EGLSurface _surface = EGL_NO_SURFACE;
|
|
|
|
private:
|
|
PassThroughShader _passThroughShader;
|
|
|
|
private:
|
|
static constexpr auto TAG = "OpenGLRenderer";
|
|
};
|
|
|
|
} // namespace vision
|