renderer/common/sprite_batch: remove string fields from SpriteParams

This commit is contained in:
Andrei Alexeyev 2024-09-22 21:06:57 +02:00
parent 2b21ee0e3f
commit 7f570d2338
No known key found for this signature in database
GPG key ID: 72D26128040B9690
19 changed files with 65 additions and 78 deletions

View file

@ -438,7 +438,7 @@ static void draw_spell_name(Boss *b, int time, bool healthbar_radial) {
float opacity = opacity_noplr * b->hud.plrproximity_opacity;
r_draw_sprite(&(SpriteParams) {
.sprite = "spell",
.sprite_ptr = res_sprite("spell"),
.pos = { (VIEWPORT_W - 128), y_offset * (1 - pow(1 - f2, 5)) + VIEWPORT_H * pow(1 - f2, 2) },
.color = color_mul_scalar(RGBA(1, 1, 1, f2 * 0.5), opacity * f2) ,
.scale.both = 3 - 2 * (1 - pow(1 - f2, 3)),
@ -684,7 +684,7 @@ void draw_boss_background(Boss *boss) {
r_mat_mv_scale(f, f, 1);
r_draw_sprite(&(SpriteParams) {
.sprite = "boss_circle",
.sprite_ptr = res_sprite("boss_circle"),
.color = RGBA(1, 1, 1, 0),
});
r_mat_mv_pop();

View file

@ -454,7 +454,7 @@ static void credits_draw_entry(CreditsEntry *e) {
r_draw_sprite(&(SpriteParams) {
.sprite_ptr = yukkuri_spr,
.pos.y = -60 * elevation * fadein + halfheight * squeeze,
.shader = "sprite_default",
.shader_ptr = res_shader("sprite_default"),
.scale.x = 1.0 - squeeze,
.scale.y = 1.0 + squeeze,
});

View file

@ -222,7 +222,7 @@ static void charprofile_draw(MenuData *m) {
SpriteParams portrait_params = {
.pos = { SCREEN_W/2 + 240 + 320 * pofs, SCREEN_H - spr->h * 0.5 },
.sprite_ptr = spr,
.shader = "sprite_default",
.shader_ptr = res_shader("sprite_default"),
.color = color,
};
@ -235,7 +235,7 @@ static void charprofile_draw(MenuData *m) {
.align = ALIGN_LEFT,
.pos = { 25, 570 },
.font = "standard",
.shader = "text_default",
.shader_ptr = res_shader("text_default"),
.color = RGBA(0.9, 0.9, 0.9, 0.9),
});
}
@ -253,7 +253,7 @@ static void charprofile_draw(MenuData *m) {
text_draw(profiles[selected].fullname, &(TextParams) {
.align = ALIGN_CENTER,
.font = "big",
.shader = "text_default",
.shader_ptr = res_shader("text_default"),
.color = RGBA(o, o, o, o),
});
r_mat_mv_pop();
@ -267,7 +267,7 @@ static void charprofile_draw(MenuData *m) {
text_draw(profiles[selected].title, &(TextParams) {
.align = ALIGN_CENTER,
.pos = { 20*(1-o), 30 },
.shader = "text_default",
.shader_ptr = res_shader("text_default"),
.color = RGBA(o, o, o, o),
});
r_mat_mv_pop();
@ -276,7 +276,7 @@ static void charprofile_draw(MenuData *m) {
.align = ALIGN_LEFT,
.pos = { -175, 120 },
.font = "small",
.shader = "text_default",
.shader_ptr = res_shader("text_default"),
.color = RGBA(o, o, o, o),
});
r_mat_mv_pop();
@ -285,14 +285,14 @@ static void charprofile_draw(MenuData *m) {
r_shader("sprite_default");
r_draw_sprite(&(SpriteParams) {
.sprite = "menu/arrow",
.sprite_ptr = res_sprite("menu/arrow"),
.pos = { 30, SCREEN_H/3+10 },
.color = RGBA(o, o, o, o),
.scale = { 0.5, 0.7 },
});
r_draw_sprite(&(SpriteParams) {
.sprite = "menu/arrow",
.sprite_ptr = res_sprite("menu/arrow"),
.pos = { 30 + 340, SCREEN_H/3+10 },
.color = RGBA(o, o, o, o),
.scale = { 0.5, 0.7 },

View file

@ -215,7 +215,7 @@ void draw_char_menu(MenuData *menu) {
SpriteParams portrait_params = {
.pos = { SCREEN_W/2 + 240 + 320 * pofs, SCREEN_H - spr->h * 0.5 },
.sprite_ptr = spr,
.shader = "sprite_default",
.shader_ptr = res_shader("sprite_default"),
.color = RGBA(pbrightness, pbrightness, pbrightness, 1),
// .flip.x = true,
};
@ -237,7 +237,7 @@ void draw_char_menu(MenuData *menu) {
text_draw(name, &(TextParams) {
.align = ALIGN_CENTER,
.font = "big",
.shader = "text_default",
.shader_ptr = res_shader("text_default"),
.color = RGBA(o, o, o, o),
});
@ -252,7 +252,7 @@ void draw_char_menu(MenuData *menu) {
text_draw(title, &(TextParams) {
.align = ALIGN_CENTER,
.pos = { 20*(1-o), 30 },
.shader = "text_default",
.shader_ptr = res_shader("text_default"),
.color = RGBA(o, o, o, o),
});
@ -298,7 +298,7 @@ void draw_char_menu(MenuData *menu) {
text_draw(buf, &(TextParams) {
.align = ALIGN_CENTER,
.pos = { 0, y},
.shader = "text_default",
.shader_ptr = res_shader("text_default"),
});
if(shot == current_subshot) {
@ -306,7 +306,7 @@ void draw_char_menu(MenuData *menu) {
text_draw_wrapped(mode->description, DESCRIPTION_WIDTH, &(TextParams) {
.align = ALIGN_CENTER,
.pos = { 0, y + 30 },
.shader = "text_default",
.shader_ptr = res_shader("text_default"),
});
}
}
@ -318,14 +318,14 @@ void draw_char_menu(MenuData *menu) {
r_shader("sprite_default");
r_draw_sprite(&(SpriteParams) {
.sprite = "menu/arrow",
.sprite_ptr = res_sprite("menu/arrow"),
.pos = { 30, SCREEN_H/3+10 },
.color = RGBA(o, o, o, o),
.scale = { 0.5, 0.7 },
});
r_draw_sprite(&(SpriteParams) {
.sprite = "menu/arrow",
.sprite_ptr = res_sprite("menu/arrow"),
.pos = { 30 + 340, SCREEN_H/3+10 },
.color = RGBA(o, o, o, o),
.scale = { 0.5, 0.7 },

View file

@ -220,7 +220,7 @@ void draw_menu_selector(float x, float y, float w, float h, float t) {
r_draw_sprite(&(SpriteParams) {
.sprite_ptr = bg,
.color = RGBA(0, 0, 0, 0.5 * (1 - transition.fade)),
.shader = "sprite_default",
.shader_ptr = res_shader("sprite_default"),
});
r_mat_mv_pop();
}
@ -231,7 +231,7 @@ void draw_menu_title(MenuData *m, const char *title) {
.align = ALIGN_RIGHT,
.font = "big",
.color = RGB(1, 1, 1),
.shader = "text_default",
.shader_ptr = res_shader("text_default"),
});
}

View file

@ -89,7 +89,7 @@ void draw_difficulty_menu(MenuData *menu) {
dynarray_foreach(&menu->entries, int i, MenuEntry *e, {
float scale = 0.5 + e->drawdata;
r_draw_sprite(&(SpriteParams) {
.sprite = difficulty_sprite_name(D_Easy + i),
.sprite_ptr = res_sprite(difficulty_sprite_name(D_Easy + i)),
.pos = { 0, 240 * tanh(0.7 * (i - menu->drawdata[0])) },
.color = RGBA(scale, scale, scale, scale),
.scale.both = scale,

View file

@ -164,9 +164,9 @@ void draw_main_menu(MenuData *menu) {
float rotfac = (1 - pow(menu_fade(menu), 2.0));
r_draw_sprite(&(SpriteParams) {
.sprite = "menu/logo",
.sprite_ptr = res_sprite("menu/logo"),
.shader_ptr = res_shader("sprite_default"),
.pos = { SCREEN_W/2, SCREEN_H/2 },
.shader = "sprite_default",
.rotation.vector = { 0, -1, 0 },
.rotation.angle = max(0, M_PI/1.5 - min(M_PI/1.5, rot) * rotfac),
.color = color_mul_scalar(RGBA(1, 1, 1, 1), min(1, rot) * rotfac),
@ -220,7 +220,7 @@ void draw_main_menu(MenuData *menu) {
continue;
r_draw_sprite(&(SpriteParams) {
.sprite = "part/petal",
.sprite_ptr = res_sprite("part/petal"),
.color = RGBA(1, 1, 1, 0),
.pos = { posx, posy },
.scale.both = 0.2,
@ -237,7 +237,7 @@ void draw_main_menu(MenuData *menu) {
.align = ALIGN_RIGHT,
.pos = { SCREEN_W-5, SCREEN_H-10 },
.font = "small",
.shader = "text_default",
.shader_ptr = res_shader("text_default"),
.color = RGBA(1, 1, 1, 1),
});
@ -256,7 +256,7 @@ void draw_loading_screen(void) {
.align = ALIGN_CENTER,
.pos = { SCREEN_W/2, SCREEN_H-20 },
.font = "standard",
.shader = "text_default",
.shader_ptr = res_shader("text_default"),
.color = RGBA(0.35, 0.35, 0.35, 0.35),
});

View file

@ -263,7 +263,7 @@ static void ent_draw_player(EntityInterface *ent) {
if(plr->focus_circle_alpha) {
r_draw_sprite(&(SpriteParams) {
.sprite = "fairy_circle",
.sprite_ptr = res_sprite("fairy_circle"),
.rotation.angle = DEG2RAD * global.frames * 10,
.color = RGBA_MUL_ALPHA(1, 1, 1, 0.2 * plr->focus_circle_alpha),
.pos = { re(plr->pos), im(plr->pos) },

View file

@ -84,8 +84,8 @@ static void draw_masterspark_ring(int t, float width) {
}
r_draw_sprite(&(SpriteParams) {
.sprite = "masterspark_ring",
.shader = "sprite_default",
.sprite_ptr = res_sprite("masterspark_ring"),
.shader_ptr = res_shader("sprite_default"),
.pos = { 0, -t*t*0.4 + 2 },
.color = RGBA(0.5, 0.5, 0.5, 0.0),
.scale = { .x = sx, .y = sy * sy * 1.5 },

View file

@ -89,7 +89,7 @@ void portrait_render(Sprite *s_base, Sprite *s_face, Sprite *s_out) {
sp.pos.x = spr_w * 0.5f - s_base->padding.offset.x;
sp.pos.y = spr_h * 0.5f - s_base->padding.offset.y;
sp.color = RGBA(1, 1, 1, 1);
sp.shader_ptr = res_shader("sprite_default"),
sp.shader_ptr = res_shader("sprite_default");
r_draw_sprite(&sp);
sp.blend = BLEND_PREMUL_ALPHA;
sp.sprite_ptr = s_face;

View file

@ -440,10 +440,10 @@ typedef union ShaderCustomParams {
} ShaderCustomParams;
typedef struct SpriteStateParams {
ShaderProgram *shader;
Texture *primary_texture;
Texture *aux_textures[R_NUM_SPRITE_AUX_TEXTURES];
BlendMode blend;
ShaderProgram *shader;
} SpriteStateParams;
typedef union SpriteScaleParams {
@ -470,12 +470,8 @@ typedef struct SpriteFlipParams {
} SpriteFlipParams;
typedef struct SpriteParams {
const char *sprite;
Sprite *sprite_ptr;
const char *shader;
ShaderProgram *shader_ptr;
Texture *aux_textures[R_NUM_SPRITE_AUX_TEXTURES];
// TODO: maybe embed these by value and get rid of SpriteParamsBuffer?

View file

@ -259,12 +259,8 @@ INLINE void _r_sprite_batch_process_params(
SpriteStateParams *restrict state_params,
Sprite *restrict *sprite
) {
assert(!(sprite_params->shader && sprite_params->shader_ptr));
assert(!(sprite_params->sprite && sprite_params->sprite_ptr));
if((*sprite = sprite_params->sprite_ptr) == NULL) {
*sprite = res_sprite(NOT_NULL(sprite_params->sprite));
}
assert(sprite_params->sprite_ptr != NULL);
*sprite = sprite_params->sprite_ptr;
state_params->primary_texture = (*sprite)->tex;
memcpy(&state_params->aux_textures, &sprite_params->aux_textures, sizeof(sprite_params->aux_textures));
@ -275,11 +271,7 @@ INLINE void _r_sprite_batch_process_params(
}
if((state_params->shader = sprite_params->shader_ptr) == NULL) {
if(sprite_params->shader != NULL) {
state_params->shader = res_shader(sprite_params->shader);
} else {
state_params->shader = r_shader_current();
}
state_params->shader = r_shader_current();
}
}

View file

@ -537,8 +537,8 @@ static void draw_spellbg(int t) {
}
r_draw_sprite(&(SpriteParams) {
.sprite = "boss_spellcircle0",
.shader = "sprite_default",
.sprite_ptr = res_sprite("boss_spellcircle0"),
.shader_ptr = res_shader("sprite_default"),
.pos = { re(b->pos), im(b->pos) },
.rotation.angle = global.frames * 7.0 * DEG2RAD,
.rotation.vector = { 0, 0, -1 },
@ -1740,10 +1740,10 @@ void stage_draw_hud(void) {
// Difficulty indicator
r_draw_sprite(&(SpriteParams) {
.sprite = difficulty_sprite_name(global.diff),
.sprite_ptr = res_sprite(difficulty_sprite_name(global.diff)),
.pos = { HUD_EFFECTIVE_WIDTH * 0.5, 400 },
.scale.both = 0.6,
.shader = "sprite_default",
.shader_ptr = res_shader("sprite_default"),
});
// Power/Item/Voltage icons
@ -1752,41 +1752,41 @@ void stage_draw_hud(void) {
r_draw_sprite(&(SpriteParams) {
.pos = { 2, labels.y.power + 2 },
.sprite = "item/power",
.shader = "sprite_default",
.sprite_ptr = res_sprite("item/power"),
.shader_ptr = res_shader("sprite_default"),
.color = RGBA(0, 0, 0, 0.5),
});
r_draw_sprite(&(SpriteParams) {
.pos = { 0, labels.y.power },
.sprite = "item/power",
.shader = "sprite_default",
.sprite_ptr = res_sprite("item/power"),
.shader_ptr = res_shader("sprite_default"),
});
r_draw_sprite(&(SpriteParams) {
.pos = { 2, labels.y.value + 2 },
.sprite = "item/point",
.shader = "sprite_default",
.sprite_ptr = res_sprite("item/point"),
.shader_ptr = res_shader("sprite_default"),
.color = RGBA(0, 0, 0, 0.5),
});
r_draw_sprite(&(SpriteParams) {
.pos = { 0, labels.y.value },
.sprite = "item/point",
.shader = "sprite_default",
.sprite_ptr = res_sprite("item/point"),
.shader_ptr = res_shader("sprite_default"),
});
r_draw_sprite(&(SpriteParams) {
.pos = { 2, labels.y.voltage + 2 },
.sprite = "item/voltage",
.shader = "sprite_default",
.sprite_ptr = res_sprite("item/voltage"),
.shader_ptr = res_shader("sprite_default"),
.color = RGBA(0, 0, 0, 0.5),
});
r_draw_sprite(&(SpriteParams) {
.pos = { 0, labels.y.voltage },
.sprite = "item/voltage",
.shader = "sprite_default",
.sprite_ptr = res_sprite("item/voltage"),
.shader_ptr = res_shader("sprite_default"),
});
r_mat_mv_pop();
@ -1828,8 +1828,8 @@ void stage_draw_hud(void) {
red = 0;
r_draw_sprite(&(SpriteParams) {
.sprite = "boss_indicator",
.shader = "sprite_default",
.sprite_ptr = res_sprite("boss_indicator"),
.shader_ptr = res_shader("sprite_default"),
.pos = { VIEWPORT_X+re(global.boss->pos), 590 },
.color = RGBA(1 - red, 1 - red, 1 - red, 1 - red),
});
@ -1874,7 +1874,7 @@ void stage_draw_hud(void) {
text_draw("Demo", &(TextParams) {
.align = ALIGN_CENTER,
.font = "big",
.shader = "text_demo",
.shader_ptr = res_shader("text_demo"),
.shader_params = &(ShaderCustomParams) { global.frames / 60.0f },
.pos.as_cmplx = pos,
});

View file

@ -198,7 +198,7 @@ static void stage1_smoke_draw(vec3 pos) {
r_mat_mv_scale(3.5*2, 2*1.5, 1);
r_mat_mv_rotate(global.frames * spin + M_PI * 2 * sin(pos[1]*321.23), 0, 0, 1);
r_draw_sprite(&(SpriteParams) {
.sprite = "stage1/fog",
.sprite_ptr = res_sprite("stage1/fog"),
.color = RGBA(0.6 * o, 0.7 * o, 0.8 * o, o * 0.5),
});
r_mat_mv_pop();
@ -260,7 +260,7 @@ static void stage1_waterplants_draw(vec3 pos) {
r_mat_tex_translate(tile, 0, 0);
r_draw_sprite(&(SpriteParams) {
.sprite_ptr = &spr,
.shader = "sprite_default",
.shader_ptr = res_shader("sprite_default"),
.flip.x = floathash(pos[1] * 231544.213) & 1,
.flip.y = floathash(pos[1] * 941233.513) & 1,
.color = RGBA(0.5*a, 0.4*a, 0.5*a, 0.5*a),
@ -316,7 +316,7 @@ static void stage1_snow_draw(vec3 pos) {
r_mat_mv_translate(pos[0] + 2200 * sawtooth(h1), pos[1] + 10 * sawtooth(h2), 1200 - 1200 * height);
r_mat_mv_rotate(M_PI/2, -1, 0, 0);
r_draw_sprite(&(SpriteParams) {
.sprite = "part/smoothdot",
.sprite_ptr = res_sprite("part/smoothdot"),
.color = RGBA(o, o, o, 0),
});
r_mat_mv_pop();

View file

@ -17,18 +17,17 @@ void stage2_draw_hina_spellbg(Boss *h, int time) {
sp.pos.y = VIEWPORT_H/2;
sp.scale.both = 0.6;
sp.shader_ptr = res_shader("sprite_default");
sp.sprite_ptr = res_sprite("stage2/spellbg1");
sp.blend = BLEND_PREMUL_ALPHA;
sp.sprite = "stage2/spellbg1";
r_draw_sprite(&sp);
sp.scale.both = 1;
sp.blend = BLEND_MOD;
sp.sprite = "stage2/spellbg2";
sp.sprite_ptr = res_sprite("stage2/spellbg2");
sp.rotation = (SpriteRotationParams) { .angle = time * 5 * DEG2RAD, .vector = { 0, 0, 1 } };
r_draw_sprite(&sp);
Animation *fireani = res_anim("fire");
sp.sprite_ptr = animation_get_frame(fireani, get_ani_sequence(fireani, "main"), global.frames);
sp.sprite = NULL;
sp.pos.x = re(h->pos);
sp.pos.y = im(h->pos);
sp.scale.both = 1;

View file

@ -18,13 +18,13 @@ TASK(spinner_bullet_redirect, { BoxedProjectile p; MoveParams move; }) {
static void amulet_draw(Enemy *e, EnemyDrawParams p) {
r_draw_sprite(&(SpriteParams) {
.color = RGBA(2, 1, 1, 0),
.sprite = "fairy_circle_big",
.sprite_ptr = res_sprite("fairy_circle_big"),
.pos.as_cmplx = p.pos,
.rotation.angle = p.time * 5 * DEG2RAD,
});
r_draw_sprite(&(SpriteParams) {
.sprite = "enemy/swirl",
.sprite_ptr = res_sprite("enemy/swirl"),
.pos.as_cmplx = p.pos,
.rotation.angle = p.time * -10 * DEG2RAD,
});

View file

@ -21,10 +21,10 @@ static void kurumi_extra_shield_draw(Enemy *e, EnemyDrawParams p) {
1 + (1 - h), 0.3 + 0.7 * h, 0.2 + 0.8 * h,
1 + 1 - h
),
.sprite = "enemy/swirl",
.sprite_ptr = res_sprite("enemy/swirl"),
.pos.as_cmplx = p.pos,
.rotation.angle = p.time * -10 * DEG2RAD,
.shader = "sprite_negative",
.shader_ptr = res_shader("sprite_negative"),
});
}
@ -179,7 +179,7 @@ TASK(kurumi_vladsarmy_drainer, { BoxedBoss boss; BoxedEnemy enemy; }) {
.func = kurumi_extra_drainer_draw,
.args[0].as_ptr = &state,
},
.shader = "sprite_default",
.shader_ptr = res_shader("sprite_default"),
.flags = PFLAG_NOCLEAR | PFLAG_NOCOLLISION,
.layer = LAYER_BOSS - 1,
));

View file

@ -155,7 +155,7 @@ static void stage6_skysphere_draw(vec3 pos) {
r_mat_mv_rotate(acos(p[2]), -p[1], p[0], 0);
r_mat_mv_scale(3e-4, 3e-4, 3e-4);
r_draw_sprite(&(SpriteParams) {
.sprite = "part/smoothdot",
.sprite_ptr = res_sprite("part/smoothdot"),
.color = RGBA_MUL_ALPHA(1, 1, 1, sqrt(p[2])),
});
r_mat_mv_pop();

View file

@ -19,7 +19,7 @@ void elly_spellbg_toe(Boss *b, int t) {
.pos = { VIEWPORT_W / 2.0, VIEWPORT_H / 2.0 },
.scale.both = 0.75 + 0.0005 * t,
.rotation.angle = t * 0.1 * DEG2RAD,
.sprite = "stage6/spellbg_toe",
.sprite_ptr = res_sprite("stage6/spellbg_toe"),
.color = RGB(0.6, 0.6, 0.6),
});
@ -56,7 +56,7 @@ void elly_spellbg_toe(Boss *b, int t) {
SpriteParams sp = {
.color = &color,
.sprite = texname,
.sprite_ptr = res_sprite(texname),
.pos = {
VIEWPORT_W / 2.0 + positions[i][0] + cos(wobble + i) * wobble,
VIEWPORT_H / 2.0 - 150 + positions[i][1] + sin(i + wobble) * wobble,