28#define EGL_EGLEXT_PROTOTYPES
30#include <EGL/eglext.h>
31#define GL_GLEXT_PROTOTYPES
33#include <GLES2/gl2ext.h>
64 eGLImage(GLint format, uint32_t width, uint32_t height, uint32_t stride, GLenum texture_unit, uint32_t texture_unit_uniform_id)
65 : format_(format), width_(width), height_(height), stride_(stride),
66 framesize_(stride * height),
67 texture_unit_uniform_id_(texture_unit_uniform_id),
68 texture_unit_(texture_unit)
70 glGenTextures(1, &texture_);
71 glGenFramebuffers(1, &fbo_);
82 glDeleteFramebuffers(1, &fbo_);
83 glDeleteTextures(1, &texture_);
96 bool dmabuf_import_failed_ =
false;
105 eGL(EGLDisplay display);
121 void pushEnv(std::vector<std::string> &shaderEnv,
const char *str);
124 std::span<const std::string> shaderEnv);
126 std::span<const std::string> shaderEnv);
127 int linkProgram(GLuint &programId, GLuint fragmentshaderId, GLuint vertexshaderId);
142 EGLDisplay display_ = EGL_NO_DISPLAY;
143 EGLContext context_ = EGL_NO_CONTEXT;
145 int compileShader(
int shaderType, GLuint &shaderId, std::span<const unsigned char> shaderData,
146 std::span<const std::string> shaderEnv);
148 int createDMABufTexture2D(
eGLImage &eglImage,
int fd,
bool output);
153 PFNGLEGLIMAGETARGETTEXTURE2DOESPROC glEGLImageTargetTexture2DOES;
154 PFNEGLCREATEIMAGEKHRPROC eglCreateImageKHR;
155 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:53
uint32_t offset_
Definition egl.h:90
~eGLImage()
Destroy the eGLImage.
Definition egl.h:80
GLuint texture_
Definition egl.h:94
GLuint fbo_
Definition egl.h:95
uint32_t stride_
Definition egl.h:89
uint32_t height_
Definition egl.h:88
GLenum texture_unit_
Definition egl.h:93
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:64
uint32_t framesize_
Definition egl.h:91
GLint format_
Definition egl.h:86
uint32_t texture_unit_uniform_id_
Definition egl.h:92
uint32_t width_
Definition egl.h:87
Helper class for managing OpenGL ES operations.
Definition egl.h:103
void createTexture2D(eGLImage &eglImage, const void *data, GLint filter)
Create a 2D texture from a memory buffer.
Definition egl.cpp:289
void resetEGLContext()
Destroy the EGL context.
Definition egl.cpp:463
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:636
int initEGLContext()
Initialise the EGL context.
Definition egl.cpp:380
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:499
void createOutputTexture2D(eGLImage &eglImage)
Create a 2D texture attached to an FBO for render-to-texture.
Definition egl.cpp:359
void assertThread() const
Assert that the execution is in the right thread.
Definition egl.h:132
int compileFragmentShader(GLuint &shaderId, std::span< const unsigned char > shaderData, std::span< const std::string > shaderEnv)
Compile a fragment shader.
Definition egl.cpp:536
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:518
~eGL()
Destroy the EGL helper.
Definition egl.cpp:80
void dumpShaderSource(GLuint shaderId)
Dump shader source code to the log.
Definition egl.cpp:605
void updateTexture2D(eGLImage &eglImage, const void *data)
Update a 2D texture already created.
Definition egl.cpp:342
static EGLDisplay probeDisplay()
Try to create an EGL display for surfaceless rendering.
Definition egl.cpp:314
#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.