Skip to content

Commit

Permalink
Fixes for Shader:getBufferFormat;
Browse files Browse the repository at this point in the history
  • Loading branch information
bjornbytes committed Jun 7, 2024
1 parent dbcfb01 commit 4b0a3c4
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 12 deletions.
27 changes: 21 additions & 6 deletions src/api/l_graphics_shader.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,14 +99,29 @@ static int l_lovrShaderGetBufferFormat(lua_State* L) {
return 1;
}

luax_pushbufferformat(L, format->fields, format->fieldCount);
lua_pushinteger(L, format->stride);
lua_setfield(L, -2, "stride");
// If the buffer just has a single array in it, unwrap it
if (format->fieldCount == 1 && format->fields->length > 0) {
const DataField* array = format->fields;

if (array->fields) { // Array of structs
luax_pushbufferformat(L, array->fields, array->fieldCount);
} else {
lua_createtable(L, 1, 1);
luax_pushenum(L, DataType, array->type);
lua_rawseti(L, -2, 1);
}

if (format->length == 0 || format->length == ~0u) {
lua_pushnil(L);
lua_pushinteger(L, array->stride);
lua_setfield(L, -2, "stride");

if (array->length == ~0u) {
lua_pushnil(L);
} else {
lua_pushinteger(L, array->length);
}
} else {
lua_pushinteger(L, format->length);
luax_pushbufferformat(L, format->fields, format->fieldCount);
lua_pushnil(L);
}

return 2;
Expand Down
6 changes: 0 additions & 6 deletions src/modules/graphics/graphics.c
Original file line number Diff line number Diff line change
Expand Up @@ -3091,12 +3091,6 @@ Shader* lovrShaderCreate(const ShaderInfo* info) {

if (buffer && resource->bufferFields) {
spv_field* field = &resource->bufferFields[0];

// Struct containing single item gets unwrapped
if (field->fieldCount == 1) {
field = &field->fields[0];
}

shader->resources[index].fieldCount = field->totalFieldCount + 1;
shader->resources[index].format = shader->fields + ((s == 1 ? spv[0].fieldCount : 0) + (field - spv[s].fields));
}
Expand Down

0 comments on commit 4b0a3c4

Please sign in to comment.