diff options
author | Clément Foucault <foucault.clem@gmail.com> | 2018-04-24 00:10:59 +0300 |
---|---|---|
committer | Clément Foucault <foucault.clem@gmail.com> | 2018-05-02 21:49:38 +0300 |
commit | 33356b7be0ace84e1d0ab7235c68541939a7ab9c (patch) | |
tree | 4c79cfaaca25750619e3de1a80e5e2846082fa30 | |
parent | 6d8e308eae4c980a093582c29084ae20ee814972 (diff) |
DRW: Add DRW_multisamples_resolve function
This manually resolve the content of a multisample FB to a single sample FB.
It resolves color (combine the 2 framebuffers in a logical maner keeping
depth buffer occlusion etc..) instead of a plain glBlitFramebuffer copy.
-rw-r--r-- | source/blender/draw/intern/DRW_render.h | 2 | ||||
-rw-r--r-- | source/blender/draw/intern/draw_manager.c | 49 |
2 files changed, 51 insertions, 0 deletions
diff --git a/source/blender/draw/intern/DRW_render.h b/source/blender/draw/intern/DRW_render.h index 31046377b19..cc0bb01adec 100644 --- a/source/blender/draw/intern/DRW_render.h +++ b/source/blender/draw/intern/DRW_render.h @@ -219,6 +219,8 @@ void DRW_uniformbuffer_free(struct GPUUniformBuffer *ubo); } while (0) void DRW_transform_to_display(struct GPUTexture *tex); +void DRW_multisamples_resolve( + struct GPUTexture *src_depth, struct GPUTexture *src_color); /* Shaders */ struct GPUShader *DRW_shader_create( diff --git a/source/blender/draw/intern/draw_manager.c b/source/blender/draw/intern/draw_manager.c index d752e64101e..b171d758832 100644 --- a/source/blender/draw/intern/draw_manager.c +++ b/source/blender/draw/intern/draw_manager.c @@ -294,6 +294,55 @@ void DRW_transform_to_display(GPUTexture *tex) /* -------------------------------------------------------------------- */ +/** \name Multisample Resolve + * \{ */ + +/* Use manual multisample resolve pass. + * Much quicker than blitting back and forth. + * Assume destination fb is bound*/ +void DRW_multisamples_resolve(GPUTexture *src_depth, GPUTexture *src_color) +{ + drw_state_set(DRW_STATE_WRITE_COLOR | DRW_STATE_BLEND_PREMUL | + DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_LESS); + + int samples = GPU_texture_samples(src_depth); + + BLI_assert(samples > 0); + BLI_assert(GPU_texture_samples(src_color) == samples); + + Gwn_Batch *geom = DRW_cache_fullscreen_quad_get(); + + int builtin; + switch (samples) { + case 2: builtin = GPU_SHADER_2D_IMAGE_MULTISAMPLE_2; break; + case 4: builtin = GPU_SHADER_2D_IMAGE_MULTISAMPLE_4; break; + case 8: builtin = GPU_SHADER_2D_IMAGE_MULTISAMPLE_8; break; + case 16: builtin = GPU_SHADER_2D_IMAGE_MULTISAMPLE_16; break; + default: + BLI_assert(0); + } + + GWN_batch_program_set_builtin(geom, builtin); + + GPU_texture_bind(src_depth, 0); + GPU_texture_bind(src_color, 1); + GWN_batch_uniform_1i(geom, "depthMulti", 0); + GWN_batch_uniform_1i(geom, "colorMulti", 1); + + float mat[4][4]; + unit_m4(mat); + GWN_batch_uniform_mat4(geom, "ModelViewProjectionMatrix", mat); + + /* avoid gpuMatrix calls */ + GWN_batch_program_use_begin(geom); + GWN_batch_draw_range_ex(geom, 0, 0, false); + GWN_batch_program_use_end(geom); +} + +/** \} */ + +/* -------------------------------------------------------------------- */ + /** \name Viewport (DRW_viewport) * \{ */ |