QOpenGLTexture: fix support for 1D textures

OpenGL ES 2 doesn't support 1D textures. So introduce a proper
feature flag and warn if we try to allocate one there.

Change-Id: I73cf58c1f257d2472564f45bff222231e39aca52
Reviewed-by: James Turner <james.turner@kdab.com>
Reviewed-by: Sean Harmer <sean.harmer@kdab.com>
This commit is contained in:
Giuseppe D'Angelo 2014-02-05 19:49:13 +01:00 committed by The Qt Project
parent 05f7f9bc58
commit bbf3d01f78
2 changed files with 30 additions and 12 deletions

View File

@ -319,15 +319,21 @@ void QOpenGLTexturePrivate::allocateMutableStorage()
return;
case QOpenGLTexture::Target1D:
for (int level = 0; level < mipLevels; ++level)
texFuncs->glTextureImage1D(textureId, target, bindingTarget, level, format,
mipLevelSize(level, dimensions[0]),
0,
QOpenGLTexture::RGBA, QOpenGLTexture::UInt8, 0);
if (features.testFlag(QOpenGLTexture::Texture1D)) {
for (int level = 0; level < mipLevels; ++level)
texFuncs->glTextureImage1D(textureId, target, bindingTarget, level, format,
mipLevelSize(level, dimensions[0]),
0,
QOpenGLTexture::RGBA, QOpenGLTexture::UInt8, 0);
} else {
qWarning("1D textures are not supported");
return;
}
break;
case QOpenGLTexture::Target1DArray:
if (features.testFlag(QOpenGLTexture::TextureArrays)) {
if (features.testFlag(QOpenGLTexture::Texture1D)
&& features.testFlag(QOpenGLTexture::TextureArrays)) {
for (int level = 0; level < mipLevels; ++level)
texFuncs->glTextureImage2D(textureId, target, bindingTarget, level, format,
mipLevelSize(level, dimensions[0]),
@ -335,7 +341,7 @@ void QOpenGLTexturePrivate::allocateMutableStorage()
0,
QOpenGLTexture::RGBA, QOpenGLTexture::UInt8, 0);
} else {
qWarning("Array textures are not supported");
qWarning("1D array textures are not supported");
return;
}
break;
@ -433,16 +439,22 @@ void QOpenGLTexturePrivate::allocateImmutableStorage()
return;
case QOpenGLTexture::Target1D:
texFuncs->glTextureStorage1D(textureId, target, bindingTarget, mipLevels, format,
dimensions[0]);
if (features.testFlag(QOpenGLTexture::Texture1D)) {
texFuncs->glTextureStorage1D(textureId, target, bindingTarget, mipLevels, format,
dimensions[0]);
} else {
qWarning("1D textures are not supported");
return;
}
break;
case QOpenGLTexture::Target1DArray:
if (features.testFlag(QOpenGLTexture::TextureArrays)) {
if (features.testFlag(QOpenGLTexture::Texture1D)
&& features.testFlag(QOpenGLTexture::TextureArrays)) {
texFuncs->glTextureStorage2D(textureId, target, bindingTarget, mipLevels, format,
dimensions[0], layers);
} else {
qWarning("Array textures are not supported");
qWarning("1D array textures are not supported");
return;
}
break;
@ -1356,6 +1368,7 @@ QOpenGLTexture *QOpenGLTexturePrivate::createTextureView(QOpenGLTexture::Target
\value NPOTTextures Basic support for non-power-of-two textures
\value NPOTTextureRepeat Full support for non-power-of-two textures including texture
repeat modes
\value Texture1D Support for the 1 dimensional texture target
*/
/*!
@ -2427,6 +2440,10 @@ bool QOpenGLTexture::hasFeature(Feature feature)
supported = ctx->hasExtension(QByteArrayLiteral("GL_ARB_texture_non_power_of_two"));
break;
case Texture1D:
supported = f.version() >= qMakePair(1, 1);
break;
case MaxFeatureFlag:
break;
}

View File

@ -404,8 +404,9 @@ public:
AnisotropicFiltering = 0x00000400,
NPOTTextures = 0x00000800,
NPOTTextureRepeat = 0x00001000,
Texture1D = 0x00002000,
#ifndef Q_QDOC
MaxFeatureFlag = 0x00002000
MaxFeatureFlag = 0x00004000
#endif
};
Q_DECLARE_FLAGS(Features, Feature)