From 0fcf1517a543e19446882ca42b4d2427c04198b8 Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Fri, 10 Aug 2018 14:57:00 -0700 Subject: [PATCH] Fix TextureCache not correctly choosing gl41 when gl45 is disabled --- libraries/model-networking/CMakeLists.txt | 2 +- .../src/model-networking/TextureCache.cpp | 31 +++++++++++++------ 2 files changed, 22 insertions(+), 11 deletions(-) diff --git a/libraries/model-networking/CMakeLists.txt b/libraries/model-networking/CMakeLists.txt index 696f4feb9a..9a4bc780a6 100644 --- a/libraries/model-networking/CMakeLists.txt +++ b/libraries/model-networking/CMakeLists.txt @@ -1,4 +1,4 @@ set(TARGET_NAME model-networking) setup_hifi_library() -link_hifi_libraries(shared networking graphics fbx ktx image) +link_hifi_libraries(shared networking graphics fbx ktx image gl) include_hifi_library_headers(gpu) diff --git a/libraries/model-networking/src/model-networking/TextureCache.cpp b/libraries/model-networking/src/model-networking/TextureCache.cpp index aa00116200..e8aec5e60e 100644 --- a/libraries/model-networking/src/model-networking/TextureCache.cpp +++ b/libraries/model-networking/src/model-networking/TextureCache.cpp @@ -31,6 +31,7 @@ #include #include +#include #include #include @@ -271,6 +272,20 @@ gpu::TexturePointer getFallbackTextureForType(image::TextureUsage::Type type) { return result; } +gpu::BackendTarget getBackendTarget() { +#if defined(USE_GLES) + gpu::BackendTarget target = gpu::BackendTarget::GLES32; +#elif defined(Q_OS_MAC) + gpu::BackendTarget target = gpu::BackendTarget::GL41; +#else + gpu::BackendTarget target = gpu::BackendTarget::GL45; + if (gl::disableGl45()) { + target = gpu::BackendTarget::GL41; + } +#endif + return target; +} + /// Returns a texture version of an image file gpu::TexturePointer TextureCache::getImageTexture(const QString& path, image::TextureUsage::Type type, QVariantMap options) { QImage image = QImage(path); @@ -279,13 +294,14 @@ gpu::TexturePointer TextureCache::getImageTexture(const QString& path, image::Te return nullptr; } auto loader = image::TextureUsage::getTextureLoaderForType(type, options); + #ifdef USE_GLES - gpu::BackendTarget target = gpu::BackendTarget::GLES32; - bool shouldCompress = true; + constexpr bool shouldCompress = true; #else - gpu::BackendTarget target = gpu::BackendTarget::GL45; - bool shouldCompress = false; + constexpr bool shouldCompress = false; #endif + auto target = getBackendTarget(); + return gpu::TexturePointer(loader(std::move(image), path.toStdString(), shouldCompress, target, false)); } @@ -1170,15 +1186,10 @@ void ImageReader::read() { #ifdef USE_GLES constexpr bool shouldCompress = true; - gpu::BackendTarget target = gpu::BackendTarget::GLES32; #else constexpr bool shouldCompress = false; -#ifdef Q_OS_MAC - gpu::BackendTarget target = gpu::BackendTarget::GL41; -#else - gpu::BackendTarget target = gpu::BackendTarget::GL45; -#endif #endif + auto target = getBackendTarget(); texture = image::processImage(std::move(buffer), _url.toString().toStdString(), _maxNumPixels, networkTexture->getTextureType(), shouldCompress, target); if (!texture) {