mirror of
https://github.com/love2d/love.git
synced 2026-08-17 19:23:38 +02:00
Added 'shaderswitches' to love.graphics.getStats.
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user