summaryrefslogtreecommitdiffstats
path: root/src/gui/opengl/qopengltexture.cpp
diff options
context:
space:
mode:
authorGiuseppe D'Angelo <giuseppe.dangelo@kdab.com>2014-11-13 18:04:48 +0100
committerSean Harmer <sean.harmer@kdab.com>2014-11-14 20:32:05 +0100
commit766775f6a0aeff1d21877518d9f7eecf44af559b (patch)
tree8e853f7b572d365f9ded816dd85ad1bd9f2c7ad7 /src/gui/opengl/qopengltexture.cpp
parentf29e4ef1a625151079e1c8c7f820efe0a8ee2a6d (diff)
QOpenGLTexture: don't allocate immutable multisample storage if not supported
Multisample textures may be supported without multisample texture storage (e.g. from GL 3.2 to 4.2). And, immutable storage may be present, but not supporting multisample textures (GL 4.3 - 4.4). Thus, we must properly check if we can allocate immutable multisample storage, falling back to mutable multisample storage if we're lacking the feature. Task-number: QTBUG-42643 Change-Id: I1f3d5a9b4296626e40b69a06710331e49c2d1a33 Reviewed-by: Sean Harmer <sean.harmer@kdab.com>
Diffstat (limited to 'src/gui/opengl/qopengltexture.cpp')
-rw-r--r--src/gui/opengl/qopengltexture.cpp38
1 files changed, 35 insertions, 3 deletions
diff --git a/src/gui/opengl/qopengltexture.cpp b/src/gui/opengl/qopengltexture.cpp
index 267505b4f7..8ba139d003 100644
--- a/src/gui/opengl/qopengltexture.cpp
+++ b/src/gui/opengl/qopengltexture.cpp
@@ -412,13 +412,45 @@ static bool isSizedTextureFormat(QOpenGLTexture::TextureFormat internalFormat)
return false;
}
+static bool isTextureTargetMultisample(QOpenGLTexture::Target target)
+{
+ switch (target) {
+ case QOpenGLTexture::Target1D:
+ case QOpenGLTexture::Target1DArray:
+ case QOpenGLTexture::Target2D:
+ case QOpenGLTexture::Target2DArray:
+ case QOpenGLTexture::Target3D:
+ case QOpenGLTexture::TargetCubeMap:
+ case QOpenGLTexture::TargetCubeMapArray:
+ return false;
+
+ case QOpenGLTexture::Target2DMultisample:
+ case QOpenGLTexture::Target2DMultisampleArray:
+ return true;
+
+ case QOpenGLTexture::TargetRectangle:
+ case QOpenGLTexture::TargetBuffer:
+ return false;
+ }
+
+ Q_UNREACHABLE();
+ return false;
+}
+
void QOpenGLTexturePrivate::allocateStorage(QOpenGLTexture::PixelFormat pixelFormat, QOpenGLTexture::PixelType pixelType)
{
// Resolve the actual number of mipmap levels we can use
mipLevels = evaluateMipLevels();
// Use immutable storage whenever possible, falling back to mutable
- if (features.testFlag(QOpenGLTexture::ImmutableStorage) && isSizedTextureFormat(format))
+ // Note that if multisample textures are not supported at all, we'll still fail into
+ // the mutable storage allocation
+ const bool useImmutableStorage = isSizedTextureFormat(format)
+ && (isTextureTargetMultisample(target)
+ ? features.testFlag(QOpenGLTexture::ImmutableMultisampleStorage)
+ : features.testFlag(QOpenGLTexture::ImmutableStorage));
+
+ if (useImmutableStorage)
allocateImmutableStorage();
else
allocateMutableStorage(pixelFormat, pixelType);
@@ -1028,7 +1060,7 @@ void QOpenGLTexturePrivate::allocateImmutableStorage()
break;
case QOpenGLTexture::Target2DMultisample:
- if (features.testFlag(QOpenGLTexture::TextureMultisample)) {
+ if (features.testFlag(QOpenGLTexture::ImmutableMultisampleStorage)) {
texFuncs->glTextureStorage2DMultisample(textureId, target, bindingTarget, samples, format,
dimensions[0], dimensions[1],
fixedSamplePositions);
@@ -1039,7 +1071,7 @@ void QOpenGLTexturePrivate::allocateImmutableStorage()
break;
case QOpenGLTexture::Target2DMultisampleArray:
- if (features.testFlag(QOpenGLTexture::TextureMultisample)
+ if (features.testFlag(QOpenGLTexture::ImmutableMultisampleStorage)
&& features.testFlag(QOpenGLTexture::TextureArrays)) {
texFuncs->glTextureStorage3DMultisample(textureId, target, bindingTarget, samples, format,
dimensions[0], dimensions[1], layers,