Added OpenGL debug groups for most graphics operations when love is built in debug mode for iOS. The Xcode frame capture tool uses them to create nice visual groups for OpenGL function calls.

This commit is contained in:
Alex Szpakowski
2015-03-16 22:55:58 -03:00
parent 14cbc91e7f
commit 06ef263537
12 changed files with 64 additions and 0 deletions
+12
View File
@@ -198,6 +198,8 @@ bool Canvas::createMSAAFBO(GLenum internalformat)
bool Canvas::loadVolatile()
{
OpenGL::TempDebugGroup debuggroup("Canvas load");
fbo = depth_stencil = texture = 0;
resolve_fbo = msaa_buffer = 0;
status = GL_FRAMEBUFFER_COMPLETE;
@@ -298,6 +300,8 @@ void Canvas::unloadVolatile()
void Canvas::drawv(const Matrix &t, const Vertex *v)
{
OpenGL::TempDebugGroup debuggroup("Canvas draw");
OpenGL::TempTransform transform(gl);
transform.get() *= t;
@@ -439,6 +443,8 @@ void Canvas::startGrab(const std::vector<Canvas *> &canvases)
canvaseschanged = true;
}
OpenGL::TempDebugGroup debuggroup("Canvas set");
setupGrab();
// Don't attach anything if there's nothing to change.
@@ -471,6 +477,8 @@ void Canvas::startGrab(const std::vector<Canvas *> &canvases)
void Canvas::startGrab()
{
OpenGL::TempDebugGroup debuggroup("Canvas set");
setupGrab();
if (attachedCanvases.size() == 0)
@@ -488,6 +496,8 @@ void Canvas::stopGrab(bool switchingToOtherCanvas)
if (current != this)
return;
OpenGL::TempDebugGroup debuggroup("Canvas un-set");
// Make sure the canvas texture is up to date if we're using MSAA.
resolveMSAA(false);
@@ -524,6 +534,8 @@ bool Canvas::checkCreateStencil()
if (depth_stencil != 0)
return true;
OpenGL::TempDebugGroup debuggroup("Canvas create stencil");
if (current != this)
gl.bindFramebuffer(GL_FRAMEBUFFER, fbo);
+4
View File
@@ -109,6 +109,8 @@ Font::TextureSize Font::getNextTextureSize() const
void Font::createTexture()
{
OpenGL::TempDebugGroup debuggroup("Font create texture");
GLenum format = type == FONT_TRUETYPE ? GL_LUMINANCE_ALPHA : GL_RGBA;
size_t bpp = format == GL_LUMINANCE_ALPHA ? 2 : 4;
@@ -551,6 +553,8 @@ void Font::printv(const Matrix &t, const std::vector<DrawCommand> &drawcommands,
if (vertices.empty() || drawcommands.empty())
return;
OpenGL::TempDebugGroup debuggroup("Font print");
OpenGL::TempTransform transform(gl);
transform.get() *= t;
+6
View File
@@ -1100,6 +1100,8 @@ void Graphics::printf(const std::string &str, float x, float y, float wrap, Font
void Graphics::point(float x, float y)
{
OpenGL::TempDebugGroup debuggroup("Graphics point draw");
GLfloat coord[] = {x, y};
gl.prepareDraw();
@@ -1199,6 +1201,8 @@ void Graphics::arc(DrawMode mode, float x, float y, float radius, float angle1,
}
else
{
OpenGL::TempDebugGroup debuggroup("Filled arc draw");
gl.prepareDraw();
gl.bindTexture(gl.getDefaultTexture());
glEnableVertexAttribArray(ATTRIB_POS);
@@ -1223,6 +1227,8 @@ void Graphics::polygon(DrawMode mode, const float *coords, size_t count)
}
else
{
OpenGL::TempDebugGroup debuggroup("Filled polygon draw");
gl.prepareDraw();
gl.bindTexture(gl.getDefaultTexture());
glEnableVertexAttribArray(ATTRIB_POS);
+4
View File
@@ -195,6 +195,8 @@ void Image::loadFromImageData()
bool Image::loadVolatile()
{
OpenGL::TempDebugGroup debuggroup("Image load");
if (isCompressed() && !hasCompressedTextureSupport(cdata->getFormat(), flags.sRGB))
{
const char *str;
@@ -346,6 +348,8 @@ bool Image::refresh(int xoffset, int yoffset, int w, int h)
void Image::drawv(const Matrix &t, const Vertex *v)
{
OpenGL::TempDebugGroup debuggroup("Image draw");
OpenGL::TempTransform transform(gl);
transform.get() *= t;
+2
View File
@@ -317,6 +317,8 @@ void Mesh::draw(float x, float y, float angle, float sx, float sy, float ox, flo
if (vertex_count == 0)
return;
OpenGL::TempDebugGroup debuggroup("Mesh draw");
if (texture.get())
gl.bindTexture(*(GLuint *) texture->getHandle());
else
+2
View File
@@ -309,6 +309,8 @@ Matrix &OpenGL::getTransform()
void OpenGL::prepareDraw()
{
TempDebugGroup debuggroup("Prepare OpenGL draw");
Shader *shader = Shader::current;
if (shader != nullptr)
{
+24
View File
@@ -22,6 +22,7 @@
#define LOVE_GRAPHICS_OPENGL_OPENGL_H
// LOVE
#include "common/config.h"
#include "graphics/Color.h"
#include "graphics/Texture.h"
#include "common/Matrix.h"
@@ -135,6 +136,29 @@ public:
OpenGL &gl;
};
class TempDebugGroup
{
public:
#if defined(DEBUG) && DEBUG == 1
TempDebugGroup(const char *name)
{
if (GLAD_EXT_debug_marker)
glPushGroupMarkerEXT(0, (const GLchar *) name);
}
#else
TempDebugGroup(const char *) {}
#endif
#if defined(DEBUG) && DEBUG == 1
~TempDebugGroup()
{
if (GLAD_EXT_debug_marker)
glPopGroupMarkerEXT();
}
#endif
};
struct Stats
{
size_t textureMemory;
@@ -852,6 +852,8 @@ void ParticleSystem::draw(float x, float y, float angle, float sx, float sy, flo
if (pCount == 0 || texture.get() == nullptr || pMem == nullptr || particleVerts == nullptr)
return;
OpenGL::TempDebugGroup debuggroup("ParticleSystem draw");
Color curcolor = gl.getColor();
static Matrix t;
+2
View File
@@ -328,6 +328,8 @@ Polyline::~Polyline()
void Polyline::draw()
{
OpenGL::TempDebugGroup debuggroup("Line draw");
GLushort *indices = nullptr;
// TODO: We should probably be using a reusable index buffer.
+2
View File
@@ -210,6 +210,8 @@ void Shader::mapActiveUniforms()
bool Shader::loadVolatile()
{
OpenGL::TempDebugGroup debuggroup("Shader load");
// Recreating the shader program will invalidate uniforms that rely on these.
lastCanvas = (Canvas *) -1;
lastViewport = OpenGL::Viewport();
@@ -233,6 +233,8 @@ void SpriteBatch::draw(float x, float y, float angle, float sx, float sy, float
if (next == 0)
return;
OpenGL::TempDebugGroup debuggroup("SpriteBatch draw");
Matrix t(x, y, angle, sx, sy, ox, oy, kx, ky);
OpenGL::TempTransform transform(gl);
+2
View File
@@ -222,6 +222,8 @@ void Text::draw(float x, float y, float angle, float sx, float sy, float ox, flo
if (vbo == nullptr || draw_commands.empty())
return;
OpenGL::TempDebugGroup debuggroup("Text object draw");
// Re-generate the text if the Font's texture cache was invalidated.
if (font->getTextureCacheID() != texture_cache_id)
regenerateVertices();