52 lines
1.5 KiB
C
52 lines
1.5 KiB
C
#include "twn_draw.h"
|
|
#include "twn_draw_c.h"
|
|
#include "twn_engine_context_c.h"
|
|
#include "twn_textures_c.h"
|
|
#include "twn_types.h"
|
|
|
|
#include <stb_ds.h>
|
|
|
|
|
|
/* TODO: automatic handling of repeating textures */
|
|
/* for that we could allocate a loner texture */
|
|
void draw_triangle(const char *path,
|
|
Vec3 v0,
|
|
Vec3 v1,
|
|
Vec3 v2,
|
|
Vec2 uv0,
|
|
Vec2 uv1,
|
|
Vec2 uv2)
|
|
{
|
|
const TextureKey texture_key = textures_get_key(&ctx.texture_cache, path);
|
|
|
|
struct MeshBatchItem *batch_p = hmgetp_null(ctx.uncolored_mesh_batches, texture_key);
|
|
if (!batch_p) {
|
|
struct MeshBatch item = {0};
|
|
hmput(ctx.uncolored_mesh_batches, texture_key, item);
|
|
batch_p = &ctx.uncolored_mesh_batches[hmlenu(ctx.uncolored_mesh_batches) - 1];
|
|
}
|
|
|
|
UncoloredSpaceTriangle const triangle = {
|
|
.v0 = v0,
|
|
.v1 = v1,
|
|
.v2 = v2,
|
|
.uv1 = uv1,
|
|
.uv0 = uv0,
|
|
.uv2 = uv2,
|
|
};
|
|
|
|
UncoloredSpaceTriangle *triangles = (UncoloredSpaceTriangle *)(void *)batch_p->value.primitives;
|
|
|
|
arrpush(triangles, triangle);
|
|
batch_p->value.primitives = (uint8_t *)triangles;
|
|
}
|
|
|
|
|
|
void draw_uncolored_space_traingle_batch(struct MeshBatch *batch,
|
|
TextureKey texture_key)
|
|
{
|
|
VertexBuffer const vertex_array = get_scratch_vertex_array();
|
|
|
|
finally_draw_uncolored_space_traingle_batch(batch, texture_key, vertex_array);
|
|
}
|