From patchwork Wed Nov 4 02:17:25 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 10329 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 E8CE8BDB89 for ; Wed, 4 Nov 2020 02:18:19 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 798CD62BC9; Wed, 4 Nov 2020 03:18:19 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="gXHysA6G"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id EE77D60344 for ; Wed, 4 Nov 2020 03:18:17 +0100 (CET) Received: from pendragon.lan (62-78-145-57.bb.dnainternet.fi [62.78.145.57]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 58006563; Wed, 4 Nov 2020 03:18:17 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1604456297; bh=qO5FhKuzidpHR/rGYAaa2IjhIko3o8JZ5hV9HNFPUgg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gXHysA6G0y6dYLa8TFXn3jEwxvms6X6E3GuRvOzG8GkmIkfj3oa0AY/8iD1Ot+IrO ROZXG5z1qwhso4NLrnvqpgNDhmAjnNHYDcHyT26cN9XwP2TqPLbJgE0pu81RdwahBM E4k3ghITCrpHT4HhC5sOXAeYLkczmThgnMrlUND8= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Wed, 4 Nov 2020 04:17:25 +0200 Message-Id: <20201104021725.32361-1-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <99ef4bf5-5e13-2264-de05-c550b20d3977@linaro.org> References: <99ef4bf5-5e13-2264-de05-c550b20d3977@linaro.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v1.1 6/7] qcam: viewfinder_gl: Store textures in an array 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" In preparation for RGB formats support, store the three Y, U and V textures in an array. This makes the code more generic, and will avoid referring to an RGB texture as textureY_. Signed-off-by: Laurent Pinchart Reviewed-by: Andrey Konovalov Reviewed-by: Niklas Söderlund --- Changes since v1: - Reorganize texture fields in the ViewFinderGL class --- src/qcam/viewfinder_gl.cpp | 37 +++++++++++++++++-------------------- src/qcam/viewfinder_gl.h | 9 +++++---- 2 files changed, 22 insertions(+), 24 deletions(-) diff --git a/src/qcam/viewfinder_gl.cpp b/src/qcam/viewfinder_gl.cpp index e6625cac9795..cbc1365500f5 100644 --- a/src/qcam/viewfinder_gl.cpp +++ b/src/qcam/viewfinder_gl.cpp @@ -33,10 +33,7 @@ static const QList supportedFormats{ ViewFinderGL::ViewFinderGL(QWidget *parent) : QOpenGLWidget(parent), buffer_(nullptr), data_(nullptr), - vertexBuffer_(QOpenGLBuffer::VertexBuffer), - textureU_(QOpenGLTexture::Target2D), - textureV_(QOpenGLTexture::Target2D), - textureY_(QOpenGLTexture::Target2D) + vertexBuffer_(QOpenGLBuffer::VertexBuffer) { } @@ -263,14 +260,14 @@ bool ViewFinderGL::createFragmentShader() textureUniformV_ = shaderProgram_.uniformLocation("tex_v"); textureUniformStepX_ = shaderProgram_.uniformLocation("tex_stepx"); - if (!textureY_.isCreated()) - textureY_.create(); + /* Create the textures. */ + for (std::unique_ptr &texture : textures_) { + if (texture) + continue; - if (!textureU_.isCreated()) - textureU_.create(); - - if (!textureV_.isCreated()) - textureV_.create(); + texture = std::make_unique(QOpenGLTexture::Target2D); + texture->create(); + } return true; } @@ -337,7 +334,7 @@ void ViewFinderGL::doRender() case libcamera::formats::NV42: /* Activate texture Y */ glActiveTexture(GL_TEXTURE0); - configureTexture(textureY_); + configureTexture(*textures_[0]); glTexImage2D(GL_TEXTURE_2D, 0, GL_RED, @@ -351,7 +348,7 @@ void ViewFinderGL::doRender() /* Activate texture UV/VU */ glActiveTexture(GL_TEXTURE1); - configureTexture(textureU_); + configureTexture(*textures_[1]); glTexImage2D(GL_TEXTURE_2D, 0, GL_RG, @@ -367,7 +364,7 @@ void ViewFinderGL::doRender() case libcamera::formats::YUV420: /* Activate texture Y */ glActiveTexture(GL_TEXTURE0); - configureTexture(textureY_); + configureTexture(*textures_[0]); glTexImage2D(GL_TEXTURE_2D, 0, GL_RED, @@ -381,7 +378,7 @@ void ViewFinderGL::doRender() /* Activate texture U */ glActiveTexture(GL_TEXTURE1); - configureTexture(textureU_); + configureTexture(*textures_[1]); glTexImage2D(GL_TEXTURE_2D, 0, GL_RED, @@ -395,7 +392,7 @@ void ViewFinderGL::doRender() /* Activate texture V */ glActiveTexture(GL_TEXTURE2); - configureTexture(textureV_); + configureTexture(*textures_[2]); glTexImage2D(GL_TEXTURE_2D, 0, GL_RED, @@ -411,7 +408,7 @@ void ViewFinderGL::doRender() case libcamera::formats::YVU420: /* Activate texture Y */ glActiveTexture(GL_TEXTURE0); - configureTexture(textureY_); + configureTexture(*textures_[0]); glTexImage2D(GL_TEXTURE_2D, 0, GL_RED, @@ -425,7 +422,7 @@ void ViewFinderGL::doRender() /* Activate texture V */ glActiveTexture(GL_TEXTURE2); - configureTexture(textureV_); + configureTexture(*textures_[2]); glTexImage2D(GL_TEXTURE_2D, 0, GL_RED, @@ -439,7 +436,7 @@ void ViewFinderGL::doRender() /* Activate texture U */ glActiveTexture(GL_TEXTURE1); - configureTexture(textureU_); + configureTexture(*textures_[1]); glTexImage2D(GL_TEXTURE_2D, 0, GL_RED, @@ -462,7 +459,7 @@ void ViewFinderGL::doRender() * The texture width is thus half of the image with. */ glActiveTexture(GL_TEXTURE0); - configureTexture(textureY_); + configureTexture(*textures_[0]); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, diff --git a/src/qcam/viewfinder_gl.h b/src/qcam/viewfinder_gl.h index b3e36514d3d4..150fa4ae94da 100644 --- a/src/qcam/viewfinder_gl.h +++ b/src/qcam/viewfinder_gl.h @@ -8,6 +8,7 @@ #ifndef __VIEWFINDER_GL_H__ #define __VIEWFINDER_GL_H__ +#include #include #include @@ -77,14 +78,14 @@ private: /* Vertex buffer */ QOpenGLBuffer vertexBuffer_; - /* YUV texture planars and parameters */ + /* Textures */ + std::array, 3> textures_; + + /* YUV texture parameters */ GLuint textureUniformU_; GLuint textureUniformV_; GLuint textureUniformY_; GLuint textureUniformStepX_; - QOpenGLTexture textureU_; - QOpenGLTexture textureV_; - QOpenGLTexture textureY_; unsigned int horzSubSample_; unsigned int vertSubSample_;