From 901cc362df32b7837675cbf4b8503beb24a9c34c Mon Sep 17 00:00:00 2001 From: Alex Szpakowski Date: Sat, 2 Apr 2016 18:14:52 -0300 Subject: [PATCH] Added 'shaderswitches' to love.graphics.getStats. --- src/modules/graphics/Graphics.cpp | 22 --------------- src/modules/graphics/Graphics.h | 18 +------------ src/modules/graphics/opengl/Graphics.cpp | 10 ++++--- src/modules/graphics/opengl/OpenGL.cpp | 6 +++++ src/modules/graphics/opengl/OpenGL.h | 6 +++++ src/modules/graphics/opengl/Shader.cpp | 10 +++---- src/modules/graphics/opengl/wrap_Graphics.cpp | 27 ++++++++----------- 7 files changed, 35 insertions(+), 64 deletions(-) diff --git a/src/modules/graphics/Graphics.cpp b/src/modules/graphics/Graphics.cpp index cca874b09..f726fc175 100644 --- a/src/modules/graphics/Graphics.cpp +++ b/src/modules/graphics/Graphics.cpp @@ -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::Entry Graphics::drawModeEntries[] = { { "line", DRAW_LINE }, @@ -290,17 +280,5 @@ StringMap::Entry Graphics::stackT StringMap Graphics::stackTypes(Graphics::stackTypeEntries, sizeof(Graphics::stackTypeEntries)); -StringMap::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::statTypes(Graphics::statTypeEntries, sizeof(Graphics::statTypeEntries)); - } // graphics } // love diff --git a/src/modules/graphics/Graphics.h b/src/modules/graphics/Graphics.h index 994997dd3..06e55db5e 100644 --- a/src/modules/graphics/Graphics.h +++ b/src/modules/graphics/Graphics.h @@ -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::Entry drawModeEntries[]; @@ -338,9 +325,6 @@ private: static StringMap::Entry stackTypeEntries[]; static StringMap stackTypes; - static StringMap::Entry statTypeEntries[]; - static StringMap statTypes; - }; // Graphics } // graphics diff --git a/src/modules/graphics/opengl/Graphics.cpp b/src/modules/graphics/opengl/Graphics.cpp index 565e5710e..ebc8a135a 100644 --- a/src/modules/graphics/opengl/Graphics.cpp +++ b/src/modules/graphics/opengl/Graphics.cpp @@ -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 &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; diff --git a/src/modules/graphics/opengl/OpenGL.cpp b/src/modules/graphics/opengl/OpenGL.cpp index 276eaead3..bb084993e 100644 --- a/src/modules/graphics/opengl/OpenGL.cpp +++ b/src/modules/graphics/opengl/OpenGL.cpp @@ -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 diff --git a/src/modules/graphics/opengl/OpenGL.h b/src/modules/graphics/opengl/OpenGL.h index e4496fde4..8b89f018c 100644 --- a/src/modules/graphics/opengl/OpenGL.h +++ b/src/modules/graphics/opengl/OpenGL.h @@ -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. diff --git a/src/modules/graphics/opengl/Shader.cpp b/src/modules/graphics/opengl/Shader.cpp index 4a71ccc91..bd288db65 100644 --- a/src/modules/graphics/opengl/Shader.cpp +++ b/src/modules/graphics/opengl/Shader.cpp @@ -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; } diff --git a/src/modules/graphics/opengl/wrap_Graphics.cpp b/src/modules/graphics/opengl/wrap_Graphics.cpp index 92686ecbe..7c0a58467 100644 --- a/src/modules/graphics/opengl/wrap_Graphics.cpp +++ b/src/modules/graphics/opengl/wrap_Graphics.cpp @@ -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; }