Use new QTextureFileData::getDataView method
Change-Id: Ib675bfaa3fd818ef3e372bc2affd87e0d9d8f480 Reviewed-by: Laszlo Agocs <laszlo.agocs@qt.io>
This commit is contained in:
parent
1cd696cf9e
commit
dfb36c91b4
|
@ -68,14 +68,14 @@ Atlas::~Atlas()
|
|||
{
|
||||
}
|
||||
|
||||
Texture *Atlas::create(const QByteArray &data, int dataLength, int dataOffset, const QSize &size)
|
||||
Texture *Atlas::create(QByteArrayView data, const QSize &size)
|
||||
{
|
||||
// Align reservation to 16x16, >= any compressed block size
|
||||
QSize paddedSize(((size.width() + 15) / 16) * 16, ((size.height() + 15) / 16) * 16);
|
||||
// No need to lock, as manager already locked it.
|
||||
QRect rect = m_allocator.allocate(paddedSize);
|
||||
if (rect.width() > 0 && rect.height() > 0) {
|
||||
Texture *t = new Texture(this, rect, data, dataLength, dataOffset, size);
|
||||
Texture *t = new Texture(this, rect, data, size);
|
||||
m_pending_uploads << t;
|
||||
return t;
|
||||
}
|
||||
|
@ -109,8 +109,8 @@ void Atlas::enqueueTextureUpload(QSGRhiAtlasTexture::TextureBase *t, QRhiResourc
|
|||
|
||||
const QRect &r = texture->atlasSubRect();
|
||||
|
||||
const char *rawData = texture->data().constData() + texture->dataOffset();
|
||||
QRhiTextureSubresourceUploadDescription subresDesc(rawData, texture->sizeInBytes());
|
||||
QRhiTextureSubresourceUploadDescription subresDesc(texture->data().constData(),
|
||||
texture->sizeInBytes());
|
||||
subresDesc.setSourceSize(texture->textureSize());
|
||||
subresDesc.setDestinationTopLeft(r.topLeft());
|
||||
|
||||
|
@ -121,14 +121,10 @@ void Atlas::enqueueTextureUpload(QSGRhiAtlasTexture::TextureBase *t, QRhiResourc
|
|||
t->textureSize().width(), t->textureSize().height(), m_format);
|
||||
}
|
||||
|
||||
Texture::Texture(Atlas *atlas, const QRect &textureRect, const QByteArray &data, int dataLength,
|
||||
int dataOffset, const QSize &size)
|
||||
Texture::Texture(Atlas *atlas, const QRect &textureRect, QByteArrayView data, const QSize &size)
|
||||
: QSGRhiAtlasTexture::TextureBase(atlas, textureRect),
|
||||
m_nonatlas_texture(nullptr),
|
||||
m_data(data),
|
||||
m_size(size),
|
||||
m_dataLength(dataLength),
|
||||
m_dataOffset(dataOffset)
|
||||
m_data(data.toByteArray())
|
||||
{
|
||||
float w = atlas->size().width();
|
||||
float h = atlas->size().height();
|
||||
|
@ -163,8 +159,6 @@ QSGTexture *Texture::removedFromAtlas(QRhiResourceUpdateBatch *) const
|
|||
texData.setData(m_data);
|
||||
texData.setSize(m_size);
|
||||
texData.setGLInternalFormat(static_cast<Atlas*>(m_atlas)->format());
|
||||
texData.setDataLength(m_dataLength);
|
||||
texData.setDataOffset(m_dataOffset);
|
||||
m_nonatlas_texture = new QSGCompressedTexture(texData);
|
||||
m_nonatlas_texture->setMipmapFiltering(mipmapFiltering());
|
||||
m_nonatlas_texture->setFiltering(filtering());
|
||||
|
|
|
@ -75,7 +75,7 @@ public:
|
|||
void enqueueTextureUpload(QSGRhiAtlasTexture::TextureBase *t,
|
||||
QRhiResourceUpdateBatch *rcub) override;
|
||||
|
||||
Texture *create(const QByteArray &data, int dataLength, int dataOffset, const QSize &size);
|
||||
Texture *create(QByteArrayView data, const QSize &size);
|
||||
|
||||
uint format() const { return m_format; }
|
||||
|
||||
|
@ -87,7 +87,7 @@ class Texture : public QSGRhiAtlasTexture::TextureBase
|
|||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
Texture(Atlas *atlas, const QRect &textureRect, const QByteArray &data, int dataLength, int dataOffset, const QSize &size);
|
||||
Texture(Atlas *atlas, const QRect &textureRect, QByteArrayView data, const QSize &size);
|
||||
~Texture();
|
||||
|
||||
QSize textureSize() const override { return m_size; }
|
||||
|
@ -99,16 +99,13 @@ public:
|
|||
QSGTexture *removedFromAtlas(QRhiResourceUpdateBatch *) const override;
|
||||
|
||||
const QByteArray &data() const { return m_data; }
|
||||
int sizeInBytes() const { return m_dataLength; }
|
||||
int dataOffset() const { return m_dataOffset; }
|
||||
int sizeInBytes() const { return m_data.length(); }
|
||||
|
||||
private:
|
||||
QRectF m_texture_coords_rect;
|
||||
mutable QSGTexture *m_nonatlas_texture;
|
||||
QByteArray m_data;
|
||||
QSize m_size;
|
||||
int m_dataLength;
|
||||
int m_dataOffset;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -397,8 +397,11 @@ void QSGCompressedTexture::commitTextureOperations(QRhi *rhi, QRhiResourceUpdate
|
|||
}
|
||||
|
||||
// only upload mip level 0 since we never do mipmapping for compressed textures (for now?)
|
||||
resourceUpdates->uploadTexture(m_texture, QRhiTextureUploadEntry(0, 0,
|
||||
{ m_textureData.data().constData() + m_textureData.dataOffset(), m_textureData.dataLength() }));
|
||||
resourceUpdates->uploadTexture(
|
||||
m_texture,
|
||||
QRhiTextureUploadEntry(0, 0,
|
||||
QRhiTextureSubresourceUploadDescription(
|
||||
m_textureData.getDataView().toByteArray())));
|
||||
|
||||
m_textureData = QTextureFileData(); // Release this memory, not needed anymore
|
||||
}
|
||||
|
@ -454,7 +457,7 @@ QSGTexture *QSGCompressedTextureFactory::createTexture(QQuickWindow *window) con
|
|||
|
||||
int QSGCompressedTextureFactory::textureByteCount() const
|
||||
{
|
||||
return qMax(0, m_textureData.data().size() - m_textureData.dataOffset());
|
||||
return m_textureData.getDataView().size();
|
||||
}
|
||||
|
||||
QSize QSGCompressedTextureFactory::textureSize() const
|
||||
|
|
|
@ -140,7 +140,7 @@ QSGTexture *Manager::create(const QSGCompressedTextureFactory *factory)
|
|||
i = m_atlases.insert(format, newAtlas);
|
||||
}
|
||||
const QTextureFileData *cmpData = factory->textureData();
|
||||
t = i.value()->create(cmpData->data(), cmpData->dataLength(), cmpData->dataOffset(), size);
|
||||
t = i.value()->create(cmpData->getDataView(), size);
|
||||
}
|
||||
|
||||
return t;
|
||||
|
|
Loading…
Reference in New Issue