Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/space_view3d/view3d_draw_legacy.c
| Show First 20 Lines • Show All 1,498 Lines • ▼ Show 20 Lines | if (sa->spacetype == SPACE_VIEW3D) { | ||||
| mask |= ED_view3d_datamask(scene, sa->spacedata.first); | mask |= ED_view3d_datamask(scene, sa->spacedata.first); | ||||
| } | } | ||||
| } | } | ||||
| return mask; | return mask; | ||||
| } | } | ||||
| /** | /** | ||||
| * Draw grease pencil object strokes | |||||
| */ | |||||
| static void draw_gpencil_object_strokes(const bContext *C, Scene *scene, View3D *v3d, ARegion *ar, Base *base) | |||||
| { | |||||
| const bool render_override = (v3d->flag2 & V3D_RENDER_OVERRIDE) != 0; | |||||
| Object *ob = base->object; | |||||
| if (ob != scene->obedit) { | |||||
| if (ob->restrictflag & OB_RESTRICT_VIEW) | |||||
| return; | |||||
| if (render_override) { | |||||
| if (ob->restrictflag & OB_RESTRICT_RENDER) | |||||
| return; | |||||
| if (ob->transflag & (OB_DUPLI & ~OB_DUPLIFRAMES)) | |||||
| return; | |||||
| } | |||||
| } | |||||
| wmWindowManager *wm = (C != NULL) ? CTX_wm_manager(C) : NULL; | |||||
| if (v3d->zbuf) glDisable(GL_DEPTH_TEST); | |||||
| ED_gpencil_draw_view3d_object(wm, scene, ob, v3d, ar, true); | |||||
| if (v3d->zbuf) glEnable(GL_DEPTH_TEST); | |||||
| } | |||||
| /* helper function to sort gpencil objects using qsort */ | |||||
| static int compare_gpencil_zdepth(const void *a1, const void *a2) | |||||
| { | |||||
| const tGPencilSort *ps1 = a1, *ps2 = a2; | |||||
| if (ps1->zdepth > ps2->zdepth) return 1; | |||||
| else if (ps1->zdepth < ps2->zdepth) return -1; | |||||
| return 0; | |||||
| } | |||||
| /* draw objects in cache from back to from */ | |||||
| static void gpencil_draw_objects(const bContext *C, Scene *scene, View3D *v3d, ARegion *ar, tGPencilSort *cache, int gp_cache_used) | |||||
| { | |||||
| if (gp_cache_used > 0) { | |||||
| /* sort by zdepth */ | |||||
| qsort(cache, gp_cache_used, sizeof(tGPencilSort), compare_gpencil_zdepth); | |||||
| /* inverse loop to draw from back to front */ | |||||
| for (int i = gp_cache_used; i > 0; --i) { | |||||
| Base *base = cache[i - 1].base; | |||||
| draw_gpencil_object_strokes(C, scene, v3d, ar, base); | |||||
| } | |||||
| } | |||||
| /* free memory */ | |||||
| if (cache) { | |||||
| MEM_freeN(cache); | |||||
| } | |||||
| } | |||||
| /** | |||||
| * Shared by #ED_view3d_draw_offscreen and #view3d_main_region_draw_objects | * Shared by #ED_view3d_draw_offscreen and #view3d_main_region_draw_objects | ||||
| * | * | ||||
| * \note \a C and \a grid_unit will be NULL when \a draw_offscreen is set. | * \note \a C and \a grid_unit will be NULL when \a draw_offscreen is set. | ||||
| * \note Drawing lamps and opengl render uses this, so dont do grease pencil or view widgets here. | * \note Drawing lamps and opengl render uses this, so dont do grease pencil or view widgets here. | ||||
| */ | */ | ||||
| static void view3d_draw_objects( | static void view3d_draw_objects( | ||||
| const bContext *C, | const bContext *C, | ||||
| const EvaluationContext *eval_ctx, | const EvaluationContext *eval_ctx, | ||||
| Scene *scene, View3D *v3d, ARegion *ar, | Scene *scene, View3D *v3d, ARegion *ar, | ||||
| const char **grid_unit, | const char **grid_unit, | ||||
| const bool do_bgpic, const bool draw_offscreen, GPUFX *fx) | const bool do_bgpic, const bool draw_offscreen, GPUFX *fx) | ||||
| { | { | ||||
| SceneLayer *sl = C ? CTX_data_scene_layer(C) : BKE_scene_layer_from_scene_get(scene); | SceneLayer *sl = C ? CTX_data_scene_layer(C) : BKE_scene_layer_from_scene_get(scene); | ||||
| RegionView3D *rv3d = ar->regiondata; | RegionView3D *rv3d = ar->regiondata; | ||||
| Base *base; | Base *base; | ||||
| const bool do_camera_frame = !draw_offscreen; | const bool do_camera_frame = !draw_offscreen; | ||||
| const bool draw_grids = !draw_offscreen && (v3d->flag2 & V3D_RENDER_OVERRIDE) == 0; | const bool draw_grids = !draw_offscreen && (v3d->flag2 & V3D_RENDER_OVERRIDE) == 0; | ||||
| const bool draw_floor = (rv3d->view == RV3D_VIEW_USER) || (rv3d->persp != RV3D_ORTHO); | const bool draw_floor = (rv3d->view == RV3D_VIEW_USER) || (rv3d->persp != RV3D_ORTHO); | ||||
| /* only draw grids after in solid modes, else it hovers over mesh wires */ | /* only draw grids after in solid modes, else it hovers over mesh wires */ | ||||
| const bool draw_grids_after = draw_grids && draw_floor && (v3d->drawtype > OB_WIRE) && fx; | const bool draw_grids_after = draw_grids && draw_floor && (v3d->drawtype > OB_WIRE) && fx; | ||||
| bool do_composite_xray = false; | bool do_composite_xray = false; | ||||
| bool xrayclear = true; | bool xrayclear = true; | ||||
| int gp_cache_used = 0; | |||||
| int gp_cache_size = 0; | |||||
| tGPencilSort *gp_cache = NULL; | |||||
| if (!draw_offscreen) { | if (!draw_offscreen) { | ||||
| ED_region_draw_cb_draw(C, ar, REGION_DRAW_PRE_VIEW); | ED_region_draw_cb_draw(C, ar, REGION_DRAW_PRE_VIEW); | ||||
| } | } | ||||
| if (rv3d->rflag & RV3D_CLIPPING) | if (rv3d->rflag & RV3D_CLIPPING) | ||||
| view3d_draw_clipping(rv3d); | view3d_draw_clipping(rv3d); | ||||
| /* set zbuffer after we draw clipping region */ | /* set zbuffer after we draw clipping region */ | ||||
| ▲ Show 20 Lines • Show All 52 Lines • ▼ Show 20 Lines | if (draw_offscreen) { | ||||
| for (base = sl->object_bases.first; base; base = base->next) { | for (base = sl->object_bases.first; base; base = base->next) { | ||||
| if ((base->flag & BASE_VISIBLED) != 0) { | if ((base->flag & BASE_VISIBLED) != 0) { | ||||
| /* dupli drawing */ | /* dupli drawing */ | ||||
| if (base->object->transflag & OB_DUPLI) { | if (base->object->transflag & OB_DUPLI) { | ||||
| draw_dupli_objects(eval_ctx, scene, sl, ar, v3d, base); | draw_dupli_objects(eval_ctx, scene, sl, ar, v3d, base); | ||||
| } | } | ||||
| draw_object(eval_ctx, scene, sl, ar, v3d, base, 0); | draw_object(eval_ctx, scene, sl, ar, v3d, base, 0); | ||||
| /* draw grease pencil */ | |||||
| if (base->object->type == OB_GPENCIL) { | |||||
| /* allocate memory for saving gp objects */ | |||||
| gp_cache = ED_gpencil_allocate_cache(gp_cache, &gp_cache_size, gp_cache_used); | |||||
| /* add for drawing later */ | |||||
| ED_gpencil_add_to_cache(gp_cache, rv3d, base, &gp_cache_used); | |||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| /* draw pending gpencil strokes */ | |||||
| gpencil_draw_objects(C, scene, v3d, ar, gp_cache, gp_cache_used); | |||||
| } | |||||
| else { | else { | ||||
| unsigned int lay_used = 0; | unsigned int lay_used = 0; | ||||
| /* then draw not selected and the duplis, but skip editmode object */ | /* then draw not selected and the duplis, but skip editmode object */ | ||||
| for (base = sl->object_bases.first; base; base = base->next) { | for (base = sl->object_bases.first; base; base = base->next) { | ||||
| lay_used |= base->lay; | lay_used |= base->lay; | ||||
| if ((base->flag & BASE_VISIBLED) != 0) { | if ((base->flag & BASE_VISIBLED) != 0) { | ||||
| /* dupli drawing */ | /* dupli drawing */ | ||||
| if (base->object->transflag & OB_DUPLI) { | if (base->object->transflag & OB_DUPLI) { | ||||
| draw_dupli_objects(eval_ctx, scene, sl, ar, v3d, base); | draw_dupli_objects(eval_ctx, scene, sl, ar, v3d, base); | ||||
| } | } | ||||
| if ((base->flag & BASE_SELECTED) == 0) { | if ((base->flag & BASE_SELECTED) == 0) { | ||||
| if (base->object != scene->obedit) | if (base->object != scene->obedit) { | ||||
| draw_object(eval_ctx, scene, sl, ar, v3d, base, 0); | draw_object(eval_ctx, scene, sl, ar, v3d, base, 0); | ||||
| /* draw grease pencil */ | |||||
| if (base->object->type == OB_GPENCIL) { | |||||
| /* allocate memory for saving gp objects */ | |||||
| gp_cache = ED_gpencil_allocate_cache(gp_cache, &gp_cache_size, gp_cache_used); | |||||
| /* add for drawing later */ | |||||
| ED_gpencil_add_to_cache(gp_cache, rv3d, base, &gp_cache_used); | |||||
| } | |||||
| } | |||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| /* mask out localview */ | /* mask out localview */ | ||||
| v3d->lay_used = lay_used & ((1 << 20) - 1); | v3d->lay_used = lay_used & ((1 << 20) - 1); | ||||
| /* draw selected and editmode */ | /* draw selected and editmode */ | ||||
| for (base = sl->object_bases.first; base; base = base->next) { | for (base = sl->object_bases.first; base; base = base->next) { | ||||
| if ((base->flag & BASE_VISIBLED) != 0) { | if ((base->flag & BASE_VISIBLED) != 0) { | ||||
| if (base->object == scene->obedit || (base->flag & BASE_SELECTED)) { | if (base->object == scene->obedit || (base->flag & BASE_SELECTED)) { | ||||
| draw_object(eval_ctx, scene, sl, ar, v3d, base, 0); | draw_object(eval_ctx, scene, sl, ar, v3d, base, 0); | ||||
| /* draw grease pencil */ | |||||
| if (base->object->type == OB_GPENCIL) { | |||||
| /* allocate memory for saving gp objects */ | |||||
| gp_cache = ED_gpencil_allocate_cache(gp_cache, &gp_cache_size, gp_cache_used); | |||||
| /* add for drawing later */ | |||||
| ED_gpencil_add_to_cache(gp_cache, rv3d, base, &gp_cache_used); | |||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| /* draw pending gpencil strokes */ | |||||
| gpencil_draw_objects(C, scene, v3d, ar, gp_cache, gp_cache_used); | |||||
| } | |||||
| /* perspective floor goes last to use scene depth and avoid writing to depth buffer */ | /* perspective floor goes last to use scene depth and avoid writing to depth buffer */ | ||||
| if (draw_grids_after) { | if (draw_grids_after) { | ||||
| VP_legacy_drawfloor(scene, v3d, grid_unit, false); | VP_legacy_drawfloor(scene, v3d, grid_unit, false); | ||||
| } | } | ||||
| /* must be before xray draw which clears the depth buffer */ | /* must be before xray draw which clears the depth buffer */ | ||||
| if (v3d->flag2 & V3D_SHOW_GPENCIL) { | if (v3d->flag2 & V3D_SHOW_GPENCIL) { | ||||
| ▲ Show 20 Lines • Show All 412 Lines • ▼ Show 20 Lines | static void view3d_main_region_draw_info(const bContext *C, Scene *scene, | ||||
| } | } | ||||
| else if (v3d->flag2 & V3D_RENDER_BORDER) { | else if (v3d->flag2 & V3D_RENDER_BORDER) { | ||||
| VP_drawrenderborder(ar, v3d); | VP_drawrenderborder(ar, v3d); | ||||
| } | } | ||||
| if (v3d->flag2 & V3D_SHOW_GPENCIL) { | if (v3d->flag2 & V3D_SHOW_GPENCIL) { | ||||
| /* draw grease-pencil stuff - needed to get paint-buffer shown too (since it's 2D) */ | /* draw grease-pencil stuff - needed to get paint-buffer shown too (since it's 2D) */ | ||||
| ED_gpencil_draw_view3d(wm, scene, v3d, ar, false); | ED_gpencil_draw_view3d(wm, scene, v3d, ar, false); | ||||
| Object *obact = CTX_data_active_object(C); | |||||
| if (obact && obact->type == OB_GPENCIL) { | |||||
| ED_gpencil_draw_view3d_object(wm, scene, obact, v3d, ar, false); | |||||
| } | |||||
| } | } | ||||
| if ((v3d->flag2 & V3D_RENDER_OVERRIDE) == 0) { | if ((v3d->flag2 & V3D_RENDER_OVERRIDE) == 0) { | ||||
| VP_legacy_drawcursor(scene, sl, ar, v3d); /* 3D cursor */ | VP_legacy_drawcursor(scene, sl, ar, v3d); /* 3D cursor */ | ||||
| if (U.uiflag & USER_SHOW_ROTVIEWICON) | if (U.uiflag & USER_SHOW_ROTVIEWICON) | ||||
| VP_legacy_draw_view_axis(rv3d, &rect); | VP_legacy_draw_view_axis(rv3d, &rect); | ||||
| else | else | ||||
| ▲ Show 20 Lines • Show All 120 Lines • Show Last 20 Lines | |||||