diff options
Diffstat (limited to 'source/blender/draw/engines/gpencil')
4 files changed, 87 insertions, 69 deletions
diff --git a/source/blender/draw/engines/gpencil/gpencil_cache_utils.c b/source/blender/draw/engines/gpencil/gpencil_cache_utils.c index 33e6d73eeeb..f9df1342bf8 100644 --- a/source/blender/draw/engines/gpencil/gpencil_cache_utils.c +++ b/source/blender/draw/engines/gpencil/gpencil_cache_utils.c @@ -50,10 +50,6 @@ static bool gpencil_has_noninstanced_object(Object *ob_instance) if (ob->type != OB_GPENCIL) { continue; } - /* object must be visible (invisible objects don't create VBO data) */ - if (!(DRW_object_visibility_in_active_context(ob) & OB_VISIBLE_SELF)) { - continue; - } /* is not duplicated and the name is equals */ if ((ob->base_flag & BASE_FROM_DUPLI) == 0) { if (STREQ(ob->id.name, ob_instance->id.name)) { diff --git a/source/blender/draw/engines/gpencil/gpencil_draw_utils.c b/source/blender/draw/engines/gpencil/gpencil_draw_utils.c index ce5d8cbf732..0997568ed22 100644 --- a/source/blender/draw/engines/gpencil/gpencil_draw_utils.c +++ b/source/blender/draw/engines/gpencil/gpencil_draw_utils.c @@ -37,7 +37,6 @@ #include "DNA_gpencil_types.h" #include "DNA_material_types.h" #include "DNA_view3d_types.h" -#include "DNA_gpencil_modifier_types.h" /* If builtin shaders are needed */ #include "GPU_shader.h" @@ -141,13 +140,9 @@ static void gpencil_calc_vertex(GPENCIL_StorageList *stl, Object *ob = cache_ob->ob; const DRWContextState *draw_ctx = DRW_context_state_get(); - const bool main_onion = draw_ctx->v3d != NULL ? - (draw_ctx->v3d->gp_flag & V3D_GP_SHOW_ONION_SKIN) : - true; + const bool main_onion = stl->storage->is_main_onion; const bool playing = stl->storage->is_playing; - const bool overlay = draw_ctx->v3d != NULL ? - (bool)((draw_ctx->v3d->flag2 & V3D_HIDE_OVERLAYS) == 0) : - true; + const bool overlay = stl->storage->is_main_overlay; const bool do_onion = (bool)((gpd->flag & GP_DATA_STROKE_WEIGHTMODE) == 0) && overlay && main_onion && !playing && gpencil_onion_active(gpd); @@ -225,23 +220,6 @@ static void gpencil_calc_vertex(GPENCIL_StorageList *stl, cache->b_point.tot_vertex = cache_ob->tot_vertex; cache->b_edit.tot_vertex = cache_ob->tot_vertex; cache->b_edlin.tot_vertex = cache_ob->tot_vertex; - - /* some modifiers can change the number of points */ - int factor = 0; - GpencilModifierData *md; - for (md = ob->greasepencil_modifiers.first; md; md = md->next) { - const GpencilModifierTypeInfo *mti = BKE_gpencil_modifierType_getInfo(md->type); - /* only modifiers that change size */ - if (mti && mti->getDuplicationFactor) { - factor = mti->getDuplicationFactor(md); - - cache->b_fill.tot_vertex *= factor; - cache->b_stroke.tot_vertex *= factor; - cache->b_point.tot_vertex *= factor; - cache->b_edit.tot_vertex *= factor; - cache->b_edlin.tot_vertex *= factor; - } - } } /* Helper for doing all the checks on whether a stroke can be drawn */ @@ -1781,8 +1759,8 @@ static void gpencil_shgroups_create(GPENCIL_e_data *e_data, const bool overlay = draw_ctx->v3d != NULL ? (bool)((draw_ctx->v3d->flag2 & V3D_HIDE_OVERLAYS) == 0) : true; - const bool main_onion = v3d != NULL ? (v3d->gp_flag & V3D_GP_SHOW_ONION_SKIN) : true; - const bool do_onion = (bool)((gpd->flag & GP_DATA_STROKE_WEIGHTMODE) == 0) && main_onion && + const bool screen_onion = v3d != NULL ? (v3d->gp_flag & V3D_GP_SHOW_ONION_SKIN) : true; + const bool do_onion = (bool)((gpd->flag & GP_DATA_STROKE_WEIGHTMODE) == 0) && screen_onion && overlay && gpencil_onion_active(gpd); int start_stroke = 0; @@ -2062,13 +2040,9 @@ void gpencil_populate_datablock(GPENCIL_e_data *e_data, bGPdata *gpd_eval = (bGPdata *)ob->data; bGPdata *gpd = (bGPdata *)DEG_get_original_id(&gpd_eval->id); - const bool main_onion = draw_ctx->v3d != NULL ? - (draw_ctx->v3d->gp_flag & V3D_GP_SHOW_ONION_SKIN) : - true; + const bool main_onion = stl->storage->is_main_onion; const bool playing = stl->storage->is_playing; - const bool overlay = draw_ctx->v3d != NULL ? - (bool)((draw_ctx->v3d->flag2 & V3D_HIDE_OVERLAYS) == 0) : - true; + const bool overlay = stl->storage->is_main_overlay; const bool do_onion = (bool)((gpd->flag & GP_DATA_STROKE_WEIGHTMODE) == 0) && overlay && main_onion && !playing && gpencil_onion_active(gpd); diff --git a/source/blender/draw/engines/gpencil/gpencil_engine.c b/source/blender/draw/engines/gpencil/gpencil_engine.c index 7d9f2d1fdf3..aed6789fe26 100644 --- a/source/blender/draw/engines/gpencil/gpencil_engine.c +++ b/source/blender/draw/engines/gpencil/gpencil_engine.c @@ -24,11 +24,13 @@ #include "BKE_gpencil.h" #include "BKE_library.h" +#include "BKE_main.h" #include "BKE_object.h" #include "BKE_paint.h" #include "BKE_shader_fx.h" #include "DNA_gpencil_types.h" +#include "DNA_screen_types.h" #include "DNA_view3d_types.h" #include "draw_mode_engines.h" @@ -310,6 +312,43 @@ static void GPENCIL_engine_free(void) GPENCIL_delete_fx_shaders(&e_data); } +/* Helper: Check if the main overlay and onion switches are enabled in any screen. + * + * This is required to generate the onion skin and limit the times the cache is updated because the + * cache is generated only in the first screen and if the first screen has the onion disabled the + * cache for onion skin is not generated. The loop adds time, but always is faster than regenerate + * the cache all the times. + */ +static void gpencil_check_screen_switches(const DRWContextState *draw_ctx, + GPENCIL_StorageList *stl) +{ + stl->storage->is_main_overlay = false; + stl->storage->is_main_onion = false; + /* Check if main onion switch is enabled in any screen. */ + Main *bmain = CTX_data_main(draw_ctx->evil_C); + + for (bScreen *screen = bmain->screens.first; screen; screen = screen->id.next) { + for (const ScrArea *sa = screen->areabase.first; sa; sa = sa->next) { + if (sa && sa->spacetype == SPACE_VIEW3D) { + View3D *v3d = sa->spacedata.first; + if (v3d == NULL) { + continue; + } + if ((v3d->flag2 & V3D_HIDE_OVERLAYS) == 0) { + stl->storage->is_main_overlay = true; + } + if (v3d->gp_flag & V3D_GP_SHOW_ONION_SKIN) { + stl->storage->is_main_onion = true; + } + } + /* If found, don't need loop more. */ + if ((stl->storage->is_main_overlay) && (stl->storage->is_main_onion)) { + return; + } + } + } +} + void GPENCIL_cache_init(void *vedata) { GPENCIL_PassList *psl = ((GPENCIL_Data *)vedata)->psl; @@ -320,6 +359,7 @@ void GPENCIL_cache_init(void *vedata) ToolSettings *ts = scene->toolsettings; View3D *v3d = draw_ctx->v3d; Brush *brush = BKE_paint_brush(&ts->gp_paint->paint); + const View3DCursor *cursor = &scene->cursor; /* Special handling for when active object is GP object (e.g. for draw mode) */ Object *obact = draw_ctx->obact; @@ -395,10 +435,15 @@ void GPENCIL_cache_init(void *vedata) stl->storage->reset_cache = true; } stl->storage->is_playing = playing; + + /* Found if main overlay and onion switches are enabled in any screen. */ + gpencil_check_screen_switches(draw_ctx, stl); } else { stl->storage->is_playing = false; stl->storage->reset_cache = false; + stl->storage->is_main_overlay = false; + stl->storage->is_main_onion = false; } /* save render state */ stl->storage->is_render = DRW_state_is_image_render(); @@ -546,11 +591,42 @@ void GPENCIL_cache_init(void *vedata) } /* grid pass */ - if (v3d) { + if ((v3d) && (obact) && (obact->type == OB_GPENCIL)) { psl->grid_pass = DRW_pass_create("GPencil Grid Pass", DRW_STATE_WRITE_COLOR | DRW_STATE_BLEND_ALPHA | DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_ALWAYS); stl->g_data->shgrps_grid = DRW_shgroup_create(e_data.gpencil_line_sh, psl->grid_pass); + + /* define grid orientation */ + switch (ts->gp_sculpt.lock_axis) { + case GP_LOCKAXIS_VIEW: { + /* align always to view */ + invert_m4_m4(stl->storage->grid_matrix, draw_ctx->rv3d->viewmat); + /* copy ob location */ + copy_v3_v3(stl->storage->grid_matrix[3], obact->obmat[3]); + break; + } + case GP_LOCKAXIS_CURSOR: { + float scale[3] = {1.0f, 1.0f, 1.0f}; + loc_eul_size_to_mat4( + stl->storage->grid_matrix, cursor->location, cursor->rotation_euler, scale); + break; + } + default: { + copy_m4_m4(stl->storage->grid_matrix, obact->obmat); + break; + } + } + + /* Move the origin to Object or Cursor */ + if (ts->gpencil_v3d_align & GP_PROJECT_CURSOR) { + copy_v3_v3(stl->storage->grid_matrix[3], cursor->location); + } + else { + copy_v3_v3(stl->storage->grid_matrix[3], obact->obmat[3]); + } + DRW_shgroup_uniform_mat4( + stl->g_data->shgrps_grid, "gpModelMatrix", stl->storage->grid_matrix); } /* blend layers pass */ @@ -633,8 +709,6 @@ void GPENCIL_cache_populate(void *vedata, Object *ob) Scene *scene = draw_ctx->scene; ToolSettings *ts = scene->toolsettings; View3D *v3d = draw_ctx->v3d; - const View3DCursor *cursor = &scene->cursor; - float grid_matrix[4][4]; if (ob->type == OB_GPENCIL && ob->data) { bGPdata *gpd = (bGPdata *)ob->data; @@ -695,36 +769,7 @@ void GPENCIL_cache_populate(void *vedata, Object *ob) ((ts->gpencil_v3d_align & GP_PROJECT_DEPTH_STROKE) == 0)) { stl->g_data->batch_grid = gpencil_get_grid(ob); - - /* define grid orientation */ - switch (ts->gp_sculpt.lock_axis) { - case GP_LOCKAXIS_VIEW: { - /* align always to view */ - invert_m4_m4(grid_matrix, draw_ctx->rv3d->viewmat); - /* copy ob location */ - copy_v3_v3(grid_matrix[3], ob->obmat[3]); - break; - } - case GP_LOCKAXIS_CURSOR: { - float scale[3] = {1.0f, 1.0f, 1.0f}; - loc_eul_size_to_mat4(grid_matrix, cursor->location, cursor->rotation_euler, scale); - break; - } - default: { - copy_m4_m4(grid_matrix, ob->obmat); - break; - } - } - - /* Move the origin to Object or Cursor */ - if (ts->gpencil_v3d_align & GP_PROJECT_CURSOR) { - copy_v3_v3(grid_matrix[3], cursor->location); - } - else { - copy_v3_v3(grid_matrix[3], ob->obmat[3]); - } - - DRW_shgroup_call_obmat(stl->g_data->shgrps_grid, stl->g_data->batch_grid, grid_matrix); + DRW_shgroup_call(stl->g_data->shgrps_grid, stl->g_data->batch_grid, NULL); } } } diff --git a/source/blender/draw/engines/gpencil/gpencil_engine.h b/source/blender/draw/engines/gpencil/gpencil_engine.h index c475c343d22..5638639cbf2 100644 --- a/source/blender/draw/engines/gpencil/gpencil_engine.h +++ b/source/blender/draw/engines/gpencil/gpencil_engine.h @@ -145,6 +145,8 @@ typedef struct GPENCIL_Storage { bool is_playing; bool is_render; bool is_mat_preview; + bool is_main_overlay; + bool is_main_onion; bool background_ready; int is_xray; bool is_ontop; @@ -155,6 +157,7 @@ typedef struct GPENCIL_Storage { int do_select_outline; float select_color[4]; short multisamples; + float grid_matrix[4][4]; short framebuffer_flag; /* flag what framebuffer need to create */ |