Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/space_graph/graph_draw.c
| Show First 20 Lines • Show All 487 Lines • ▼ Show 20 Lines | static void draw_fcurve_samples(SpaceGraph *sipo, ARegion *ar, FCurve *fcu) | ||||
| } | } | ||||
| } | } | ||||
| /* Curve ---------------- */ | /* Curve ---------------- */ | ||||
| /* Helper func - just draw the F-Curve by sampling the visible region | /* Helper func - just draw the F-Curve by sampling the visible region | ||||
| * (for drawing curves with modifiers). */ | * (for drawing curves with modifiers). */ | ||||
| static void draw_fcurve_curve( | static void draw_fcurve_curve( | ||||
| bAnimContext *ac, ID *id, FCurve *fcu_, View2D *v2d, View2DGrid *grid, unsigned int pos) | bAnimContext *ac, ID *id, FCurve *fcu_, View2D *v2d, unsigned int pos) | ||||
| { | { | ||||
| SpaceGraph *sipo = (SpaceGraph *)ac->sl; | SpaceGraph *sipo = (SpaceGraph *)ac->sl; | ||||
| float samplefreq; | float samplefreq; | ||||
| float stime, etime; | float stime, etime; | ||||
| float unitFac, offset; | float unitFac, offset; | ||||
| float dx, dy; | |||||
| short mapping_flag = ANIM_get_normalization_flags(ac); | short mapping_flag = ANIM_get_normalization_flags(ac); | ||||
| int i, n; | int i, n; | ||||
| /* when opening a blend file on a different sized screen or while dragging the toolbar this can | /* when opening a blend file on a different sized screen or while dragging the toolbar this can | ||||
| * happen best just bail out in this case. */ | * happen best just bail out in this case. */ | ||||
| UI_view2d_grid_size(grid, &dx, &dy); | if (UI_view2d_scale_get_x(v2d) <= 0.0f) { | ||||
| if (dx <= 0.0f) { | |||||
| return; | return; | ||||
| } | } | ||||
| /* disable any drivers */ | /* disable any drivers */ | ||||
| FCurve fcurve_for_draw = *fcu_; | FCurve fcurve_for_draw = *fcu_; | ||||
| fcurve_for_draw.driver = NULL; | fcurve_for_draw.driver = NULL; | ||||
| /* compute unit correction factor */ | /* compute unit correction factor */ | ||||
| unitFac = ANIM_unit_mapping_get_factor(ac->scene, id, &fcurve_for_draw, mapping_flag, &offset); | unitFac = ANIM_unit_mapping_get_factor(ac->scene, id, &fcurve_for_draw, mapping_flag, &offset); | ||||
| /* Note about sampling frequency: | /* Note about sampling frequency: | ||||
| * Ideally, this is chosen such that we have 1-2 pixels = 1 segment | * Ideally, this is chosen such that we have 1-2 pixels = 1 segment | ||||
| * which means that our curves can be as smooth as possible. However, | * which means that our curves can be as smooth as possible. However, | ||||
| * this does mean that curves may not be fully accurate (i.e. if they have | * this does mean that curves may not be fully accurate (i.e. if they have | ||||
| * sudden spikes which happen at the sampling point, we may have problems). | * sudden spikes which happen at the sampling point, we may have problems). | ||||
| * Also, this may introduce lower performance on less densely detailed curves, | * Also, this may introduce lower performance on less densely detailed curves, | ||||
| * though it is impossible to predict this from the modifiers! | * though it is impossible to predict this from the modifiers! | ||||
| * | * | ||||
| * If the automatically determined sampling frequency is likely to cause an infinite | * If the automatically determined sampling frequency is likely to cause an infinite | ||||
| * loop (i.e. too close to 0), then clamp it to a determined "safe" value. The value | * loop (i.e. too close to 0), then clamp it to a determined "safe" value. The value | ||||
| * chosen here is just the coarsest value which still looks reasonable... | * chosen here is just the coarsest value which still looks reasonable... | ||||
| */ | */ | ||||
| /* grid->dx represents the number of 'frames' between gridlines, | |||||
| * but we divide by U.v2d_min_gridsize to get pixels-steps */ | |||||
| /* TODO: perhaps we should have 1.0 frames | /* TODO: perhaps we should have 1.0 frames | ||||
| * as upper limit so that curves don't get too distorted? */ | * as upper limit so that curves don't get too distorted? */ | ||||
| samplefreq = dx / (U.v2d_min_gridsize * U.pixelsize); | float pixels_per_sample = 1.5f; | ||||
| samplefreq = pixels_per_sample / UI_view2d_scale_get_x(v2d); | |||||
| if (sipo->flag & SIPO_BEAUTYDRAW_OFF) { | if (sipo->flag & SIPO_BEAUTYDRAW_OFF) { | ||||
| /* Low Precision = coarse lower-bound clamping | /* Low Precision = coarse lower-bound clamping | ||||
| * | * | ||||
| * Although the "Beauty Draw" flag was originally for AA'd | * Although the "Beauty Draw" flag was originally for AA'd | ||||
| * line drawing, the sampling rate here has a much greater | * line drawing, the sampling rate here has a much greater | ||||
| * impact on performance (e.g. for T40372)! | * impact on performance (e.g. for T40372)! | ||||
| * | * | ||||
| ▲ Show 20 Lines • Show All 493 Lines • ▼ Show 20 Lines | if ((sipo->flag & SIPO_BEAUTYDRAW_OFF) == 0) { | ||||
| GPU_line_smooth(false); | GPU_line_smooth(false); | ||||
| } | } | ||||
| GPU_blend(false); | GPU_blend(false); | ||||
| } | } | ||||
| /* This is called twice from space_graph.c -> graph_main_region_draw() | /* This is called twice from space_graph.c -> graph_main_region_draw() | ||||
| * Unselected then selected F-Curves are drawn so that they do not occlude each other. | * Unselected then selected F-Curves are drawn so that they do not occlude each other. | ||||
| */ | */ | ||||
| void graph_draw_curves( | void graph_draw_curves(bAnimContext *ac, SpaceGraph *sipo, ARegion *ar, short sel) | ||||
| bAnimContext *ac, SpaceGraph *sipo, ARegion *ar, View2DGrid *grid, short sel) | |||||
| { | { | ||||
| ListBase anim_data = {NULL, NULL}; | ListBase anim_data = {NULL, NULL}; | ||||
| bAnimListElem *ale; | bAnimListElem *ale; | ||||
| int filter; | int filter; | ||||
| /* build list of curves to draw */ | /* build list of curves to draw */ | ||||
| filter = (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_CURVE_VISIBLE); | filter = (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_CURVE_VISIBLE); | ||||
| filter |= ((sel) ? (ANIMFILTER_SEL) : (ANIMFILTER_UNSEL)); | filter |= ((sel) ? (ANIMFILTER_SEL) : (ANIMFILTER_UNSEL)); | ||||
| ▲ Show 20 Lines • Show All 70 Lines • ▼ Show 20 Lines | if (((fcu->modifiers.first) || (fcu->flag & FCURVE_INT_VALUES)) || | ||||
| immUniformColor3fvAlpha(fcu->color, fcurve_display_alpha(fcu)); | immUniformColor3fvAlpha(fcu->color, fcurve_display_alpha(fcu)); | ||||
| } | } | ||||
| /* draw F-Curve */ | /* draw F-Curve */ | ||||
| if ((fcu->modifiers.first) || (fcu->flag & FCURVE_INT_VALUES)) { | if ((fcu->modifiers.first) || (fcu->flag & FCURVE_INT_VALUES)) { | ||||
| /* draw a curve affected by modifiers or only allowed to have integer values | /* draw a curve affected by modifiers or only allowed to have integer values | ||||
| * by sampling it at various small-intervals over the visible region | * by sampling it at various small-intervals over the visible region | ||||
| */ | */ | ||||
| draw_fcurve_curve(ac, ale->id, fcu, &ar->v2d, grid, shdr_pos); | draw_fcurve_curve(ac, ale->id, fcu, &ar->v2d, shdr_pos); | ||||
| } | } | ||||
| else if (((fcu->bezt) || (fcu->fpt)) && (fcu->totvert)) { | else if (((fcu->bezt) || (fcu->fpt)) && (fcu->totvert)) { | ||||
| /* just draw curve based on defined data (i.e. no modifiers) */ | /* just draw curve based on defined data (i.e. no modifiers) */ | ||||
| if (fcu->bezt) { | if (fcu->bezt) { | ||||
| if (fcurve_can_use_simple_bezt_drawing(fcu)) { | if (fcurve_can_use_simple_bezt_drawing(fcu)) { | ||||
| draw_fcurve_curve_bezts(ac, ale->id, fcu, &ar->v2d, shdr_pos); | draw_fcurve_curve_bezts(ac, ale->id, fcu, &ar->v2d, shdr_pos); | ||||
| } | } | ||||
| else { | else { | ||||
| draw_fcurve_curve(ac, ale->id, fcu, &ar->v2d, grid, shdr_pos); | draw_fcurve_curve(ac, ale->id, fcu, &ar->v2d, shdr_pos); | ||||
| } | } | ||||
| } | } | ||||
| else if (fcu->fpt) { | else if (fcu->fpt) { | ||||
| draw_fcurve_curve_samples(ac, ale->id, fcu, &ar->v2d, shdr_pos); | draw_fcurve_curve_samples(ac, ale->id, fcu, &ar->v2d, shdr_pos); | ||||
| } | } | ||||
| } | } | ||||
| immUnbindProgram(); | immUnbindProgram(); | ||||
| ▲ Show 20 Lines • Show All 161 Lines • Show Last 20 Lines | |||||