From 23806ed67d73bf870b0a98a336581679bd94e165 Mon Sep 17 00:00:00 2001 From: sabrina-shanman Date: Fri, 8 Feb 2019 14:33:55 -0800 Subject: [PATCH 01/10] Add support for GLTF roughness/metallic --- libraries/fbx/src/GLTFSerializer.cpp | 2 + libraries/hfm/src/hfm/HFM.h | 2 + libraries/image/src/image/Image.cpp | 46 ++++++++++++++++++- libraries/image/src/image/Image.h | 3 +- .../src/model-networking/ModelCache.cpp | 2 +- .../src/model-networking/TextureCache.cpp | 36 ++++++++++----- .../src/model-networking/TextureCache.h | 6 ++- .../shared/src/shared/ColorChannelMapping.h | 37 +++++++++++++++ 8 files changed, 118 insertions(+), 16 deletions(-) create mode 100644 libraries/shared/src/shared/ColorChannelMapping.h diff --git a/libraries/fbx/src/GLTFSerializer.cpp b/libraries/fbx/src/GLTFSerializer.cpp index 96c236f703..f7493ad88b 100644 --- a/libraries/fbx/src/GLTFSerializer.cpp +++ b/libraries/fbx/src/GLTFSerializer.cpp @@ -1057,8 +1057,10 @@ void GLTFSerializer::setHFMMaterial(HFMMaterial& fbxmat, const GLTFMaterial& mat } if (material.pbrMetallicRoughness.defined["metallicRoughnessTexture"]) { fbxmat.roughnessTexture = getHFMTexture(_file.textures[material.pbrMetallicRoughness.metallicRoughnessTexture]); + fbxmat.roughnessTexture.channelMapping = ColorChannelMapping::GREEN; fbxmat.useRoughnessMap = true; fbxmat.metallicTexture = getHFMTexture(_file.textures[material.pbrMetallicRoughness.metallicRoughnessTexture]); + fbxmat.metallicTexture.channelMapping = ColorChannelMapping::BLUE; fbxmat.useMetallicMap = true; } if (material.pbrMetallicRoughness.defined["roughnessFactor"]) { diff --git a/libraries/hfm/src/hfm/HFM.h b/libraries/hfm/src/hfm/HFM.h index 1bd87332a1..f733e4ef69 100644 --- a/libraries/hfm/src/hfm/HFM.h +++ b/libraries/hfm/src/hfm/HFM.h @@ -24,6 +24,7 @@ #include #include +#include #if defined(Q_OS_ANDROID) #define HFM_PACK_NORMALS 0 @@ -125,6 +126,7 @@ public: QString name; QByteArray filename; QByteArray content; + ColorChannelMapping channelMapping { ColorChannelMapping::NONE }; Transform transform; int maxNumPixels { MAX_NUM_PIXELS_FOR_FBX_TEXTURE }; diff --git a/libraries/image/src/image/Image.cpp b/libraries/image/src/image/Image.cpp index ac2813667f..0f7acabf85 100644 --- a/libraries/image/src/image/Image.cpp +++ b/libraries/image/src/image/Image.cpp @@ -16,6 +16,7 @@ #include #include #include +#include #include #include @@ -221,7 +222,45 @@ QImage processRawImageData(QIODevice& content, const std::string& filename) { return QImage(); } -gpu::TexturePointer processImage(std::shared_ptr content, const std::string& filename, +void mapToRedChannel(QImage& image, ColorChannelMapping sourceChannel) { + // Change format of image so we know exactly how to process it + if (image.format() != QImage::Format_ARGB32) { + image = image.convertToFormat(QImage::Format_ARGB32); + } + + for (int i = 0; i < image.height(); i++) { + QRgb* pixel = reinterpret_cast(image.scanLine(i)); + // Past end pointer + QRgb* lineEnd = pixel + image.width(); + + // Transfer channel data from source to target + for (; pixel < lineEnd; pixel++) { + int colorValue; + switch (sourceChannel) { + case ColorChannelMapping::RED: + colorValue = qRed(*pixel); + break; + case ColorChannelMapping::GREEN: + colorValue = qGreen(*pixel); + break; + case ColorChannelMapping::BLUE: + colorValue = qBlue(*pixel); + break; + case ColorChannelMapping::ALPHA: + colorValue = qAlpha(*pixel); + break; + default: + colorValue = qRed(*pixel); + break; + } + + // Dump the color in the red channel, ignore the rest + *pixel = qRgba(colorValue, 0, 0, 0); + } + } +} + +gpu::TexturePointer processImage(std::shared_ptr content, const std::string& filename, ColorChannelMapping channelMapping, int maxNumPixels, TextureUsage::Type textureType, bool compress, BackendTarget target, const std::atomic& abortProcessing) { @@ -252,6 +291,11 @@ gpu::TexturePointer processImage(std::shared_ptr content, const std:: QSize(originalWidth, originalHeight) << " to " << QSize(imageWidth, imageHeight) << ")"; } + + // Re-map to image with single red channel texture if requested + if (channelMapping != ColorChannelMapping::NONE) { + mapToRedChannel(image, channelMapping); + } auto loader = TextureUsage::getTextureLoaderForType(textureType); auto texture = loader(std::move(image), filename, compress, target, abortProcessing); diff --git a/libraries/image/src/image/Image.h b/libraries/image/src/image/Image.h index ae72a183b3..cc68ef6718 100644 --- a/libraries/image/src/image/Image.h +++ b/libraries/image/src/image/Image.h @@ -15,6 +15,7 @@ #include #include +#include class QByteArray; class QImage; @@ -81,7 +82,7 @@ gpu::TexturePointer processCubeTextureColorFromImage(QImage&& srcImage, const st const QStringList getSupportedFormats(); -gpu::TexturePointer processImage(std::shared_ptr content, const std::string& url, +gpu::TexturePointer processImage(std::shared_ptr content, const std::string& url, ColorChannelMapping channelMapping, int maxNumPixels, TextureUsage::Type textureType, bool compress, gpu::BackendTarget target, const std::atomic& abortProcessing = false); diff --git a/libraries/model-networking/src/model-networking/ModelCache.cpp b/libraries/model-networking/src/model-networking/ModelCache.cpp index 1535f5cfad..0da683789e 100644 --- a/libraries/model-networking/src/model-networking/ModelCache.cpp +++ b/libraries/model-networking/src/model-networking/ModelCache.cpp @@ -599,7 +599,7 @@ graphics::TextureMapPointer NetworkMaterial::fetchTextureMap(const QUrl& baseUrl } const auto url = getTextureUrl(baseUrl, hfmTexture); - const auto texture = DependencyManager::get()->getTexture(url, type, hfmTexture.content, hfmTexture.maxNumPixels); + const auto texture = DependencyManager::get()->getTexture(url, type, hfmTexture.content, hfmTexture.maxNumPixels, hfmTexture.channelMapping); _textures[channel] = Texture { hfmTexture.name, texture }; auto map = std::make_shared(); diff --git a/libraries/model-networking/src/model-networking/TextureCache.cpp b/libraries/model-networking/src/model-networking/TextureCache.cpp index 910de258f9..fe68c4ca6e 100644 --- a/libraries/model-networking/src/model-networking/TextureCache.cpp +++ b/libraries/model-networking/src/model-networking/TextureCache.cpp @@ -192,6 +192,7 @@ public: image::TextureUsage::Type type; const QByteArray& content; int maxNumPixels; + ColorChannelMapping channelMapping; }; namespace std { @@ -206,19 +207,19 @@ namespace std { struct hash { size_t operator()(const TextureExtra& a) const { size_t result = 0; - hash_combine(result, (int)a.type, a.content, a.maxNumPixels); + hash_combine(result, (int)a.type, a.content, a.maxNumPixels, a.channelMapping); return result; } }; } -ScriptableResource* TextureCache::prefetch(const QUrl& url, int type, int maxNumPixels) { +ScriptableResource* TextureCache::prefetch(const QUrl& url, int type, int maxNumPixels, ColorChannelMapping channelMapping) { auto byteArray = QByteArray(); - TextureExtra extra = { (image::TextureUsage::Type)type, byteArray, maxNumPixels }; + TextureExtra extra = { (image::TextureUsage::Type)type, byteArray, maxNumPixels, channelMapping }; return ResourceCache::prefetch(url, &extra, std::hash()(extra)); } -NetworkTexturePointer TextureCache::getTexture(const QUrl& url, image::TextureUsage::Type type, const QByteArray& content, int maxNumPixels) { +NetworkTexturePointer TextureCache::getTexture(const QUrl& url, image::TextureUsage::Type type, const QByteArray& content, int maxNumPixels, ColorChannelMapping channelMapping) { if (url.scheme() == RESOURCE_SCHEME) { return getResourceTexture(url); } @@ -228,7 +229,7 @@ NetworkTexturePointer TextureCache::getTexture(const QUrl& url, image::TextureUs query.addQueryItem("skybox", ""); modifiedUrl.setQuery(query.toString()); } - TextureExtra extra = { type, content, maxNumPixels }; + TextureExtra extra = { type, content, maxNumPixels, channelMapping }; return ResourceCache::getResource(modifiedUrl, QUrl(), &extra, std::hash()(extra)).staticCast(); } @@ -346,6 +347,7 @@ NetworkTexture::NetworkTexture(const QUrl& url) : NetworkTexture::NetworkTexture(const NetworkTexture& other) : Resource(other), _type(other._type), + _channelMapping(other._channelMapping), _currentlyLoadingResourceType(other._currentlyLoadingResourceType), _originalWidth(other._originalWidth), _originalHeight(other._originalHeight), @@ -353,6 +355,11 @@ NetworkTexture::NetworkTexture(const NetworkTexture& other) : _height(other._height), _maxNumPixels(other._maxNumPixels) { + if (_width == 0 || _height == 0 || + other._currentlyLoadingResourceType == ResourceType::META || + (other._currentlyLoadingResourceType == ResourceType::KTX && other._ktxResourceState != KTXResourceState::WAITING_FOR_MIP_REQUEST)) { + _startedLoading = false; + } } static bool isLocalUrl(const QUrl& url) { @@ -364,6 +371,7 @@ void NetworkTexture::setExtra(void* extra) { const TextureExtra* textureExtra = static_cast(extra); _type = textureExtra ? textureExtra->type : image::TextureUsage::DEFAULT_TEXTURE; _maxNumPixels = textureExtra ? textureExtra->maxNumPixels : ABSOLUTE_MAX_TEXTURE_NUM_PIXELS; + _channelMapping = textureExtra ? textureExtra->channelMapping : ColorChannelMapping::NONE; _textureSource = std::make_shared(_url, (int)_type); _lowestRequestedMipLevel = 0; @@ -425,7 +433,8 @@ gpu::TexturePointer NetworkTexture::getFallbackTexture() const { class ImageReader : public QRunnable { public: ImageReader(const QWeakPointer& resource, const QUrl& url, - const QByteArray& data, int maxNumPixels); + const QByteArray& data, size_t extraHash, int maxNumPixels, + ColorChannelMapping channelMapping); void run() override final; void read(); @@ -435,7 +444,9 @@ private: QWeakPointer _resource; QUrl _url; QByteArray _content; + size_t _extraHash; int _maxNumPixels; + ColorChannelMapping _channelMapping; }; NetworkTexture::~NetworkTexture() { @@ -1068,7 +1079,7 @@ void NetworkTexture::loadTextureContent(const QByteArray& content) { return; } - QThreadPool::globalInstance()->start(new ImageReader(_self, _url, content, _maxNumPixels)); + QThreadPool::globalInstance()->start(new ImageReader(_self, _url, content, _extraHash, _maxNumPixels, _channelMapping)); } void NetworkTexture::refresh() { @@ -1093,11 +1104,13 @@ void NetworkTexture::refresh() { Resource::refresh(); } -ImageReader::ImageReader(const QWeakPointer& resource, const QUrl& url, const QByteArray& data, int maxNumPixels) : +ImageReader::ImageReader(const QWeakPointer& resource, const QUrl& url, const QByteArray& data, size_t extraHash, int maxNumPixels, const ColorChannelMapping channelMapping) : _resource(resource), _url(url), _content(data), - _maxNumPixels(maxNumPixels) + _extraHash(extraHash), + _maxNumPixels(maxNumPixels), + _channelMapping(channelMapping) { DependencyManager::get()->incrementStat("PendingProcessing"); listSupportedImageFormats(); @@ -1152,11 +1165,12 @@ void ImageReader::read() { } auto networkTexture = resource.staticCast(); - // Hash the source image to for KTX caching + // Hash the source image and extra to for KTX caching std::string hash; { QCryptographicHash hasher(QCryptographicHash::Md5); hasher.addData(_content); + hasher.addData(std::to_string(_extraHash).c_str()); hash = hasher.result().toHex().toStdString(); } @@ -1204,7 +1218,7 @@ void ImageReader::read() { constexpr bool shouldCompress = false; #endif auto target = getBackendTarget(); - texture = image::processImage(std::move(buffer), _url.toString().toStdString(), _maxNumPixels, networkTexture->getTextureType(), shouldCompress, target); + texture = image::processImage(std::move(buffer), _url.toString().toStdString(), _channelMapping, _maxNumPixels, networkTexture->getTextureType(), shouldCompress, target); if (!texture) { QMetaObject::invokeMethod(resource.data(), "setImage", diff --git a/libraries/model-networking/src/model-networking/TextureCache.h b/libraries/model-networking/src/model-networking/TextureCache.h index d744d060b6..44f7a0034c 100644 --- a/libraries/model-networking/src/model-networking/TextureCache.h +++ b/libraries/model-networking/src/model-networking/TextureCache.h @@ -96,6 +96,7 @@ private: friend class ImageReader; image::TextureUsage::Type _type; + ColorChannelMapping _channelMapping; enum class ResourceType { META, @@ -178,7 +179,8 @@ public: /// Loads a texture from the specified URL. NetworkTexturePointer getTexture(const QUrl& url, image::TextureUsage::Type type = image::TextureUsage::DEFAULT_TEXTURE, - const QByteArray& content = QByteArray(), int maxNumPixels = ABSOLUTE_MAX_TEXTURE_NUM_PIXELS); + const QByteArray& content = QByteArray(), int maxNumPixels = ABSOLUTE_MAX_TEXTURE_NUM_PIXELS, + ColorChannelMapping channelMapping = ColorChannelMapping::NONE); gpu::TexturePointer getTextureByHash(const std::string& hash); gpu::TexturePointer cacheTextureByHash(const std::string& hash, const gpu::TexturePointer& texture); @@ -201,7 +203,7 @@ signals: protected: // Overload ResourceCache::prefetch to allow specifying texture type for loads - Q_INVOKABLE ScriptableResource* prefetch(const QUrl& url, int type, int maxNumPixels = ABSOLUTE_MAX_TEXTURE_NUM_PIXELS); + Q_INVOKABLE ScriptableResource* prefetch(const QUrl& url, int type, int maxNumPixels = ABSOLUTE_MAX_TEXTURE_NUM_PIXELS, ColorChannelMapping channelMapping = ColorChannelMapping::NONE); virtual QSharedPointer createResource(const QUrl& url) override; QSharedPointer createResourceCopy(const QSharedPointer& resource) override; diff --git a/libraries/shared/src/shared/ColorChannelMapping.h b/libraries/shared/src/shared/ColorChannelMapping.h new file mode 100644 index 0000000000..c400ec1414 --- /dev/null +++ b/libraries/shared/src/shared/ColorChannelMapping.h @@ -0,0 +1,37 @@ +// +// ColorChannelMapping.h +// libraries/shared/src +// +// Created by Sabrina Shanman on 2019/02/05. +// Copyright 2019 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +#ifndef hifi_ColorChannelMapping_h +#define hifi_ColorChannelMapping_h + +#include "../RegisteredMetaTypes.h" + +enum class ColorChannelMapping { + NONE, + RED, + GREEN, + BLUE, + ALPHA, + COUNT +}; + +namespace std { + template <> + struct hash { + size_t operator()(const ColorChannelMapping& a) const { + size_t result = 0; + hash_combine(result, (int)a); + return result; + } + }; +}; + +#endif // hifi_ColorChannelMapping_h From 0f291612c3b92dcce2d0d323234e896824fbd448 Mon Sep 17 00:00:00 2001 From: sabrina-shanman Date: Mon, 11 Feb 2019 09:04:41 -0800 Subject: [PATCH 02/10] Fix invalid processImage calls in TextureBaker.cpp --- libraries/baking/src/TextureBaker.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libraries/baking/src/TextureBaker.cpp b/libraries/baking/src/TextureBaker.cpp index 2516323c37..b9e476b714 100644 --- a/libraries/baking/src/TextureBaker.cpp +++ b/libraries/baking/src/TextureBaker.cpp @@ -154,7 +154,7 @@ void TextureBaker::processTexture() { gpu::BackendTarget::GLES32 }}; for (auto target : BACKEND_TARGETS) { - auto processedTexture = image::processImage(buffer, _textureURL.toString().toStdString(), + auto processedTexture = image::processImage(buffer, _textureURL.toString().toStdString(), ColorChannelMapping::NONE, ABSOLUTE_MAX_TEXTURE_NUM_PIXELS, _textureType, true, target, _abortProcessing); if (!processedTexture) { @@ -197,7 +197,7 @@ void TextureBaker::processTexture() { // Uncompressed KTX if (_textureType == image::TextureUsage::Type::CUBE_TEXTURE) { buffer->reset(); - auto processedTexture = image::processImage(std::move(buffer), _textureURL.toString().toStdString(), + auto processedTexture = image::processImage(std::move(buffer), _textureURL.toString().toStdString(), ColorChannelMapping::NONE, ABSOLUTE_MAX_TEXTURE_NUM_PIXELS, _textureType, false, gpu::BackendTarget::GL45, _abortProcessing); if (!processedTexture) { handleError("Could not process texture " + _textureURL.toString()); From f7d7136b3ea9dc98e8b715072210d1ab47d7e263 Mon Sep 17 00:00:00 2001 From: sabrina-shanman Date: Mon, 11 Feb 2019 09:06:26 -0800 Subject: [PATCH 03/10] Do not have hash specialization just for ColorChannelMapping --- .../src/model-networking/TextureCache.cpp | 2 +- libraries/shared/src/shared/ColorChannelMapping.h | 11 ----------- 2 files changed, 1 insertion(+), 12 deletions(-) diff --git a/libraries/model-networking/src/model-networking/TextureCache.cpp b/libraries/model-networking/src/model-networking/TextureCache.cpp index fe68c4ca6e..36893b4280 100644 --- a/libraries/model-networking/src/model-networking/TextureCache.cpp +++ b/libraries/model-networking/src/model-networking/TextureCache.cpp @@ -207,7 +207,7 @@ namespace std { struct hash { size_t operator()(const TextureExtra& a) const { size_t result = 0; - hash_combine(result, (int)a.type, a.content, a.maxNumPixels, a.channelMapping); + hash_combine(result, (int)a.type, a.content, a.maxNumPixels, (int)a.channelMapping); return result; } }; diff --git a/libraries/shared/src/shared/ColorChannelMapping.h b/libraries/shared/src/shared/ColorChannelMapping.h index c400ec1414..0f70b9d9f7 100644 --- a/libraries/shared/src/shared/ColorChannelMapping.h +++ b/libraries/shared/src/shared/ColorChannelMapping.h @@ -23,15 +23,4 @@ enum class ColorChannelMapping { COUNT }; -namespace std { - template <> - struct hash { - size_t operator()(const ColorChannelMapping& a) const { - size_t result = 0; - hash_combine(result, (int)a); - return result; - } - }; -}; - #endif // hifi_ColorChannelMapping_h From 5840f272ede0b261f997d29a8bb18687e4aa2887 Mon Sep 17 00:00:00 2001 From: sabrina-shanman Date: Mon, 11 Feb 2019 09:07:45 -0800 Subject: [PATCH 04/10] Store mapped single channel texture with alpha of 255 just to be safe --- libraries/image/src/image/Image.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/image/src/image/Image.cpp b/libraries/image/src/image/Image.cpp index 0f7acabf85..bce322c9ee 100644 --- a/libraries/image/src/image/Image.cpp +++ b/libraries/image/src/image/Image.cpp @@ -255,7 +255,7 @@ void mapToRedChannel(QImage& image, ColorChannelMapping sourceChannel) { } // Dump the color in the red channel, ignore the rest - *pixel = qRgba(colorValue, 0, 0, 0); + *pixel = qRgba(colorValue, 0, 0, 255); } } } From 2b355e9d52a7c129e642ed64334c80813d125838 Mon Sep 17 00:00:00 2001 From: sabrina-shanman Date: Tue, 12 Feb 2019 11:56:44 -0800 Subject: [PATCH 05/10] Re-name ColorChannelMapping to ColorChannel and put versions in two specific libraries rather than shared --- libraries/fbx/src/GLTFSerializer.cpp | 4 +-- libraries/hfm/src/hfm/ColorChannel.h | 26 +++++++++++++++++ libraries/hfm/src/hfm/HFM.h | 5 ++-- libraries/image/src/image/Image.cpp | 16 +++++------ libraries/image/src/image/Image.h | 12 ++++++-- .../src/model-networking/ModelCache.cpp | 2 +- .../src/model-networking/TextureCache.cpp | 28 +++++++++---------- .../src/model-networking/TextureCache.h | 7 +++-- libraries/procedural/CMakeLists.txt | 1 + .../shared/src/shared/ColorChannelMapping.h | 26 ----------------- 10 files changed, 69 insertions(+), 58 deletions(-) create mode 100644 libraries/hfm/src/hfm/ColorChannel.h delete mode 100644 libraries/shared/src/shared/ColorChannelMapping.h diff --git a/libraries/fbx/src/GLTFSerializer.cpp b/libraries/fbx/src/GLTFSerializer.cpp index 428dc3a77d..eb29ef3fad 100755 --- a/libraries/fbx/src/GLTFSerializer.cpp +++ b/libraries/fbx/src/GLTFSerializer.cpp @@ -1146,10 +1146,10 @@ void GLTFSerializer::setHFMMaterial(HFMMaterial& fbxmat, const GLTFMaterial& mat } if (material.pbrMetallicRoughness.defined["metallicRoughnessTexture"]) { fbxmat.roughnessTexture = getHFMTexture(_file.textures[material.pbrMetallicRoughness.metallicRoughnessTexture]); - fbxmat.roughnessTexture.channelMapping = ColorChannelMapping::GREEN; + fbxmat.roughnessTexture.sourceChannel = hfm::ColorChannel::GREEN; fbxmat.useRoughnessMap = true; fbxmat.metallicTexture = getHFMTexture(_file.textures[material.pbrMetallicRoughness.metallicRoughnessTexture]); - fbxmat.metallicTexture.channelMapping = ColorChannelMapping::BLUE; + fbxmat.metallicTexture.sourceChannel = hfm::ColorChannel::BLUE; fbxmat.useMetallicMap = true; } if (material.pbrMetallicRoughness.defined["roughnessFactor"]) { diff --git a/libraries/hfm/src/hfm/ColorChannel.h b/libraries/hfm/src/hfm/ColorChannel.h new file mode 100644 index 0000000000..a5db0354da --- /dev/null +++ b/libraries/hfm/src/hfm/ColorChannel.h @@ -0,0 +1,26 @@ +// +// ColorChannel.h +// libraries/hfm/src +// +// Created by Sabrina Shanman on 2019/02/12. +// Copyright 2019 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +#ifndef hifi_hfm_ColorChannel_h +#define hifi_hfm_ColorChannel_h + +namespace hfm { + enum class ColorChannel { + NONE, + RED, + GREEN, + BLUE, + ALPHA, + COUNT + }; +}; + +#endif // hifi_hfm_ColorChannel_h diff --git a/libraries/hfm/src/hfm/HFM.h b/libraries/hfm/src/hfm/HFM.h index d238ff7de0..68b091c8d8 100644 --- a/libraries/hfm/src/hfm/HFM.h +++ b/libraries/hfm/src/hfm/HFM.h @@ -24,7 +24,8 @@ #include #include -#include + +#include "ColorChannel.h" #if defined(Q_OS_ANDROID) #define HFM_PACK_NORMALS 0 @@ -124,7 +125,7 @@ public: QString name; QByteArray filename; QByteArray content; - ColorChannelMapping channelMapping { ColorChannelMapping::NONE }; + ColorChannel sourceChannel { ColorChannel::NONE }; Transform transform; int maxNumPixels { MAX_NUM_PIXELS_FOR_FBX_TEXTURE }; diff --git a/libraries/image/src/image/Image.cpp b/libraries/image/src/image/Image.cpp index bce322c9ee..e2ee8c68f8 100644 --- a/libraries/image/src/image/Image.cpp +++ b/libraries/image/src/image/Image.cpp @@ -222,7 +222,7 @@ QImage processRawImageData(QIODevice& content, const std::string& filename) { return QImage(); } -void mapToRedChannel(QImage& image, ColorChannelMapping sourceChannel) { +void mapToRedChannel(QImage& image, TextureUsage::ColorChannel sourceChannel) { // Change format of image so we know exactly how to process it if (image.format() != QImage::Format_ARGB32) { image = image.convertToFormat(QImage::Format_ARGB32); @@ -237,16 +237,16 @@ void mapToRedChannel(QImage& image, ColorChannelMapping sourceChannel) { for (; pixel < lineEnd; pixel++) { int colorValue; switch (sourceChannel) { - case ColorChannelMapping::RED: + case TextureUsage::ColorChannel::RED: colorValue = qRed(*pixel); break; - case ColorChannelMapping::GREEN: + case TextureUsage::ColorChannel::GREEN: colorValue = qGreen(*pixel); break; - case ColorChannelMapping::BLUE: + case TextureUsage::ColorChannel::BLUE: colorValue = qBlue(*pixel); break; - case ColorChannelMapping::ALPHA: + case TextureUsage::ColorChannel::ALPHA: colorValue = qAlpha(*pixel); break; default: @@ -260,7 +260,7 @@ void mapToRedChannel(QImage& image, ColorChannelMapping sourceChannel) { } } -gpu::TexturePointer processImage(std::shared_ptr content, const std::string& filename, ColorChannelMapping channelMapping, +gpu::TexturePointer processImage(std::shared_ptr content, const std::string& filename, TextureUsage::ColorChannel sourceChannel, int maxNumPixels, TextureUsage::Type textureType, bool compress, BackendTarget target, const std::atomic& abortProcessing) { @@ -293,8 +293,8 @@ gpu::TexturePointer processImage(std::shared_ptr content, const std:: } // Re-map to image with single red channel texture if requested - if (channelMapping != ColorChannelMapping::NONE) { - mapToRedChannel(image, channelMapping); + if (sourceChannel != TextureUsage::ColorChannel::NONE) { + mapToRedChannel(image, sourceChannel); } auto loader = TextureUsage::getTextureLoaderForType(textureType); diff --git a/libraries/image/src/image/Image.h b/libraries/image/src/image/Image.h index cc68ef6718..5497d72fe9 100644 --- a/libraries/image/src/image/Image.h +++ b/libraries/image/src/image/Image.h @@ -15,7 +15,6 @@ #include #include -#include class QByteArray; class QImage; @@ -42,6 +41,15 @@ enum Type { UNUSED_TEXTURE }; +enum class ColorChannel { + NONE, + RED, + GREEN, + BLUE, + ALPHA, + COUNT +}; + using TextureLoader = std::function&)>; TextureLoader getTextureLoaderForType(Type type, const QVariantMap& options = QVariantMap()); @@ -82,7 +90,7 @@ gpu::TexturePointer processCubeTextureColorFromImage(QImage&& srcImage, const st const QStringList getSupportedFormats(); -gpu::TexturePointer processImage(std::shared_ptr content, const std::string& url, ColorChannelMapping channelMapping, +gpu::TexturePointer processImage(std::shared_ptr content, const std::string& url, TextureUsage::ColorChannel sourceChannel, int maxNumPixels, TextureUsage::Type textureType, bool compress, gpu::BackendTarget target, const std::atomic& abortProcessing = false); diff --git a/libraries/model-networking/src/model-networking/ModelCache.cpp b/libraries/model-networking/src/model-networking/ModelCache.cpp index 021c70ccf2..a4fae67958 100644 --- a/libraries/model-networking/src/model-networking/ModelCache.cpp +++ b/libraries/model-networking/src/model-networking/ModelCache.cpp @@ -599,7 +599,7 @@ graphics::TextureMapPointer NetworkMaterial::fetchTextureMap(const QUrl& baseUrl } const auto url = getTextureUrl(baseUrl, hfmTexture); - const auto texture = DependencyManager::get()->getTexture(url, type, hfmTexture.content, hfmTexture.maxNumPixels, hfmTexture.channelMapping); + const auto texture = DependencyManager::get()->getTexture(url, type, hfmTexture.content, hfmTexture.maxNumPixels, hfmTexture.sourceChannel); _textures[channel] = Texture { hfmTexture.name, texture }; auto map = std::make_shared(); diff --git a/libraries/model-networking/src/model-networking/TextureCache.cpp b/libraries/model-networking/src/model-networking/TextureCache.cpp index c28db444c0..54f991a179 100644 --- a/libraries/model-networking/src/model-networking/TextureCache.cpp +++ b/libraries/model-networking/src/model-networking/TextureCache.cpp @@ -192,7 +192,7 @@ public: image::TextureUsage::Type type; const QByteArray& content; int maxNumPixels; - ColorChannelMapping channelMapping; + hfm::ColorChannel sourceChannel; }; namespace std { @@ -207,19 +207,19 @@ namespace std { struct hash { size_t operator()(const TextureExtra& a) const { size_t result = 0; - hash_combine(result, (int)a.type, a.content, a.maxNumPixels, (int)a.channelMapping); + hash_combine(result, (int)a.type, a.content, a.maxNumPixels, (int)a.sourceChannel); return result; } }; } -ScriptableResource* TextureCache::prefetch(const QUrl& url, int type, int maxNumPixels, ColorChannelMapping channelMapping) { +ScriptableResource* TextureCache::prefetch(const QUrl& url, int type, int maxNumPixels, hfm::ColorChannel sourceChannel) { auto byteArray = QByteArray(); - TextureExtra extra = { (image::TextureUsage::Type)type, byteArray, maxNumPixels, channelMapping }; + TextureExtra extra = { (image::TextureUsage::Type)type, byteArray, maxNumPixels, sourceChannel }; return ResourceCache::prefetch(url, &extra, std::hash()(extra)); } -NetworkTexturePointer TextureCache::getTexture(const QUrl& url, image::TextureUsage::Type type, const QByteArray& content, int maxNumPixels, ColorChannelMapping channelMapping) { +NetworkTexturePointer TextureCache::getTexture(const QUrl& url, image::TextureUsage::Type type, const QByteArray& content, int maxNumPixels, hfm::ColorChannel sourceChannel) { if (url.scheme() == RESOURCE_SCHEME) { return getResourceTexture(url); } @@ -229,7 +229,7 @@ NetworkTexturePointer TextureCache::getTexture(const QUrl& url, image::TextureUs query.addQueryItem("skybox", ""); modifiedUrl.setQuery(query.toString()); } - TextureExtra extra = { type, content, maxNumPixels, channelMapping }; + TextureExtra extra = { type, content, maxNumPixels, sourceChannel }; return ResourceCache::getResource(modifiedUrl, QUrl(), &extra, std::hash()(extra)).staticCast(); } @@ -347,7 +347,7 @@ NetworkTexture::NetworkTexture(const QUrl& url, bool resourceTexture) : NetworkTexture::NetworkTexture(const NetworkTexture& other) : Resource(other), _type(other._type), - _channelMapping(other._channelMapping), + _sourceChannel(other._sourceChannel), _currentlyLoadingResourceType(other._currentlyLoadingResourceType), _originalWidth(other._originalWidth), _originalHeight(other._originalHeight), @@ -371,7 +371,7 @@ void NetworkTexture::setExtra(void* extra) { const TextureExtra* textureExtra = static_cast(extra); _type = textureExtra ? textureExtra->type : image::TextureUsage::DEFAULT_TEXTURE; _maxNumPixels = textureExtra ? textureExtra->maxNumPixels : ABSOLUTE_MAX_TEXTURE_NUM_PIXELS; - _channelMapping = textureExtra ? textureExtra->channelMapping : ColorChannelMapping::NONE; + _sourceChannel = textureExtra ? textureExtra->sourceChannel : hfm::ColorChannel::NONE; _textureSource = std::make_shared(_url, (int)_type); _lowestRequestedMipLevel = 0; @@ -434,7 +434,7 @@ class ImageReader : public QRunnable { public: ImageReader(const QWeakPointer& resource, const QUrl& url, const QByteArray& data, size_t extraHash, int maxNumPixels, - ColorChannelMapping channelMapping); + hfm::ColorChannel sourceChannel); void run() override final; void read(); @@ -446,7 +446,7 @@ private: QByteArray _content; size_t _extraHash; int _maxNumPixels; - ColorChannelMapping _channelMapping; + hfm::ColorChannel _sourceChannel; }; NetworkTexture::~NetworkTexture() { @@ -1079,7 +1079,7 @@ void NetworkTexture::loadTextureContent(const QByteArray& content) { return; } - QThreadPool::globalInstance()->start(new ImageReader(_self, _url, content, _extraHash, _maxNumPixels, _channelMapping)); + QThreadPool::globalInstance()->start(new ImageReader(_self, _url, content, _extraHash, _maxNumPixels, _sourceChannel)); } void NetworkTexture::refresh() { @@ -1104,13 +1104,13 @@ void NetworkTexture::refresh() { Resource::refresh(); } -ImageReader::ImageReader(const QWeakPointer& resource, const QUrl& url, const QByteArray& data, size_t extraHash, int maxNumPixels, const ColorChannelMapping channelMapping) : +ImageReader::ImageReader(const QWeakPointer& resource, const QUrl& url, const QByteArray& data, size_t extraHash, int maxNumPixels, hfm::ColorChannel sourceChannel) : _resource(resource), _url(url), _content(data), _extraHash(extraHash), _maxNumPixels(maxNumPixels), - _channelMapping(channelMapping) + _sourceChannel(sourceChannel) { DependencyManager::get()->incrementStat("PendingProcessing"); listSupportedImageFormats(); @@ -1218,7 +1218,7 @@ void ImageReader::read() { constexpr bool shouldCompress = false; #endif auto target = getBackendTarget(); - texture = image::processImage(std::move(buffer), _url.toString().toStdString(), _channelMapping, _maxNumPixels, networkTexture->getTextureType(), shouldCompress, target); + texture = image::processImage(std::move(buffer), _url.toString().toStdString(), (image::TextureUsage::ColorChannel)_sourceChannel, _maxNumPixels, networkTexture->getTextureType(), shouldCompress, target); if (!texture) { QMetaObject::invokeMethod(resource.data(), "setImage", diff --git a/libraries/model-networking/src/model-networking/TextureCache.h b/libraries/model-networking/src/model-networking/TextureCache.h index 170cd0ceb7..16627012b3 100644 --- a/libraries/model-networking/src/model-networking/TextureCache.h +++ b/libraries/model-networking/src/model-networking/TextureCache.h @@ -22,6 +22,7 @@ #include #include #include +#include #include #include #include @@ -96,7 +97,7 @@ private: friend class ImageReader; image::TextureUsage::Type _type; - ColorChannelMapping _channelMapping; + hfm::ColorChannel _sourceChannel; enum class ResourceType { META, @@ -180,7 +181,7 @@ public: /// Loads a texture from the specified URL. NetworkTexturePointer getTexture(const QUrl& url, image::TextureUsage::Type type = image::TextureUsage::DEFAULT_TEXTURE, const QByteArray& content = QByteArray(), int maxNumPixels = ABSOLUTE_MAX_TEXTURE_NUM_PIXELS, - ColorChannelMapping channelMapping = ColorChannelMapping::NONE); + hfm::ColorChannel sourceChannel = hfm::ColorChannel::NONE); gpu::TexturePointer getTextureByHash(const std::string& hash); gpu::TexturePointer cacheTextureByHash(const std::string& hash, const gpu::TexturePointer& texture); @@ -203,7 +204,7 @@ signals: protected: // Overload ResourceCache::prefetch to allow specifying texture type for loads - Q_INVOKABLE ScriptableResource* prefetch(const QUrl& url, int type, int maxNumPixels = ABSOLUTE_MAX_TEXTURE_NUM_PIXELS, ColorChannelMapping channelMapping = ColorChannelMapping::NONE); + Q_INVOKABLE ScriptableResource* prefetch(const QUrl& url, int type, int maxNumPixels = ABSOLUTE_MAX_TEXTURE_NUM_PIXELS, hfm::ColorChannel sourceChannel = hfm::ColorChannel::NONE); virtual QSharedPointer createResource(const QUrl& url) override; QSharedPointer createResourceCopy(const QSharedPointer& resource) override; diff --git a/libraries/procedural/CMakeLists.txt b/libraries/procedural/CMakeLists.txt index 6d6610a323..f2562907e0 100644 --- a/libraries/procedural/CMakeLists.txt +++ b/libraries/procedural/CMakeLists.txt @@ -2,3 +2,4 @@ set(TARGET_NAME procedural) setup_hifi_library() link_hifi_libraries(shared gpu shaders networking graphics model-networking ktx image) +include_hifi_library_headers(hfm) diff --git a/libraries/shared/src/shared/ColorChannelMapping.h b/libraries/shared/src/shared/ColorChannelMapping.h deleted file mode 100644 index 0f70b9d9f7..0000000000 --- a/libraries/shared/src/shared/ColorChannelMapping.h +++ /dev/null @@ -1,26 +0,0 @@ -// -// ColorChannelMapping.h -// libraries/shared/src -// -// Created by Sabrina Shanman on 2019/02/05. -// Copyright 2019 High Fidelity, Inc. -// -// Distributed under the Apache License, Version 2.0. -// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html -// - -#ifndef hifi_ColorChannelMapping_h -#define hifi_ColorChannelMapping_h - -#include "../RegisteredMetaTypes.h" - -enum class ColorChannelMapping { - NONE, - RED, - GREEN, - BLUE, - ALPHA, - COUNT -}; - -#endif // hifi_ColorChannelMapping_h From 1b2cb94b0cd7e578b7089b0e4a55833a1a7a73e3 Mon Sep 17 00:00:00 2001 From: sabrina-shanman Date: Tue, 12 Feb 2019 13:21:21 -0800 Subject: [PATCH 06/10] Fix not changing input to processImage in TextureBaker.cpp --- libraries/baking/src/TextureBaker.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libraries/baking/src/TextureBaker.cpp b/libraries/baking/src/TextureBaker.cpp index b9e476b714..e069578bc5 100644 --- a/libraries/baking/src/TextureBaker.cpp +++ b/libraries/baking/src/TextureBaker.cpp @@ -154,7 +154,7 @@ void TextureBaker::processTexture() { gpu::BackendTarget::GLES32 }}; for (auto target : BACKEND_TARGETS) { - auto processedTexture = image::processImage(buffer, _textureURL.toString().toStdString(), ColorChannelMapping::NONE, + auto processedTexture = image::processImage(buffer, _textureURL.toString().toStdString(), image::TextureUsage::ColorChannel::NONE, ABSOLUTE_MAX_TEXTURE_NUM_PIXELS, _textureType, true, target, _abortProcessing); if (!processedTexture) { @@ -197,7 +197,7 @@ void TextureBaker::processTexture() { // Uncompressed KTX if (_textureType == image::TextureUsage::Type::CUBE_TEXTURE) { buffer->reset(); - auto processedTexture = image::processImage(std::move(buffer), _textureURL.toString().toStdString(), ColorChannelMapping::NONE, + auto processedTexture = image::processImage(std::move(buffer), _textureURL.toString().toStdString(), image::TextureUsage::ColorChannel::NONE, ABSOLUTE_MAX_TEXTURE_NUM_PIXELS, _textureType, false, gpu::BackendTarget::GL45, _abortProcessing); if (!processedTexture) { handleError("Could not process texture " + _textureURL.toString()); From b2af6d1374dcf5e19a7f376ea4c773197600c9c2 Mon Sep 17 00:00:00 2001 From: sabrina-shanman Date: Tue, 12 Feb 2019 16:14:41 -0800 Subject: [PATCH 07/10] Have only one ColorChannel enum as header in image library --- libraries/baking/src/TextureBaker.cpp | 4 ++-- libraries/fbx/src/GLTFSerializer.cpp | 5 +++-- libraries/hfm/CMakeLists.txt | 1 + libraries/hfm/src/hfm/HFM.h | 4 ++-- .../src/hfm => image/src/image}/ColorChannel.h | 10 +++++----- libraries/image/src/image/Image.cpp | 14 +++++++------- libraries/image/src/image/Image.h | 4 +++- .../src/model-networking/TextureCache.cpp | 16 ++++++++-------- .../src/model-networking/TextureCache.h | 8 ++++---- libraries/procedural/CMakeLists.txt | 2 -- 10 files changed, 35 insertions(+), 33 deletions(-) rename libraries/{hfm/src/hfm => image/src/image}/ColorChannel.h (71%) diff --git a/libraries/baking/src/TextureBaker.cpp b/libraries/baking/src/TextureBaker.cpp index e069578bc5..6407ce1846 100644 --- a/libraries/baking/src/TextureBaker.cpp +++ b/libraries/baking/src/TextureBaker.cpp @@ -154,7 +154,7 @@ void TextureBaker::processTexture() { gpu::BackendTarget::GLES32 }}; for (auto target : BACKEND_TARGETS) { - auto processedTexture = image::processImage(buffer, _textureURL.toString().toStdString(), image::TextureUsage::ColorChannel::NONE, + auto processedTexture = image::processImage(buffer, _textureURL.toString().toStdString(), image::ColorChannel::NONE, ABSOLUTE_MAX_TEXTURE_NUM_PIXELS, _textureType, true, target, _abortProcessing); if (!processedTexture) { @@ -197,7 +197,7 @@ void TextureBaker::processTexture() { // Uncompressed KTX if (_textureType == image::TextureUsage::Type::CUBE_TEXTURE) { buffer->reset(); - auto processedTexture = image::processImage(std::move(buffer), _textureURL.toString().toStdString(), image::TextureUsage::ColorChannel::NONE, + auto processedTexture = image::processImage(std::move(buffer), _textureURL.toString().toStdString(), image::ColorChannel::NONE, ABSOLUTE_MAX_TEXTURE_NUM_PIXELS, _textureType, false, gpu::BackendTarget::GL45, _abortProcessing); if (!processedTexture) { handleError("Could not process texture " + _textureURL.toString()); diff --git a/libraries/fbx/src/GLTFSerializer.cpp b/libraries/fbx/src/GLTFSerializer.cpp index eb29ef3fad..82a4361723 100755 --- a/libraries/fbx/src/GLTFSerializer.cpp +++ b/libraries/fbx/src/GLTFSerializer.cpp @@ -32,6 +32,7 @@ #include #include #include +#include #include "FBXSerializer.h" @@ -1146,10 +1147,10 @@ void GLTFSerializer::setHFMMaterial(HFMMaterial& fbxmat, const GLTFMaterial& mat } if (material.pbrMetallicRoughness.defined["metallicRoughnessTexture"]) { fbxmat.roughnessTexture = getHFMTexture(_file.textures[material.pbrMetallicRoughness.metallicRoughnessTexture]); - fbxmat.roughnessTexture.sourceChannel = hfm::ColorChannel::GREEN; + fbxmat.roughnessTexture.sourceChannel = image::ColorChannel::GREEN; fbxmat.useRoughnessMap = true; fbxmat.metallicTexture = getHFMTexture(_file.textures[material.pbrMetallicRoughness.metallicRoughnessTexture]); - fbxmat.metallicTexture.sourceChannel = hfm::ColorChannel::BLUE; + fbxmat.metallicTexture.sourceChannel = image::ColorChannel::BLUE; fbxmat.useMetallicMap = true; } if (material.pbrMetallicRoughness.defined["roughnessFactor"]) { diff --git a/libraries/hfm/CMakeLists.txt b/libraries/hfm/CMakeLists.txt index 553fd935d9..be3d866b70 100644 --- a/libraries/hfm/CMakeLists.txt +++ b/libraries/hfm/CMakeLists.txt @@ -5,3 +5,4 @@ link_hifi_libraries(shared) include_hifi_library_headers(gpu) include_hifi_library_headers(graphics) +include_hifi_library_headers(image) diff --git a/libraries/hfm/src/hfm/HFM.h b/libraries/hfm/src/hfm/HFM.h index 68b091c8d8..577ca6f413 100644 --- a/libraries/hfm/src/hfm/HFM.h +++ b/libraries/hfm/src/hfm/HFM.h @@ -25,7 +25,7 @@ #include #include -#include "ColorChannel.h" +#include #if defined(Q_OS_ANDROID) #define HFM_PACK_NORMALS 0 @@ -125,7 +125,7 @@ public: QString name; QByteArray filename; QByteArray content; - ColorChannel sourceChannel { ColorChannel::NONE }; + image::ColorChannel sourceChannel { image::ColorChannel::NONE }; Transform transform; int maxNumPixels { MAX_NUM_PIXELS_FOR_FBX_TEXTURE }; diff --git a/libraries/hfm/src/hfm/ColorChannel.h b/libraries/image/src/image/ColorChannel.h similarity index 71% rename from libraries/hfm/src/hfm/ColorChannel.h rename to libraries/image/src/image/ColorChannel.h index a5db0354da..e1d107018b 100644 --- a/libraries/hfm/src/hfm/ColorChannel.h +++ b/libraries/image/src/image/ColorChannel.h @@ -1,6 +1,6 @@ // // ColorChannel.h -// libraries/hfm/src +// libraries/image/src/image // // Created by Sabrina Shanman on 2019/02/12. // Copyright 2019 High Fidelity, Inc. @@ -9,10 +9,10 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -#ifndef hifi_hfm_ColorChannel_h -#define hifi_hfm_ColorChannel_h +#ifndef hifi_image_ColorChannel_h +#define hifi_image_ColorChannel_h -namespace hfm { +namespace image { enum class ColorChannel { NONE, RED, @@ -23,4 +23,4 @@ namespace hfm { }; }; -#endif // hifi_hfm_ColorChannel_h +#endif // hifi_image_ColorChannel_h diff --git a/libraries/image/src/image/Image.cpp b/libraries/image/src/image/Image.cpp index e2ee8c68f8..a2161caec9 100644 --- a/libraries/image/src/image/Image.cpp +++ b/libraries/image/src/image/Image.cpp @@ -222,7 +222,7 @@ QImage processRawImageData(QIODevice& content, const std::string& filename) { return QImage(); } -void mapToRedChannel(QImage& image, TextureUsage::ColorChannel sourceChannel) { +void mapToRedChannel(QImage& image, ColorChannel sourceChannel) { // Change format of image so we know exactly how to process it if (image.format() != QImage::Format_ARGB32) { image = image.convertToFormat(QImage::Format_ARGB32); @@ -237,16 +237,16 @@ void mapToRedChannel(QImage& image, TextureUsage::ColorChannel sourceChannel) { for (; pixel < lineEnd; pixel++) { int colorValue; switch (sourceChannel) { - case TextureUsage::ColorChannel::RED: + case ColorChannel::RED: colorValue = qRed(*pixel); break; - case TextureUsage::ColorChannel::GREEN: + case ColorChannel::GREEN: colorValue = qGreen(*pixel); break; - case TextureUsage::ColorChannel::BLUE: + case ColorChannel::BLUE: colorValue = qBlue(*pixel); break; - case TextureUsage::ColorChannel::ALPHA: + case ColorChannel::ALPHA: colorValue = qAlpha(*pixel); break; default: @@ -260,7 +260,7 @@ void mapToRedChannel(QImage& image, TextureUsage::ColorChannel sourceChannel) { } } -gpu::TexturePointer processImage(std::shared_ptr content, const std::string& filename, TextureUsage::ColorChannel sourceChannel, +gpu::TexturePointer processImage(std::shared_ptr content, const std::string& filename, ColorChannel sourceChannel, int maxNumPixels, TextureUsage::Type textureType, bool compress, BackendTarget target, const std::atomic& abortProcessing) { @@ -293,7 +293,7 @@ gpu::TexturePointer processImage(std::shared_ptr content, const std:: } // Re-map to image with single red channel texture if requested - if (sourceChannel != TextureUsage::ColorChannel::NONE) { + if (sourceChannel != ColorChannel::NONE) { mapToRedChannel(image, sourceChannel); } diff --git a/libraries/image/src/image/Image.h b/libraries/image/src/image/Image.h index 5497d72fe9..74e9268451 100644 --- a/libraries/image/src/image/Image.h +++ b/libraries/image/src/image/Image.h @@ -16,6 +16,8 @@ #include +#include "ColorChannel.h" + class QByteArray; class QImage; @@ -90,7 +92,7 @@ gpu::TexturePointer processCubeTextureColorFromImage(QImage&& srcImage, const st const QStringList getSupportedFormats(); -gpu::TexturePointer processImage(std::shared_ptr content, const std::string& url, TextureUsage::ColorChannel sourceChannel, +gpu::TexturePointer processImage(std::shared_ptr content, const std::string& url, ColorChannel sourceChannel, int maxNumPixels, TextureUsage::Type textureType, bool compress, gpu::BackendTarget target, const std::atomic& abortProcessing = false); diff --git a/libraries/model-networking/src/model-networking/TextureCache.cpp b/libraries/model-networking/src/model-networking/TextureCache.cpp index 54f991a179..a78812b2f9 100644 --- a/libraries/model-networking/src/model-networking/TextureCache.cpp +++ b/libraries/model-networking/src/model-networking/TextureCache.cpp @@ -192,7 +192,7 @@ public: image::TextureUsage::Type type; const QByteArray& content; int maxNumPixels; - hfm::ColorChannel sourceChannel; + image::ColorChannel sourceChannel; }; namespace std { @@ -213,13 +213,13 @@ namespace std { }; } -ScriptableResource* TextureCache::prefetch(const QUrl& url, int type, int maxNumPixels, hfm::ColorChannel sourceChannel) { +ScriptableResource* TextureCache::prefetch(const QUrl& url, int type, int maxNumPixels, image::ColorChannel sourceChannel) { auto byteArray = QByteArray(); TextureExtra extra = { (image::TextureUsage::Type)type, byteArray, maxNumPixels, sourceChannel }; return ResourceCache::prefetch(url, &extra, std::hash()(extra)); } -NetworkTexturePointer TextureCache::getTexture(const QUrl& url, image::TextureUsage::Type type, const QByteArray& content, int maxNumPixels, hfm::ColorChannel sourceChannel) { +NetworkTexturePointer TextureCache::getTexture(const QUrl& url, image::TextureUsage::Type type, const QByteArray& content, int maxNumPixels, image::ColorChannel sourceChannel) { if (url.scheme() == RESOURCE_SCHEME) { return getResourceTexture(url); } @@ -371,7 +371,7 @@ void NetworkTexture::setExtra(void* extra) { const TextureExtra* textureExtra = static_cast(extra); _type = textureExtra ? textureExtra->type : image::TextureUsage::DEFAULT_TEXTURE; _maxNumPixels = textureExtra ? textureExtra->maxNumPixels : ABSOLUTE_MAX_TEXTURE_NUM_PIXELS; - _sourceChannel = textureExtra ? textureExtra->sourceChannel : hfm::ColorChannel::NONE; + _sourceChannel = textureExtra ? textureExtra->sourceChannel : image::ColorChannel::NONE; _textureSource = std::make_shared(_url, (int)_type); _lowestRequestedMipLevel = 0; @@ -434,7 +434,7 @@ class ImageReader : public QRunnable { public: ImageReader(const QWeakPointer& resource, const QUrl& url, const QByteArray& data, size_t extraHash, int maxNumPixels, - hfm::ColorChannel sourceChannel); + image::ColorChannel sourceChannel); void run() override final; void read(); @@ -446,7 +446,7 @@ private: QByteArray _content; size_t _extraHash; int _maxNumPixels; - hfm::ColorChannel _sourceChannel; + image::ColorChannel _sourceChannel; }; NetworkTexture::~NetworkTexture() { @@ -1104,7 +1104,7 @@ void NetworkTexture::refresh() { Resource::refresh(); } -ImageReader::ImageReader(const QWeakPointer& resource, const QUrl& url, const QByteArray& data, size_t extraHash, int maxNumPixels, hfm::ColorChannel sourceChannel) : +ImageReader::ImageReader(const QWeakPointer& resource, const QUrl& url, const QByteArray& data, size_t extraHash, int maxNumPixels, image::ColorChannel sourceChannel) : _resource(resource), _url(url), _content(data), @@ -1218,7 +1218,7 @@ void ImageReader::read() { constexpr bool shouldCompress = false; #endif auto target = getBackendTarget(); - texture = image::processImage(std::move(buffer), _url.toString().toStdString(), (image::TextureUsage::ColorChannel)_sourceChannel, _maxNumPixels, networkTexture->getTextureType(), shouldCompress, target); + texture = image::processImage(std::move(buffer), _url.toString().toStdString(), _sourceChannel, _maxNumPixels, networkTexture->getTextureType(), shouldCompress, target); if (!texture) { QMetaObject::invokeMethod(resource.data(), "setImage", diff --git a/libraries/model-networking/src/model-networking/TextureCache.h b/libraries/model-networking/src/model-networking/TextureCache.h index 16627012b3..acca916acc 100644 --- a/libraries/model-networking/src/model-networking/TextureCache.h +++ b/libraries/model-networking/src/model-networking/TextureCache.h @@ -22,7 +22,7 @@ #include #include #include -#include +#include #include #include #include @@ -97,7 +97,7 @@ private: friend class ImageReader; image::TextureUsage::Type _type; - hfm::ColorChannel _sourceChannel; + image::ColorChannel _sourceChannel; enum class ResourceType { META, @@ -181,7 +181,7 @@ public: /// Loads a texture from the specified URL. NetworkTexturePointer getTexture(const QUrl& url, image::TextureUsage::Type type = image::TextureUsage::DEFAULT_TEXTURE, const QByteArray& content = QByteArray(), int maxNumPixels = ABSOLUTE_MAX_TEXTURE_NUM_PIXELS, - hfm::ColorChannel sourceChannel = hfm::ColorChannel::NONE); + image::ColorChannel sourceChannel = image::ColorChannel::NONE); gpu::TexturePointer getTextureByHash(const std::string& hash); gpu::TexturePointer cacheTextureByHash(const std::string& hash, const gpu::TexturePointer& texture); @@ -204,7 +204,7 @@ signals: protected: // Overload ResourceCache::prefetch to allow specifying texture type for loads - Q_INVOKABLE ScriptableResource* prefetch(const QUrl& url, int type, int maxNumPixels = ABSOLUTE_MAX_TEXTURE_NUM_PIXELS, hfm::ColorChannel sourceChannel = hfm::ColorChannel::NONE); + Q_INVOKABLE ScriptableResource* prefetch(const QUrl& url, int type, int maxNumPixels = ABSOLUTE_MAX_TEXTURE_NUM_PIXELS, image::ColorChannel sourceChannel = image::ColorChannel::NONE); virtual QSharedPointer createResource(const QUrl& url) override; QSharedPointer createResourceCopy(const QSharedPointer& resource) override; diff --git a/libraries/procedural/CMakeLists.txt b/libraries/procedural/CMakeLists.txt index f2562907e0..f3c3be687a 100644 --- a/libraries/procedural/CMakeLists.txt +++ b/libraries/procedural/CMakeLists.txt @@ -1,5 +1,3 @@ set(TARGET_NAME procedural) setup_hifi_library() link_hifi_libraries(shared gpu shaders networking graphics model-networking ktx image) - -include_hifi_library_headers(hfm) From b2e3b87ef474262d03f5ab88d904010a653be937 Mon Sep 17 00:00:00 2001 From: sabrina-shanman Date: Tue, 12 Feb 2019 16:24:13 -0800 Subject: [PATCH 08/10] Add two missing CMake includes --- libraries/animation/CMakeLists.txt | 1 + libraries/model-baker/CMakeLists.txt | 2 ++ 2 files changed, 3 insertions(+) diff --git a/libraries/animation/CMakeLists.txt b/libraries/animation/CMakeLists.txt index 30addadcaa..1ab54ed342 100644 --- a/libraries/animation/CMakeLists.txt +++ b/libraries/animation/CMakeLists.txt @@ -4,5 +4,6 @@ link_hifi_libraries(shared graphics fbx) include_hifi_library_headers(networking) include_hifi_library_headers(gpu) include_hifi_library_headers(hfm) +include_hifi_library_headers(image) target_nsight() diff --git a/libraries/model-baker/CMakeLists.txt b/libraries/model-baker/CMakeLists.txt index 6fa7c1815a..aabd6eba3a 100644 --- a/libraries/model-baker/CMakeLists.txt +++ b/libraries/model-baker/CMakeLists.txt @@ -2,3 +2,5 @@ set(TARGET_NAME model-baker) setup_hifi_library() link_hifi_libraries(shared task gpu graphics hfm) + +include_hifi_library_headers(image) From 08ef9b6f8405d18c6dd8ad402edd507882a51cac Mon Sep 17 00:00:00 2001 From: sabrina-shanman Date: Tue, 12 Feb 2019 16:44:37 -0800 Subject: [PATCH 09/10] Remove unused duplicate ColorChannel enum --- libraries/image/src/image/Image.h | 9 --------- 1 file changed, 9 deletions(-) diff --git a/libraries/image/src/image/Image.h b/libraries/image/src/image/Image.h index 74e9268451..40c31eeeff 100644 --- a/libraries/image/src/image/Image.h +++ b/libraries/image/src/image/Image.h @@ -43,15 +43,6 @@ enum Type { UNUSED_TEXTURE }; -enum class ColorChannel { - NONE, - RED, - GREEN, - BLUE, - ALPHA, - COUNT -}; - using TextureLoader = std::function&)>; TextureLoader getTextureLoaderForType(Type type, const QVariantMap& options = QVariantMap()); From efd22172b40009bd67f4ce3578388d60f66a931c Mon Sep 17 00:00:00 2001 From: sabrina-shanman Date: Tue, 12 Feb 2019 17:27:04 -0800 Subject: [PATCH 10/10] Add final missing CMake includes --- tools/skeleton-dump/CMakeLists.txt | 2 ++ tools/vhacd-util/CMakeLists.txt | 2 ++ 2 files changed, 4 insertions(+) diff --git a/tools/skeleton-dump/CMakeLists.txt b/tools/skeleton-dump/CMakeLists.txt index baec1d163b..7d4248d171 100644 --- a/tools/skeleton-dump/CMakeLists.txt +++ b/tools/skeleton-dump/CMakeLists.txt @@ -2,3 +2,5 @@ set(TARGET_NAME skeleton-dump) setup_hifi_project(Core) setup_memory_debugger() link_hifi_libraries(shared fbx hfm graphics gpu gl animation) + +include_hifi_library_headers(image) diff --git a/tools/vhacd-util/CMakeLists.txt b/tools/vhacd-util/CMakeLists.txt index aa6642c610..90cfdf878a 100644 --- a/tools/vhacd-util/CMakeLists.txt +++ b/tools/vhacd-util/CMakeLists.txt @@ -2,6 +2,8 @@ set(TARGET_NAME vhacd-util) setup_hifi_project(Core) link_hifi_libraries(shared fbx hfm graphics gpu gl) +include_hifi_library_headers(image) + add_dependency_external_projects(vhacd) find_package(VHACD REQUIRED)