billboards!

This commit is contained in:
veclavtalica
2025-01-05 19:46:05 +03:00
parent 7c0bf39f12
commit 3bfa86066e
17 changed files with 626 additions and 413 deletions

View File

@ -55,16 +55,16 @@ typedef struct RectPrimitive {
} RectPrimitive;
typedef struct CirclePrimitive {
Vec2 position;
float radius;
Color color;
Vec2 position;
} CirclePrimitive;
typedef struct TextPrimitive {
Color color;
Vec2 position;
char *text;
const char *font;
Color color;
int height_px;
} TextPrimitive;
@ -76,7 +76,7 @@ typedef enum Primitive2DType {
} Primitive2DType;
typedef struct Primitive2D {
Primitive2DType type;
Primitive2DType type; /* TODO: separate to structure of arrays for more efficient memory usage? */
union {
SpritePrimitive sprite;
@ -97,6 +97,14 @@ typedef struct UncoloredSpaceTriangle {
Vec2 uv2; /* in pixels */
} UncoloredSpaceTriangle;
typedef struct SpaceBillboard {
Vec3 position;
Vec2 size;
Color color;
// TextureKey texture; /* is assumed from other places */
bool cylindrical;
} SpaceBillboard;
/* batch of primitives with overlapping properties */
typedef struct MeshBatch {
uint8_t *primitives; /* note: interpretation of it is arbitrary */
@ -179,6 +187,26 @@ typedef struct ElementIndexedQuadWithoutColorWithoutTexture {
Vec2 v3;
} ElementIndexedQuadWithoutColorWithoutTexture;
/* TODO: no color variant */
typedef struct ElementIndexedBillboard {
/* upper-left */
Vec3 v0;
Vec2 uv0;
Color c0;
/* bottom-left */
Vec3 v1;
Vec2 uv1;
Color c1;
/* bottom-right */
Vec3 v2;
Vec2 uv2;
Color c2;
/* upper-right */
Vec3 v3;
Vec2 uv3;
Color c3;
} ElementIndexedBillboard;
/* renders the background, then the primitives in all render queues */
void render(void);
@ -207,9 +235,6 @@ struct QuadBatch collect_rect_batch(const Primitive2D primitives[], size_t len);
void render_sprite_batch(const Primitive2D primitives[], struct QuadBatch batch);
void render_rect_batch(const Primitive2D primitives[], struct QuadBatch batch);
void draw_uncolored_space_traingle_batch(MeshBatch *batch,
TextureKey texture_key);
/* text */
void render_text(const TextPrimitive *text);
@ -280,8 +305,10 @@ bool push_quad_payload_to_vertex_buffer_builder(struct QuadBatch batch,
Color color);
void finally_draw_uncolored_space_traingle_batch(MeshBatch const *batch,
TextureKey texture_key,
VertexBuffer buffer);
TextureKey texture_key);
void finally_draw_billboard_batch(MeshBatch const *batch,
TextureKey texture_key);
size_t get_text_payload_size(void);