From f9d323279a0b3928acf40d56d84e9e5cc2cb7ee9 Mon Sep 17 00:00:00 2001 From: Laszlo Agocs Date: Thu, 24 Apr 2014 17:11:23 +0200 Subject: Rename new QOpenGLContext APIs isES() becomes isOpenGLES(). The library type enums are changed DesktopGL -> LibGL and GLES2 -> LibGLES. This removes the now unnecessary version number, the confusing "desktop" term and provides better readability. The old function/values are kept until the related qtdeclarative changes are integrated. Task-number: QTBUG-38564 Change-Id: Ibb0a1209985f1ce4bb9451f9b7b093c2b68a6505 Reviewed-by: Sean Harmer --- src/opengl/qgl.cpp | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) (limited to 'src/opengl/qgl.cpp') diff --git a/src/opengl/qgl.cpp b/src/opengl/qgl.cpp index 3cfdcc549c..ae70072c4d 100644 --- a/src/opengl/qgl.cpp +++ b/src/opengl/qgl.cpp @@ -1700,7 +1700,7 @@ QImage qt_gl_read_texture(const QSize &size, bool alpha_format, bool include_alp int w = size.width(); int h = size.height(); #ifndef QT_OPENGL_ES - if (!QOpenGLContext::currentContext()->isES()) { + if (!QOpenGLContext::currentContext()->isOpenGLES()) { //### glGetTexImage not in GL ES 2.0, need to do something else here! glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_UNSIGNED_BYTE, img.bits()); } @@ -2285,7 +2285,7 @@ QGLTexture* QGLContextPrivate::bindTexture(const QImage &image, GLenum target, G glTexParameteri(target, GL_TEXTURE_MAG_FILTER, filtering); QOpenGLContext *ctx = QOpenGLContext::currentContext(); - bool genMipmap = !ctx->isES(); + bool genMipmap = !ctx->isOpenGLES(); if (glFormat.directRendering() && (qgl_extensions()->hasOpenGLExtension(QOpenGLExtensions::GenerateMipmap)) && target == GL_TEXTURE_2D @@ -2427,7 +2427,7 @@ QGLTexture* QGLContextPrivate::bindTexture(const QImage &image, GLenum target, G printf(" - did byte swapping (%d ms)\n", time.elapsed()); #endif } - if (ctx->isES()) { + if (ctx->isOpenGLES()) { // OpenGL/ES requires that the internal and external formats be // identical. internalFormat = externalFormat; @@ -2440,7 +2440,7 @@ QGLTexture* QGLContextPrivate::bindTexture(const QImage &image, GLenum target, G const QImage &constRef = img; // to avoid detach in bits()... glTexImage2D(target, 0, internalFormat, img.width(), img.height(), 0, externalFormat, pixel_type, constRef.bits()); - if (genMipmap && ctx->isES()) + if (genMipmap && ctx->isOpenGLES()) q->functions()->glGenerateMipmap(target); #ifndef QT_NO_DEBUG GLenum error = glGetError(); @@ -2524,7 +2524,7 @@ int QGLContextPrivate::maxTextureSize() #ifndef QT_OPENGL_ES Q_Q(QGLContext); - if (!q->contextHandle()->isES()) { + if (!q->contextHandle()->isOpenGLES()) { GLenum proxy = GL_PROXY_TEXTURE_2D; GLint size; @@ -2702,7 +2702,7 @@ static void qDrawTextureRect(const QRectF &target, GLint textureWidth, GLint tex Q_UNUSED(textureHeight); Q_UNUSED(textureTarget); #else - if (textureTarget != GL_TEXTURE_2D && !QOpenGLContext::currentContext()->isES()) { + if (textureTarget != GL_TEXTURE_2D && !QOpenGLContext::currentContext()->isOpenGLES()) { if (textureWidth == -1 || textureHeight == -1) { glGetTexLevelParameteriv(textureTarget, 0, GL_TEXTURE_WIDTH, &textureWidth); glGetTexLevelParameteriv(textureTarget, 0, GL_TEXTURE_HEIGHT, &textureHeight); @@ -2769,7 +2769,7 @@ void QGLContext::drawTexture(const QRectF &target, GLuint textureId, GLenum text #endif #ifndef QT_OPENGL_ES_2 - if (!contextHandle()->isES()) { + if (!contextHandle()->isOpenGLES()) { #ifdef QT_OPENGL_ES if (textureTarget != GL_TEXTURE_2D) { qWarning("QGLContext::drawTexture(): texture target must be GL_TEXTURE_2D on OpenGL ES"); @@ -2831,7 +2831,7 @@ void QGLContext::drawTexture(const QPointF &point, GLuint textureId, GLenum text Q_UNUSED(textureId); Q_UNUSED(textureTarget); #else - if (!contextHandle()->isES()) { + if (!contextHandle()->isOpenGLES()) { const bool wasEnabled = glIsEnabled(GL_TEXTURE_2D); GLint oldTexture; glGetIntegerv(GL_TEXTURE_BINDING_2D, &oldTexture); @@ -4135,7 +4135,7 @@ void QGLWidget::glDraw() return; makeCurrent(); #ifndef QT_OPENGL_ES - if (d->glcx->deviceIsPixmap() && !d->glcx->contextHandle()->isES()) + if (d->glcx->deviceIsPixmap() && !d->glcx->contextHandle()->isOpenGLES()) glDrawBuffer(GL_FRONT); #endif QSize readback_target_size = d->glcx->d_ptr->readback_target_size; @@ -4180,7 +4180,7 @@ void QGLWidget::qglColor(const QColor& c) const #else Q_D(const QGLWidget); const QGLContext *ctx = QGLContext::currentContext(); - if (ctx && !ctx->contextHandle()->isES()) { + if (ctx && !ctx->contextHandle()->isOpenGLES()) { if (ctx->format().rgba()) glColor4f(c.redF(), c.greenF(), c.blueF(), c.alphaF()); else if (!d->cmap.isEmpty()) { // QGLColormap in use? @@ -4212,7 +4212,7 @@ void QGLWidget::qglClearColor(const QColor& c) const #else Q_D(const QGLWidget); const QGLContext *ctx = QGLContext::currentContext(); - if (ctx && !ctx->contextHandle()->isES()) { + if (ctx && !ctx->contextHandle()->isOpenGLES()) { if (ctx->format().rgba()) glClearColor(c.redF(), c.greenF(), c.blueF(), c.alphaF()); else if (!d->cmap.isEmpty()) { // QGLColormap in use? @@ -4387,7 +4387,7 @@ void QGLWidget::renderText(int x, int y, const QString &str, const QFont &font) { #ifndef QT_OPENGL_ES Q_D(QGLWidget); - if (!d->glcx->contextHandle()->isES()) { + if (!d->glcx->contextHandle()->isOpenGLES()) { Q_D(QGLWidget); if (str.isEmpty() || !isValid()) return; @@ -4477,7 +4477,7 @@ void QGLWidget::renderText(double x, double y, double z, const QString &str, con { #ifndef QT_OPENGL_ES Q_D(QGLWidget); - if (!d->glcx->contextHandle()->isES()) { + if (!d->glcx->contextHandle()->isOpenGLES()) { Q_D(QGLWidget); if (str.isEmpty() || !isValid()) return; -- cgit v1.2.3 From fab46b1c6fb170bd8adc9a289fd5b33e7c6200ab Mon Sep 17 00:00:00 2001 From: Allan Sandfeld Jensen Date: Wed, 23 Apr 2014 13:07:04 +0200 Subject: Avoid a double memory copy during bindTexture If a painter is active on a QPixmap being uploaded, it will be copied twice, first to create a QImage and then from QImage into a texture. The first copy is unnecessary since the QImage is only temporary, so we can force it to be created as a reference instead of a copy. Change-Id: Iabcfb514a634446a01f1c4031349c185ec09290b Reviewed-by: Gunnar Sletta --- src/opengl/qgl.cpp | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'src/opengl/qgl.cpp') diff --git a/src/opengl/qgl.cpp b/src/opengl/qgl.cpp index 3cfdcc549c..d73109dfd9 100644 --- a/src/opengl/qgl.cpp +++ b/src/opengl/qgl.cpp @@ -2497,7 +2497,19 @@ QGLTexture *QGLContextPrivate::bindTexture(const QPixmap &pixmap, GLenum target, } if (!texture) { - QImage image = pixmap.toImage(); + QImage image; + QPaintEngine* paintEngine = pixmap.paintEngine(); + if (!paintEngine || paintEngine->type() != QPaintEngine::Raster) + image = pixmap.toImage(); + else { + // QRasterPixmapData::toImage() will deep-copy the backing QImage if there's an active QPainter on it. + // For performance reasons, we don't want that here, so we temporarily redirect the paint engine. + QPaintDevice* currentPaintDevice = paintEngine->paintDevice(); + paintEngine->setPaintDevice(0); + image = pixmap.toImage(); + paintEngine->setPaintDevice(currentPaintDevice); + } + // If the system depth is 16 and the pixmap doesn't have an alpha channel // then we convert it to RGB16 in the hope that it gets uploaded as a 16 // bit texture which is much faster to access than a 32-bit one. -- cgit v1.2.3