Commit: 1fe3139477f5b2d02cf902752183889fb6267a4b Author: Antonioya Date: Wed Jun 19 12:25:15 2019 +0200 Branches: greasepencil-object https://developer.blender.org/rB1fe3139477f5b2d02cf902752183889fb6267a4b
GPencil: Separate Stencils in groups of 255 Also some more changes to improve drawing. =================================================================== M source/blender/draw/engines/gpencil/gpencil_draw_utils.c M source/blender/draw/engines/gpencil/gpencil_engine.c M source/blender/draw/engines/gpencil/gpencil_engine.h =================================================================== diff --git a/source/blender/draw/engines/gpencil/gpencil_draw_utils.c b/source/blender/draw/engines/gpencil/gpencil_draw_utils.c index 89fe479c7d9..eca6b0bfb23 100644 --- a/source/blender/draw/engines/gpencil/gpencil_draw_utils.c +++ b/source/blender/draw/engines/gpencil/gpencil_draw_utils.c @@ -1528,7 +1528,10 @@ void DRW_gpencil_populate_buffer_strokes(GPENCIL_e_data *e_data, 1.0f, (const int *)stl->storage->shade_render); - if (!gpencil_is_stencil_required(gp_style)) { + if (gpencil_is_stencil_required(gp_style)) { + DRW_shgroup_stencil_mask(stl->g_data->shgrps_drawing_stroke, 0x01); + } + else { /* Disable stencil for this type */ DRW_shgroup_state_disable(stl->g_data->shgrps_drawing_stroke, DRW_STATE_WRITE_STENCIL | DRW_STATE_STENCIL_NEQUAL); diff --git a/source/blender/draw/engines/gpencil/gpencil_engine.c b/source/blender/draw/engines/gpencil/gpencil_engine.c index 2025ecc404a..7e320cc8055 100644 --- a/source/blender/draw/engines/gpencil/gpencil_engine.c +++ b/source/blender/draw/engines/gpencil/gpencil_engine.c @@ -749,7 +749,7 @@ static void gpencil_prepare_fast_drawing(GPENCIL_StorageList *stl, GPU_framebuffer_bind(fbl->background_fb); /* clean only in first loop cycle */ if (stl->g_data->session_flag & GP_DRW_PAINT_IDLE) { - GPU_framebuffer_clear_color_depth_stencil(fbl->background_fb, clearcol, 1.0f, 0x00f); + GPU_framebuffer_clear_color_depth_stencil(fbl->background_fb, clearcol, 1.0f, 0x0); stl->g_data->session_flag = GP_DRW_PAINT_FILLING; } /* repeat pass to fill temp texture */ @@ -798,16 +798,74 @@ static void gpencil_draw_pass_range(GPENCIL_FramebufferList *fbl, return; } - /* previews don't use AA */ - if ((!stl->storage->is_mat_preview) && (multi)) { + 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 = false; + + 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) { + 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 = shgrp; + to_shgrp = shgrp; + stencil_tot = 0; + continue; + } + 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 ((!stl->storage->is_mat_preview) && (multi)) { + if (do_antialiasing) { MULTISAMPLE_GP_SYNC_DISABLE(stl->storage->multisamples, fbl, fb, txl); } } @@ -901,10 +959,12 @@ void GPENCIL_draw_scene(void *ved) if ((!is_render) && (stl->g_data->session_flag & GP_DRW_PAINT_PAINTING)) { GPU_framebuffer_bind(dfbl->default_fb); - MULTISAMPLE_GP_SYNC_ENABLE(stl->storage->multisamples, fbl); if (obact->dt != OB_BOUNDBOX) { DRW_draw_pass(psl->background_pass); } + + MULTISAMPLE_GP_SYNC_ENABLE(stl->storage->multisamples, fbl); + DRW_draw_pass(psl->drawing_pass); MULTISAMPLE_GP_SYNC_DISABLE(stl->storage->multisamples, fbl, dfbl->default_fb, txl); @@ -938,7 +998,7 @@ void GPENCIL_draw_scene(void *ved) init_shgrp = NULL; /* Render stroke in separated framebuffer */ GPU_framebuffer_bind(fbl->temp_fb_a); - GPU_framebuffer_clear_color_depth_stencil(fbl->temp_fb_a, clearcol, 1.0f, 0x00f); + GPU_framebuffer_clear_color_depth_stencil(fbl->temp_fb_a, clearcol, 1.0f, 0x0); /* Stroke Pass: * draw only a subset that usually starts with a fill and ends with stroke */ @@ -967,13 +1027,13 @@ void GPENCIL_draw_scene(void *ved) end_shgrp = array_elm->end_shgrp; GPU_framebuffer_bind(fbl->temp_fb_fx); - GPU_framebuffer_clear_color_depth_stencil(fbl->temp_fb_fx, clearcol, 1.0f, 0x00f); + GPU_framebuffer_clear_color_depth_stencil(fbl->temp_fb_fx, clearcol, 1.0f, 0x0); gpencil_draw_pass_range( fbl, stl, psl, txl, fbl->temp_fb_fx, ob, gpd, init_shgrp, end_shgrp, is_last); /* Blend A texture and FX texture */ GPU_framebuffer_bind(fbl->temp_fb_b); - GPU_framebuffer_clear_color_depth_stencil(fbl->temp_fb_b, clearcol, 1.0f, 0x00f); + GPU_framebuffer_clear_color_depth_stencil(fbl->temp_fb_b, clearcol, 1.0f, 0x0); stl->storage->blend_mode = array_elm->mode; stl->storage->clamp_layer = (int)array_elm->clamp_layer; stl->storage->tonemapping = DRW_state_do_color_management() ? 0 : 1; @@ -985,7 +1045,7 @@ void GPENCIL_draw_scene(void *ved) e_data.input_color_tx = e_data.temp_color_tx_b; GPU_framebuffer_bind(fbl->temp_fb_a); - GPU_framebuffer_clear_color_depth_stencil(fbl->temp_fb_a, clearcol, 1.0f, 0x00f); + GPU_framebuffer_clear_color_depth_stencil(fbl->temp_fb_a, clearcol, 1.0f, 0x0); DRW_draw_pass(psl->mix_pass_noblend); /* prepare next group */ diff --git a/source/blender/draw/engines/gpencil/gpencil_engine.h b/source/blender/draw/engines/gpencil/gpencil_engine.h index 4c34e67f77a..04dc9257ec7 100644 --- a/source/blender/draw/engines/gpencil/gpencil_engine.h +++ b/source/blender/draw/engines/gpencil/gpencil_engine.h @@ -517,7 +517,7 @@ void GPENCIL_render_to_image(void *vedata, DRW_stats_query_start("GP Multisample Blit"); \ GPU_framebuffer_bind(fbl->multisample_fb); \ GPU_framebuffer_clear_color_depth_stencil( \ - fbl->multisample_fb, (const float[4]){0.0f}, 1.0f, 0x00f); \ + fbl->multisample_fb, (const float[4]){0.0f}, 1.0f, 0x0); \ DRW_stats_query_end(); \ } \ } \ _______________________________________________ Bf-blender-cvs mailing list Bf-blender-cvs@blender.org https://lists.blender.org/mailman/listinfo/bf-blender-cvs