| Message ID | 20260624085849.873784-3-bryan.odonoghue@linaro.org |
|---|---|
| State | New |
| Headers | show |
| Series |
|
| Related | show |
On 24.06.26 10:58, Bryan O'Donoghue wrote: > This method does what it says on the tin. It attaches a texture to a > framebuffer object, splitting existing code into a helper function which we > will use in subsequent patches. > > Signed-off-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org> LGTM. Reviewed-by: Robert Mader <robert.mader@collabora.com> > --- > include/libcamera/internal/egl.h | 2 ++ > src/libcamera/egl.cpp | 42 +++++++++++++++++++++++--------- > 2 files changed, 32 insertions(+), 12 deletions(-) > > diff --git a/include/libcamera/internal/egl.h b/include/libcamera/internal/egl.h > index f7bfb28d4..4b0757afd 100644 > --- a/include/libcamera/internal/egl.h > +++ b/include/libcamera/internal/egl.h > @@ -109,6 +109,8 @@ public: > int createOutputDMABufTexture2D(eGLImage &eglImage, int fd); > void createTexture2D(eGLImage &eglImage, void *data); > > + int attachTextureToFBO(eGLImage &eglImage); > + > void pushEnv(std::vector<std::string> &shaderEnv, const char *str); > void makeCurrent(); > > diff --git a/src/libcamera/egl.cpp b/src/libcamera/egl.cpp > index f03abb8ae..e83e24606 100644 > --- a/src/libcamera/egl.cpp > +++ b/src/libcamera/egl.cpp > @@ -112,6 +112,32 @@ void eGL::flushOutput() > glFlush(); > } > > +/** > + * \brief Attach a texture to a frame-buffer-object > + * > + * \param[in,out] eglImage EGL image containing texture to attach to FBO > + * > + * Helper function to make attachment of texture to FBO easy to reuse. > + * > + * \return 0 on success, or -ENODEV on failure > + */ > +int eGL::attachTextureToFBO(eGLImage &eglImage) > +{ > + int ret = 0; > + > + // Generate a framebuffer from our texture direct to dma-buf handle buffer > + glBindFramebuffer(GL_FRAMEBUFFER, eglImage.fbo_); > + glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, eglImage.texture_, 0); > + > + GLenum err = glCheckFramebufferStatus(GL_FRAMEBUFFER); > + if (err != GL_FRAMEBUFFER_COMPLETE) { > + LOG(eGL, Error) << "glFrameBufferTexture2D error " << err; > + ret = -ENODEV; > + } > + > + return ret; > +} > + > /** > * \brief Create a DMA-BUF backed 2D texture > * \param[in,out] eglImage EGL image to associate with the DMA-BUF > @@ -127,6 +153,7 @@ void eGL::flushOutput() > int eGL::createDMABufTexture2D(eGLImage &eglImage, int fd, bool output) > { > EGLint drm_format; > + int ret = 0; > > ASSERT(tid_ == Thread::currentId()); > > @@ -186,19 +213,10 @@ int eGL::createDMABufTexture2D(eGLImage &eglImage, int fd, bool output) > glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); > glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); > > - if (output) { > - // Generate a framebuffer from our texture direct to dma-buf handle buffer > - glBindFramebuffer(GL_FRAMEBUFFER, eglImage.fbo_); > - glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, eglImage.texture_, 0); > + if (output) > + ret = attachTextureToFBO(eglImage); > > - GLenum err = glCheckFramebufferStatus(GL_FRAMEBUFFER); > - if (err != GL_FRAMEBUFFER_COMPLETE) { > - LOG(eGL, Error) << "glFrameBufferTexture2D error " << err; > - return -ENODEV; > - } > - } > - > - return 0; > + return ret; > } > > /**
diff --git a/include/libcamera/internal/egl.h b/include/libcamera/internal/egl.h index f7bfb28d4..4b0757afd 100644 --- a/include/libcamera/internal/egl.h +++ b/include/libcamera/internal/egl.h @@ -109,6 +109,8 @@ public: int createOutputDMABufTexture2D(eGLImage &eglImage, int fd); void createTexture2D(eGLImage &eglImage, void *data); + int attachTextureToFBO(eGLImage &eglImage); + void pushEnv(std::vector<std::string> &shaderEnv, const char *str); void makeCurrent(); diff --git a/src/libcamera/egl.cpp b/src/libcamera/egl.cpp index f03abb8ae..e83e24606 100644 --- a/src/libcamera/egl.cpp +++ b/src/libcamera/egl.cpp @@ -112,6 +112,32 @@ void eGL::flushOutput() glFlush(); } +/** + * \brief Attach a texture to a frame-buffer-object + * + * \param[in,out] eglImage EGL image containing texture to attach to FBO + * + * Helper function to make attachment of texture to FBO easy to reuse. + * + * \return 0 on success, or -ENODEV on failure + */ +int eGL::attachTextureToFBO(eGLImage &eglImage) +{ + int ret = 0; + + // Generate a framebuffer from our texture direct to dma-buf handle buffer + glBindFramebuffer(GL_FRAMEBUFFER, eglImage.fbo_); + glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, eglImage.texture_, 0); + + GLenum err = glCheckFramebufferStatus(GL_FRAMEBUFFER); + if (err != GL_FRAMEBUFFER_COMPLETE) { + LOG(eGL, Error) << "glFrameBufferTexture2D error " << err; + ret = -ENODEV; + } + + return ret; +} + /** * \brief Create a DMA-BUF backed 2D texture * \param[in,out] eglImage EGL image to associate with the DMA-BUF @@ -127,6 +153,7 @@ void eGL::flushOutput() int eGL::createDMABufTexture2D(eGLImage &eglImage, int fd, bool output) { EGLint drm_format; + int ret = 0; ASSERT(tid_ == Thread::currentId()); @@ -186,19 +213,10 @@ int eGL::createDMABufTexture2D(eGLImage &eglImage, int fd, bool output) glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); - if (output) { - // Generate a framebuffer from our texture direct to dma-buf handle buffer - glBindFramebuffer(GL_FRAMEBUFFER, eglImage.fbo_); - glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, eglImage.texture_, 0); + if (output) + ret = attachTextureToFBO(eglImage); - GLenum err = glCheckFramebufferStatus(GL_FRAMEBUFFER); - if (err != GL_FRAMEBUFFER_COMPLETE) { - LOG(eGL, Error) << "glFrameBufferTexture2D error " << err; - return -ENODEV; - } - } - - return 0; + return ret; } /**
This method does what it says on the tin. It attaches a texture to a framebuffer object, splitting existing code into a helper function which we will use in subsequent patches. Signed-off-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org> --- include/libcamera/internal/egl.h | 2 ++ src/libcamera/egl.cpp | 42 +++++++++++++++++++++++--------- 2 files changed, 32 insertions(+), 12 deletions(-)