Added love.graphics.getStats. It returns a table with performance-related graphics statistics. Currently it contains these fields:

drawcalls: The number of internal draw calls made so far in the current frame.

canvasswitches: The number of times the active Canvas has been changed so far in the current frame.

texturememory: The approximate amount of video memory (in bytes) used by OpenGL textures created by Images, Canvases, and Fonts.

images: The number of active Image objects.

canvases: The number of active Canvas objects.

fonts: The number of active Font objects.
This commit is contained in:
Alex Szpakowski
2014-08-21 15:01:29 -03:00
parent e1f7e4abd3
commit 8ffe610659
18 changed files with 266 additions and 16 deletions
+34 -1
View File
@@ -31,6 +31,8 @@ namespace graphics
namespace opengl
{
int Image::imageCount = 0;
float Image::maxMipmapSharpness = 0.0f;
Texture::FilterMode Image::defaultMipmapFilter = Texture::FILTER_NONE;
@@ -47,10 +49,14 @@ Image::Image(love::image::ImageData *data, Format format)
, compressed(false)
, format(format)
, usingDefaultTexture(false)
, textureMemorySize(0)
{
width = data->getWidth();
height = data->getHeight();
preload();
textureMemorySize = data->getSize();
++imageCount;
}
Image::Image(love::image::CompressedData *cdata, Format format)
@@ -64,15 +70,21 @@ Image::Image(love::image::CompressedData *cdata, Format format)
, compressed(true)
, format(format)
, usingDefaultTexture(false)
, textureMemorySize(0)
{
width = cdata->getWidth(0);
height = cdata->getHeight(0);
preload();
textureMemorySize = cdata->getSize(0);
++imageCount;
}
Image::~Image()
{
unload();
--imageCount;
}
love::image::ImageData *Image::getImageData() const
@@ -151,8 +163,11 @@ void Image::uploadCompressedMipmaps()
"compressed image does not have all required levels.");
}
size_t totalsize = cdata->getSize(0);
for (int i = 1; i < count; i++)
{
totalsize += cdata->getSize(i);
glCompressedTexImage2DARB(GL_TEXTURE_2D,
i,
getCompressedFormat(cdata->getFormat()),
@@ -162,6 +177,10 @@ void Image::uploadCompressedMipmaps()
GLsizei(cdata->getSize(i)),
cdata->getData(i));
}
size_t prevmemsize = textureMemorySize;
textureMemorySize = totalsize;
gl.updateTextureMemorySize(prevmemsize, textureMemorySize);
}
void Image::createMipmaps()
@@ -216,6 +235,10 @@ void Image::createMipmaps()
data->getData());
glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_FALSE);
}
size_t prevmemsize = textureMemorySize;
textureMemorySize = paddedWidth * paddedHeight * 4 * 1.3333;
gl.updateTextureMemorySize(prevmemsize, textureMemorySize);
}
void Image::checkMipmapsCreated()
@@ -381,6 +404,13 @@ bool Image::loadVolatile()
if (glerr != GL_NO_ERROR)
throw love::Exception("Cannot create image (error code 0x%x)", glerr);
if (isCompressed())
textureMemorySize = cdata->getSize(0);
else
textureMemorySize = paddedWidth * paddedHeight * 4;
gl.updateTextureMemorySize(0, textureMemorySize);
usingDefaultTexture = false;
mipmapsCreated = false;
checkMipmapsCreated();
@@ -456,6 +486,9 @@ void Image::unloadVolatile()
{
gl.deleteTexture(texture);
texture = 0;
gl.updateTextureMemorySize(textureMemorySize, 0);
textureMemorySize = 0;
}
}
@@ -530,7 +563,7 @@ void Image::drawv(const Matrix &t, const Vertex *v)
glTexCoordPointer(2, GL_FLOAT, sizeof(Vertex), (GLvoid *)&v[0].s);
gl.prepareDraw();
glDrawArrays(GL_QUADS, 0, 4);
gl.drawArrays(GL_QUADS, 0, 4);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
glDisableClientState(GL_VERTEX_ARRAY);