summaryrefslogtreecommitdiffstats
path: root/src/gui/opengl
diff options
context:
space:
mode:
authorJørgen Lind <jorgen.lind@digia.com>2014-02-13 22:03:52 +0100
committerThe Qt Project <gerrit-noreply@qt-project.org>2014-02-16 11:06:19 +0100
commit937a4f5443603b0ad1d1558ac9a9a59db8ce299f (patch)
tree6d3ea438cc9245f5f22bd0f34746b1dc3384a59d /src/gui/opengl
parent6fbef080a07f5b9b5a3bda985fd020a0bf064973 (diff)
QOpenGLTextureBlitter: Remove Origin location for the Target rect
The Origin for Target rect was deemed a confusing concept. The current implementation would translate the target rect to the coordinate system specified. However, the order and "direction" of the vertices would always be the same. So drawing a texture in for one target rect defined in one coordinate system would paint the texture the same way as it would when a texture was drawn for a target rect drawn in the "opposite" coordinate system. The point with this was that if you wanted to "flip" the texture you would specify that with the source coordinate system. However, this approach breaks on different levels, such as QRect has functions which expects a top left coordinate system (ie. top() and bottom()). In the end Qt uses a top left coordinate system, hence QWindow specifies a top left coordinate system, and hence the api becomes easier if it is not possible to define the coordinate system of the target viewport. Change-Id: I7dd59b3718380876e87a4bff88381d7a1c7d58c1 Reviewed-by: Laszlo Agocs <laszlo.agocs@digia.com>
Diffstat (limited to 'src/gui/opengl')
-rw-r--r--src/gui/opengl/qopengltextureblitter.cpp24
-rw-r--r--src/gui/opengl/qopengltextureblitter_p.h2
2 files changed, 12 insertions, 14 deletions
diff --git a/src/gui/opengl/qopengltextureblitter.cpp b/src/gui/opengl/qopengltextureblitter.cpp
index 1fbdd20207..8085089bce 100644
--- a/src/gui/opengl/qopengltextureblitter.cpp
+++ b/src/gui/opengl/qopengltextureblitter.cpp
@@ -344,25 +344,23 @@ void QOpenGLTextureBlitter::blit(GLuint texture,
}
QMatrix4x4 QOpenGLTextureBlitter::targetTransform(const QRectF &target,
- const QRect &viewport,
- Origin origin)
+ const QRect &viewport)
{
- qreal x_scale = target.size().width() / viewport.width();
- qreal y_scale = target.size().height() / viewport.height();
+ qreal x_scale = target.width() / viewport.width();
+ qreal y_scale = target.height() / viewport.height();
const QPointF relative_to_viewport = target.topLeft() - viewport.topLeft();
- qreal x_translate = ((relative_to_viewport.x() / viewport.width()) + (x_scale / 2)) * 2 - 1;
- qreal y_translate = ((relative_to_viewport.y() / viewport.height()) + (y_scale / 2)) * 2 - 1;
+ qreal x_translate = x_scale - 1 + ((relative_to_viewport.x() / viewport.width()) * 2);
+ qreal y_translate = -y_scale + 1 - ((relative_to_viewport.y() / viewport.height()) * 2);
- if (origin == OriginTopLeft) {
- y_translate = -y_translate;
- }
+ QMatrix4x4 matrix;
+ matrix(0,3) = x_translate;
+ matrix(1,3) = y_translate;
- QMatrix4x4 vertexMatrix;
+ matrix(0,0) = x_scale;
+ matrix(1,1) = y_scale;
- vertexMatrix.translate(x_translate, y_translate);
- vertexMatrix.scale(x_scale, y_scale);
- return vertexMatrix;
+ return matrix;
}
QMatrix3x3 QOpenGLTextureBlitter::sourceTransform(const QRectF &subTexture,
diff --git a/src/gui/opengl/qopengltextureblitter_p.h b/src/gui/opengl/qopengltextureblitter_p.h
index 5164d8630e..b2ccc13391 100644
--- a/src/gui/opengl/qopengltextureblitter_p.h
+++ b/src/gui/opengl/qopengltextureblitter_p.h
@@ -72,7 +72,7 @@ public:
void blit(GLuint texture, const QMatrix4x4 &targetTransform, Origin sourceOrigin);
void blit(GLuint texture, const QMatrix4x4 &targetTransform, const QMatrix3x3 &sourceTransform);
- static QMatrix4x4 targetTransform(const QRectF &target, const QRect &viewport, Origin origin);
+ static QMatrix4x4 targetTransform(const QRectF &target, const QRect &viewport);
static QMatrix3x3 sourceTransform(const QRectF &subTexture, const QSize &textureSize, Origin origin);
private: