mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-06-22 21:00:02 +02:00
FIxing the bug preventing to deserialize normals, clean up the ktx usage of the storage::Storage class and cleaning up somewhat the Qt pixel formats used
This commit is contained in:
parent
bbded6aa51
commit
fbb0a24c4f
10 changed files with 50 additions and 19 deletions
|
@ -11,6 +11,7 @@
|
||||||
using namespace gpu;
|
using namespace gpu;
|
||||||
|
|
||||||
const Element Element::COLOR_R_8 { SCALAR, NUINT8, RED };
|
const Element Element::COLOR_R_8 { SCALAR, NUINT8, RED };
|
||||||
|
const Element Element::COLOR_SR_8 { SCALAR, NUINT8, SRED };
|
||||||
|
|
||||||
const Element Element::COLOR_RGBA_32{ VEC4, NUINT8, RGBA };
|
const Element Element::COLOR_RGBA_32{ VEC4, NUINT8, RGBA };
|
||||||
const Element Element::COLOR_SRGBA_32{ VEC4, NUINT8, SRGBA };
|
const Element Element::COLOR_SRGBA_32{ VEC4, NUINT8, SRGBA };
|
||||||
|
|
|
@ -150,6 +150,7 @@ enum Semantic {
|
||||||
STENCIL, // Stencil only buffer
|
STENCIL, // Stencil only buffer
|
||||||
DEPTH_STENCIL, // Depth Stencil buffer
|
DEPTH_STENCIL, // Depth Stencil buffer
|
||||||
|
|
||||||
|
SRED,
|
||||||
SRGB,
|
SRGB,
|
||||||
SRGBA,
|
SRGBA,
|
||||||
SBGRA,
|
SBGRA,
|
||||||
|
@ -229,6 +230,7 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
static const Element COLOR_R_8;
|
static const Element COLOR_R_8;
|
||||||
|
static const Element COLOR_SR_8;
|
||||||
static const Element COLOR_RGBA_32;
|
static const Element COLOR_RGBA_32;
|
||||||
static const Element COLOR_SRGBA_32;
|
static const Element COLOR_SRGBA_32;
|
||||||
static const Element COLOR_BGRA_32;
|
static const Element COLOR_BGRA_32;
|
||||||
|
|
|
@ -77,8 +77,8 @@ KTX::KTX() {
|
||||||
KTX::~KTX() {
|
KTX::~KTX() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void KTX::resetStorage(Storage* storage) {
|
void KTX::resetStorage(StoragePointer& storage) {
|
||||||
_storage.reset(storage);
|
_storage = storage;
|
||||||
}
|
}
|
||||||
|
|
||||||
const Header* KTX::getHeader() const {
|
const Header* KTX::getHeader() const {
|
||||||
|
|
|
@ -345,8 +345,7 @@ namespace ktx {
|
||||||
|
|
||||||
void setUncompressed(GLType type, uint32_t typeSize, GLFormat format, GLInternalFormat_Uncompressed internalFormat, GLBaseInternalFormat baseInternalFormat) {
|
void setUncompressed(GLType type, uint32_t typeSize, GLFormat format, GLInternalFormat_Uncompressed internalFormat, GLBaseInternalFormat baseInternalFormat) {
|
||||||
glType = (uint32_t) type;
|
glType = (uint32_t) type;
|
||||||
// FIXME this should correspond to the size of glType
|
glTypeSize = typeSize;
|
||||||
glTypeSize = 1;
|
|
||||||
glFormat = (uint32_t) format;
|
glFormat = (uint32_t) format;
|
||||||
glInternalFormat = (uint32_t) internalFormat;
|
glInternalFormat = (uint32_t) internalFormat;
|
||||||
glBaseInternalFormat = (uint32_t) baseInternalFormat;
|
glBaseInternalFormat = (uint32_t) baseInternalFormat;
|
||||||
|
@ -421,7 +420,7 @@ namespace ktx {
|
||||||
using Images = std::vector<Image>;
|
using Images = std::vector<Image>;
|
||||||
|
|
||||||
class KTX {
|
class KTX {
|
||||||
void resetStorage(Storage* src);
|
void resetStorage(StoragePointer& src);
|
||||||
|
|
||||||
KTX();
|
KTX();
|
||||||
public:
|
public:
|
||||||
|
@ -449,7 +448,7 @@ namespace ktx {
|
||||||
static Images writeImages(Byte* destBytes, size_t destByteSize, const Images& images);
|
static Images writeImages(Byte* destBytes, size_t destByteSize, const Images& images);
|
||||||
|
|
||||||
// Parse a block of memory and create a KTX object from it
|
// Parse a block of memory and create a KTX object from it
|
||||||
static std::unique_ptr<KTX> create(std::unique_ptr<Storage>& src);
|
static std::unique_ptr<KTX> create(StoragePointer& src);
|
||||||
|
|
||||||
static bool checkHeaderFromStorage(size_t srcSize, const Byte* srcBytes);
|
static bool checkHeaderFromStorage(size_t srcSize, const Byte* srcBytes);
|
||||||
static Images parseImages(const Header& header, size_t srcSize, const Byte* srcBytes);
|
static Images parseImages(const Header& header, size_t srcSize, const Byte* srcBytes);
|
||||||
|
|
|
@ -163,7 +163,7 @@ namespace ktx {
|
||||||
return images;
|
return images;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::unique_ptr<KTX> KTX::create(std::unique_ptr<Storage>& src) {
|
std::unique_ptr<KTX> KTX::create(StoragePointer& src) {
|
||||||
if (!src) {
|
if (!src) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
@ -173,7 +173,7 @@ namespace ktx {
|
||||||
}
|
}
|
||||||
|
|
||||||
std::unique_ptr<KTX> result(new KTX());
|
std::unique_ptr<KTX> result(new KTX());
|
||||||
result->resetStorage(src.release());
|
result->resetStorage(src);
|
||||||
|
|
||||||
// read metadata
|
// read metadata
|
||||||
// result->_keyValues = getKeyValues(result->getHeader()->bytesOfKeyValueData, result->getKeyValueData());
|
// result->_keyValues = getKeyValues(result->getHeader()->bytesOfKeyValueData, result->getKeyValueData());
|
||||||
|
|
|
@ -27,7 +27,7 @@ namespace ktx {
|
||||||
};
|
};
|
||||||
|
|
||||||
std::unique_ptr<KTX> KTX::create(const Header& header, const Images& images, const KeyValues& keyValues) {
|
std::unique_ptr<KTX> KTX::create(const Header& header, const Images& images, const KeyValues& keyValues) {
|
||||||
std::unique_ptr<storage::Storage> storagePointer;
|
StoragePointer storagePointer;
|
||||||
{
|
{
|
||||||
auto storageSize = ktx::KTX::evalStorageSize(header, images);
|
auto storageSize = ktx::KTX::evalStorageSize(header, images);
|
||||||
auto memoryStorage = new storage::MemoryStorage(storageSize);
|
auto memoryStorage = new storage::MemoryStorage(storageSize);
|
||||||
|
|
|
@ -232,6 +232,10 @@ NetworkTexture::TextureLoaderFunc getTextureLoaderForType(NetworkTexture::Type t
|
||||||
return model::TextureUsage::createMetallicTextureFromImage;
|
return model::TextureUsage::createMetallicTextureFromImage;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case Type::OCCLUSION_TEXTURE: {
|
||||||
|
return model::TextureUsage::create2DTextureFromImage;
|
||||||
|
break;
|
||||||
|
}
|
||||||
case Type::STRICT_TEXTURE: {
|
case Type::STRICT_TEXTURE: {
|
||||||
return model::TextureUsage::createStrict2DTextureFromImage;
|
return model::TextureUsage::createStrict2DTextureFromImage;
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -85,7 +85,7 @@ QImage processSourceImage(const QImage& srcImage, bool cubemap) {
|
||||||
return srcImage;
|
return srcImage;
|
||||||
}
|
}
|
||||||
|
|
||||||
gpu::Texture* cacheTexture(const std::string& name, gpu::Texture* srcTexture, bool write = true, bool read = false) { // FIXME: set read to false for a working state
|
gpu::Texture* cacheTexture(const std::string& name, gpu::Texture* srcTexture, bool write = true, bool read = true) {
|
||||||
if (!srcTexture) {
|
if (!srcTexture) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
@ -132,8 +132,32 @@ gpu::Texture* cacheTexture(const std::string& name, gpu::Texture* srcTexture, bo
|
||||||
}
|
}
|
||||||
|
|
||||||
if (read && QFileInfo(cacheFilename.c_str()).exists()) {
|
if (read && QFileInfo(cacheFilename.c_str()).exists()) {
|
||||||
auto ktxFile = ktx::KTX::create(std::unique_ptr<storage::Storage>(new storage::FileStorage(cacheFilename.c_str())));
|
{
|
||||||
returnedTexture->setKtxBacking(ktxFile);
|
FILE* file = fopen(cacheFilename.c_str(), "rb");
|
||||||
|
if (file != nullptr) {
|
||||||
|
// obtain file size:
|
||||||
|
fseek (file , 0 , SEEK_END);
|
||||||
|
auto size = ftell(file);
|
||||||
|
rewind(file);
|
||||||
|
|
||||||
|
auto storage = std::make_shared<storage::MemoryStorage>(size);
|
||||||
|
fread(storage->data(), 1, storage->size(), file);
|
||||||
|
fclose (file);
|
||||||
|
|
||||||
|
//then create a new texture out of the ktx
|
||||||
|
auto theNewTexure = Texture::unserialize(srcTexture->getUsage(), srcTexture->getUsageType(),
|
||||||
|
ktx::KTX::create(std::static_pointer_cast<storage::Storage>(storage)), srcTexture->getSampler());
|
||||||
|
|
||||||
|
if (theNewTexure) {
|
||||||
|
returnedTexture = theNewTexure;
|
||||||
|
delete srcTexture;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// auto ktxFile = ktx::KTX::create(std::unique_ptr<storage::Storage>(new storage::FileStorage(cacheFilename.c_str())));
|
||||||
|
// returnedTexture->setKtxBacking(ktxFile);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -360,15 +384,16 @@ gpu::Texture* TextureUsage::createNormalTextureFromNormalImage(const QImage& src
|
||||||
PROFILE_RANGE(resource_parse, "createNormalTextureFromNormalImage");
|
PROFILE_RANGE(resource_parse, "createNormalTextureFromNormalImage");
|
||||||
QImage image = processSourceImage(srcImage, false);
|
QImage image = processSourceImage(srcImage, false);
|
||||||
|
|
||||||
// Make sure the normal map source image is RGBA32
|
// Make sure the normal map source image is ARGB32
|
||||||
if (image.format() != QImage::Format_RGBA8888) {
|
if (image.format() != QImage::Format_ARGB32) {
|
||||||
image = image.convertToFormat(QImage::Format_RGBA8888);
|
image = image.convertToFormat(QImage::Format_ARGB32);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
gpu::Texture* theTexture = nullptr;
|
gpu::Texture* theTexture = nullptr;
|
||||||
if ((image.width() > 0) && (image.height() > 0)) {
|
if ((image.width() > 0) && (image.height() > 0)) {
|
||||||
|
|
||||||
gpu::Element formatMip = gpu::Element::COLOR_RGBA_32;
|
gpu::Element formatMip = gpu::Element::COLOR_BGRA_32;
|
||||||
gpu::Element formatGPU = gpu::Element::COLOR_RGBA_32;
|
gpu::Element formatGPU = gpu::Element::COLOR_RGBA_32;
|
||||||
|
|
||||||
theTexture = (gpu::Texture::create2D(formatGPU, image.width(), image.height(), gpu::Sampler(gpu::Sampler::FILTER_MIN_MAG_MIP_LINEAR)));
|
theTexture = (gpu::Texture::create2D(formatGPU, image.width(), image.height(), gpu::Sampler(gpu::Sampler::FILTER_MIN_MAG_MIP_LINEAR)));
|
||||||
|
@ -378,7 +403,7 @@ gpu::Texture* TextureUsage::createNormalTextureFromNormalImage(const QImage& src
|
||||||
generateMips(theTexture, image, true);
|
generateMips(theTexture, image, true);
|
||||||
|
|
||||||
theTexture->setSource(srcImageName);
|
theTexture->setSource(srcImageName);
|
||||||
theTexture = cacheTexture(theTexture->source(), theTexture, true, false);
|
theTexture = cacheTexture(theTexture->source(), theTexture, true, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
return theTexture;
|
return theTexture;
|
||||||
|
|
|
@ -113,7 +113,7 @@ int main(int argc, char** argv) {
|
||||||
outFile.close();
|
outFile.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
auto ktxFile = ktx::KTX::create(std::unique_ptr<storage::Storage>(new storage::FileStorage(TEST_IMAGE_KTX)));
|
auto ktxFile = ktx::KTX::create(std::shared_ptr<storage::Storage>(new storage::FileStorage(TEST_IMAGE_KTX)));
|
||||||
{
|
{
|
||||||
const auto& memStorage = ktxMemory->getStorage();
|
const auto& memStorage = ktxMemory->getStorage();
|
||||||
const auto& fileStorage = ktxFile->getStorage();
|
const auto& fileStorage = ktxFile->getStorage();
|
||||||
|
|
Loading…
Reference in a new issue