diff options
author | Jere Tuliniemi <jere.tuliniemi@qt.io> | 2019-12-05 14:12:40 +0200 |
---|---|---|
committer | Jere Tuliniemi <jere.tuliniemi@qt.io> | 2019-12-09 13:32:06 +0200 |
commit | 144d7644eca920a44950282848929602d1e79f90 (patch) | |
tree | d8b070dbd5abfae3c1a8d9b050523dbe1784ce1d | |
parent | 51a30b170d181c30804b1a8d6a9da2ad95dd1033 (diff) |
Add env flag for selecting OpenGL backend
Implementation copied from Quick3D. OpenGL backend can be selected by
setting QT3DS_FORCE_OPENGL_BACKEND to 1, 2 or 3. ES2 backend with 1, GL3
backend with 2 and GL4 backend with 3.
Task-number: QT3DS-4023
Change-Id: I484770240f377b3bfe897f31c986deca5805607f
Reviewed-by: Miikka Heikkinen <miikka.heikkinen@qt.io>
Reviewed-by: Tomi Korpipää <tomi.korpipaa@qt.io>
-rw-r--r-- | src/render/backends/gl/Qt3DSRenderContextGL.cpp | 61 |
1 files changed, 35 insertions, 26 deletions
diff --git a/src/render/backends/gl/Qt3DSRenderContextGL.cpp b/src/render/backends/gl/Qt3DSRenderContextGL.cpp index 88670ef..53af912 100644 --- a/src/render/backends/gl/Qt3DSRenderContextGL.cpp +++ b/src/render/backends/gl/Qt3DSRenderContextGL.cpp @@ -42,50 +42,59 @@ using namespace eastl; namespace qt3ds { namespace render { - NVRenderContext &NVRenderContext::CreateGL(NVFoundationBase &foundation, - IStringTable &inStringTable, - const QSurfaceFormat &format) - { - NVRenderContext *retval = NULL; +NVRenderContext &NVRenderContext::CreateGL(NVFoundationBase &foundation, + IStringTable &inStringTable, + const QSurfaceFormat &format) +{ + NVRenderContext *retval = NULL; - QT3DS_ASSERT(format.majorVersion() >= 2); + QT3DS_ASSERT(format.majorVersion() >= 2); - // create backend - NVScopedRefCounted<IStringTable> theStringTable(inStringTable); - NVScopedRefCounted<NVRenderBackend> theBackend; - bool isES = format.renderableType() == QSurfaceFormat::OpenGLES; + // create backend + NVScopedRefCounted<IStringTable> theStringTable(inStringTable); + NVScopedRefCounted<NVRenderBackend> theBackend; + bool isES = format.renderableType() == QSurfaceFormat::OpenGLES; + + static int envBE = qEnvironmentVariableIntValue("QT3DS_FORCE_OPENGL_BACKEND"); + if (envBE == 1) { + theBackend = QT3DS_NEW(foundation.getAllocator(), NVRenderBackendGLES2Impl)( + foundation, *theStringTable, format); + } else if (envBE == 2) { + theBackend = QT3DS_NEW(foundation.getAllocator(), NVRenderBackendGL3Impl)( + foundation, *theStringTable, format); + } else if (envBE == 3) { + theBackend = QT3DS_NEW(foundation.getAllocator(), NVRenderBackendGL4Impl)( + foundation, *theStringTable, format); + } else { if (isES && (format.majorVersion() == 2 || (format.majorVersion() == 3 && format.minorVersion() == 0))) { - theBackend = QT3DS_NEW(foundation.getAllocator(), NVRenderBackendGLES2Impl)(foundation, - *theStringTable, - format); + theBackend = QT3DS_NEW(foundation.getAllocator(), NVRenderBackendGLES2Impl)( + foundation, *theStringTable, format); } else if (format.majorVersion() == 3 && format.minorVersion() >= 1 && !isES) { - theBackend = QT3DS_NEW(foundation.getAllocator(), NVRenderBackendGL3Impl)(foundation, - *theStringTable, - format); + theBackend = QT3DS_NEW(foundation.getAllocator(), NVRenderBackendGL3Impl)( + foundation, *theStringTable, format); } else if (format.majorVersion() == 4 || (isES && format.majorVersion() == 3 && format.minorVersion() >= 1)) { #ifdef Q_OS_MACOS // TODO: macOS crashes with glTextStorage2DMultisample, so fall back to OpenGL3 // for now (QT3DS-590) - theBackend = QT3DS_NEW(foundation.getAllocator(), NVRenderBackendGL3Impl)(foundation, - *theStringTable, - format); + theBackend = QT3DS_NEW(foundation.getAllocator(), NVRenderBackendGL3Impl)( + foundation, *theStringTable, format); #else - theBackend = QT3DS_NEW(foundation.getAllocator(), NVRenderBackendGL4Impl)(foundation, - *theStringTable, - format); + theBackend = QT3DS_NEW(foundation.getAllocator(), NVRenderBackendGL4Impl)( + foundation, *theStringTable, format); #endif } else { QT3DS_ASSERT(false); qCCritical(INTERNAL_ERROR) << "Can't find a suitable OpenGL version for" << format; } + } + retval = QT3DS_NEW(foundation.getAllocator(), NVRenderContextImpl)(foundation, *theBackend, + *theStringTable); - retval = QT3DS_NEW(foundation.getAllocator(), NVRenderContextImpl)(foundation, *theBackend, - *theStringTable); + return *retval; +} - return *retval; - } } } |