mirror of https://github.com/bjornbytes/lovr.git
Fix vertex format binding;
This commit is contained in:
parent
7e5221492d
commit
3b33f4917e
|
@ -4011,57 +4011,55 @@ static void bindPipeline(Pass* pass, Draw* draw, Shader* shader) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Vertex formats
|
// Vertex formats
|
||||||
if (pipeline->formatHash != 1 + draw->vertex.format) {
|
if (draw->vertex.buffer && pipeline->formatHash != draw->vertex.buffer->hash) {
|
||||||
if (!draw->vertex.buffer) {
|
pipeline->formatHash = draw->vertex.buffer->hash;
|
||||||
pipeline->formatHash = 1 + draw->vertex.format;
|
pipeline->info.vertex.bufferCount = 2;
|
||||||
pipeline->info.vertex = state.vertexFormats[draw->vertex.format];
|
pipeline->info.vertex.attributeCount = shader->attributeCount;
|
||||||
pipeline->dirty = true;
|
pipeline->info.vertex.bufferStrides[0] = draw->vertex.buffer->info.stride;
|
||||||
|
pipeline->info.vertex.bufferStrides[1] = 0;
|
||||||
|
pipeline->dirty = true;
|
||||||
|
|
||||||
if (shader->hasCustomAttributes) {
|
for (uint32_t i = 0; i < shader->attributeCount; i++) {
|
||||||
for (uint32_t i = 0; i < shader->attributeCount; i++) {
|
ShaderAttribute* attribute = &shader->attributes[i];
|
||||||
if (shader->attributes[i].location < 10) {
|
bool found = false;
|
||||||
pipeline->info.vertex.attributes[pipeline->info.vertex.attributeCount++] = (gpu_attribute) {
|
|
||||||
.buffer = 1,
|
for (uint32_t j = 0; j < draw->vertex.buffer->info.fieldCount; j++) {
|
||||||
.location = shader->attributes[i].location,
|
BufferField field = draw->vertex.buffer->info.fields[j];
|
||||||
.type = GPU_TYPE_F32x4,
|
lovrCheck(field.type < FIELD_MAT2, "Currently, matrix and index types can not be used in vertex buffers");
|
||||||
.offset = shader->attributes[i].location == LOCATION_COLOR ? 16 : 0
|
if (field.hash ? (field.hash == attribute->hash) : (field.location == attribute->location)) {
|
||||||
};
|
pipeline->info.vertex.attributes[i] = (gpu_attribute) {
|
||||||
}
|
.buffer = 0,
|
||||||
|
.location = attribute->location,
|
||||||
|
.offset = field.offset,
|
||||||
|
.type = field.type
|
||||||
|
};
|
||||||
|
found = true;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
pipeline->formatHash = draw->vertex.buffer->hash;
|
|
||||||
pipeline->info.vertex.bufferCount = 2;
|
|
||||||
pipeline->info.vertex.attributeCount = shader->attributeCount;
|
|
||||||
pipeline->info.vertex.bufferStrides[0] = draw->vertex.buffer->info.stride;
|
|
||||||
pipeline->info.vertex.bufferStrides[1] = 0;
|
|
||||||
pipeline->dirty = true;
|
|
||||||
|
|
||||||
|
if (!found) {
|
||||||
|
pipeline->info.vertex.attributes[i] = (gpu_attribute) {
|
||||||
|
.buffer = 1,
|
||||||
|
.location = attribute->location,
|
||||||
|
.offset = attribute->location == LOCATION_COLOR ? 16 : 0,
|
||||||
|
.type = GPU_TYPE_F32x4
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (!draw->vertex.buffer && pipeline->formatHash != 1 + draw->vertex.format) {
|
||||||
|
pipeline->formatHash = 1 + draw->vertex.format;
|
||||||
|
pipeline->info.vertex = state.vertexFormats[draw->vertex.format];
|
||||||
|
pipeline->dirty = true;
|
||||||
|
|
||||||
|
if (shader->hasCustomAttributes) {
|
||||||
for (uint32_t i = 0; i < shader->attributeCount; i++) {
|
for (uint32_t i = 0; i < shader->attributeCount; i++) {
|
||||||
ShaderAttribute* attribute = &shader->attributes[i];
|
if (shader->attributes[i].location < 10) {
|
||||||
bool found = false;
|
pipeline->info.vertex.attributes[pipeline->info.vertex.attributeCount++] = (gpu_attribute) {
|
||||||
|
|
||||||
for (uint32_t j = 0; j < draw->vertex.buffer->info.fieldCount; j++) {
|
|
||||||
BufferField field = draw->vertex.buffer->info.fields[j];
|
|
||||||
lovrCheck(field.type < FIELD_MAT2, "Currently, matrix and index types can not be used in vertex buffers");
|
|
||||||
if (field.hash ? (field.hash == attribute->hash) : (field.location == attribute->location)) {
|
|
||||||
pipeline->info.vertex.attributes[i] = (gpu_attribute) {
|
|
||||||
.buffer = 0,
|
|
||||||
.location = attribute->location,
|
|
||||||
.offset = field.offset,
|
|
||||||
.type = field.type
|
|
||||||
};
|
|
||||||
found = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!found) {
|
|
||||||
pipeline->info.vertex.attributes[i] = (gpu_attribute) {
|
|
||||||
.buffer = 1,
|
.buffer = 1,
|
||||||
.location = attribute->location,
|
.location = shader->attributes[i].location,
|
||||||
.offset = attribute->location == LOCATION_COLOR ? 16 : 0,
|
.type = GPU_TYPE_F32x4,
|
||||||
.type = GPU_TYPE_F32x4
|
.offset = shader->attributes[i].location == LOCATION_COLOR ? 16 : 0
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue