mirror of
https://github.com/overte-org/overte.git
synced 2025-08-09 15:29:32 +02:00
KTX serialization / unserialization working with compressed HDR. Not sure with packed floats
This commit is contained in:
parent
f4579d44bc
commit
98820f720d
3 changed files with 35 additions and 26 deletions
|
@ -319,7 +319,7 @@ void RenderableModelEntityItem::computeShapeInfo(ShapeInfo& shapeInfo) {
|
||||||
|
|
||||||
// should never fall in here when collision model not fully loaded
|
// should never fall in here when collision model not fully loaded
|
||||||
// hence we assert that all geometries exist and are loaded
|
// hence we assert that all geometries exist and are loaded
|
||||||
assert(_model && _model->isLoaded() && _compoundShapeResource && _compoundShapeResource->isLoaded());
|
assert(model && model->isLoaded() && _compoundShapeResource && _compoundShapeResource->isLoaded());
|
||||||
const FBXGeometry& collisionGeometry = _compoundShapeResource->getFBXGeometry();
|
const FBXGeometry& collisionGeometry = _compoundShapeResource->getFBXGeometry();
|
||||||
|
|
||||||
ShapeInfo::PointCollection& pointCollection = shapeInfo.getPointCollection();
|
ShapeInfo::PointCollection& pointCollection = shapeInfo.getPointCollection();
|
||||||
|
@ -408,7 +408,7 @@ void RenderableModelEntityItem::computeShapeInfo(ShapeInfo& shapeInfo) {
|
||||||
shapeInfo.setParams(type, dimensions, getCompoundShapeURL());
|
shapeInfo.setParams(type, dimensions, getCompoundShapeURL());
|
||||||
} else if (type >= SHAPE_TYPE_SIMPLE_HULL && type <= SHAPE_TYPE_STATIC_MESH) {
|
} else if (type >= SHAPE_TYPE_SIMPLE_HULL && type <= SHAPE_TYPE_STATIC_MESH) {
|
||||||
// should never fall in here when model not fully loaded
|
// should never fall in here when model not fully loaded
|
||||||
assert(_model && _model->isLoaded());
|
assert(model && model->isLoaded());
|
||||||
|
|
||||||
updateModelBounds();
|
updateModelBounds();
|
||||||
model->updateGeometry();
|
model->updateGeometry();
|
||||||
|
|
|
@ -518,17 +518,17 @@ TexturePointer Texture::build(const ktx::KTXDescriptor& descriptor) {
|
||||||
|
|
||||||
|
|
||||||
TexturePointer Texture::unserialize(const cache::FilePointer& cacheEntry) {
|
TexturePointer Texture::unserialize(const cache::FilePointer& cacheEntry) {
|
||||||
std::unique_ptr<ktx::KTX> ktxPointer = ktx::KTX::create(std::make_shared<storage::FileStorage>(cacheEntry->getFilepath().c_str()));
|
std::unique_ptr<ktx::KTX> ktxPointer = ktx::KTX::create(std::make_shared<storage::FileStorage>(cacheEntry->getFilepath().c_str()));
|
||||||
if (!ktxPointer) {
|
if (!ktxPointer) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto texture = build(ktxPointer->toDescriptor());
|
auto texture = build(ktxPointer->toDescriptor());
|
||||||
if (texture) {
|
if (texture) {
|
||||||
texture->setKtxBacking(cacheEntry);
|
texture->setKtxBacking(cacheEntry);
|
||||||
}
|
}
|
||||||
|
|
||||||
return texture;
|
return texture;
|
||||||
}
|
}
|
||||||
|
|
||||||
TexturePointer Texture::unserialize(const std::string& ktxfile) {
|
TexturePointer Texture::unserialize(const std::string& ktxfile) {
|
||||||
|
@ -536,7 +536,7 @@ TexturePointer Texture::unserialize(const std::string& ktxfile) {
|
||||||
if (!ktxPointer) {
|
if (!ktxPointer) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto texture = build(ktxPointer->toDescriptor());
|
auto texture = build(ktxPointer->toDescriptor());
|
||||||
if (texture) {
|
if (texture) {
|
||||||
texture->setKtxBacking(ktxfile);
|
texture->setKtxBacking(ktxfile);
|
||||||
|
@ -618,6 +618,12 @@ bool Texture::evalTextureFormat(const ktx::Header& header, Element& mipFormat, E
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
} else if (header.getGLFormat() == ktx::GLFormat::RGB && header.getGLType() == ktx::GLType::UNSIGNED_INT_10F_11F_11F_REV) {
|
||||||
|
mipFormat = Format::COLOR_R11G11B10;
|
||||||
|
texelFormat = Format::COLOR_R11G11B10;
|
||||||
|
} else if (header.getGLFormat() == ktx::GLFormat::RGB && header.getGLType() == ktx::GLType::UNSIGNED_INT_5_9_9_9_REV) {
|
||||||
|
mipFormat = Format::COLOR_RGB9E5;
|
||||||
|
texelFormat = Format::COLOR_RGB9E5;
|
||||||
} else if (header.isCompressed()) {
|
} else if (header.isCompressed()) {
|
||||||
if (header.getGLInternaFormat() == ktx::GLInternalFormat::COMPRESSED_SRGB_S3TC_DXT1_EXT) {
|
if (header.getGLInternaFormat() == ktx::GLInternalFormat::COMPRESSED_SRGB_S3TC_DXT1_EXT) {
|
||||||
mipFormat = Format::COLOR_COMPRESSED_SRGB;
|
mipFormat = Format::COLOR_COMPRESSED_SRGB;
|
||||||
|
@ -640,12 +646,6 @@ bool Texture::evalTextureFormat(const ktx::Header& header, Element& mipFormat, E
|
||||||
} else if (header.getGLInternaFormat() == ktx::GLInternalFormat::COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT) {
|
} else if (header.getGLInternaFormat() == ktx::GLInternalFormat::COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT) {
|
||||||
mipFormat = Format::COLOR_COMPRESSED_HDR_RGB;
|
mipFormat = Format::COLOR_COMPRESSED_HDR_RGB;
|
||||||
texelFormat = Format::COLOR_COMPRESSED_HDR_RGB;
|
texelFormat = Format::COLOR_COMPRESSED_HDR_RGB;
|
||||||
} else if (header.getGLInternaFormat() == ktx::GLInternalFormat::RGB9_E5) {
|
|
||||||
mipFormat = Format::COLOR_RGB9E5;
|
|
||||||
texelFormat = Format::COLOR_RGB9E5;
|
|
||||||
} else if (header.getGLInternaFormat() == ktx::GLInternalFormat::R11F_G11F_B10F) {
|
|
||||||
mipFormat = Format::COLOR_R11G11B10;
|
|
||||||
texelFormat = Format::COLOR_R11G11B10;
|
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,6 +43,8 @@ bool DEV_DECIMATE_TEXTURES = false;
|
||||||
std::atomic<size_t> DECIMATED_TEXTURE_COUNT{ 0 };
|
std::atomic<size_t> DECIMATED_TEXTURE_COUNT{ 0 };
|
||||||
std::atomic<size_t> RECTIFIED_TEXTURE_COUNT{ 0 };
|
std::atomic<size_t> RECTIFIED_TEXTURE_COUNT{ 0 };
|
||||||
|
|
||||||
|
static const auto HDR_FORMAT = gpu::Element::COLOR_R11G11B10;
|
||||||
|
|
||||||
bool needsSparseRectification(const glm::uvec2& size) {
|
bool needsSparseRectification(const glm::uvec2& size) {
|
||||||
// Don't attempt to rectify small textures (textures less than the sparse page size in any dimension)
|
// Don't attempt to rectify small textures (textures less than the sparse page size in any dimension)
|
||||||
if (glm::any(glm::lessThan(size, SPARSE_PAGE_SIZE))) {
|
if (glm::any(glm::lessThan(size, SPARSE_PAGE_SIZE))) {
|
||||||
|
@ -423,18 +425,26 @@ void generateHDRMips(gpu::Texture* texture, const QImage& image, int face) {
|
||||||
compressionOptions.setFormat(nvtt::Format_RGB);
|
compressionOptions.setFormat(nvtt::Format_RGB);
|
||||||
compressionOptions.setPixelType(nvtt::PixelType_Float);
|
compressionOptions.setPixelType(nvtt::PixelType_Float);
|
||||||
compressionOptions.setPixelFormat(32, 32, 32, 0);
|
compressionOptions.setPixelFormat(32, 32, 32, 0);
|
||||||
unpackFunc = glm::unpackF3x9_E1x5;
|
|
||||||
} else if (mipFormat == gpu::Element::COLOR_R11G11B10) {
|
} else if (mipFormat == gpu::Element::COLOR_R11G11B10) {
|
||||||
compressionOptions.setFormat(nvtt::Format_RGB);
|
compressionOptions.setFormat(nvtt::Format_RGB);
|
||||||
compressionOptions.setPixelType(nvtt::PixelType_Float);
|
compressionOptions.setPixelType(nvtt::PixelType_Float);
|
||||||
compressionOptions.setPixelFormat(32, 32, 32, 0);
|
compressionOptions.setPixelFormat(32, 32, 32, 0);
|
||||||
unpackFunc = glm::unpackF2x11_1x10;
|
|
||||||
} else {
|
} else {
|
||||||
qCWarning(imagelogging) << "Unknown mip format";
|
qCWarning(imagelogging) << "Unknown mip format";
|
||||||
Q_UNREACHABLE();
|
Q_UNREACHABLE();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (HDR_FORMAT == gpu::Element::COLOR_RGB9E5) {
|
||||||
|
unpackFunc = glm::unpackF3x9_E1x5;
|
||||||
|
} else if (HDR_FORMAT == gpu::Element::COLOR_R11G11B10) {
|
||||||
|
unpackFunc = glm::unpackF2x11_1x10;
|
||||||
|
} else {
|
||||||
|
qCWarning(imagelogging) << "Unknown HDR encoding format in QImage";
|
||||||
|
Q_UNREACHABLE();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
data.resize(width*height);
|
data.resize(width*height);
|
||||||
dataIt = data.begin();
|
dataIt = data.begin();
|
||||||
for (auto lineNb = 0; lineNb < height; lineNb++) {
|
for (auto lineNb = 0; lineNb < height; lineNb++) {
|
||||||
|
@ -1144,19 +1154,18 @@ gpu::TexturePointer TextureUsage::processCubeTextureColorFromImage(const QImage&
|
||||||
if ((srcImage.width() > 0) && (srcImage.height() > 0)) {
|
if ((srcImage.width() > 0) && (srcImage.height() > 0)) {
|
||||||
QImage image = processSourceImage(srcImage, true);
|
QImage image = processSourceImage(srcImage, true);
|
||||||
|
|
||||||
const auto cubeMapHDRFormat = gpu::Element::COLOR_R11G11B10;
|
|
||||||
gpu::Element formatMip;
|
gpu::Element formatMip;
|
||||||
gpu::Element formatGPU;
|
gpu::Element formatGPU;
|
||||||
if (isCubeTexturesCompressionEnabled()) {
|
if (isCubeTexturesCompressionEnabled()) {
|
||||||
formatMip = gpu::Element::COLOR_COMPRESSED_HDR_RGB;
|
formatMip = gpu::Element::COLOR_COMPRESSED_HDR_RGB;
|
||||||
formatGPU = gpu::Element::COLOR_COMPRESSED_HDR_RGB;
|
formatGPU = gpu::Element::COLOR_COMPRESSED_HDR_RGB;
|
||||||
} else {
|
} else {
|
||||||
formatMip = cubeMapHDRFormat;
|
formatMip = HDR_FORMAT;
|
||||||
formatGPU = cubeMapHDRFormat;
|
formatGPU = HDR_FORMAT;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (image.format() != QIMAGE_HDR_FORMAT) {
|
if (image.format() != QIMAGE_HDR_FORMAT) {
|
||||||
image = convertToHDRFormat(image, cubeMapHDRFormat);
|
image = convertToHDRFormat(image, HDR_FORMAT);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Find the layout of the cubemap in the 2D image
|
// Find the layout of the cubemap in the 2D image
|
||||||
|
@ -1204,9 +1213,9 @@ gpu::TexturePointer TextureUsage::processCubeTextureColorFromImage(const QImage&
|
||||||
// Generate irradiance while we are at it
|
// Generate irradiance while we are at it
|
||||||
if (generateIrradiance) {
|
if (generateIrradiance) {
|
||||||
PROFILE_RANGE(resource_parse, "generateIrradiance");
|
PROFILE_RANGE(resource_parse, "generateIrradiance");
|
||||||
auto irradianceTexture = gpu::Texture::createCube(cubeMapHDRFormat, faces[0].width(), gpu::Texture::MAX_NUM_MIPS, gpu::Sampler(gpu::Sampler::FILTER_MIN_MAG_MIP_LINEAR, gpu::Sampler::WRAP_CLAMP));
|
auto irradianceTexture = gpu::Texture::createCube(HDR_FORMAT, faces[0].width(), gpu::Texture::MAX_NUM_MIPS, gpu::Sampler(gpu::Sampler::FILTER_MIN_MAG_MIP_LINEAR, gpu::Sampler::WRAP_CLAMP));
|
||||||
irradianceTexture->setSource(srcImageName);
|
irradianceTexture->setSource(srcImageName);
|
||||||
irradianceTexture->setStoredMipFormat(cubeMapHDRFormat);
|
irradianceTexture->setStoredMipFormat(HDR_FORMAT);
|
||||||
for (uint8 face = 0; face < faces.size(); ++face) {
|
for (uint8 face = 0; face < faces.size(); ++face) {
|
||||||
irradianceTexture->assignStoredMipFace(0, face, faces[face].byteCount(), faces[face].constBits());
|
irradianceTexture->assignStoredMipFace(0, face, faces[face].byteCount(), faces[face].constBits());
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue