From e6441ec4f4a68518c3f01c753ef179226f56ebfc Mon Sep 17 00:00:00 2001 From: Laurent Pinchart Date: Mon, 9 Sep 2024 16:13:20 +0300 Subject: qcam: viewfinder_gl: Render image centered in letterbox Mimic the letterbox behaviour of the Qt viewfinder by rendering the image centered. This is done by adding a projection matrix to the vertex shader to scale the rendered rectangle. Another option would have been to keep using glViewport() (which would have needed to be moved to paintGL(), as Qt resets the viewport to span the full widget before calling). Hidpi displays would then need special handling of the device pixel ratio, which is done automatically by Qt when it sets the default viewport. Using a projection matrix avoids this complication. Signed-off-by: Laurent Pinchart Tested-by: Kieran Bingham Reviewed-by: Kieran Bingham --- src/apps/qcam/assets/shader/identity.vert | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/apps/qcam/assets/shader/identity.vert') diff --git a/src/apps/qcam/assets/shader/identity.vert b/src/apps/qcam/assets/shader/identity.vert index 12c41377..907e8741 100644 --- a/src/apps/qcam/assets/shader/identity.vert +++ b/src/apps/qcam/assets/shader/identity.vert @@ -9,10 +9,11 @@ attribute vec4 vertexIn; attribute vec2 textureIn; varying vec2 textureOut; +uniform mat4 proj_matrix; uniform float stride_factor; void main(void) { - gl_Position = vertexIn; + gl_Position = proj_matrix * vertexIn; textureOut = vec2(textureIn.x * stride_factor, textureIn.y); } -- cgit v1.2.1