From patchwork Fri Jun 26 11:33:22 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: 27052 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 D2C6BC3304 for ; Fri, 26 Jun 2026 11:33:47 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 5D5A065EE0; Fri, 26 Jun 2026 13:33:47 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="Ax9NxrNd"; dkim-atps=neutral Received: from mail-wm1-x32f.google.com (mail-wm1-x32f.google.com [IPv6:2a00:1450:4864:20::32f]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 88F08658FE for ; Fri, 26 Jun 2026 13:33:43 +0200 (CEST) Received: by mail-wm1-x32f.google.com with SMTP id 5b1f17b1804b1-490cf3000f0so8768165e9.1 for ; Fri, 26 Jun 2026 04:33:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1782473623; x=1783078423; 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; bh=oKZ71QaBtM6ROt/Onecsm43QmMC4gfI0FGbAVT9Ibl4=; b=Ax9NxrNdFqHSFAoeZ4lz5J1I5KM211xOLkB0bf9nNDtlxGXqsSP5SYEEjYBqgyuY8X tH0Scn4FFHMFIyfvFnvqYDVwLIYoaH6sL3GB5yG6h52I9sfzuLlLG7bK1Eef4N/Nk8U2 4/9EN5IlP45TtnsxxUNUr7ebw1fnmF+UpHWAM6gJWtzF8aF4duIe2VqiZAxBakTdXgaM yxYVh9bO0bGQkattzT6cCnSVfJjmTquINF3p0JHGHzFTqZgHjQiDJraTaZ0dkcArObSz 197vzF8og40n2691Tyqk2wvbu2OjH7Fh7H/RwJHeK7cRv1uN1klAo7vx9kHZ/hBV3oEy qRAQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1782473623; x=1783078423; 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; bh=oKZ71QaBtM6ROt/Onecsm43QmMC4gfI0FGbAVT9Ibl4=; b=aNy2Ybth2NtiBrZawTGKMJCYu9UYYscIUpomKQk55pgjLU2S9rFAs7mqOipIYAGNq+ Y6wKs9UhNEOVUx0yHqGuL4AyQye770nMFSbJNpuo5KszQfKF/pARn+4tmfx0pVpu906h lJAxdL0F7AkxVOgIu8jC0podbRGFfL5LK3TBnHHOyehbwQkUk3SEFW6djNPlFStEZU1n xCUpxvNnK7KMDGkhw0dksMFNOWXCUCD8gwkebbryu0O3/mCC4QfZjWVpfpzMGptFIG15 z1XUWqWJuTUPPEK5VUoHvqES0RyYdIRycAtZmB1469eybp5ScrWsGHcn6xlwo1szndDf ObAw== X-Gm-Message-State: AOJu0YwKtEwGWz//1Pot9KrsX2S+6w9g5I2SbgbDxm/XMOBgS+kucfXO MU32x2AznD6qCzZnohmpisG0DFO9XoZdYqHigU3Kx0PowNrBEJ8mdVOjHyy/xj/hjxNoQi4PaUi AMlmz1HM= X-Gm-Gg: AfdE7ckNAsMNlSAI/nq3AxhTRs5goabZ+7GhMzaXqBbd10PznrI0YU4gOM410itk3iu 6ICU/QPveVqfBFLqLX1SpXMPYpoMlzztru9SIK30MXJe13r8Vc/OZwYO+dp4b9yK6w+580n4Ly+ oipHUR9wTNtspXexqa9ja0XKpNcVjLeAJxb+LPVuYdErA35Lr17fyR9nhT1hMojYnSAKPbQdpyv cdMaA1Mk8j5XOTZu6NvLV0Ehci19kYX4+1SOGm9brGDnNbA/a59MCXjn+1WSPneS2xNXWKoc2HO Bxl+LgfRLGSPd058qsj1Akdf3LjIB6Jkp8Wr93vVvQHa5iQMdT7xG1sOx7nv4em15BV9FojABSE paS4wwP8V1YL3a1q6ALp1+8grrUrusm7xgYaxGoOB08Wq4D/4B90YjntRCg8FpKOkHurcrQmdD0 QjiLhAwBiNw63ao9JY1nK6ZIoqazN7jlQ1Hjkg X-Received: by 2002:a05:600c:1d0e:b0:492:63ff:d577 with SMTP id 5b1f17b1804b1-49266899cf0mr97714435e9.27.1782473623005; Fri, 26 Jun 2026 04:33:43 -0700 (PDT) Received: from inspiron14p-linux ([109.76.78.98]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-49268fe31b0sm79265985e9.4.2026.06.26.04.33.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Jun 2026 04:33:42 -0700 (PDT) From: Bryan O'Donoghue To: libcamera-devel@lists.libcamera.org Cc: bryan.odonoghue@linaro.org, pavel@ucw.cz, Robert Mader Subject: [PATCH v3 5/8] libcamera: egl: Add updateTexture2D Date: Fri, 26 Jun 2026 12:33:22 +0100 Message-ID: <20260626113325.3218045-6-bryan.odonoghue@linaro.org> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260626113325.3218045-1-bryan.odonoghue@linaro.org> References: <20260626113325.3218045-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" The internet box tells me that glTextSubImage2D lets us update a texture's data only, instead of recreating the texture and uploading data. This is a smallish optimisation but we are hunting for every possible cycle and watt so add the routine as precursor to using it in-place of createTexture2D on every upload cycle. Reviewed-by: Robert Mader Signed-off-by: Bryan O'Donoghue --- include/libcamera/internal/egl.h | 1 + src/libcamera/egl.cpp | 35 ++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/include/libcamera/internal/egl.h b/include/libcamera/internal/egl.h index e24a726dc..9b679332c 100644 --- a/include/libcamera/internal/egl.h +++ b/include/libcamera/internal/egl.h @@ -108,6 +108,7 @@ public: int createInputDMABufTexture2D(eGLImage &eglImage, int fd); int createOutputDMABufTexture2D(eGLImage &eglImage, int fd); void createTexture2D(eGLImage &eglImage, void *data); + void updateTexture2D(eGLImage &eglImage, void *data); void createOutputTexture2D(eGLImage &eglImage); int attachTextureToFBO(eGLImage &eglImage); diff --git a/src/libcamera/egl.cpp b/src/libcamera/egl.cpp index 8e8d61813..22f46e92a 100644 --- a/src/libcamera/egl.cpp +++ b/src/libcamera/egl.cpp @@ -329,6 +329,41 @@ bool eGL::isAvailable() return true; } +/** + * \brief Update a 2D texture already created + * \param[in,out] eglImage EGL image to associate with the texture + * \param[data] Data to update the texture with + * + * Updates a 2D texture in VRAM. + */ +void eGL::updateTexture2D(eGLImage &eglImage, void *data) +{ + GLenum format; + GLenum type = GL_UNSIGNED_BYTE; + + ASSERT(tid_ == Thread::currentId()); + + glActiveTexture(eglImage.texture_unit_); + glBindTexture(GL_TEXTURE_2D, eglImage.texture_); + + switch (eglImage.format_) { + case GL_R16F: + format = GL_RED; + type = GL_HALF_FLOAT; + break; + case GL_RG8: + format = GL_RG; + break; + case GL_LUMINANCE: + default: + format = GL_LUMINANCE; + break; + } + + // Update an already exsiting texture + glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, eglImage.width_, eglImage.height_, format, type, data); +} + /** * \brief Create a 2D texture attached to an FBO for render-to-texture * \param[in,out] eglImage EGL image to associate with the texture