Re-name ColorChannelMapping to ColorChannel and put versions in two specific libraries rather than shared

This commit is contained in:
sabrina-shanman 2019-02-12 11:56:44 -08:00
parent 2c5446dfb5
commit 2b355e9d52
10 changed files with 69 additions and 58 deletions

View file

@ -1146,10 +1146,10 @@ void GLTFSerializer::setHFMMaterial(HFMMaterial& fbxmat, const GLTFMaterial& mat
} }
if (material.pbrMetallicRoughness.defined["metallicRoughnessTexture"]) { if (material.pbrMetallicRoughness.defined["metallicRoughnessTexture"]) {
fbxmat.roughnessTexture = getHFMTexture(_file.textures[material.pbrMetallicRoughness.metallicRoughnessTexture]); fbxmat.roughnessTexture = getHFMTexture(_file.textures[material.pbrMetallicRoughness.metallicRoughnessTexture]);
fbxmat.roughnessTexture.channelMapping = ColorChannelMapping::GREEN; fbxmat.roughnessTexture.sourceChannel = hfm::ColorChannel::GREEN;
fbxmat.useRoughnessMap = true; fbxmat.useRoughnessMap = true;
fbxmat.metallicTexture = getHFMTexture(_file.textures[material.pbrMetallicRoughness.metallicRoughnessTexture]); fbxmat.metallicTexture = getHFMTexture(_file.textures[material.pbrMetallicRoughness.metallicRoughnessTexture]);
fbxmat.metallicTexture.channelMapping = ColorChannelMapping::BLUE; fbxmat.metallicTexture.sourceChannel = hfm::ColorChannel::BLUE;
fbxmat.useMetallicMap = true; fbxmat.useMetallicMap = true;
} }
if (material.pbrMetallicRoughness.defined["roughnessFactor"]) { if (material.pbrMetallicRoughness.defined["roughnessFactor"]) {

View file

@ -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

View file

@ -24,7 +24,8 @@
#include <graphics/Geometry.h> #include <graphics/Geometry.h>
#include <graphics/Material.h> #include <graphics/Material.h>
#include <shared/ColorChannelMapping.h>
#include "ColorChannel.h"
#if defined(Q_OS_ANDROID) #if defined(Q_OS_ANDROID)
#define HFM_PACK_NORMALS 0 #define HFM_PACK_NORMALS 0
@ -124,7 +125,7 @@ public:
QString name; QString name;
QByteArray filename; QByteArray filename;
QByteArray content; QByteArray content;
ColorChannelMapping channelMapping { ColorChannelMapping::NONE }; ColorChannel sourceChannel { ColorChannel::NONE };
Transform transform; Transform transform;
int maxNumPixels { MAX_NUM_PIXELS_FOR_FBX_TEXTURE }; int maxNumPixels { MAX_NUM_PIXELS_FOR_FBX_TEXTURE };

View file

@ -222,7 +222,7 @@ QImage processRawImageData(QIODevice& content, const std::string& filename) {
return QImage(); 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 // Change format of image so we know exactly how to process it
if (image.format() != QImage::Format_ARGB32) { if (image.format() != QImage::Format_ARGB32) {
image = image.convertToFormat(QImage::Format_ARGB32); image = image.convertToFormat(QImage::Format_ARGB32);
@ -237,16 +237,16 @@ void mapToRedChannel(QImage& image, ColorChannelMapping sourceChannel) {
for (; pixel < lineEnd; pixel++) { for (; pixel < lineEnd; pixel++) {
int colorValue; int colorValue;
switch (sourceChannel) { switch (sourceChannel) {
case ColorChannelMapping::RED: case TextureUsage::ColorChannel::RED:
colorValue = qRed(*pixel); colorValue = qRed(*pixel);
break; break;
case ColorChannelMapping::GREEN: case TextureUsage::ColorChannel::GREEN:
colorValue = qGreen(*pixel); colorValue = qGreen(*pixel);
break; break;
case ColorChannelMapping::BLUE: case TextureUsage::ColorChannel::BLUE:
colorValue = qBlue(*pixel); colorValue = qBlue(*pixel);
break; break;
case ColorChannelMapping::ALPHA: case TextureUsage::ColorChannel::ALPHA:
colorValue = qAlpha(*pixel); colorValue = qAlpha(*pixel);
break; break;
default: default:
@ -260,7 +260,7 @@ void mapToRedChannel(QImage& image, ColorChannelMapping sourceChannel) {
} }
} }
gpu::TexturePointer processImage(std::shared_ptr<QIODevice> content, const std::string& filename, ColorChannelMapping channelMapping, gpu::TexturePointer processImage(std::shared_ptr<QIODevice> content, const std::string& filename, TextureUsage::ColorChannel sourceChannel,
int maxNumPixels, TextureUsage::Type textureType, int maxNumPixels, TextureUsage::Type textureType,
bool compress, BackendTarget target, const std::atomic<bool>& abortProcessing) { bool compress, BackendTarget target, const std::atomic<bool>& abortProcessing) {
@ -293,8 +293,8 @@ gpu::TexturePointer processImage(std::shared_ptr<QIODevice> content, const std::
} }
// Re-map to image with single red channel texture if requested // Re-map to image with single red channel texture if requested
if (channelMapping != ColorChannelMapping::NONE) { if (sourceChannel != TextureUsage::ColorChannel::NONE) {
mapToRedChannel(image, channelMapping); mapToRedChannel(image, sourceChannel);
} }
auto loader = TextureUsage::getTextureLoaderForType(textureType); auto loader = TextureUsage::getTextureLoaderForType(textureType);

View file

@ -15,7 +15,6 @@
#include <QVariant> #include <QVariant>
#include <gpu/Texture.h> #include <gpu/Texture.h>
#include <shared/ColorChannelMapping.h>
class QByteArray; class QByteArray;
class QImage; class QImage;
@ -42,6 +41,15 @@ enum Type {
UNUSED_TEXTURE UNUSED_TEXTURE
}; };
enum class ColorChannel {
NONE,
RED,
GREEN,
BLUE,
ALPHA,
COUNT
};
using TextureLoader = std::function<gpu::TexturePointer(QImage&&, const std::string&, bool, gpu::BackendTarget, const std::atomic<bool>&)>; using TextureLoader = std::function<gpu::TexturePointer(QImage&&, const std::string&, bool, gpu::BackendTarget, const std::atomic<bool>&)>;
TextureLoader getTextureLoaderForType(Type type, const QVariantMap& options = QVariantMap()); TextureLoader getTextureLoaderForType(Type type, const QVariantMap& options = QVariantMap());
@ -82,7 +90,7 @@ gpu::TexturePointer processCubeTextureColorFromImage(QImage&& srcImage, const st
const QStringList getSupportedFormats(); const QStringList getSupportedFormats();
gpu::TexturePointer processImage(std::shared_ptr<QIODevice> content, const std::string& url, ColorChannelMapping channelMapping, gpu::TexturePointer processImage(std::shared_ptr<QIODevice> content, const std::string& url, TextureUsage::ColorChannel sourceChannel,
int maxNumPixels, TextureUsage::Type textureType, int maxNumPixels, TextureUsage::Type textureType,
bool compress, gpu::BackendTarget target, const std::atomic<bool>& abortProcessing = false); bool compress, gpu::BackendTarget target, const std::atomic<bool>& abortProcessing = false);

View file

@ -599,7 +599,7 @@ graphics::TextureMapPointer NetworkMaterial::fetchTextureMap(const QUrl& baseUrl
} }
const auto url = getTextureUrl(baseUrl, hfmTexture); const auto url = getTextureUrl(baseUrl, hfmTexture);
const auto texture = DependencyManager::get<TextureCache>()->getTexture(url, type, hfmTexture.content, hfmTexture.maxNumPixels, hfmTexture.channelMapping); const auto texture = DependencyManager::get<TextureCache>()->getTexture(url, type, hfmTexture.content, hfmTexture.maxNumPixels, hfmTexture.sourceChannel);
_textures[channel] = Texture { hfmTexture.name, texture }; _textures[channel] = Texture { hfmTexture.name, texture };
auto map = std::make_shared<graphics::TextureMap>(); auto map = std::make_shared<graphics::TextureMap>();

View file

@ -192,7 +192,7 @@ public:
image::TextureUsage::Type type; image::TextureUsage::Type type;
const QByteArray& content; const QByteArray& content;
int maxNumPixels; int maxNumPixels;
ColorChannelMapping channelMapping; hfm::ColorChannel sourceChannel;
}; };
namespace std { namespace std {
@ -207,19 +207,19 @@ namespace std {
struct hash<TextureExtra> { struct hash<TextureExtra> {
size_t operator()(const TextureExtra& a) const { size_t operator()(const TextureExtra& a) const {
size_t result = 0; 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; 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(); 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<TextureExtra>()(extra)); return ResourceCache::prefetch(url, &extra, std::hash<TextureExtra>()(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) { if (url.scheme() == RESOURCE_SCHEME) {
return getResourceTexture(url); return getResourceTexture(url);
} }
@ -229,7 +229,7 @@ NetworkTexturePointer TextureCache::getTexture(const QUrl& url, image::TextureUs
query.addQueryItem("skybox", ""); query.addQueryItem("skybox", "");
modifiedUrl.setQuery(query.toString()); modifiedUrl.setQuery(query.toString());
} }
TextureExtra extra = { type, content, maxNumPixels, channelMapping }; TextureExtra extra = { type, content, maxNumPixels, sourceChannel };
return ResourceCache::getResource(modifiedUrl, QUrl(), &extra, std::hash<TextureExtra>()(extra)).staticCast<NetworkTexture>(); return ResourceCache::getResource(modifiedUrl, QUrl(), &extra, std::hash<TextureExtra>()(extra)).staticCast<NetworkTexture>();
} }
@ -347,7 +347,7 @@ NetworkTexture::NetworkTexture(const QUrl& url, bool resourceTexture) :
NetworkTexture::NetworkTexture(const NetworkTexture& other) : NetworkTexture::NetworkTexture(const NetworkTexture& other) :
Resource(other), Resource(other),
_type(other._type), _type(other._type),
_channelMapping(other._channelMapping), _sourceChannel(other._sourceChannel),
_currentlyLoadingResourceType(other._currentlyLoadingResourceType), _currentlyLoadingResourceType(other._currentlyLoadingResourceType),
_originalWidth(other._originalWidth), _originalWidth(other._originalWidth),
_originalHeight(other._originalHeight), _originalHeight(other._originalHeight),
@ -371,7 +371,7 @@ void NetworkTexture::setExtra(void* extra) {
const TextureExtra* textureExtra = static_cast<const TextureExtra*>(extra); const TextureExtra* textureExtra = static_cast<const TextureExtra*>(extra);
_type = textureExtra ? textureExtra->type : image::TextureUsage::DEFAULT_TEXTURE; _type = textureExtra ? textureExtra->type : image::TextureUsage::DEFAULT_TEXTURE;
_maxNumPixels = textureExtra ? textureExtra->maxNumPixels : ABSOLUTE_MAX_TEXTURE_NUM_PIXELS; _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<gpu::TextureSource>(_url, (int)_type); _textureSource = std::make_shared<gpu::TextureSource>(_url, (int)_type);
_lowestRequestedMipLevel = 0; _lowestRequestedMipLevel = 0;
@ -434,7 +434,7 @@ class ImageReader : public QRunnable {
public: public:
ImageReader(const QWeakPointer<Resource>& resource, const QUrl& url, ImageReader(const QWeakPointer<Resource>& resource, const QUrl& url,
const QByteArray& data, size_t extraHash, int maxNumPixels, const QByteArray& data, size_t extraHash, int maxNumPixels,
ColorChannelMapping channelMapping); hfm::ColorChannel sourceChannel);
void run() override final; void run() override final;
void read(); void read();
@ -446,7 +446,7 @@ private:
QByteArray _content; QByteArray _content;
size_t _extraHash; size_t _extraHash;
int _maxNumPixels; int _maxNumPixels;
ColorChannelMapping _channelMapping; hfm::ColorChannel _sourceChannel;
}; };
NetworkTexture::~NetworkTexture() { NetworkTexture::~NetworkTexture() {
@ -1079,7 +1079,7 @@ void NetworkTexture::loadTextureContent(const QByteArray& content) {
return; 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() { void NetworkTexture::refresh() {
@ -1104,13 +1104,13 @@ void NetworkTexture::refresh() {
Resource::refresh(); Resource::refresh();
} }
ImageReader::ImageReader(const QWeakPointer<Resource>& resource, const QUrl& url, const QByteArray& data, size_t extraHash, int maxNumPixels, const ColorChannelMapping channelMapping) : ImageReader::ImageReader(const QWeakPointer<Resource>& resource, const QUrl& url, const QByteArray& data, size_t extraHash, int maxNumPixels, hfm::ColorChannel sourceChannel) :
_resource(resource), _resource(resource),
_url(url), _url(url),
_content(data), _content(data),
_extraHash(extraHash), _extraHash(extraHash),
_maxNumPixels(maxNumPixels), _maxNumPixels(maxNumPixels),
_channelMapping(channelMapping) _sourceChannel(sourceChannel)
{ {
DependencyManager::get<StatTracker>()->incrementStat("PendingProcessing"); DependencyManager::get<StatTracker>()->incrementStat("PendingProcessing");
listSupportedImageFormats(); listSupportedImageFormats();
@ -1218,7 +1218,7 @@ void ImageReader::read() {
constexpr bool shouldCompress = false; constexpr bool shouldCompress = false;
#endif #endif
auto target = getBackendTarget(); 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) { if (!texture) {
QMetaObject::invokeMethod(resource.data(), "setImage", QMetaObject::invokeMethod(resource.data(), "setImage",

View file

@ -22,6 +22,7 @@
#include <DependencyManager.h> #include <DependencyManager.h>
#include <ResourceCache.h> #include <ResourceCache.h>
#include <graphics/TextureMap.h> #include <graphics/TextureMap.h>
#include <hfm/ColorChannel.h>
#include <image/Image.h> #include <image/Image.h>
#include <ktx/KTX.h> #include <ktx/KTX.h>
#include <TextureMeta.h> #include <TextureMeta.h>
@ -96,7 +97,7 @@ private:
friend class ImageReader; friend class ImageReader;
image::TextureUsage::Type _type; image::TextureUsage::Type _type;
ColorChannelMapping _channelMapping; hfm::ColorChannel _sourceChannel;
enum class ResourceType { enum class ResourceType {
META, META,
@ -180,7 +181,7 @@ public:
/// Loads a texture from the specified URL. /// Loads a texture from the specified URL.
NetworkTexturePointer getTexture(const QUrl& url, image::TextureUsage::Type type = image::TextureUsage::DEFAULT_TEXTURE, 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); hfm::ColorChannel sourceChannel = hfm::ColorChannel::NONE);
gpu::TexturePointer getTextureByHash(const std::string& hash); gpu::TexturePointer getTextureByHash(const std::string& hash);
gpu::TexturePointer cacheTextureByHash(const std::string& hash, const gpu::TexturePointer& texture); gpu::TexturePointer cacheTextureByHash(const std::string& hash, const gpu::TexturePointer& texture);
@ -203,7 +204,7 @@ signals:
protected: protected:
// Overload ResourceCache::prefetch to allow specifying texture type for loads // 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<Resource> createResource(const QUrl& url) override; virtual QSharedPointer<Resource> createResource(const QUrl& url) override;
QSharedPointer<Resource> createResourceCopy(const QSharedPointer<Resource>& resource) override; QSharedPointer<Resource> createResourceCopy(const QSharedPointer<Resource>& resource) override;

View file

@ -2,3 +2,4 @@ set(TARGET_NAME procedural)
setup_hifi_library() setup_hifi_library()
link_hifi_libraries(shared gpu shaders networking graphics model-networking ktx image) link_hifi_libraries(shared gpu shaders networking graphics model-networking ktx image)
include_hifi_library_headers(hfm)

View file

@ -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