Force software renderer to using ES2

Task-number: QTRD-3410
Change-Id: I86b240b6548ec4c94f6be0dc352ed112965926f3
Change-Id: I86b240b6548ec4c94f6be0dc352ed112965926f3
Reviewed-by: Miikka Heikkinen <miikka.heikkinen@theqtcompany.com>
This commit is contained in:
Tomi Korpipää 2014-11-05 08:43:49 +02:00
parent a1feedcf46
commit 39d5ffbdc4
4 changed files with 59 additions and 11 deletions

3
README
View File

@ -88,4 +88,5 @@ Known Issues
"QT += datavisualization" in the pro file. This is because Qt Data Visualization QML plugin has
a dependency to Qt Data Visualization C++ library, which Qt Creator doesn't automatically add
to the deployment package.
- Only OpenGL ES2 emulation is available for software renderer (that is, when using
QCoreApplication::setAttribute(Qt::AA_UseSoftwareOpenGL))

View File

@ -338,6 +338,8 @@
"QT += datavisualization" in the pro file. This is because Qt Data Visualization
QML plugin has a dependency to Qt Data Visualization C++ library, which Qt Creator
doesn't automatically add to the deployment package.
\li Only OpenGL ES2 emulation is available for software renderer (that is, when using
QCoreApplication::setAttribute(Qt::AA_UseSoftwareOpenGL))
\endlist
*/

View File

@ -20,29 +20,68 @@
#define QUTILS_H
#include <QtGui/QSurfaceFormat>
#include <QtGui/QOpenGLContext>
#include <QtGui/QOffscreenSurface>
#include <QtCore/QCoreApplication>
namespace QtDataVisualization {
inline static QSurfaceFormat qDefaultSurfaceFormat(bool antialias = true)
{
bool isES = false;
QSurfaceFormat surfaceFormat;
// Common attributes
surfaceFormat.setDepthBufferSize(24);
surfaceFormat.setStencilBufferSize(8);
surfaceFormat.setSwapBehavior(QSurfaceFormat::DoubleBuffer);
surfaceFormat.setRenderableType(QSurfaceFormat::DefaultRenderableType);
QOpenGLContext *ctx = QOpenGLContext::currentContext();
QOffscreenSurface *dummySurface = 0;
if (!ctx) {
dummySurface = new QOffscreenSurface();
dummySurface->setFormat(surfaceFormat);
dummySurface->create();
ctx = new QOpenGLContext;
ctx->setFormat(surfaceFormat);
ctx->create();
ctx->makeCurrent(dummySurface);
}
#if defined(QT_OPENGL_ES_2)
// Antialias not supported for ES
antialias = false;
surfaceFormat.setRedBufferSize(8);
surfaceFormat.setBlueBufferSize(8);
surfaceFormat.setGreenBufferSize(8);
isES = true;
#elif (QT_VERSION < QT_VERSION_CHECK(5, 3, 0))
isES = false;
#else
isES = ctx->isOpenGLES();
#endif
if (antialias)
surfaceFormat.setSamples(8);
else
surfaceFormat.setSamples(0);
if (dummySurface) {
ctx->doneCurrent();
delete ctx;
delete dummySurface;
}
// We support only ES2 emulation with software renderer for now
if (QCoreApplication::testAttribute(Qt::AA_UseSoftwareOpenGL)) {
qWarning("Only OpenGL ES2 emulation is available for software rendering.");
isES = true;
}
if (isES) {
// For ES2 only attributes
surfaceFormat.setRedBufferSize(8);
surfaceFormat.setBlueBufferSize(8);
surfaceFormat.setGreenBufferSize(8);
} else {
// For OpenGL only attributes
if (antialias)
surfaceFormat.setSamples(8);
else
surfaceFormat.setSamples(0);
}
return surfaceFormat;
}

View File

@ -329,7 +329,7 @@ void Utils::resolveStatics()
QOpenGLContext *ctx = QOpenGLContext::currentContext();
QOffscreenSurface *dummySurface = 0;
if (!ctx) {
QSurfaceFormat surfaceFormat = qDefaultSurfaceFormat();
QSurfaceFormat surfaceFormat;
dummySurface = new QOffscreenSurface();
dummySurface->setFormat(surfaceFormat);
dummySurface->create();
@ -355,6 +355,12 @@ void Utils::resolveStatics()
delete dummySurface;
}
// We support only ES2 emulation with software renderer for now
if (QCoreApplication::testAttribute(Qt::AA_UseSoftwareOpenGL)) {
qWarning("Only OpenGL ES2 emulation is available for software rendering.");
isES = true;
}
staticsResolved = true;
}