mirror of
https://github.com/JulianGro/overte.git
synced 2025-04-08 11:02:24 +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
|
@ -146,7 +146,7 @@ void GL45Texture::copyMipFaceFromTexture(uint16_t sourceMip, uint16_t targetMip,
|
|||
GLTexelFormat texelFormat = GLTexelFormat::evalGLTexelFormat(_gpuObject.getTexelFormat(), _gpuObject.getStoredMipFormat());
|
||||
copyMipFaceLinesFromTexture(targetMip, face, size, 0, texelFormat.format, texelFormat.type, mipData->readData());
|
||||
} else {
|
||||
qCDebug(gpugllogging) << "Missing mipData level=" << sourceMip << " face=" << (int)face << " for texture " << _gpuObject.source().c_str();
|
||||
qCDebug(gpugllogging) << "Missing mipData level=" << sourceMip << " face=" << (int)face << " for texture " << _gpuObject.source().c_str();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
using namespace gpu;
|
||||
|
||||
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_SRGBA_32{ VEC4, NUINT8, SRGBA };
|
||||
|
|
|
@ -150,6 +150,7 @@ enum Semantic {
|
|||
STENCIL, // Stencil only buffer
|
||||
DEPTH_STENCIL, // Depth Stencil buffer
|
||||
|
||||
SRED,
|
||||
SRGB,
|
||||
SRGBA,
|
||||
SBGRA,
|
||||
|
@ -229,6 +230,7 @@ public:
|
|||
}
|
||||
|
||||
static const Element COLOR_R_8;
|
||||
static const Element COLOR_SR_8;
|
||||
static const Element COLOR_RGBA_32;
|
||||
static const Element COLOR_SRGBA_32;
|
||||
static const Element COLOR_BGRA_32;
|
||||
|
|
|
@ -77,8 +77,8 @@ KTX::KTX() {
|
|||
KTX::~KTX() {
|
||||
}
|
||||
|
||||
void KTX::resetStorage(Storage* storage) {
|
||||
_storage.reset(storage);
|
||||
void KTX::resetStorage(StoragePointer& storage) {
|
||||
_storage = storage;
|
||||
}
|
||||
|
||||
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) {
|
||||
glType = (uint32_t) type;
|
||||
// FIXME this should correspond to the size of glType
|
||||
glTypeSize = 1;
|
||||
glTypeSize = typeSize;
|
||||
glFormat = (uint32_t) format;
|
||||
glInternalFormat = (uint32_t) internalFormat;
|
||||
glBaseInternalFormat = (uint32_t) baseInternalFormat;
|
||||
|
@ -421,7 +420,7 @@ namespace ktx {
|
|||
using Images = std::vector<Image>;
|
||||
|
||||
class KTX {
|
||||
void resetStorage(Storage* src);
|
||||
void resetStorage(StoragePointer& src);
|
||||
|
||||
KTX();
|
||||
public:
|
||||
|
@ -449,7 +448,7 @@ namespace ktx {
|
|||
static Images writeImages(Byte* destBytes, size_t destByteSize, const Images& images);
|
||||
|
||||
// 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 Images parseImages(const Header& header, size_t srcSize, const Byte* srcBytes);
|
||||
|
|
|
@ -163,7 +163,7 @@ namespace ktx {
|
|||
return images;
|
||||
}
|
||||
|
||||
std::unique_ptr<KTX> KTX::create(std::unique_ptr<Storage>& src) {
|
||||
std::unique_ptr<KTX> KTX::create(StoragePointer& src) {
|
||||
if (!src) {
|
||||
return nullptr;
|
||||
}
|
||||
|
@ -173,7 +173,7 @@ namespace ktx {
|
|||
}
|
||||
|
||||
std::unique_ptr<KTX> result(new KTX());
|
||||
result->resetStorage(src.release());
|
||||
result->resetStorage(src);
|
||||
|
||||
// read metadata
|
||||
// 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<storage::Storage> storagePointer;
|
||||
StoragePointer storagePointer;
|
||||
{
|
||||
auto storageSize = ktx::KTX::evalStorageSize(header, images);
|
||||
auto memoryStorage = new storage::MemoryStorage(storageSize);
|
||||
|
|
|
@ -232,6 +232,10 @@ NetworkTexture::TextureLoaderFunc getTextureLoaderForType(NetworkTexture::Type t
|
|||
return model::TextureUsage::createMetallicTextureFromImage;
|
||||
break;
|
||||
}
|
||||
case Type::OCCLUSION_TEXTURE: {
|
||||
return model::TextureUsage::create2DTextureFromImage;
|
||||
break;
|
||||
}
|
||||
case Type::STRICT_TEXTURE: {
|
||||
return model::TextureUsage::createStrict2DTextureFromImage;
|
||||
break;
|
||||
|
|
|
@ -85,7 +85,7 @@ QImage processSourceImage(const QImage& srcImage, bool cubemap) {
|
|||
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) {
|
||||
return nullptr;
|
||||
}
|
||||
|
@ -132,8 +132,32 @@ gpu::Texture* cacheTexture(const std::string& name, gpu::Texture* srcTexture, bo
|
|||
}
|
||||
|
||||
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");
|
||||
QImage image = processSourceImage(srcImage, false);
|
||||
|
||||
// Make sure the normal map source image is RGBA32
|
||||
if (image.format() != QImage::Format_RGBA8888) {
|
||||
image = image.convertToFormat(QImage::Format_RGBA8888);
|
||||
// Make sure the normal map source image is ARGB32
|
||||
if (image.format() != QImage::Format_ARGB32) {
|
||||
image = image.convertToFormat(QImage::Format_ARGB32);
|
||||
}
|
||||
|
||||
|
||||
gpu::Texture* theTexture = nullptr;
|
||||
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;
|
||||
|
||||
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);
|
||||
|
||||
theTexture->setSource(srcImageName);
|
||||
theTexture = cacheTexture(theTexture->source(), theTexture, true, false);
|
||||
theTexture = cacheTexture(theTexture->source(), theTexture, true, true);
|
||||
}
|
||||
|
||||
return theTexture;
|
||||
|
|
|
@ -113,7 +113,7 @@ int main(int argc, char** argv) {
|
|||
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& fileStorage = ktxFile->getStorage();
|
||||
|
|
Loading…
Reference in a new issue