diff options
author | Mike Erwin <significant.bit@gmail.com> | 2017-02-11 08:24:59 +0300 |
---|---|---|
committer | Mike Erwin <significant.bit@gmail.com> | 2017-02-11 08:24:59 +0300 |
commit | bbc31e89292d918f5d1a69ad6b43a68adb8a509d (patch) | |
tree | 2b159d966f1ff52eb5ffcc5f1cdf62e2c2c1fd43 /source/blender/editors/space_clip/clip_dopesheet_draw.c | |
parent | a161d45cfb6de45c5227f4bfc5161f5567c25e6c (diff) |
OpenGL: draw keyframe markers as point sprites
Also some conversion to new imm mode (T49043).
Multiple editors affected.
We could push this even further & draw all keyframes in an editor with a single draw call.
Something is strange with keyframe markers in blender2.8 -- they're not showing up before or after this commit. They do appear in master. This commit probably needs some follow-up work after keyframes are showing again. Better to share this code now instead of sitting on it.
Diffstat (limited to 'source/blender/editors/space_clip/clip_dopesheet_draw.c')
-rw-r--r-- | source/blender/editors/space_clip/clip_dopesheet_draw.c | 245 |
1 files changed, 133 insertions, 112 deletions
diff --git a/source/blender/editors/space_clip/clip_dopesheet_draw.c b/source/blender/editors/space_clip/clip_dopesheet_draw.c index 9fda063f194..c381a58ba16 100644 --- a/source/blender/editors/space_clip/clip_dopesheet_draw.c +++ b/source/blender/editors/space_clip/clip_dopesheet_draw.c @@ -74,71 +74,25 @@ static void track_channel_color(MovieTrackingTrack *track, float default_color[3 } } -static void draw_keyframe_shape(float x, float y, float xscale, float yscale, bool sel, float alpha) +static void draw_keyframe_shape(float x, float y, bool sel, float alpha, + unsigned int pos_id, unsigned int color_id) { - /* coordinates for diamond shape */ - static const float _unit_diamond_shape[4][2] = { - {0.0f, 1.0f}, /* top vert */ - {1.0f, 0.0f}, /* mid-right */ - {0.0f, -1.0f}, /* bottom vert */ - {-1.0f, 0.0f} /* mid-left */ - }; - - int hsize = STRIP_HEIGHT_HALF; - - VertexFormat *format = immVertexFormat(); - unsigned pos = add_attrib(format, "pos", GL_FLOAT, 2, KEEP_FLOAT); - - glPushMatrix(); - - /* adjust view transform before starting */ - glTranslatef(x, y, 0.0f); - glScalef(1.0f / xscale * hsize, 1.0f / yscale * hsize, 1.0f); - - /* anti-aliased lines for more consistent appearance */ - glEnable(GL_LINE_SMOOTH); - - immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR); - /* interior */ - if (sel) - immUniformThemeColorShadeAlpha(TH_STRIP_SELECT, 50, -255 * (1.0f - alpha)); - else - immUniformColor4f(0.91f, 0.91f, 0.91f, alpha); - - immBegin(GL_QUADS, 4); - immVertex2fv(pos, _unit_diamond_shape[0]); - immVertex2fv(pos, _unit_diamond_shape[1]); - immVertex2fv(pos, _unit_diamond_shape[2]); - immVertex2fv(pos, _unit_diamond_shape[3]); - immEnd(); - - /* exterior - black frame */ - immUniformColor4f(0.0f, 0.0f, 0.0f, alpha); - immBegin(GL_LINE_LOOP, 4); - immVertex2fv(pos, _unit_diamond_shape[0]); - immVertex2fv(pos, _unit_diamond_shape[1]); - immVertex2fv(pos, _unit_diamond_shape[2]); - immVertex2fv(pos, _unit_diamond_shape[3]); - immEnd(); - immUnbindProgram(); - - glDisable(GL_LINE_SMOOTH); + float color[4] = { 0.91f, 0.91f, 0.91f, alpha }; + if (sel) { + UI_GetThemeColorShadeAlpha4fv(TH_STRIP_SELECT, 50, -255 * (1.0f - alpha), color); + } - /* restore view transform */ - glPopMatrix(); + immAttrib4fv(color_id, color); + immVertex2f(pos_id, x, y); } -static void clip_draw_dopesheet_background(ARegion *ar, MovieClip *clip) +static void clip_draw_dopesheet_background(ARegion *ar, MovieClip *clip, unsigned int pos_id) { View2D *v2d = &ar->v2d; MovieTracking *tracking = &clip->tracking; MovieTrackingDopesheet *dopesheet = &tracking->dopesheet; MovieTrackingDopesheetCoverageSegment *coverage_segment; - VertexFormat *format = immVertexFormat(); - unsigned pos = add_attrib(format, "pos", GL_FLOAT, 2, KEEP_FLOAT); - - immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR); for (coverage_segment = dopesheet->coverage_segments.first; coverage_segment; coverage_segment = coverage_segment->next) @@ -150,13 +104,13 @@ static void clip_draw_dopesheet_background(ARegion *ar, MovieClip *clip) if (coverage_segment->coverage == TRACKING_COVERAGE_BAD) { immUniformColor4f(1.0f, 0.0f, 0.0f, 0.07f); } - else + else { immUniformColor4f(1.0f, 1.0f, 0.0f, 0.07f); + } - immRectf(pos, start_frame, v2d->cur.ymin, end_frame, v2d->cur.ymax); + immRectf(pos_id, start_frame, v2d->cur.ymin, end_frame, v2d->cur.ymax); } } - immUnbindProgram(); } void clip_draw_dopesheet_main(SpaceClip *sc, ARegion *ar, Scene *scene) @@ -171,21 +125,21 @@ void clip_draw_dopesheet_main(SpaceClip *sc, ARegion *ar, Scene *scene) MovieTracking *tracking = &clip->tracking; MovieTrackingDopesheet *dopesheet = &tracking->dopesheet; MovieTrackingDopesheetChannel *channel; - float y, xscale, yscale; float strip[4], selected_strip[4]; float height = (dopesheet->tot_channel * CHANNEL_STEP) + (CHANNEL_HEIGHT); - + + unsigned int keyframe_ct = 0; + VertexFormat *format = immVertexFormat(); - unsigned pos = add_attrib(format, "pos", GL_FLOAT, 2, KEEP_FLOAT); + unsigned int pos_id = add_attrib(format, "pos", COMP_F32, 2, KEEP_FLOAT); + immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR); /* don't use totrect set, as the width stays the same * (NOTE: this is ok here, the configuration is pretty straightforward) */ v2d->tot.ymin = (float)(-height); - y = (float) CHANNEL_FIRST; - - UI_view2d_scale_get(v2d, &xscale, &yscale); + float y = (float) CHANNEL_FIRST; /* setup colors for regular and selected strips */ UI_GetThemeColor3fv(TH_STRIP, strip); @@ -196,7 +150,7 @@ void clip_draw_dopesheet_main(SpaceClip *sc, ARegion *ar, Scene *scene) glEnable(GL_BLEND); - clip_draw_dopesheet_background(ar, clip); + clip_draw_dopesheet_background(ar, clip, pos_id); for (channel = dopesheet->channels.first; channel; channel = channel->next) { float yminc = (float) (y - CHANNEL_HEIGHT_HALF); @@ -207,7 +161,6 @@ void clip_draw_dopesheet_main(SpaceClip *sc, ARegion *ar, Scene *scene) IN_RANGE(ymaxc, v2d->cur.ymin, v2d->cur.ymax)) { MovieTrackingTrack *track = channel->track; - float alpha; int i; bool sel = (track->flag & TRACK_DOPE_SEL) != 0; @@ -217,37 +170,26 @@ void clip_draw_dopesheet_main(SpaceClip *sc, ARegion *ar, Scene *scene) float default_color[4] = {0.8f, 0.93f, 0.8f, 0.3f}; track_channel_color(track, default_color, color); - immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR); immUniformColor4fv(color); - immRectf(pos, v2d->cur.xmin, (float) y - CHANNEL_HEIGHT_HALF, - v2d->cur.xmax + EXTRA_SCROLL_PAD, (float) y + CHANNEL_HEIGHT_HALF); - immUnbindProgram(); + immRectf(pos_id, v2d->cur.xmin, (float) y - CHANNEL_HEIGHT_HALF, + v2d->cur.xmax + EXTRA_SCROLL_PAD, (float) y + CHANNEL_HEIGHT_HALF); } - alpha = (track->flag & TRACK_LOCKED) ? 0.5f : 1.0f; - /* tracked segments */ for (i = 0; i < channel->tot_segment; i++) { int start_frame = BKE_movieclip_remap_clip_to_scene_frame(clip, channel->segments[2 * i]); int end_frame = BKE_movieclip_remap_clip_to_scene_frame(clip, channel->segments[2 * i + 1]); - immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR); - if (sel) - immUniformColor4fv(selected_strip); - else - immUniformColor4fv(strip); + immUniformColor4fv(sel ? selected_strip : strip); if (start_frame != end_frame) { - immRectf(pos, start_frame, (float) y - STRIP_HEIGHT_HALF, - end_frame, (float) y + STRIP_HEIGHT_HALF); - immUnbindProgram(); - draw_keyframe_shape(start_frame, y, xscale, yscale, sel, alpha); - draw_keyframe_shape(end_frame, y, xscale, yscale, sel, alpha); + immRectf(pos_id, start_frame, (float) y - STRIP_HEIGHT_HALF, + end_frame, (float) y + STRIP_HEIGHT_HALF); + keyframe_ct += 2; } else { - immUnbindProgram(); - draw_keyframe_shape(start_frame, y, xscale, yscale, sel, alpha); + keyframe_ct++; } } @@ -257,9 +199,7 @@ void clip_draw_dopesheet_main(SpaceClip *sc, ARegion *ar, Scene *scene) MovieTrackingMarker *marker = &track->markers[i]; if ((marker->flag & (MARKER_DISABLED | MARKER_TRACKED)) == 0) { - int framenr = BKE_movieclip_remap_clip_to_scene_frame(clip, marker->framenr); - - draw_keyframe_shape(framenr, y, xscale, yscale, sel, alpha); + keyframe_ct++; } i++; @@ -270,6 +210,75 @@ void clip_draw_dopesheet_main(SpaceClip *sc, ARegion *ar, Scene *scene) y -= CHANNEL_STEP; } + immUnbindProgram(); + + if (keyframe_ct > 0) { + /* draw keyframe markers */ + format = immVertexFormat(); + pos_id = add_attrib(format, "pos", COMP_F32, 2, KEEP_FLOAT); + unsigned int size_id = add_attrib(format, "size", COMP_F32, 1, KEEP_FLOAT); + unsigned int color_id = add_attrib(format, "color", COMP_U8, 4, NORMALIZE_INT_TO_FLOAT); + unsigned int outline_color_id = add_attrib(format, "outlineColor", COMP_U8, 4, NORMALIZE_INT_TO_FLOAT); + + immBindBuiltinProgram(GPU_SHADER_KEYFRAME_DIAMOND); + + immBegin(PRIM_POINTS, keyframe_ct); + + /* all same size with black outline */ + immAttrib1f(size_id, 2.0f * STRIP_HEIGHT_HALF); + immAttrib3ub(outline_color_id, 0, 0, 0); + + y = (float) CHANNEL_FIRST; /* start again at the top */ + for (channel = dopesheet->channels.first; channel; channel = channel->next) { + float yminc = (float) (y - CHANNEL_HEIGHT_HALF); + float ymaxc = (float) (y + CHANNEL_HEIGHT_HALF); + + /* check if visible */ + if (IN_RANGE(yminc, v2d->cur.ymin, v2d->cur.ymax) || + IN_RANGE(ymaxc, v2d->cur.ymin, v2d->cur.ymax)) + { + MovieTrackingTrack *track = channel->track; + int i; + bool sel = (track->flag & TRACK_DOPE_SEL) != 0; + float alpha = (track->flag & TRACK_LOCKED) ? 0.5f : 1.0f; + + /* tracked segments */ + for (i = 0; i < channel->tot_segment; i++) { + int start_frame = BKE_movieclip_remap_clip_to_scene_frame(clip, channel->segments[2 * i]); + int end_frame = BKE_movieclip_remap_clip_to_scene_frame(clip, channel->segments[2 * i + 1]); + + if (start_frame != end_frame) { + draw_keyframe_shape(start_frame, y, sel, alpha, pos_id, color_id); + draw_keyframe_shape(end_frame, y, sel, alpha, pos_id, color_id); + } + else { + draw_keyframe_shape(start_frame, y, sel, alpha, pos_id, color_id); + } + } + + /* keyframes */ + i = 0; + while (i < track->markersnr) { + MovieTrackingMarker *marker = &track->markers[i]; + + if ((marker->flag & (MARKER_DISABLED | MARKER_TRACKED)) == 0) { + int framenr = BKE_movieclip_remap_clip_to_scene_frame(clip, marker->framenr); + + draw_keyframe_shape(framenr, y, sel, alpha, pos_id, color_id); + } + + i++; + } + } + + /* adjust y-position for next one */ + y -= CHANNEL_STEP; + } + + immEnd(); + immUnbindProgram(); + } + glDisable(GL_BLEND); } @@ -283,25 +292,15 @@ void clip_draw_dopesheet_channels(const bContext *C, ARegion *ar) SpaceClip *sc = CTX_wm_space_clip(C); View2D *v2d = &ar->v2d; MovieClip *clip = ED_space_clip_get_clip(sc); - MovieTracking *tracking; - MovieTrackingDopesheet *dopesheet; - MovieTrackingDopesheetChannel *channel; uiStyle *style = UI_style_get(); - uiBlock *block; int fontid = style->widget.uifont_id; - int height; - float y; - PropertyRNA *chan_prop_lock; - VertexFormat *format = immVertexFormat(); - unsigned pos = add_attrib(format, "pos", GL_FLOAT, 2, KEEP_FLOAT); - if (!clip) return; - tracking = &clip->tracking; - dopesheet = &tracking->dopesheet; - height = (dopesheet->tot_channel * CHANNEL_STEP) + (CHANNEL_HEIGHT); + MovieTracking *tracking = &clip->tracking; + MovieTrackingDopesheet *dopesheet = &tracking->dopesheet; + int height = (dopesheet->tot_channel * CHANNEL_STEP) + (CHANNEL_HEIGHT); if (height > BLI_rcti_size_y(&v2d->mask)) { /* don't use totrect set, as the width stays the same @@ -316,10 +315,14 @@ void clip_draw_dopesheet_channels(const bContext *C, ARegion *ar) /* loop through channels, and set up drawing depending on their type * first pass: just the standard GL-drawing for backdrop + text */ - y = (float) CHANNEL_FIRST; + float y = (float) CHANNEL_FIRST; - BLF_size(fontid, 11.0f * U.pixelsize, U.dpi); + VertexFormat *format = immVertexFormat(); + unsigned pos = add_attrib(format, "pos", GL_FLOAT, 2, KEEP_FLOAT); + immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR); + + MovieTrackingDopesheetChannel *channel; for (channel = dopesheet->channels.first; channel; channel = channel->next) { float yminc = (float) (y - CHANNEL_HEIGHT_HALF); float ymaxc = (float) (y + CHANNEL_HEIGHT_HALF); @@ -329,20 +332,38 @@ void clip_draw_dopesheet_channels(const bContext *C, ARegion *ar) IN_RANGE(ymaxc, v2d->cur.ymin, v2d->cur.ymax)) { MovieTrackingTrack *track = channel->track; - float font_height, color[3]; - bool sel = (track->flag & TRACK_DOPE_SEL) != 0; - + float color[3]; track_channel_color(track, NULL, color); - immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR); immUniformColor3fv(color); immRectf(pos, v2d->cur.xmin, (float) y - CHANNEL_HEIGHT_HALF, - v2d->cur.xmax + EXTRA_SCROLL_PAD, (float) y + CHANNEL_HEIGHT_HALF); - immUnbindProgram(); + v2d->cur.xmax + EXTRA_SCROLL_PAD, (float) y + CHANNEL_HEIGHT_HALF); + } + + /* adjust y-position for next one */ + y -= CHANNEL_STEP; + } + immUnbindProgram(); + + /* second pass: text */ + y = (float) CHANNEL_FIRST; + + BLF_size(fontid, 11.0f * U.pixelsize, U.dpi); + + for (channel = dopesheet->channels.first; channel; channel = channel->next) { + float yminc = (float) (y - CHANNEL_HEIGHT_HALF); + float ymaxc = (float) (y + CHANNEL_HEIGHT_HALF); + + /* check if visible */ + if (IN_RANGE(yminc, v2d->cur.ymin, v2d->cur.ymax) || + IN_RANGE(ymaxc, v2d->cur.ymin, v2d->cur.ymax)) + { + MovieTrackingTrack *track = channel->track; + bool sel = (track->flag & TRACK_DOPE_SEL) != 0; UI_FontThemeColor(fontid, sel ? TH_TEXT_HI : TH_TEXT); - font_height = BLF_height(fontid, channel->name, sizeof(channel->name)); + float font_height = BLF_height(fontid, channel->name, sizeof(channel->name)); BLF_position(fontid, v2d->cur.xmin + CHANNEL_PAD, y - font_height / 2.0f, 0.0f); BLF_draw(fontid, channel->name, strlen(channel->name)); @@ -352,12 +373,12 @@ void clip_draw_dopesheet_channels(const bContext *C, ARegion *ar) y -= CHANNEL_STEP; } - /* second pass: widgets */ - block = UI_block_begin(C, ar, __func__, UI_EMBOSS); + /* third pass: widgets */ + uiBlock *block = UI_block_begin(C, ar, __func__, UI_EMBOSS); y = (float) CHANNEL_FIRST; /* get RNA properties (once) */ - chan_prop_lock = RNA_struct_type_find_property(&RNA_MovieTrackingTrack, "lock"); + PropertyRNA *chan_prop_lock = RNA_struct_type_find_property(&RNA_MovieTrackingTrack, "lock"); BLI_assert(chan_prop_lock); glEnable(GL_BLEND); |