ソースを参照

moved Mesh:setWireframe to love.graphics.setWireframe (affects all draws until it's disabled.)

Wireframe mode should only be used for debugging: the wireframe lines behave differently than regular lines, their widths aren't affected by the graphics scale, and the mode isn't available on OpenGL ES.
Alex Szpakowski 11 年 前
コミット
b625bb6624

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

@@ -102,6 +102,8 @@ DisplayState Graphics::saveState()
 	for (int i = 0; i < 4; i++)
 		s.colorMask[i] = colorMask[i];
 
+	wireframe = isWireframe();
+
 	return s;
 }
 
@@ -119,6 +121,7 @@ void Graphics::restoreState(const DisplayState &s)
 	else
 		setScissor();
 	setColorMask(s.colorMask[0], s.colorMask[1], s.colorMask[2], s.colorMask[3]);
+	setWireframe(s.wireframe);
 }
 
 void Graphics::setViewportSize(int width, int height)
@@ -749,6 +752,17 @@ Graphics::PointStyle Graphics::getPointStyle() const
 		return POINT_ROUGH;
 }
 
+void Graphics::setWireframe(bool enable)
+{
+	wireframe = enable;
+	glPolygonMode(GL_FRONT_AND_BACK, enable ? GL_LINE : GL_FILL);
+}
+
+bool Graphics::isWireframe() const
+{
+	return wireframe;
+}
+
 void Graphics::print(const std::string &str, float x, float y , float angle, float sx, float sy, float ox, float oy, float kx, float ky)
 {
 	if (currentFont != nullptr)

+ 17 - 0
src/modules/graphics/opengl/Graphics.h

@@ -81,6 +81,8 @@ struct DisplayState
 	// Color mask.
 	bool colorMask[4];
 
+	bool wireframe;
+
 	// Default values.
 	DisplayState()
 	{
@@ -93,6 +95,7 @@ struct DisplayState
 		pointStyle = Graphics::POINT_SMOOTH;
 		scissor = false;
 		colorMask[0] = colorMask[1] = colorMask[2] = colorMask[3] = true;
+		wireframe = false;
 	}
 
 };
@@ -334,6 +337,19 @@ public:
 	 **/
 	PointStyle getPointStyle() const;
 
+	/**
+	 * Sets whether graphics will be drawn as wireframe lines instead of filled
+	 * triangles (has no effect for drawn 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);
+
+	/**
+	 * Gets whether wireframe drawing mode is enabled.
+	 **/
+	bool isWireframe() const;
+
 	/**
 	 * Draws text at the specified coordinates, with rotation and
 	 * scaling along both axes.
@@ -460,6 +476,7 @@ private:
 	GLint matrixLimit;
 	GLint userMatrices;
 	bool colorMask[4];
+	bool wireframe;
 
 	int width;
 	int height;

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

@@ -44,7 +44,6 @@ Mesh::Mesh(const std::vector<Vertex> &verts, Mesh::DrawMode mode)
 	, range_max(-1)
 	, texture(nullptr)
 	, colors_enabled(false)
-	, wireframe(false)
 {
 	setVertices(verts);
 }
@@ -59,7 +58,6 @@ Mesh::Mesh(int vertexcount, Mesh::DrawMode mode)
 	, range_max(-1)
 	, texture(nullptr)
 	, colors_enabled(false)
-	, wireframe(false)
 {
 	if (vertexcount < 1)
 		throw love::Exception("Invalid number of vertices.");
@@ -278,16 +276,6 @@ bool Mesh::hasVertexColors() const
 	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 size_t pos_offset   = offsetof(Vertex, x);
@@ -326,9 +314,6 @@ void Mesh::draw(float x, float y, float angle, float sx, float sy, float ox, flo
 		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);
 
 	gl.prepareDraw();
@@ -374,9 +359,6 @@ void Mesh::draw(float x, float y, float angle, float sx, float sy, float ox, flo
 			glDrawArrays(mode, min, max - min + 1);
 	}
 
-	if (wireframe)
-		glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
-
 	glDisableClientState(GL_VERTEX_ARRAY);
 	glDisableClientState(GL_TEXTURE_COORD_ARRAY);
 

+ 0 - 11
src/modules/graphics/opengl/Mesh.h

@@ -162,15 +162,6 @@ public:
 	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);
 
@@ -201,8 +192,6 @@ private:
 	// 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;
 

+ 14 - 0
src/modules/graphics/opengl/wrap_Graphics.cpp

@@ -844,6 +844,18 @@ int w_getMaxPointSize(lua_State *L)
 	return 1;
 }
 
+int w_setWireframe(lua_State *L)
+{
+	instance->setWireframe(luax_toboolean(L, 1));
+	return 0;
+}
+
+int w_isWireframe(lua_State *L)
+{
+	luax_pushboolean(L, instance->isWireframe());
+	return 1;
+}
+
 int w_newScreenshot(lua_State *L)
 {
 	love::image::Image *image = luax_getmodule<love::image::Image>(L, "image", MODULE_IMAGE_T);
@@ -1388,6 +1400,8 @@ static const luaL_Reg functions[] =
 	{ "setPointStyle", w_setPointStyle },
 	{ "getPointSize", w_getPointSize },
 	{ "getPointStyle", w_getPointStyle },
+	{ "setWireframe", w_setWireframe },
+	{ "isWireframe", w_isWireframe },
 	{ "newScreenshot", w_newScreenshot },
 	{ "setCanvas", w_setCanvas },
 	{ "getCanvas", w_getCanvas },

+ 2 - 0
src/modules/graphics/opengl/wrap_Graphics.h

@@ -85,6 +85,8 @@ int w_setPointStyle(lua_State *L);
 int w_getPointSize(lua_State *L);
 int w_getPointStyle(lua_State *L);
 int w_getMaxPointSize(lua_State *L);
+int w_setWireframe(lua_State *L);
+int w_isWireframe(lua_State *L);
 int w_newScreenshot(lua_State *L);
 int w_setCanvas(lua_State *L);
 int w_getCanvas(lua_State *L);

+ 0 - 16
src/modules/graphics/opengl/wrap_Mesh.cpp

@@ -361,20 +361,6 @@ int w_Mesh_hasVertexColors(lua_State *L)
 	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 },
@@ -394,8 +380,6 @@ static const luaL_Reg functions[] =
 	{ "getDrawRange", w_Mesh_getDrawRange },
 	{ "setVertexColors", w_Mesh_setVertexColors },
 	{ "hasVertexColors", w_Mesh_hasVertexColors },
-	{ "setWireframe", w_Mesh_setWireframe },
-	{ "isWireframe", w_Mesh_isWireframe },
 
 	// Deprecated since 0.9.1.
 	{ "setImage", w_Mesh_setTexture },

+ 0 - 2
src/modules/graphics/opengl/wrap_Mesh.h

@@ -51,8 +51,6 @@ int w_Mesh_setDrawRange(lua_State *L);
 int w_Mesh_getDrawRange(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);