diff options
author | Clément Foucault <foucault.clem@gmail.com> | 2017-11-11 01:36:05 +0300 |
---|---|---|
committer | Clément Foucault <foucault.clem@gmail.com> | 2017-11-11 18:23:55 +0300 |
commit | f30a2a786214c4ef08612486c227add0bb6bf35b (patch) | |
tree | c12d720ce8b4f3c3b5888fda471e6d77df8fa1b2 /source/blender | |
parent | 0260fad9ba41c3a714df9b39e6e6d171b143cf41 (diff) |
GPUFramebuffer: Add possibility to blit stencil buffer.
Diffstat (limited to 'source/blender')
-rw-r--r-- | source/blender/draw/engines/basic/basic_engine.c | 2 | ||||
-rw-r--r-- | source/blender/draw/engines/clay/clay_engine.c | 2 | ||||
-rw-r--r-- | source/blender/draw/engines/eevee/eevee_screen_raytrace.c | 2 | ||||
-rw-r--r-- | source/blender/draw/engines/eevee/eevee_temporal_sampling.c | 4 | ||||
-rw-r--r-- | source/blender/draw/intern/DRW_render.h | 10 | ||||
-rw-r--r-- | source/blender/draw/intern/draw_manager.c | 4 | ||||
-rw-r--r-- | source/blender/gpu/GPU_framebuffer.h | 2 | ||||
-rw-r--r-- | source/blender/gpu/intern/gpu_framebuffer.c | 34 |
8 files changed, 40 insertions, 20 deletions
diff --git a/source/blender/draw/engines/basic/basic_engine.c b/source/blender/draw/engines/basic/basic_engine.c index 16678beec4d..a4ee3d22444 100644 --- a/source/blender/draw/engines/basic/basic_engine.c +++ b/source/blender/draw/engines/basic/basic_engine.c @@ -233,7 +233,7 @@ static void BASIC_draw_scene(void *vedata) if (use_depth || use_depth_cull) { /* Unless we go for deferred shading we need this to avoid manual depth test and artifacts */ if (DRW_state_is_fbo()) { - DRW_framebuffer_blit(dfbl->default_fb, fbl->dupli_depth, true); + DRW_framebuffer_blit(dfbl->default_fb, fbl->dupli_depth, true, false); } } #endif diff --git a/source/blender/draw/engines/clay/clay_engine.c b/source/blender/draw/engines/clay/clay_engine.c index 937cf7579c6..c3ec878b94b 100644 --- a/source/blender/draw/engines/clay/clay_engine.c +++ b/source/blender/draw/engines/clay/clay_engine.c @@ -850,7 +850,7 @@ static void CLAY_draw_scene(void *vedata) /* attach temp textures */ DRW_framebuffer_texture_attach(fbl->dupli_depth, e_data.depth_dup, 0, 0); - DRW_framebuffer_blit(dfbl->default_fb, fbl->dupli_depth, true); + DRW_framebuffer_blit(dfbl->default_fb, fbl->dupli_depth, true, false); /* detach temp textures */ DRW_framebuffer_texture_detach(e_data.depth_dup); diff --git a/source/blender/draw/engines/eevee/eevee_screen_raytrace.c b/source/blender/draw/engines/eevee/eevee_screen_raytrace.c index bb593867a52..e287ba6fc14 100644 --- a/source/blender/draw/engines/eevee/eevee_screen_raytrace.c +++ b/source/blender/draw/engines/eevee/eevee_screen_raytrace.c @@ -279,7 +279,7 @@ void EEVEE_refraction_compute(EEVEE_SceneLayerData *UNUSED(sldata), EEVEE_Data * if ((effects->enabled_effects & EFFECT_REFRACT) != 0) { DRW_framebuffer_texture_attach(fbl->refract_fb, txl->refract_color, 0, 0); - DRW_framebuffer_blit(fbl->main, fbl->refract_fb, false); + DRW_framebuffer_blit(fbl->main, fbl->refract_fb, false, false); EEVEE_downsample_buffer(vedata, fbl->downsample_fb, txl->refract_color, 9); /* Restore */ diff --git a/source/blender/draw/engines/eevee/eevee_temporal_sampling.c b/source/blender/draw/engines/eevee/eevee_temporal_sampling.c index 02becfb260f..434c76643f2 100644 --- a/source/blender/draw/engines/eevee/eevee_temporal_sampling.c +++ b/source/blender/draw/engines/eevee/eevee_temporal_sampling.c @@ -167,7 +167,7 @@ void EEVEE_temporal_sampling_draw(EEVEE_Data *vedata) DRW_draw_pass(psl->taa_resolve); /* Restore the depth from sample 1. */ - DRW_framebuffer_blit(fbl->depth_double_buffer_fb, fbl->main, true); + DRW_framebuffer_blit(fbl->depth_double_buffer_fb, fbl->main, true, false); /* Special Swap */ SWAP(struct GPUFrameBuffer *, fbl->effect_fb, fbl->double_buffer); @@ -180,7 +180,7 @@ void EEVEE_temporal_sampling_draw(EEVEE_Data *vedata) /* Save the depth buffer for the next frame. * This saves us from doing anything special * in the other mode engines. */ - DRW_framebuffer_blit(fbl->main, fbl->depth_double_buffer_fb, true); + DRW_framebuffer_blit(fbl->main, fbl->depth_double_buffer_fb, true, false); } if ((effects->taa_total_sample == 0) || diff --git a/source/blender/draw/intern/DRW_render.h b/source/blender/draw/intern/DRW_render.h index b54d90a5682..1941ad0a441 100644 --- a/source/blender/draw/intern/DRW_render.h +++ b/source/blender/draw/intern/DRW_render.h @@ -94,8 +94,8 @@ typedef char DRWViewportEmptyList; #define MULTISAMPLE_SYNC_ENABLE(dfbl) { \ if (dfbl->multisample_fb != NULL) { \ DRW_stats_query_start("Multisample Blit"); \ - DRW_framebuffer_blit(dfbl->default_fb, dfbl->multisample_fb, false); \ - DRW_framebuffer_blit(dfbl->default_fb, dfbl->multisample_fb, true); \ + DRW_framebuffer_blit(dfbl->default_fb, dfbl->multisample_fb, false, false); \ + DRW_framebuffer_blit(dfbl->default_fb, dfbl->multisample_fb, true, false); \ DRW_framebuffer_bind(dfbl->multisample_fb); \ DRW_stats_query_end(); \ } \ @@ -104,8 +104,8 @@ typedef char DRWViewportEmptyList; #define MULTISAMPLE_SYNC_DISABLE(dfbl) { \ if (dfbl->multisample_fb != NULL) { \ DRW_stats_query_start("Multisample Resolve"); \ - DRW_framebuffer_blit(dfbl->multisample_fb, dfbl->default_fb, false); \ - DRW_framebuffer_blit(dfbl->multisample_fb, dfbl->default_fb, true); \ + DRW_framebuffer_blit(dfbl->multisample_fb, dfbl->default_fb, false, false); \ + DRW_framebuffer_blit(dfbl->multisample_fb, dfbl->default_fb, true, false); \ DRW_framebuffer_bind(dfbl->default_fb); \ DRW_stats_query_end(); \ } \ @@ -234,7 +234,7 @@ void DRW_framebuffer_texture_attach(struct GPUFrameBuffer *fb, struct GPUTexture void DRW_framebuffer_texture_layer_attach(struct GPUFrameBuffer *fb, struct GPUTexture *tex, int slot, int layer, int mip); void DRW_framebuffer_cubeface_attach(struct GPUFrameBuffer *fb, struct GPUTexture *tex, int slot, int face, int mip); void DRW_framebuffer_texture_detach(struct GPUTexture *tex); -void DRW_framebuffer_blit(struct GPUFrameBuffer *fb_read, struct GPUFrameBuffer *fb_write, bool depth); +void DRW_framebuffer_blit(struct GPUFrameBuffer *fb_read, struct GPUFrameBuffer *fb_write, bool depth, bool stencil); void DRW_framebuffer_recursive_downsample( struct GPUFrameBuffer *fb, struct GPUTexture *tex, int num_iter, void (*callback)(void *userData, int level), void *userData); diff --git a/source/blender/draw/intern/draw_manager.c b/source/blender/draw/intern/draw_manager.c index 7061aa640a5..2e35a30351a 100644 --- a/source/blender/draw/intern/draw_manager.c +++ b/source/blender/draw/intern/draw_manager.c @@ -2393,9 +2393,9 @@ void DRW_framebuffer_texture_detach(GPUTexture *tex) GPU_framebuffer_texture_detach(tex); } -void DRW_framebuffer_blit(struct GPUFrameBuffer *fb_read, struct GPUFrameBuffer *fb_write, bool depth) +void DRW_framebuffer_blit(struct GPUFrameBuffer *fb_read, struct GPUFrameBuffer *fb_write, bool depth, bool stencil) { - GPU_framebuffer_blit(fb_read, 0, fb_write, 0, depth); + GPU_framebuffer_blit(fb_read, 0, fb_write, 0, depth, stencil); } void DRW_framebuffer_recursive_downsample( diff --git a/source/blender/gpu/GPU_framebuffer.h b/source/blender/gpu/GPU_framebuffer.h index a079d12b469..705ef1997c1 100644 --- a/source/blender/gpu/GPU_framebuffer.h +++ b/source/blender/gpu/GPU_framebuffer.h @@ -73,7 +73,7 @@ void GPU_framebuffer_blur( void GPU_framebuffer_blit( GPUFrameBuffer *fb_read, int read_slot, - GPUFrameBuffer *fb_write, int write_slot, bool use_depth); + GPUFrameBuffer *fb_write, int write_slot, bool use_depth, bool use_stencil); void GPU_framebuffer_recursive_downsample( GPUFrameBuffer *fb, struct GPUTexture *tex, int num_iter, diff --git a/source/blender/gpu/intern/gpu_framebuffer.c b/source/blender/gpu/intern/gpu_framebuffer.c index de5dff1b69c..9f0ccffb8eb 100644 --- a/source/blender/gpu/intern/gpu_framebuffer.c +++ b/source/blender/gpu/intern/gpu_framebuffer.c @@ -507,12 +507,18 @@ void GPU_framebuffer_blur( GWN_batch_draw(&batch); } -void GPU_framebuffer_blit(GPUFrameBuffer *fb_read, int read_slot, GPUFrameBuffer *fb_write, int write_slot, bool use_depth) +void GPU_framebuffer_blit( + GPUFrameBuffer *fb_read, int read_slot, GPUFrameBuffer *fb_write, + int write_slot, bool use_depth, bool use_stencil) { - GPUTexture *read_tex = (use_depth) ? fb_read->depthtex : fb_read->colortex[read_slot]; - GPUTexture *write_tex = (use_depth) ? fb_write->depthtex : fb_write->colortex[write_slot]; - int read_attach = (use_depth) ? GL_DEPTH_ATTACHMENT : GL_COLOR_ATTACHMENT0 + GPU_texture_framebuffer_attachment(read_tex); - int write_attach = (use_depth) ? GL_DEPTH_ATTACHMENT : GL_COLOR_ATTACHMENT0 + GPU_texture_framebuffer_attachment(write_tex); + GPUTexture *read_tex = (use_depth || use_stencil) ? fb_read->depthtex : fb_read->colortex[read_slot]; + GPUTexture *write_tex = (use_depth || use_stencil) ? fb_write->depthtex : fb_write->colortex[write_slot]; + int read_attach = (use_depth) ? GL_DEPTH_ATTACHMENT : + (use_stencil) ? GL_DEPTH_STENCIL_ATTACHMENT : + GL_COLOR_ATTACHMENT0 + GPU_texture_framebuffer_attachment(read_tex); + int write_attach = (use_depth) ? GL_DEPTH_ATTACHMENT : + (use_stencil) ? GL_DEPTH_STENCIL_ATTACHMENT : + GL_COLOR_ATTACHMENT0 + GPU_texture_framebuffer_attachment(write_tex); int read_bind = GPU_texture_opengl_bindcode(read_tex); int write_bind = GPU_texture_opengl_bindcode(write_tex); const int read_w = GPU_texture_width(read_tex); @@ -520,6 +526,17 @@ void GPU_framebuffer_blit(GPUFrameBuffer *fb_read, int read_slot, GPUFrameBuffer const int write_w = GPU_texture_width(write_tex); const int write_h = GPU_texture_height(write_tex); + + /* Never both! */ + BLI_assert(!(use_depth && use_stencil)); + + if (use_depth) { + BLI_assert(GPU_texture_depth(read_tex) && GPU_texture_depth(write_tex)); + } + else if (use_stencil) { + BLI_assert(GPU_texture_stencil(read_tex) && GPU_texture_stencil(write_tex)); + } + /* read from multi-sample buffer */ glBindFramebuffer(GL_READ_FRAMEBUFFER, fb_read->object); glFramebufferTexture2D( @@ -534,8 +551,11 @@ void GPU_framebuffer_blit(GPUFrameBuffer *fb_read, int read_slot, GPUFrameBuffer GPU_texture_target(write_tex), write_bind, 0); BLI_assert(glCheckFramebufferStatus(GL_DRAW_FRAMEBUFFER) == GL_FRAMEBUFFER_COMPLETE); - glDrawBuffer((use_depth) ? GL_COLOR_ATTACHMENT0 : read_attach); - glBlitFramebuffer(0, 0, read_w, read_h, 0, 0, write_w, write_h, (use_depth) ? GL_DEPTH_BUFFER_BIT : GL_COLOR_BUFFER_BIT, GL_NEAREST); + glDrawBuffer((use_depth || use_stencil) ? GL_COLOR_ATTACHMENT0 : read_attach); + glBlitFramebuffer(0, 0, read_w, read_h, 0, 0, write_w, write_h, + (use_depth) ? GL_DEPTH_BUFFER_BIT : + (use_stencil) ? GL_STENCIL_BUFFER_BIT : + GL_COLOR_BUFFER_BIT, GL_NEAREST); /* Restore previous framebuffer */ glBindFramebuffer(GL_FRAMEBUFFER, GG.currentfb); |