Add a way of transforming texture coordinates of a simple textured quad
authorSean Harmer <sean.harmer@kdab.com>
Mon, 15 Apr 2013 10:52:24 +0000 (11:52 +0100)
committerThe Qt Project <gerrit-noreply@qt-project.org>
Tue, 16 Apr 2013 13:41:31 +0000 (15:41 +0200)
commit5c7225572746201cc60496530f410178cdb4283b
tree23acb1618e7bef65b502be39b323e9318ef66dba
parenta6ccf8b484596091b9a38ac37dac43c456cdc730
Add a way of transforming texture coordinates of a simple textured quad

This commit introduces the enum TextureCoordinatesTransformFlag and
corresponding QFlags OR combination TextureCoordinatesTransformMode.
This enum is used to control the orientation of texture coordinates
relative to window/item coordinates.

The common use case addressed by this commit is when rendering to a
texture via an FBO using some 3rd party OpenGL library. Some libraries
do not offer a way to orient the rendered output which results in the
texture being displayed upside down when used in conjunction with
QSGSimpleTextureNode.

There are a number of possible solutions to this:

1 Mirror the item by scaling by -1 in the y-direction in QML document

2 Use a custom material (shader) that transforms texture coordinates
  in GLSL

3 Generate texture coordinates differently

This commit opts for approach 3. Approach 1 is ugly and visible to the
end user and also causes more work when other transformations interact
with the necessary scaling. Approach 2 has a performance cost in both
switching material (shader) and also in additional per-vertex or per-
fragment operations. The chosen approach hides it from the end user
and has zero runtime cost delta compared to any other textured quad.

Change-Id: I95870da50a09d113aeff2681bfd458669ec7a5a4
Reviewed-by: Gunnar Sletta <gunnar.sletta@digia.com>
src/quick/scenegraph/util/qsgsimpletexturenode.cpp
src/quick/scenegraph/util/qsgsimpletexturenode.h