new option-based api for sprite issue
This commit is contained in:
@ -2,6 +2,7 @@
|
||||
#define RENDERING_H
|
||||
|
||||
#include "util.h"
|
||||
#include "macros/option.h"
|
||||
#include "camera.h"
|
||||
|
||||
#include <SDL2/SDL.h>
|
||||
@ -10,10 +11,13 @@
|
||||
|
||||
typedef struct push_sprite_args {
|
||||
char *path;
|
||||
t_color color;
|
||||
float rotation;
|
||||
bool flip_x;
|
||||
bool flip_y;
|
||||
t_frect rect;
|
||||
|
||||
m_option_list(
|
||||
t_color, color,
|
||||
float, rotation,
|
||||
bool, flip_x,
|
||||
bool, flip_y )
|
||||
} t_push_sprite_args;
|
||||
|
||||
/* clears all render queues */
|
||||
@ -21,12 +25,9 @@ void render_queue_clear(void);
|
||||
|
||||
/* pushes a sprite onto the sprite render queue */
|
||||
/* this is a simplified version of push_sprite_ex for the most common case. */
|
||||
/* it assumes you want no color modulation, no rotation, no flip, layer 0, and alpha blending */
|
||||
void push_sprite(char *path, t_frect rect);
|
||||
|
||||
/* pushes a sprite onto the sprite render queue */
|
||||
/* note that if args is zeroed out, the color will be transparent black */
|
||||
void push_sprite_ex(t_frect rect, t_push_sprite_args args);
|
||||
/* it assumes you want no color modulation, no rotation, no flip */
|
||||
void push_sprite(t_push_sprite_args args);
|
||||
#define m_sprite(...) (push_sprite((t_push_sprite_args){__VA_ARGS__}))
|
||||
|
||||
/* pushes a filled rectangle onto the rectangle render queue */
|
||||
void push_rectangle(t_frect rect, t_color color);
|
||||
@ -65,7 +66,7 @@ void unfurl_triangle(const char *path,
|
||||
// t_frect uvs);
|
||||
|
||||
/* pushes a camera state to be used for all future unfurl_* commands */
|
||||
void push_camera(const t_camera *camera);
|
||||
void set_camera(const t_camera *camera);
|
||||
|
||||
/* renders the background, then the primitives in all render queues */
|
||||
void render(void);
|
||||
|
@ -61,33 +61,14 @@ struct sprite_primitive_payload_without_color {
|
||||
*/
|
||||
/* TODO: it might make sense to infer alpha channel presence / meaningfulness for textures in atlas */
|
||||
/* so that they are rendered with no blend / batched in a way to reduce overdraw automatically */
|
||||
void push_sprite(char *path, t_frect rect) {
|
||||
void push_sprite(const t_push_sprite_args args) {
|
||||
struct sprite_primitive sprite = {
|
||||
.rect = rect,
|
||||
.color = (t_color) { 255, 255, 255, 255 },
|
||||
.rotation = 0.0,
|
||||
.texture_key = textures_get_key(&ctx.texture_cache, path),
|
||||
.flip_x = false,
|
||||
.flip_y = false,
|
||||
};
|
||||
|
||||
struct primitive_2d primitive = {
|
||||
.type = PRIMITIVE_2D_SPRITE,
|
||||
.sprite = sprite,
|
||||
};
|
||||
|
||||
arrput(ctx.render_queue_2d, primitive);
|
||||
}
|
||||
|
||||
|
||||
void push_sprite_ex(t_frect rect, t_push_sprite_args args) {
|
||||
struct sprite_primitive sprite = {
|
||||
.rect = rect,
|
||||
.color = args.color,
|
||||
.rotation = args.rotation,
|
||||
.rect = args.rect,
|
||||
.color = m_or(args, color, ((t_color) { 255, 255, 255, 255 })),
|
||||
.rotation = m_or(args, rotation, 0.0f),
|
||||
.texture_key = textures_get_key(&ctx.texture_cache, args.path),
|
||||
.flip_x = args.flip_x,
|
||||
.flip_y = args.flip_y,
|
||||
.flip_x = m_or(args, flip_x, false),
|
||||
.flip_y = m_or(args, flip_y, false),
|
||||
};
|
||||
|
||||
struct primitive_2d primitive = {
|
||||
|
Reference in New Issue
Block a user