Skip to content

Commit b7e174f

Browse files
fix(vtfpp): aux compressed 3d vtfs now load correctly
1 parent fa0dc26 commit b7e174f

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

src/vtfpp/vtfpp.cpp

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -257,19 +257,16 @@ std::span<const std::byte> VTF::getImageDataRaw(uint8_t mip, uint16_t frame, uin
257257
return {};
258258
}
259259

260+
// Keep in mind that the slice parameter gets ignored when returning raw compressed data - the slices are compressed together
260261
offset = 0;
261262
for (int i = this->mipCount - 1; i >= 0; i--) {
262263
for (int j = 0; j < this->frameCount; j++) {
263264
for (int k = 0; k < this->getFaceCount(); k++) {
264-
// This is done out of hope that it works, but it probably doesn't...
265-
// Don't compress a volumetric texture if you want it to load properly...
266-
for (int l = 0; l < this->sliceCount; l++) {
267-
length = auxResource->getDataAsAuxCompressionLength(i, this->mipCount, j, this->frameCount, k, this->getFaceCount());
268-
if (i == mip && j == frame && k == face && l == slice) {
269-
return imageResource->data.subspan(offset, length);
270-
} else {
271-
offset += length;
272-
}
265+
length = auxResource->getDataAsAuxCompressionLength(i, this->mipCount, j, this->frameCount, k, this->getFaceCount());
266+
if (i == mip && j == frame && k == face) {
267+
return imageResource->data.subspan(offset, length);
268+
} else {
269+
offset += length;
273270
}
274271
}
275272
}
@@ -309,7 +306,13 @@ std::vector<std::byte> VTF::getImageDataAs(ImageFormat newFormat, uint8_t mip, u
309306
return {};
310307
}
311308
decompressedImageData.resize(decompressedImageDataSize);
312-
return ImageConversion::convertImageDataToFormat(decompressedImageData, this->format, newFormat, ImageDimensions::getMipDim(mip, this->width), ImageDimensions::getMipDim(mip, this->height));
309+
310+
// 3D compressed images will have their slices aggregated together, so we need to do some trickery to pull a specific one out
311+
if (this->sliceCount == 1) {
312+
return ImageConversion::convertImageDataToFormat(decompressedImageData, this->format, newFormat, ImageDimensions::getMipDim(mip, this->width), ImageDimensions::getMipDim(mip, this->height));
313+
}
314+
const auto sliceSize = ImageFormatDetails::getDataLength(this->format, ImageDimensions::getMipDim(mip, this->width), ImageDimensions::getMipDim(mip, this->height), 1);
315+
return ImageConversion::convertImageDataToFormat({decompressedImageData.begin() + (slice * sliceSize), sliceSize}, this->format, newFormat, ImageDimensions::getMipDim(mip, this->width), ImageDimensions::getMipDim(mip, this->height));
313316
}
314317

315318
std::vector<std::byte> VTF::getImageDataAsRGBA8888(uint8_t mip, uint16_t frame, uint16_t face, uint16_t slice) const {

0 commit comments

Comments
 (0)