mirror of
https://github.com/lubosz/overte.git
synced 2025-08-08 03:48:38 +02:00
pad MemoryStorage size to multiple of 4 rather than using a vector of uint32_t -- this gets the same alignment without needs casts
This commit is contained in:
parent
712386f256
commit
dfb9fecf17
2 changed files with 7 additions and 7 deletions
|
@ -39,8 +39,9 @@ StoragePointer Storage::toFileStorage(const QString& filename) const {
|
||||||
}
|
}
|
||||||
|
|
||||||
MemoryStorage::MemoryStorage(size_t size, const uint8_t* data) : _size(size) {
|
MemoryStorage::MemoryStorage(size_t size, const uint8_t* data) : _size(size) {
|
||||||
_data.resize((size + 3) / 4); // alloc smallest number of 4-byte chunks that will cover size bytes
|
// alloc smallest number of 4-byte chunks that will cover size bytes. The buffer is padded out to a multiple
|
||||||
|
// of 4 to force an alignment that glTextureSubImage2D can later use.
|
||||||
|
_data.resize((size + 3) & ~0x3);
|
||||||
if (data) {
|
if (data) {
|
||||||
memcpy(_data.data(), data, size);
|
memcpy(_data.data(), data, size);
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,16 +41,15 @@ namespace storage {
|
||||||
class MemoryStorage : public Storage {
|
class MemoryStorage : public Storage {
|
||||||
public:
|
public:
|
||||||
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 reinterpret_cast<const uint8_t*>(_data.data()); }
|
const uint8_t* data() const override { return _data.data(); }
|
||||||
uint8_t* data() { return reinterpret_cast<uint8_t*>(_data.data()); }
|
uint8_t* data() { return _data.data(); }
|
||||||
uint8_t* mutableData() override { return reinterpret_cast<uint8_t*>(_data.data()); }
|
uint8_t* mutableData() override { return _data.data(); }
|
||||||
|
|
||||||
size_t _size { 0 };
|
size_t _size { 0 };
|
||||||
size_t size() const override { return _size; }
|
size_t size() const override { return _size; }
|
||||||
operator bool() const override { return true; }
|
operator bool() const override { return true; }
|
||||||
private:
|
private:
|
||||||
// the vector is of uint32_t rather than uint8_t to force alignment
|
std::vector<uint8_t> _data;
|
||||||
std::vector<uint32_t> _data;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class FileStorage : public Storage {
|
class FileStorage : public Storage {
|
||||||
|
|
Loading…
Reference in a new issue