diff options
author | Gunnar Sletta <gunnar@sletta.org> | 2015-06-11 10:17:45 +0200 |
---|---|---|
committer | Simon Hausmann <simon.hausmann@theqtcompany.com> | 2015-06-15 09:31:08 +0000 |
commit | e9c5ac78deaae6775ad5cf08c022a0105f7702a7 (patch) | |
tree | 8eca91f4d1dc1c13f07f96369023e42b65bbcded /src/quick/items | |
parent | d845227aca013f9d3c0d63a394a5c27733f6d019 (diff) | |
download | qtdeclarative-e9c5ac78deaae6775ad5cf08c022a0105f7702a7.tar.gz qtdeclarative-e9c5ac78deaae6775ad5cf08c022a0105f7702a7.tar.bz2 qtdeclarative-e9c5ac78deaae6775ad5cf08c022a0105f7702a7.zip |
Add QQuickWindow::TextureIsOpaque as option to createTextureFromImage.
Opaque textures can be a lot faster, so give this option without
forcing the user to reimplement her/his own QSGTexture class.
The old behavior was that createTextureFromImage() disregarded
TextureHasAlphaChannel and looked solely at the image's format. To
keep this behavior intact, we introduce a second opt-in flag to switch
textures from auto-detect to false, namely TextureIsOpaque.
[ChangeLog][QtQuick][QQuickWindow] Add TextureIsOpaque option to
createTextureFromImage()
Change-Id: I248db4bc5f7920864b6aa8d831ce24d23ad370ef
Reviewed-by: Laszlo Agocs <laszlo.agocs@theqtcompany.com>
Diffstat (limited to 'src/quick/items')
-rw-r--r-- | src/quick/items/qquickwindow.cpp | 31 | ||||
-rw-r--r-- | src/quick/items/qquickwindow.h | 3 |
2 files changed, 24 insertions, 10 deletions
diff --git a/src/quick/items/qquickwindow.cpp b/src/quick/items/qquickwindow.cpp index 7ad2cbc3d..90f46d495 100644 --- a/src/quick/items/qquickwindow.cpp +++ b/src/quick/items/qquickwindow.cpp @@ -3372,6 +3372,11 @@ QQmlIncubationController *QQuickWindow::incubationController() const will delete the GL texture when the texture object is deleted. \value TextureCanUseAtlas The image can be uploaded into a texture atlas. + + \value TextureIsOpaque The texture will return false for + QSGTexture::hasAlphaChannel() and will not be blended. This flag was added + in Qt 5.6. + */ /*! @@ -3576,12 +3581,21 @@ QSGTexture *QQuickWindow::createTextureFromImage(const QImage &image) const The caller of the function is responsible for deleting the returned texture. The actual GL texture will be deleted when the texture object is deleted. - When \a options contains TextureCanUseAtlas the engine may put the image + When \a options contains TextureCanUseAtlas, the engine may put the image into a texture atlas. Textures in an atlas need to rely on QSGTexture::normalizedTextureSubRect() for their geometry and will not support QSGTexture::Repeat. Other values from CreateTextureOption are ignored. + When \a options contains TextureIsOpaque, the engine will create an RGB + texture which returns false for QSGTexture::hasAlphaChannel(). Opaque + textures will in most cases be faster to render. When this flag is not set, + the texture will have an alpha channel based on the image's format. + + When \a options contains TextureHasMipmaps, the engine will create a + texture which can use mipmap filtering. Mipmapped textures can not be in + an atlas. + The returned texture will be using \c GL_TEXTURE_2D as texture target and \c GL_RGBA as internal format. Reimplement QSGTexture to create textures with different parameters. @@ -3603,14 +3617,13 @@ QSGTexture *QQuickWindow::createTextureFromImage(const QImage &image) const QSGTexture *QQuickWindow::createTextureFromImage(const QImage &image, CreateTextureOptions options) const { Q_D(const QQuickWindow); - if (d->context) { - if (options & TextureCanUseAtlas) - return d->context->createTexture(image); - else - return d->context->createTextureNoAtlas(image); - } - else - return 0; + if (!d->context) + return 0; + uint flags = 0; + if (options & TextureCanUseAtlas) flags |= QSGRenderContext::CreateTexture_Atlas; + if (options & TextureHasMipmaps) flags |= QSGRenderContext::CreateTexture_Mipmap; + if (!(options & TextureIsOpaque)) flags |= QSGRenderContext::CreateTexture_Alpha; + return d->context->createTexture(image, flags); } diff --git a/src/quick/items/qquickwindow.h b/src/quick/items/qquickwindow.h index 1a1d44c3b..3d09e0c03 100644 --- a/src/quick/items/qquickwindow.h +++ b/src/quick/items/qquickwindow.h @@ -69,7 +69,8 @@ public: TextureHasAlphaChannel = 0x0001, TextureHasMipmaps = 0x0002, TextureOwnsGLTexture = 0x0004, - TextureCanUseAtlas = 0x0008 + TextureCanUseAtlas = 0x0008, + TextureIsOpaque = 0x0010, }; enum RenderStage { |