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>
This commit is contained in:
Morten Johan Sørvig 2014-03-19 11:26:30 +01:00 committed by The Qt Project
parent f5b552b590
commit 8c91c9912f

View File

@ -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;