|
libcamera v0.7.2
Supporting cameras in Linux since 2019
|
Helper class for managing OpenGL ES operations. More...
Public Member Functions | |
| eGL () | |
| Construct an EGL helper. | |
| ~eGL () | |
| Destroy the EGL helper. | |
| int | initEGLContext () |
| Initialise 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. | |
| void | makeCurrent () |
| Make the EGL context current for the calling thread. | |
| int | compileVertexShader (GLuint &shaderId, Span< const unsigned char > shaderData, Span< const std::string > shaderEnv) |
| Compile a vertex shader. | |
| int | compileFragmentShader (GLuint &shaderId, Span< const unsigned char > shaderData, 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 | useProgram (GLuint programId) |
| Activate a shader program for rendering. | |
| void | deleteProgram (GLuint programId) |
| Delete a shader program. | |
| void | syncOutput () |
| Synchronise rendering output. | |
| void | flushOutput () |
| Flush the rendering pipeline. | |
Static Public Member Functions | |
| static bool | isAvailable () |
| Probe whether EGL surfaceless rendering is available. | |
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 | ( | ) |
Construct an EGL helper.
Creates an eGL instance with uninitialised context. Call initEGLContext() to set up the EGL display, context, and load extension functions.
| libcamera::eGL::~eGL | ( | ) |
Destroy the EGL helper.
Destroys the EGL context and surface if they were successfully created.
| 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.
| 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, |
| Span< const unsigned char > | shaderData, | ||
| 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, |
| Span< const unsigned char > | shaderData, | ||
| 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::deleteProgram | ( | GLuint | programId | ) |
Delete a shader program.
| [in] | programId | OpenGL program object ID |
Deletes a shader program and frees associated resources. The program must not be currently in use.
| 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:
|
static |
Probe whether EGL surfaceless rendering is available.
Checks if an EGL surfaceless display can be obtained and initialised. The display is immediately terminated so that no resources are leaked.
| 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.
| void libcamera::eGL::makeCurrent | ( | ) |
Make the EGL context current for the calling thread.
Binds the EGL context to the current thread, allowing OpenGL ES operations to be performed. Must be called from the thread that will perform rendering operations.
| 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::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.
| void libcamera::eGL::useProgram | ( | GLuint | programId | ) |
Activate a shader program for rendering.
| [in] | programId | OpenGL program object ID |
Sets the specified program as the current rendering program. All subsequent draw calls will use this program's shaders.