Mercurial > love-experiments
diff src/modules/image/CompressedData.cpp @ 1426:a5e46f43e3d6 image-CompressedData
Made the getSize() and getData() methods for CompressedData consistent with each other. Note that CompressedData's data may not all be contiguous in memory, so getData(miplevel) and getSize(miplevel) should always be used instead.
| author | Alex Szpakowski <slime73@gmail.com> |
|---|---|
| date | Tue, 09 Apr 2013 23:39:20 -0300 |
| parents | 377f9dad7a2d |
| children |
line wrap: on
line diff
--- a/src/modules/image/CompressedData.cpp Mon Apr 08 21:58:20 2013 -0300 +++ b/src/modules/image/CompressedData.cpp Tue Apr 09 23:39:20 2013 -0300 @@ -36,18 +36,23 @@ int CompressedData::getSize() const { - size_t totalsize = sizeof(SubImage) * dataImages.size(); - - for (size_t i = 0; i < dataImages.size(); i++) - totalsize += dataImages[i].size; - - return totalsize; + // Adding up the total size for all mipmap levels would make more sense, but + // it's probably better for getSize() to match getData() so no bad memory + // accesses happen... + if (dataImages.size() > 0) + return dataImages[0].size; + else + return 0; } void *CompressedData::getData() const { - // ? - return (void *) &dataImages[0].data[0]; + // Data for different mipmap levels is not stored contiguously in memory, so + // getData() won't work properly for CompressedData. + if (dataImages.size() > 0) + return (void *) &(dataImages[0].data[0]); + else + return 0; } int CompressedData::getNumMipmaps() const
