From b625bb6624ae07f7019c3d3fb45ff6e93e4fb8df Mon Sep 17 00:00:00 2001 From: Alex Szpakowski Date: Mon, 3 Feb 2014 04:59:58 -0400 Subject: [PATCH] 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. --- src/modules/graphics/opengl/Graphics.cpp | 14 ++++++++++++++ src/modules/graphics/opengl/Graphics.h | 17 +++++++++++++++++ src/modules/graphics/opengl/Mesh.cpp | 18 ------------------ src/modules/graphics/opengl/Mesh.h | 11 ----------- src/modules/graphics/opengl/wrap_Graphics.cpp | 14 ++++++++++++++ src/modules/graphics/opengl/wrap_Graphics.h | 2 ++ src/modules/graphics/opengl/wrap_Mesh.cpp | 16 ---------------- src/modules/graphics/opengl/wrap_Mesh.h | 2 -- 8 files changed, 47 insertions(+), 47 deletions(-) diff --git a/src/modules/graphics/opengl/Graphics.cpp b/src/modules/graphics/opengl/Graphics.cpp index 64298dc51..5df3d4d0a 100644 --- a/src/modules/graphics/opengl/Graphics.cpp +++ b/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) diff --git a/src/modules/graphics/opengl/Graphics.h b/src/modules/graphics/opengl/Graphics.h index 276b06378..b68755d08 100644 --- a/src/modules/graphics/opengl/Graphics.h +++ b/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; diff --git a/src/modules/graphics/opengl/Mesh.cpp b/src/modules/graphics/opengl/Mesh.cpp index d440bc786..62b8275c3 100644 --- a/src/modules/graphics/opengl/Mesh.cpp +++ b/src/modules/graphics/opengl/Mesh.cpp @@ -44,7 +44,6 @@ Mesh::Mesh(const std::vector &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); diff --git a/src/modules/graphics/opengl/Mesh.h b/src/modules/graphics/opengl/Mesh.h index 3a5029a4d..5e6e974fe 100644 --- a/src/modules/graphics/opengl/Mesh.h +++ b/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::Entry drawModeEntries[]; static StringMap drawModes; diff --git a/src/modules/graphics/opengl/wrap_Graphics.cpp b/src/modules/graphics/opengl/wrap_Graphics.cpp index 7cd02c52f..e7d6a6d74 100644 --- a/src/modules/graphics/opengl/wrap_Graphics.cpp +++ b/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(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 }, diff --git a/src/modules/graphics/opengl/wrap_Graphics.h b/src/modules/graphics/opengl/wrap_Graphics.h index 60c525121..85977cca6 100644 --- a/src/modules/graphics/opengl/wrap_Graphics.h +++ b/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); diff --git a/src/modules/graphics/opengl/wrap_Mesh.cpp b/src/modules/graphics/opengl/wrap_Mesh.cpp index 4548030a1..e3e8800b9 100644 --- a/src/modules/graphics/opengl/wrap_Mesh.cpp +++ b/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 }, diff --git a/src/modules/graphics/opengl/wrap_Mesh.h b/src/modules/graphics/opengl/wrap_Mesh.h index 9b4cdc77a..aa7c0f08b 100644 --- a/src/modules/graphics/opengl/wrap_Mesh.h +++ b/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);