1
0
Fork 0
mirror of https://github.com/bjornbytes/lovr.git synced 2024-07-02 12:33:52 +00:00

Mesh: more flexible int attributes;

This is ugh but be patient.
This commit is contained in:
bjorn 2018-12-10 15:58:50 -08:00
parent eaf26ce4b8
commit aa2f8867ee
2 changed files with 18 additions and 6 deletions

View file

@ -15,6 +15,7 @@ typedef struct {
AttributeType type;
uint8_t components;
uint8_t divisor;
bool integer;
bool enabled;
} MeshAttribute;

View file

@ -2277,10 +2277,11 @@ Mesh* lovrMeshCreate(uint32_t count, VertexFormat format, MeshDrawMode drawMode,
lovrRetain(mesh->vbo);
map_set(&mesh->attributes, format.attributes[i].name, ((MeshAttribute) {
.buffer = mesh->vbo,
.type = format.attributes[i].type,
.components = format.attributes[i].count,
.offset = format.attributes[i].offset,
.stride = format.stride,
.type = format.attributes[i].type,
.components = format.attributes[i].count,
.integer = format.attributes[i].type == ATTR_INT,
.enabled = true
}));
}
@ -2378,10 +2379,20 @@ void lovrMeshBind(Mesh* mesh, Shader* shader, int divisorMultiplier) {
int count = current.components;
int stride = current.stride;
GLvoid* offset = (GLvoid*) current.offset;
switch (current.type) {
case ATTR_FLOAT: glVertexAttribPointer(i, count, GL_FLOAT, GL_TRUE, stride, offset); break;
case ATTR_BYTE: glVertexAttribPointer(i, count, GL_UNSIGNED_BYTE, GL_TRUE, stride, offset); break;
case ATTR_INT: glVertexAttribIPointer(i, count, GL_INT, stride, offset); break;
// TODO
if (current.integer) {
switch (current.type) {
case ATTR_BYTE: glVertexAttribIPointer(i, count, GL_UNSIGNED_BYTE, stride, offset); break;
case ATTR_INT: glVertexAttribIPointer(i, count, GL_INT, stride, offset); break;
default: lovrThrow("Cannot use float data for int attribute");
}
} else {
switch (current.type) {
case ATTR_FLOAT: glVertexAttribPointer(i, count, GL_FLOAT, GL_TRUE, stride, offset); break;
case ATTR_BYTE: glVertexAttribPointer(i, count, GL_UNSIGNED_BYTE, GL_TRUE, stride, offset); break;
case ATTR_INT: glVertexAttribPointer(i, count, GL_INT, GL_TRUE, stride, offset); break;
}
}
}
}