diff options
author | Clément Foucault <foucault.clem@gmail.com> | 2019-09-14 00:02:45 +0300 |
---|---|---|
committer | Clément Foucault <foucault.clem@gmail.com> | 2019-09-14 00:03:10 +0300 |
commit | fd5c1972cd5c8a826c0d40effb0e2d367389666a (patch) | |
tree | 6a093944267ff888e9fb4323bac22d52468ab7ec /source/blender/draw/engines/gpencil/gpencil_engine.c | |
parent | c80564ef9f557fadd235b87533b24d126e2138c9 (diff) |
Revert "DRW: Refactor to support draw call batching"
This reverts commit ce34a6b0d727bbde6ae373afa8ec6c42bc8980ce.
Diffstat (limited to 'source/blender/draw/engines/gpencil/gpencil_engine.c')
-rw-r--r-- | source/blender/draw/engines/gpencil/gpencil_engine.c | 79 |
1 files changed, 67 insertions, 12 deletions
diff --git a/source/blender/draw/engines/gpencil/gpencil_engine.c b/source/blender/draw/engines/gpencil/gpencil_engine.c index b2e8cef1db2..9efae54b376 100644 --- a/source/blender/draw/engines/gpencil/gpencil_engine.c +++ b/source/blender/draw/engines/gpencil/gpencil_engine.c @@ -61,8 +61,6 @@ extern char datatoc_gpencil_edit_point_geom_glsl[]; extern char datatoc_gpencil_edit_point_frag_glsl[]; extern char datatoc_gpencil_blend_frag_glsl[]; -extern char datatoc_gpu_shader_3D_smooth_color_frag_glsl[]; - extern char datatoc_common_colormanagement_lib_glsl[]; extern char datatoc_common_view_lib_glsl[]; @@ -223,12 +221,7 @@ static void GPENCIL_create_shaders(void) /* used for edit lines for edit modes */ if (!e_data.gpencil_line_sh) { - e_data.gpencil_line_sh = DRW_shader_create_with_lib( - datatoc_gpencil_edit_point_vert_glsl, - NULL, - datatoc_gpu_shader_3D_smooth_color_frag_glsl, - datatoc_common_view_lib_glsl, - NULL); + e_data.gpencil_line_sh = GPU_shader_get_builtin_shader(GPU_SHADER_3D_FLAT_COLOR); } /* used to filling during drawing */ @@ -286,7 +279,6 @@ static void GPENCIL_engine_free(void) DRW_SHADER_FREE_SAFE(e_data.gpencil_stroke_sh); DRW_SHADER_FREE_SAFE(e_data.gpencil_point_sh); DRW_SHADER_FREE_SAFE(e_data.gpencil_edit_point_sh); - DRW_SHADER_FREE_SAFE(e_data.gpencil_line_sh); DRW_SHADER_FREE_SAFE(e_data.gpencil_fullscreen_sh); DRW_SHADER_FREE_SAFE(e_data.gpencil_simple_fullscreen_sh); DRW_SHADER_FREE_SAFE(e_data.gpencil_blend_fullscreen_sh); @@ -842,13 +834,76 @@ static void gpencil_draw_pass_range(GPENCIL_FramebufferList *fbl, const bool do_antialiasing = ((!stl->storage->is_mat_preview) && (multi)); + DRWShadingGroup *shgrp = init_shgrp; + DRWShadingGroup *from_shgrp = init_shgrp; + DRWShadingGroup *to_shgrp = init_shgrp; + int stencil_tot = 0; + bool do_last = true; + if (do_antialiasing) { MULTISAMPLE_GP_SYNC_ENABLE(stl->storage->multisamples, fbl); } - DRW_draw_pass_subset(GPENCIL_3D_DRAWMODE(ob, gpd) ? psl->stroke_pass_3d : psl->stroke_pass_2d, - init_shgrp, - end_shgrp); + /* Loop all shading groups to separate by stencil groups. */ + while ((shgrp) && (shgrp != end_shgrp)) { + do_last = true; + /* Count number of groups using stencil. */ + if (DRW_shgroup_stencil_mask_get(shgrp) != 0) { + stencil_tot++; + } + + /* Draw stencil group and clear stencil bit. This is required because the number of + * shading groups can be greater than the limit of 255 stencil values. + * Only count as stencil if the shading group has an stencil value assigned. This reduces + * the number of clears because Dots, Fills and some Line strokes don't need stencil. + */ + if (stencil_tot == 255) { + DRW_draw_pass_subset(GPENCIL_3D_DRAWMODE(ob, gpd) ? psl->stroke_pass_3d : + psl->stroke_pass_2d, + from_shgrp, + to_shgrp); + /* Clear Stencil and prepare for next group. */ + if (do_antialiasing) { + GPU_framebuffer_clear_stencil(fbl->multisample_fb, 0x0); + } + else { + GPU_framebuffer_clear_stencil(fb, 0x0); + } + + /* Set new init group and reset. */ + do_last = false; + + shgrp = DRW_shgroup_get_next(shgrp); + if (shgrp) { + from_shgrp = to_shgrp = shgrp; + stencil_tot = 0; + if (shgrp != end_shgrp) { + continue; + } + else { + do_last = true; + break; + } + } + else { + /* No more groups. */ + break; + } + } + + /* Still below stencil group limit. */ + shgrp = DRW_shgroup_get_next(shgrp); + if (shgrp) { + to_shgrp = shgrp; + } + } + + /* Draw last pending groups. */ + if (do_last) { + DRW_draw_pass_subset(GPENCIL_3D_DRAWMODE(ob, gpd) ? psl->stroke_pass_3d : psl->stroke_pass_2d, + from_shgrp, + to_shgrp); + } if (do_antialiasing) { MULTISAMPLE_GP_SYNC_DISABLE(stl->storage->multisamples, fbl, fb, txl); |