Fixed Image level computation

Array depth will no longer be taked in consideration when computing
level count


Former-commit-id: 93bf114127b5e252c3f8a8cbf938fcd09534a9ca
This commit is contained in:
Lynix 2014-08-18 17:19:09 +02:00
parent f56e0504e6
commit e76b57e120
2 changed files with 27 additions and 3 deletions

View File

@ -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 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(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 struct SharedImage
{ {

View File

@ -271,7 +271,7 @@ bool NzImage::Create(nzImageType type, nzPixelFormat format, unsigned int width,
} }
#endif #endif
levelCount = std::min(levelCount, GetMaxLevel(width, height, depth)); levelCount = std::min(levelCount, GetMaxLevel(type, width, height, depth));
nzUInt8** levels = new nzUInt8*[levelCount]; nzUInt8** levels = new nzUInt8*[levelCount];
@ -673,7 +673,7 @@ nzUInt8 NzImage::GetLevelCount() const
nzUInt8 NzImage::GetMaxLevel() 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 NzColor NzImage::GetPixelColor(unsigned int x, unsigned int y, unsigned int z) const
@ -1003,7 +1003,7 @@ void NzImage::SetLevelCount(nzUInt8 levelCount)
} }
#endif #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) if (m_sharedImage->levelCount == levelCount)
return; 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); 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() void NzImage::EnsureOwnership()
{ {
if (m_sharedImage == &emptyImage) if (m_sharedImage == &emptyImage)