libcamera v0.7.2 Supporting cameras in Linux since 2019

Loading...
Searching...
No Matches
libcamera::eGL Class Reference

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.

## Detailed Description

Helper class for managing OpenGL ES operations.

It provides:

- EGL context setup and management
- Extension function pointer retrieval
- Shader compilation and program linking
- DMA-BUF texture creation and management
- Synchronisation primitives

This class is designed to work with zero-copy buffers via DMA-BUF file descriptors.

## Constructor & Destructor Documentation

## ◆ eGL()

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.

## ◆ ~eGL()

libcamera::eGL::~eGL | ( |  | ) |

Destroy the EGL helper.

Destroys the EGL context and surface if they were successfully created.

## Member Function Documentation

## ◆ activateBindTexture()

void libcamera::eGL::activateBindTexture | ( | eGLImage & | eglImage | ) |

Activate a texture unit and bind a texture to that unit.

Parameters

  [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.

## ◆ attachTextureToFBO()

int libcamera::eGL::attachTextureToFBO | ( | eGLImage & | eglImage | ) |

Attach a texture to a frame-buffer-object.

Parameters

  [in,out] | eglImage | EGL image containing texture to attach to FBO

Helper function to make attachment of texture to FBO easy to reuse.

Returns
  0 on success, or -ENODEV on failure

## ◆ compileFragmentShader()

int libcamera::eGL::compileFragmentShader | ( | GLuint & | shaderId,
|  | Span< const unsigned char > | shaderData,
|  | Span< const std::string > | shaderEnv )

Compile a fragment shader.

Parameters

  [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.

Returns
  0 on success, or -EINVAL on compilation failure

## ◆ compileVertexShader()

int libcamera::eGL::compileVertexShader | ( | GLuint & | shaderId,
|  | Span< const unsigned char > | shaderData,
|  | Span< const std::string > | shaderEnv )

Compile a vertex shader.

Parameters

  [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.

Returns
  0 on success, or -EINVAL on compilation failure

## ◆ createInputDMABufTexture2D()

int libcamera::eGL::createInputDMABufTexture2D | ( | eGLImage & | eglImage,
|  | int | fd )

Create an input DMA-BUF backed texture.

Parameters

  [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.

Returns
  0 on success, or -ENODEV on failure

## ◆ createOutputDMABufTexture2D()

int libcamera::eGL::createOutputDMABufTexture2D | ( | eGLImage & | eglImage,
|  | int | fd )

Create an output DMA-BUF backed texture.

Parameters

  [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.

Returns
  0 on success, or -ENODEV on failure

## ◆ createOutputTexture2D()

void libcamera::eGL::createOutputTexture2D | ( | eGLImage & | eglImage | ) |

Create a 2D texture attached to an FBO for render-to-texture.

Parameters

  [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.

## ◆ createTexture2D()

void libcamera::eGL::createTexture2D | ( | eGLImage & | eglImage,
|  | void * | data )

Create a 2D texture from a memory buffer.

Parameters

  [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.

## ◆ deleteProgram()

void libcamera::eGL::deleteProgram | ( | GLuint | programId | ) |

Delete a shader program.

Parameters

  [in] | programId | OpenGL program object ID

Deletes a shader program and frees associated resources. The program must not be currently in use.

## ◆ dumpShaderSource()

void libcamera::eGL::dumpShaderSource | ( | GLuint | shaderId | ) |

Dump shader source code to the log.

Parameters

  [in] | shaderId | OpenGL shader object ID

Retrieves and logs the complete source code of a compiled shader. Useful for debugging shader compilation issues.

## ◆ flushOutput()

void libcamera::eGL::flushOutput | ( |  | ) |

Flush the rendering pipeline.

Calls glFlush().

## ◆ initEGLContext()

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:

- eglCreateImageKHR / eglDestroyImageKHR
- glEGLImageTargetTexture2DOES

Returns
  0 on success, or -ENODEV on failure

## ◆ isAvailable()

bool libcamera::eGL::isAvailable | ( |  | ) |
| 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.

Returns
  True if EGL surfaceless rendering is available, false otherwise

## ◆ linkProgram()

int libcamera::eGL::linkProgram | ( | GLuint & | programId,
|  | GLuint | vertexshaderId,
|  | GLuint | fragmentshaderId )

Link a shader program.

Parameters

  [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.

Returns
  0 on success, or -ENODEV on link failure

## ◆ makeCurrent()

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.

## ◆ pushEnv()

void libcamera::eGL::pushEnv | ( | std::vector< std::string > & | shaderEnv,
|  | const char * | str )

Add a preprocessor definition to shader environment.

Parameters

  [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.

## ◆ syncOutput()

void libcamera::eGL::syncOutput | ( |  | ) |

Synchronise rendering output.

Sychronise here. Calls glFinish() right now.

## ◆ updateTexture2D()

void libcamera::eGL::updateTexture2D | ( | eGLImage & | eglImage,
|  | void * | data )

Update a 2D texture already created.

Parameters

  [in,out] | eglImage | EGL image to associate with the texture
  | [data] | Data to update the texture with

Updates a 2D texture in VRAM.

## ◆ useProgram()

void libcamera::eGL::useProgram | ( | GLuint | programId | ) |

Activate a shader program for rendering.

Parameters

  [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.

The documentation for this class was generated from the following files:

- include/libcamera/internal/egl.h
- src/libcamera/egl.cpp