diff options
author | Konstantin Käfer <mail@kkaefer.com> | 2018-02-08 17:53:05 +0100 |
---|---|---|
committer | Konstantin Käfer <mail@kkaefer.com> | 2018-02-08 17:53:05 +0100 |
commit | 153d8512b7c0bc5ee80e26c868fb52dd66ee62cc (patch) | |
tree | 821349520909225e8a2a138a500b0544970f870c /src | |
parent | 4498917a3b9dbf6cc9728da01f479a027f27f902 (diff) | |
download | qtlocation-mapboxgl-upstream/glcontextmode.tar.gz |
[core] allow disabling the use of extensions via GLContextModeupstream/glcontextmode
Diffstat (limited to 'src')
-rw-r--r-- | src/mbgl/gl/context.cpp | 62 | ||||
-rw-r--r-- | src/mbgl/gl/context.hpp | 13 | ||||
-rw-r--r-- | src/mbgl/renderer/renderer_backend.cpp | 7 | ||||
-rw-r--r-- | src/mbgl/renderer/renderer_impl.cpp | 6 |
4 files changed, 43 insertions, 45 deletions
diff --git a/src/mbgl/gl/context.cpp b/src/mbgl/gl/context.cpp index b6244d58c7..7e51084d5a 100644 --- a/src/mbgl/gl/context.cpp +++ b/src/mbgl/gl/context.cpp @@ -92,7 +92,11 @@ Context::~Context() { } } -void Context::initializeExtensions(const std::function<gl::ProcAddress(const char*)>& getProcAddress) { +void Context::initializeExtensions( + const std::function<gl::ProcAddress(const char*)>& getProcAddress, + bool disableVAOExtension, + bool disableProgramBinariesExtension) { + const std::string renderer = reinterpret_cast<const char*>(MBGL_CHECK_ERROR(glGetString(GL_RENDERER))); if (const auto* extensions = reinterpret_cast<const char*>(MBGL_CHECK_ERROR(glGetString(GL_EXTENSIONS)))) { @@ -109,11 +113,32 @@ void Context::initializeExtensions(const std::function<gl::ProcAddress(const cha }; debugging = std::make_unique<extension::Debugging>(fn); - if (!disableVAOExtension) { + + // Load the Vertex Array Objects extension + // Blacklist Adreno 2xx, 3xx as it crashes on glBuffer(Sub)Data + // Qt + ANGLE crashes with VAO enabled. + if (!disableVAOExtension && + !(renderer.find("Adreno (TM) 2") != std::string::npos || + renderer.find("Adreno (TM) 3") != std::string::npos || + renderer.find("ANGLE") != std::string::npos)) { vertexArray = std::make_unique<extension::VertexArray>(fn); } + + // Load the Program Binaries extension + (void)disableProgramBinariesExtension; #if MBGL_HAS_BINARY_PROGRAMS - programBinary = std::make_unique<extension::ProgramBinary>(fn); + // Blacklist Adreno 3xx, 4xx, and 5xx GPUs due to known bugs: + // https://bugs.chromium.org/p/chromium/issues/detail?id=510637 + // https://chromium.googlesource.com/chromium/src/gpu/+/master/config/gpu_driver_bug_list.json#2316 + // Blacklist Vivante GC4000 due to bugs when linking loaded programs: + // https://github.com/mapbox/mapbox-gl-native/issues/10704 + if (!disableProgramBinariesExtension && + !(renderer.find("Adreno (TM) 3") != std::string::npos || + renderer.find("Adreno (TM) 4") != std::string::npos || + renderer.find("Adreno (TM) 5") != std::string::npos || + renderer.find("Vivante GC4000") != std::string::npos)) { + programBinary = std::make_unique<extension::ProgramBinary>(fn); + } #endif if (!supportsVertexArrays()) { @@ -257,15 +282,7 @@ UniqueTexture Context::createTexture() { } bool Context::supportsVertexArrays() const { - static bool blacklisted = []() { - // Blacklist Adreno 2xx, 3xx as it crashes on glBuffer(Sub)Data - const std::string renderer = reinterpret_cast<const char*>(glGetString(GL_RENDERER)); - return renderer.find("Adreno (TM) 2") != std::string::npos - || renderer.find("Adreno (TM) 3") != std::string::npos; - }(); - - return !blacklisted && - vertexArray && + return vertexArray && vertexArray->genVertexArrays && vertexArray->bindVertexArray && vertexArray->deleteVertexArrays; @@ -273,24 +290,9 @@ bool Context::supportsVertexArrays() const { #if MBGL_HAS_BINARY_PROGRAMS bool Context::supportsProgramBinaries() const { - if (!programBinary || !programBinary->programBinary || !programBinary->getProgramBinary) { - return false; - } - - // Blacklist Adreno 3xx, 4xx, and 5xx GPUs due to known bugs: - // https://bugs.chromium.org/p/chromium/issues/detail?id=510637 - // https://chromium.googlesource.com/chromium/src/gpu/+/master/config/gpu_driver_bug_list.json#2316 - // Blacklist Vivante GC4000 due to bugs when linking loaded programs: - // https://github.com/mapbox/mapbox-gl-native/issues/10704 - const std::string renderer = reinterpret_cast<const char*>(glGetString(GL_RENDERER)); - if (renderer.find("Adreno (TM) 3") != std::string::npos - || renderer.find("Adreno (TM) 4") != std::string::npos - || renderer.find("Adreno (TM) 5") != std::string::npos - || renderer.find("Vivante GC4000") != std::string::npos) { - return false; - } - - return true; + return programBinary && + programBinary->programBinary && + programBinary->getProgramBinary; } optional<std::pair<BinaryProgramFormat, std::string>> diff --git a/src/mbgl/gl/context.hpp b/src/mbgl/gl/context.hpp index 14f078367f..db7b8e133e 100644 --- a/src/mbgl/gl/context.hpp +++ b/src/mbgl/gl/context.hpp @@ -41,7 +41,9 @@ public: Context(); ~Context(); - void initializeExtensions(const std::function<gl::ProcAddress(const char*)>&); + void initializeExtensions(const std::function<gl::ProcAddress(const char*)>&, + bool disableVAOExtension, + bool disableProgramBinariesExtension); void enableDebugging(); @@ -287,15 +289,6 @@ private: std::vector<VertexArrayID> abandonedVertexArrays; std::vector<FramebufferID> abandonedFramebuffers; std::vector<RenderbufferID> abandonedRenderbuffers; - -public: - // For testing and Windows because Qt + ANGLE - // crashes with VAO enabled. -#if defined(_WINDOWS) - bool disableVAOExtension = true; -#else - bool disableVAOExtension = false; -#endif }; } // namespace gl diff --git a/src/mbgl/renderer/renderer_backend.cpp b/src/mbgl/renderer/renderer_backend.cpp index 22d263313c..1d06cb313b 100644 --- a/src/mbgl/renderer/renderer_backend.cpp +++ b/src/mbgl/renderer/renderer_backend.cpp @@ -8,7 +8,8 @@ namespace mbgl { -RendererBackend::RendererBackend() = default; +RendererBackend::RendererBackend(GLContextMode mode_) : mode(mode_) { +} gl::Context& RendererBackend::getContext() { assert(BackendScope::exists()); @@ -16,7 +17,9 @@ gl::Context& RendererBackend::getContext() { context = std::make_unique<gl::Context>(); context->enableDebugging(); context->initializeExtensions( - std::bind(&RendererBackend::getExtensionFunctionPointer, this, std::placeholders::_1)); + std::bind(&RendererBackend::getExtensionFunctionPointer, this, std::placeholders::_1), + mode & GLContextMode::DisableVAOExtension, + mode & GLContextMode::DisableProgramBinariesExtension); }); return *context; } diff --git a/src/mbgl/renderer/renderer_impl.cpp b/src/mbgl/renderer/renderer_impl.cpp index 61e7d17242..e3aff4999c 100644 --- a/src/mbgl/renderer/renderer_impl.cpp +++ b/src/mbgl/renderer/renderer_impl.cpp @@ -272,7 +272,7 @@ void Renderer::Impl::render(const UpdateParameters& updateParameters) { backend.updateAssumedState(); - if (parameters.contextMode == GLContextMode::Shared) { + if (parameters.contextMode & GLContextMode::SharedState) { parameters.context.setDirtyState(); } @@ -300,7 +300,7 @@ void Renderer::Impl::render(const UpdateParameters& updateParameters) { if (const RenderBackgroundLayer* background = layer->as<RenderBackgroundLayer>()) { const BackgroundPaintProperties::PossiblyEvaluated& paint = background->evaluated; - if (parameters.contextMode == GLContextMode::Unique + if (parameters.contextMode == GLContextMode::Automatic && layerImpl.get() == layerImpls->at(0).get() && paint.get<BackgroundPattern>().from.empty()) { // This is a solid background. We can use glClear(). @@ -470,7 +470,7 @@ void Renderer::Impl::render(const UpdateParameters& updateParameters) { parameters.backend.bind(); if (parameters.debugOptions & MapDebugOptions::Overdraw) { parameters.context.clear(Color::black(), ClearDepth::Default, ClearStencil::Default); - } else if (parameters.contextMode == GLContextMode::Shared) { + } else if (parameters.contextMode & GLContextMode::SharedState) { parameters.context.clear({}, ClearDepth::Default, ClearStencil::Default); } else { parameters.context.clear(backgroundColor, ClearDepth::Default, ClearStencil::Default); |