Pass:line;

This commit is contained in:
bjorn 2022-06-04 01:33:50 -07:00
parent a2668a1632
commit ebc6d9d3a3
3 changed files with 36 additions and 11 deletions

View File

@ -400,16 +400,21 @@ static void luax_readvertices(lua_State* L, int index, float* vertices, uint32_t
static int l_lovrPassPoints(lua_State* L) {
Pass* pass = luax_checktype(L, 1, Pass);
Buffer* buffer = luax_totype(L, 2, Buffer);
float* vertices;
uint32_t count = luax_getvertexcount(L, 2);
lovrPassPoints(pass, count, &vertices);
luax_readvertices(L, 2, vertices, count);
return 0;
}
if (buffer || !lua_toboolean(L, 2)) {
//
} else {
float* vertices;
uint32_t count = luax_getvertexcount(L, 2);
lovrPassPoints(pass, count, &vertices);
luax_readvertices(L, 2, vertices, count);
}
static int l_lovrPassLine(lua_State* L) {
Pass* pass = luax_checktype(L, 1, Pass);
float* vertices;
uint32_t count = luax_getvertexcount(L, 2);
lovrPassLine(pass, count, &vertices);
luax_readvertices(L, 2, vertices, count);
return 0;
}
return 0;
}
@ -590,6 +595,7 @@ const luaL_Reg lovrPass[] = {
{ "send", l_lovrPassSend },
{ "points", l_lovrPassPoints },
{ "line", l_lovrPassLine },
{ "clear", l_lovrPassClear },
{ "copy", l_lovrPassCopy },

View File

@ -1995,15 +1995,33 @@ static void lovrPassDraw(Pass* pass, Draw* draw) {
pass->drawCount++;
}
void lovrPassPoints(Pass* pass, uint32_t count, float** vertices) {
void lovrPassPoints(Pass* pass, uint32_t count, float** points) {
lovrPassDraw(pass, &(Draw) {
.mode = GPU_DRAW_POINTS,
.vertex.format = VERTEX_POINT,
.vertex.pointer = (void**) vertices,
.vertex.pointer = (void**) points,
.vertex.count = count
});
}
void lovrPassLine(Pass* pass, uint32_t count, float** points) {
uint16_t* indices;
lovrPassDraw(pass, &(Draw) {
.mode = GPU_DRAW_LINES,
.vertex.format = VERTEX_POINT,
.vertex.pointer = (void**) points,
.vertex.count = count,
.index.pointer = (void**) &indices,
.index.count = 2 * (count - 1)
});
for (uint32_t i = 0; i < count - 1; i++) {
indices[2 * i + 0] = i;
indices[2 * i + 1] = i + 1;
}
}
void lovrPassClearBuffer(Pass* pass, Buffer* buffer, uint32_t offset, uint32_t extent) {
if (extent == 0) return;
if (extent == ~0u) extent = buffer->size - offset;

View File

@ -389,6 +389,7 @@ void lovrPassSendBuffer(Pass* pass, const char* name, size_t length, uint32_t sl
void lovrPassSendTexture(Pass* pass, const char* name, size_t length, uint32_t slot, Texture* texture);
void lovrPassSendSampler(Pass* pass, const char* name, size_t length, uint32_t slot, Sampler* sampler);
void lovrPassPoints(Pass* pass, uint32_t count, float** vertices);
void lovrPassLine(Pass* pass, uint32_t count, float** vertices);
void lovrPassClearBuffer(Pass* pass, Buffer* buffer, uint32_t offset, uint32_t extent);
void lovrPassClearTexture(Pass* pass, Texture* texture, float value[4], uint32_t layer, uint32_t layerCount, uint32_t level, uint32_t levelCount);
void lovrPassCopyDataToBuffer(Pass* pass, void* data, Buffer* buffer, uint32_t offset, uint32_t size);