diff options
author | Morten Johan Sørvig <morten.sorvig@digia.com> | 2014-03-19 11:26:30 +0100 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2014-03-20 10:36:34 +0100 |
commit | 8c91c9912f556897db4f05be1acc335ef3a5d1fb (patch) | |
tree | 31040468d7f9a399369bc4a79e38b20c11a0a9c5 /src/gui | |
parent | f5b552b5900d3bed72ace43c22f35c09b499bbdf (diff) |
Avoid QImage copy in toTexture()
Desktop OpenGL has GL_UNPACK_ROW_LENGTH which we
can use use to specify the image row stride.
This removes the need to call QImage::copy(). On
a retina MacbBok pro this reduces toTexture's share
of the total run time by 1-4%. (on tests/manual/
qopenglwidget/openglwidget)
Change-Id: Ia7f49d5c4ffcc347a495701bbaca6aecc2dc3433
Reviewed-by: Paul Olav Tvete <paul.tvete@digia.com>
Reviewed-by: Laszlo Agocs <laszlo.agocs@digia.com>
Diffstat (limited to 'src/gui')
-rw-r--r-- | src/gui/painting/qplatformbackingstore.cpp | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/src/gui/painting/qplatformbackingstore.cpp b/src/gui/painting/qplatformbackingstore.cpp index add3624feb..710d84e3aa 100644 --- a/src/gui/painting/qplatformbackingstore.cpp +++ b/src/gui/painting/qplatformbackingstore.cpp @@ -330,6 +330,13 @@ GLuint QPlatformBackingStore::toTexture(const QRegion &dirtyRegion) const funcs->glBindTexture(GL_TEXTURE_2D, d_ptr->textureId); QRect imageRect = image.rect(); QRect rect = dirtyRegion.boundingRect() & imageRect; + +#ifndef QT_OPENGL_ES_2 + funcs->glPixelStorei(GL_UNPACK_ROW_LENGTH, image.width()); + funcs->glTexSubImage2D(GL_TEXTURE_2D, 0, rect.x(), rect.y(), rect.width(), rect.height(), GL_RGBA, GL_UNSIGNED_BYTE, + image.constScanLine(rect.y()) + rect.x() * 4); + funcs->glPixelStorei(GL_UNPACK_ROW_LENGTH, 0); +#else // if the rect is wide enough it's cheaper to just // extend it instead of doing an image copy if (rect.width() >= imageRect.width() / 2) { @@ -347,6 +354,7 @@ GLuint QPlatformBackingStore::toTexture(const QRegion &dirtyRegion) const funcs->glTexSubImage2D(GL_TEXTURE_2D, 0, rect.x(), rect.y(), rect.width(), rect.height(), GL_RGBA, GL_UNSIGNED_BYTE, image.copy(rect).constBits()); } +#endif } return d_ptr->textureId; |