rendering: use sprite batching techniques for rect primitives, unite their render path

This commit is contained in:
2024-10-14 11:46:07 +03:00
parent 82bad550e5
commit b295c5920c
10 changed files with 308 additions and 116 deletions

View File

@ -133,15 +133,18 @@ void create_circle_geometry(Vec2 position,
SDL_Vertex **vertices_out,
int **indices_out);
struct SpriteBatch {
struct QuadBatch {
size_t size; /* how many primitives are in current batch */
TextureMode mode;
TextureMode mode; /* how color should be applied */
bool constant_colored; /* whether colored batch is uniformly colored */
bool repeat; /* whether repeat is needed */
} collect_sprite_batch(const Primitive2D primitives[], size_t len);
void render_sprites(const Primitive2D primitives[],
const struct SpriteBatch batch);
bool textured;
} collect_quad_batch(const Primitive2D primitives[], size_t len);
void render_quad_batch(const Primitive2D primitives[], struct QuadBatch batch);
struct QuadBatch collect_sprite_batch(const Primitive2D primitives[], size_t len);
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);
@ -162,14 +165,14 @@ VertexBuffer create_vertex_buffer(void);
void delete_vertex_buffer(VertexBuffer buffer);
void specify_vertex_buffer(VertexBuffer buffer, void *data, size_t bytes);
void specify_vertex_buffer(VertexBuffer buffer, void const *data, size_t bytes);
/* uses present in 1.5 buffer mapping feature */
VertexBufferBuilder build_vertex_buffer(VertexBuffer buffer, size_t bytes);
/* collects bytes for sending to the gpu until all is pushed, which is when false is returned */
bool push_to_vertex_buffer_builder(VertexBufferBuilder *builder,
void *bytes,
void const *bytes,
size_t size);
/* state */
@ -194,19 +197,17 @@ void use_2d_pipeline(void);
void use_texture_mode(TextureMode mode);
void upload_quad_vertices(Rect rect);
void finally_render_quads(Primitive2D const primitives[],
struct QuadBatch batch,
VertexBuffer buffer);
void finally_render_sprites(Primitive2D const primitives[],
struct SpriteBatch batch,
VertexBuffer buffer);
size_t get_quad_payload_size(struct QuadBatch batch);
size_t get_sprite_payload_size(struct SpriteBatch batch);
bool push_sprite_payload_to_vertex_buffer_builder(struct SpriteBatch batch,
VertexBufferBuilder *builder,
Vec2 v0, Vec2 v1, Vec2 v2, Vec2 v3,
Vec2 uv0, Vec2 uv1, Vec2 uv2, Vec2 uv3,
Color color);
bool push_quad_payload_to_vertex_buffer_builder(struct QuadBatch batch,
VertexBufferBuilder *builder,
Vec2 v0, Vec2 v1, Vec2 v2, Vec2 v3,
Vec2 uv0, Vec2 uv1, Vec2 uv2, Vec2 uv3,
Color color);
void finally_draw_uncolored_space_traingle_batch(MeshBatch const *batch,
TextureKey texture_key,