diff --git a/src/rendering/twn_gl_15_rendering.c b/src/rendering/twn_gl_15_rendering.c index 6db99d3..4a98ac3 100644 --- a/src/rendering/twn_gl_15_rendering.c +++ b/src/rendering/twn_gl_15_rendering.c @@ -9,89 +9,69 @@ #include -typedef struct { - float x, y; -} Vec2Packed; - - -typedef struct { - int16_t x, y; -} Vec2ShortPacked; - - -typedef struct { - uint8_t r, g, b, a; -} ColorPacked; - - -#define m_vec2_packed_from(p_vec2) ((Vec2Packed){ (p_vec2).x, (p_vec2).y }) -#define m_vec2_short_packed_from(p_vec2) ((Vec2ShortPacked){ (uint16_t)((p_vec2).x * 32768 * 2), (uint16_t)((p_vec2).y * 32768 * 2) }) -#define m_color_packed_from(p_color) ((ColorPacked){ (p_color).r, (p_color).g, (p_color).b, (p_color).a }) - - /* TODO: try using the fact we utilize edge coloring and step virtual color attributes to bogus points */ /* this is only doable is we take out color attribute to separate array or a portion of it */ /* interleaved vertex array data */ typedef struct ElementIndexedQuad { /* upper-left */ - Vec2Packed v0; - Vec2Packed uv0; - ColorPacked c0; + Vec2 v0; + Vec2 uv0; + Color c0; /* bottom-left */ - Vec2Packed v1; - Vec2Packed uv1; - ColorPacked c1; + Vec2 v1; + Vec2 uv1; + Color c1; /* bottom-right */ - Vec2Packed v2; - Vec2Packed uv2; - ColorPacked c2; + Vec2 v2; + Vec2 uv2; + Color c2; /* upper-right */ - Vec2Packed v3; - Vec2Packed uv3; - ColorPacked c3; + Vec2 v3; + Vec2 uv3; + Color c3; } ElementIndexedQuad; typedef struct ElementIndexedQuadWithoutColor { /* upper-left */ - Vec2Packed v0; - Vec2Packed uv0; + Vec2 v0; + Vec2 uv0; /* bottom-left */ - Vec2Packed v1; - Vec2Packed uv1; + Vec2 v1; + Vec2 uv1; /* bottom-right */ - Vec2Packed v2; - Vec2Packed uv2; + Vec2 v2; + Vec2 uv2; /* upper-right */ - Vec2Packed v3; - Vec2Packed uv3; + Vec2 v3; + Vec2 uv3; } ElementIndexedQuadWithoutColor; typedef struct ElementIndexedQuadWithoutTexture { /* upper-left */ - Vec2Packed v0; - ColorPacked c0; + Vec2 v0; + Color c0; /* bottom-left */ - Vec2Packed v1; - ColorPacked c1; + Vec2 v1; + Color c1; /* bottom-right */ - Vec2Packed v2; - ColorPacked c2; + Vec2 v2; + Color c2; /* upper-right */ - Vec2Packed v3; - ColorPacked c3; + Vec2 v3; + Color c3; } ElementIndexedQuadWithoutTexture; typedef struct ElementIndexedQuadWithoutColorWithoutTexture { /* upper-left */ - Vec2Packed v0; + Vec2 v0; /* bottom-left */ - Vec2Packed v1; + Vec2 v1; /* bottom-right */ - Vec2Packed v2; + Vec2 v2; /* upper-right */ - Vec2Packed v3; + Vec2 v3; } ElementIndexedQuadWithoutColorWithoutTexture; @@ -698,62 +678,62 @@ bool push_quad_payload_to_vertex_buffer_builder(struct QuadBatch batch, { if (!batch.constant_colored && batch.textured) { ElementIndexedQuad const buffer_element = { - .v0 = m_vec2_packed_from(v0), - .v1 = m_vec2_packed_from(v1), - .v2 = m_vec2_packed_from(v2), - .v3 = m_vec2_packed_from(v3), + .v0 = v0, + .v1 = v1, + .v2 = v2, + .v3 = v3, - .uv0 = m_vec2_packed_from(uv0), - .uv1 = m_vec2_packed_from(uv1), - .uv2 = m_vec2_packed_from(uv2), - .uv3 = m_vec2_packed_from(uv3), + .uv0 = uv0, + .uv1 = uv1, + .uv2 = uv2, + .uv3 = uv3, /* equal for all (flat shaded) */ - .c0 = m_color_packed_from(color), - // .c1 = m_color_packed_from(color), - .c2 = m_color_packed_from(color), - // .c3 = m_color_packed_from(color), + .c0 = color, + // .c1 = color, + .c2 = color, + // .c3 = color, }; return push_to_vertex_buffer_builder(builder, &buffer_element, sizeof buffer_element); } else if (batch.constant_colored && batch.textured) { ElementIndexedQuadWithoutColor const buffer_element = { - .v0 = m_vec2_packed_from(v0), - .v1 = m_vec2_packed_from(v1), - .v2 = m_vec2_packed_from(v2), - .v3 = m_vec2_packed_from(v3), + .v0 = v0, + .v1 = v1, + .v2 = v2, + .v3 = v3, - .uv0 = m_vec2_packed_from(uv0), - .uv1 = m_vec2_packed_from(uv1), - .uv2 = m_vec2_packed_from(uv2), - .uv3 = m_vec2_packed_from(uv3), + .uv0 = uv0, + .uv1 = uv1, + .uv2 = uv2, + .uv3 = uv3, }; return push_to_vertex_buffer_builder(builder, &buffer_element, sizeof buffer_element); } else if (!batch.constant_colored && !batch.textured) { ElementIndexedQuadWithoutTexture const buffer_element = { - .v0 = m_vec2_packed_from(v0), - .v1 = m_vec2_packed_from(v1), - .v2 = m_vec2_packed_from(v2), - .v3 = m_vec2_packed_from(v3), + .v0 = v0, + .v1 = v1, + .v2 = v2, + .v3 = v3, /* equal for all (flat shaded) */ - .c0 = m_color_packed_from(color), - // .c1 = m_color_packed_from(color), - .c2 = m_color_packed_from(color), - // .c3 = m_color_packed_from(color), + .c0 = color, + // .c1 = color, + .c2 = color, + // .c3 = color, }; return push_to_vertex_buffer_builder(builder, &buffer_element, sizeof buffer_element); } else if (batch.constant_colored && !batch.textured) { ElementIndexedQuadWithoutColorWithoutTexture const buffer_element = { - .v0 = m_vec2_packed_from(v0), - .v1 = m_vec2_packed_from(v1), - .v2 = m_vec2_packed_from(v2), - .v3 = m_vec2_packed_from(v3), + .v0 = v0, + .v1 = v1, + .v2 = v2, + .v3 = v3, }; return push_to_vertex_buffer_builder(builder, &buffer_element, sizeof buffer_element); @@ -809,15 +789,15 @@ bool push_text_payload_to_vertex_buffer_builder(FontData const *font_data, (void)font_data; ElementIndexedQuadWithoutColor buffer_element = { - .v0 = (Vec2Packed){ quad.x0, quad.y0 }, - .v1 = (Vec2Packed){ quad.x1, quad.y0 }, - .v2 = (Vec2Packed){ quad.x1, quad.y1 }, - .v3 = (Vec2Packed){ quad.x0, quad.y1 }, + .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 = (Vec2Packed){ quad.s0, quad.t0 }, - .uv1 = (Vec2Packed){ quad.s1, quad.t0 }, - .uv2 = (Vec2Packed){ quad.s1, quad.t1 }, - .uv3 = (Vec2Packed){ 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);