Alex Szpakowski avatar Alex Szpakowski committed 21e3088

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

Comments (0)

Files changed (3)

src/modules/graphics/opengl/wrap_Geometry.cpp

 // 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
 	{
 
 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;
 		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;
 
 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 }
 };
 

src/modules/graphics/opengl/wrap_Geometry.h

 {
 
 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

src/modules/graphics/opengl/wrap_Graphics.cpp

 		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);
 
 
 		lua_pop(L, 9);
 
+		if (v.r != 255 || v.g != 255 || v.b != 255 || v.a != 255)
+			hasvertexcolors = true;
+
 		vertices.push_back(v);
 	}
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.