diff options
author | Germano Cavalcante <germano.costa@ig.com.br> | 2021-07-23 18:19:08 +0300 |
---|---|---|
committer | Germano Cavalcante <germano.costa@ig.com.br> | 2021-07-24 00:47:07 +0300 |
commit | 3123f33380b35ae93afee0a30f36bc7181927b28 (patch) | |
tree | b399a799e1f6d75dc6930cba02f0953f83391038 /source/blender/editors | |
parent | a092baa7f90b2d5f13771d46f64ff5cf86cc5a05 (diff) |
Many tweaks to f-curve drawing code
Diffstat (limited to 'source/blender/editors')
-rw-r--r-- | source/blender/editors/space_sequencer/sequencer_draw.c | 197 |
1 files changed, 91 insertions, 106 deletions
diff --git a/source/blender/editors/space_sequencer/sequencer_draw.c b/source/blender/editors/space_sequencer/sequencer_draw.c index db18c651791..57c65fa56c2 100644 --- a/source/blender/editors/space_sequencer/sequencer_draw.c +++ b/source/blender/editors/space_sequencer/sequencer_draw.c @@ -1020,98 +1020,82 @@ static void draw_seq_fcurve_overlay(Scene *scene, float pixelx, float pixely) { - SpeedControlVars *v = (SpeedControlVars *)seq->effectdata; - FCurve *fcu; + /* Clamp curve evaluation to the editor's borders. */ + const int eval_start = max_ff(x1, v2d->cur.xmin); + const int eval_end = min_ff(x2, v2d->cur.xmax + 1); + if (eval_start >= eval_end) { + return; + } + + const float y_height = y2 - y1; double curve_val; + GPUVertBuf *vbo = NULL; + uint vert_count = 0; + + GPUVertFormat format = {0}; + GPU_vertformat_attr_add(&format, "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT); + const char *prop_name = NULL; if (seq->type == SEQ_TYPE_SPEED) { + SpeedControlVars *v = (SpeedControlVars *)seq->effectdata; switch (v->speed_control_type) { case SEQ_SPEED_MULTIPLY: { - fcu = id_data_find_fcurve(&scene->id, seq, &RNA_Sequence, "speed_factor", 0, NULL); + prop_name = "speed_factor"; break; } case SEQ_SPEED_FRAME_NUMBER: { - fcu = id_data_find_fcurve(&scene->id, seq, &RNA_Sequence, "speed_frame_number", 0, NULL); + prop_name = "speed_frame_number"; break; } case SEQ_SPEED_LENGTH: { - fcu = id_data_find_fcurve(&scene->id, seq, &RNA_Sequence, "speed_length", 0, NULL); + prop_name = "speed_length"; break; } case SEQ_SPEED_STRETCH: { - fcu = NULL; break; } } } else if (seq->type == SEQ_TYPE_SOUND_RAM) { - fcu = id_data_find_fcurve(&scene->id, seq, &RNA_Sequence, "volume", 0, NULL); + prop_name = "volume"; } else { - fcu = id_data_find_fcurve(&scene->id, seq, &RNA_Sequence, "blend_alpha", 0, NULL); + prop_name = "blend_alpha"; } - if (fcu && !BKE_fcurve_is_empty(fcu)) { + FCurve *fcu = NULL; + if (prop_name) { + fcu = id_data_find_fcurve(&scene->id, seq, &RNA_Sequence, prop_name, 0, NULL); + } - /* Clamp curve evaluation to the editor's borders. */ - int eval_start = max_ff(x1, v2d->cur.xmin); - int eval_end = min_ff(x2, v2d->cur.xmax + 1); + float ymax = 1.0f; + float ymin = 0.0f; + if (fcu && !BKE_fcurve_is_empty(fcu)) { int eval_step = max_ii(1, floor(pixelx)); - - if (eval_start >= eval_end) { - return; - } - - GPUVertFormat format = {0}; - GPU_vertformat_attr_add(&format, "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT); - GPUVertBuf *vbo = GPU_vertbuf_create_with_format(&format); - uint max_verts = 2 * ((eval_end - eval_start) / eval_step + 1); + + vbo = GPU_vertbuf_create_with_format(&format); GPU_vertbuf_data_alloc(vbo, max_verts); - uint vert_count = 0; - const float y_height = y2 - y1; float prev_val = INT_MIN; bool skip = false; - double ymax = 1.0; - double ymin = 0.0; if (seq->type == SEQ_TYPE_SPEED) { - SEQ_effect_handle_get(seq); + BKE_fcurve_calc_bounds(fcu, NULL, NULL, &ymin, &ymax, false, false); + ymin = min_ff(ymin, 0.0f); + SpeedControlVars *v = (SpeedControlVars *)seq->effectdata; switch (v->speed_control_type) { case SEQ_SPEED_LENGTH: { - ymin = 0.0; - ymax = 100.0; + ymax = max_ff(ymax, 100.0f); break; } case SEQ_SPEED_FRAME_NUMBER: { - ymin = 0; - ymax = seq_effect_speed_get_strip_content_length(seq->seq1); + ymax = max_ff(ymax, (float)seq_effect_speed_get_strip_content_length(seq->seq1)); break; } case SEQ_SPEED_MULTIPLY: { - ymin = 0.0; - ymax = 0.0; - /* Get range. */ - for (int timeline_frame = eval_start; timeline_frame <= eval_end; - timeline_frame += eval_step) { - curve_val = evaluate_fcurve(fcu, timeline_frame); - if (curve_val > ymax) { - ymax = curve_val; - } - if (curve_val < ymin) { - ymin = curve_val; - } - } - if (ymin < 0) { - ymax = ymax + fabs(ymin); - ymin = fabs(ymin); - } - else { - ymax = ymax - ymin; - ymin = -ymin; - } + ymax = max_ff(ymax, 1.0f); } } } @@ -1119,19 +1103,11 @@ static void draw_seq_fcurve_overlay(Scene *scene, for (int timeline_frame = eval_start; timeline_frame <= eval_end; timeline_frame += eval_step) { + curve_val = evaluate_fcurve(fcu, timeline_frame); if (seq->type == SEQ_TYPE_SPEED) { - curve_val = evaluate_fcurve(fcu, timeline_frame); - - if (v->speed_control_type == SEQ_SPEED_MULTIPLY) { - curve_val = (((curve_val + ymin) / (ymax + ymin)) * v->globalSpeed); - } - else { - curve_val = ((curve_val / (ymax - ymin)) * v->globalSpeed); - } - } - else { - curve_val = evaluate_fcurve(fcu, timeline_frame); + curve_val = ratiof(ymin, ymax, curve_val); } + CLAMP(curve_val, 0.0f, 1.0f); /* Avoid adding adjacent verts that have the same value. */ @@ -1150,60 +1126,69 @@ static void draw_seq_fcurve_overlay(Scene *scene, fcurve_batch_add_verts(vbo, y1, y2, y_height, timeline_frame, curve_val, &vert_count); prev_val = curve_val; } + } + else { + /* Draw the values without f-curves. */ + if (seq->type == SEQ_TYPE_SPEED) { + SpeedControlVars *v = (SpeedControlVars *)seq->effectdata; + if (v->speed_control_type != SEQ_SPEED_MULTIPLY) { + if (v->speed_control_type == SEQ_SPEED_FRAME_NUMBER) { + curve_val = ((float)v->speed_fader_frame_number / + (float)seq_effect_speed_get_strip_content_length(seq->seq1)); + } + else if (v->speed_control_type == SEQ_SPEED_LENGTH) { + curve_val = (v->speed_fader_length / 100.0f); + } + else { + BLI_assert(v->speed_control_type == SEQ_SPEED_STRETCH); + const int target_strip_length = seq_effect_speed_get_strip_content_length(seq->seq1); + if ((seq->seq1->enddisp != seq->seq1->start) && (target_strip_length != 0)) { + curve_val = (float)target_strip_length / + (float)(seq->seq1->enddisp - seq->seq1->start); + } + } + if (curve_val < 0.0f) { + ymin = curve_val; + curve_val = 0.0f; + } + if (curve_val > 1.0f) { + ymax = curve_val; + curve_val = 1.0f; + } + + vbo = GPU_vertbuf_create_with_format(&format); + GPU_vertbuf_data_alloc(vbo, 4); + fcurve_batch_add_verts(vbo, y1, y2, y_height, eval_start, curve_val, &vert_count); + fcurve_batch_add_verts(vbo, y1, y2, y_height, eval_end, curve_val, &vert_count); + } + } + } - GPUBatch *batch = GPU_batch_create_ex(GPU_PRIM_TRI_STRIP, vbo, NULL, GPU_BATCH_OWNS_VBO); + if (vert_count > 0) { + GPUBatch *batch = GPU_batch_create(GPU_PRIM_TRI_STRIP, vbo, NULL); GPU_vertbuf_data_len_set(vbo, vert_count); GPU_batch_program_set_builtin(batch, GPU_SHADER_2D_UNIFORM_COLOR); GPU_batch_uniform_4f(batch, "color", 0.0f, 0.0f, 0.0f, 0.15f); GPU_blend(GPU_BLEND_ALPHA); - if (vert_count > 0) { - GPU_batch_draw(batch); - } + GPU_batch_draw(batch); GPU_blend(GPU_BLEND_NONE); GPU_batch_discard(batch); - - if ((v->speed_control_type == SEQ_SPEED_MULTIPLY) && (ymin > 0.0f)) { - /* Draw line at zero. */ - uint pos = GPU_vertformat_attr_add( - immVertexFormat(), "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT); - GPU_blend(GPU_BLEND_ALPHA); - immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR); - immUniformThemeColorShade(TH_CFRAME, -10); - immRectf( - pos, x1, (ymin / (ymax + ymin)) + y1, x2, (ymin / (ymax + ymin)) + y1 + (2 * pixely)); - immUnbindProgram(); - } } - else { - /* Draw the values without f-curves. */ - if (seq->type == SEQ_TYPE_SPEED) { - if (v->speed_control_type == SEQ_SPEED_FRAME_NUMBER) { - curve_val = ((float)v->speed_fader_frame_number / - (float)seq_effect_speed_get_strip_content_length(seq->seq1)); - } - else if (v->speed_control_type == SEQ_SPEED_LENGTH) { - curve_val = (v->speed_fader_length / 100); - } - else if (v->speed_control_type == SEQ_SPEED_STRETCH) { - const int target_strip_length = seq_effect_speed_get_strip_content_length(seq->seq1); - if ((seq->seq1->enddisp != seq->seq1->start) && (target_strip_length != 0)) { - curve_val = (float)target_strip_length / (float)(seq->seq1->enddisp - seq->seq1->start); - } - } - else { - curve_val = 0; - } - CLAMP(curve_val, 0.0f, 1.0f); - uint pos = GPU_vertformat_attr_add( - immVertexFormat(), "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT); - GPU_blend(GPU_BLEND_ALPHA); - immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR); - immUniformColor4ub(0, 0, 0, 51); - immRectf(pos, x1, ((y2 - y1) * curve_val) + y1, x2, y2); - immUnbindProgram(); - } + GPU_VERTBUF_DISCARD_SAFE(vbo); + + if (ymin < 0.0f) { + /* Draw line at zero. */ + float y_ratio = ratiof(ymin, ymax, 0.0f); + float y_orig = y1 + y_ratio * y_height; + + uint pos = GPU_vertformat_attr_add(immVertexFormat(), "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT); + GPU_blend(GPU_BLEND_ALPHA); + immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR); + immUniformThemeColorShade(TH_CFRAME, -10); + immRectf(pos, eval_start, y_orig, eval_end, y_orig + (2 * pixely)); + immUnbindProgram(); } } |