From 7c2620578ba0698a14c1d4ff5c7a4e260f06ad31 Mon Sep 17 00:00:00 2001 From: Gunnar Sletta Date: Fri, 28 Aug 2009 14:07:20 +0200 Subject: Attempting to make EGL compile again and fix some potential issues with flipped pixmaps on X11 --- .../gl2paintengineex/qpaintengineex_opengl2.cpp | 4 +++- src/opengl/qgl.cpp | 8 ++++++- src/opengl/qgl.h | 25 +++++++++++++--------- src/opengl/qgl_x11.cpp | 5 +++-- src/opengl/qgl_x11egl.cpp | 10 ++++++--- 5 files changed, 35 insertions(+), 17 deletions(-) diff --git a/src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp b/src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp index cc9b014..612ba1b 100644 --- a/src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp +++ b/src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp @@ -1104,7 +1104,9 @@ void QGL2PaintEngineEx::drawPixmap(const QRectF& dest, const QPixmap & pixmap, c QGLContext *ctx = d->ctx; glActiveTexture(GL_TEXTURE0 + QT_IMAGE_TEXTURE_UNIT); QGLTexture *texture = - ctx->d_func()->bindTexture(pixmap, GL_TEXTURE_2D, GL_RGBA, QGLContext::InternalBindOption); + ctx->d_func()->bindTexture(pixmap, GL_TEXTURE_2D, GL_RGBA, + QGLContext::InternalBindOption + | QGLContext::CanFlipNativePixmapBindOption); GLfloat top = texture->options & QGLContext::InvertedYBindOption ? (pixmap.height() - src.top()) : src.top(); GLfloat bottom = texture->options & QGLContext::InvertedYBindOption ? (pixmap.height() - src.bottom()) : src.bottom(); diff --git a/src/opengl/qgl.cpp b/src/opengl/qgl.cpp index 02991d9..b4c7e10 100644 --- a/src/opengl/qgl.cpp +++ b/src/opengl/qgl.cpp @@ -1607,7 +1607,13 @@ Q_OPENGL_EXPORT QGLShareRegister* qgl_share_reg() would mirror the image and automatically generate mipmaps. This option helps preserve this default behavior. - \omitvalue MemoryManagedBindOption + \omitvalue CanFlipNativePixmapBindOption Used by x11 from pixmap to choose + wether or not it can bind the pixmap upside down or not. + + \omitvalue MemoryManagedBindOption Used by paint engines to + indicate that the pixmap should be memory managed along side with + the pixmap/image that it stems from, e.g. installing destruction + hooks in them. \omitvalue InternalBindOption */ diff --git a/src/opengl/qgl.h b/src/opengl/qgl.h index 13ad668..96a8b08 100644 --- a/src/opengl/qgl.h +++ b/src/opengl/qgl.h @@ -289,16 +289,20 @@ public: virtual void swapBuffers() const; enum BindOption { - NoBindOption = 0x0000, - InvertedYBindOption = 0x0001, - MipmapBindOption = 0x0002, - PremultipliedAlphaBindOption = 0x0004, - LinearFilteringBindOption = 0x0008, - - MemoryManagedBindOption = 0x1000, // internal flag - - DefaultBindOption = LinearFilteringBindOption | InvertedYBindOption | MipmapBindOption, - InternalBindOption = MemoryManagedBindOption | PremultipliedAlphaBindOption + NoBindOption = 0x0000, + InvertedYBindOption = 0x0001, + MipmapBindOption = 0x0002, + PremultipliedAlphaBindOption = 0x0004, + LinearFilteringBindOption = 0x0008, + + MemoryManagedBindOption = 0x0010, // internal flag + CanFlipNativePixmapBindOption = 0x0020, // internal flag + + DefaultBindOption = LinearFilteringBindOption + | InvertedYBindOption + | MipmapBindOption, + InternalBindOption = MemoryManagedBindOption + | PremultipliedAlphaBindOption }; Q_DECLARE_FLAGS(BindOptions, BindOption) @@ -407,6 +411,7 @@ private: Q_DISABLE_COPY(QGLContext) }; +Q_DECLARE_OPERATORS_FOR_FLAGS(QGLContext::BindOptions); class Q_OPENGL_EXPORT QGLWidget : public QWidget { diff --git a/src/opengl/qgl_x11.cpp b/src/opengl/qgl_x11.cpp index aca60bc..a34ea37 100644 --- a/src/opengl/qgl_x11.cpp +++ b/src/opengl/qgl_x11.cpp @@ -1633,7 +1633,7 @@ QGLTexture *QGLContextPrivate::bindTextureFromNativePixmap(QPixmapData *pmd, con GLX_DRAWABLE_TYPE, GLX_PIXMAP_BIT, GLX_BIND_TO_TEXTURE_TARGETS_EXT, GLX_TEXTURE_2D_BIT_EXT, // QGLContext::bindTexture() can't return an inverted texture, but QPainter::drawPixmap() can: - GLX_Y_INVERTED_EXT, options & QGLContext::InvertedYBindOption ? GLX_DONT_CARE : False, + GLX_Y_INVERTED_EXT, options & QGLContext::CanFlipNativePixmapBindOption ? GLX_DONT_CARE : False, XNone }; configList = glXChooseFBConfig(x11Info.display(), x11Info.screen(), configAttribs, &configCount); @@ -1694,8 +1694,9 @@ QGLTexture *QGLContextPrivate::bindTextureFromNativePixmap(QPixmapData *pmd, con glBindTexture(GL_TEXTURE_2D, textureId); - if (!((hasAlpha && RGBAConfigInverted) || (!hasAlpha && RGBConfigInverted))); + if (!((hasAlpha && RGBAConfigInverted) || (!hasAlpha && RGBConfigInverted))) options &= ~QGLContext::InvertedYBindOption; + QGLTexture *texture = new QGLTexture(q, textureId, GL_TEXTURE_2D, options); if (texture->options & QGLContext::InvertedYBindOption) pixmapData->flags |= QX11PixmapData::InvertedWhenBoundToTexture; diff --git a/src/opengl/qgl_x11egl.cpp b/src/opengl/qgl_x11egl.cpp index b982a19..f40cdc9 100644 --- a/src/opengl/qgl_x11egl.cpp +++ b/src/opengl/qgl_x11egl.cpp @@ -490,12 +490,13 @@ void QGLWidgetPrivate::recreateEglSurface(bool force) } -QGLTexture *QGLContextPrivate::bindTextureFromNativePixmap(QPixmapData* pd, const qint64 key, bool canInvert) +QGLTexture *QGLContextPrivate::bindTextureFromNativePixmap(QPixmapData* pd, const qint64 key, + QGLContext::BindOptions options) { Q_Q(QGLContext); // The EGL texture_from_pixmap has no facility to invert the y coordinate - if (!canInvert) + if (!(options & QGLContext::CanFlipNativePixmapBindOption)) return 0; Q_ASSERT(pd->classId() == QPixmapData::X11Class); @@ -623,7 +624,10 @@ QGLTexture *QGLContextPrivate::bindTextureFromNativePixmap(QPixmapData* pd, cons return 0; } - QGLTexture *texture = new QGLTexture(q, textureId, GL_TEXTURE_2D, canInvert, true); + // Always inverted because the opposite is not supported... + options |= QGLContext::InvertedYBindOption; + + QGLTexture *texture = new QGLTexture(q, textureId, GL_TEXTURE_2D, options); pixmapData->flags |= QX11PixmapData::InvertedWhenBoundToTexture; // We assume the cost of bound pixmaps is zero -- cgit v0.12