26#define EGL_EGLEXT_PROTOTYPES
28#include <EGL/eglext.h>
29#define GL_GLEXT_PROTOTYPES
31#include <GLES2/gl2ext.h>
62 eGLImage(GLint format, uint32_t width, uint32_t height, uint32_t stride, GLenum texture_unit, uint32_t texture_unit_uniform_id)
63 : format_(format), width_(width), height_(height), stride_(stride),
64 framesize_(stride * height),
65 texture_unit_uniform_id_(texture_unit_uniform_id),
66 texture_unit_(texture_unit)
68 glGenTextures(1, &texture_);
69 glGenFramebuffers(1, &fbo_);
80 glDeleteFramebuffers(1, &fbo_);
81 glDeleteTextures(1, &texture_);
94 bool dmabuf_import_failed_ =
false;
103 eGL(EGLDisplay display);
119 void pushEnv(std::vector<std::string> &shaderEnv,
const char *str);
122 std::span<const std::string> shaderEnv);
124 std::span<const std::string> shaderEnv);
125 int linkProgram(GLuint &programId, GLuint fragmentshaderId, GLuint vertexshaderId);
140 EGLDisplay display_ = EGL_NO_DISPLAY;
141 EGLContext context_ = EGL_NO_CONTEXT;
143 int compileShader(
int shaderType, GLuint &shaderId, std::span<const unsigned char> shaderData,
144 std::span<const std::string> shaderEnv);
146 int createDMABufTexture2D(
eGLImage &eglImage,
int fd,
bool output);
151 PFNGLEGLIMAGETARGETTEXTURE2DOESPROC glEGLImageTargetTexture2DOES;
152 PFNEGLCREATEIMAGEKHRPROC eglCreateImageKHR;
153 PFNEGLDESTROYIMAGEKHRPROC eglDestroyImageKHR;
#define LIBCAMERA_DISABLE_COPY_AND_MOVE(klass)
Disable copy and move construction and assignment of the klass.
Definition class.h:29
static pid_t currentId()
Retrieve the ID of the current thread.
Definition thread.cpp:511
Helper class for managing EGL image resources.
Definition egl.h:51
uint32_t offset_
Definition egl.h:88
~eGLImage()
Destroy the eGLImage.
Definition egl.h:78
GLuint texture_
Definition egl.h:92
GLuint fbo_
Definition egl.h:93
uint32_t stride_
Definition egl.h:87
uint32_t height_
Definition egl.h:86
GLenum texture_unit_
Definition egl.h:91
eGLImage(GLint format, uint32_t width, uint32_t height, uint32_t stride, GLenum texture_unit, uint32_t texture_unit_uniform_id)
Construct an eGLImage with explicit stride.
Definition egl.h:62
uint32_t framesize_
Definition egl.h:89
GLint format_
Definition egl.h:84
uint32_t texture_unit_uniform_id_
Definition egl.h:90
uint32_t width_
Definition egl.h:85
Helper class for managing OpenGL ES operations.
Definition egl.h:101
void resetEGLContext()
Destroy the EGL context.
Definition egl.cpp:462
void activateBindTexture(eGLImage &eglImage)
Activate a texture unit and bind a texture to that unit.
Definition egl.cpp:155
void flushOutput()
Flush the rendering pipeline.
Definition egl.cpp:104
int createInputDMABufTexture2D(eGLImage &eglImage, int fd)
Create an input DMA-BUF backed texture.
Definition egl.cpp:252
int linkProgram(GLuint &programId, GLuint fragmentshaderId, GLuint vertexshaderId)
Link a shader program.
Definition egl.cpp:635
int initEGLContext()
Initialise the EGL context.
Definition egl.cpp:379
int createOutputDMABufTexture2D(eGLImage &eglImage, int fd)
Create an output DMA-BUF backed texture.
Definition egl.cpp:271
void pushEnv(std::vector< std::string > &shaderEnv, const char *str)
Add a preprocessor definition to shader environment.
Definition egl.cpp:498
void createOutputTexture2D(eGLImage &eglImage)
Create a 2D texture attached to an FBO for render-to-texture.
Definition egl.cpp:358
void assertThread() const
Assert that the execution is in the right thread.
Definition egl.h:130
int compileFragmentShader(GLuint &shaderId, std::span< const unsigned char > shaderData, std::span< const std::string > shaderEnv)
Compile a fragment shader.
Definition egl.cpp:535
int attachTextureToFBO(eGLImage &eglImage)
Attach a texture to a frame-buffer-object.
Definition egl.cpp:128
void syncOutput()
Synchronise rendering output.
Definition egl.cpp:91
int compileVertexShader(GLuint &shaderId, std::span< const unsigned char > shaderData, std::span< const std::string > shaderEnv)
Compile a vertex shader.
Definition egl.cpp:517
~eGL()
Destroy the EGL helper.
Definition egl.cpp:80
void updateTexture2D(eGLImage &eglImage, void *data)
Update a 2D texture already created.
Definition egl.cpp:341
void dumpShaderSource(GLuint shaderId)
Dump shader source code to the log.
Definition egl.cpp:604
void createTexture2D(eGLImage &eglImage, void *data)
Create a 2D texture from a memory buffer.
Definition egl.cpp:288
static EGLDisplay probeDisplay()
Try to create an EGL display for surfaceless rendering.
Definition egl.cpp:313
#define LOG_DECLARE_CATEGORY(name)
Declare a category of log messages.
Definition log.h:51
#define ASSERT(condition)
Abort program execution if assertion fails.
Definition log.h:159
Top-level libcamera namespace.
Definition backtrace.h:17
Miscellaneous utility functions.