Added 'shaderswitches' to love.graphics.getStats.

This commit is contained in:
Alex Szpakowski
2016-04-02 18:14:52 -03:00
parent b365574bff
commit 901cc362df
7 changed files with 35 additions and 64 deletions
-22
View File
@@ -172,16 +172,6 @@ bool Graphics::getConstant(StackType in, const char *&out)
return stackTypes.find(in, out);
}
bool Graphics::getConstant(const char *in, StatType &out)
{
return statTypes.find(in, out);
}
bool Graphics::getConstant(StatType in, const char *&out)
{
return statTypes.find(in, out);
}
StringMap<Graphics::DrawMode, Graphics::DRAW_MAX_ENUM>::Entry Graphics::drawModeEntries[] =
{
{ "line", DRAW_LINE },
@@ -290,17 +280,5 @@ StringMap<Graphics::StackType, Graphics::STACK_MAX_ENUM>::Entry Graphics::stackT
StringMap<Graphics::StackType, Graphics::STACK_MAX_ENUM> Graphics::stackTypes(Graphics::stackTypeEntries, sizeof(Graphics::stackTypeEntries));
StringMap<Graphics::StatType, Graphics::STAT_MAX_ENUM>::Entry Graphics::statTypeEntries[] =
{
{ "drawcalls", STAT_DRAW_CALLS },
{ "canvasswitches", STAT_CANVAS_SWITCHES },
{ "canvases", STAT_CANVASES },
{ "images", STAT_IMAGES },
{ "fonts", STAT_FONTS },
{ "texturememory", STAT_TEXTURE_MEMORY },
};
StringMap<Graphics::StatType, Graphics::STAT_MAX_ENUM> Graphics::statTypes(Graphics::statTypeEntries, sizeof(Graphics::statTypeEntries));
} // graphics
} // love
+1 -17
View File
@@ -167,17 +167,6 @@ public:
STACK_MAX_ENUM
};
enum StatType
{
STAT_DRAW_CALLS,
STAT_CANVAS_SWITCHES,
STAT_CANVASES,
STAT_IMAGES,
STAT_FONTS,
STAT_TEXTURE_MEMORY,
STAT_MAX_ENUM
};
struct RendererInfo
{
std::string name;
@@ -190,6 +179,7 @@ public:
{
int drawCalls;
int canvasSwitches;
int shaderSwitches;
int canvases;
int images;
int fonts;
@@ -300,9 +290,6 @@ public:
static bool getConstant(const char *in, StackType &out);
static bool getConstant(StackType in, const char *&out);
static bool getConstant(const char *in, StatType &out);
static bool getConstant(StatType in, const char *&out);
private:
static StringMap<DrawMode, DRAW_MAX_ENUM>::Entry drawModeEntries[];
@@ -338,9 +325,6 @@ private:
static StringMap<StackType, STACK_MAX_ENUM>::Entry stackTypeEntries[];
static StringMap<StackType, STACK_MAX_ENUM> stackTypes;
static StringMap<StatType, STAT_MAX_ENUM>::Entry statTypeEntries[];
static StringMap<StatType, STAT_MAX_ENUM> statTypes;
}; // Graphics
} // graphics
+6 -4
View File
@@ -452,8 +452,8 @@ void Graphics::clear(Colorf c)
{
// This seems to be enough to fix the bug for me. Other methods I've
// tried (e.g. dummy draws) don't work in all cases.
glUseProgram(0);
glUseProgram(Shader::current->getProgram());
gl.useProgram(0);
gl.useProgram(Shader::current->getProgram());
}
}
@@ -530,8 +530,8 @@ void Graphics::clear(const std::vector<OptionalColorf> &colors)
{
// This seems to be enough to fix the bug for me. Other methods I've
// tried (e.g. dummy draws) don't work in all cases.
glUseProgram(0);
glUseProgram(Shader::current->getProgram());
gl.useProgram(0);
gl.useProgram(Shader::current->getProgram());
}
}
@@ -610,6 +610,7 @@ void Graphics::present()
// Reset the per-frame stat counts.
gl.stats.drawCalls = 0;
gl.stats.framebufferBinds = 0;
gl.stats.shaderSwitches = 0;
}
int Graphics::getWidth() const
@@ -1653,6 +1654,7 @@ Graphics::Stats Graphics::getStats() const
stats.drawCalls = gl.stats.drawCalls;
stats.canvasSwitches = gl.stats.framebufferBinds;
stats.shaderSwitches = gl.stats.shaderSwitches;
stats.canvases = Canvas::canvasCount;
stats.images = Image::imageCount;
stats.fonts = Font::fontCount;
+6
View File
@@ -495,6 +495,12 @@ void OpenGL::bindFramebuffer(GLenum target, GLuint framebuffer)
++stats.framebufferBinds;
}
void OpenGL::useProgram(GLuint program)
{
glUseProgram(program);
++stats.shaderSwitches;
}
GLuint OpenGL::getDefaultFBO() const
{
#ifdef LOVE_IOS
+6
View File
@@ -167,6 +167,7 @@ public:
size_t textureMemory;
int drawCalls;
int framebufferBinds;
int shaderSwitches;
} stats;
struct Bugs
@@ -305,6 +306,11 @@ public:
**/
void bindFramebuffer(GLenum target, GLuint framebuffer);
/**
* Calls glUseProgram.
**/
void useProgram(GLuint program);
/**
* This will usually be 0 (system drawable), but some platforms require a
* non-zero FBO for rendering.
+5 -5
View File
@@ -181,7 +181,7 @@ void Shader::mapActiveUniforms()
GLint activeprogram = 0;
glGetIntegerv(GL_CURRENT_PROGRAM, &activeprogram);
glUseProgram(program);
gl.useProgram(program);
GLint numuniforms;
glGetProgramiv(program, GL_ACTIVE_UNIFORMS, &numuniforms);
@@ -223,7 +223,7 @@ void Shader::mapActiveUniforms()
uniforms[u.name] = u;
}
glUseProgram(activeprogram);
gl.useProgram(activeprogram);
}
bool Shader::loadVolatile()
@@ -334,7 +334,7 @@ bool Shader::loadVolatile()
void Shader::unloadVolatile()
{
if (current == this)
glUseProgram(0);
gl.useProgram(0);
if (program != 0)
{
@@ -406,7 +406,7 @@ void Shader::attach(bool temporary)
{
if (current != this)
{
glUseProgram(program);
gl.useProgram(program);
current = this;
// retain/release happens in Graphics::setShader.
}
@@ -437,7 +437,7 @@ void Shader::detach()
}
if (current != nullptr)
glUseProgram(0);
gl.useProgram(0);
current = nullptr;
}
+11 -16
View File
@@ -1473,33 +1473,28 @@ int w_getStats(lua_State *L)
{
Graphics::Stats stats = instance()->getStats();
lua_createtable(L, 0, (int) Graphics::STAT_MAX_ENUM);
lua_createtable(L, 0, 7);
const char *sname = nullptr;
Graphics::getConstant(Graphics::STAT_DRAW_CALLS, sname);
lua_pushinteger(L, stats.drawCalls);
lua_setfield(L, -2, sname);
lua_setfield(L, -2, "drawcalls");
Graphics::getConstant(Graphics::STAT_CANVAS_SWITCHES, sname);
lua_pushinteger(L, stats.canvasSwitches);
lua_setfield(L, -2, sname);
lua_setfield(L, -2, "canvasswitches");
lua_pushinteger(L, stats.shaderSwitches);
lua_setfield(L, -2, "shaderswitches");
Graphics::getConstant(Graphics::STAT_CANVASES, sname);
lua_pushinteger(L, stats.canvases);
lua_setfield(L, -2, sname);
lua_setfield(L, -2, "canvases");
Graphics::getConstant(Graphics::STAT_IMAGES, sname);
lua_pushinteger(L, stats.images);
lua_setfield(L, -2, sname);
lua_setfield(L, -2, "images");
Graphics::getConstant(Graphics::STAT_FONTS, sname);
lua_pushinteger(L, stats.fonts);
lua_setfield(L, -2, sname);
lua_setfield(L, -2, "fonts");
Graphics::getConstant(Graphics::STAT_TEXTURE_MEMORY, sname);
lua_pushnumber(L, (lua_Number) stats.textureMemory);
lua_setfield(L, -2, sname);
lua_pushinteger(L, stats.textureMemory);
lua_setfield(L, -2, "texturememory");
return 1;
}