ANY help would be greatly appreciated...
Code: Select all
static int lua_sceGumDrawArray(lua_State *L) {
int argc = lua_gettop(L);
if (argc != 3) return luaL_error(L, "wrong number of arguments");
int prim = luaL_checkint(L, 1);
int vtype = luaL_checkint(L, 2);
if (lua_type(L, 3) != LUA_TTABLE) return luaL_error(L, "vertices table missing");
int n = luaL_getn(L, 3);
int quads = 0;
int colorLuaIndex = -1;
if (vtype & GU_TEXTURE_32BITF) quads += 2;
if (vtype & GU_COLOR_8888) {
quads++;
colorLuaIndex = quads;
}
if (vtype & GU_NORMAL_32BITF) quads += 3;
if (vtype & GU_VERTEX_32BITF) quads += 3;
void* vertices = memalign(16, n * quads*4);
float* vertex = (float*) vertices;
int i;
for (i = 1; i <= n; ++i) {
// get vertice table
lua_rawgeti(L, 3, i);
int n2 = luaL_getn(L, -1);
if (n2 != quads) {
free(vertices);
return luaL_error(L, "wrong number of vertex components");
}
int j;
for (j = 1; j <= n2; ++j) {
lua_rawgeti(L, -1, j);
if (j != colorLuaIndex) {
*vertex = luaL_checknumber(L, -1);
} else {
*((Color*) vertex) = *toColor(L, -1);
}
lua_pop(L, 1); // removes 'value'
vertex++;
}
// remove vertice table
lua_pop(L, 1);
}
sceKernelDcacheWritebackInvalidateAll();
sceGumDrawArray(prim, vtype, n, NULL, vertices);
free(vertices);
return 0;
}