mirror of https://github.com/bjornbytes/lovr.git
Mesh:isAttributeEnabled; Mesh:setAttributeEnabled;
This commit is contained in:
parent
faad61614f
commit
7648bffda7
|
@ -299,6 +299,21 @@ int l_lovrMeshSetVertexMap(lua_State* L) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int l_lovrMeshIsAttributeEnabled(lua_State* L) {
|
||||||
|
Mesh* mesh = luax_checktype(L, 1, Mesh);
|
||||||
|
const char* attribute = luaL_checkstring(L, 2);
|
||||||
|
lua_pushboolean(L, lovrMeshIsAttributeEnabled(mesh, attribute));
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int l_lovrMeshSetAttributeEnabled(lua_State* L) {
|
||||||
|
Mesh* mesh = luax_checktype(L, 1, Mesh);
|
||||||
|
const char* attribute = luaL_checkstring(L, 2);
|
||||||
|
int enabled = lua_toboolean(L, 3);
|
||||||
|
lovrMeshSetAttributeEnabled(mesh, attribute, enabled);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
int l_lovrMeshGetDrawRange(lua_State* L) {
|
int l_lovrMeshGetDrawRange(lua_State* L) {
|
||||||
Mesh* mesh = luax_checktype(L, 1, Mesh);
|
Mesh* mesh = luax_checktype(L, 1, Mesh);
|
||||||
if (!lovrMeshIsRangeEnabled(mesh)) {
|
if (!lovrMeshIsRangeEnabled(mesh)) {
|
||||||
|
@ -361,6 +376,8 @@ const luaL_Reg lovrMesh[] = {
|
||||||
{ "setVertices", l_lovrMeshSetVertices },
|
{ "setVertices", l_lovrMeshSetVertices },
|
||||||
{ "getVertexMap", l_lovrMeshGetVertexMap },
|
{ "getVertexMap", l_lovrMeshGetVertexMap },
|
||||||
{ "setVertexMap", l_lovrMeshSetVertexMap },
|
{ "setVertexMap", l_lovrMeshSetVertexMap },
|
||||||
|
{ "isAttributeEnabled", l_lovrMeshIsAttributeEnabled },
|
||||||
|
{ "setAttributeEnabled", l_lovrMeshSetAttributeEnabled },
|
||||||
{ "getDrawMode", l_lovrMeshGetDrawMode },
|
{ "getDrawMode", l_lovrMeshGetDrawMode },
|
||||||
{ "setDrawMode", l_lovrMeshSetDrawMode },
|
{ "setDrawMode", l_lovrMeshSetDrawMode },
|
||||||
{ "getDrawRange", l_lovrMeshGetDrawRange },
|
{ "getDrawRange", l_lovrMeshGetDrawRange },
|
||||||
|
|
|
@ -36,6 +36,7 @@ Mesh* lovrMeshCreate(int size, MeshFormat* format, MeshDrawMode drawMode, MeshUs
|
||||||
mesh->stride = stride;
|
mesh->stride = stride;
|
||||||
mesh->data = malloc(mesh->size * mesh->stride);
|
mesh->data = malloc(mesh->size * mesh->stride);
|
||||||
mesh->scratchVertex = malloc(mesh->stride);
|
mesh->scratchVertex = malloc(mesh->stride);
|
||||||
|
mesh->enabledAttributes = ~0;
|
||||||
mesh->drawMode = drawMode;
|
mesh->drawMode = drawMode;
|
||||||
mesh->usage = usage;
|
mesh->usage = usage;
|
||||||
mesh->vao = 0;
|
mesh->vao = 0;
|
||||||
|
@ -96,13 +97,15 @@ void lovrMeshDraw(Mesh* mesh, mat4 transform) {
|
||||||
int i;
|
int i;
|
||||||
MeshAttribute attribute;
|
MeshAttribute attribute;
|
||||||
vec_foreach(&mesh->format, attribute, i) {
|
vec_foreach(&mesh->format, attribute, i) {
|
||||||
int location = lovrShaderGetAttributeId(shader, attribute.name);
|
if (mesh->enabledAttributes & (1 << i)) {
|
||||||
if (location >= 0) {
|
int location = lovrShaderGetAttributeId(shader, attribute.name);
|
||||||
glEnableVertexAttribArray(location);
|
if (location >= 0) {
|
||||||
if (attribute.type == MESH_INT) {
|
glEnableVertexAttribArray(location);
|
||||||
glVertexAttribIPointer(location, attribute.count, attribute.type, mesh->stride, (void*) offset);
|
if (attribute.type == MESH_INT) {
|
||||||
} else {
|
glVertexAttribIPointer(location, attribute.count, attribute.type, mesh->stride, (void*) offset);
|
||||||
glVertexAttribPointer(location, attribute.count, attribute.type, GL_FALSE, mesh->stride, (void*) offset);
|
} else {
|
||||||
|
glVertexAttribPointer(location, attribute.count, attribute.type, GL_FALSE, mesh->stride, (void*) offset);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
offset += sizeof(attribute.type) * attribute.count;
|
offset += sizeof(attribute.type) * attribute.count;
|
||||||
|
@ -196,6 +199,34 @@ void lovrMeshSetVertexMap(Mesh* mesh, unsigned int* map, int count) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int lovrMeshIsAttributeEnabled(Mesh* mesh, const char* name) {
|
||||||
|
int i;
|
||||||
|
MeshAttribute attribute;
|
||||||
|
|
||||||
|
vec_foreach(&mesh->format, attribute, i) {
|
||||||
|
if (!strcmp(attribute.name, name)) {
|
||||||
|
return mesh->enabledAttributes & (1 << i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void lovrMeshSetAttributeEnabled(Mesh* mesh, const char* name, int enable) {
|
||||||
|
int i;
|
||||||
|
MeshAttribute attribute;
|
||||||
|
|
||||||
|
vec_foreach(&mesh->format, attribute, i) {
|
||||||
|
if (!strcmp(attribute.name, name)) {
|
||||||
|
if (enable) {
|
||||||
|
mesh->enabledAttributes |= 1 << i;
|
||||||
|
} else {
|
||||||
|
mesh->enabledAttributes &= ~(1 << i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int lovrMeshIsRangeEnabled(Mesh* mesh) {
|
int lovrMeshIsRangeEnabled(Mesh* mesh) {
|
||||||
return mesh->isRangeEnabled;
|
return mesh->isRangeEnabled;
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,6 +38,7 @@ typedef struct {
|
||||||
int stride;
|
int stride;
|
||||||
void* data;
|
void* data;
|
||||||
void* scratchVertex;
|
void* scratchVertex;
|
||||||
|
int enabledAttributes;
|
||||||
MeshFormat format;
|
MeshFormat format;
|
||||||
MeshDrawMode drawMode;
|
MeshDrawMode drawMode;
|
||||||
MeshUsage usage;
|
MeshUsage usage;
|
||||||
|
@ -65,6 +66,8 @@ void lovrMeshSetVertex(Mesh* mesh, int index, void* vertex);
|
||||||
void lovrMeshSetVertices(Mesh* mesh, void* vertices, int size);
|
void lovrMeshSetVertices(Mesh* mesh, void* vertices, int size);
|
||||||
unsigned int* lovrMeshGetVertexMap(Mesh* mesh, int* count);
|
unsigned int* lovrMeshGetVertexMap(Mesh* mesh, int* count);
|
||||||
void lovrMeshSetVertexMap(Mesh* mesh, unsigned int* map, int count);
|
void lovrMeshSetVertexMap(Mesh* mesh, unsigned int* map, int count);
|
||||||
|
int lovrMeshIsAttributeEnabled(Mesh* mesh, const char* name);
|
||||||
|
void lovrMeshSetAttributeEnabled(Mesh* mesh, const char* name, int enabled);
|
||||||
int lovrMeshIsRangeEnabled(Mesh* mesh);
|
int lovrMeshIsRangeEnabled(Mesh* mesh);
|
||||||
void lovrMeshSetRangeEnabled(Mesh* mesh, char isEnabled);
|
void lovrMeshSetRangeEnabled(Mesh* mesh, char isEnabled);
|
||||||
void lovrMeshGetDrawRange(Mesh* mesh, int* start, int* count);
|
void lovrMeshGetDrawRange(Mesh* mesh, int* start, int* count);
|
||||||
|
|
Loading…
Reference in New Issue