mirror of
https://github.com/overte-org/overte.git
synced 2025-04-14 07:27:04 +02:00
Add a way to write data to a storage object
This commit is contained in:
parent
ccd9c4697b
commit
b20fcbfcdb
11 changed files with 47 additions and 6 deletions
|
@ -259,7 +259,9 @@ void GLBackend::do_setResourceTexture(const Batch& batch, size_t paramOffset) {
|
||||||
glActiveTexture(GL_TEXTURE0 + slot);
|
glActiveTexture(GL_TEXTURE0 + slot);
|
||||||
glBindTexture(target, to);
|
glBindTexture(target, to);
|
||||||
|
|
||||||
(void) CHECK_GL_ERROR();
|
if (CHECK_GL_ERROR()) {
|
||||||
|
qDebug() << "slot: " << slot << ", target: " << target << ", to: " << to;
|
||||||
|
}
|
||||||
|
|
||||||
_resource._textures[slot] = resourceTexture;
|
_resource._textures[slot] = resourceTexture;
|
||||||
|
|
||||||
|
|
|
@ -411,6 +411,7 @@ const Element& Texture::getStoredMipFormat() const {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Texture::assignStoredMip(uint16 level, Size size, const Byte* bytes) {
|
void Texture::assignStoredMip(uint16 level, Size size, const Byte* bytes) {
|
||||||
|
// TODO Skip the extra allocation here
|
||||||
storage::StoragePointer storage = std::make_shared<storage::MemoryStorage>(size, bytes);
|
storage::StoragePointer storage = std::make_shared<storage::MemoryStorage>(size, bytes);
|
||||||
assignStoredMip(level, storage);
|
assignStoredMip(level, storage);
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,6 +45,7 @@ std::string GPUKTXPayload::KEY { "hifi.gpu" };
|
||||||
|
|
||||||
KtxStorage::KtxStorage(const std::string& filename) : _filename(filename) {
|
KtxStorage::KtxStorage(const std::string& filename) : _filename(filename) {
|
||||||
{
|
{
|
||||||
|
// We are doing a lot of work here just to get descriptor data
|
||||||
ktx::StoragePointer storage { new storage::FileStorage(_filename.c_str()) };
|
ktx::StoragePointer storage { new storage::FileStorage(_filename.c_str()) };
|
||||||
auto ktxPointer = ktx::KTX::create(storage);
|
auto ktxPointer = ktx::KTX::create(storage);
|
||||||
_ktxDescriptor.reset(new ktx::KTXDescriptor(ktxPointer->toDescriptor()));
|
_ktxDescriptor.reset(new ktx::KTXDescriptor(ktxPointer->toDescriptor()));
|
||||||
|
@ -74,8 +75,9 @@ Size KtxStorage::getMipFaceSize(uint16 level, uint8 face) const {
|
||||||
|
|
||||||
|
|
||||||
bool KtxStorage::isMipAvailable(uint16 level, uint8 face) const {
|
bool KtxStorage::isMipAvailable(uint16 level, uint8 face) const {
|
||||||
|
return true;
|
||||||
auto numLevels = _ktxDescriptor->header.numberOfMipmapLevels;
|
auto numLevels = _ktxDescriptor->header.numberOfMipmapLevels;
|
||||||
auto minLevel = 7 > numLevels ? 0 : numLevels - 7;
|
auto minLevel = 7 > numLevels ? 0 : numLevels - 10;
|
||||||
auto avail = level >= minLevel;
|
auto avail = level >= minLevel;
|
||||||
qDebug() << "isMipAvailable: " << level << " " << face << avail << minLevel << " " << _ktxDescriptor->header.numberOfMipmapLevels;
|
qDebug() << "isMipAvailable: " << level << " " << face << avail << minLevel << " " << _ktxDescriptor->header.numberOfMipmapLevels;
|
||||||
//return true;
|
//return true;
|
||||||
|
|
|
@ -211,6 +211,7 @@ Image ImageDescriptor::toImage(const ktx::StoragePointer& storage) const {
|
||||||
FaceBytes faces;
|
FaceBytes faces;
|
||||||
faces.resize(_faceOffsets.size());
|
faces.resize(_faceOffsets.size());
|
||||||
for (size_t face = 0; face < _numFaces; ++face) {
|
for (size_t face = 0; face < _numFaces; ++face) {
|
||||||
|
// TODO Should we be storing pointers to unowned data?
|
||||||
faces[face] = storage->data() + _faceOffsets[face];
|
faces[face] = storage->data() + _faceOffsets[face];
|
||||||
}
|
}
|
||||||
// Note, implicit cast of *this to const ImageHeader&
|
// Note, implicit cast of *this to const ImageHeader&
|
||||||
|
|
|
@ -384,7 +384,7 @@ namespace ktx {
|
||||||
ImageDescriptors generateImageDescriptors() const;
|
ImageDescriptors generateImageDescriptors() const;
|
||||||
};
|
};
|
||||||
static const size_t KTX_HEADER_SIZE = 64;
|
static const size_t KTX_HEADER_SIZE = 64;
|
||||||
static_assert(sizeof(Header) == KTX_HEADER_SIZE, "KTX Header size is static");
|
static_assert(sizeof(Header) == KTX_HEADER_SIZE, "KTX Header size is static and should not change from the spec");
|
||||||
|
|
||||||
// Key Values
|
// Key Values
|
||||||
struct KeyValue {
|
struct KeyValue {
|
||||||
|
@ -497,6 +497,8 @@ namespace ktx {
|
||||||
static size_t writeKeyValues(Byte* destBytes, size_t destByteSize, const KeyValues& keyValues);
|
static size_t writeKeyValues(Byte* destBytes, size_t destByteSize, const KeyValues& keyValues);
|
||||||
static Images writeImages(Byte* destBytes, size_t destByteSize, const Images& images);
|
static Images writeImages(Byte* destBytes, size_t destByteSize, const Images& images);
|
||||||
|
|
||||||
|
void writeMipData(uint16_t level, const Byte* sourceBytes, size_t source_size);
|
||||||
|
|
||||||
// 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(const StoragePointer& src);
|
static std::unique_ptr<KTX> create(const StoragePointer& src);
|
||||||
|
|
||||||
|
|
|
@ -235,4 +235,11 @@ namespace ktx {
|
||||||
return destImages;
|
return destImages;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void KTX::writeMipData(uint16_t level, const Byte* sourceBytes, size_t sourceSize) {
|
||||||
|
Q_ASSERT(level > 0);
|
||||||
|
Q_ASSERT(level < _images.size());
|
||||||
|
Q_ASSERT(sourceSize == _images[level]._imageSize);
|
||||||
|
|
||||||
|
//memcpy(reinterpret_cast<void*>(_images[level]._faceBytes[0]), sourceBytes, sourceSize);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -545,7 +545,6 @@ void NetworkTexture::loadContent(const QByteArray& content) {
|
||||||
texture = textureCache->cacheTextureByHash(filename, texture);
|
texture = textureCache->cacheTextureByHash(filename, texture);
|
||||||
}
|
}
|
||||||
|
|
||||||
setImage(texture, header->getPixelWidth(), header->getPixelHeight());
|
|
||||||
|
|
||||||
|
|
||||||
auto desc = memKtx->toDescriptor();
|
auto desc = memKtx->toDescriptor();
|
||||||
|
@ -559,10 +558,24 @@ void NetworkTexture::loadContent(const QByteArray& content) {
|
||||||
}
|
}
|
||||||
_requestByteRange.fromInclusive = length - sizeOfTopMips;
|
_requestByteRange.fromInclusive = length - sizeOfTopMips;
|
||||||
_requestByteRange.toExclusive = length;
|
_requestByteRange.toExclusive = length;
|
||||||
attemptRequest();
|
QMetaObject::invokeMethod(this, "attemptRequest", Qt::QueuedConnection);
|
||||||
|
|
||||||
|
|
||||||
|
//texture->setMinMip(desc.images.size() - 1);
|
||||||
|
setImage(texture, header->getPixelWidth(), header->getPixelHeight());
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
qDebug() << "Got highest 6 mips";
|
qDebug() << "Got highest 6 mips";
|
||||||
|
|
||||||
|
ktx::StoragePointer storage { new storage::FileStorage(QString::fromStdString(_file->getFilepath())) };
|
||||||
|
auto data = storage->mutableData();
|
||||||
|
auto size = storage->getSize();
|
||||||
|
//*data = 'H';
|
||||||
|
memcpy(data + _requestByteRange.fromInclusive, content.data(), content.size());
|
||||||
|
//getGPUTexture()->setMinMip(getGPUTexture()->getMinMip() - 6);
|
||||||
|
//auto ktxPointer = ktx::KTX::create(storage);
|
||||||
|
|
||||||
|
//ktxPointer->writeMipData(level, data, size);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,6 +22,7 @@
|
||||||
#include "NetworkLogging.h"
|
#include "NetworkLogging.h"
|
||||||
|
|
||||||
HTTPResourceRequest::~HTTPResourceRequest() {
|
HTTPResourceRequest::~HTTPResourceRequest() {
|
||||||
|
qDebug() << "Cleaning up:" << _url << " " << _byteRange.fromInclusive << "-" << _byteRange.toExclusive;
|
||||||
if (_reply) {
|
if (_reply) {
|
||||||
_reply->disconnect(this);
|
_reply->disconnect(this);
|
||||||
_reply->deleteLater();
|
_reply->deleteLater();
|
||||||
|
@ -76,9 +77,12 @@ void HTTPResourceRequest::doSend() {
|
||||||
connect(_reply, &QNetworkReply::downloadProgress, this, &HTTPResourceRequest::onDownloadProgress);
|
connect(_reply, &QNetworkReply::downloadProgress, this, &HTTPResourceRequest::onDownloadProgress);
|
||||||
|
|
||||||
setupTimer();
|
setupTimer();
|
||||||
|
qDebug() << "Sent: " << _url;
|
||||||
}
|
}
|
||||||
|
|
||||||
void HTTPResourceRequest::onRequestFinished() {
|
void HTTPResourceRequest::onRequestFinished() {
|
||||||
|
qDebug() << "On request finished: " << _url;
|
||||||
|
|
||||||
Q_ASSERT(_state == InProgress);
|
Q_ASSERT(_state == InProgress);
|
||||||
Q_ASSERT(_reply);
|
Q_ASSERT(_reply);
|
||||||
|
|
||||||
|
@ -181,6 +185,7 @@ void HTTPResourceRequest::onRequestFinished() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void HTTPResourceRequest::onDownloadProgress(qint64 bytesReceived, qint64 bytesTotal) {
|
void HTTPResourceRequest::onDownloadProgress(qint64 bytesReceived, qint64 bytesTotal) {
|
||||||
|
qDebug() << "Progress: " << _url;
|
||||||
Q_ASSERT(_state == InProgress);
|
Q_ASSERT(_state == InProgress);
|
||||||
|
|
||||||
// We've received data, so reset the timer
|
// We've received data, so reset the timer
|
||||||
|
@ -190,6 +195,7 @@ void HTTPResourceRequest::onDownloadProgress(qint64 bytesReceived, qint64 bytesT
|
||||||
}
|
}
|
||||||
|
|
||||||
void HTTPResourceRequest::onTimeout() {
|
void HTTPResourceRequest::onTimeout() {
|
||||||
|
qDebug() << "Timeout: " << _url << ":" << _reply->isFinished();
|
||||||
Q_ASSERT(_state == InProgress);
|
Q_ASSERT(_state == InProgress);
|
||||||
_reply->disconnect(this);
|
_reply->disconnect(this);
|
||||||
_reply->abort();
|
_reply->abort();
|
||||||
|
|
|
@ -698,6 +698,7 @@ void Resource::handleDownloadProgress(uint64_t bytesReceived, uint64_t bytesTota
|
||||||
}
|
}
|
||||||
|
|
||||||
void Resource::handleReplyFinished() {
|
void Resource::handleReplyFinished() {
|
||||||
|
qDebug() << "Got response for " << _activeUrl;
|
||||||
Q_ASSERT_X(_request, "Resource::handleReplyFinished", "Request should not be null while in handleReplyFinished");
|
Q_ASSERT_X(_request, "Resource::handleReplyFinished", "Request should not be null while in handleReplyFinished");
|
||||||
|
|
||||||
PROFILE_ASYNC_END(resource, "Resource:" + getType(), QString::number(_requestID), {
|
PROFILE_ASYNC_END(resource, "Resource:" + getType(), QString::number(_requestID), {
|
||||||
|
|
|
@ -69,7 +69,8 @@ StoragePointer FileStorage::create(const QString& filename, size_t size, const u
|
||||||
|
|
||||||
// Represents a memory mapped file
|
// Represents a memory mapped file
|
||||||
FileStorage::FileStorage(const QString& filename) : _file(filename) {
|
FileStorage::FileStorage(const QString& filename) : _file(filename) {
|
||||||
if (_file.open(QFile::ReadOnly)) {
|
if (_file.open(QFile::ReadWrite)) {
|
||||||
|
qDebug() << ">>> Opening mmapped file: " << filename;
|
||||||
_mapped = _file.map(0, _file.size());
|
_mapped = _file.map(0, _file.size());
|
||||||
if (_mapped) {
|
if (_mapped) {
|
||||||
_valid = true;
|
_valid = true;
|
||||||
|
@ -82,6 +83,7 @@ FileStorage::FileStorage(const QString& filename) : _file(filename) {
|
||||||
}
|
}
|
||||||
|
|
||||||
FileStorage::~FileStorage() {
|
FileStorage::~FileStorage() {
|
||||||
|
qDebug() << ">>> Closing mmapped file: " << _file.fileName();
|
||||||
if (_mapped) {
|
if (_mapped) {
|
||||||
if (!_file.unmap(_mapped)) {
|
if (!_file.unmap(_mapped)) {
|
||||||
throw std::runtime_error("Unable to unmap file");
|
throw std::runtime_error("Unable to unmap file");
|
||||||
|
|
|
@ -25,6 +25,7 @@ namespace storage {
|
||||||
public:
|
public:
|
||||||
virtual ~Storage() {}
|
virtual ~Storage() {}
|
||||||
virtual const uint8_t* data() const = 0;
|
virtual const uint8_t* data() const = 0;
|
||||||
|
virtual uint8_t* mutableData() = 0;
|
||||||
virtual size_t size() const = 0;
|
virtual size_t size() const = 0;
|
||||||
virtual operator bool() const { return true; }
|
virtual operator bool() const { return true; }
|
||||||
|
|
||||||
|
@ -42,6 +43,7 @@ namespace storage {
|
||||||
MemoryStorage(size_t size, const uint8_t* data = nullptr);
|
MemoryStorage(size_t size, const uint8_t* data = nullptr);
|
||||||
const uint8_t* data() const override { return _data.data(); }
|
const uint8_t* data() const override { return _data.data(); }
|
||||||
uint8_t* data() { return _data.data(); }
|
uint8_t* data() { return _data.data(); }
|
||||||
|
uint8_t* mutableData() override { return 0; }
|
||||||
size_t size() const override { return _data.size(); }
|
size_t size() const override { return _data.size(); }
|
||||||
operator bool() const override { return true; }
|
operator bool() const override { return true; }
|
||||||
private:
|
private:
|
||||||
|
@ -58,6 +60,7 @@ namespace storage {
|
||||||
FileStorage& operator=(const FileStorage& other) = delete;
|
FileStorage& operator=(const FileStorage& other) = delete;
|
||||||
|
|
||||||
const uint8_t* data() const override { return _mapped; }
|
const uint8_t* data() const override { return _mapped; }
|
||||||
|
uint8_t* mutableData() override { return _mapped; }
|
||||||
size_t size() const override { return _file.size(); }
|
size_t size() const override { return _file.size(); }
|
||||||
operator bool() const override { return _valid; }
|
operator bool() const override { return _valid; }
|
||||||
private:
|
private:
|
||||||
|
@ -70,6 +73,7 @@ namespace storage {
|
||||||
public:
|
public:
|
||||||
ViewStorage(const storage::StoragePointer& owner, size_t size, const uint8_t* data);
|
ViewStorage(const storage::StoragePointer& owner, size_t size, const uint8_t* data);
|
||||||
const uint8_t* data() const override { return _data; }
|
const uint8_t* data() const override { return _data; }
|
||||||
|
uint8_t* mutableData() override { return 0; }
|
||||||
size_t size() const override { return _size; }
|
size_t size() const override { return _size; }
|
||||||
operator bool() const override { return *_owner; }
|
operator bool() const override { return *_owner; }
|
||||||
private:
|
private:
|
||||||
|
|
Loading…
Reference in a new issue