|
libcamera v0.7.0+1-4ceceb68
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 | destroyDMABufTexture (eGLImage &eglImage) |
| Destroy a DMA-BUF texture's EGL image. | |
| void | createTexture2D (eGLImage &eglImage, GLint format, uint32_t width, uint32_t height, void *data) |
| Create a 2D texture from a memory buffer. | |
| 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, const unsigned char *shaderData, unsigned int shaderDataLen, Span< const std::string > shaderEnv) |
| Compile a vertex shader. | |
| int | compileFragmentShader (GLuint &shaderId, const unsigned char *shaderData, unsigned int shaderDataLen, 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. | |
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.
| int libcamera::eGL::compileFragmentShader | ( | GLuint & | shaderId, |
| const unsigned char * | shaderData, | ||
| unsigned int | shaderDataLen, | ||
| Span< const std::string > | shaderEnv | ||
| ) |
Compile a fragment shader.
| [out] | shaderId | OpenGL shader object ID |
| [in] | shaderData | Pointer to shader source code |
| [in] | shaderDataLen | Length of shader source in bytes |
| [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, |
| const unsigned char * | shaderData, | ||
| unsigned int | shaderDataLen, | ||
| Span< const std::string > | shaderEnv | ||
| ) |
Compile a vertex shader.
| [out] | shaderId | OpenGL shader object ID |
| [in] | shaderData | Pointer to shader source code |
| [in] | shaderDataLen | Length of shader source in bytes |
| [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::createTexture2D | ( | eGLImage & | eglImage, |
| GLint | format, | ||
| uint32_t | width, | ||
| uint32_t | height, | ||
| void * | data | ||
| ) |
Create a 2D texture from a memory buffer.
| [in,out] | eglImage | EGL image to associate with the texture |
| [in] | format | OpenGL internal format (e.g., GL_RGB, GL_RGBA) |
| [in] | width | Texture width in pixels |
| [in] | height | Texture height in pixels |
| [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::destroyDMABufTexture | ( | eGLImage & | eglImage | ) |
Destroy a DMA-BUF texture's EGL image.
| [in,out] | eglImage | EGL image to destroy |
Destroys the EGL image associated with a DMA-BUF texture. The OpenGL texture and framebuffer objects are destroyed separately in the eGLImage destructor.
| 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.
| 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:
| 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::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.