mirror of
https://github.com/love2d/love.git
synced 2026-08-16 08:11:02 +02:00
Exposed Geometry:setVertexColors and Geometry:hasVertexColors, to enable/disable per-vertex colors.
Vertex colors are automatically enabled if newGeometry or setVertex is called with a color other than 255,255,255,255
This commit is contained in:
@@ -37,14 +37,14 @@ Geometry *luax_checkgeometry(lua_State *L, int idx)
|
||||
// different name than in Geometry.cpp to make the triangulation transparent
|
||||
int w_Geometry_getVertexCount(lua_State *L)
|
||||
{
|
||||
Geometry *geom = luax_checktype<Geometry>(L, 1, "Geometry", GRAPHICS_GEOMETRY_T);
|
||||
Geometry *geom = luax_checkgeometry(L, 1);
|
||||
lua_pushinteger(L, geom->getNumVertices());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_Geometry_getVertex(lua_State *L)
|
||||
{
|
||||
Geometry *geom = luax_checktype<Geometry>(L, 1, "Geometry", GRAPHICS_GEOMETRY_T);
|
||||
Geometry *geom = luax_checkgeometry(L, 1);
|
||||
size_t i = size_t(luaL_checkint(L, 2));
|
||||
try
|
||||
{
|
||||
@@ -68,7 +68,7 @@ int w_Geometry_getVertex(lua_State *L)
|
||||
|
||||
int w_Geometry_setVertex(lua_State *L)
|
||||
{
|
||||
Geometry *geom = luax_checktype<Geometry>(L, 1, "Geometry", GRAPHICS_GEOMETRY_T);
|
||||
Geometry *geom = luax_checkgeometry(L, 1);
|
||||
size_t i = size_t(luaL_checkint(L, 2));
|
||||
|
||||
vertex v;
|
||||
@@ -90,7 +90,7 @@ int w_Geometry_setVertex(lua_State *L)
|
||||
return luaL_error(L, e.what());
|
||||
}
|
||||
|
||||
if (lua_gettop(L) > 6)
|
||||
if (v.r != 255 || v.g != 255 || v.b != 255 || v.a != 255)
|
||||
geom->setVertexColors(true);
|
||||
|
||||
return 0;
|
||||
@@ -98,17 +98,33 @@ int w_Geometry_setVertex(lua_State *L)
|
||||
|
||||
int w_Geometry_flip(lua_State *L)
|
||||
{
|
||||
Geometry *geom = luax_checktype<Geometry>(L, 1, "Geometry", GRAPHICS_GEOMETRY_T);
|
||||
Geometry *geom = luax_checkgeometry(L, 1);
|
||||
geom->flip(luax_toboolean(L, 2), luax_toboolean(L, 3));
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_Geometry_setVertexColors(lua_State *L)
|
||||
{
|
||||
Geometry *geom = luax_checkgeometry(L, 1);
|
||||
geom->setVertexColors(luax_toboolean(L, 2));
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_Geometry_hasVertexColors(lua_State *L)
|
||||
{
|
||||
Geometry *geom = luax_checkgeometry(L, 1);
|
||||
luax_pushboolean(L, geom->hasVertexColors());
|
||||
return 1;
|
||||
}
|
||||
|
||||
static const luaL_Reg w_Geometry_functions[] =
|
||||
{
|
||||
{ "getVertexCount", w_Geometry_getVertexCount },
|
||||
{ "getVertex", w_Geometry_getVertex },
|
||||
{ "setVertex", w_Geometry_setVertex },
|
||||
{ "flip", w_Geometry_flip },
|
||||
{ "setVertexColors", w_Geometry_setVertexColors },
|
||||
{ "hasVertexColors", w_Geometry_hasVertexColors },
|
||||
{ 0, 0 }
|
||||
};
|
||||
|
||||
|
||||
@@ -33,10 +33,12 @@ namespace opengl
|
||||
{
|
||||
|
||||
Geometry *luax_checkgeometry(lua_State *L, int idx);
|
||||
int w_Geometry_flip(lua_State *L);
|
||||
int w_Geometry_getVertexCount(lua_State *L);
|
||||
int w_Geometry_getVertex(lua_State *L);
|
||||
int w_Geometry_setVertex(lua_State *L);
|
||||
int w_Geometry_flip(lua_State *L);
|
||||
int w_Geometry_setVertexColors(lua_State *L);
|
||||
int w_Geometry_hasVertexColors(lua_State *L);
|
||||
extern "C" int luaopen_geometry(lua_State *L);
|
||||
|
||||
} // opengl
|
||||
|
||||
@@ -391,9 +391,6 @@ int w_newGeometry(lua_State *L)
|
||||
if (!lua_istable(L, -1))
|
||||
return luaL_typerror(L, 1, "table of tables");
|
||||
|
||||
if (lua_objlen(L, -1) > 4)
|
||||
hasvertexcolors = true;
|
||||
|
||||
for (int j = 1; j <= 8; j++)
|
||||
lua_rawgeti(L, -j, j);
|
||||
|
||||
@@ -410,6 +407,9 @@ int w_newGeometry(lua_State *L)
|
||||
|
||||
lua_pop(L, 9);
|
||||
|
||||
if (v.r != 255 || v.g != 255 || v.b != 255 || v.a != 255)
|
||||
hasvertexcolors = true;
|
||||
|
||||
vertices.push_back(v);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user