diff --git a/CMakeLists.txt b/CMakeLists.txt index 73a5efe..1c6cd98 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -105,6 +105,7 @@ else() -Wdouble-promotion -Wconversion -Wno-sign-conversion -Werror=vla + $<$:-Wcast-align=strict> $<$:${WARNING_FLAGS_CLANG}>) set(BUILD_FLAGS diff --git a/src/rendering/sprites.h b/src/rendering/sprites.h index 72ef96d..6825532 100644 --- a/src/rendering/sprites.h +++ b/src/rendering/sprites.h @@ -15,6 +15,7 @@ /* interleaved vertex array data */ /* 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 sprite_primitive_payload { /* upper-left */ @@ -113,7 +114,7 @@ static struct sprite_batch { .constant_colored = true, }; - const t_color uniform_color = primitives[0].sprite.color; + const uint32_t uniform_color = *(uint32_t *)&primitives[0].sprite.color; /* batch size is clamped so that reallocated short indices could be used */ if (len >= QUAD_ELEMENT_BUFFER_LENGTH) @@ -136,10 +137,7 @@ static struct sprite_batch { break; /* if all are modulated the same we can skip sending the color data */ - if (batch.constant_colored && (current->sprite.color.r != uniform_color.r || - current->sprite.color.g != uniform_color.g || - current->sprite.color.b != uniform_color.b || - current->sprite.color.a != uniform_color.a )) + if (batch.constant_colored && *(uint32_t *)¤t->sprite.color == uniform_color) batch.constant_colored = false; ++batch.size; diff --git a/src/util.h b/src/util.h index 10b02af..44ea51f 100644 --- a/src/util.h +++ b/src/util.h @@ -70,6 +70,7 @@ bool strends(const char *str, const char *suffix); /* 32-bit color data */ typedef struct color { +_Alignas(4) uint8_t r; uint8_t g; uint8_t b; @@ -85,14 +86,19 @@ typedef struct vec2 { /* a point in some space (floating point) */ typedef struct fvec2 { - float x, y; +_Alignas(8) + float x; + float y; } t_fvec2; /* a point in some three dimension space (floating point) */ /* y goes up, x goes to the right */ typedef struct fvec3 { - float x, y, z; +_Alignas(8) + float x; + float y; + float z; } t_fvec3; @@ -111,8 +117,11 @@ typedef struct rect { /* a rectangle with the origin at the upper left (floating point) */ typedef struct frect { - float x, y; - float w, h; +_Alignas(16) + float x; + float y; + float w; + float h; } t_frect;