@@ -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();
@@ -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;
}
/**
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(-)