aligned for vectorization commor primitives, uint32_t cast for color comparison in batch collection
This commit is contained in:
parent
c9f4f85fce
commit
8846e788b2
@ -105,6 +105,7 @@ else()
|
||||
-Wdouble-promotion
|
||||
-Wconversion -Wno-sign-conversion
|
||||
-Werror=vla
|
||||
$<$<STREQUAL:${CMAKE_C_COMPILER_ID},Gnu>:-Wcast-align=strict>
|
||||
$<$<STREQUAL:${CMAKE_C_COMPILER_ID},Clang>:${WARNING_FLAGS_CLANG}>)
|
||||
|
||||
set(BUILD_FLAGS
|
||||
|
@ -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;
|
||||
|
17
src/util.h
17
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;
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user