mirror of
https://github.com/overte-org/overte.git
synced 2025-04-25 06:54:11 +02:00
Switching texture backing to opaque storage type
This commit is contained in:
parent
eafe0a04d5
commit
61ce66a039
3 changed files with 20 additions and 56 deletions
|
@ -122,36 +122,12 @@ uint8 Texture::NUM_FACES_PER_TYPE[NUM_TYPES] = { 1, 1, 1, 6 };
|
|||
|
||||
Texture::Pixels::Pixels(const Element& format, Size size, const Byte* bytes) :
|
||||
_format(format),
|
||||
_sysmem(size, bytes),
|
||||
_isGPULoaded(false) {
|
||||
Texture::updateTextureCPUMemoryUsage(0, _sysmem.getSize());
|
||||
_storage(new storage::MemoryStorage(size, bytes)) {
|
||||
Texture::updateTextureCPUMemoryUsage(0, _storage->size());
|
||||
}
|
||||
|
||||
Texture::Pixels::~Pixels() {
|
||||
Texture::updateTextureCPUMemoryUsage(_sysmem.getSize(), 0);
|
||||
}
|
||||
|
||||
Texture::Size Texture::Pixels::resize(Size pSize) {
|
||||
auto prevSize = _sysmem.getSize();
|
||||
auto newSize = _sysmem.resize(pSize);
|
||||
Texture::updateTextureCPUMemoryUsage(prevSize, newSize);
|
||||
return newSize;
|
||||
}
|
||||
|
||||
Texture::Size Texture::Pixels::setData(const Element& format, Size size, const Byte* bytes ) {
|
||||
_format = format;
|
||||
auto prevSize = _sysmem.getSize();
|
||||
auto newSize = _sysmem.setData(size, bytes);
|
||||
Texture::updateTextureCPUMemoryUsage(prevSize, newSize);
|
||||
_isGPULoaded = false;
|
||||
return newSize;
|
||||
}
|
||||
|
||||
void Texture::Pixels::notifyGPULoaded() {
|
||||
_isGPULoaded = true;
|
||||
auto prevSize = _sysmem.getSize();
|
||||
auto newSize = _sysmem.resize(0);
|
||||
Texture::updateTextureCPUMemoryUsage(prevSize, newSize);
|
||||
Texture::updateTextureCPUMemoryUsage(_storage->size(), 0);
|
||||
}
|
||||
|
||||
void Texture::Storage::assignTexture(Texture* texture) {
|
||||
|
@ -183,14 +159,6 @@ const Texture::PixelsPointer Texture::Storage::getMipFace(uint16 level, uint8 fa
|
|||
return PixelsPointer();
|
||||
}
|
||||
|
||||
void Texture::Storage::notifyMipFaceGPULoaded(uint16 level, uint8 face) const {
|
||||
PixelsPointer mipFace = getMipFace(level, face);
|
||||
// Free the mips
|
||||
if (mipFace) {
|
||||
mipFace->notifyGPULoaded();
|
||||
}
|
||||
}
|
||||
|
||||
bool Texture::Storage::isMipAvailable(uint16 level, uint8 face) const {
|
||||
PixelsPointer mipFace = getMipFace(level, face);
|
||||
return (mipFace && mipFace->getSize());
|
||||
|
@ -229,7 +197,8 @@ bool Texture::Storage::assignMipData(uint16 level, const Element& format, Size s
|
|||
auto faceBytes = bytes;
|
||||
Size allocated = 0;
|
||||
for (auto& face : mip) {
|
||||
allocated += face->setData(format, sizePerFace, faceBytes);
|
||||
face.reset(new Pixels(format, size, bytes));
|
||||
allocated += size;
|
||||
faceBytes += sizePerFace;
|
||||
}
|
||||
|
||||
|
@ -242,11 +211,11 @@ bool Texture::Storage::assignMipData(uint16 level, const Element& format, Size s
|
|||
bool Texture::Storage::assignMipFaceData(uint16 level, const Element& format, Size size, const Byte* bytes, uint8 face) {
|
||||
|
||||
allocateMip(level);
|
||||
auto mip = _mips[level];
|
||||
auto& mip = _mips[level];
|
||||
Size allocated = 0;
|
||||
if (face < mip.size()) {
|
||||
auto mipFace = mip[face];
|
||||
allocated += mipFace->setData(format, size, bytes);
|
||||
mip[face].reset(new Pixels(format, size, bytes));
|
||||
allocated += size;
|
||||
bumpStamp();
|
||||
}
|
||||
|
||||
|
|
|
@ -17,6 +17,8 @@
|
|||
#include <QMetaType>
|
||||
#include <QUrl>
|
||||
|
||||
#include <shared/Storage.h>
|
||||
|
||||
#include "Forward.h"
|
||||
#include "Resource.h"
|
||||
|
||||
|
@ -224,26 +226,26 @@ public:
|
|||
bool operator!=(const Usage& usage) { return (_flags != usage._flags); }
|
||||
};
|
||||
|
||||
|
||||
class Pixels {
|
||||
public:
|
||||
using StoragePointer = storage::StoragePointer;
|
||||
|
||||
Pixels() {}
|
||||
Pixels(const Pixels& pixels) = default;
|
||||
Pixels(const Element& format, Size size, const Byte* bytes);
|
||||
Pixels(const Element& format, StoragePointer& storage) : _format(format), _storage(storage.release()) {}
|
||||
~Pixels();
|
||||
|
||||
const Byte* readData() const { return _sysmem.readData(); }
|
||||
Size getSize() const { return _sysmem.getSize(); }
|
||||
Size resize(Size pSize);
|
||||
Size setData(const Element& format, Size size, const Byte* bytes );
|
||||
const Byte* readData() const { return _storage->data(); }
|
||||
Size getSize() const { return _storage->size(); }
|
||||
|
||||
const Element& getFormat() const { return _format; }
|
||||
|
||||
void notifyGPULoaded();
|
||||
|
||||
|
||||
|
||||
protected:
|
||||
Element _format;
|
||||
Sysmem _sysmem;
|
||||
bool _isGPULoaded;
|
||||
StoragePointer _storage;
|
||||
|
||||
friend class Texture;
|
||||
};
|
||||
|
@ -296,10 +298,6 @@ public:
|
|||
const Texture* getTexture() const { return _texture; }
|
||||
|
||||
friend class Texture;
|
||||
|
||||
// THis should be only called by the Texture from the Backend to notify the storage that the specified mip face pixels
|
||||
// have been uploaded to the GPU memory. IT is possible for the storage to free the system memory then
|
||||
virtual void notifyMipFaceGPULoaded(uint16 level, uint8 face) const;
|
||||
};
|
||||
|
||||
|
||||
|
@ -481,9 +479,6 @@ public:
|
|||
const Sampler& getSampler() const { return _sampler; }
|
||||
Stamp getSamplerStamp() const { return _samplerStamp; }
|
||||
|
||||
// Only callable by the Backend
|
||||
void notifyMipFaceGPULoaded(uint16 level, uint8 face = 0) const { return _storage->notifyMipFaceGPULoaded(level, face); }
|
||||
|
||||
void setExternalTexture(uint32 externalId, void* externalFence);
|
||||
void setExternalRecycler(const ExternalRecycler& recycler);
|
||||
ExternalRecycler getExternalRecycler() const;
|
||||
|
|
|
@ -72,7 +72,7 @@ ktx::KTXUniquePointer Texture::serialize(const Texture& texture) {
|
|||
for (uint32_t level = 0; level < header.numberOfMipmapLevels; level++) {
|
||||
auto mip = texture.accessStoredMipFace(level);
|
||||
if (mip) {
|
||||
images.emplace_back(ktx::Image(mip->getSize(), 0, mip->readData()));
|
||||
images.emplace_back(ktx::Image((uint32_t)mip->getSize(), 0, mip->readData()));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue