typedef & PascalCase for ALL structs and enums
This commit is contained in:
@ -11,50 +11,50 @@
|
||||
/* TODO: use int16_t for uvs */
|
||||
/* TODO: use packed types? */
|
||||
/* TODO: int16_t could be used for positioning, but we would need to have more CPU calcs */
|
||||
struct element_indexed_quad {
|
||||
typedef struct ElementIndexedQuad {
|
||||
/* upper-left */
|
||||
t_fvec2 v0;
|
||||
t_fvec2 uv0;
|
||||
t_color c0;
|
||||
Vec2 v0;
|
||||
Vec2 uv0;
|
||||
Color c0;
|
||||
/* bottom-left */
|
||||
t_fvec2 v1;
|
||||
t_fvec2 uv1;
|
||||
t_color c1;
|
||||
Vec2 v1;
|
||||
Vec2 uv1;
|
||||
Color c1;
|
||||
/* bottom-right */
|
||||
t_fvec2 v2;
|
||||
t_fvec2 uv2;
|
||||
t_color c2;
|
||||
Vec2 v2;
|
||||
Vec2 uv2;
|
||||
Color c2;
|
||||
/* upper-right */
|
||||
t_fvec2 v3;
|
||||
t_fvec2 uv3;
|
||||
t_color c3;
|
||||
};
|
||||
Vec2 v3;
|
||||
Vec2 uv3;
|
||||
Color c3;
|
||||
} ElementIndexedQuad;
|
||||
|
||||
|
||||
struct element_indexed_quad_without_color {
|
||||
typedef struct ElementIndexedQuadWithoutColor {
|
||||
/* upper-left */
|
||||
t_fvec2 v0;
|
||||
t_fvec2 uv0;
|
||||
Vec2 v0;
|
||||
Vec2 uv0;
|
||||
/* bottom-left */
|
||||
t_fvec2 v1;
|
||||
t_fvec2 uv1;
|
||||
Vec2 v1;
|
||||
Vec2 uv1;
|
||||
/* bottom-right */
|
||||
t_fvec2 v2;
|
||||
t_fvec2 uv2;
|
||||
Vec2 v2;
|
||||
Vec2 uv2;
|
||||
/* upper-right */
|
||||
t_fvec2 v3;
|
||||
t_fvec2 uv3;
|
||||
};
|
||||
Vec2 v3;
|
||||
Vec2 uv3;
|
||||
} ElementIndexedQuadWithoutColor;
|
||||
|
||||
|
||||
typedef enum {
|
||||
PIPELINE_NO,
|
||||
PIPELINE_SPACE,
|
||||
PIPELINE_2D,
|
||||
} pipeline;
|
||||
} Pipeline;
|
||||
|
||||
|
||||
static pipeline pipeline_last_used = PIPELINE_NO;
|
||||
static Pipeline pipeline_last_used = PIPELINE_NO;
|
||||
|
||||
|
||||
void use_space_pipeline(void) {
|
||||
@ -117,7 +117,7 @@ void use_2d_pipeline(void) {
|
||||
}
|
||||
|
||||
|
||||
void upload_quad_vertices(t_frect rect) {
|
||||
void upload_quad_vertices(Rect rect) {
|
||||
/* client memory needs to be reachable on glDraw*, so */
|
||||
static float vertices[6 * 2];
|
||||
|
||||
@ -132,7 +132,7 @@ void upload_quad_vertices(t_frect rect) {
|
||||
}
|
||||
|
||||
|
||||
void render_rectangle(const struct rect_primitive *rectangle) {
|
||||
void render_rectangle(const RectPrimitive *rectangle) {
|
||||
glColor4ub(rectangle->color.r, rectangle->color.g,
|
||||
rectangle->color.b, rectangle->color.a);
|
||||
|
||||
@ -144,7 +144,7 @@ void render_rectangle(const struct rect_primitive *rectangle) {
|
||||
}
|
||||
|
||||
|
||||
void render_circle(const struct circle_primitive *circle) {
|
||||
void render_circle(const CirclePrimitive *circle) {
|
||||
SDL_Vertex *vertices = NULL;
|
||||
int *indices = NULL;
|
||||
int num_vertices = (int)circle->radius;
|
||||
@ -181,7 +181,7 @@ void render_circle(const struct circle_primitive *circle) {
|
||||
}
|
||||
|
||||
|
||||
void use_texture_mode(enum texture_mode mode) {
|
||||
void use_texture_mode(TextureMode mode) {
|
||||
if (mode == TEXTURE_MODE_GHOSTLY) {
|
||||
glEnable(GL_BLEND);
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
@ -203,21 +203,21 @@ void use_texture_mode(enum texture_mode mode) {
|
||||
}
|
||||
|
||||
|
||||
vertex_buffer_builder build_vertex_buffer(vertex_buffer buffer, size_t bytes) {
|
||||
VertexBufferBuilder build_vertex_buffer(VertexBuffer buffer, size_t bytes) {
|
||||
glBindBuffer(GL_ARRAY_BUFFER, buffer);
|
||||
glBufferData(GL_ARRAY_BUFFER, bytes, NULL, GL_STREAM_DRAW);
|
||||
void *mapping = glMapBuffer(GL_ARRAY_BUFFER, GL_WRITE_ONLY);
|
||||
if (!mapping)
|
||||
CRY("build_vertex_buffer", "Error mapping a vertex array buffer");
|
||||
|
||||
return (vertex_buffer_builder) {
|
||||
return (VertexBufferBuilder) {
|
||||
.mapping = mapping,
|
||||
.bytes_left = bytes,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
bool push_to_vertex_buffer_builder(vertex_buffer_builder *builder,
|
||||
bool push_to_vertex_buffer_builder(VertexBufferBuilder *builder,
|
||||
void *bytes, size_t size) {
|
||||
if (builder->bytes_left == 0)
|
||||
return false;
|
||||
@ -237,9 +237,9 @@ bool push_to_vertex_buffer_builder(vertex_buffer_builder *builder,
|
||||
}
|
||||
|
||||
|
||||
void finally_render_sprites(const struct primitive_2d primitives[],
|
||||
const struct sprite_batch batch,
|
||||
const vertex_buffer buffer)
|
||||
void finally_render_sprites(const Primitive2D primitives[],
|
||||
const struct SpriteBatch batch,
|
||||
const VertexBuffer buffer)
|
||||
{
|
||||
/* TODO: maybe do, dunno */
|
||||
// glBindBuffer(GL_VERTEX_ARRAY, vertex_buffer);
|
||||
@ -250,13 +250,13 @@ void finally_render_sprites(const struct primitive_2d primitives[],
|
||||
GLsizei uvoff;
|
||||
|
||||
if (!batch.constant_colored) {
|
||||
off = offsetof(struct element_indexed_quad, v1);
|
||||
voff = offsetof(struct element_indexed_quad, v0);
|
||||
uvoff = offsetof(struct element_indexed_quad, uv0);
|
||||
off = offsetof(ElementIndexedQuad, v1);
|
||||
voff = offsetof(ElementIndexedQuad, v0);
|
||||
uvoff = offsetof(ElementIndexedQuad, uv0);
|
||||
} else {
|
||||
off = offsetof(struct element_indexed_quad_without_color, v1);
|
||||
voff = offsetof(struct element_indexed_quad_without_color, v0);
|
||||
uvoff = offsetof(struct element_indexed_quad_without_color, uv0);
|
||||
off = offsetof(ElementIndexedQuadWithoutColor, v1);
|
||||
voff = offsetof(ElementIndexedQuadWithoutColor, v0);
|
||||
uvoff = offsetof(ElementIndexedQuadWithoutColor, uv0);
|
||||
}
|
||||
|
||||
/* vertex specification */
|
||||
@ -278,7 +278,7 @@ void finally_render_sprites(const struct primitive_2d primitives[],
|
||||
glColorPointer(4,
|
||||
GL_UNSIGNED_BYTE,
|
||||
off,
|
||||
(void *)offsetof(struct element_indexed_quad, c0));
|
||||
(void *)offsetof(ElementIndexedQuad, c0));
|
||||
} else
|
||||
glColor4ub(primitives[0].sprite.color.r,
|
||||
primitives[0].sprite.color.g,
|
||||
@ -307,22 +307,22 @@ void finally_render_sprites(const struct primitive_2d primitives[],
|
||||
}
|
||||
|
||||
|
||||
size_t get_sprite_payload_size(struct sprite_batch batch) {
|
||||
size_t get_sprite_payload_size(struct SpriteBatch batch) {
|
||||
if (batch.constant_colored)
|
||||
return sizeof (struct element_indexed_quad_without_color);
|
||||
return sizeof (ElementIndexedQuadWithoutColor);
|
||||
else
|
||||
return sizeof (struct element_indexed_quad);
|
||||
return sizeof (ElementIndexedQuad);
|
||||
}
|
||||
|
||||
|
||||
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)
|
||||
{
|
||||
if (!batch.constant_colored) {
|
||||
struct element_indexed_quad buffer_element = {
|
||||
ElementIndexedQuad buffer_element = {
|
||||
.v0 = v0,
|
||||
.v1 = v1,
|
||||
.v2 = v2,
|
||||
@ -343,7 +343,7 @@ bool push_sprite_payload_to_vertex_buffer_builder(struct sprite_batch batch,
|
||||
return push_to_vertex_buffer_builder(builder, &buffer_element, sizeof buffer_element);
|
||||
|
||||
} else {
|
||||
struct element_indexed_quad_without_color buffer_element = {
|
||||
ElementIndexedQuadWithoutColor buffer_element = {
|
||||
.v0 = v0,
|
||||
.v1 = v1,
|
||||
.v2 = v2,
|
||||
@ -360,9 +360,9 @@ bool push_sprite_payload_to_vertex_buffer_builder(struct sprite_batch batch,
|
||||
}
|
||||
|
||||
|
||||
void finally_draw_uncolored_space_traingle_batch(const struct mesh_batch *batch,
|
||||
const t_texture_key texture_key,
|
||||
const vertex_buffer buffer)
|
||||
void finally_draw_uncolored_space_traingle_batch(const MeshBatch *batch,
|
||||
const TextureKey texture_key,
|
||||
const VertexBuffer buffer)
|
||||
{
|
||||
const size_t primitives_len = arrlenu(batch->primitives);
|
||||
|
||||
@ -374,15 +374,15 @@ void finally_draw_uncolored_space_traingle_batch(const struct mesh_batch *batch,
|
||||
glEnableClientState(GL_VERTEX_ARRAY);
|
||||
glVertexPointer(3,
|
||||
GL_FLOAT,
|
||||
offsetof(struct uncolored_space_triangle_payload, v1),
|
||||
(void *)offsetof(struct uncolored_space_triangle_payload, v0));
|
||||
offsetof(struct UncoloredSpaceTrianglePayload, v1),
|
||||
(void *)offsetof(struct UncoloredSpaceTrianglePayload, v0));
|
||||
|
||||
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
glClientActiveTexture(GL_TEXTURE0);
|
||||
glTexCoordPointer(2,
|
||||
GL_FLOAT,
|
||||
offsetof(struct uncolored_space_triangle_payload, v1),
|
||||
(void *)offsetof(struct uncolored_space_triangle_payload, uv0));
|
||||
offsetof(struct UncoloredSpaceTrianglePayload, v1),
|
||||
(void *)offsetof(struct UncoloredSpaceTrianglePayload, uv0));
|
||||
|
||||
/* commit for drawing */
|
||||
glDrawArrays(GL_TRIANGLES, 0, 3 * (GLint)primitives_len);
|
||||
@ -396,32 +396,32 @@ void finally_draw_uncolored_space_traingle_batch(const struct mesh_batch *batch,
|
||||
}
|
||||
|
||||
|
||||
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)font_data;
|
||||
|
||||
struct element_indexed_quad_without_color buffer_element = {
|
||||
.v0 = (t_fvec2){ quad.x0, quad.y0 },
|
||||
.v1 = (t_fvec2){ quad.x1, quad.y0 },
|
||||
.v2 = (t_fvec2){ quad.x1, quad.y1 },
|
||||
.v3 = (t_fvec2){ quad.x0, quad.y1 },
|
||||
ElementIndexedQuadWithoutColor buffer_element = {
|
||||
.v0 = (Vec2){ quad.x0, quad.y0 },
|
||||
.v1 = (Vec2){ quad.x1, quad.y0 },
|
||||
.v2 = (Vec2){ quad.x1, quad.y1 },
|
||||
.v3 = (Vec2){ quad.x0, quad.y1 },
|
||||
|
||||
.uv0 = (t_fvec2){ quad.s0, quad.t0 },
|
||||
.uv1 = (t_fvec2){ quad.s1, quad.t0 },
|
||||
.uv2 = (t_fvec2){ quad.s1, quad.t1 },
|
||||
.uv3 = (t_fvec2){ quad.s0, quad.t1 },
|
||||
.uv0 = (Vec2){ quad.s0, quad.t0 },
|
||||
.uv1 = (Vec2){ quad.s1, quad.t0 },
|
||||
.uv2 = (Vec2){ quad.s1, quad.t1 },
|
||||
.uv3 = (Vec2){ quad.s0, quad.t1 },
|
||||
};
|
||||
|
||||
return push_to_vertex_buffer_builder(builder, &buffer_element, sizeof buffer_element);
|
||||
}
|
||||
|
||||
|
||||
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)
|
||||
{
|
||||
(void)buffer;
|
||||
|
||||
@ -429,15 +429,15 @@ void finally_draw_text(struct font_data const *font_data,
|
||||
glEnableClientState(GL_VERTEX_ARRAY);
|
||||
glVertexPointer(2,
|
||||
GL_FLOAT,
|
||||
offsetof(struct element_indexed_quad_without_color, v1),
|
||||
(void *)(size_t)offsetof(struct element_indexed_quad_without_color, v0));
|
||||
offsetof(ElementIndexedQuadWithoutColor, v1),
|
||||
(void *)(size_t)offsetof(ElementIndexedQuadWithoutColor, v0));
|
||||
|
||||
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
glClientActiveTexture(GL_TEXTURE0);
|
||||
glTexCoordPointer(2,
|
||||
GL_FLOAT,
|
||||
offsetof(struct element_indexed_quad_without_color, v1),
|
||||
(void *)(size_t)offsetof(struct element_indexed_quad_without_color, uv0));
|
||||
offsetof(ElementIndexedQuadWithoutColor, v1),
|
||||
(void *)(size_t)offsetof(ElementIndexedQuadWithoutColor, uv0));
|
||||
|
||||
bind_quad_element_buffer();
|
||||
|
||||
@ -462,5 +462,5 @@ void finally_draw_text(struct font_data const *font_data,
|
||||
|
||||
|
||||
size_t get_text_payload_size(void) {
|
||||
return sizeof (struct element_indexed_quad_without_color);
|
||||
return sizeof (ElementIndexedQuadWithoutColor);
|
||||
}
|
||||
|
Reference in New Issue
Block a user