Commits

Alex Szpakowski committed 75ecde9

Added Mesh:setWireframe and Mesh:isWireframe.

This should *only* be used for debugging: the wireframe lines behave differently from regular love.graphics lines, and the functionality may not work on OpenGL ES.

Comments (0)

Files changed (4)

src/modules/graphics/opengl/Mesh.cpp

 	, draw_mode(mode)
 	, image(nullptr)
 	, colors_enabled(false)
+	, wireframe(false)
 {
 	setVertices(verts);
 }
 	return colors_enabled;
 }
 
+void Mesh::setWireframe(bool enable)
+{
+	wireframe = enable;
+}
+
+bool Mesh::isWireframe() const
+{
+	return wireframe;
+}
+
 void Mesh::draw(float x, float y, float angle, float sx, float sy, float ox, float oy, float kx, float ky) const
 {
 	const size_t pos_offset   = offsetof(Vertex, x);
 		glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(Vertex), vbo->getPointer(color_offset));
 	}
 
+	if (wireframe)
+		glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
+
 	GLenum mode = getGLDrawMode(draw_mode);
 
 	if (ibo && element_count > 0)
 		glDrawArrays(mode, 0, vertex_count);
 	}
 
+	if (wireframe)
+		glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
+
 	glDisableClientState(GL_VERTEX_ARRAY);
 	glDisableClientState(GL_TEXTURE_COORD_ARRAY);
 

src/modules/graphics/opengl/Mesh.h

 	void setVertexColors(bool enable);
 	bool hasVertexColors() const;
 
+	/**
+	 * Sets whether the Mesh will be drawn as wireframe lines instead of filled
+	 * triangles (has no effect for DRAW_MODE_POINTS.)
+	 * This should only be used as a debugging tool. The wireframe lines do not
+	 * behave the same as regular love.graphics lines.
+	 **/
+	void setWireframe(bool enable);
+	bool isWireframe() const;
+
 	// Implements Drawable.
 	void draw(float x, float y, float angle, float sx, float sy, float ox, float oy, float kx, float ky) const;
 
 	// Whether the per-vertex colors are used when drawing.
 	bool colors_enabled;
 
+	bool wireframe;
+
 	static StringMap<DrawMode, DRAW_MODE_MAX_ENUM>::Entry drawModeEntries[];
 	static StringMap<DrawMode, DRAW_MODE_MAX_ENUM> drawModes;
 

src/modules/graphics/opengl/wrap_Mesh.cpp

 	return 1;
 }
 
+int w_Mesh_setWireframe(lua_State *L)
+{
+	Mesh *t = luax_checkmesh(L, 1);
+	t->setWireframe(luax_toboolean(L, 2));
+	return 0;
+}
+
+int w_Mesh_isWireframe(lua_State *L)
+{
+	Mesh *t = luax_checkmesh(L, 1);
+	luax_pushboolean(L, t->isWireframe());
+	return 1;
+}
+
 static const luaL_Reg functions[] =
 {
 	{ "setVertex", w_Mesh_setVertex },
 	{ "getDrawMode", w_Mesh_getDrawMode },
 	{ "setVertexColors", w_Mesh_setVertexColors },
 	{ "hasVertexColors", w_Mesh_hasVertexColors },
+	{ "setWireframe", w_Mesh_setWireframe },
+	{ "isWireframe", w_Mesh_isWireframe },
 	{ 0, 0 }
 };
 

src/modules/graphics/opengl/wrap_Mesh.h

 int w_Mesh_getDrawMode(lua_State *L);
 int w_Mesh_setVertexColors(lua_State *L);
 int w_Mesh_hasVertexColors(lua_State *L);
+int w_Mesh_setWireframe(lua_State *L);
+int w_Mesh_isWireframe(lua_State *L);
 
 extern "C" int luaopen_mesh(lua_State *L);