mirror of
https://github.com/love2d/love.git
synced 2026-08-18 11:44:15 +02:00
metal: fix texture memory tracking
This commit is contained in:
@@ -450,7 +450,7 @@ Texture::Texture(Graphics *gfx, Texture *base, const ViewSettings &viewsettings)
|
||||
|
||||
Texture::~Texture()
|
||||
{
|
||||
setGraphicsMemorySize(0);
|
||||
updateGraphicsMemorySize(false);
|
||||
|
||||
if (this == rootView.texture)
|
||||
--textureCount;
|
||||
@@ -461,13 +461,34 @@ Texture::~Texture()
|
||||
parentView.texture->release();
|
||||
}
|
||||
|
||||
void Texture::setGraphicsMemorySize(int64 bytes)
|
||||
void Texture::updateGraphicsMemorySize(bool loaded)
|
||||
{
|
||||
int64 memsize = 0;
|
||||
|
||||
if (loaded)
|
||||
{
|
||||
for (int mip = 0; mip < getMipmapCount(); mip++)
|
||||
{
|
||||
int w = getPixelWidth(mip);
|
||||
int h = getPixelHeight(mip);
|
||||
int slices = getDepth(mip) * layers * (texType == TEXTURE_CUBE ? 6 : 1);
|
||||
memsize += getPixelFormatSliceSize(format, w, h) * slices;
|
||||
}
|
||||
|
||||
if (getMSAA() > 1 && isReadable())
|
||||
{
|
||||
int slices = depth * layers * (texType == TEXTURE_CUBE ? 6 : 1);
|
||||
memsize += getPixelFormatSliceSize(format, pixelWidth, pixelHeight) * slices * getMSAA();
|
||||
}
|
||||
else if (getMSAA() > 1)
|
||||
memsize *= getMSAA();
|
||||
}
|
||||
|
||||
totalGraphicsMemory = std::max(totalGraphicsMemory - graphicsMemorySize, (int64) 0);
|
||||
|
||||
bytes = std::max(bytes, (int64) 0);
|
||||
graphicsMemorySize = bytes;
|
||||
totalGraphicsMemory += bytes;
|
||||
memsize = std::max(memsize, (int64) 0);
|
||||
graphicsMemorySize = memsize;
|
||||
totalGraphicsMemory += memsize;
|
||||
}
|
||||
|
||||
void Texture::draw(Graphics *gfx, const Matrix4 &m)
|
||||
|
||||
Reference in New Issue
Block a user