Add stage_add_static_framebuffer
Register a stagedraw-managed framebuffer with static size
This commit is contained in:
parent
f12fc3db0f
commit
3fc75a4bbd
3 changed files with 40 additions and 19 deletions
|
@ -244,14 +244,21 @@ static Framebuffer *add_custom_framebuffer(
|
|||
return fbmgr_group_framebuffer_create(stagedraw.mfb_group, label, &fbconf);
|
||||
}
|
||||
|
||||
Framebuffer* stage_add_foreground_framebuffer(const char *label, float scale_worst, float scale_best, uint num_attachments, FBAttachmentConfig attachments[num_attachments]) {
|
||||
Framebuffer *stage_add_foreground_framebuffer(const char *label, float scale_worst, float scale_best, uint num_attachments, FBAttachmentConfig attachments[num_attachments]) {
|
||||
return add_custom_framebuffer(label, FBPAIR_FG, scale_worst, scale_best, num_attachments, attachments);
|
||||
}
|
||||
|
||||
Framebuffer* stage_add_background_framebuffer(const char *label, float scale_worst, float scale_best, uint num_attachments, FBAttachmentConfig attachments[num_attachments]) {
|
||||
Framebuffer *stage_add_background_framebuffer(const char *label, float scale_worst, float scale_best, uint num_attachments, FBAttachmentConfig attachments[num_attachments]) {
|
||||
return add_custom_framebuffer(label, FBPAIR_BG, scale_worst, scale_best, num_attachments, attachments);
|
||||
}
|
||||
|
||||
Framebuffer *stage_add_static_framebuffer(const char *label, uint num_attachments, FBAttachmentConfig attachments[num_attachments]) {
|
||||
FramebufferConfig fbconf = { 0 };
|
||||
fbconf.attachments = attachments;
|
||||
fbconf.num_attachments = num_attachments;
|
||||
return fbmgr_group_framebuffer_create(stagedraw.mfb_group, label, &fbconf);
|
||||
}
|
||||
|
||||
static void stage_draw_destroy_framebuffers(void) {
|
||||
fbmgr_group_destroy(stagedraw.mfb_group);
|
||||
stagedraw.mfb_group = NULL;
|
||||
|
|
|
@ -51,5 +51,6 @@ FBPair *stage_get_fbpair(StageFBPair id) attr_returns_nonnull;
|
|||
FBPair *stage_get_postprocess_fbpair(void) attr_returns_nonnull;
|
||||
Framebuffer *stage_add_foreground_framebuffer(const char *label, float scale_worst, float scale_best, uint num_attachments, FBAttachmentConfig attachments[num_attachments]);
|
||||
Framebuffer *stage_add_background_framebuffer(const char *label, float scale_worst, float scale_best, uint num_attachments, FBAttachmentConfig attachments[num_attachments]);
|
||||
Framebuffer *stage_add_static_framebuffer(const char *label, uint num_attachments, FBAttachmentConfig attachments[num_attachments]);
|
||||
|
||||
#endif // IGUARD_stagedraw_h
|
||||
|
|
|
@ -31,17 +31,21 @@ struct ManagedFramebufferGroup {
|
|||
|
||||
static ManagedFramebufferData *framebuffers;
|
||||
|
||||
static inline void fbmgr_framebuffer_get_metrics(ManagedFramebuffer *mfb, IntExtent *fb_size, FloatRect *fb_viewport) {
|
||||
ManagedFramebufferData *mfb_data = GET_DATA(mfb);
|
||||
static inline void fbmgr_framebuffer_get_metrics(ManagedFramebufferData *mfb_data, IntExtent *fb_size, FloatRect *fb_viewport) {
|
||||
assume(mfb_data->resize_strategy.resize_func != NULL);
|
||||
mfb_data->resize_strategy.resize_func(mfb_data->resize_strategy.userdata, fb_size, fb_viewport);
|
||||
}
|
||||
|
||||
static void fbmgr_framebuffer_update(ManagedFramebuffer *mfb) {
|
||||
static void fbmgr_framebuffer_update(ManagedFramebufferData *mfb_data) {
|
||||
IntExtent fb_size;
|
||||
FloatRect fb_viewport;
|
||||
Framebuffer *fb = mfb->fb;
|
||||
Framebuffer *fb = GET_MFB(mfb_data)->fb;
|
||||
|
||||
fbmgr_framebuffer_get_metrics(mfb, &fb_size, &fb_viewport);
|
||||
if(mfb_data->resize_strategy.resize_func == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
fbmgr_framebuffer_get_metrics(mfb_data, &fb_size, &fb_viewport);
|
||||
|
||||
for(uint i = 0; i < FRAMEBUFFER_MAX_ATTACHMENTS; ++i) {
|
||||
fbutil_resize_attachment(fb, i, fb_size.w, fb_size.h);
|
||||
|
@ -52,12 +56,11 @@ static void fbmgr_framebuffer_update(ManagedFramebuffer *mfb) {
|
|||
|
||||
static void fbmgr_framebuffer_update_all(void) {
|
||||
for(ManagedFramebufferData *d = framebuffers; d; d = d->next) {
|
||||
fbmgr_framebuffer_update(GET_MFB(d));
|
||||
fbmgr_framebuffer_update(d);
|
||||
}
|
||||
}
|
||||
|
||||
ManagedFramebuffer *fbmgr_framebuffer_create(const char *name, const FramebufferConfig *cfg) {
|
||||
assert(cfg->resize_strategy.resize_func != NULL);
|
||||
assert(cfg->attachments != NULL);
|
||||
assert(cfg->num_attachments >= 1);
|
||||
|
||||
|
@ -67,19 +70,30 @@ ManagedFramebuffer *fbmgr_framebuffer_create(const char *name, const Framebuffer
|
|||
mfb->fb = r_framebuffer_create();
|
||||
r_framebuffer_set_debug_label(mfb->fb, name);
|
||||
|
||||
FBAttachmentConfig ac[cfg->num_attachments];
|
||||
memcpy(ac, cfg->attachments, sizeof(ac));
|
||||
|
||||
IntExtent fb_size;
|
||||
FloatRect fb_viewport;
|
||||
fbmgr_framebuffer_get_metrics(mfb, &fb_size, &fb_viewport);
|
||||
|
||||
for(int i = 0; i < cfg->num_attachments; ++i) {
|
||||
ac[i].tex_params.width = fb_size.w;
|
||||
ac[i].tex_params.height = fb_size.h;
|
||||
if(data->resize_strategy.resize_func != NULL) {
|
||||
FBAttachmentConfig ac[cfg->num_attachments];
|
||||
memcpy(ac, cfg->attachments, sizeof(ac));
|
||||
|
||||
IntExtent fb_size;
|
||||
|
||||
fbmgr_framebuffer_get_metrics(data, &fb_size, &fb_viewport);
|
||||
|
||||
for(int i = 0; i < cfg->num_attachments; ++i) {
|
||||
ac[i].tex_params.width = fb_size.w;
|
||||
ac[i].tex_params.height = fb_size.h;
|
||||
}
|
||||
|
||||
fbutil_create_attachments(mfb->fb, ARRAY_SIZE(ac), ac);
|
||||
} else {
|
||||
FBAttachmentConfig *ac = cfg->attachments;
|
||||
fb_viewport = (FloatRect) {
|
||||
.extent = { ac[0].tex_params.width, ac[0].tex_params.height }
|
||||
};
|
||||
fbutil_create_attachments(mfb->fb, cfg->num_attachments, cfg->attachments);
|
||||
}
|
||||
|
||||
fbutil_create_attachments(mfb->fb, cfg->num_attachments, ac);
|
||||
r_framebuffer_viewport_rect(mfb->fb, fb_viewport);
|
||||
r_framebuffer_clear(mfb->fb, CLEAR_ALL, RGBA(0, 0, 0, 0), 1);
|
||||
|
||||
|
@ -173,4 +187,3 @@ 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);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue