From patchwork Mon Jul 6 22:22:41 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bryan O'Donoghue X-Patchwork-Id: 27255 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 3B8F8C3308 for ; Mon, 6 Jul 2026 22:23:03 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id CF7D76605E; Tue, 7 Jul 2026 00:23:01 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="QTsGj0c/"; dkim-atps=neutral Received: from mail-wr1-x42c.google.com (mail-wr1-x42c.google.com [IPv6:2a00:1450:4864:20::42c]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id ED7D16604F for ; Tue, 7 Jul 2026 00:22:58 +0200 (CEST) Received: by mail-wr1-x42c.google.com with SMTP id ffacd0b85a97d-45fd464d51fso1814859f8f.3 for ; Mon, 06 Jul 2026 15:22:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1783376578; x=1783981378; darn=lists.libcamera.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=sCherSufb0on4kaTY2CKoIjTcZ+GTv1qK3dt1yZ0ysg=; b=QTsGj0c/FYjGwuBw5jh8YjYIPAhBbfZ2MdTXqwxo54pAnopT3oHh7e9VD7PLAiJ4Dh Soiin1HvN1PU0AlGv4bwxoxi9hEvRu6uTfpCibqADOfWcOP4fxxPgZMiCjZRqFn5qHvj xsZlBlpv0dSYpFgsyl+LGsyJcBtWPdGYigdEFPKrEXR9GIp+75BTzCCUbg0E2l2iht7s ne7QUizdAOqyv+OgCDdKuZ7b6dCx002IxoCMQkVCLtN4W80Z2LEZuMh2F3+UTJ+mByOI G9WWxioJT5bwXD+3769oOOma2AcCg8FCvXg5pXwJY6d6GXgsTi9129sjr+fFxSpvdOMu gwMw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1783376578; x=1783981378; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=sCherSufb0on4kaTY2CKoIjTcZ+GTv1qK3dt1yZ0ysg=; b=CHHjh3Mg14vSUN2Q1AstsfbwDFaT88XI5QeHlLAE/0OfzXhqbdi19026B9sU+asHt/ JAxB7f89dL0DmZ7QIT8yUzwgnTXEMG9aqBOZCBdjrESS+iUQFH8ayR6tT3KR2S4zq2g4 kqY3oe8jIFixB8PTMY8RVP/Uuy50sPirqun7byMCRABxi+GjhxamYelzC0oAlG5mqC33 60VrAcljXHGviwa/wkcRpMDMrCAFmCbQwUvA1BlH8Ib5hMvPCD+1mBNvXVHGC8WPoiBU k7CD8fYqPv0+rijtPzUu7s01ibzyQqR5+GlRSZA5Fl0Agkzg9IgAaLc/xhBt9jx7U9uT jsrQ== X-Gm-Message-State: AOJu0YynCowIxGaeBIaIVMkx4A5ufY3IzOOfM5TwBvqAiB0y5iRwr/jS zgJ3vU+FSMn0OO4CuPshUY7+Ox8IMjOPN1qCgOSNCjoljBg4siiPlDrTlWf8hoAkktDOds8jI0T kj8FN X-Gm-Gg: AfdE7cmUfP0sTaMSN3TNGT41mlaslRDZo13/1lvgUJLsB5PiQNnQEomeC/IoMVYEa5s 8KFfBlqKtIixs8l51ylmowUtjwFKoTXFGWsut9z6FeAGjuVRGXR8Jzf+fxUXKXNymV8lV36qfbt GYafRPqm3uGFHf0+Q8gOjSObc8NfWRkLmiNUGsYVafsKdBlfWzE7glEYefAX/COujxrgpOoSYfI jeyKM/2P8R7MdKQGrb6IWGzYfnDpF/CaJSWXhkrJNL1TA/asX75Jqo2hLW1WqtuTOmHpu9Kgs/V JtJAQUG6TSqFQLKJTj/g24brmXMJ1X1jJAxb5W7xlZyCLFFZiBm2MegOT9F3vIw9J2sGDqXRfPx fYYU8dHQrjCjilyFymJpr9ggsLWHtIj2P/NuyGwNYbuygcMtORQJNdYOFAooDwavbMQjxEvRl+C jUn8EYXuHqxVHa5+BbWzZT9SFEBHIHbLJ0oFRIWcY= X-Received: by 2002:adf:f390:0:b0:473:fe94:9bf1 with SMTP id ffacd0b85a97d-47de66693b9mr1854859f8f.26.1783376578276; Mon, 06 Jul 2026 15:22:58 -0700 (PDT) Received: from inspiron14p-linux ([109.77.44.220]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-47aa039ad21sm27916413f8f.20.2026.07.06.15.22.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Jul 2026 15:22:57 -0700 (PDT) From: Bryan O'Donoghue To: libcamera-devel@lists.libcamera.org Cc: bryan.odonoghue@linaro.org, pavel@ucw.cz, Robert Mader , Milan Zamazal Subject: [PATCH v6 2/6] libcamera: egl: Add new helper attachTextureToFBO Date: Mon, 6 Jul 2026 23:22:41 +0100 Message-ID: <20260706222245.247396-3-bryan.odonoghue@linaro.org> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260706222245.247396-1-bryan.odonoghue@linaro.org> References: <20260706222245.247396-1-bryan.odonoghue@linaro.org> MIME-Version: 1.0 X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" 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. Reviewed-by: Robert Mader Reviewed-by: Milan Zamazal Signed-off-by: Bryan O'Donoghue --- 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 523a62aa8..085a371f3 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 &shaderEnv, const char *str); void makeCurrent(); diff --git a/src/libcamera/egl.cpp b/src/libcamera/egl.cpp index b5a5dc60b..ed67aca7b 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; } /**