mirror of
https://github.com/overte-org/overte.git
synced 2025-08-09 22:10:25 +02:00
Do not allow divide by zero on assigning mip data
This commit is contained in:
parent
f9c6cecb23
commit
6490c52245
2 changed files with 18 additions and 20 deletions
|
@ -123,42 +123,40 @@ bool MemoryStorage::isMipAvailable(uint16 level, uint8 face) const {
|
||||||
return (mipFace && mipFace->getSize());
|
return (mipFace && mipFace->getSize());
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MemoryStorage::allocateMip(uint16 level) {
|
void MemoryStorage::allocateMip(uint16 level) {
|
||||||
bool changed = false;
|
auto faceCount = Texture::NUM_FACES_PER_TYPE[getType()];
|
||||||
if (level >= _mips.size()) {
|
if (level >= _mips.size()) {
|
||||||
_mips.resize(level+1, std::vector<PixelsPointer>(Texture::NUM_FACES_PER_TYPE[getType()]));
|
_mips.resize(level + 1, std::vector<PixelsPointer>(faceCount));
|
||||||
changed = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
auto& mip = _mips[level];
|
auto& mip = _mips[level];
|
||||||
for (auto& face : mip) {
|
if (mip.size() != faceCount) {
|
||||||
if (!face) {
|
mip.resize(faceCount);
|
||||||
changed = true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bumpStamp();
|
bumpStamp();
|
||||||
|
|
||||||
return changed;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MemoryStorage::assignMipData(uint16 level, const storage::StoragePointer& storagePointer) {
|
void MemoryStorage::assignMipData(uint16 level, const storage::StoragePointer& storagePointer) {
|
||||||
|
|
||||||
allocateMip(level);
|
allocateMip(level);
|
||||||
auto& mip = _mips[level];
|
auto& mip = _mips[level];
|
||||||
|
|
||||||
|
auto faceCount = Texture::NUM_FACES_PER_TYPE[getType()];
|
||||||
|
|
||||||
// here we grabbed an array of faces
|
// here we grabbed an array of faces
|
||||||
// The bytes assigned here are supposed to contain all the faces bytes of the mip.
|
// The bytes assigned here are supposed to contain all the faces bytes of the mip.
|
||||||
// For tex1D, 2D, 3D there is only one face
|
// For tex1D, 2D, 3D there is only one face
|
||||||
// For Cube, we expect the 6 faces in the order X+, X-, Y+, Y-, Z+, Z-
|
// For Cube, we expect the 6 faces in the order X+, X-, Y+, Y-, Z+, Z-
|
||||||
auto sizePerFace = storagePointer->size() / mip.size();
|
auto sizePerFace = storagePointer->size() / faceCount;
|
||||||
size_t offset = 0;
|
|
||||||
for (auto& face : mip) {
|
|
||||||
face = storagePointer->createView(sizePerFace, offset);
|
|
||||||
offset += sizePerFace;
|
|
||||||
}
|
|
||||||
|
|
||||||
bumpStamp();
|
if (sizePerFace > 0) {
|
||||||
|
size_t offset = 0;
|
||||||
|
for (auto& face : mip) {
|
||||||
|
face = storagePointer->createView(sizePerFace, offset);
|
||||||
|
offset += sizePerFace;
|
||||||
|
}
|
||||||
|
|
||||||
|
bumpStamp();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -304,7 +304,7 @@ public:
|
||||||
bool isMipAvailable(uint16 level, uint8 face = 0) const override;
|
bool isMipAvailable(uint16 level, uint8 face = 0) const override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
bool allocateMip(uint16 level);
|
void allocateMip(uint16 level);
|
||||||
std::vector<std::vector<PixelsPointer>> _mips; // an array of mips, each mip is an array of faces
|
std::vector<std::vector<PixelsPointer>> _mips; // an array of mips, each mip is an array of faces
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue