Warning, /frameworks/kdeclarative/src/qmlcontrols/graphicaleffects/preserveaspect.vert is written in an unsupported language. File is not indexed.

0001 /*
0002 SPDX-FileCopyrightText: 2021 Arjen Hiemstra <ahiemstra@heimr.nl>
0003 SPDX-FileCopyrightText: 2023 Mike Noe <noeerover@gmail.com>
0004 
0005 SPDX-License-Identifier: LGPL-2.0-or-later
0006 */
0007 
0008 #version 440
0009 
0010 // This shader performs UV coordinates that account for the aspect ratio of some
0011 // source as specified by the sourceSize uniform. The effective result is that
0012 // this results in behaviour similar to the "PreserveAspectFit" mode of QML Image.
0013 
0014 layout(location = 0) in vec4 position;
0015 layout(location = 1) in vec2 texcoord;
0016 
0017 layout(location = 0) out vec2 coord;
0018 
0019 layout(std140, binding = 0) uniform buf {
0020     mat4 qt_Matrix;
0021     float qt_Opacity;
0022 
0023     vec2 sourceSize;
0024     vec2 targetSize;
0025 } ubuf;
0026 
0027 void main() {
0028     float scale = min(ubuf.targetSize.x / ubuf.sourceSize.x, ubuf.targetSize.y / ubuf.sourceSize.y);
0029 
0030     vec2 newSize = ubuf.sourceSize * scale;
0031     vec2 newOffset = (ubuf.targetSize - newSize) / 2.0;
0032     vec2 uvOffset = (1.0 / newSize) * newOffset;
0033 
0034     coord = -uvOffset + (ubuf.targetSize / newSize) * texcoord;
0035     gl_Position = ubuf.qt_Matrix * position;
0036 }