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
+42 -1
View File
@@ -185,6 +185,7 @@ struct FramebufferStrategyGL3 : public FramebufferStrategy
virtual void bindFBO(GLuint framebuffer)
{
glBindFramebuffer(GL_FRAMEBUFFER, framebuffer);
++Canvas::switchCount;
}
virtual void setAttachments()
@@ -314,6 +315,7 @@ struct FramebufferStrategyPackedEXT : public FramebufferStrategy
virtual void bindFBO(GLuint framebuffer)
{
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, framebuffer);
++Canvas::switchCount;
}
virtual void setAttachments()
@@ -407,6 +409,8 @@ FramebufferStrategyEXT strategyEXT;
Canvas *Canvas::current = nullptr;
OpenGL::Viewport Canvas::systemViewport = OpenGL::Viewport();
bool Canvas::screenHasSRGB = false;
int Canvas::switchCount = 0;
int Canvas::canvasCount = 0;
static void getStrategy()
{
@@ -432,6 +436,7 @@ Canvas::Canvas(int width, int height, Format format, int msaa)
, format(format)
, msaa_samples(msaa)
, msaa_dirty(false)
, texture_memory(0)
{
this->width = width;
this->height = height;
@@ -462,10 +467,14 @@ Canvas::Canvas(int width, int height, Format format, int msaa)
getStrategy();
loadVolatile();
++canvasCount;
}
Canvas::~Canvas()
{
--canvasCount;
// reset framebuffer if still using this one
if (current == this)
stopGrab();
@@ -581,6 +590,14 @@ bool Canvas::loadVolatile()
msaa_dirty = (msaa_buffer != 0);
size_t prevmemsize = texture_memory;
texture_memory = (getFormatBitsPerPixel(format) * width * height) / 8;
if (msaa_buffer != 0)
texture_memory += (texture_memory * msaa_samples);
gl.updateTextureMemorySize(prevmemsize, texture_memory);
return true;
}
@@ -595,6 +612,9 @@ void Canvas::unloadVolatile()
resolve_fbo = msaa_buffer = 0;
attachedCanvases.clear();
gl.updateTextureMemorySize(texture_memory, 0);
texture_memory = 0;
}
void Canvas::drawv(const Matrix &t, const Vertex *v)
@@ -611,7 +631,7 @@ void Canvas::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);
@@ -1012,6 +1032,27 @@ void Canvas::convertFormat(Canvas::Format format, GLenum &internalformat, GLenum
}
}
size_t Canvas::getFormatBitsPerPixel(Format format)
{
switch (getSizedFormat(format))
{
case FORMAT_RGBA8:
case FORMAT_RGB10A2:
case FORMAT_RG11B10F:
case FORMAT_SRGB:
default:
return 32;
case FORMAT_RGBA4:
case FORMAT_RGB5A1:
case FORMAT_RGB565:
return 16;
case FORMAT_RGBA16F:
return 64;
case FORMAT_RGBA32F:
return 128;
}
}
bool Canvas::isSupported()
{
getStrategy();