support arbitrary count of billboards per batch (in regards to preallocated short index buffer)

This commit is contained in:
veclavtalica 2025-01-05 23:36:48 +03:00
parent d7a119a592
commit 4dd028aeae

View File

@ -3,6 +3,7 @@
#include "twn_engine_context_c.h"
#include "twn_textures_c.h"
#include "twn_types.h"
#include "twn_util_c.h"
#include "twn_vec.h"
#include <stb_ds.h>
@ -85,12 +86,16 @@ void finally_draw_billboard_batch(struct MeshBatch const *batch,
const Vec2 uv2 = { xr, yr + hr };
const Vec2 uv3 = { xr, yr };
for (size_t batch_n = 0; batch_n <= (primitives_len - 1) / QUAD_ELEMENT_BUFFER_LENGTH; batch_n++) {
/* emit vertex data */
VertexBuffer const buffer = get_scratch_vertex_array();
VertexBufferBuilder builder = build_vertex_buffer(buffer, sizeof (ElementIndexedBillboard) * primitives_len);
VertexBufferBuilder builder = build_vertex_buffer(
buffer,
sizeof (ElementIndexedBillboard) * MIN(primitives_len - batch_n * QUAD_ELEMENT_BUFFER_LENGTH, QUAD_ELEMENT_BUFFER_LENGTH));
for (size_t i = 0; i < primitives_len; ++i) {
struct SpaceBillboard const billboard = ((SpaceBillboard *)(void *)batch->primitives)[i];
struct SpaceBillboard const billboard = ((SpaceBillboard *)(void *)batch->primitives)[batch_n * QUAD_ELEMENT_BUFFER_LENGTH + i];
/* a = (right + up) * size, b = (right - up) * size*/
Vec3 a, b;
@ -170,3 +175,4 @@ void finally_draw_billboard_batch(struct MeshBatch const *batch,
arrpush(deferred_commands, final_command);
}
}