no need for packed types no more
This commit is contained in:
parent
7f56ed8421
commit
1dc0dea762
@ -9,89 +9,69 @@
|
|||||||
#include <stb_ds.h>
|
#include <stb_ds.h>
|
||||||
|
|
||||||
|
|
||||||
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 */
|
/* 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 */
|
/* this is only doable is we take out color attribute to separate array or a portion of it */
|
||||||
/* interleaved vertex array data */
|
/* interleaved vertex array data */
|
||||||
typedef struct ElementIndexedQuad {
|
typedef struct ElementIndexedQuad {
|
||||||
/* upper-left */
|
/* upper-left */
|
||||||
Vec2Packed v0;
|
Vec2 v0;
|
||||||
Vec2Packed uv0;
|
Vec2 uv0;
|
||||||
ColorPacked c0;
|
Color c0;
|
||||||
/* bottom-left */
|
/* bottom-left */
|
||||||
Vec2Packed v1;
|
Vec2 v1;
|
||||||
Vec2Packed uv1;
|
Vec2 uv1;
|
||||||
ColorPacked c1;
|
Color c1;
|
||||||
/* bottom-right */
|
/* bottom-right */
|
||||||
Vec2Packed v2;
|
Vec2 v2;
|
||||||
Vec2Packed uv2;
|
Vec2 uv2;
|
||||||
ColorPacked c2;
|
Color c2;
|
||||||
/* upper-right */
|
/* upper-right */
|
||||||
Vec2Packed v3;
|
Vec2 v3;
|
||||||
Vec2Packed uv3;
|
Vec2 uv3;
|
||||||
ColorPacked c3;
|
Color c3;
|
||||||
} ElementIndexedQuad;
|
} ElementIndexedQuad;
|
||||||
|
|
||||||
typedef struct ElementIndexedQuadWithoutColor {
|
typedef struct ElementIndexedQuadWithoutColor {
|
||||||
/* upper-left */
|
/* upper-left */
|
||||||
Vec2Packed v0;
|
Vec2 v0;
|
||||||
Vec2Packed uv0;
|
Vec2 uv0;
|
||||||
/* bottom-left */
|
/* bottom-left */
|
||||||
Vec2Packed v1;
|
Vec2 v1;
|
||||||
Vec2Packed uv1;
|
Vec2 uv1;
|
||||||
/* bottom-right */
|
/* bottom-right */
|
||||||
Vec2Packed v2;
|
Vec2 v2;
|
||||||
Vec2Packed uv2;
|
Vec2 uv2;
|
||||||
/* upper-right */
|
/* upper-right */
|
||||||
Vec2Packed v3;
|
Vec2 v3;
|
||||||
Vec2Packed uv3;
|
Vec2 uv3;
|
||||||
} ElementIndexedQuadWithoutColor;
|
} ElementIndexedQuadWithoutColor;
|
||||||
|
|
||||||
|
|
||||||
typedef struct ElementIndexedQuadWithoutTexture {
|
typedef struct ElementIndexedQuadWithoutTexture {
|
||||||
/* upper-left */
|
/* upper-left */
|
||||||
Vec2Packed v0;
|
Vec2 v0;
|
||||||
ColorPacked c0;
|
Color c0;
|
||||||
/* bottom-left */
|
/* bottom-left */
|
||||||
Vec2Packed v1;
|
Vec2 v1;
|
||||||
ColorPacked c1;
|
Color c1;
|
||||||
/* bottom-right */
|
/* bottom-right */
|
||||||
Vec2Packed v2;
|
Vec2 v2;
|
||||||
ColorPacked c2;
|
Color c2;
|
||||||
/* upper-right */
|
/* upper-right */
|
||||||
Vec2Packed v3;
|
Vec2 v3;
|
||||||
ColorPacked c3;
|
Color c3;
|
||||||
} ElementIndexedQuadWithoutTexture;
|
} ElementIndexedQuadWithoutTexture;
|
||||||
|
|
||||||
|
|
||||||
typedef struct ElementIndexedQuadWithoutColorWithoutTexture {
|
typedef struct ElementIndexedQuadWithoutColorWithoutTexture {
|
||||||
/* upper-left */
|
/* upper-left */
|
||||||
Vec2Packed v0;
|
Vec2 v0;
|
||||||
/* bottom-left */
|
/* bottom-left */
|
||||||
Vec2Packed v1;
|
Vec2 v1;
|
||||||
/* bottom-right */
|
/* bottom-right */
|
||||||
Vec2Packed v2;
|
Vec2 v2;
|
||||||
/* upper-right */
|
/* upper-right */
|
||||||
Vec2Packed v3;
|
Vec2 v3;
|
||||||
} ElementIndexedQuadWithoutColorWithoutTexture;
|
} ElementIndexedQuadWithoutColorWithoutTexture;
|
||||||
|
|
||||||
|
|
||||||
@ -698,62 +678,62 @@ bool push_quad_payload_to_vertex_buffer_builder(struct QuadBatch batch,
|
|||||||
{
|
{
|
||||||
if (!batch.constant_colored && batch.textured) {
|
if (!batch.constant_colored && batch.textured) {
|
||||||
ElementIndexedQuad const buffer_element = {
|
ElementIndexedQuad const buffer_element = {
|
||||||
.v0 = m_vec2_packed_from(v0),
|
.v0 = v0,
|
||||||
.v1 = m_vec2_packed_from(v1),
|
.v1 = v1,
|
||||||
.v2 = m_vec2_packed_from(v2),
|
.v2 = v2,
|
||||||
.v3 = m_vec2_packed_from(v3),
|
.v3 = v3,
|
||||||
|
|
||||||
.uv0 = m_vec2_packed_from(uv0),
|
.uv0 = uv0,
|
||||||
.uv1 = m_vec2_packed_from(uv1),
|
.uv1 = uv1,
|
||||||
.uv2 = m_vec2_packed_from(uv2),
|
.uv2 = uv2,
|
||||||
.uv3 = m_vec2_packed_from(uv3),
|
.uv3 = uv3,
|
||||||
|
|
||||||
/* equal for all (flat shaded) */
|
/* equal for all (flat shaded) */
|
||||||
.c0 = m_color_packed_from(color),
|
.c0 = color,
|
||||||
// .c1 = m_color_packed_from(color),
|
// .c1 = color,
|
||||||
.c2 = m_color_packed_from(color),
|
.c2 = color,
|
||||||
// .c3 = m_color_packed_from(color),
|
// .c3 = color,
|
||||||
};
|
};
|
||||||
|
|
||||||
return push_to_vertex_buffer_builder(builder, &buffer_element, sizeof buffer_element);
|
return push_to_vertex_buffer_builder(builder, &buffer_element, sizeof buffer_element);
|
||||||
|
|
||||||
} else if (batch.constant_colored && batch.textured) {
|
} else if (batch.constant_colored && batch.textured) {
|
||||||
ElementIndexedQuadWithoutColor const buffer_element = {
|
ElementIndexedQuadWithoutColor const buffer_element = {
|
||||||
.v0 = m_vec2_packed_from(v0),
|
.v0 = v0,
|
||||||
.v1 = m_vec2_packed_from(v1),
|
.v1 = v1,
|
||||||
.v2 = m_vec2_packed_from(v2),
|
.v2 = v2,
|
||||||
.v3 = m_vec2_packed_from(v3),
|
.v3 = v3,
|
||||||
|
|
||||||
.uv0 = m_vec2_packed_from(uv0),
|
.uv0 = uv0,
|
||||||
.uv1 = m_vec2_packed_from(uv1),
|
.uv1 = uv1,
|
||||||
.uv2 = m_vec2_packed_from(uv2),
|
.uv2 = uv2,
|
||||||
.uv3 = m_vec2_packed_from(uv3),
|
.uv3 = uv3,
|
||||||
};
|
};
|
||||||
|
|
||||||
return push_to_vertex_buffer_builder(builder, &buffer_element, sizeof buffer_element);
|
return push_to_vertex_buffer_builder(builder, &buffer_element, sizeof buffer_element);
|
||||||
|
|
||||||
} else if (!batch.constant_colored && !batch.textured) {
|
} else if (!batch.constant_colored && !batch.textured) {
|
||||||
ElementIndexedQuadWithoutTexture const buffer_element = {
|
ElementIndexedQuadWithoutTexture const buffer_element = {
|
||||||
.v0 = m_vec2_packed_from(v0),
|
.v0 = v0,
|
||||||
.v1 = m_vec2_packed_from(v1),
|
.v1 = v1,
|
||||||
.v2 = m_vec2_packed_from(v2),
|
.v2 = v2,
|
||||||
.v3 = m_vec2_packed_from(v3),
|
.v3 = v3,
|
||||||
|
|
||||||
/* equal for all (flat shaded) */
|
/* equal for all (flat shaded) */
|
||||||
.c0 = m_color_packed_from(color),
|
.c0 = color,
|
||||||
// .c1 = m_color_packed_from(color),
|
// .c1 = color,
|
||||||
.c2 = m_color_packed_from(color),
|
.c2 = color,
|
||||||
// .c3 = m_color_packed_from(color),
|
// .c3 = color,
|
||||||
};
|
};
|
||||||
|
|
||||||
return push_to_vertex_buffer_builder(builder, &buffer_element, sizeof buffer_element);
|
return push_to_vertex_buffer_builder(builder, &buffer_element, sizeof buffer_element);
|
||||||
|
|
||||||
} else if (batch.constant_colored && !batch.textured) {
|
} else if (batch.constant_colored && !batch.textured) {
|
||||||
ElementIndexedQuadWithoutColorWithoutTexture const buffer_element = {
|
ElementIndexedQuadWithoutColorWithoutTexture const buffer_element = {
|
||||||
.v0 = m_vec2_packed_from(v0),
|
.v0 = v0,
|
||||||
.v1 = m_vec2_packed_from(v1),
|
.v1 = v1,
|
||||||
.v2 = m_vec2_packed_from(v2),
|
.v2 = v2,
|
||||||
.v3 = m_vec2_packed_from(v3),
|
.v3 = v3,
|
||||||
};
|
};
|
||||||
|
|
||||||
return push_to_vertex_buffer_builder(builder, &buffer_element, sizeof buffer_element);
|
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;
|
(void)font_data;
|
||||||
|
|
||||||
ElementIndexedQuadWithoutColor buffer_element = {
|
ElementIndexedQuadWithoutColor buffer_element = {
|
||||||
.v0 = (Vec2Packed){ quad.x0, quad.y0 },
|
.v0 = (Vec2){ quad.x0, quad.y0 },
|
||||||
.v1 = (Vec2Packed){ quad.x1, quad.y0 },
|
.v1 = (Vec2){ quad.x1, quad.y0 },
|
||||||
.v2 = (Vec2Packed){ quad.x1, quad.y1 },
|
.v2 = (Vec2){ quad.x1, quad.y1 },
|
||||||
.v3 = (Vec2Packed){ quad.x0, quad.y1 },
|
.v3 = (Vec2){ quad.x0, quad.y1 },
|
||||||
|
|
||||||
.uv0 = (Vec2Packed){ quad.s0, quad.t0 },
|
.uv0 = (Vec2){ quad.s0, quad.t0 },
|
||||||
.uv1 = (Vec2Packed){ quad.s1, quad.t0 },
|
.uv1 = (Vec2){ quad.s1, quad.t0 },
|
||||||
.uv2 = (Vec2Packed){ quad.s1, quad.t1 },
|
.uv2 = (Vec2){ quad.s1, quad.t1 },
|
||||||
.uv3 = (Vec2Packed){ quad.s0, quad.t1 },
|
.uv3 = (Vec2){ quad.s0, quad.t1 },
|
||||||
};
|
};
|
||||||
|
|
||||||
return push_to_vertex_buffer_builder(builder, &buffer_element, sizeof buffer_element);
|
return push_to_vertex_buffer_builder(builder, &buffer_element, sizeof buffer_element);
|
||||||
|
Loading…
Reference in New Issue
Block a user