diff options
author | Jørgen Lind <jorgen.lind@nokia.com> | 2011-01-18 14:15:05 (GMT) |
---|---|---|
committer | Jørgen Lind <jorgen.lind@nokia.com> | 2011-01-26 13:16:07 (GMT) |
commit | d39662822785484ec8e76066f4f2b65ef8778b40 (patch) | |
tree | 386321f3303d22c9330edce8211a936f36d9d62e /src | |
parent | af15d5e128c1216bafa4f9d0121bb4178354e35e (diff) | |
download | Qt-d39662822785484ec8e76066f4f2b65ef8778b40.zip Qt-d39662822785484ec8e76066f4f2b65ef8778b40.tar.gz Qt-d39662822785484ec8e76066f4f2b65ef8778b40.tar.bz2 |
Make it possible to vertically mirror gl painting
The GLPaintDevice gets a flip property. If this is set, the pvr matrix
is altered to paint "upside down"
Reviewed-by: sroedal
Diffstat (limited to 'src')
-rw-r--r-- | src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp | 21 | ||||
-rw-r--r-- | src/opengl/qglpaintdevice.cpp | 6 | ||||
-rw-r--r-- | src/opengl/qglpaintdevice_p.h | 1 |
3 files changed, 23 insertions, 5 deletions
diff --git a/src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp b/src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp index cf63626..d07fc54 100644 --- a/src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp +++ b/src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp @@ -337,7 +337,13 @@ void QGL2PaintEngineExPrivate::updateBrushUniforms() matrix.translate(brushOrigin.x(), brushOrigin.y()); QTransform translate(1, 0, 0, 1, -translationPoint.x(), -translationPoint.y()); - QTransform gl_to_qt(1, 0, 0, -1, 0, height); + qreal m22 = -1; + qreal dy = height; + if (device->isFlipped()) { + m22 = 1; + dy = 0; + } + QTransform gl_to_qt(1, 0, 0, m22, 0, dy); QTransform inv_matrix; if (style == Qt::TexturePattern && textureInvertedY == -1) inv_matrix = gl_to_qt * (QTransform(1, 0, 0, -1, 0, currentBrush.texture().height()) * brushQTransform * matrix).inverted() * translate; @@ -376,10 +382,16 @@ void QGL2PaintEngineExPrivate::updateMatrix() // NOTE: The resultant matrix is also transposed, as GL expects column-major matracies const GLfloat wfactor = 2.0f / width; - const GLfloat hfactor = -2.0f / height; + GLfloat hfactor = -2.0f / height; + GLfloat dx = transform.dx(); GLfloat dy = transform.dy(); + if (device->isFlipped()) { + hfactor *= -1; + dy -= height; + } + // Non-integer translates can have strange effects for some rendering operations such as // anti-aliased text rendering. In such cases, we snap the translate to the pixel grid. if (snapToPixelGrid && transform.type() == QTransform::TxTranslate) { @@ -2059,7 +2071,10 @@ void QGL2PaintEngineExPrivate::setScissor(const QRect &rect) { const int left = rect.left(); const int width = rect.width(); - const int bottom = height - (rect.top() + rect.height()); + int bottom = height - (rect.top() + rect.height()); + if (device->isFlipped()) { + bottom = rect.top(); + } const int height = rect.height(); glScissor(left, bottom, width, height); diff --git a/src/opengl/qglpaintdevice.cpp b/src/opengl/qglpaintdevice.cpp index e1dcbfd..c2b2adf 100644 --- a/src/opengl/qglpaintdevice.cpp +++ b/src/opengl/qglpaintdevice.cpp @@ -145,8 +145,10 @@ bool QGLPaintDevice::alphaRequested() const return context()->d_func()->reqFormat.alpha(); } - - +bool QGLPaintDevice::isFlipped() const +{ + return false; +} ////////////////// QGLWidgetGLPaintDevice ////////////////// diff --git a/src/opengl/qglpaintdevice_p.h b/src/opengl/qglpaintdevice_p.h index 04f9c3c..39b91c9 100644 --- a/src/opengl/qglpaintdevice_p.h +++ b/src/opengl/qglpaintdevice_p.h @@ -76,6 +76,7 @@ public: virtual QGLFormat format() const; virtual QSize size() const = 0; virtual bool alphaRequested() const; + virtual bool isFlipped() const; // returns the QGLPaintDevice for the given QPaintDevice static QGLPaintDevice* getDevice(QPaintDevice*); |