From 2b355e9d52a7c129e642ed64334c80813d125838 Mon Sep 17 00:00:00 2001 From: sabrina-shanman Date: Tue, 12 Feb 2019 11:56:44 -0800 Subject: [PATCH] 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