mirror of
https://github.com/love2d/love.git
synced 2026-08-16 00:02:12 +02:00
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.
This commit is contained in:
@@ -38,6 +38,7 @@ Mesh::Mesh(const std::vector<Vertex> &verts, Mesh::DrawMode mode)
|
||||
, draw_mode(mode)
|
||||
, image(nullptr)
|
||||
, colors_enabled(false)
|
||||
, wireframe(false)
|
||||
{
|
||||
setVertices(verts);
|
||||
}
|
||||
@@ -212,6 +213,16 @@ 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
|
||||
{
|
||||
const size_t pos_offset = offsetof(Vertex, x);
|
||||
@@ -250,6 +261,9 @@ 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);
|
||||
|
||||
if (ibo && element_count > 0)
|
||||
@@ -268,6 +282,9 @@ void Mesh::draw(float x, float y, float angle, float sx, float sy, float ox, flo
|
||||
glDrawArrays(mode, 0, vertex_count);
|
||||
}
|
||||
|
||||
if (wireframe)
|
||||
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
|
||||
|
||||
glDisableClientState(GL_VERTEX_ARRAY);
|
||||
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
|
||||
|
||||
@@ -138,6 +138,15 @@ 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) const;
|
||||
|
||||
@@ -163,6 +172,8 @@ 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;
|
||||
|
||||
|
||||
@@ -299,6 +299,20 @@ 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 },
|
||||
@@ -314,6 +328,8 @@ static const luaL_Reg functions[] =
|
||||
{ "getDrawMode", w_Mesh_getDrawMode },
|
||||
{ "setVertexColors", w_Mesh_setVertexColors },
|
||||
{ "hasVertexColors", w_Mesh_hasVertexColors },
|
||||
{ "setWireframe", w_Mesh_setWireframe },
|
||||
{ "isWireframe", w_Mesh_isWireframe },
|
||||
{ 0, 0 }
|
||||
};
|
||||
|
||||
|
||||
@@ -47,6 +47,8 @@ int w_Mesh_setDrawMode(lua_State *L);
|
||||
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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user