Resurrect advanced bindTexture() features in QtOpenGL

During the Qt 4 -> 5 migration the setting of the extension flags
in QOpenGLFunctions/Extensions suffered a regression: flags like
GenerateMipmap were never set. This led to the unfortunate sitation
that features that were tied to these flags, like compressed texture
support or mipmap generation, got disabled.

This is now corrected by checking for the extensions like Qt 4 did.

Task-number: QTBUG-37588
Change-Id: I4a7beb1b435af11e05f5304aa04df2ec63b34c18
Reviewed-by: Gunnar Sletta <gunnar.sletta@jollamobile.com>
bb10
Laszlo Agocs 2014-03-19 12:52:03 +01:00 committed by The Qt Project
parent 33cac84df3
commit 8adca56674
2 changed files with 81 additions and 2 deletions

View File

@ -359,10 +359,37 @@ static int qt_gl_resolve_extensions()
{
int extensions = 0;
QOpenGLExtensionMatcher extensionMatcher;
QOpenGLContext *ctx = QOpenGLContext::currentContext();
QSurfaceFormat format = ctx->format();
if (extensionMatcher.match("GL_EXT_bgra"))
extensions |= QOpenGLExtensions::BGRATextureFormat;
if (extensionMatcher.match("GL_ARB_texture_rectangle"))
extensions |= QOpenGLExtensions::TextureRectangle;
if (extensionMatcher.match("GL_SGIS_generate_mipmap"))
extensions |= QOpenGLExtensions::GenerateMipmap;
if (extensionMatcher.match("GL_ARB_texture_compression"))
extensions |= QOpenGLExtensions::TextureCompression;
if (extensionMatcher.match("GL_EXT_texture_compression_s3tc"))
extensions |= QOpenGLExtensions::DDSTextureCompression;
if (extensionMatcher.match("GL_OES_compressed_ETC1_RGB8_texture"))
extensions |= QOpenGLExtensions::ETC1TextureCompression;
if (extensionMatcher.match("GL_IMG_texture_compression_pvrtc"))
extensions |= QOpenGLExtensions::PVRTCTextureCompression;
if (extensionMatcher.match("GL_ARB_texture_mirrored_repeat"))
extensions |= QOpenGLExtensions::MirroredRepeat;
if (extensionMatcher.match("GL_EXT_stencil_two_side"))
extensions |= QOpenGLExtensions::StencilTwoSide;
if (extensionMatcher.match("GL_EXT_stencil_wrap"))
extensions |= QOpenGLExtensions::StencilWrap;
if (extensionMatcher.match("GL_NV_float_buffer"))
extensions |= QOpenGLExtensions::NVFloatBuffer;
if (extensionMatcher.match("GL_ARB_pixel_buffer_object"))
extensions |= QOpenGLExtensions::PixelBufferObject;
if (QOpenGLContext::currentContext()->isES()) {
if (ctx->isES()) {
if (format.majorVersion() >= 2)
extensions |= QOpenGLExtensions::GenerateMipmap;
if (extensionMatcher.match("GL_OES_mapbuffer"))
extensions |= QOpenGLExtensions::MapBuffer;
if (extensionMatcher.match("GL_OES_packed_depth_stencil"))
@ -375,7 +402,6 @@ static int qt_gl_resolve_extensions()
if (extensionMatcher.match("GL_IMG_texture_format_BGRA8888") || extensionMatcher.match("GL_EXT_texture_format_BGRA8888"))
extensions |= QOpenGLExtensions::BGRATextureFormat;
} else {
QSurfaceFormat format = QOpenGLContext::currentContext()->format();
extensions |= QOpenGLExtensions::ElementIndexUint | QOpenGLExtensions::MapBuffer;
// Recognize features by extension name.
@ -394,6 +420,19 @@ static int qt_gl_resolve_extensions()
extensions |= QOpenGLExtensions::PackedDepthStencil;
}
}
if (format.renderableType() == QSurfaceFormat::OpenGL && format.version() >= qMakePair(3, 2))
extensions |= QOpenGLExtensions::GeometryShaders;
#ifndef QT_OPENGL_ES
if (extensionMatcher.match("GL_EXT_framebuffer_sRGB")) {
GLboolean srgbCapableFramebuffers = false;
ctx->functions()->glGetBooleanv(GL_FRAMEBUFFER_SRGB_CAPABLE_EXT, &srgbCapableFramebuffers);
if (srgbCapableFramebuffers)
extensions |= QOpenGLExtensions::SRGBFrameBuffer;
}
#endif
return extensions;
}

View File

@ -60,6 +60,7 @@
#include <QtOpenGL/private/qgl_p.h>
#include <QtGui/private/qimage_p.h>
#include <QtGui/private/qimagepixmapcleanuphooks_p.h>
#include <QtGui/private/qopenglextensions_p.h>
#endif
class tst_QGL : public QObject
@ -99,6 +100,7 @@ private slots:
void threadImages();
void nullRectCrash();
void graphicsViewClipping();
void extensions();
};
tst_QGL::tst_QGL()
@ -2361,5 +2363,43 @@ void tst_QGL::nullRectCrash()
fboPainter.end();
}
void tst_QGL::extensions()
{
QGLWidget glw;
glw.makeCurrent();
QOpenGLContext *ctx = QOpenGLContext::currentContext();
QVERIFY(ctx);
QOpenGLFunctions *funcs = ctx->functions();
QVERIFY(funcs);
QSurfaceFormat format = ctx->format();
#ifdef QT_BUILD_INTERNAL
QOpenGLExtensions *exts = static_cast<QOpenGLExtensions *>(funcs);
QOpenGLExtensions::OpenGLExtensions allExts = exts->openGLExtensions();
// Mipmapping is always available in GL2/GLES2+. Verify this.
if (format.majorVersion() >= 2)
QVERIFY(allExts.testFlag(QOpenGLExtensions::GenerateMipmap));
#endif
// Now look for some features should always be available in a given version.
QOpenGLFunctions::OpenGLFeatures allFeatures = funcs->openGLFeatures();
QVERIFY(allFeatures.testFlag(QOpenGLFunctions::Multitexture));
if (format.majorVersion() >= 2) {
QVERIFY(allFeatures.testFlag(QOpenGLFunctions::Shaders));
QVERIFY(allFeatures.testFlag(QOpenGLFunctions::Buffers));
QVERIFY(allFeatures.testFlag(QOpenGLFunctions::Multisample));
QVERIFY(!ctx->isES() || allFeatures.testFlag(QOpenGLFunctions::Framebuffers));
QVERIFY(allFeatures.testFlag(QOpenGLFunctions::NPOTTextures)
&& allFeatures.testFlag(QOpenGLFunctions::NPOTTextureRepeat));
if (ctx->isES()) {
QVERIFY(!allFeatures.testFlag(QOpenGLFunctions::FixedFunctionPipeline));
QVERIFY(allFeatures.testFlag(QOpenGLFunctions::Framebuffers));
}
}
if (format.majorVersion() >= 3)
QVERIFY(allFeatures.testFlag(QOpenGLFunctions::Framebuffers));
}
QTEST_MAIN(tst_QGL)
#include "tst_qgl.moc"