From ea2b188b64fb89ff51bd9bdf3c958757296afb4c Mon Sep 17 00:00:00 2001 From: Atlante45 Date: Tue, 2 May 2017 17:07:50 -0700 Subject: [PATCH 1/5] Recompute Y from X/Z for normal maps --- libraries/render-utils/src/MaterialTextures.slh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/libraries/render-utils/src/MaterialTextures.slh b/libraries/render-utils/src/MaterialTextures.slh index 7b73896cc5..a530f4faf2 100644 --- a/libraries/render-utils/src/MaterialTextures.slh +++ b/libraries/render-utils/src/MaterialTextures.slh @@ -64,7 +64,9 @@ float fetchRoughnessMap(vec2 uv) { uniform sampler2D normalMap; vec3 fetchNormalMap(vec2 uv) { // unpack normal, swizzle to get into hifi tangent space with Y axis pointing out - return normalize(texture(normalMap, uv).rbg -vec3(0.5, 0.5, 0.5)); + vec2 t = 2.0 * (texture(normalMap, uv).rg - vec2(0.5, 0.5)); + vec2 t2 = t*t; + return normalize(vec3(t.x, sqrt(1 - t2.x - t2.y), t.y)); } <@endif@> From 10289f542319dfe689a51b581305d247eb2c77f9 Mon Sep 17 00:00:00 2001 From: Atlante45 Date: Tue, 2 May 2017 19:39:07 -0700 Subject: [PATCH 2/5] Format non compressed normal maps to new format. --- libraries/gpu-gl/src/gpu/gl/GLTexelFormat.cpp | 3 ++ libraries/gpu/src/gpu/Format.cpp | 2 ++ libraries/gpu/src/gpu/Format.h | 1 + libraries/gpu/src/gpu/Texture_ktx.cpp | 2 ++ libraries/image/src/image/Image.cpp | 36 ++++++++++--------- 5 files changed, 28 insertions(+), 16 deletions(-) diff --git a/libraries/gpu-gl/src/gpu/gl/GLTexelFormat.cpp b/libraries/gpu-gl/src/gpu/gl/GLTexelFormat.cpp index 7f724cce65..12bfb8e70b 100644 --- a/libraries/gpu-gl/src/gpu/gl/GLTexelFormat.cpp +++ b/libraries/gpu-gl/src/gpu/gl/GLTexelFormat.cpp @@ -140,6 +140,7 @@ GLenum GLTexelFormat::evalGLTexelFormatInternal(const gpu::Element& dstFormat) { switch (dstFormat.getSemantic()) { case gpu::RGB: case gpu::RGBA: + case gpu::XY: result = GL_RG8; break; default: @@ -289,6 +290,7 @@ GLTexelFormat GLTexelFormat::evalGLTexelFormat(const Element& dstFormat, const E switch (dstFormat.getSemantic()) { case gpu::RGB: case gpu::RGBA: + case gpu::XY: texel.internalFormat = GL_RG8; break; default: @@ -516,6 +518,7 @@ GLTexelFormat GLTexelFormat::evalGLTexelFormat(const Element& dstFormat, const E switch (dstFormat.getSemantic()) { case gpu::RGB: case gpu::RGBA: + case gpu::XY: texel.internalFormat = GL_RG8; break; default: diff --git a/libraries/gpu/src/gpu/Format.cpp b/libraries/gpu/src/gpu/Format.cpp index 19d8855bd9..a9c7d249a8 100644 --- a/libraries/gpu/src/gpu/Format.cpp +++ b/libraries/gpu/src/gpu/Format.cpp @@ -25,6 +25,8 @@ const Element Element::COLOR_COMPRESSED_SRGBA_MASK{ VEC4, NUINT8, COMPRESSED_BC1 const Element Element::COLOR_COMPRESSED_SRGBA{ VEC4, NUINT8, COMPRESSED_BC3_SRGBA }; const Element Element::COLOR_COMPRESSED_XY{ VEC4, NUINT8, COMPRESSED_BC5_XY }; +const Element Element::VEC2_XY{ VEC2, NUINT8, XY }; + const Element Element::COLOR_R11G11B10{ SCALAR, FLOAT, R11G11B10 }; const Element Element::VEC4F_COLOR_RGBA{ VEC4, FLOAT, RGBA }; const Element Element::VEC2F_UV{ VEC2, FLOAT, UV }; diff --git a/libraries/gpu/src/gpu/Format.h b/libraries/gpu/src/gpu/Format.h index f69e8d9386..9fadcecb22 100644 --- a/libraries/gpu/src/gpu/Format.h +++ b/libraries/gpu/src/gpu/Format.h @@ -234,6 +234,7 @@ public: static const Element COLOR_COMPRESSED_SRGBA_MASK; static const Element COLOR_COMPRESSED_SRGBA; static const Element COLOR_COMPRESSED_XY; + static const Element VEC2_XY; static const Element VEC4F_COLOR_RGBA; static const Element VEC2F_UV; static const Element VEC2F_XY; diff --git a/libraries/gpu/src/gpu/Texture_ktx.cpp b/libraries/gpu/src/gpu/Texture_ktx.cpp index d2f93c0036..4952e7a83b 100644 --- a/libraries/gpu/src/gpu/Texture_ktx.cpp +++ b/libraries/gpu/src/gpu/Texture_ktx.cpp @@ -423,6 +423,8 @@ bool Texture::evalKTXFormat(const Element& mipFormat, const Element& texelFormat header.setUncompressed(ktx::GLType::UNSIGNED_BYTE, 1, ktx::GLFormat::RGBA, ktx::GLInternalFormat_Uncompressed::SRGB8_ALPHA8, ktx::GLBaseInternalFormat::RGBA); } else if (texelFormat == Format::COLOR_R_8 && mipFormat == Format::COLOR_R_8) { header.setUncompressed(ktx::GLType::UNSIGNED_BYTE, 1, ktx::GLFormat::RED, ktx::GLInternalFormat_Uncompressed::R8, ktx::GLBaseInternalFormat::RED); + } else if (texelFormat == Format::VEC2_XY && mipFormat == Format::VEC2_XY) { + header.setUncompressed(ktx::GLType::UNSIGNED_BYTE, 1, ktx::GLFormat::RG, ktx::GLInternalFormat_Uncompressed::RG8, ktx::GLBaseInternalFormat::RG); } else if (texelFormat == Format::COLOR_COMPRESSED_SRGB && mipFormat == Format::COLOR_COMPRESSED_SRGB) { header.setCompressed(ktx::GLInternalFormat_Compressed::COMPRESSED_SRGB_S3TC_DXT1_EXT, ktx::GLBaseInternalFormat::RGB); } else if (texelFormat == Format::COLOR_COMPRESSED_SRGBA_MASK && mipFormat == Format::COLOR_COMPRESSED_SRGBA_MASK) { diff --git a/libraries/image/src/image/Image.cpp b/libraries/image/src/image/Image.cpp index 707a2e4496..63c7d0d8ab 100644 --- a/libraries/image/src/image/Image.cpp +++ b/libraries/image/src/image/Image.cpp @@ -290,6 +290,19 @@ void generateMips(gpu::Texture* texture, QImage& image, int face = -1) { float inputGamma = 2.2f; float outputGamma = 2.2f; + nvtt::InputOptions inputOptions; + inputOptions.setTextureLayout(textureType, width, height); + inputOptions.setMipmapData(data, width, height); + + inputOptions.setFormat(inputFormat); + inputOptions.setGamma(inputGamma, outputGamma); + inputOptions.setAlphaMode(alphaMode); + inputOptions.setWrapMode(wrapMode); + inputOptions.setRoundMode(roundMode); + + inputOptions.setMipmapGeneration(true); + inputOptions.setMipmapFilter(nvtt::MipmapFilter_Box); + nvtt::CompressionOptions compressionOptions; compressionOptions.setQuality(nvtt::Quality_Production); @@ -346,26 +359,17 @@ void generateMips(gpu::Texture* texture, QImage& image, int face = -1) { compressionOptions.setFormat(nvtt::Format_RGB); compressionOptions.setPixelType(nvtt::PixelType_UnsignedNorm); compressionOptions.setPixelFormat(8, 0, 0, 0); + } else if (mipFormat == gpu::Element::VEC2_XY) { + inputOptions.setNormalMap(true); + compressionOptions.setFormat(nvtt::Format_RGBA); + compressionOptions.setPixelType(nvtt::PixelType_UnsignedNorm); + compressionOptions.setPixelFormat(8, 8, 0, 0); } else { qCWarning(imagelogging) << "Unknown mip format"; Q_UNREACHABLE(); return; } - - nvtt::InputOptions inputOptions; - inputOptions.setTextureLayout(textureType, width, height); - inputOptions.setMipmapData(data, width, height); - - inputOptions.setFormat(inputFormat); - inputOptions.setGamma(inputGamma, outputGamma); - inputOptions.setAlphaMode(alphaMode); - inputOptions.setWrapMode(wrapMode); - inputOptions.setRoundMode(roundMode); - - inputOptions.setMipmapGeneration(true); - inputOptions.setMipmapFilter(nvtt::MipmapFilter_Box); - nvtt::OutputOptions outputOptions; outputOptions.setOutputHeader(false); MyOutputHandler outputHandler(texture, face); @@ -548,8 +552,8 @@ gpu::TexturePointer TextureUsage::process2DTextureNormalMapFromImage(const QImag gpu::Element formatMip = gpu::Element::COLOR_COMPRESSED_XY; gpu::Element formatGPU = gpu::Element::COLOR_COMPRESSED_XY; #else - gpu::Element formatMip = gpu::Element::COLOR_RGBA_32; - gpu::Element formatGPU = gpu::Element::COLOR_RGBA_32; + gpu::Element formatMip = gpu::Element::VEC2_XY; + gpu::Element formatGPU = gpu::Element::VEC2_XY; #endif theTexture = gpu::Texture::create2D(formatGPU, image.width(), image.height(), gpu::Texture::MAX_NUM_MIPS, gpu::Sampler(gpu::Sampler::FILTER_MIN_MAG_MIP_LINEAR)); From 542923839dc75a4e55297d7a4df9eddf03432e4b Mon Sep 17 00:00:00 2001 From: Atlante45 Date: Wed, 3 May 2017 15:54:07 -0700 Subject: [PATCH 3/5] Change name to VEC2NU8_XY --- libraries/gpu/src/gpu/Format.cpp | 2 +- libraries/gpu/src/gpu/Format.h | 2 +- libraries/gpu/src/gpu/Texture_ktx.cpp | 2 +- libraries/image/src/image/Image.cpp | 6 +++--- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/libraries/gpu/src/gpu/Format.cpp b/libraries/gpu/src/gpu/Format.cpp index a9c7d249a8..43bcd35b88 100644 --- a/libraries/gpu/src/gpu/Format.cpp +++ b/libraries/gpu/src/gpu/Format.cpp @@ -25,7 +25,7 @@ const Element Element::COLOR_COMPRESSED_SRGBA_MASK{ VEC4, NUINT8, COMPRESSED_BC1 const Element Element::COLOR_COMPRESSED_SRGBA{ VEC4, NUINT8, COMPRESSED_BC3_SRGBA }; const Element Element::COLOR_COMPRESSED_XY{ VEC4, NUINT8, COMPRESSED_BC5_XY }; -const Element Element::VEC2_XY{ VEC2, NUINT8, XY }; +const Element Element::VEC2NU8_XY{ VEC2, NUINT8, XY }; const Element Element::COLOR_R11G11B10{ SCALAR, FLOAT, R11G11B10 }; const Element Element::VEC4F_COLOR_RGBA{ VEC4, FLOAT, RGBA }; diff --git a/libraries/gpu/src/gpu/Format.h b/libraries/gpu/src/gpu/Format.h index 9fadcecb22..8b7bbdcbed 100644 --- a/libraries/gpu/src/gpu/Format.h +++ b/libraries/gpu/src/gpu/Format.h @@ -234,7 +234,7 @@ public: static const Element COLOR_COMPRESSED_SRGBA_MASK; static const Element COLOR_COMPRESSED_SRGBA; static const Element COLOR_COMPRESSED_XY; - static const Element VEC2_XY; + static const Element VEC2NU8_XY; static const Element VEC4F_COLOR_RGBA; static const Element VEC2F_UV; static const Element VEC2F_XY; diff --git a/libraries/gpu/src/gpu/Texture_ktx.cpp b/libraries/gpu/src/gpu/Texture_ktx.cpp index 4952e7a83b..7c61540043 100644 --- a/libraries/gpu/src/gpu/Texture_ktx.cpp +++ b/libraries/gpu/src/gpu/Texture_ktx.cpp @@ -423,7 +423,7 @@ bool Texture::evalKTXFormat(const Element& mipFormat, const Element& texelFormat header.setUncompressed(ktx::GLType::UNSIGNED_BYTE, 1, ktx::GLFormat::RGBA, ktx::GLInternalFormat_Uncompressed::SRGB8_ALPHA8, ktx::GLBaseInternalFormat::RGBA); } else if (texelFormat == Format::COLOR_R_8 && mipFormat == Format::COLOR_R_8) { header.setUncompressed(ktx::GLType::UNSIGNED_BYTE, 1, ktx::GLFormat::RED, ktx::GLInternalFormat_Uncompressed::R8, ktx::GLBaseInternalFormat::RED); - } else if (texelFormat == Format::VEC2_XY && mipFormat == Format::VEC2_XY) { + } else if (texelFormat == Format::VEC2NU8_XY && mipFormat == Format::VEC2NU8_XY) { header.setUncompressed(ktx::GLType::UNSIGNED_BYTE, 1, ktx::GLFormat::RG, ktx::GLInternalFormat_Uncompressed::RG8, ktx::GLBaseInternalFormat::RG); } else if (texelFormat == Format::COLOR_COMPRESSED_SRGB && mipFormat == Format::COLOR_COMPRESSED_SRGB) { header.setCompressed(ktx::GLInternalFormat_Compressed::COMPRESSED_SRGB_S3TC_DXT1_EXT, ktx::GLBaseInternalFormat::RGB); diff --git a/libraries/image/src/image/Image.cpp b/libraries/image/src/image/Image.cpp index 63c7d0d8ab..825b07003b 100644 --- a/libraries/image/src/image/Image.cpp +++ b/libraries/image/src/image/Image.cpp @@ -359,7 +359,7 @@ void generateMips(gpu::Texture* texture, QImage& image, int face = -1) { compressionOptions.setFormat(nvtt::Format_RGB); compressionOptions.setPixelType(nvtt::PixelType_UnsignedNorm); compressionOptions.setPixelFormat(8, 0, 0, 0); - } else if (mipFormat == gpu::Element::VEC2_XY) { + } else if (mipFormat == gpu::Element::VEC2NU8_XY) { inputOptions.setNormalMap(true); compressionOptions.setFormat(nvtt::Format_RGBA); compressionOptions.setPixelType(nvtt::PixelType_UnsignedNorm); @@ -552,8 +552,8 @@ gpu::TexturePointer TextureUsage::process2DTextureNormalMapFromImage(const QImag gpu::Element formatMip = gpu::Element::COLOR_COMPRESSED_XY; gpu::Element formatGPU = gpu::Element::COLOR_COMPRESSED_XY; #else - gpu::Element formatMip = gpu::Element::VEC2_XY; - gpu::Element formatGPU = gpu::Element::VEC2_XY; + gpu::Element formatMip = gpu::Element::VEC2NU8_XY; + gpu::Element formatGPU = gpu::Element::VEC2NU8_XY; #endif theTexture = gpu::Texture::create2D(formatGPU, image.width(), image.height(), gpu::Texture::MAX_NUM_MIPS, gpu::Sampler(gpu::Sampler::FILTER_MIN_MAG_MIP_LINEAR)); From f728ae795595550182cc45554f85f020a2a5caa6 Mon Sep 17 00:00:00 2001 From: Atlante45 Date: Thu, 4 May 2017 12:38:27 -0700 Subject: [PATCH 4/5] Remove unecessary normalize --- libraries/render-utils/src/MaterialTextures.slh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/render-utils/src/MaterialTextures.slh b/libraries/render-utils/src/MaterialTextures.slh index a530f4faf2..e694935361 100644 --- a/libraries/render-utils/src/MaterialTextures.slh +++ b/libraries/render-utils/src/MaterialTextures.slh @@ -66,7 +66,7 @@ vec3 fetchNormalMap(vec2 uv) { // unpack normal, swizzle to get into hifi tangent space with Y axis pointing out vec2 t = 2.0 * (texture(normalMap, uv).rg - vec2(0.5, 0.5)); vec2 t2 = t*t; - return normalize(vec3(t.x, sqrt(1 - t2.x - t2.y), t.y)); + return vec3(t.x, sqrt(1 - t2.x - t2.y), t.y); } <@endif@> From ecda3132233f36dd53046ab9ff92f730fd0adc0e Mon Sep 17 00:00:00 2001 From: Atlante45 Date: Thu, 4 May 2017 15:07:59 -0700 Subject: [PATCH 5/5] Add runtime access to compression settings --- interface/src/ui/PreferencesDialog.cpp | 24 +++++ libraries/image/src/image/Image.cpp | 131 ++++++++++++++++++------- libraries/image/src/image/Image.h | 10 ++ 3 files changed, 131 insertions(+), 34 deletions(-) diff --git a/interface/src/ui/PreferencesDialog.cpp b/interface/src/ui/PreferencesDialog.cpp index e2e22fe366..767c122bb6 100644 --- a/interface/src/ui/PreferencesDialog.cpp +++ b/interface/src/ui/PreferencesDialog.cpp @@ -330,6 +330,30 @@ void setupPreferences() { preferences->addPreference(preference); } } + { + auto getter = []()->bool { return image::isColorTexturesCompressionEnabled(); }; + auto setter = [](bool value) { return image::setColorTexturesCompressionEnabled(value); }; + auto preference = new CheckPreference(RENDER, "Compress Color Textures", getter, setter); + preferences->addPreference(preference); + } + { + auto getter = []()->bool { return image::isNormalTexturesCompressionEnabled(); }; + auto setter = [](bool value) { return image::setNormalTexturesCompressionEnabled(value); }; + auto preference = new CheckPreference(RENDER, "Compress Normal Textures", getter, setter); + preferences->addPreference(preference); + } + { + auto getter = []()->bool { return image::isGrayscaleTexturesCompressionEnabled(); }; + auto setter = [](bool value) { return image::setGrayscaleTexturesCompressionEnabled(value); }; + auto preference = new CheckPreference(RENDER, "Compress Grayscale Textures", getter, setter); + preferences->addPreference(preference); + } + { + auto getter = []()->bool { return image::isCubeTexturesCompressionEnabled(); }; + auto setter = [](bool value) { return image::setCubeTexturesCompressionEnabled(value); }; + auto preference = new CheckPreference(RENDER, "Compress Cube Textures", getter, setter); + preferences->addPreference(preference); + } } { static const QString RENDER("Networking"); diff --git a/libraries/image/src/image/Image.cpp b/libraries/image/src/image/Image.cpp index 825b07003b..68add428c1 100644 --- a/libraries/image/src/image/Image.cpp +++ b/libraries/image/src/image/Image.cpp @@ -22,16 +22,19 @@ #include #include #include +#include #include "ImageLogging.h" using namespace gpu; #define CPU_MIPMAPS 1 -#define COMPRESS_COLOR_TEXTURES 0 -#define COMPRESS_NORMALMAP_TEXTURES 0 // Disable Normalmap compression for now -#define COMPRESS_GRAYSCALE_TEXTURES 0 -#define COMPRESS_CUBEMAP_TEXTURES 0 // Disable Cubemap compression for now + +static std::mutex settingsMutex; +static Setting::Handle compressColorTextures("hifi.graphics.compressColorTextures", false); +static Setting::Handle compressNormalTextures("hifi.graphics.compressNormalTextures", false); +static Setting::Handle compressGrayscaleTextures("hifi.graphics.compressGrayscaleTextures", false); +static Setting::Handle compressCubeTextures("hifi.graphics.compressCubeTextures", false); static const glm::uvec2 SPARSE_PAGE_SIZE(128); static const glm::uvec2 MAX_TEXTURE_SIZE(4096); @@ -144,6 +147,64 @@ gpu::TexturePointer TextureUsage::createCubeTextureFromImageWithoutIrradiance(co return processCubeTextureColorFromImage(srcImage, srcImageName, false); } + +bool isColorTexturesCompressionEnabled() { +#if CPU_MIPMAPS + std::lock_guard guard(settingsMutex); + return compressColorTextures.get(); +#else + return false; +#endif +} + +bool isNormalTexturesCompressionEnabled() { +#if CPU_MIPMAPS + std::lock_guard guard(settingsMutex); + return compressNormalTextures.get(); +#else + return false; +#endif +} + +bool isGrayscaleTexturesCompressionEnabled() { +#if CPU_MIPMAPS + std::lock_guard guard(settingsMutex); + return compressGrayscaleTextures.get(); +#else + return false; +#endif +} + +bool isCubeTexturesCompressionEnabled() { +#if CPU_MIPMAPS + std::lock_guard guard(settingsMutex); + return compressCubeTextures.get(); +#else + return false; +#endif +} + +void setColorTexturesCompressionEnabled(bool enabled) { + std::lock_guard guard(settingsMutex); + compressColorTextures.set(enabled); +} + +void setNormalTexturesCompressionEnabled(bool enabled) { + std::lock_guard guard(settingsMutex); + compressNormalTextures.set(enabled); +} + +void setGrayscaleTexturesCompressionEnabled(bool enabled) { + std::lock_guard guard(settingsMutex); + compressGrayscaleTextures.set(enabled); +} + +void setCubeTexturesCompressionEnabled(bool enabled) { + std::lock_guard guard(settingsMutex); + compressCubeTextures.set(enabled); +} + + gpu::TexturePointer processImage(const QByteArray& content, const std::string& filename, int maxNumPixels, TextureUsage::Type textureType) { // Help the QImage loader by extracting the image file format from the url filename ext. // Some tga are not created properly without it. @@ -428,18 +489,19 @@ gpu::TexturePointer TextureUsage::process2DTextureColorFromImage(const QImage& s gpu::TexturePointer theTexture = nullptr; if ((image.width() > 0) && (image.height() > 0)) { -#if CPU_MIPMAPS && COMPRESS_COLOR_TEXTURES + gpu::Element formatMip; gpu::Element formatGPU; - if (validAlpha) { - formatGPU = alphaAsMask ? gpu::Element::COLOR_COMPRESSED_SRGBA_MASK : gpu::Element::COLOR_COMPRESSED_SRGBA; + if (isColorTexturesCompressionEnabled()) { + if (validAlpha) { + formatGPU = alphaAsMask ? gpu::Element::COLOR_COMPRESSED_SRGBA_MASK : gpu::Element::COLOR_COMPRESSED_SRGBA; + } else { + formatGPU = gpu::Element::COLOR_COMPRESSED_SRGB; + } + formatMip = formatGPU; } else { - formatGPU = gpu::Element::COLOR_COMPRESSED_SRGB; + formatMip = gpu::Element::COLOR_SBGRA_32; + formatGPU = gpu::Element::COLOR_SRGBA_32; } - gpu::Element formatMip = formatGPU; -#else - gpu::Element formatMip = gpu::Element::COLOR_SBGRA_32; - gpu::Element formatGPU = gpu::Element::COLOR_SRGBA_32; -#endif if (isStrict) { theTexture = gpu::Texture::createStrict(formatGPU, image.width(), image.height(), gpu::Texture::MAX_NUM_MIPS, gpu::Sampler(gpu::Sampler::FILTER_MIN_MAG_MIP_LINEAR)); @@ -547,14 +609,12 @@ gpu::TexturePointer TextureUsage::process2DTextureNormalMapFromImage(const QImag gpu::TexturePointer theTexture = nullptr; if ((image.width() > 0) && (image.height() > 0)) { - -#if CPU_MIPMAPS && COMPRESS_NORMALMAP_TEXTURES - gpu::Element formatMip = gpu::Element::COLOR_COMPRESSED_XY; - gpu::Element formatGPU = gpu::Element::COLOR_COMPRESSED_XY; -#else gpu::Element formatMip = gpu::Element::VEC2NU8_XY; gpu::Element formatGPU = gpu::Element::VEC2NU8_XY; -#endif + if (isNormalTexturesCompressionEnabled()) { + formatMip = gpu::Element::COLOR_COMPRESSED_XY; + formatGPU = gpu::Element::COLOR_COMPRESSED_XY; + } theTexture = gpu::Texture::create2D(formatGPU, image.width(), image.height(), gpu::Texture::MAX_NUM_MIPS, gpu::Sampler(gpu::Sampler::FILTER_MIN_MAG_MIP_LINEAR)); theTexture->setSource(srcImageName); @@ -580,14 +640,15 @@ gpu::TexturePointer TextureUsage::process2DTextureGrayscaleFromImage(const QImag gpu::TexturePointer theTexture = nullptr; if ((image.width() > 0) && (image.height() > 0)) { - -#if CPU_MIPMAPS && COMPRESS_GRAYSCALE_TEXTURES - gpu::Element formatMip = gpu::Element::COLOR_COMPRESSED_RED; - gpu::Element formatGPU = gpu::Element::COLOR_COMPRESSED_RED; -#else - gpu::Element formatMip = gpu::Element::COLOR_R_8; - gpu::Element formatGPU = gpu::Element::COLOR_R_8; -#endif + gpu::Element formatMip; + gpu::Element formatGPU; + if (isGrayscaleTexturesCompressionEnabled()) { + formatMip = gpu::Element::COLOR_COMPRESSED_RED; + formatGPU = gpu::Element::COLOR_COMPRESSED_RED; + } else { + formatMip = gpu::Element::COLOR_R_8; + formatGPU = gpu::Element::COLOR_R_8; + } theTexture = gpu::Texture::create2D(formatGPU, image.width(), image.height(), gpu::Texture::MAX_NUM_MIPS, gpu::Sampler(gpu::Sampler::FILTER_MIN_MAG_MIP_LINEAR)); theTexture->setSource(srcImageName); @@ -864,13 +925,15 @@ gpu::TexturePointer TextureUsage::processCubeTextureColorFromImage(const QImage& image = image.convertToFormat(QImage::Format_ARGB32); } -#if CPU_MIPMAPS && COMPRESS_CUBEMAP_TEXTURES - gpu::Element formatMip = gpu::Element::COLOR_COMPRESSED_SRGBA; - gpu::Element formatGPU = gpu::Element::COLOR_COMPRESSED_SRGBA; -#else - gpu::Element formatMip = gpu::Element::COLOR_SRGBA_32; - gpu::Element formatGPU = gpu::Element::COLOR_SRGBA_32; -#endif + gpu::Element formatMip; + gpu::Element formatGPU; + if (isCubeTexturesCompressionEnabled()) { + formatMip = gpu::Element::COLOR_COMPRESSED_SRGBA; + formatGPU = gpu::Element::COLOR_COMPRESSED_SRGBA; + } else { + formatMip = gpu::Element::COLOR_SRGBA_32; + formatGPU = gpu::Element::COLOR_SRGBA_32; + } // Find the layout of the cubemap in the 2D image // Use the original image size since processSourceImage may have altered the size / aspect ratio diff --git a/libraries/image/src/image/Image.h b/libraries/image/src/image/Image.h index 3e5aa868d2..d9dd1105cd 100644 --- a/libraries/image/src/image/Image.h +++ b/libraries/image/src/image/Image.h @@ -63,6 +63,16 @@ gpu::TexturePointer processCubeTextureColorFromImage(const QImage& srcImage, con } // namespace TextureUsage +bool isColorTexturesCompressionEnabled(); +bool isNormalTexturesCompressionEnabled(); +bool isGrayscaleTexturesCompressionEnabled(); +bool isCubeTexturesCompressionEnabled(); + +void setColorTexturesCompressionEnabled(bool enabled); +void setNormalTexturesCompressionEnabled(bool enabled); +void setGrayscaleTexturesCompressionEnabled(bool enabled); +void setCubeTexturesCompressionEnabled(bool enabled); + gpu::TexturePointer processImage(const QByteArray& content, const std::string& url, int maxNumPixels, TextureUsage::Type textureType); } // namespace image