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); 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[] = StringMap<Graphics::DrawMode, Graphics::DRAW_MAX_ENUM>::Entry Graphics::drawModeEntries[] =
{ {
{ "line", DRAW_LINE }, { "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::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 } // graphics
} // love } // love
+1 -17
View File
@@ -167,17 +167,6 @@ public:
STACK_MAX_ENUM 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 struct RendererInfo
{ {
std::string name; std::string name;
@@ -190,6 +179,7 @@ public:
{ {
int drawCalls; int drawCalls;
int canvasSwitches; int canvasSwitches;
int shaderSwitches;
int canvases; int canvases;
int images; int images;
int fonts; int fonts;
@@ -300,9 +290,6 @@ public:
static bool getConstant(const char *in, StackType &out); static bool getConstant(const char *in, StackType &out);
static bool getConstant(StackType in, const char *&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: private:
static StringMap<DrawMode, DRAW_MAX_ENUM>::Entry drawModeEntries[]; 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>::Entry stackTypeEntries[];
static StringMap<StackType, STACK_MAX_ENUM> stackTypes; static StringMap<StackType, STACK_MAX_ENUM> stackTypes;
static StringMap<StatType, STAT_MAX_ENUM>::Entry statTypeEntries[];
static StringMap<StatType, STAT_MAX_ENUM> statTypes;
}; // Graphics }; // Graphics
} // 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 // 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. // tried (e.g. dummy draws) don't work in all cases.
glUseProgram(0); gl.useProgram(0);
glUseProgram(Shader::current->getProgram()); 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 // 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. // tried (e.g. dummy draws) don't work in all cases.
glUseProgram(0); gl.useProgram(0);
glUseProgram(Shader::current->getProgram()); gl.useProgram(Shader::current->getProgram());
} }
} }
@@ -610,6 +610,7 @@ void Graphics::present()
// Reset the per-frame stat counts. // Reset the per-frame stat counts.
gl.stats.drawCalls = 0; gl.stats.drawCalls = 0;
gl.stats.framebufferBinds = 0; gl.stats.framebufferBinds = 0;
gl.stats.shaderSwitches = 0;
} }
int Graphics::getWidth() const int Graphics::getWidth() const
@@ -1653,6 +1654,7 @@ Graphics::Stats Graphics::getStats() const
stats.drawCalls = gl.stats.drawCalls; stats.drawCalls = gl.stats.drawCalls;
stats.canvasSwitches = gl.stats.framebufferBinds; stats.canvasSwitches = gl.stats.framebufferBinds;
stats.shaderSwitches = gl.stats.shaderSwitches;
stats.canvases = Canvas::canvasCount; stats.canvases = Canvas::canvasCount;
stats.images = Image::imageCount; stats.images = Image::imageCount;
stats.fonts = Font::fontCount; stats.fonts = Font::fontCount;
+6
View File
@@ -495,6 +495,12 @@ void OpenGL::bindFramebuffer(GLenum target, GLuint framebuffer)
++stats.framebufferBinds; ++stats.framebufferBinds;
} }
void OpenGL::useProgram(GLuint program)
{
glUseProgram(program);
++stats.shaderSwitches;
}
GLuint OpenGL::getDefaultFBO() const GLuint OpenGL::getDefaultFBO() const
{ {
#ifdef LOVE_IOS #ifdef LOVE_IOS
+6
View File
@@ -167,6 +167,7 @@ public:
size_t textureMemory; size_t textureMemory;
int drawCalls; int drawCalls;
int framebufferBinds; int framebufferBinds;
int shaderSwitches;
} stats; } stats;
struct Bugs struct Bugs
@@ -305,6 +306,11 @@ public:
**/ **/
void bindFramebuffer(GLenum target, GLuint framebuffer); void bindFramebuffer(GLenum target, GLuint framebuffer);
/**
* Calls glUseProgram.
**/
void useProgram(GLuint program);
/** /**
* This will usually be 0 (system drawable), but some platforms require a * This will usually be 0 (system drawable), but some platforms require a
* non-zero FBO for rendering. * non-zero FBO for rendering.
+5 -5
View File
@@ -181,7 +181,7 @@ void Shader::mapActiveUniforms()
GLint activeprogram = 0; GLint activeprogram = 0;
glGetIntegerv(GL_CURRENT_PROGRAM, &activeprogram); glGetIntegerv(GL_CURRENT_PROGRAM, &activeprogram);
glUseProgram(program); gl.useProgram(program);
GLint numuniforms; GLint numuniforms;
glGetProgramiv(program, GL_ACTIVE_UNIFORMS, &numuniforms); glGetProgramiv(program, GL_ACTIVE_UNIFORMS, &numuniforms);
@@ -223,7 +223,7 @@ void Shader::mapActiveUniforms()
uniforms[u.name] = u; uniforms[u.name] = u;
} }
glUseProgram(activeprogram); gl.useProgram(activeprogram);
} }
bool Shader::loadVolatile() bool Shader::loadVolatile()
@@ -334,7 +334,7 @@ bool Shader::loadVolatile()
void Shader::unloadVolatile() void Shader::unloadVolatile()
{ {
if (current == this) if (current == this)
glUseProgram(0); gl.useProgram(0);
if (program != 0) if (program != 0)
{ {
@@ -406,7 +406,7 @@ void Shader::attach(bool temporary)
{ {
if (current != this) if (current != this)
{ {
glUseProgram(program); gl.useProgram(program);
current = this; current = this;
// retain/release happens in Graphics::setShader. // retain/release happens in Graphics::setShader.
} }
@@ -437,7 +437,7 @@ void Shader::detach()
} }
if (current != nullptr) if (current != nullptr)
glUseProgram(0); gl.useProgram(0);
current = nullptr; current = nullptr;
} }
+11 -16
View File
@@ -1473,33 +1473,28 @@ int w_getStats(lua_State *L)
{ {
Graphics::Stats stats = instance()->getStats(); 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_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_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_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_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_pushinteger(L, stats.fonts);
lua_setfield(L, -2, sname); lua_setfield(L, -2, "fonts");
Graphics::getConstant(Graphics::STAT_TEXTURE_MEMORY, sname); lua_pushinteger(L, stats.textureMemory);
lua_pushnumber(L, (lua_Number) stats.textureMemory); lua_setfield(L, -2, "texturememory");
lua_setfield(L, -2, sname);
return 1; return 1;
} }