From e76b57e12002f163b8bdd4bd5169beccc77b157d Mon Sep 17 00:00:00 2001 From: Lynix Date: Mon, 18 Aug 2014 17:19:09 +0200 Subject: [PATCH] Fixed Image level computation Array depth will no longer be taked in consideration when computing level count Former-commit-id: 93bf114127b5e252c3f8a8cbf938fcd09534a9ca --- include/Nazara/Utility/Image.hpp | 1 + src/Nazara/Utility/Image.cpp | 29 ++++++++++++++++++++++++++--- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/include/Nazara/Utility/Image.hpp b/include/Nazara/Utility/Image.hpp index 2234b7c3e..0b83022bc 100644 --- a/include/Nazara/Utility/Image.hpp +++ b/include/Nazara/Utility/Image.hpp @@ -109,6 +109,7 @@ class NAZARA_API NzImage : public NzResource static void Copy(nzUInt8* destination, const nzUInt8* source, nzUInt8 bpp, unsigned int width, unsigned int height, unsigned int depth = 1, unsigned int dstWidth = 0, unsigned int dstHeight = 0, unsigned int srcWidth = 0, unsigned int srcHeight = 0); static nzUInt8 GetMaxLevel(unsigned int width, unsigned int height, unsigned int depth = 1); + static nzUInt8 GetMaxLevel(nzImageType type, unsigned int width, unsigned int height, unsigned int depth = 1); struct SharedImage { diff --git a/src/Nazara/Utility/Image.cpp b/src/Nazara/Utility/Image.cpp index a6ceaf41a..5eb826e6c 100644 --- a/src/Nazara/Utility/Image.cpp +++ b/src/Nazara/Utility/Image.cpp @@ -271,7 +271,7 @@ bool NzImage::Create(nzImageType type, nzPixelFormat format, unsigned int width, } #endif - levelCount = std::min(levelCount, GetMaxLevel(width, height, depth)); + levelCount = std::min(levelCount, GetMaxLevel(type, width, height, depth)); nzUInt8** levels = new nzUInt8*[levelCount]; @@ -673,7 +673,7 @@ nzUInt8 NzImage::GetLevelCount() const nzUInt8 NzImage::GetMaxLevel() const { - return GetMaxLevel(m_sharedImage->width, m_sharedImage->height, m_sharedImage->depth); + return GetMaxLevel(m_sharedImage->type, m_sharedImage->width, m_sharedImage->height, m_sharedImage->depth); } NzColor NzImage::GetPixelColor(unsigned int x, unsigned int y, unsigned int z) const @@ -1003,7 +1003,7 @@ void NzImage::SetLevelCount(nzUInt8 levelCount) } #endif - levelCount = std::min(levelCount, GetMaxLevel(m_sharedImage->width, m_sharedImage->height, m_sharedImage->depth)); + levelCount = std::min(levelCount, GetMaxLevel()); if (m_sharedImage->levelCount == levelCount) return; @@ -1287,6 +1287,29 @@ nzUInt8 NzImage::GetMaxLevel(unsigned int width, unsigned int height, unsigned i return std::max(std::max(std::max(widthLevel, heightLevel), depthLevel), 1U); } +nzUInt8 NzImage::GetMaxLevel(nzImageType type, unsigned int width, unsigned int height, unsigned int depth) +{ + // Pour éviter que la profondeur ne soit comptée dans le calcul des niveaux + switch (type) + { + case nzImageType_1D: + case nzImageType_1D_Array: + return GetMaxLevel(width, 1U, 1U); + + case nzImageType_2D: + case nzImageType_2D_Array: + case nzImageType_Cubemap: + return GetMaxLevel(width, height, 1U); + + case nzImageType_3D: + return GetMaxLevel(width, height, depth); + } + + NazaraError("Image type not handled (0x" + NzString::Number(type, 16) + ')'); + return 0; + +} + void NzImage::EnsureOwnership() { if (m_sharedImage == &emptyImage)