[04/30] libcamera: software_isp: egl: Add new helper attachTextureToFBO
diff mbox series

Message ID 20260618122245.946138-5-bryan.odonoghue@linaro.org
State New
Headers show
Series
  • RFC/RFT: gpuisp: Multipass with speed optimisations on top
Related show

Commit Message

Bryan O'Donoghue June 18, 2026, 12:22 p.m. UTC
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(-)

Patch
diff mbox series

diff --git a/include/libcamera/internal/egl.h b/include/libcamera/internal/egl.h
index 57f90d93f..d88617afa 100644
--- a/include/libcamera/internal/egl.h
+++ b/include/libcamera/internal/egl.h
@@ -108,6 +108,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 c185bb7ad..3ea694d7c 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;
 
 	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;
 }
 
 /**