From patchwork Tue Sep 10 23:46:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 21225 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 2629FBF415 for ; Tue, 10 Sep 2024 23:47:28 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id B04EF63502; Wed, 11 Sep 2024 01:47:26 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="IbNTiej5"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 7A144634F5 for ; Wed, 11 Sep 2024 01:47:24 +0200 (CEST) Received: from pendragon.ideasonboard.com (213-229-8-243.static.upcbusiness.at [213.229.8.243]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 325B3BEB; Wed, 11 Sep 2024 01:46:07 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1726011967; bh=KGfAVXmSPWZE+yattAsCkhFdb5Uewtihi2avsou+KGw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=IbNTiej5kez5BfcmivdpS7xMOQnhLeI8crmjKNhQf8//URl9iuXsRIZtd4ZBPjOjN ya/Vtwosbj98Ld096HDYaHMyoBeKgulCAaamTLpSCvgZu6GAJOPXkfLUJw44u9kJWI KQEHdYTXd2t0ToscxbNWFer4USH4QK273AM8vF2I= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Cc: Neal Gompa Subject: [PATCH 1/3] qcam: viewfinder_gl: Fix binding of vertex buffer and shader program Date: Wed, 11 Sep 2024 02:46:47 +0300 Message-ID: <20240910234649.28591-2-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.44.2 In-Reply-To: <20240910234649.28591-1-laurent.pinchart@ideasonboard.com> References: <20240910234649.28591-1-laurent.pinchart@ideasonboard.com> 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" Starting in Qt 6.7.0, vertex buffers and shader programs are unbound just before calling QOpenGLWidget::paintGL(). This breaks rendering in the GL viewfinder in two ways. First, we bind the vertex buffer only once at initialization time. There is therefore no vertex buffer mapped at rendering time, preventing both the vertex shader from having access to the vertex and texture coordinates. Then, we bind the shader program only when rendering the first frame. There is thus no shader program bound for all subsequent frames, breaking rendering. Fix this by binding the vertex buffer where needed, when setting attribute buffers for the shader program, and binding the shader program for every frame. As we use a single vertex buffer, we could bind it at the beginning of paintGL() and keep it bound indefinitely. That would however fail to clearly indicate in the source code where the vertex buffer is needed, making the code more difficult to understand as it would rely on implicit assumptions. Release the vertex buffer explicitly when we don't need it anymore to avoid this. While at it, fix a coding style violation by adding missing curly brackets. Signed-off-by: Laurent Pinchart --- src/apps/qcam/viewfinder_gl.cpp | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/apps/qcam/viewfinder_gl.cpp b/src/apps/qcam/viewfinder_gl.cpp index 9d2a69600db1..5be7bec539bf 100644 --- a/src/apps/qcam/viewfinder_gl.cpp +++ b/src/apps/qcam/viewfinder_gl.cpp @@ -443,15 +443,11 @@ bool ViewFinderGL::createFragmentShader() close(); } - /* Bind shader pipeline for use */ - if (!shaderProgram_.bind()) { - qWarning() << "[ViewFinderGL]:" << shaderProgram_.log(); - close(); - } - attributeVertex = shaderProgram_.attributeLocation("vertexIn"); attributeTexture = shaderProgram_.attributeLocation("textureIn"); + vertexBuffer_.bind(); + shaderProgram_.enableAttributeArray(attributeVertex); shaderProgram_.setAttributeBuffer(attributeVertex, GL_FLOAT, @@ -466,6 +462,8 @@ bool ViewFinderGL::createFragmentShader() 2, 2 * sizeof(GLfloat)); + vertexBuffer_.release(); + textureUniformY_ = shaderProgram_.uniformLocation("tex_y"); textureUniformU_ = shaderProgram_.uniformLocation("tex_u"); textureUniformV_ = shaderProgram_.uniformLocation("tex_v"); @@ -809,11 +807,18 @@ void ViewFinderGL::doRender() void ViewFinderGL::paintGL() { - if (!fragmentShader_) + if (!fragmentShader_) { if (!createFragmentShader()) { qWarning() << "[ViewFinderGL]:" << "create fragment shader failed."; } + } + + /* Bind shader pipeline for use. */ + if (!shaderProgram_.bind()) { + qWarning() << "[ViewFinderGL]:" << shaderProgram_.log(); + close(); + } if (image_) { glClearColor(0.0, 0.0, 0.0, 1.0);