fbmgr: add common resize strategy for screen-sized framebuffers

This commit is contained in:
Andrei Alexeyev 2021-04-13 20:17:30 +03:00
parent 0880e7696f
commit 4d8470b0c5
No known key found for this signature in database
GPG key ID: 72D26128040B9690
4 changed files with 16 additions and 22 deletions

View file

@ -413,19 +413,6 @@ static void cutscene_preload(const CutscenePhase phases[]) {
}
}
static void resize_fb(void *userdata, IntExtent *out_dimensions, FloatRect *out_viewport) {
float w, h;
video_get_viewport_size(&w, &h);
out_dimensions->w = w;
out_dimensions->h = h;
out_viewport->w = w;
out_viewport->h = h;
out_viewport->x = 0;
out_viewport->y = 0;
}
static CutsceneState *cutscene_state_new(const CutscenePhase phases[]) {
cutscene_preload(phases);
CutsceneState *st = calloc(1, sizeof(*st));
@ -446,7 +433,7 @@ static CutsceneState *cutscene_state_new(const CutscenePhase phases[]) {
FramebufferConfig fbconf = { 0 };
fbconf.attachments = &a;
fbconf.num_attachments = 1;
fbconf.resize_strategy.resize_func = resize_fb;
fbconf.resize_strategy.resize_func = fbmgr_resize_strategy_screensized;
st->text_fb = fbmgr_group_framebuffer_create(st->mfb_group, "Cutscene text", &fbconf);

View file

@ -12,6 +12,7 @@
#include "list.h"
#include "events.h"
#include "config.h"
#include "video.h"
typedef struct ManagedFramebufferData ManagedFramebufferData;
@ -187,3 +188,10 @@ void fbmgr_group_fbpair_create(ManagedFramebufferGroup *group, const char *name,
snprintf(buf, sizeof(buf), "%s FB 2", name);
fbpair->back = fbmgr_group_framebuffer_create(group, buf, cfg);
}
void fbmgr_resize_strategy_screensized(void *ignored, IntExtent *out_dimensions, FloatRect *out_viewport) {
float w, h;
video_get_viewport_size(&w, &h);
*out_dimensions = (IntExtent) { w, h };
*out_viewport = (FloatRect) { 0, 0, w, h };
}

View file

@ -60,4 +60,10 @@ Framebuffer *fbmgr_group_framebuffer_create(ManagedFramebufferGroup *group, cons
void fbmgr_group_fbpair_create(ManagedFramebufferGroup *group, const char *name, const FramebufferConfig *cfg, FBPair *fbpair)
attr_nonnull(1, 2, 3, 4);
// For use as FramebufferConfig.resize_func.resize_func
// Configures the framebuffer to be as large as the main framebuffer, minus the letterboxing
// (as in video_get_viewport_size())
// Requires no cleanup
void fbmgr_resize_strategy_screensized(void *ignored, IntExtent *out_dimensions, FloatRect *out_viewport);
#endif // IGUARD_util_fbmgr_h

View file

@ -22,13 +22,6 @@ struct VideoPostProcess {
int frames;
};
static void video_postprocess_resize_strategy(void *userdata, IntExtent *fb_size, FloatRect *fb_viewport) {
float w, h;
video_get_viewport_size(&w, &h);
*fb_size = (IntExtent) { w, h };
*fb_viewport = (FloatRect) { 0, 0, w, h };
}
VideoPostProcess *video_postprocess_init(void) {
PostprocessShader *pps = get_resource_data(RES_POSTPROCESS, "global", RESF_OPTIONAL | RESF_PERMANENT | RESF_PRELOAD);
@ -54,7 +47,7 @@ VideoPostProcess *video_postprocess_init(void) {
FramebufferConfig fbconf = { 0 };
fbconf.num_attachments = 1;
fbconf.attachments = &a;
fbconf.resize_strategy.resize_func = video_postprocess_resize_strategy;
fbconf.resize_strategy.resize_func = fbmgr_resize_strategy_screensized;
fbmgr_group_fbpair_create(vpp->mfb_group, "Global postprocess", &fbconf, &vpp->framebuffers);
return vpp;