Browse Source

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.

Alex Szpakowski 10 years ago
parent
commit
06ef263537

+ 12 - 0
src/modules/graphics/opengl/Canvas.cpp

@@ -198,6 +198,8 @@ bool Canvas::createMSAAFBO(GLenum internalformat)
 
 
 bool Canvas::loadVolatile()
 bool Canvas::loadVolatile()
 {
 {
+	OpenGL::TempDebugGroup debuggroup("Canvas load");
+
 	fbo = depth_stencil = texture = 0;
 	fbo = depth_stencil = texture = 0;
 	resolve_fbo = msaa_buffer = 0;
 	resolve_fbo = msaa_buffer = 0;
 	status = GL_FRAMEBUFFER_COMPLETE;
 	status = GL_FRAMEBUFFER_COMPLETE;
@@ -298,6 +300,8 @@ void Canvas::unloadVolatile()
 
 
 void Canvas::drawv(const Matrix &t, const Vertex *v)
 void Canvas::drawv(const Matrix &t, const Vertex *v)
 {
 {
+	OpenGL::TempDebugGroup debuggroup("Canvas draw");
+
 	OpenGL::TempTransform transform(gl);
 	OpenGL::TempTransform transform(gl);
 	transform.get() *= t;
 	transform.get() *= t;
 
 
@@ -439,6 +443,8 @@ void Canvas::startGrab(const std::vector<Canvas *> &canvases)
 			canvaseschanged = true;
 			canvaseschanged = true;
 	}
 	}
 
 
+	OpenGL::TempDebugGroup debuggroup("Canvas set");
+
 	setupGrab();
 	setupGrab();
 
 
 	// Don't attach anything if there's nothing to change.
 	// 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()
 void Canvas::startGrab()
 {
 {
+	OpenGL::TempDebugGroup debuggroup("Canvas set");
+
 	setupGrab();
 	setupGrab();
 
 
 	if (attachedCanvases.size() == 0)
 	if (attachedCanvases.size() == 0)
@@ -488,6 +496,8 @@ void Canvas::stopGrab(bool switchingToOtherCanvas)
 	if (current != this)
 	if (current != this)
 		return;
 		return;
 
 
+	OpenGL::TempDebugGroup debuggroup("Canvas un-set");
+
 	// Make sure the canvas texture is up to date if we're using MSAA.
 	// Make sure the canvas texture is up to date if we're using MSAA.
 	resolveMSAA(false);
 	resolveMSAA(false);
 
 
@@ -524,6 +534,8 @@ bool Canvas::checkCreateStencil()
 	if (depth_stencil != 0)
 	if (depth_stencil != 0)
 		return true;
 		return true;
 
 
+	OpenGL::TempDebugGroup debuggroup("Canvas create stencil");
+
 	if (current != this)
 	if (current != this)
 		gl.bindFramebuffer(GL_FRAMEBUFFER, fbo);
 		gl.bindFramebuffer(GL_FRAMEBUFFER, fbo);
 
 

+ 4 - 0
src/modules/graphics/opengl/Font.cpp

@@ -109,6 +109,8 @@ Font::TextureSize Font::getNextTextureSize() const
 
 
 void Font::createTexture()
 void Font::createTexture()
 {
 {
+	OpenGL::TempDebugGroup debuggroup("Font create texture");
+
 	GLenum format = type == FONT_TRUETYPE ? GL_LUMINANCE_ALPHA : GL_RGBA;
 	GLenum format = type == FONT_TRUETYPE ? GL_LUMINANCE_ALPHA : GL_RGBA;
 	size_t bpp = format == GL_LUMINANCE_ALPHA ? 2 : 4;
 	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())
 	if (vertices.empty() || drawcommands.empty())
 		return;
 		return;
 
 
+	OpenGL::TempDebugGroup debuggroup("Font print");
+
 	OpenGL::TempTransform transform(gl);
 	OpenGL::TempTransform transform(gl);
 	transform.get() *= t;
 	transform.get() *= t;
 
 

+ 6 - 0
src/modules/graphics/opengl/Graphics.cpp

@@ -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)
 void Graphics::point(float x, float y)
 {
 {
+	OpenGL::TempDebugGroup debuggroup("Graphics point draw");
+
 	GLfloat coord[] = {x, y};
 	GLfloat coord[] = {x, y};
 
 
 	gl.prepareDraw();
 	gl.prepareDraw();
@@ -1199,6 +1201,8 @@ void Graphics::arc(DrawMode mode, float x, float y, float radius, float angle1,
 	}
 	}
 	else
 	else
 	{
 	{
+		OpenGL::TempDebugGroup debuggroup("Filled arc draw");
+
 		gl.prepareDraw();
 		gl.prepareDraw();
 		gl.bindTexture(gl.getDefaultTexture());
 		gl.bindTexture(gl.getDefaultTexture());
 		glEnableVertexAttribArray(ATTRIB_POS);
 		glEnableVertexAttribArray(ATTRIB_POS);
@@ -1223,6 +1227,8 @@ void Graphics::polygon(DrawMode mode, const float *coords, size_t count)
 	}
 	}
 	else
 	else
 	{
 	{
+		OpenGL::TempDebugGroup debuggroup("Filled polygon draw");
+
 		gl.prepareDraw();
 		gl.prepareDraw();
 		gl.bindTexture(gl.getDefaultTexture());
 		gl.bindTexture(gl.getDefaultTexture());
 		glEnableVertexAttribArray(ATTRIB_POS);
 		glEnableVertexAttribArray(ATTRIB_POS);

+ 4 - 0
src/modules/graphics/opengl/Image.cpp

@@ -195,6 +195,8 @@ void Image::loadFromImageData()
 
 
 bool Image::loadVolatile()
 bool Image::loadVolatile()
 {
 {
+	OpenGL::TempDebugGroup debuggroup("Image load");
+
 	if (isCompressed() && !hasCompressedTextureSupport(cdata->getFormat(), flags.sRGB))
 	if (isCompressed() && !hasCompressedTextureSupport(cdata->getFormat(), flags.sRGB))
 	{
 	{
 		const char *str;
 		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)
 void Image::drawv(const Matrix &t, const Vertex *v)
 {
 {
+	OpenGL::TempDebugGroup debuggroup("Image draw");
+
 	OpenGL::TempTransform transform(gl);
 	OpenGL::TempTransform transform(gl);
 	transform.get() *= t;
 	transform.get() *= t;
 
 

+ 2 - 0
src/modules/graphics/opengl/Mesh.cpp

@@ -317,6 +317,8 @@ void Mesh::draw(float x, float y, float angle, float sx, float sy, float ox, flo
 	if (vertex_count == 0)
 	if (vertex_count == 0)
 		return;
 		return;
 
 
+	OpenGL::TempDebugGroup debuggroup("Mesh draw");
+
 	if (texture.get())
 	if (texture.get())
 		gl.bindTexture(*(GLuint *) texture->getHandle());
 		gl.bindTexture(*(GLuint *) texture->getHandle());
 	else
 	else

+ 2 - 0
src/modules/graphics/opengl/OpenGL.cpp

@@ -309,6 +309,8 @@ Matrix &OpenGL::getTransform()
 
 
 void OpenGL::prepareDraw()
 void OpenGL::prepareDraw()
 {
 {
+	TempDebugGroup debuggroup("Prepare OpenGL draw");
+
 	Shader *shader = Shader::current;
 	Shader *shader = Shader::current;
 	if (shader != nullptr)
 	if (shader != nullptr)
 	{
 	{

+ 24 - 0
src/modules/graphics/opengl/OpenGL.h

@@ -22,6 +22,7 @@
 #define LOVE_GRAPHICS_OPENGL_OPENGL_H
 #define LOVE_GRAPHICS_OPENGL_OPENGL_H
 
 
 // LOVE
 // LOVE
+#include "common/config.h"
 #include "graphics/Color.h"
 #include "graphics/Color.h"
 #include "graphics/Texture.h"
 #include "graphics/Texture.h"
 #include "common/Matrix.h"
 #include "common/Matrix.h"
@@ -135,6 +136,29 @@ public:
 		OpenGL &gl;
 		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
 	struct Stats
 	{
 	{
 		size_t textureMemory;
 		size_t textureMemory;

+ 2 - 0
src/modules/graphics/opengl/ParticleSystem.cpp

@@ -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)
 	if (pCount == 0 || texture.get() == nullptr || pMem == nullptr || particleVerts == nullptr)
 		return;
 		return;
 
 
+	OpenGL::TempDebugGroup debuggroup("ParticleSystem draw");
+
 	Color curcolor = gl.getColor();
 	Color curcolor = gl.getColor();
 
 
 	static Matrix t;
 	static Matrix t;

+ 2 - 0
src/modules/graphics/opengl/Polyline.cpp

@@ -328,6 +328,8 @@ Polyline::~Polyline()
 
 
 void Polyline::draw()
 void Polyline::draw()
 {
 {
+	OpenGL::TempDebugGroup debuggroup("Line draw");
+
 	GLushort *indices = nullptr;
 	GLushort *indices = nullptr;
 
 
 	// TODO: We should probably be using a reusable index buffer.
 	// TODO: We should probably be using a reusable index buffer.

+ 2 - 0
src/modules/graphics/opengl/Shader.cpp

@@ -210,6 +210,8 @@ void Shader::mapActiveUniforms()
 
 
 bool Shader::loadVolatile()
 bool Shader::loadVolatile()
 {
 {
+	OpenGL::TempDebugGroup debuggroup("Shader load");
+
     // Recreating the shader program will invalidate uniforms that rely on these.
     // Recreating the shader program will invalidate uniforms that rely on these.
     lastCanvas = (Canvas *) -1;
     lastCanvas = (Canvas *) -1;
     lastViewport = OpenGL::Viewport();
     lastViewport = OpenGL::Viewport();

+ 2 - 0
src/modules/graphics/opengl/SpriteBatch.cpp

@@ -233,6 +233,8 @@ void SpriteBatch::draw(float x, float y, float angle, float sx, float sy, float
 	if (next == 0)
 	if (next == 0)
 		return;
 		return;
 
 
+	OpenGL::TempDebugGroup debuggroup("SpriteBatch draw");
+
 	Matrix t(x, y, angle, sx, sy, ox, oy, kx, ky);
 	Matrix t(x, y, angle, sx, sy, ox, oy, kx, ky);
 
 
 	OpenGL::TempTransform transform(gl);
 	OpenGL::TempTransform transform(gl);

+ 2 - 0
src/modules/graphics/opengl/Text.cpp

@@ -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())
 	if (vbo == nullptr || draw_commands.empty())
 		return;
 		return;
 
 
+	OpenGL::TempDebugGroup debuggroup("Text object draw");
+
 	// Re-generate the text if the Font's texture cache was invalidated.
 	// Re-generate the text if the Font's texture cache was invalidated.
 	if (font->getTextureCacheID() != texture_cache_id)
 	if (font->getTextureCacheID() != texture_cache_id)
 		regenerateVertices();
 		regenerateVertices();