Skip to content

Commit

Permalink
Add getDataView() method to QTextureFileData
Browse files Browse the repository at this point in the history
This method will return a QByteArrayView of the data range corresponding
to the level. This avoids a leaky abstraction by moving the needed data
pointer arithmetic from the caller to the method. It will also make it
easier adding cubemap support in the future.

Change-Id: I2415bd88365d8d69ba14aefc77f5f1117f9e0033
Reviewed-by: Eirik Aavitsland <[email protected]>
  • Loading branch information
karjonas committed Dec 29, 2020
1 parent 89b2b60 commit 162a859
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/gui/util/qtexturefiledata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,17 @@ int QTextureFileData::dataLength(int level) const
return (d && d->lengths.size() > level) ? d->lengths.at(level) : 0;
}

QByteArrayView QTextureFileData::getDataView(int level) const
{
const int dataLength = this->dataLength(level);
const int dataOffset = this->dataOffset(level);

if (d == nullptr || dataLength == 0)
return QByteArrayView();

return QByteArrayView(d->data.constData() + dataOffset, dataLength);
}

void QTextureFileData::setDataLength(int length, int level)
{
if (d.constData() && level >= 0) {
Expand Down
2 changes: 2 additions & 0 deletions src/gui/util/qtexturefiledata_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ class Q_GUI_EXPORT QTextureFileData
int dataLength(int level = 0) const;
void setDataLength(int length, int level = 0);

QByteArrayView getDataView(int level = 0) const;

int numLevels() const;
void setNumLevels(int num);

Expand Down

0 comments on commit 162a859

Please sign in to comment.