mirror of https://github.com/bjornbytes/lovr.git
luax_pushvertex;
This commit is contained in:
parent
ea7f3d48a2
commit
dc801d8590
|
@ -62,24 +62,9 @@ int l_lovrMeshGetVertexCount(lua_State* L) {
|
|||
int l_lovrMeshGetVertex(lua_State* L) {
|
||||
Mesh* mesh = luax_checktype(L, 1, Mesh);
|
||||
int index = luaL_checkint(L, 2) - 1;
|
||||
char* vertex = lovrMeshMap(mesh, index, 1, true, false);
|
||||
uint8_t* vertex = lovrMeshMap(mesh, index, 1, true, false);
|
||||
VertexFormat format = lovrMeshGetVertexFormat(mesh);
|
||||
|
||||
int total = 0;
|
||||
for (int i = 0; i < format.length; i++) {
|
||||
Attribute attribute = format.data[i];
|
||||
total += attribute.count;
|
||||
for (int j = 0; j < attribute.count; j++) {
|
||||
switch (attribute.type) {
|
||||
case ATTR_FLOAT: lua_pushnumber(L, *((float*) vertex)); break;
|
||||
case ATTR_BYTE: lua_pushnumber(L, *((uint8_t*) vertex)); break;
|
||||
case ATTR_INT: lua_pushnumber(L, *((int*) vertex)); break;
|
||||
}
|
||||
vertex += AttributeSizes[attribute.type];
|
||||
}
|
||||
}
|
||||
|
||||
return total;
|
||||
return luax_pushvertex(L, vertex, format);
|
||||
}
|
||||
|
||||
int l_lovrMeshSetVertex(lua_State* L) {
|
||||
|
|
19
src/luax.c
19
src/luax.c
|
@ -196,3 +196,22 @@ Color luax_checkcolor(lua_State* L, int index) {
|
|||
|
||||
return color;
|
||||
}
|
||||
|
||||
int luax_pushvertex(lua_State* L, uint8_t* vertex, VertexFormat format) {
|
||||
int count = 0;
|
||||
|
||||
for (int i = 0; i < format.length; i++) {
|
||||
Attribute attribute = format.data[i];
|
||||
count += attribute.count;
|
||||
for (int j = 0; j < attribute.count; j++) {
|
||||
switch (attribute.type) {
|
||||
case ATTR_FLOAT: lua_pushnumber(L, *((float*) vertex)); break;
|
||||
case ATTR_BYTE: lua_pushnumber(L, *((uint8_t*) vertex)); break;
|
||||
case ATTR_INT: lua_pushnumber(L, *((int*) vertex)); break;
|
||||
}
|
||||
vertex += AttributeSizes[attribute.type];
|
||||
}
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
#include <lauxlib.h>
|
||||
#include <lualib.h>
|
||||
#include "lib/map/map.h"
|
||||
#include "lib/vertex.h"
|
||||
#include "util.h"
|
||||
|
||||
#pragma once
|
||||
|
@ -42,3 +43,4 @@ void luax_pushenum(lua_State* L, map_int_t* map, int value);
|
|||
void* luax_checkenum(lua_State* L, int index, map_int_t* map, const char* typeName);
|
||||
void* luax_optenum(lua_State* L, int index, const char* fallback, map_int_t* map, const char* typeName);
|
||||
Color luax_checkcolor(lua_State* L, int index);
|
||||
int luax_pushvertex(lua_State* L, uint8_t* vertex, VertexFormat format);
|
||||
|
|
Loading…
Reference in New Issue