From 47c6f41b8926befcf1ffe8b0dcccb90922c4b9be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Foucault?= Date: Tue, 18 Aug 2020 15:49:48 +0200 Subject: Fix T77564: VSE (and compositor background) lost stereoscopy preview Issue introduced on fe045b2b77dc6d7f0b552619fe824b496d34db6c. Since the stereoscopy compositing (anaglyph, ...) is only done for viewports the VSE preview and compositor need to use viewports. Reviewed by: dfelinto Differential Revision: https://developer.blender.org/D8472 --- source/blender/editors/space_node/node_draw.c | 13 +++++++++++-- source/blender/editors/space_sequencer/sequencer_draw.c | 14 +++++++++++++- source/blender/gpu/GPU_framebuffer.h | 1 + source/blender/gpu/intern/gpu_framebuffer.c | 12 ++++++++++++ source/blender/windowmanager/intern/wm_draw.c | 4 +++- 5 files changed, 40 insertions(+), 4 deletions(-) diff --git a/source/blender/editors/space_node/node_draw.c b/source/blender/editors/space_node/node_draw.c index 22b549cbd5d..884f551bad1 100644 --- a/source/blender/editors/space_node/node_draw.c +++ b/source/blender/editors/space_node/node_draw.c @@ -47,11 +47,13 @@ #include "BIF_glutil.h" +#include "GPU_batch_presets.h" #include "GPU_framebuffer.h" #include "GPU_immediate.h" #include "GPU_immediate_util.h" #include "GPU_matrix.h" #include "GPU_state.h" +#include "GPU_viewport.h" #include "WM_api.h" #include "WM_types.h" @@ -1771,11 +1773,18 @@ void drawnodespace(const bContext *C, ARegion *region) SpaceNode *snode = CTX_wm_space_node(C); View2D *v2d = ®ion->v2d; + UI_view2d_view_ortho(v2d); + + /* Setup offscreen buffers. */ + GPUViewport *viewport = WM_draw_region_get_viewport(region); + + GPUFrameBuffer *framebuffer_overlay = GPU_viewport_framebuffer_overlay_get(viewport); + GPU_framebuffer_bind_no_srgb(framebuffer_overlay); + GPU_batch_presets_reset(); + UI_ThemeClearColor(TH_BACK); GPU_clear(GPU_COLOR_BIT); - UI_view2d_view_ortho(v2d); - /* XXX snode->cursor set in coordspace for placing new nodes, used for drawing noodles too */ UI_view2d_region_to_view(®ion->v2d, win->eventstate->x - region->winrct.xmin, diff --git a/source/blender/editors/space_sequencer/sequencer_draw.c b/source/blender/editors/space_sequencer/sequencer_draw.c index 995e980aba0..edbe830683f 100644 --- a/source/blender/editors/space_sequencer/sequencer_draw.c +++ b/source/blender/editors/space_sequencer/sequencer_draw.c @@ -50,12 +50,14 @@ #include "IMB_colormanagement.h" #include "IMB_imbuf.h" +#include "GPU_batch_presets.h" #include "GPU_framebuffer.h" #include "GPU_immediate.h" #include "GPU_immediate_util.h" #include "GPU_matrix.h" #include "GPU_state.h" #include "GPU_vertex_buffer.h" +#include "GPU_viewport.h" #include "ED_anim_api.h" #include "ED_gpencil.h" @@ -1537,7 +1539,7 @@ static void sequencer_preview_clear(void) float col[3]; UI_GetThemeColor3fv(TH_SEQ_PREVIEW, col); - GPU_clear_color(col[0], col[1], col[2], 0.0); + GPU_clear_color(col[0], col[1], col[2], 1.0); GPU_clear(GPU_COLOR_BIT); } @@ -1775,6 +1777,13 @@ void sequencer_draw_preview(const bContext *C, return; } + /* Setup offscreen buffers. */ + GPUViewport *viewport = WM_draw_region_get_viewport(region); + + GPUFrameBuffer *framebuffer_overlay = GPU_viewport_framebuffer_overlay_get(viewport); + GPU_framebuffer_bind_no_srgb(framebuffer_overlay); + GPU_batch_presets_reset(); + if (sseq->render_size == SEQ_PROXY_RENDER_SIZE_NONE) { sequencer_preview_clear(); return; @@ -1798,6 +1807,9 @@ void sequencer_draw_preview(const bContext *C, ibuf = sequencer_ibuf_get( bmain, depsgraph, scene, sseq, cfra, frame_ofs, names[sseq->multiview_eye]); + /* sequencer_ibuf_get can call GPU_framebuffer_bind. So disable srgb framebuffer again. */ + GPU_framebuffer_bind_no_srgb(framebuffer_overlay); + if (ibuf) { scope = sequencer_get_scope(scene, sseq, ibuf, draw_backdrop); diff --git a/source/blender/gpu/GPU_framebuffer.h b/source/blender/gpu/GPU_framebuffer.h index 4958d1eaac8..ee99f1f68c8 100644 --- a/source/blender/gpu/GPU_framebuffer.h +++ b/source/blender/gpu/GPU_framebuffer.h @@ -61,6 +61,7 @@ typedef struct GPUOffScreen GPUOffScreen; GPUFrameBuffer *GPU_framebuffer_create(void); void GPU_framebuffer_free(GPUFrameBuffer *fb); void GPU_framebuffer_bind(GPUFrameBuffer *fb); +void GPU_framebuffer_bind_no_srgb(GPUFrameBuffer *fb); void GPU_framebuffer_restore(void); bool GPU_framebuffer_bound(GPUFrameBuffer *fb); diff --git a/source/blender/gpu/intern/gpu_framebuffer.c b/source/blender/gpu/intern/gpu_framebuffer.c index 77abb786117..838450e6528 100644 --- a/source/blender/gpu/intern/gpu_framebuffer.c +++ b/source/blender/gpu/intern/gpu_framebuffer.c @@ -544,6 +544,18 @@ void GPU_framebuffer_bind(GPUFrameBuffer *fb) glViewport(0, 0, fb->width, fb->height); } +/* Workaround for binding a srgb framebuffer without doing the srgb transform. */ +void GPU_framebuffer_bind_no_srgb(GPUFrameBuffer *fb) +{ + GPU_framebuffer_bind(fb); + + glDisable(GL_FRAMEBUFFER_SRGB); + + GPUTexture *first_target = fb->attachments[GPU_FB_COLOR_ATTACHMENT0].tex; + const bool is_srgb_target = (first_target && (GPU_texture_format(first_target) == GPU_SRGB8_A8)); + GPU_shader_set_framebuffer_srgb_target(!is_srgb_target); +} + void GPU_framebuffer_restore(void) { if (GPU_framebuffer_active_get() != NULL) { diff --git a/source/blender/windowmanager/intern/wm_draw.c b/source/blender/windowmanager/intern/wm_draw.c index fdbc7a7d136..622e8359541 100644 --- a/source/blender/windowmanager/intern/wm_draw.c +++ b/source/blender/windowmanager/intern/wm_draw.c @@ -308,7 +308,9 @@ static void wm_region_test_xr_do_draw(const wmWindowManager *wm, static bool wm_region_use_viewport_by_type(short space_type, short region_type) { - return (ELEM(space_type, SPACE_VIEW3D, SPACE_IMAGE) && region_type == RGN_TYPE_WINDOW); + return (ELEM(space_type, SPACE_VIEW3D, SPACE_IMAGE, SPACE_NODE) && + region_type == RGN_TYPE_WINDOW) || + ((space_type == SPACE_SEQ) && region_type == RGN_TYPE_PREVIEW); } bool WM_region_use_viewport(ScrArea *area, ARegion *region) -- cgit v1.2.3