mirror of
https://github.com/love2d/love.git
synced 2026-08-16 08:11:02 +02:00
Improve setCanvas validation of volume texture layer + mipmap values.
This commit is contained in:
@@ -779,7 +779,7 @@ void Graphics::setRenderTargets(const RenderTargets &rts)
|
||||
if (firsttarget.mipmap < 0 || firsttarget.mipmap >= firsttex->getMipmapCount())
|
||||
throw love::Exception("Invalid mipmap level %d.", firsttarget.mipmap + 1);
|
||||
|
||||
if (!firsttex->isValidSlice(firsttarget.slice))
|
||||
if (!firsttex->isValidSlice(firsttarget.slice, firsttarget.mipmap))
|
||||
throw love::Exception("Invalid slice index: %d.", firsttarget.slice + 1);
|
||||
|
||||
bool hasSRGBtexture = isPixelFormatSRGB(firstcolorformat);
|
||||
@@ -800,7 +800,7 @@ void Graphics::setRenderTargets(const RenderTargets &rts)
|
||||
if (mip < 0 || mip >= c->getMipmapCount())
|
||||
throw love::Exception("Invalid mipmap level %d.", mip + 1);
|
||||
|
||||
if (!c->isValidSlice(slice))
|
||||
if (!c->isValidSlice(slice, mip))
|
||||
throw love::Exception("Invalid slice index: %d.", slice + 1);
|
||||
|
||||
if (c->getPixelWidth(mip) != pixelw || c->getPixelHeight(mip) != pixelh)
|
||||
@@ -840,7 +840,7 @@ void Graphics::setRenderTargets(const RenderTargets &rts)
|
||||
if (mip < 0 || mip >= c->getMipmapCount())
|
||||
throw love::Exception("Invalid mipmap level %d.", mip + 1);
|
||||
|
||||
if (!c->isValidSlice(slice))
|
||||
if (!c->isValidSlice(slice, mip))
|
||||
throw love::Exception("Invalid slice index: %d.", slice + 1);
|
||||
}
|
||||
|
||||
|
||||
@@ -609,21 +609,22 @@ bool Texture::isFormatLinear() const
|
||||
return isGammaCorrect() && !sRGB && !isPixelFormatSRGB(format);
|
||||
}
|
||||
|
||||
bool Texture::isValidSlice(int slice) const
|
||||
bool Texture::isValidSlice(int slice, int mip) const
|
||||
{
|
||||
if (slice < 0)
|
||||
return false;
|
||||
return slice >= 0 && slice < getSliceCount(mip);
|
||||
}
|
||||
|
||||
if (texType == TEXTURE_CUBE)
|
||||
return slice < 6;
|
||||
else if (texType == TEXTURE_VOLUME)
|
||||
return slice < depth;
|
||||
int Texture::getSliceCount(int mip) const
|
||||
{
|
||||
if (texType == TEXTURE_2D)
|
||||
return 1;
|
||||
else if (texType == TEXTURE_CUBE)
|
||||
return 6;
|
||||
else if (texType == TEXTURE_2D_ARRAY)
|
||||
return slice < layers;
|
||||
else if (slice > 0)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
return layers;
|
||||
else if (texType == TEXTURE_VOLUME)
|
||||
return getDepth(mip);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int Texture::getWidth(int mip) const
|
||||
|
||||
@@ -264,7 +264,10 @@ public:
|
||||
bool isCompressed() const;
|
||||
bool isFormatLinear() const;
|
||||
|
||||
bool isValidSlice(int slice) const;
|
||||
bool isValidSlice(int slice, int mip) const;
|
||||
|
||||
// Number of array layers, cube faces, or volume layers for the given mip.
|
||||
int getSliceCount(int mip) const;
|
||||
|
||||
int getWidth(int mip = 0) const;
|
||||
int getHeight(int mip = 0) const;
|
||||
|
||||
Reference in New Issue
Block a user