mirror of
https://github.com/JulianGro/overte.git
synced 2025-04-09 05:03:41 +02:00
Add support for Grayscale and NormalMap textures
This commit is contained in:
parent
27c6011e6e
commit
ae73cf4038
8 changed files with 86 additions and 217 deletions
|
@ -76,10 +76,6 @@ GLenum GLTexelFormat::evalGLTexelFormatInternal(const gpu::Element& dstFormat) {
|
|||
}
|
||||
break;
|
||||
|
||||
case gpu::COMPRESSED_R:
|
||||
result = GL_COMPRESSED_RED_RGTC1;
|
||||
break;
|
||||
|
||||
case gpu::R11G11B10:
|
||||
// the type should be float
|
||||
result = GL_R11F_G11F_B10F;
|
||||
|
@ -149,12 +145,6 @@ GLenum GLTexelFormat::evalGLTexelFormatInternal(const gpu::Element& dstFormat) {
|
|||
case gpu::SRGBA:
|
||||
result = GL_SRGB8; // standard 2.2 gamma correction color
|
||||
break;
|
||||
case gpu::COMPRESSED_RGB:
|
||||
result = GL_COMPRESSED_RGB;
|
||||
break;
|
||||
case gpu::COMPRESSED_SRGB:
|
||||
result = GL_COMPRESSED_SRGB;
|
||||
break;
|
||||
default:
|
||||
qCWarning(gpugllogging) << "Unknown combination of texel format";
|
||||
}
|
||||
|
@ -217,13 +207,10 @@ GLenum GLTexelFormat::evalGLTexelFormatInternal(const gpu::Element& dstFormat) {
|
|||
case gpu::SRGBA:
|
||||
result = GL_SRGB8_ALPHA8; // standard 2.2 gamma correction color
|
||||
break;
|
||||
case gpu::COMPRESSED_RGBA:
|
||||
result = GL_COMPRESSED_RGBA;
|
||||
break;
|
||||
case gpu::COMPRESSED_SRGBA:
|
||||
result = GL_COMPRESSED_SRGB_ALPHA;
|
||||
break;
|
||||
|
||||
case gpu::COMPRESSED_BC4_RED:
|
||||
result = GL_COMPRESSED_RED_RGTC1;
|
||||
break;
|
||||
case gpu::COMPRESSED_BC1_SRGB:
|
||||
result = GL_COMPRESSED_SRGB_S3TC_DXT1_EXT;
|
||||
break;
|
||||
|
@ -233,6 +220,9 @@ GLenum GLTexelFormat::evalGLTexelFormatInternal(const gpu::Element& dstFormat) {
|
|||
case gpu::COMPRESSED_BC3_SRGBA:
|
||||
result = GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT;
|
||||
break;
|
||||
case gpu::COMPRESSED_BC5_XY:
|
||||
result = GL_COMPRESSED_RG_RGTC2;
|
||||
break;
|
||||
|
||||
default:
|
||||
qCWarning(gpugllogging) << "Unknown combination of texel format";
|
||||
|
@ -262,10 +252,6 @@ GLTexelFormat GLTexelFormat::evalGLTexelFormat(const Element& dstFormat, const E
|
|||
texel.internalFormat = GL_R8;
|
||||
break;
|
||||
|
||||
case gpu::COMPRESSED_R:
|
||||
texel.internalFormat = GL_COMPRESSED_RED_RGTC1;
|
||||
break;
|
||||
|
||||
case gpu::DEPTH:
|
||||
texel.format = GL_DEPTH_COMPONENT;
|
||||
texel.internalFormat = GL_DEPTH_COMPONENT32;
|
||||
|
@ -308,12 +294,6 @@ GLTexelFormat GLTexelFormat::evalGLTexelFormat(const Element& dstFormat, const E
|
|||
case gpu::RGBA:
|
||||
texel.internalFormat = GL_RGB8;
|
||||
break;
|
||||
case gpu::COMPRESSED_RGB:
|
||||
texel.internalFormat = GL_COMPRESSED_RGB;
|
||||
break;
|
||||
case gpu::COMPRESSED_SRGB:
|
||||
texel.internalFormat = GL_COMPRESSED_SRGB;
|
||||
break;
|
||||
default:
|
||||
qCWarning(gpugllogging) << "Unknown combination of texel format";
|
||||
}
|
||||
|
@ -352,6 +332,10 @@ GLTexelFormat GLTexelFormat::evalGLTexelFormat(const Element& dstFormat, const E
|
|||
texel.internalFormat = GL_SRGB8_ALPHA8;
|
||||
break;
|
||||
|
||||
|
||||
case gpu::COMPRESSED_BC4_RED:
|
||||
texel.internalFormat = GL_COMPRESSED_RED_RGTC1;
|
||||
break;
|
||||
case gpu::COMPRESSED_BC1_SRGB:
|
||||
texel.internalFormat = GL_COMPRESSED_SRGB_S3TC_DXT1_EXT;
|
||||
break;
|
||||
|
@ -361,6 +345,9 @@ GLTexelFormat GLTexelFormat::evalGLTexelFormat(const Element& dstFormat, const E
|
|||
case gpu::COMPRESSED_BC3_SRGBA:
|
||||
texel.internalFormat = GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT;
|
||||
break;
|
||||
case gpu::COMPRESSED_BC5_XY:
|
||||
texel.internalFormat = GL_COMPRESSED_RG_RGTC2;
|
||||
break;
|
||||
|
||||
default:
|
||||
qCWarning(gpugllogging) << "Unknown combination of texel format";
|
||||
|
@ -381,10 +368,6 @@ GLTexelFormat GLTexelFormat::evalGLTexelFormat(const Element& dstFormat, const E
|
|||
texel.type = ELEMENT_TYPE_TO_GL[dstFormat.getType()];
|
||||
|
||||
switch (dstFormat.getSemantic()) {
|
||||
case gpu::COMPRESSED_R: {
|
||||
texel.internalFormat = GL_COMPRESSED_RED_RGTC1;
|
||||
break;
|
||||
}
|
||||
case gpu::RED:
|
||||
case gpu::RGB:
|
||||
case gpu::RGBA:
|
||||
|
@ -542,12 +525,6 @@ GLTexelFormat GLTexelFormat::evalGLTexelFormat(const Element& dstFormat, const E
|
|||
case gpu::SRGBA:
|
||||
texel.internalFormat = GL_SRGB8; // standard 2.2 gamma correction color
|
||||
break;
|
||||
case gpu::COMPRESSED_RGB:
|
||||
texel.internalFormat = GL_COMPRESSED_RGB;
|
||||
break;
|
||||
case gpu::COMPRESSED_SRGB:
|
||||
texel.internalFormat = GL_COMPRESSED_SRGB;
|
||||
break;
|
||||
default:
|
||||
qCWarning(gpugllogging) << "Unknown combination of texel format";
|
||||
}
|
||||
|
@ -624,13 +601,10 @@ GLTexelFormat GLTexelFormat::evalGLTexelFormat(const Element& dstFormat, const E
|
|||
case gpu::SRGBA:
|
||||
texel.internalFormat = GL_SRGB8_ALPHA8; // standard 2.2 gamma correction color
|
||||
break;
|
||||
case gpu::COMPRESSED_RGBA:
|
||||
texel.internalFormat = GL_COMPRESSED_RGBA;
|
||||
break;
|
||||
case gpu::COMPRESSED_SRGBA:
|
||||
texel.internalFormat = GL_COMPRESSED_SRGB_ALPHA;
|
||||
break;
|
||||
|
||||
case gpu::COMPRESSED_BC4_RED:
|
||||
texel.internalFormat = GL_COMPRESSED_RED_RGTC1;
|
||||
break;
|
||||
case gpu::COMPRESSED_BC1_SRGB:
|
||||
texel.internalFormat = GL_COMPRESSED_SRGB_S3TC_DXT1_EXT;
|
||||
break;
|
||||
|
@ -640,6 +614,9 @@ GLTexelFormat GLTexelFormat::evalGLTexelFormat(const Element& dstFormat, const E
|
|||
case gpu::COMPRESSED_BC3_SRGBA:
|
||||
texel.internalFormat = GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT;
|
||||
break;
|
||||
case gpu::COMPRESSED_BC5_XY:
|
||||
texel.internalFormat = GL_COMPRESSED_RG_RGTC2;
|
||||
break;
|
||||
default:
|
||||
qCWarning(gpugllogging) << "Unknown combination of texel format";
|
||||
}
|
||||
|
|
|
@ -98,6 +98,8 @@ void GL41Texture::copyMipFaceLinesFromTexture(uint16_t mip, uint8_t face, const
|
|||
case GL_COMPRESSED_SRGB_S3TC_DXT1_EXT:
|
||||
case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT:
|
||||
case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT:
|
||||
case GL_COMPRESSED_RED_RGTC1:
|
||||
case GL_COMPRESSED_RG_RGTC2:
|
||||
glCompressedTexSubImage2D(_id, mip, 0, yOffset, size.x, size.y, internalFormat, sourceSize, sourcePointer);
|
||||
break;
|
||||
default:
|
||||
|
|
|
@ -123,6 +123,8 @@ void GL45Texture::copyMipFaceLinesFromTexture(uint16_t mip, uint8_t face, const
|
|||
case GL_COMPRESSED_SRGB_S3TC_DXT1_EXT:
|
||||
case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT:
|
||||
case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT:
|
||||
case GL_COMPRESSED_RED_RGTC1:
|
||||
case GL_COMPRESSED_RG_RGTC2:
|
||||
glCompressedTextureSubImage2D(_id, mip, 0, yOffset, size.x, size.y, internalFormat, sourceSize, sourcePointer);
|
||||
break;
|
||||
default:
|
||||
|
|
|
@ -19,9 +19,11 @@ const Element Element::COLOR_SRGBA_32{ VEC4, NUINT8, SRGBA };
|
|||
const Element Element::COLOR_BGRA_32{ VEC4, NUINT8, BGRA };
|
||||
const Element Element::COLOR_SBGRA_32{ VEC4, NUINT8, SBGRA };
|
||||
|
||||
const Element Element::COLOR_COMPRESSED_RED{VEC4, NUINT8, COMPRESSED_BC4_RED};
|
||||
const Element Element::COLOR_COMPRESSED_SRGB{ VEC4, NUINT8, COMPRESSED_BC1_SRGB };
|
||||
const Element Element::COLOR_COMPRESSED_SRGBA_MASK{ VEC4, NUINT8, COMPRESSED_BC1_SRGBA };
|
||||
const Element Element::COLOR_COMPRESSED_SRGBA{ VEC4, NUINT8, COMPRESSED_BC3_SRGBA };
|
||||
const Element Element::COLOR_COMPRESSED_SRGBA_MASK{VEC4, NUINT8, COMPRESSED_BC1_SRGBA};
|
||||
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::COLOR_R11G11B10{ SCALAR, FLOAT, R11G11B10 };
|
||||
const Element Element::VEC4F_COLOR_RGBA{ VEC4, FLOAT, RGBA };
|
||||
|
|
|
@ -157,17 +157,12 @@ enum Semantic {
|
|||
|
||||
// These are generic compression format smeantic for images
|
||||
_FIRST_COMPRESSED,
|
||||
COMPRESSED_R,
|
||||
|
||||
COMPRESSED_RGB,
|
||||
COMPRESSED_RGBA,
|
||||
|
||||
COMPRESSED_SRGB,
|
||||
COMPRESSED_SRGBA,
|
||||
|
||||
COMPRESSED_BC1_SRGB,
|
||||
COMPRESSED_BC1_SRGBA,
|
||||
COMPRESSED_BC3_SRGBA,
|
||||
COMPRESSED_BC4_RED,
|
||||
COMPRESSED_BC5_XY,
|
||||
|
||||
_LAST_COMPRESSED,
|
||||
|
||||
|
@ -234,9 +229,11 @@ public:
|
|||
static const Element COLOR_BGRA_32;
|
||||
static const Element COLOR_SBGRA_32;
|
||||
static const Element COLOR_R11G11B10;
|
||||
static const Element COLOR_COMPRESSED_RED;
|
||||
static const Element COLOR_COMPRESSED_SRGB;
|
||||
static const Element COLOR_COMPRESSED_SRGBA_MASK;
|
||||
static const Element COLOR_COMPRESSED_SRGBA;
|
||||
static const Element COLOR_COMPRESSED_XY;
|
||||
static const Element VEC4F_COLOR_RGBA;
|
||||
static const Element VEC2F_UV;
|
||||
static const Element VEC2F_XY;
|
||||
|
|
|
@ -266,6 +266,10 @@ bool Texture::evalKTXFormat(const Element& mipFormat, const Element& texelFormat
|
|||
header.setCompressed(ktx::GLInternalFormat_Compressed::COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT, ktx::GLBaseInternalFormat::RGBA);
|
||||
} else if (texelFormat == Format::COLOR_COMPRESSED_SRGBA && mipFormat == Format::COLOR_COMPRESSED_SRGBA) {
|
||||
header.setCompressed(ktx::GLInternalFormat_Compressed::COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT, ktx::GLBaseInternalFormat::RGBA);
|
||||
} else if (texelFormat == Format::COLOR_COMPRESSED_RED && mipFormat == Format::COLOR_COMPRESSED_RED) {
|
||||
header.setCompressed(ktx::GLInternalFormat_Compressed::COMPRESSED_RED_RGTC1, ktx::GLBaseInternalFormat::RED);
|
||||
} else if (texelFormat == Format::COLOR_COMPRESSED_XY && mipFormat == Format::COLOR_COMPRESSED_XY) {
|
||||
header.setCompressed(ktx::GLInternalFormat_Compressed::COMPRESSED_RG_RGTC2, ktx::GLBaseInternalFormat::RG);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
@ -311,6 +315,12 @@ bool Texture::evalTextureFormat(const ktx::Header& header, Element& mipFormat, E
|
|||
} else if (header.getGLInternaFormat_Compressed() == ktx::GLInternalFormat_Compressed::COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT) {
|
||||
mipFormat = Format::COLOR_COMPRESSED_SRGBA;
|
||||
texelFormat = Format::COLOR_COMPRESSED_SRGBA;
|
||||
} else if (header.getGLInternaFormat_Compressed() == ktx::GLInternalFormat_Compressed::COMPRESSED_RED_RGTC1) {
|
||||
mipFormat = Format::COLOR_COMPRESSED_RED;
|
||||
texelFormat = Format::COLOR_COMPRESSED_RED;
|
||||
} else if (header.getGLInternaFormat_Compressed() == ktx::GLInternalFormat_Compressed::COMPRESSED_RG_RGTC2) {
|
||||
mipFormat = Format::COLOR_COMPRESSED_XY;
|
||||
texelFormat = Format::COLOR_COMPRESSED_XY;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -28,7 +28,6 @@ using namespace gpu;
|
|||
// FIXME: Declare this to enable compression
|
||||
//#define COMPRESS_TEXTURES
|
||||
#define CPU_MIPMAPS 1
|
||||
#define DEBUG_NVTT 1
|
||||
|
||||
static const glm::uvec2 SPARSE_PAGE_SIZE(128);
|
||||
static const glm::uvec2 MAX_TEXTURE_SIZE(4096);
|
||||
|
@ -221,29 +220,16 @@ const QImage TextureUsage::process2DImageColor(const QImage& srcImage, bool& val
|
|||
}
|
||||
|
||||
void TextureUsage::defineColorTexelFormats(gpu::Element& formatGPU, gpu::Element& formatMip,
|
||||
const QImage& image, bool isLinear, bool doCompress) {
|
||||
#ifdef COMPRESS_TEXTURES
|
||||
#else
|
||||
doCompress = false;
|
||||
#endif
|
||||
|
||||
const QImage& image, bool isLinear) {
|
||||
if (image.hasAlphaChannel()) {
|
||||
gpu::Semantic gpuSemantic;
|
||||
gpu::Semantic mipSemantic;
|
||||
if (isLinear) {
|
||||
mipSemantic = gpu::BGRA;
|
||||
if (doCompress) {
|
||||
gpuSemantic = gpu::COMPRESSED_RGBA;
|
||||
} else {
|
||||
gpuSemantic = gpu::RGBA;
|
||||
}
|
||||
gpuSemantic = gpu::RGBA;
|
||||
} else {
|
||||
mipSemantic = gpu::SBGRA;
|
||||
if (doCompress) {
|
||||
gpuSemantic = gpu::COMPRESSED_SRGBA;
|
||||
} else {
|
||||
gpuSemantic = gpu::SRGBA;
|
||||
}
|
||||
gpuSemantic = gpu::SRGBA;
|
||||
}
|
||||
formatGPU = gpu::Element(gpu::VEC4, gpu::NUINT8, gpuSemantic);
|
||||
formatMip = gpu::Element(gpu::VEC4, gpu::NUINT8, mipSemantic);
|
||||
|
@ -252,62 +238,16 @@ void TextureUsage::defineColorTexelFormats(gpu::Element& formatGPU, gpu::Element
|
|||
gpu::Semantic mipSemantic;
|
||||
if (isLinear) {
|
||||
mipSemantic = gpu::RGB;
|
||||
if (doCompress) {
|
||||
gpuSemantic = gpu::COMPRESSED_RGB;
|
||||
} else {
|
||||
gpuSemantic = gpu::RGB;
|
||||
}
|
||||
gpuSemantic = gpu::RGB;
|
||||
} else {
|
||||
mipSemantic = gpu::SRGB;
|
||||
if (doCompress) {
|
||||
gpuSemantic = gpu::COMPRESSED_SRGB;
|
||||
} else {
|
||||
gpuSemantic = gpu::SRGB;
|
||||
}
|
||||
gpuSemantic = gpu::SRGB;
|
||||
}
|
||||
formatGPU = gpu::Element(gpu::VEC3, gpu::NUINT8, gpuSemantic);
|
||||
formatMip = gpu::Element(gpu::VEC3, gpu::NUINT8, mipSemantic);
|
||||
}
|
||||
}
|
||||
|
||||
void generateMips(gpu::Texture* texture, QImage& image, bool fastResize) {
|
||||
#if CPU_MIPMAPS
|
||||
PROFILE_RANGE(resource_parse, "generateMips");
|
||||
#if DEBUG_NVTT
|
||||
QDebug debug = qDebug();
|
||||
|
||||
debug << Q_FUNC_INFO << "\n";
|
||||
debug << (QList<int>() << image.byteCount() << image.width() << image.height() << image.depth()) << "\n";
|
||||
#endif // DEBUG_NVTT
|
||||
|
||||
texture->assignStoredMip(0, image.byteCount(), image.constBits());
|
||||
|
||||
auto numMips = texture->getNumMips();
|
||||
for (uint16 level = 1; level < numMips; ++level) {
|
||||
QSize mipSize(texture->evalMipWidth(level), texture->evalMipHeight(level));
|
||||
if (fastResize) {
|
||||
image = image.scaled(mipSize);
|
||||
|
||||
#if DEBUG_NVTT
|
||||
debug << "Begin fast { " << image.byteCount() << image.width() << image.height() << image.depth() << level << " } Ends\n";
|
||||
#endif // DEBUG_NVTT
|
||||
|
||||
texture->assignStoredMip(level, image.byteCount(), image.constBits());
|
||||
} else {
|
||||
QImage mipImage = image.scaled(mipSize, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
|
||||
|
||||
#if DEBUG_NVTT
|
||||
debug << "Begin { " << mipImage.byteCount() << mipImage.width() << mipImage.height() << mipImage.depth() << level << " } Ends\n";
|
||||
#endif // DEBUG_NVTT
|
||||
|
||||
texture->assignStoredMip(level, mipImage.byteCount(), mipImage.constBits());
|
||||
}
|
||||
}
|
||||
#else
|
||||
texture->autoGenerateMips(-1);
|
||||
#endif
|
||||
}
|
||||
|
||||
void generateFaceMips(gpu::Texture* texture, QImage& image, uint8 face) {
|
||||
#if CPU_MIPMAPS
|
||||
PROFILE_RANGE(resource_parse, "generateFaceMips");
|
||||
|
@ -325,26 +265,9 @@ void generateFaceMips(gpu::Texture* texture, QImage& image, uint8 face) {
|
|||
}
|
||||
|
||||
struct MyOutputHandler : public nvtt::OutputHandler {
|
||||
MyOutputHandler(gpu::Texture* texture, QDebug* debug) :
|
||||
#if DEBUG_NVTT
|
||||
_debug(debug),
|
||||
#endif // DEBUG_NVTT
|
||||
_texture(texture) {
|
||||
|
||||
}
|
||||
MyOutputHandler(gpu::Texture* texture) : _texture(texture) {}
|
||||
|
||||
virtual void beginImage(int size, int width, int height, int depth, int face, int miplevel) {
|
||||
#if DEBUG_NVTT
|
||||
auto list = QStringList() << QString::number(size)
|
||||
<< QString::number(width)
|
||||
<< QString::number(height)
|
||||
<< QString::number(depth)
|
||||
<< QString::number(face)
|
||||
<< QString::number(miplevel);
|
||||
_count = 0;
|
||||
_str = "Begin { " + list.join(", ");
|
||||
#endif // DEBUG_NVTT
|
||||
|
||||
_size = size;
|
||||
_miplevel = miplevel;
|
||||
|
||||
|
@ -352,31 +275,17 @@ struct MyOutputHandler : public nvtt::OutputHandler {
|
|||
_current = _data;
|
||||
}
|
||||
virtual bool writeData(const void* data, int size) {
|
||||
#if DEBUG_NVTT
|
||||
++_count;
|
||||
#endif // DEBUG_NVTT
|
||||
|
||||
assert(_current + size <= _data + _size);
|
||||
memcpy(_current, data, size);
|
||||
_current += size;
|
||||
return true;
|
||||
}
|
||||
virtual void endImage() {
|
||||
#if DEBUG_NVTT
|
||||
_str += " } End " + QString::number(_count) + "\n";
|
||||
*_debug << qPrintable(_str);
|
||||
#endif // DEBUG_NVTT
|
||||
|
||||
_texture->assignStoredMip(_miplevel, _size, static_cast<const gpu::Byte*>(_data));
|
||||
free(_data);
|
||||
_data = nullptr;
|
||||
}
|
||||
|
||||
#if DEBUG_NVTT
|
||||
int _count = 0;
|
||||
QString _str;
|
||||
QDebug* _debug{ nullptr };
|
||||
#endif // DEBUG_NVTT
|
||||
gpu::Byte* _data{ nullptr };
|
||||
gpu::Byte* _current{ nullptr };
|
||||
gpu::Texture* _texture{ nullptr };
|
||||
|
@ -389,26 +298,10 @@ struct MyErrorHandler : public nvtt::ErrorHandler {
|
|||
}
|
||||
};
|
||||
|
||||
void generateNVTTMips(gpu::Texture* texture, QImage& image, bool validAlpha, bool alphaAsMask) {
|
||||
void generateMips(gpu::Texture* texture, QImage& image, bool validAlpha, bool alphaAsMask, bool grayscale, bool normalMap) {
|
||||
#if CPU_MIPMAPS
|
||||
PROFILE_RANGE(resource_parse, "generateMips");
|
||||
|
||||
/*/
|
||||
generateMips(texture, image, false);
|
||||
return;
|
||||
/**/
|
||||
|
||||
|
||||
#if DEBUG_NVTT
|
||||
QDebug debug = qDebug();
|
||||
QDebug* debugPtr = &debug;
|
||||
|
||||
debug << Q_FUNC_INFO << "\n";
|
||||
debug << (QList<int>() << image.byteCount() << image.width() << image.height() << image.depth()) << "\n";
|
||||
#else
|
||||
QDebug* debugPtr = nullptr;
|
||||
#endif // DEBUG_NVTT
|
||||
|
||||
Q_ASSERT(image.format() == QImage::Format_ARGB32);
|
||||
|
||||
const int width = image.width(), height = image.height();
|
||||
|
@ -426,6 +319,10 @@ void generateNVTTMips(gpu::Texture* texture, QImage& image, bool validAlpha, boo
|
|||
} else {
|
||||
compressionFormat = nvtt::Format_BC3;
|
||||
}
|
||||
} else if (grayscale) {
|
||||
compressionFormat = nvtt::Format_BC4;
|
||||
} else if (normalMap) {
|
||||
compressionFormat = nvtt::Format_BC5;
|
||||
}
|
||||
float inputGamma = 2.2f;
|
||||
float outputGamma = 2.2f;
|
||||
|
@ -446,7 +343,7 @@ void generateNVTTMips(gpu::Texture* texture, QImage& image, bool validAlpha, boo
|
|||
|
||||
nvtt::OutputOptions outputOptions;
|
||||
outputOptions.setOutputHeader(false);
|
||||
MyOutputHandler outputHandler(texture, debugPtr);
|
||||
MyOutputHandler outputHandler(texture);
|
||||
outputOptions.setOutputHandler(&outputHandler);
|
||||
MyErrorHandler errorHandler;
|
||||
outputOptions.setErrorHandler(&errorHandler);
|
||||
|
@ -462,7 +359,7 @@ void generateNVTTMips(gpu::Texture* texture, QImage& image, bool validAlpha, boo
|
|||
#endif
|
||||
}
|
||||
|
||||
gpu::Texture* TextureUsage::process2DTextureColorFromImage(const QImage& srcImage, const std::string& srcImageName, bool isLinear, bool doCompress, bool generateMips, bool isStrict) {
|
||||
gpu::Texture* TextureUsage::process2DTextureColorFromImage(const QImage& srcImage, const std::string& srcImageName, bool isLinear, bool doGenerateMips, bool isStrict) {
|
||||
PROFILE_RANGE(resource_parse, "process2DTextureColorFromImage");
|
||||
bool validAlpha = false;
|
||||
bool alphaAsMask = true;
|
||||
|
@ -495,8 +392,8 @@ gpu::Texture* TextureUsage::process2DTextureColorFromImage(const QImage& srcImag
|
|||
theTexture->setUsage(usage.build());
|
||||
theTexture->setStoredMipFormat(formatMip);
|
||||
|
||||
if (generateMips) {
|
||||
generateNVTTMips(theTexture, image, validAlpha, alphaAsMask);
|
||||
if (doGenerateMips) {
|
||||
generateMips(theTexture, image, validAlpha, alphaAsMask, false, false);
|
||||
}
|
||||
theTexture->setSource(srcImageName);
|
||||
}
|
||||
|
@ -505,23 +402,23 @@ gpu::Texture* TextureUsage::process2DTextureColorFromImage(const QImage& srcImag
|
|||
}
|
||||
|
||||
gpu::Texture* TextureUsage::createStrict2DTextureFromImage(const QImage& srcImage, const std::string& srcImageName) {
|
||||
return process2DTextureColorFromImage(srcImage, srcImageName, false, false, true, true);
|
||||
return process2DTextureColorFromImage(srcImage, srcImageName, false, true, true);
|
||||
}
|
||||
|
||||
gpu::Texture* TextureUsage::create2DTextureFromImage(const QImage& srcImage, const std::string& srcImageName) {
|
||||
return process2DTextureColorFromImage(srcImage, srcImageName, false, false, true);
|
||||
return process2DTextureColorFromImage(srcImage, srcImageName, false, true);
|
||||
}
|
||||
|
||||
gpu::Texture* TextureUsage::createAlbedoTextureFromImage(const QImage& srcImage, const std::string& srcImageName) {
|
||||
return process2DTextureColorFromImage(srcImage, srcImageName, false, true, true);
|
||||
return process2DTextureColorFromImage(srcImage, srcImageName, false, true);
|
||||
}
|
||||
|
||||
gpu::Texture* TextureUsage::createEmissiveTextureFromImage(const QImage& srcImage, const std::string& srcImageName) {
|
||||
return process2DTextureColorFromImage(srcImage, srcImageName, false, true, true);
|
||||
return process2DTextureColorFromImage(srcImage, srcImageName, false, true);
|
||||
}
|
||||
|
||||
gpu::Texture* TextureUsage::createLightmapTextureFromImage(const QImage& srcImage, const std::string& srcImageName) {
|
||||
return process2DTextureColorFromImage(srcImage, srcImageName, false, true, true);
|
||||
return process2DTextureColorFromImage(srcImage, srcImageName, false, true);
|
||||
}
|
||||
|
||||
|
||||
|
@ -538,14 +435,13 @@ gpu::Texture* TextureUsage::createNormalTextureFromNormalImage(const QImage& src
|
|||
gpu::Texture* theTexture = nullptr;
|
||||
if ((image.width() > 0) && (image.height() > 0)) {
|
||||
|
||||
gpu::Element formatMip = gpu::Element::COLOR_BGRA_32;
|
||||
gpu::Element formatGPU = gpu::Element::COLOR_RGBA_32;
|
||||
gpu::Element formatMip = gpu::Element::COLOR_COMPRESSED_XY;
|
||||
gpu::Element 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);
|
||||
theTexture->setStoredMipFormat(formatMip);
|
||||
theTexture->assignStoredMip(0, image.byteCount(), image.constBits());
|
||||
generateMips(theTexture, image, true);
|
||||
generateMips(theTexture, image, false, false, false, true);
|
||||
|
||||
theTexture->setSource(srcImageName);
|
||||
}
|
||||
|
@ -627,15 +523,14 @@ gpu::Texture* TextureUsage::createNormalTextureFromBumpImage(const QImage& srcIm
|
|||
gpu::Texture* theTexture = nullptr;
|
||||
if ((result.width() > 0) && (result.height() > 0)) {
|
||||
|
||||
gpu::Element formatMip = gpu::Element::COLOR_BGRA_32;
|
||||
gpu::Element formatGPU = gpu::Element::COLOR_RGBA_32;
|
||||
gpu::Element formatMip = gpu::Element::COLOR_COMPRESSED_XY;
|
||||
gpu::Element formatGPU = gpu::Element::COLOR_COMPRESSED_XY;
|
||||
|
||||
|
||||
theTexture = (gpu::Texture::create2D(formatGPU, result.width(), result.height(), gpu::Texture::MAX_NUM_MIPS, gpu::Sampler(gpu::Sampler::FILTER_MIN_MAG_MIP_LINEAR)));
|
||||
theTexture->setSource(srcImageName);
|
||||
theTexture->setStoredMipFormat(formatMip);
|
||||
theTexture->assignStoredMip(0, result.byteCount(), result.constBits());
|
||||
generateMips(theTexture, result, true);
|
||||
generateMips(theTexture, image, false, false, false, true);
|
||||
|
||||
theTexture->setSource(srcImageName);
|
||||
}
|
||||
|
@ -656,22 +551,17 @@ gpu::Texture* TextureUsage::createRoughnessTextureFromImage(const QImage& srcIma
|
|||
}
|
||||
}
|
||||
|
||||
image = image.convertToFormat(QImage::Format_Grayscale8);
|
||||
image = image.convertToFormat(QImage::Format_ARGB32);
|
||||
|
||||
gpu::Texture* theTexture = nullptr;
|
||||
if ((image.width() > 0) && (image.height() > 0)) {
|
||||
#ifdef COMPRESS_TEXTURES
|
||||
gpu::Element formatGPU = gpu::Element(gpu::SCALAR, gpu::NUINT8, gpu::COMPRESSED_R);
|
||||
#else
|
||||
gpu::Element formatGPU = gpu::Element::COLOR_R_8;
|
||||
#endif
|
||||
gpu::Element formatMip = gpu::Element::COLOR_R_8;
|
||||
gpu::Element formatGPU = gpu::Element::COLOR_COMPRESSED_RED;
|
||||
gpu::Element formatMip = gpu::Element::COLOR_COMPRESSED_RED;
|
||||
|
||||
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);
|
||||
theTexture->setStoredMipFormat(formatMip);
|
||||
theTexture->assignStoredMip(0, image.byteCount(), image.constBits());
|
||||
generateMips(theTexture, image, true);
|
||||
generateMips(theTexture, image, false, false, true, false);
|
||||
|
||||
theTexture->setSource(srcImageName);
|
||||
}
|
||||
|
@ -695,23 +585,18 @@ gpu::Texture* TextureUsage::createRoughnessTextureFromGlossImage(const QImage& s
|
|||
// Gloss turned into Rough
|
||||
image.invertPixels(QImage::InvertRgba);
|
||||
|
||||
image = image.convertToFormat(QImage::Format_Grayscale8);
|
||||
image = image.convertToFormat(QImage::Format_ARGB32);
|
||||
|
||||
gpu::Texture* theTexture = nullptr;
|
||||
if ((image.width() > 0) && (image.height() > 0)) {
|
||||
|
||||
#ifdef COMPRESS_TEXTURES
|
||||
gpu::Element formatGPU = gpu::Element(gpu::SCALAR, gpu::NUINT8, gpu::COMPRESSED_R);
|
||||
#else
|
||||
gpu::Element formatGPU = gpu::Element::COLOR_R_8;
|
||||
#endif
|
||||
gpu::Element formatMip = gpu::Element::COLOR_R_8;
|
||||
gpu::Element formatGPU = gpu::Element::COLOR_COMPRESSED_RED;
|
||||
gpu::Element formatMip = gpu::Element::COLOR_COMPRESSED_RED;
|
||||
|
||||
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);
|
||||
theTexture->setStoredMipFormat(formatMip);
|
||||
theTexture->assignStoredMip(0, image.byteCount(), image.constBits());
|
||||
generateMips(theTexture, image, true);
|
||||
generateMips(theTexture, image, false, false, true, false);
|
||||
|
||||
theTexture->setSource(srcImageName);
|
||||
}
|
||||
|
@ -732,23 +617,18 @@ gpu::Texture* TextureUsage::createMetallicTextureFromImage(const QImage& srcImag
|
|||
}
|
||||
}
|
||||
|
||||
image = image.convertToFormat(QImage::Format_Grayscale8);
|
||||
image = image.convertToFormat(QImage::Format_ARGB32);
|
||||
|
||||
gpu::Texture* theTexture = nullptr;
|
||||
if ((image.width() > 0) && (image.height() > 0)) {
|
||||
|
||||
#ifdef COMPRESS_TEXTURES
|
||||
gpu::Element formatGPU = gpu::Element(gpu::SCALAR, gpu::NUINT8, gpu::COMPRESSED_R);
|
||||
#else
|
||||
gpu::Element formatGPU = gpu::Element::COLOR_R_8;
|
||||
#endif
|
||||
gpu::Element formatMip = gpu::Element::COLOR_R_8;
|
||||
gpu::Element formatGPU = gpu::Element::COLOR_COMPRESSED_RED;
|
||||
gpu::Element formatMip = gpu::Element::COLOR_COMPRESSED_RED;
|
||||
|
||||
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);
|
||||
theTexture->setStoredMipFormat(formatMip);
|
||||
theTexture->assignStoredMip(0, image.byteCount(), image.constBits());
|
||||
generateMips(theTexture, image, true);
|
||||
generateMips(theTexture, image, false, false, true, false);
|
||||
|
||||
theTexture->setSource(srcImageName);
|
||||
}
|
||||
|
@ -1012,7 +892,7 @@ const CubeLayout CubeLayout::CUBEMAP_LAYOUTS[] = {
|
|||
};
|
||||
const int CubeLayout::NUM_CUBEMAP_LAYOUTS = sizeof(CubeLayout::CUBEMAP_LAYOUTS) / sizeof(CubeLayout);
|
||||
|
||||
gpu::Texture* TextureUsage::processCubeTextureColorFromImage(const QImage& srcImage, const std::string& srcImageName, bool isLinear, bool doCompress, bool generateMips, bool generateIrradiance) {
|
||||
gpu::Texture* TextureUsage::processCubeTextureColorFromImage(const QImage& srcImage, const std::string& srcImageName, bool isLinear, bool generateMips, bool generateIrradiance) {
|
||||
PROFILE_RANGE(resource_parse, "processCubeTextureColorFromImage");
|
||||
|
||||
gpu::Texture* theTexture = nullptr;
|
||||
|
@ -1024,7 +904,7 @@ gpu::Texture* TextureUsage::processCubeTextureColorFromImage(const QImage& srcIm
|
|||
|
||||
gpu::Element formatGPU;
|
||||
gpu::Element formatMip;
|
||||
defineColorTexelFormats(formatGPU, formatMip, image, isLinear, doCompress);
|
||||
defineColorTexelFormats(formatGPU, formatMip, image, isLinear);
|
||||
|
||||
// Find the layout of the cubemap in the 2D image
|
||||
// Use the original image size since processSourceImage may have altered the size / aspect ratio
|
||||
|
@ -1086,11 +966,11 @@ gpu::Texture* TextureUsage::processCubeTextureColorFromImage(const QImage& srcIm
|
|||
}
|
||||
|
||||
gpu::Texture* TextureUsage::createCubeTextureFromImage(const QImage& srcImage, const std::string& srcImageName) {
|
||||
return processCubeTextureColorFromImage(srcImage, srcImageName, false, true, true, true);
|
||||
return processCubeTextureColorFromImage(srcImage, srcImageName, false, true, true);
|
||||
}
|
||||
|
||||
gpu::Texture* TextureUsage::createCubeTextureFromImageWithoutIrradiance(const QImage& srcImage, const std::string& srcImageName) {
|
||||
return processCubeTextureColorFromImage(srcImage, srcImageName, false, true, true, false);
|
||||
return processCubeTextureColorFromImage(srcImage, srcImageName, false, true, false);
|
||||
}
|
||||
|
||||
} // namespace image
|
|
@ -44,10 +44,9 @@ gpu::Texture* createCubeTextureFromImageWithoutIrradiance(const QImage& image, c
|
|||
gpu::Texture* createLightmapTextureFromImage(const QImage& image, const std::string& srcImageName);
|
||||
|
||||
const QImage process2DImageColor(const QImage& srcImage, bool& validAlpha, bool& alphaAsMask);
|
||||
void defineColorTexelFormats(gpu::Element& formatGPU, gpu::Element& formatMip,
|
||||
const QImage& srcImage, bool isLinear, bool doCompress);
|
||||
gpu::Texture* process2DTextureColorFromImage(const QImage& srcImage, const std::string& srcImageName, bool isLinear, bool doCompress, bool generateMips, bool isStrict = false);
|
||||
gpu::Texture* processCubeTextureColorFromImage(const QImage& srcImage, const std::string& srcImageName, bool isLinear, bool doCompress, bool generateMips, bool generateIrradiance);
|
||||
void defineColorTexelFormats(gpu::Element& formatGPU, gpu::Element& formatMip, const QImage& srcImage, bool isLinear);
|
||||
gpu::Texture* process2DTextureColorFromImage(const QImage& srcImage, const std::string& srcImageName, bool isLinear, bool generateMips, bool isStrict = false);
|
||||
gpu::Texture* processCubeTextureColorFromImage(const QImage& srcImage, const std::string& srcImageName, bool isLinear, bool generateMips, bool generateIrradiance);
|
||||
|
||||
} // namespace TextureUsage
|
||||
|
||||
|
|
Loading…
Reference in a new issue