remove optional by pointer texture_region parameters
This commit is contained in:
@ -12,7 +12,7 @@
|
||||
void draw_billboard(char const *texture,
|
||||
Vec3 position,
|
||||
Vec2 size,
|
||||
Rect const *texture_region,
|
||||
Rect texture_region,
|
||||
Color color,
|
||||
bool cylindrical)
|
||||
{
|
||||
@ -26,16 +26,19 @@ void draw_billboard(char const *texture,
|
||||
batch_p = &ctx.billboard_batches[hmlenu(ctx.billboard_batches) - 1]; /* TODO: can last index be used? */
|
||||
}
|
||||
|
||||
bool const texture_region_valid = fabsf(texture_region.w - texture_region.h) > 0.00001f
|
||||
&& fabsf(0.0f - texture_region.w) > 0.00001f;
|
||||
|
||||
struct SpaceBillboard billboard = {
|
||||
.color = color,
|
||||
.cylindrical = cylindrical,
|
||||
.position = position,
|
||||
.size = size,
|
||||
.texture_region_opt_set = texture_region != NULL,
|
||||
.texture_region_opt_set = texture_region_valid,
|
||||
};
|
||||
|
||||
if (texture_region)
|
||||
billboard.texture_region_opt = *texture_region;
|
||||
if (texture_region_valid)
|
||||
billboard.texture_region_opt = texture_region;
|
||||
|
||||
struct SpaceBillboard *billboards = (struct SpaceBillboard *)(void *)batch_p->value.primitives;
|
||||
|
||||
|
@ -19,13 +19,18 @@
|
||||
*/
|
||||
void draw_sprite(char const *path,
|
||||
Rect rect,
|
||||
Rect const *texture_region, /* optional, default: NULL */
|
||||
Rect texture_region, /* optional, default: 0 */
|
||||
Color color, /* optional, default: all 255 */
|
||||
float rotation, /* optional, default: 0 */
|
||||
bool flip_x, /* optional, default: false */
|
||||
bool flip_y, /* optional, default: false */
|
||||
bool stretch)
|
||||
{
|
||||
/* if .w and .h are zeroed then assume whole region */
|
||||
/* TODO: don't check here, just move to redner code ? */
|
||||
bool const texture_region_valid = fabsf(texture_region.w - texture_region.h) > 0.00001f
|
||||
&& fabsf(0.0f - texture_region.w) > 0.00001f;
|
||||
|
||||
SpritePrimitive sprite = {
|
||||
.rect = rect,
|
||||
.color = color,
|
||||
@ -34,11 +39,11 @@ void draw_sprite(char const *path,
|
||||
.flip_x = flip_x,
|
||||
.flip_y = flip_y,
|
||||
.repeat = !stretch,
|
||||
.texture_region_opt_set = texture_region != NULL,
|
||||
.texture_region_opt_set = texture_region_valid,
|
||||
};
|
||||
|
||||
if (texture_region)
|
||||
sprite.texture_region_opt = *texture_region;
|
||||
if (texture_region_valid)
|
||||
sprite.texture_region_opt = texture_region;
|
||||
|
||||
Primitive2D primitive = {
|
||||
.type = PRIMITIVE_2D_SPRITE,
|
||||
@ -54,7 +59,7 @@ void draw_sprite_args(const DrawSpriteArgs args) {
|
||||
bool const flip_x = m_or(args, flip_x, false);
|
||||
bool const flip_y = m_or(args, flip_y, false);
|
||||
bool const stretch = m_or(args, stretch, false);
|
||||
Rect const *texture_region = m_is_set(args, texture_region) ? &args.texture_region_opt : NULL;
|
||||
Rect const texture_region = m_or(args, texture_region, ((Rect){0}));
|
||||
|
||||
draw_sprite(args.texture, args.rect, texture_region, color, rotation, flip_x, flip_y, stretch);
|
||||
}
|
||||
|
Reference in New Issue
Block a user