diff options
author | Clément Foucault <foucault.clem@gmail.com> | 2017-09-23 21:47:42 +0300 |
---|---|---|
committer | Clément Foucault <foucault.clem@gmail.com> | 2017-09-25 21:14:42 +0300 |
commit | 00955d8d7a2e17ee86767e5f3703d6c20f2602b8 (patch) | |
tree | 8fe6b473504c0d0ceffcb32753721f82466ab60a /source/blender/draw | |
parent | 709315a0d7cd382320c060f369717f8af4ea364e (diff) |
DRW : Add AA to non meshes objects.
You can change the amount of samples in the user preferences. You do not need to restart blender to see the effect in the new viewport.
This adds another Multisample Framebuffer and textures (so even more memory required).
It works by blitting the default_fb to the multisample_fb each time the renderer need to render one or more "wire" pass.
It it then blit back to the default_fb so that the rest of pipeline is working as expected.
We COULD lower the GPU memory / bandwidth usage to render everything to the same multisample fbo and change the logic depending on if MSAA is enabled or not, but I think it's a bit too much work for now.
Diffstat (limited to 'source/blender/draw')
-rw-r--r-- | source/blender/draw/DRW_engine.h | 3 | ||||
-rw-r--r-- | source/blender/draw/intern/DRW_render.h | 26 | ||||
-rw-r--r-- | source/blender/draw/modes/edit_armature_mode.c | 5 | ||||
-rw-r--r-- | source/blender/draw/modes/edit_curve_mode.c | 6 | ||||
-rw-r--r-- | source/blender/draw/modes/edit_lattice_mode.c | 6 | ||||
-rw-r--r-- | source/blender/draw/modes/object_mode.c | 7 |
6 files changed, 50 insertions, 3 deletions
diff --git a/source/blender/draw/DRW_engine.h b/source/blender/draw/DRW_engine.h index b780e86b9ec..3b1dcba1503 100644 --- a/source/blender/draw/DRW_engine.h +++ b/source/blender/draw/DRW_engine.h @@ -48,11 +48,14 @@ struct GPUOffScreen; /* Buffer and textures used by the viewport by default */ typedef struct DefaultFramebufferList { struct GPUFrameBuffer *default_fb; + struct GPUFrameBuffer *multisample_fb; } DefaultFramebufferList; typedef struct DefaultTextureList { struct GPUTexture *color; struct GPUTexture *depth; + struct GPUTexture *multisample_color; + struct GPUTexture *multisample_depth; } DefaultTextureList; void DRW_engines_register(void); diff --git a/source/blender/draw/intern/DRW_render.h b/source/blender/draw/intern/DRW_render.h index 4b0bbc3c175..b546631b8c3 100644 --- a/source/blender/draw/intern/DRW_render.h +++ b/source/blender/draw/intern/DRW_render.h @@ -90,6 +90,29 @@ typedef char DRWViewportEmptyList; DRW_VIEWPORT_LIST_SIZE(*(((ty *)NULL)->stl)) \ } +/* Use of multisample framebuffers. */ +#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_bind(dfbl->multisample_fb); \ + DRW_stats_query_end(); \ + } \ +} + +#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_bind(dfbl->default_fb); \ + DRW_stats_query_end(); \ + } \ +} + + + typedef struct DrawEngineDataSize { int fbl_len; int txl_len; @@ -119,11 +142,14 @@ typedef struct DrawEngineType { /* Buffer and textures used by the viewport by default */ typedef struct DefaultFramebufferList { struct GPUFrameBuffer *default_fb; + struct GPUFrameBuffer *multisample_fb; } DefaultFramebufferList; typedef struct DefaultTextureList { struct GPUTexture *color; struct GPUTexture *depth; + struct GPUTexture *multisample_color; + struct GPUTexture *multisample_depth; } DefaultTextureList; #endif diff --git a/source/blender/draw/modes/edit_armature_mode.c b/source/blender/draw/modes/edit_armature_mode.c index 61a56dab244..06756e5a240 100644 --- a/source/blender/draw/modes/edit_armature_mode.c +++ b/source/blender/draw/modes/edit_armature_mode.c @@ -120,11 +120,16 @@ static void EDIT_ARMATURE_cache_populate(void *vedata, Object *ob) static void EDIT_ARMATURE_draw_scene(void *vedata) { EDIT_ARMATURE_PassList *psl = ((EDIT_ARMATURE_Data *)vedata)->psl; + DefaultFramebufferList *dfbl = DRW_viewport_framebuffer_list_get(); + + MULTISAMPLE_SYNC_ENABLE(dfbl) DRW_draw_pass(psl->bone_envelope); DRW_draw_pass(psl->bone_solid); DRW_draw_pass(psl->bone_wire); DRW_draw_pass(psl->relationship); + + MULTISAMPLE_SYNC_DISABLE(dfbl) } #if 0 diff --git a/source/blender/draw/modes/edit_curve_mode.c b/source/blender/draw/modes/edit_curve_mode.c index dc81725d19a..02a35e07798 100644 --- a/source/blender/draw/modes/edit_curve_mode.c +++ b/source/blender/draw/modes/edit_curve_mode.c @@ -264,7 +264,9 @@ static void EDIT_CURVE_draw_scene(void *vedata) DefaultFramebufferList *dfbl = DRW_viewport_framebuffer_list_get(); DefaultTextureList *dtxl = DRW_viewport_texture_list_get(); - UNUSED_VARS(fbl, dfbl, dtxl); + UNUSED_VARS(fbl, dtxl); + + MULTISAMPLE_SYNC_ENABLE(dfbl) /* Show / hide entire passes, swap framebuffers ... whatever you fancy */ /* @@ -280,6 +282,8 @@ static void EDIT_CURVE_draw_scene(void *vedata) DRW_draw_pass(psl->overlay_edge_pass); DRW_draw_pass(psl->overlay_vert_pass); + MULTISAMPLE_SYNC_DISABLE(dfbl) + /* If you changed framebuffer, double check you rebind * the default one with its textures attached before finishing */ } diff --git a/source/blender/draw/modes/edit_lattice_mode.c b/source/blender/draw/modes/edit_lattice_mode.c index 722010148ff..48ea723613a 100644 --- a/source/blender/draw/modes/edit_lattice_mode.c +++ b/source/blender/draw/modes/edit_lattice_mode.c @@ -227,7 +227,9 @@ static void EDIT_LATTICE_draw_scene(void *vedata) DefaultFramebufferList *dfbl = DRW_viewport_framebuffer_list_get(); DefaultTextureList *dtxl = DRW_viewport_texture_list_get(); - UNUSED_VARS(fbl, dfbl, dtxl); + UNUSED_VARS(fbl, dtxl); + + MULTISAMPLE_SYNC_ENABLE(dfbl) /* Show / hide entire passes, swap framebuffers ... whatever you fancy */ /* @@ -242,6 +244,8 @@ static void EDIT_LATTICE_draw_scene(void *vedata) DRW_draw_pass(psl->wire_pass); DRW_draw_pass(psl->vert_pass); + MULTISAMPLE_SYNC_DISABLE(dfbl) + /* If you changed framebuffer, double check you rebind * the default one with its textures attached before finishing */ } diff --git a/source/blender/draw/modes/object_mode.c b/source/blender/draw/modes/object_mode.c index 7fe7e5f0042..bde0a43120f 100644 --- a/source/blender/draw/modes/object_mode.c +++ b/source/blender/draw/modes/object_mode.c @@ -1826,15 +1826,20 @@ static void OBJECT_draw_scene(void *vedata) DRW_stats_group_end(); } + MULTISAMPLE_SYNC_ENABLE(dfbl) + /* This needs to be drawn after the oultine */ // DRW_draw_pass(psl->bone_envelope); /* Never drawn in Object mode currently. */ DRW_draw_pass(psl->bone_wire); DRW_draw_pass(psl->bone_solid); DRW_draw_pass(psl->non_meshes); - DRW_draw_pass(psl->ob_center); DRW_draw_pass(psl->particle); DRW_draw_pass(psl->reference_image); + MULTISAMPLE_SYNC_DISABLE(dfbl) + + DRW_draw_pass(psl->ob_center); + if (!DRW_state_is_select()) { if (e_data.draw_grid) { DRW_draw_pass(psl->grid); |