|
libcamera v0.7.2+1-aebe4861-nvm
Supporting cameras in Linux since 2019
|
Helper class for managing OpenGL ES operations. More...
Public Member Functions | |
| eGL (EGLDisplay display) | |
| Construct an EGL helper. | |
| ~eGL () | |
| Destroy the EGL helper. | |
| int | initEGLContext () |
| Initialise the EGL context. | |
| void | resetEGLContext () |
| Destroy the EGL context. | |
| int | createInputDMABufTexture2D (eGLImage &eglImage, int fd) |
| Create an input DMA-BUF backed texture. | |
| int | createOutputDMABufTexture2D (eGLImage &eglImage, int fd) |
| Create an output DMA-BUF backed texture. | |
| void | createTexture2D (eGLImage &eglImage, void *data) |
| Create a 2D texture from a memory buffer. | |
| void | updateTexture2D (eGLImage &eglImage, void *data) |
| Update a 2D texture already created. | |
| void | createOutputTexture2D (eGLImage &eglImage) |
| Create a 2D texture attached to an FBO for render-to-texture. | |
| int | attachTextureToFBO (eGLImage &eglImage) |
| Attach a texture to a frame-buffer-object. | |
| void | activateBindTexture (eGLImage &eglImage) |
| Activate a texture unit and bind a texture to that unit. | |
| void | pushEnv (std::vector< std::string > &shaderEnv, const char *str) |
| Add a preprocessor definition to shader environment. | |
| int | compileVertexShader (GLuint &shaderId, std::span< const unsigned char > shaderData, std::span< const std::string > shaderEnv) |
| Compile a vertex shader. | |
| int | compileFragmentShader (GLuint &shaderId, std::span< const unsigned char > shaderData, std::span< const std::string > shaderEnv) |
| Compile a fragment shader. | |
| int | linkProgram (GLuint &programId, GLuint fragmentshaderId, GLuint vertexshaderId) |
| Link a shader program. | |
| void | dumpShaderSource (GLuint shaderId) |
| Dump shader source code to the log. | |
| void | syncOutput () |
| Synchronise rendering output. | |
| void | flushOutput () |
| Flush the rendering pipeline. | |
| void | assertThread () const |
| Assert that the execution is in the right thread. | |
Static Public Member Functions | |
| static EGLDisplay | probeDisplay () |
| Try to create an EGL display for surfaceless rendering. | |
Helper class for managing OpenGL ES operations.
It provides:
This class is designed to work with zero-copy buffers via DMA-BUF file descriptors.
| libcamera::eGL::eGL | ( | EGLDisplay | display | ) |
Construct an EGL helper.
| [in] | display | The EGL display to use |
Creates an eGL instance with uninitialised context. Call initEGLContext() to set up the EGL context, and load extension functions.
| libcamera::eGL::~eGL | ( | ) |
Destroy the EGL helper.
An instance must only be destroyed if there is no active EGL context.
| void libcamera::eGL::activateBindTexture | ( | eGLImage & | eglImage | ) |
Activate a texture unit and bind a texture to that unit.
| [in,out] | eglImage | EGL image containing data related to unit and texture id |
When we create a texture we will bind a texture unit and texture id so we can set filters. For the case where a texture already exists though we need to activate and bind an existing texture. This helper function facilitates both cases.
|
inline |
Assert that the execution is in the right thread.
Asserts that the execution is in the thread for which the created EGL context has been made current.
| int libcamera::eGL::attachTextureToFBO | ( | eGLImage & | eglImage | ) |
Attach a texture to a frame-buffer-object.
| [in,out] | eglImage | EGL image containing texture to attach to FBO |
Helper function to make attachment of texture to FBO easy to reuse.
| int libcamera::eGL::compileFragmentShader | ( | GLuint & | shaderId, |
| std::span< const unsigned char > | shaderData, | ||
| std::span< const std::string > | shaderEnv | ||
| ) |
Compile a fragment shader.
| [out] | shaderId | OpenGL shader object ID |
| [in] | shaderData | Shader source code |
| [in] | shaderEnv | Span of preprocessor definitions to prepend |
Compiles a fragment shader from source code with optional preprocessor definitions. On compilation failure, logs the shader info log.
| int libcamera::eGL::compileVertexShader | ( | GLuint & | shaderId, |
| std::span< const unsigned char > | shaderData, | ||
| std::span< const std::string > | shaderEnv | ||
| ) |
Compile a vertex shader.
| [out] | shaderId | OpenGL shader object ID |
| [in] | shaderData | Shader source code |
| [in] | shaderEnv | Span of preprocessor definitions to prepend |
Compiles a vertex shader from source code with optional preprocessor definitions. On compilation failure, logs the shader info log.
| int libcamera::eGL::createInputDMABufTexture2D | ( | eGLImage & | eglImage, |
| int | fd | ||
| ) |
Create an input DMA-BUF backed texture.
| [in,out] | eglImage | EGL image to associate with the DMA-BUF |
| [in] | fd | DMA-BUF file descriptor |
Creates an EGL image from a DMA-BUF file descriptor and binds it to a 2D texture for use as an input texture in shaders. The texture is configured with nearest filtering and clamp-to-edge wrapping.
| int libcamera::eGL::createOutputDMABufTexture2D | ( | eGLImage & | eglImage, |
| int | fd | ||
| ) |
Create an output DMA-BUF backed texture.
| [in,out] | eglImage | EGL image to associate with the DMA-BUF |
| [in] | fd | DMA-BUF file descriptor |
Creates an EGL image from a DMA-BUF file descriptor and binds it to a 2D texture, then attaches it to a framebuffer object for use as a render target. This enables zero-copy rendering directly to the DMA-BUF.
| void libcamera::eGL::createOutputTexture2D | ( | eGLImage & | eglImage | ) |
Create a 2D texture attached to an FBO for render-to-texture.
| [in,out] | eglImage | EGL image to associate with the texture |
Creates a 2D texture in VRAM. Subsequetly attach the texture to the texture unit specified in the eGLImage object.
| void libcamera::eGL::createTexture2D | ( | eGLImage & | eglImage, |
| void * | data | ||
| ) |
Create a 2D texture from a memory buffer.
| [in,out] | eglImage | EGL image to associate with the texture |
| [in] | data | Pointer to pixel data, or nullptr for uninitialised texture |
Creates a 2D texture from a CPU-accessible memory buffer. The texture is configured with nearest filtering and clamp-to-edge wrapping. This is useful for uploading static data like lookup tables or uniform color matrices to the GPU.
| void libcamera::eGL::dumpShaderSource | ( | GLuint | shaderId | ) |
Dump shader source code to the log.
| [in] | shaderId | OpenGL shader object ID |
Retrieves and logs the complete source code of a compiled shader. Useful for debugging shader compilation issues.
| void libcamera::eGL::flushOutput | ( | ) |
Flush the rendering pipeline.
Calls glFlush().
| int libcamera::eGL::initEGLContext | ( | ) |
Initialise the EGL context.
Sets up the EGL display, creates an OpenGL ES 2.0 context, and retrieves function pointers for required extensions including:
Each successful invocation must be followed by a call to resetEGLContext().
If a valid EGL context is already present, initialization attempts will be rejected.
| int libcamera::eGL::linkProgram | ( | GLuint & | programId, |
| GLuint | vertexshaderId, | ||
| GLuint | fragmentshaderId | ||
| ) |
Link a shader program.
| [out] | programId | OpenGL program object ID |
| [in] | fragmentshaderId | Compiled fragment shader ID |
| [in] | vertexshaderId | Compiled vertex shader ID |
Links vertex and fragment shaders into an executable shader program. On link failure, logs the program info log and deletes the program.
|
static |
Try to create an EGL display for surfaceless rendering.
Tries to create an EGL display for surfaceless rendering.
| void libcamera::eGL::pushEnv | ( | std::vector< std::string > & | shaderEnv, |
| const char * | str | ||
| ) |
Add a preprocessor definition to shader environment.
| [in,out] | shaderEnv | Vector of shader environment strings |
| [in] | str | Preprocessor definition string (e.g., "#define APPLY_RGB_PARAMETERS") |
Appends a preprocessor definition to the shader environment vector. These definitions are prepended to shader source code during compilation.
| void libcamera::eGL::resetEGLContext | ( | ) |
Destroy the EGL context.
This function destroys the EGL context created by initEGLContext(). If there is no valid EGL context, this function has no effect.
| void libcamera::eGL::syncOutput | ( | ) |
Synchronise rendering output.
Sychronise here. Calls glFinish() right now.
| void libcamera::eGL::updateTexture2D | ( | eGLImage & | eglImage, |
| void * | data | ||
| ) |
Update a 2D texture already created.
| [in,out] | eglImage | EGL image to associate with the texture |
| [data] | Data to update the texture with |
Updates a 2D texture in VRAM.