mirror of https://github.com/bjornbytes/lovr.git
Make indirect draws a :mesh variant;
This commit is contained in:
parent
fcbeccdfb1
commit
2a3215fa05
|
@ -823,24 +823,20 @@ static int l_lovrPassMesh(lua_State* L) {
|
||||||
Pass* pass = luax_checktype(L, 1, Pass);
|
Pass* pass = luax_checktype(L, 1, Pass);
|
||||||
Buffer* vertices = !lua_toboolean(L, 2) ? NULL : luax_checktype(L, 2, Buffer);
|
Buffer* vertices = !lua_toboolean(L, 2) ? NULL : luax_checktype(L, 2, Buffer);
|
||||||
Buffer* indices = luax_totype(L, 3, Buffer);
|
Buffer* indices = luax_totype(L, 3, Buffer);
|
||||||
float transform[16];
|
Buffer* indirect = luax_totype(L, 4, Buffer);
|
||||||
int index = luax_readmat4(L, indices ? 4 : 3, transform, 1);
|
if (indirect) {
|
||||||
uint32_t start = luax_optu32(L, index++, 1) - 1;
|
uint32_t count = luax_optu32(L, 5, 1);
|
||||||
uint32_t count = luax_optu32(L, index++, ~0u);
|
uint32_t offset = luax_optu32(L, 6, 0);
|
||||||
uint32_t instances = luax_optu32(L, index, 1);
|
uint32_t stride = luax_optu32(L, 7, 0);
|
||||||
lovrPassMesh(pass, vertices, indices, transform, start, count, instances);
|
lovrPassMeshIndirect(pass, vertices, indices, indirect, count, offset, stride);
|
||||||
return 0;
|
} else {
|
||||||
}
|
float transform[16];
|
||||||
|
int index = luax_readmat4(L, indices ? 4 : 3, transform, 1);
|
||||||
static int l_lovrPassMultimesh(lua_State* L) {
|
uint32_t start = luax_optu32(L, index++, 1) - 1;
|
||||||
Pass* pass = luax_checktype(L, 1, Pass);
|
uint32_t count = luax_optu32(L, index++, ~0u);
|
||||||
Buffer* vertices = !lua_toboolean(L, 2) ? NULL : luax_totype(L, 2, Buffer);
|
uint32_t instances = luax_optu32(L, index, 1);
|
||||||
Buffer* indices = luax_totype(L, 3, Buffer);
|
lovrPassMesh(pass, vertices, indices, transform, start, count, instances);
|
||||||
Buffer* draws = luax_checktype(L, 4, Buffer);
|
}
|
||||||
uint32_t count = luax_optu32(L, 5, 1);
|
|
||||||
uint32_t offset = luax_optu32(L, 6, 0);
|
|
||||||
uint32_t stride = luax_optu32(L, 7, 0);
|
|
||||||
lovrPassMultimesh(pass, vertices, indices, draws, count, offset, stride);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1164,7 +1160,6 @@ const luaL_Reg lovrPass[] = {
|
||||||
{ "monkey", l_lovrPassMonkey },
|
{ "monkey", l_lovrPassMonkey },
|
||||||
{ "draw", l_lovrPassDraw },
|
{ "draw", l_lovrPassDraw },
|
||||||
{ "mesh", l_lovrPassMesh },
|
{ "mesh", l_lovrPassMesh },
|
||||||
{ "multimesh", l_lovrPassMultimesh },
|
|
||||||
|
|
||||||
{ "compute", l_lovrPassCompute },
|
{ "compute", l_lovrPassCompute },
|
||||||
|
|
||||||
|
|
|
@ -5044,13 +5044,13 @@ void lovrPassMesh(Pass* pass, Buffer* vertices, Buffer* indices, float* transfor
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void lovrPassMultimesh(Pass* pass, Buffer* vertices, Buffer* indices, Buffer* draws, uint32_t count, uint32_t offset, uint32_t stride) {
|
void lovrPassMeshIndirect(Pass* pass, Buffer* vertices, Buffer* indices, Buffer* draws, uint32_t count, uint32_t offset, uint32_t stride) {
|
||||||
lovrCheck(pass->info.type == PASS_RENDER, "This function can only be called on a render pass");
|
lovrCheck(pass->info.type == PASS_RENDER, "This function can only be called on a render pass");
|
||||||
lovrCheck(offset % 4 == 0, "Multimesh draw buffer offset must be a multiple of 4");
|
lovrCheck(offset % 4 == 0, "Buffer offset must be a multiple of 4 when sourcing draws from a Buffer");
|
||||||
uint32_t commandSize = indices ? 20 : 16;
|
uint32_t commandSize = indices ? 20 : 16;
|
||||||
stride = stride ? stride : commandSize;
|
stride = stride ? stride : commandSize;
|
||||||
uint32_t totalSize = stride * (count - 1) + commandSize;
|
uint32_t totalSize = stride * (count - 1) + commandSize;
|
||||||
lovrCheck(offset + totalSize < draws->size, "Multimesh draw range exceeds size of draw buffer");
|
lovrCheck(offset + totalSize < draws->size, "Draw buffer range exceeds the size of the buffer");
|
||||||
|
|
||||||
Draw draw = (Draw) {
|
Draw draw = (Draw) {
|
||||||
.mode = pass->pipeline->mode,
|
.mode = pass->pipeline->mode,
|
||||||
|
@ -5059,12 +5059,13 @@ void lovrPassMultimesh(Pass* pass, Buffer* vertices, Buffer* indices, Buffer* dr
|
||||||
};
|
};
|
||||||
|
|
||||||
Shader* shader = pass->pipeline->shader;
|
Shader* shader = pass->pipeline->shader;
|
||||||
lovrCheck(shader, "A custom Shader must be bound to draw a multimesh");
|
lovrCheck(shader, "A custom Shader must be bound to source draws from a Buffer");
|
||||||
|
|
||||||
flushPipeline(pass, &draw, shader);
|
flushPipeline(pass, &draw, shader);
|
||||||
flushConstants(pass, shader);
|
flushConstants(pass, shader);
|
||||||
flushBindings(pass, shader);
|
flushBindings(pass, shader);
|
||||||
flushBuiltins(pass, &draw, shader);
|
flushBuiltins(pass, &draw, shader);
|
||||||
|
flushMaterial(pass, &draw, shader);
|
||||||
flushBuffers(pass, &draw);
|
flushBuffers(pass, &draw);
|
||||||
|
|
||||||
if (indices) {
|
if (indices) {
|
||||||
|
|
|
@ -648,7 +648,7 @@ void lovrPassFill(Pass* pass, Texture* texture);
|
||||||
void lovrPassMonkey(Pass* pass, float* transform);
|
void lovrPassMonkey(Pass* pass, float* transform);
|
||||||
void lovrPassDrawModel(Pass* pass, Model* model, float* transform, uint32_t node, bool recurse, uint32_t instances);
|
void lovrPassDrawModel(Pass* pass, Model* model, float* transform, uint32_t node, bool recurse, uint32_t instances);
|
||||||
void lovrPassMesh(Pass* pass, Buffer* vertices, Buffer* indices, float* transform, uint32_t start, uint32_t count, uint32_t instances);
|
void lovrPassMesh(Pass* pass, Buffer* vertices, Buffer* indices, float* transform, uint32_t start, uint32_t count, uint32_t instances);
|
||||||
void lovrPassMultimesh(Pass* pass, Buffer* vertices, Buffer* indices, Buffer* indirect, uint32_t count, uint32_t offset, uint32_t stride);
|
void lovrPassMeshIndirect(Pass* pass, Buffer* vertices, Buffer* indices, Buffer* indirect, uint32_t count, uint32_t offset, uint32_t stride);
|
||||||
|
|
||||||
void lovrPassCompute(Pass* pass, uint32_t x, uint32_t y, uint32_t z, Buffer* indirect, uint32_t offset);
|
void lovrPassCompute(Pass* pass, uint32_t x, uint32_t y, uint32_t z, Buffer* indirect, uint32_t offset);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue