typedef & PascalCase for ALL structs and enums

This commit is contained in:
2024-09-23 14:43:16 -03:00
parent e093a6d492
commit 73bf92e706
43 changed files with 795 additions and 793 deletions

View File

@@ -2,6 +2,7 @@
#define TWN_RENDERING_C_H
#include "twn_textures_c.h"
#include "twn_text_c.h"
#include "twn_util.h"
#include "twn_option.h"
@@ -16,107 +17,107 @@
#include <stdbool.h>
extern t_matrix4 camera_projection_matrix;
extern t_matrix4 camera_look_at_matrix;
extern Matrix4 camera_projection_matrix;
extern Matrix4 camera_look_at_matrix;
#define QUAD_ELEMENT_BUFFER_LENGTH (65536 / 6)
typedef GLuint vertex_buffer;
typedef GLuint VertexBuffer;
typedef struct vertex_buffer_builder {
typedef struct VertexBufferBuilder {
size_t bytes_left;
void *mapping;
} vertex_buffer_builder;
} VertexBufferBuilder;
struct sprite_primitive {
t_frect rect;
t_color color;
typedef struct SpritePrimitive {
Rect rect;
Color color;
float rotation;
t_texture_key texture_key;
TextureKey texture_key;
bool flip_x;
bool flip_y;
bool repeat;
m_option_list(
t_frect, texture_region )
};
Rect, texture_region )
} SpritePrimitive;
struct rect_primitive {
t_frect rect;
t_color color;
};
typedef struct RectPrimitive {
Rect rect;
Color color;
} RectPrimitive;
struct circle_primitive {
typedef struct CirclePrimitive {
float radius;
t_color color;
t_fvec2 position;
};
Color color;
Vec2 position;
} CirclePrimitive;
struct text_primitive {
t_color color;
t_fvec2 position;
typedef struct TextPrimitive {
Color color;
Vec2 position;
char *text;
const char *font;
int height_px;
};
} TextPrimitive;
enum primitive_2d_type {
typedef enum Primitive2DType {
PRIMITIVE_2D_SPRITE,
PRIMITIVE_2D_RECT,
PRIMITIVE_2D_CIRCLE,
PRIMITIVE_2D_TEXT,
};
} Primitive2DType;
struct primitive_2d {
enum primitive_2d_type type;
typedef struct Primitive2D {
Primitive2DType type;
union {
struct sprite_primitive sprite;
struct rect_primitive rect;
struct circle_primitive circle;
struct text_primitive text;
SpritePrimitive sprite;
RectPrimitive rect;
CirclePrimitive circle;
TextPrimitive text;
};
};
} Primitive2D;
/* union for in-place recalculation of texture coordinates */
union uncolored_space_triangle {
union UncoloredSpaceTriangle {
/* pending for sending, uvs are not final as texture atlases could update */
struct uncolored_space_triangle_primitive {
t_fvec3 v0;
t_fvec2 uv0; /* in pixels */
t_fvec3 v1;
t_fvec2 uv1; /* in pixels */
t_fvec3 v2;
t_fvec2 uv2; /* in pixels */
struct UncoloredSpaceTrianglePrimitive {
Vec3 v0;
Vec2 uv0; /* in pixels */
Vec3 v1;
Vec2 uv1; /* in pixels */
Vec3 v2;
Vec2 uv2; /* in pixels */
} primitive;
/* TODO: have it packed? */
/* structure that is passed in opengl vertex array */
struct uncolored_space_triangle_payload {
t_fvec3 v0;
t_fvec2 uv0;
t_fvec3 v1;
t_fvec2 uv1;
t_fvec3 v2;
t_fvec2 uv2;
struct UncoloredSpaceTrianglePayload {
Vec3 v0;
Vec2 uv0;
Vec3 v1;
Vec2 uv1;
Vec3 v2;
Vec2 uv2;
} payload;
};
/* batch of primitives with overlapping properties */
struct mesh_batch {
typedef struct MeshBatch {
uint8_t *primitives;
};
} MeshBatch;
struct mesh_batch_item {
t_texture_key key;
struct mesh_batch value;
};
typedef struct MeshBatchItem {
TextureKey key;
struct MeshBatch value;
} MeshBatchItem;
struct text_cache {
struct font_data **data;
};
typedef struct TextCache {
struct FontData **data;
} TextCache;
/* renders the background, then the primitives in all render queues */
@@ -125,47 +126,47 @@ void render(void);
/* clears all render queues */
void render_queue_clear(void);
void create_circle_geometry(t_fvec2 position,
t_color color,
void create_circle_geometry(Vec2 position,
Color color,
float radius,
size_t num_vertices,
SDL_Vertex **vertices_out,
int **indices_out);
struct sprite_batch {
struct SpriteBatch {
size_t size; /* how many primitives are in current batch */
enum texture_mode mode;
TextureMode mode;
bool constant_colored; /* whether colored batch is uniformly colored */
bool repeat; /* whether repeat is needed */
} collect_sprite_batch(const struct primitive_2d primitives[], size_t len);
} collect_sprite_batch(const Primitive2D primitives[], size_t len);
void render_sprites(const struct primitive_2d primitives[],
const struct sprite_batch batch);
void render_sprites(const Primitive2D primitives[],
const struct SpriteBatch batch);
void draw_uncolored_space_traingle_batch(struct mesh_batch *batch,
t_texture_key texture_key);
void draw_uncolored_space_traingle_batch(MeshBatch *batch,
TextureKey texture_key);
/* text */
void render_text(const struct text_primitive *text);
void render_text(const TextPrimitive *text);
void text_cache_init(struct text_cache *cache);
void text_cache_init(TextCache *cache);
void text_cache_deinit(struct text_cache *cache);
void text_cache_deinit(TextCache *cache);
/* vertex buffer */
vertex_buffer create_vertex_buffer(void);
VertexBuffer create_vertex_buffer(void);
void delete_vertex_buffer(vertex_buffer buffer);
void delete_vertex_buffer(VertexBuffer buffer);
void specify_vertex_buffer(vertex_buffer buffer, void *data, size_t bytes);
void specify_vertex_buffer(VertexBuffer buffer, void *data, size_t bytes);
/* uses present in 1.5 buffer mapping feature */
vertex_buffer_builder build_vertex_buffer(vertex_buffer buffer, size_t bytes);
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(vertex_buffer_builder *builder,
bool push_to_vertex_buffer_builder(VertexBufferBuilder *builder,
void *bytes,
size_t size);
@@ -181,41 +182,41 @@ void set_depth_range(double low, double high);
void bind_quad_element_buffer(void);
void render_circle(const struct circle_primitive *circle);
void render_circle(const CirclePrimitive *circle);
void render_rectangle(const struct rect_primitive *rectangle);
void render_rectangle(const RectPrimitive *rectangle);
void use_space_pipeline(void);
void use_2d_pipeline(void);
void use_texture_mode(enum texture_mode mode);
void use_texture_mode(TextureMode mode);
void finally_render_sprites(struct primitive_2d const primitives[],
struct sprite_batch batch,
vertex_buffer buffer);
void finally_render_sprites(Primitive2D const primitives[],
struct SpriteBatch batch,
VertexBuffer buffer);
size_t get_sprite_payload_size(struct sprite_batch batch);
size_t get_sprite_payload_size(struct SpriteBatch batch);
bool push_sprite_payload_to_vertex_buffer_builder(struct sprite_batch batch,
vertex_buffer_builder *builder,
t_fvec2 v0, t_fvec2 v1, t_fvec2 v2, t_fvec2 v3,
t_fvec2 uv0, t_fvec2 uv1, t_fvec2 uv2, t_fvec2 uv3,
t_color color);
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);
void finally_draw_uncolored_space_traingle_batch(struct mesh_batch const *batch,
t_texture_key texture_key,
vertex_buffer buffer);
void finally_draw_uncolored_space_traingle_batch(MeshBatch const *batch,
TextureKey texture_key,
VertexBuffer buffer);
size_t get_text_payload_size(void);
bool push_text_payload_to_vertex_buffer_builder(struct font_data const *font_data,
vertex_buffer_builder *builder,
bool push_text_payload_to_vertex_buffer_builder(FontData const *font_data,
VertexBufferBuilder *builder,
stbtt_aligned_quad quad);
void finally_draw_text(struct font_data const *font_data,
void finally_draw_text(FontData const *font_data,
size_t len,
t_color color,
vertex_buffer buffer);
Color color,
VertexBuffer buffer);
#endif