diff options
Diffstat (limited to 'source/blender/editors/space_clip/clip_draw.c')
-rw-r--r-- | source/blender/editors/space_clip/clip_draw.c | 1007 |
1 files changed, 624 insertions, 383 deletions
diff --git a/source/blender/editors/space_clip/clip_draw.c b/source/blender/editors/space_clip/clip_draw.c index 695d04d3850..7edd5ca45d1 100644 --- a/source/blender/editors/space_clip/clip_draw.c +++ b/source/blender/editors/space_clip/clip_draw.c @@ -55,10 +55,11 @@ #include "ED_mask.h" #include "ED_gpencil.h" -#include "BIF_gl.h" #include "BIF_glutil.h" -#include "GPU_basic_shader.h" +#include "GPU_immediate.h" +#include "GPU_immediate_util.h" +#include "GPU_matrix.h" #include "WM_types.h" @@ -66,26 +67,25 @@ #include "UI_resources.h" #include "UI_view2d.h" - #include "BLF_api.h" #include "clip_intern.h" // own include /*********************** main area drawing *************************/ -static void draw_keyframe(int frame, int cfra, int sfra, float framelen, int width) +static void draw_keyframe(int frame, int cfra, int sfra, float framelen, int width, unsigned int pos) { int height = (frame == cfra) ? 22 : 10; int x = (frame - sfra) * framelen; if (width == 1) { - glBegin(GL_LINES); - glVertex2i(x, 0); - glVertex2i(x, height * UI_DPI_FAC); - glEnd(); + immBegin(PRIM_LINES, 2); + immVertex2i(pos, x, 0); + immVertex2i(pos, x, height * UI_DPI_FAC); + immEnd(); } else { - glRecti(x, 0, x + width, height * UI_DPI_FAC); + immRecti(pos, x, 0, x + width, height * UI_DPI_FAC); } } @@ -166,6 +166,9 @@ static void draw_movieclip_cache(SpaceClip *sc, ARegion *ar, MovieClip *clip, Sc BKE_movieclip_get_cache_segments(clip, &sc->user, &totseg, &points); ED_region_cache_draw_cached_segments(ar, totseg, points, sfra, efra); + unsigned int pos = VertexFormat_add_attrib(immVertexFormat(), "pos", COMP_I32, 2, CONVERT_INT_TO_FLOAT); + immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR); + /* track */ if (act_track || act_plane_track) { for (i = sfra - clip->start_frame + 1, a = 0; i <= efra - clip->start_frame + 1; i++) { @@ -189,14 +192,17 @@ static void draw_movieclip_cache(SpaceClip *sc, ARegion *ar, MovieClip *clip, Sc if (generic_track_is_marker_enabled(act_track, act_plane_track, a)) { framenr = generic_track_get_marker_framenr(act_track, act_plane_track, a); - if (framenr != i) - glColor4ub(128, 128, 0, 96); - else if (generic_track_is_marker_keyframed(act_track, act_plane_track, a)) - glColor4ub(255, 255, 0, 196); - else - glColor4ub(255, 255, 0, 96); + if (framenr != i) { + immUniformColor4ub(128, 128, 0, 96); + } + else if (generic_track_is_marker_keyframed(act_track, act_plane_track, a)) { + immUniformColor4ub(255, 255, 0, 196); + } + else { + immUniformColor4ub(255, 255, 0, 96); + } - glRecti((i - sfra + clip->start_frame - 1) * framelen, 0, (i - sfra + clip->start_frame) * framelen, 4 * UI_DPI_FAC); + immRecti(pos, (i - sfra + clip->start_frame - 1) * framelen, 0, (i - sfra + clip->start_frame) * framelen, 4 * UI_DPI_FAC); } } } @@ -206,7 +212,7 @@ static void draw_movieclip_cache(SpaceClip *sc, ARegion *ar, MovieClip *clip, Sc int n = reconstruction->camnr; MovieReconstructedCamera *cameras = reconstruction->cameras; - glColor4ub(255, 0, 0, 96); + immUniformColor4ub(255, 0, 0, 96); for (i = sfra, a = 0; i <= efra; i++) { bool ok = false; @@ -223,8 +229,9 @@ static void draw_movieclip_cache(SpaceClip *sc, ARegion *ar, MovieClip *clip, Sc a++; } - if (!ok) - glRecti((i - sfra + clip->start_frame - 1) * framelen, 0, (i - sfra + clip->start_frame) * framelen, 8 * UI_DPI_FAC); + if (!ok) { + immRecti(pos, (i - sfra + clip->start_frame - 1) * framelen, 0, (i - sfra + clip->start_frame) * framelen, 8 * UI_DPI_FAC); + } } } @@ -233,15 +240,22 @@ static void draw_movieclip_cache(SpaceClip *sc, ARegion *ar, MovieClip *clip, Sc /* current frame */ x = (sc->user.framenr - sfra) / (efra - sfra + 1) * ar->winx; - UI_ThemeColor(TH_CFRAME); - glRecti(x, 0, x + ceilf(framelen), 8 * UI_DPI_FAC); + immUniformThemeColor(TH_CFRAME); + immRecti(pos, x, 0, x + ceilf(framelen), 8 * UI_DPI_FAC); + + immUnbindProgram(); ED_region_cache_draw_curfra_label(sc->user.framenr, x, 8.0f * UI_DPI_FAC); + pos = VertexFormat_add_attrib(immVertexFormat(), "pos", COMP_I32, 2, CONVERT_INT_TO_FLOAT); + immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR); + /* solver keyframes */ - glColor4ub(175, 255, 0, 255); - draw_keyframe(act_object->keyframe1 + clip->start_frame - 1, CFRA, sfra, framelen, 2); - draw_keyframe(act_object->keyframe2 + clip->start_frame - 1, CFRA, sfra, framelen, 2); + immUniformColor4ub(175, 255, 0, 255); + draw_keyframe(act_object->keyframe1 + clip->start_frame - 1, CFRA, sfra, framelen, 2, pos); + draw_keyframe(act_object->keyframe2 + clip->start_frame - 1, CFRA, sfra, framelen, 2, pos); + + immUnbindProgram(); /* movie clip animation */ if ((sc->mode == SC_MODE_MASKEDIT) && sc->mask_info.mask) { @@ -275,11 +289,16 @@ static void draw_movieclip_muted(ARegion *ar, int width, int height, float zoomx { int x, y; + unsigned int pos = VertexFormat_add_attrib(immVertexFormat(), "pos", COMP_F32, 2, KEEP_FLOAT); + immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR); + /* find window pixel coordinates of origin */ UI_view2d_view_to_region(&ar->v2d, 0.0f, 0.0f, &x, &y); - glColor3f(0.0f, 0.0f, 0.0f); - glRectf(x, y, x + zoomx * width, y + zoomy * height); + immUniformColor3f(0.0f, 0.0f, 0.0f); + immRectf(pos, x, y, x + zoomx * width, y + zoomy * height); + + immUnbindProgram(); } static void draw_movieclip_buffer(const bContext *C, SpaceClip *sc, ARegion *ar, ImBuf *ibuf, @@ -297,7 +316,7 @@ static void draw_movieclip_buffer(const bContext *C, SpaceClip *sc, ARegion *ar, glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - fdrawcheckerboard(x, y, x + zoomx * ibuf->x, y + zoomy * ibuf->y); + imm_draw_checker_box(x, y, x + zoomx * ibuf->x, y + zoomy * ibuf->y); } /* non-scaled proxy shouldn't use filtering */ @@ -307,13 +326,7 @@ static void draw_movieclip_buffer(const bContext *C, SpaceClip *sc, ARegion *ar, filter = GL_NEAREST; } - /* set zoom */ - glPixelZoom(zoomx * width / ibuf->x, zoomy * height / ibuf->y); - - glaDrawImBuf_glsl_ctx(C, ibuf, x, y, filter); - /* reset zoom */ - glPixelZoom(1.0f, 1.0f); - + glaDrawImBuf_glsl_ctx(C, ibuf, x, y, filter, zoomx * width / ibuf->x, zoomy * height / ibuf->y); if (sc->flag & SC_SHOW_METADATA) { rctf frame; @@ -335,31 +348,39 @@ static void draw_stabilization_border(SpaceClip *sc, ARegion *ar, int width, int /* draw boundary border for frame if stabilization is enabled */ if (sc->flag & SC_SHOW_STABLE && clip->tracking.stabilization.flag & TRACKING_2D_STABILIZATION) { - glColor3f(0.0f, 0.0f, 0.0f); - - GPU_basic_shader_bind_enable(GPU_SHADER_LINE | GPU_SHADER_STIPPLE); - GPU_basic_shader_line_stipple(3, 0xAAAA); + VertexFormat *format = immVertexFormat(); + const uint shdr_dashed_pos = VertexFormat_add_attrib(format, "pos", COMP_F32, 2, KEEP_FLOAT); + const uint shdr_dashed_origin = VertexFormat_add_attrib(format, "line_origin", COMP_F32, 2, KEEP_FLOAT); + /* Exclusive OR allows to get orig value when second operand is 0, + * and negative of orig value when second operand is 1. */ glEnable(GL_COLOR_LOGIC_OP); - glLogicOp(GL_NOR); + glLogicOp(GL_XOR); - glPushMatrix(); - glTranslatef(x, y, 0.0f); + gpuPushMatrix(); + gpuTranslate2f(x, y); - glScalef(zoomx, zoomy, 1.0f); - glMultMatrixf(sc->stabmat); + gpuScale2f(zoomx, zoomy); + gpuMultMatrix(sc->stabmat); - glBegin(GL_LINE_LOOP); - glVertex2f(0.0f, 0.0f); - glVertex2f(width, 0.0f); - glVertex2f(width, height); - glVertex2f(0.0f, height); - glEnd(); + immBindBuiltinProgram(GPU_SHADER_2D_LINE_DASHED_COLOR); - glPopMatrix(); + float viewport_size[4]; + glGetFloatv(GL_VIEWPORT, viewport_size); + immUniform2f("viewport_size", viewport_size[2] / UI_DPI_FAC, viewport_size[3] / UI_DPI_FAC); + + immUniform4f("color1", 1.0f, 1.0f, 1.0f, 0.0f); + immUniform4f("color2", 0.0f, 0.0f, 0.0f, 0.0f); + immUniform1f("dash_width", 6.0f); + immUniform1f("dash_width_on", 3.0f); + + imm_draw_line_box_dashed(shdr_dashed_pos, shdr_dashed_origin, 0.0f, 0.0f, width, height); + + immUnbindProgram(); + + gpuPopMatrix(); glDisable(GL_COLOR_LOGIC_OP); - GPU_basic_shader_bind_disable(GPU_SHADER_LINE | GPU_SHADER_STIPPLE); } } @@ -423,69 +444,113 @@ static void draw_track_path(SpaceClip *sc, MovieClip *UNUSED(clip), MovieTrackin i++; } + unsigned int pos = VertexFormat_add_attrib(immVertexFormat(), "pos", COMP_F32, 2, KEEP_FLOAT); + + immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR); + if (!tiny) { - UI_ThemeColor(TH_MARKER_OUTLINE); + immUniformThemeColor(TH_MARKER_OUTLINE); if (TRACK_VIEW_SELECTED(sc, track)) { - glPointSize(5.0f); - glBegin(GL_POINTS); - for (i = a; i < b; i++) { - if (i != curindex) - glVertex2f(path[i][0], path[i][1]); + if ((b - a - 1) >= 1) { + glPointSize(5.0f); + + immBegin(PRIM_POINTS, b - a - 1); + + for (i = a; i < b; i++) { + if (i != curindex) { + immVertex2f(pos, path[i][0], path[i][1]); + } + } + + immEnd(); } - glEnd(); } - glLineWidth(3.0f); - glBegin(GL_LINE_STRIP); - for (i = a; i < b; i++) - glVertex2f(path[i][0], path[i][1]); - glEnd(); - } + if ((b - a) >= 2) { + glLineWidth(3.0f); - UI_ThemeColor(TH_PATH_BEFORE); + immBegin(PRIM_LINE_STRIP, b - a); + + for (i = a; i < b; i++) { + immVertex2f(pos, path[i][0], path[i][1]); + } + + immEnd(); + } + } if (TRACK_VIEW_SELECTED(sc, track)) { glPointSize(3.0f); - glBegin(GL_POINTS); - for (i = a; i < b; i++) { - if (i == count + 1) - UI_ThemeColor(TH_PATH_AFTER); - if (i != curindex) - glVertex2f(path[i][0], path[i][1]); + if ((curindex - a) >= 1) { + immUniformThemeColor(TH_PATH_BEFORE); + + immBegin(PRIM_POINTS, curindex - a); + + for (i = a; i < curindex; i++) { + immVertex2f(pos, path[i][0], path[i][1]); + } + + immEnd(); } - glEnd(); - } - UI_ThemeColor(TH_PATH_BEFORE); + if ((b - curindex - 1) >= 1) { + immUniformThemeColor(TH_PATH_AFTER); + + immBegin(PRIM_POINTS, b - curindex - 1); + + for (i = curindex + 1; i < b; i++) { + immVertex2f(pos, path[i][0], path[i][1]); + } + + immEnd(); + } + } glLineWidth(1); - glBegin(GL_LINE_STRIP); - for (i = a; i < b; i++) { - if (i == count + 1) - UI_ThemeColor(TH_PATH_AFTER); + if ((curindex - a + 1) >= 2) { + immUniformThemeColor(TH_PATH_BEFORE); + + immBegin(PRIM_LINE_STRIP, curindex - a + 1); - glVertex2f(path[i][0], path[i][1]); + for (i = a; i <= curindex; i++) { + immVertex2f(pos, path[i][0], path[i][1]); + } + + immEnd(); } - glEnd(); + + if ((b - curindex) >= 2) { + immUniformThemeColor(TH_PATH_AFTER); + + immBegin(PRIM_LINE_STRIP, b - curindex); + + for (i = curindex; i < b; i++) { + immVertex2f(pos, path[i][0], path[i][1]); + } + + immEnd(); + } + + immUnbindProgram(); } static void draw_marker_outline(SpaceClip *sc, MovieTrackingTrack *track, MovieTrackingMarker *marker, - const float marker_pos[2], int width, int height) + const float marker_pos[2], int width, int height, unsigned int position) { int tiny = sc->flag & SC_SHOW_TINY_MARKER; bool show_search = false; float px[2]; - UI_ThemeColor(TH_MARKER_OUTLINE); - px[0] = 1.0f / width / sc->zoom; px[1] = 1.0f / height / sc->zoom; glLineWidth(tiny ? 1.0f : 3.0f); + immUniformThemeColor(TH_MARKER_OUTLINE); + if ((marker->flag & MARKER_DISABLED) == 0) { float pos[2]; float p[2]; @@ -500,51 +565,54 @@ static void draw_marker_outline(SpaceClip *sc, MovieTrackingTrack *track, MovieT marker->pattern_corners[2], marker->pattern_corners[3])) { glPointSize(tiny ? 3.0f : 4.0f); - glBegin(GL_POINTS); - glVertex2f(pos[0], pos[1]); - glEnd(); + + immBegin(PRIM_POINTS, 1); + immVertex2f(position, pos[0], pos[1]); + immEnd(); } else { - glBegin(GL_LINES); - glVertex2f(pos[0] + px[0] * 2, pos[1]); - glVertex2f(pos[0] + px[0] * 8, pos[1]); + immBegin(PRIM_LINES, 8); + + immVertex2f(position, pos[0] + px[0] * 2, pos[1]); + immVertex2f(position, pos[0] + px[0] * 8, pos[1]); - glVertex2f(pos[0] - px[0] * 2, pos[1]); - glVertex2f(pos[0] - px[0] * 8, pos[1]); + immVertex2f(position, pos[0] - px[0] * 2, pos[1]); + immVertex2f(position, pos[0] - px[0] * 8, pos[1]); - glVertex2f(pos[0], pos[1] - px[1] * 2); - glVertex2f(pos[0], pos[1] - px[1] * 8); + immVertex2f(position, pos[0], pos[1] - px[1] * 2); + immVertex2f(position, pos[0], pos[1] - px[1] * 8); - glVertex2f(pos[0], pos[1] + px[1] * 2); - glVertex2f(pos[0], pos[1] + px[1] * 8); - glEnd(); + immVertex2f(position, pos[0], pos[1] + px[1] * 2); + immVertex2f(position, pos[0], pos[1] + px[1] * 8); + + immEnd(); } } /* pattern and search outline */ - glPushMatrix(); - glTranslate2fv(marker_pos); + gpuPushMatrix(); + gpuTranslate2fv(marker_pos); if (sc->flag & SC_SHOW_MARKER_PATTERN) { - glBegin(GL_LINE_LOOP); - glVertex2fv(marker->pattern_corners[0]); - glVertex2fv(marker->pattern_corners[1]); - glVertex2fv(marker->pattern_corners[2]); - glVertex2fv(marker->pattern_corners[3]); - glEnd(); + immBegin(PRIM_LINE_LOOP, 4); + immVertex2fv(position, marker->pattern_corners[0]); + immVertex2fv(position, marker->pattern_corners[1]); + immVertex2fv(position, marker->pattern_corners[2]); + immVertex2fv(position, marker->pattern_corners[3]); + immEnd(); } show_search = (TRACK_VIEW_SELECTED(sc, track) && ((marker->flag & MARKER_DISABLED) == 0 || (sc->flag & SC_SHOW_MARKER_PATTERN) == 0)) != 0; + if (sc->flag & SC_SHOW_MARKER_SEARCH && show_search) { - glBegin(GL_LINE_LOOP); - glVertex2f(marker->search_min[0], marker->search_min[1]); - glVertex2f(marker->search_max[0], marker->search_min[1]); - glVertex2f(marker->search_max[0], marker->search_max[1]); - glVertex2f(marker->search_min[0], marker->search_max[1]); - glEnd(); - } - glPopMatrix(); + imm_draw_line_box(position, marker->search_min[0], + marker->search_min[1], + marker->search_max[0], + marker->search_max[1]); + } + + gpuPopMatrix(); } static void track_colors(MovieTrackingTrack *track, int act, float col[3], float scol[3]) @@ -568,11 +636,16 @@ static void track_colors(MovieTrackingTrack *track, int act, float col[3], float } static void draw_marker_areas(SpaceClip *sc, MovieTrackingTrack *track, MovieTrackingMarker *marker, - const float marker_pos[2], int width, int height, int act, int sel) + const float marker_pos[2], int width, int height, int act, int sel, const uint shdr_pos) { int tiny = sc->flag & SC_SHOW_TINY_MARKER; bool show_search = false; - float col[3], scol[3], px[2]; + float *curr_col, other_col[3], col[3], scol[3]; + float px[2]; + bool is_dashed_shader = false; + + /* Vertex attributes ids for dashed shader... */ + uint shdr_dashed_pos, shdr_dashed_origin; track_colors(track, act, col, scol); @@ -586,19 +659,21 @@ static void draw_marker_areas(SpaceClip *sc, MovieTrackingTrack *track, MovieTra float pos[2], p[2]; if (track->flag & TRACK_LOCKED) { - if (act) - UI_ThemeColor(TH_ACT_MARKER); - else if (track->flag & SELECT) - UI_ThemeColorShade(TH_LOCK_MARKER, 64); - else - UI_ThemeColor(TH_LOCK_MARKER); + if (act) { + UI_GetThemeColor3fv(TH_ACT_MARKER, other_col); + } + else if (track->flag & SELECT) { + UI_GetThemeColorShade3fv(TH_LOCK_MARKER, 64, other_col); + } + else { + UI_GetThemeColor3fv(TH_LOCK_MARKER, other_col); + } + curr_col = other_col; } else { - if (track->flag & SELECT) - glColor3fv(scol); - else - glColor3fv(col); + curr_col = (track->flag & SELECT) ? scol : col; } + immUniformColor3fv(curr_col); add_v2_v2v2(pos, marker->pos, track->offset); ED_clip_point_undistorted_pos(sc, pos, pos); @@ -609,123 +684,183 @@ static void draw_marker_areas(SpaceClip *sc, MovieTrackingTrack *track, MovieTra marker->pattern_corners[2], marker->pattern_corners[3])) { glPointSize(tiny ? 1.0f : 2.0f); - glBegin(GL_POINTS); - glVertex2f(pos[0], pos[1]); - glEnd(); + + immBegin(PRIM_POINTS, 1); + immVertex2f(shdr_pos, pos[0], pos[1]); + immEnd(); } else { - glBegin(GL_LINES); - glVertex2f(pos[0] + px[0] * 3, pos[1]); - glVertex2f(pos[0] + px[0] * 7, pos[1]); + immBegin(PRIM_LINES, 8); + + immVertex2f(shdr_pos, pos[0] + px[0] * 3, pos[1]); + immVertex2f(shdr_pos, pos[0] + px[0] * 7, pos[1]); + + immVertex2f(shdr_pos, pos[0] - px[0] * 3, pos[1]); + immVertex2f(shdr_pos, pos[0] - px[0] * 7, pos[1]); + + immVertex2f(shdr_pos, pos[0], pos[1] - px[1] * 3); + immVertex2f(shdr_pos, pos[0], pos[1] - px[1] * 7); + + immVertex2f(shdr_pos, pos[0], pos[1] + px[1] * 3); + immVertex2f(shdr_pos, pos[0], pos[1] + px[1] * 7); + + immEnd(); - glVertex2f(pos[0] - px[0] * 3, pos[1]); - glVertex2f(pos[0] - px[0] * 7, pos[1]); + immUnbindProgram(); - glVertex2f(pos[0], pos[1] - px[1] * 3); - glVertex2f(pos[0], pos[1] - px[1] * 7); + is_dashed_shader = true; + VertexFormat *format = immVertexFormat(); + shdr_dashed_pos = VertexFormat_add_attrib(format, "pos", COMP_F32, 2, KEEP_FLOAT); + shdr_dashed_origin = VertexFormat_add_attrib(format, "line_origin", COMP_F32, 2, KEEP_FLOAT); - glVertex2f(pos[0], pos[1] + px[1] * 3); - glVertex2f(pos[0], pos[1] + px[1] * 7); - glEnd(); + immBindBuiltinProgram(GPU_SHADER_2D_LINE_DASHED_COLOR); + + float viewport_size[4]; + glGetFloatv(GL_VIEWPORT, viewport_size); + immUniform2f("viewport_size", viewport_size[2] / UI_DPI_FAC, viewport_size[3] / UI_DPI_FAC); + + immUniform4f("color1", 1.0f, 1.0f, 1.0f, 0.0f); + immUniform4f("color2", 0.0f, 0.0f, 0.0f, 0.0f); + immUniform1f("dash_width", 6.0f); + immUniform1f("dash_width_on", 3.0f); - glColor3f(0.0f, 0.0f, 0.0f); - GPU_basic_shader_bind_enable(GPU_SHADER_LINE | GPU_SHADER_STIPPLE); - GPU_basic_shader_line_stipple(3, 0xAAAA); glEnable(GL_COLOR_LOGIC_OP); - glLogicOp(GL_NOR); + glLogicOp(GL_XOR); - glBegin(GL_LINES); - glVertex2fv(pos); - glVertex2fv(marker_pos); - glEnd(); + immBegin(PRIM_LINES, 2); + immAttrib2fv(shdr_dashed_origin, pos); + immVertex2fv(shdr_dashed_pos, pos); + immVertex2fv(shdr_dashed_pos, marker_pos); + immEnd(); glDisable(GL_COLOR_LOGIC_OP); - GPU_basic_shader_bind_disable(GPU_SHADER_LINE | GPU_SHADER_STIPPLE); } } /* pattern */ - glPushMatrix(); - glTranslate2fv(marker_pos); + gpuPushMatrix(); + gpuTranslate2fv(marker_pos); - if (tiny) { - GPU_basic_shader_bind_enable(GPU_SHADER_LINE | GPU_SHADER_STIPPLE); - GPU_basic_shader_line_stipple(3, 0xAAAA); - } - else { - GPU_basic_shader_bind_enable(GPU_SHADER_LINE); + if (track->flag & TRACK_LOCKED) { + if (act) { + UI_GetThemeColor3fv(TH_ACT_MARKER, other_col); + } + else if (track->pat_flag & SELECT) { + UI_GetThemeColorShade3fv(TH_LOCK_MARKER, 64, other_col); + } + else { + UI_GetThemeColor3fv(TH_LOCK_MARKER, other_col); + } + curr_col = other_col; } - - if ((track->pat_flag & SELECT) == sel && (sc->flag & SC_SHOW_MARKER_PATTERN)) { - if (track->flag & TRACK_LOCKED) { - if (act) - UI_ThemeColor(TH_ACT_MARKER); - else if (track->pat_flag & SELECT) - UI_ThemeColorShade(TH_LOCK_MARKER, 64); - else UI_ThemeColor(TH_LOCK_MARKER); + else if (marker->flag & MARKER_DISABLED) { + if (act) { + UI_GetThemeColor3fv(TH_ACT_MARKER, other_col); } - else if (marker->flag & MARKER_DISABLED) { - if (act) - UI_ThemeColor(TH_ACT_MARKER); - else if (track->pat_flag & SELECT) - UI_ThemeColorShade(TH_DIS_MARKER, 128); - else UI_ThemeColor(TH_DIS_MARKER); + else if (track->pat_flag & SELECT) { + UI_GetThemeColorShade3fv(TH_DIS_MARKER, 128, other_col); } else { - if (track->pat_flag & SELECT) - glColor3fv(scol); - else glColor3fv(col); + UI_GetThemeColor3fv(TH_DIS_MARKER, other_col); } - - glBegin(GL_LINE_LOOP); - glVertex2fv(marker->pattern_corners[0]); - glVertex2fv(marker->pattern_corners[1]); - glVertex2fv(marker->pattern_corners[2]); - glVertex2fv(marker->pattern_corners[3]); - glEnd(); + curr_col = other_col; + } + else { + curr_col = (track->pat_flag & SELECT) ? scol : col; } - /* search */ - show_search = (TRACK_VIEW_SELECTED(sc, track) && - ((marker->flag & MARKER_DISABLED) == 0 || (sc->flag & SC_SHOW_MARKER_PATTERN) == 0)) != 0; - if ((track->search_flag & SELECT) == sel && (sc->flag & SC_SHOW_MARKER_SEARCH) && show_search) { - if (track->flag & TRACK_LOCKED) { - if (act) - UI_ThemeColor(TH_ACT_MARKER); - else if (track->search_flag & SELECT) - UI_ThemeColorShade(TH_LOCK_MARKER, 64); - else UI_ThemeColor(TH_LOCK_MARKER); + if (tiny) { + if (!is_dashed_shader) { + immUnbindProgram(); + + is_dashed_shader = true; + VertexFormat *format = immVertexFormat(); + shdr_dashed_pos = VertexFormat_add_attrib(format, "pos", COMP_F32, 2, KEEP_FLOAT); + shdr_dashed_origin = VertexFormat_add_attrib(format, "line_origin", COMP_F32, 2, KEEP_FLOAT); + + immBindBuiltinProgram(GPU_SHADER_2D_LINE_DASHED_COLOR); } - else if (marker->flag & MARKER_DISABLED) { - if (act) - UI_ThemeColor(TH_ACT_MARKER); - else if (track->search_flag & SELECT) - UI_ThemeColorShade(TH_DIS_MARKER, 128); - else UI_ThemeColor(TH_DIS_MARKER); + + glEnable(GL_BLEND); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + + float viewport_size[4]; + glGetFloatv(GL_VIEWPORT, viewport_size); + immUniform2f("viewport_size", viewport_size[2] / UI_DPI_FAC, viewport_size[3] / UI_DPI_FAC); + + immUniform4f("color1", curr_col[0], curr_col[1], curr_col[2], 1.0f); + immUniform4f("color2", 0.0f, 0.0f, 0.0f, 0.0f); + immUniform1f("dash_width", 6.0f); + immUniform1f("dash_width_on", 3.0f); + + if ((track->pat_flag & SELECT) == sel && (sc->flag & SC_SHOW_MARKER_PATTERN)) { + immBegin(PRIM_LINES, 8); + immAttrib2fv(shdr_dashed_origin, marker->pattern_corners[0]); + immVertex2fv(shdr_dashed_pos, marker->pattern_corners[0]); + immVertex2fv(shdr_dashed_pos, marker->pattern_corners[1]); + + immAttrib2fv(shdr_dashed_origin, marker->pattern_corners[1]); + immVertex2fv(shdr_dashed_pos, marker->pattern_corners[1]); + immVertex2fv(shdr_dashed_pos, marker->pattern_corners[2]); + + immAttrib2fv(shdr_dashed_origin, marker->pattern_corners[3]); + immVertex2fv(shdr_dashed_pos, marker->pattern_corners[2]); + immVertex2fv(shdr_dashed_pos, marker->pattern_corners[3]); + + immAttrib2fv(shdr_dashed_origin, marker->pattern_corners[0]); + immVertex2fv(shdr_dashed_pos, marker->pattern_corners[3]); + immVertex2fv(shdr_dashed_pos, marker->pattern_corners[0]); + immEnd(); } - else { - if (track->search_flag & SELECT) - glColor3fv(scol); - else - glColor3fv(col); + + /* search */ + show_search = (TRACK_VIEW_SELECTED(sc, track) && + ((marker->flag & MARKER_DISABLED) == 0 || (sc->flag & SC_SHOW_MARKER_PATTERN) == 0)) != 0; + + if ((track->search_flag & SELECT) == sel && (sc->flag & SC_SHOW_MARKER_SEARCH) && show_search) { + imm_draw_line_box_dashed(shdr_dashed_pos, shdr_dashed_origin, marker->search_min[0], marker->search_min[1], + marker->search_max[0], marker->search_max[1]); } - glBegin(GL_LINE_LOOP); - glVertex2f(marker->search_min[0], marker->search_min[1]); - glVertex2f(marker->search_max[0], marker->search_min[1]); - glVertex2f(marker->search_max[0], marker->search_max[1]); - glVertex2f(marker->search_min[0], marker->search_max[1]); - glEnd(); + glDisable(GL_BLEND); } - if (tiny) { - GPU_basic_shader_bind_disable(GPU_SHADER_LINE | GPU_SHADER_STIPPLE); + if (is_dashed_shader) { + immUnbindProgram(); + + uint pos = VertexFormat_add_attrib(immVertexFormat(), "pos", COMP_F32, 2, KEEP_FLOAT); + BLI_assert(pos == shdr_pos); + UNUSED_VARS_NDEBUG(pos); + + immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR); + is_dashed_shader = false; } - else { - GPU_basic_shader_bind_disable(GPU_SHADER_LINE); + + if (!tiny) { + immUniformColor3fv(curr_col); + + if ((track->pat_flag & SELECT) == sel && (sc->flag & SC_SHOW_MARKER_PATTERN)) { + immBegin(PRIM_LINE_LOOP, 4); + immVertex2fv(shdr_pos, marker->pattern_corners[0]); + immVertex2fv(shdr_pos, marker->pattern_corners[1]); + immVertex2fv(shdr_pos, marker->pattern_corners[2]); + immVertex2fv(shdr_pos, marker->pattern_corners[3]); + immEnd(); + } + + /* search */ + show_search = (TRACK_VIEW_SELECTED(sc, track) && + ((marker->flag & MARKER_DISABLED) == 0 || (sc->flag & SC_SHOW_MARKER_PATTERN) == 0)) != 0; + + if ((track->search_flag & SELECT) == sel && (sc->flag & SC_SHOW_MARKER_SEARCH) && show_search) { + imm_draw_line_box(shdr_pos, marker->search_min[0], + marker->search_min[1], + marker->search_max[0], + marker->search_max[1]); + } } - glPopMatrix(); + gpuPopMatrix(); } static float get_shortest_pattern_side(MovieTrackingMarker *marker) @@ -746,7 +881,7 @@ static float get_shortest_pattern_side(MovieTrackingMarker *marker) return sqrtf(len_sq); } -static void draw_marker_slide_square(float x, float y, float dx, float dy, int outline, float px[2]) +static void draw_marker_slide_square(float x, float y, float dx, float dy, int outline, float px[2], unsigned int pos) { float tdx, tdy; @@ -758,15 +893,10 @@ static void draw_marker_slide_square(float x, float y, float dx, float dy, int o tdy += px[1]; } - glBegin(GL_QUADS); - glVertex3f(x - tdx, y + tdy, 0.0f); - glVertex3f(x + tdx, y + tdy, 0.0f); - glVertex3f(x + tdx, y - tdy, 0.0f); - glVertex3f(x - tdx, y - tdy, 0.0f); - glEnd(); + immRectf(pos, x - tdx, y - tdy, x + tdx, y + tdy); } -static void draw_marker_slide_triangle(float x, float y, float dx, float dy, int outline, float px[2]) +static void draw_marker_slide_triangle(float x, float y, float dx, float dy, int outline, float px[2], unsigned int pos) { float tdx, tdy; @@ -778,15 +908,16 @@ static void draw_marker_slide_triangle(float x, float y, float dx, float dy, int tdy += px[1]; } - glBegin(GL_TRIANGLES); - glVertex3f(x, y, 0.0f); - glVertex3f(x - tdx, y, 0.0f); - glVertex3f(x, y + tdy, 0.0f); - glEnd(); + immBegin(PRIM_TRIANGLES, 3); + immVertex2f(pos, x, y); + immVertex2f(pos, x - tdx, y); + immVertex2f(pos, x, y + tdy); + immEnd(); } static void draw_marker_slide_zones(SpaceClip *sc, MovieTrackingTrack *track, MovieTrackingMarker *marker, - const float marker_pos[2], int outline, int sel, int act, int width, int height) + const float marker_pos[2], int outline, int sel, int act, + int width, int height, unsigned int pos) { float dx, dy, patdx, patdy, searchdx, searchdy; int tiny = sc->flag & SC_SHOW_TINY_MARKER; @@ -801,11 +932,11 @@ static void draw_marker_slide_zones(SpaceClip *sc, MovieTrackingTrack *track, Mo track_colors(track, act, col, scol); if (outline) { - UI_ThemeColor(TH_MARKER_OUTLINE); + immUniformThemeColor(TH_MARKER_OUTLINE); } - glPushMatrix(); - glTranslate2fv(marker_pos); + gpuPushMatrix(); + gpuTranslate2fv(marker_pos); dx = 6.0f / width / sc->zoom; dy = 6.0f / height / sc->zoom; @@ -822,17 +953,14 @@ static void draw_marker_slide_zones(SpaceClip *sc, MovieTrackingTrack *track, Mo if ((sc->flag & SC_SHOW_MARKER_SEARCH) && ((track->search_flag & SELECT) == sel || outline)) { if (!outline) { - if (track->search_flag & SELECT) - glColor3fv(scol); - else - glColor3fv(col); + immUniformColor3fv((track->search_flag & SELECT) ? scol : col); } /* search offset square */ - draw_marker_slide_square(marker->search_min[0], marker->search_max[1], searchdx, searchdy, outline, px); + draw_marker_slide_square(marker->search_min[0], marker->search_max[1], searchdx, searchdy, outline, px, pos); /* search re-sizing triangle */ - draw_marker_slide_triangle(marker->search_max[0], marker->search_min[1], searchdx, searchdy, outline, px); + draw_marker_slide_triangle(marker->search_max[0], marker->search_min[1], searchdx, searchdy, outline, px, pos); } if ((sc->flag & SC_SHOW_MARKER_PATTERN) && ((track->pat_flag & SELECT) == sel || outline)) { @@ -842,16 +970,13 @@ static void draw_marker_slide_zones(SpaceClip *sc, MovieTrackingTrack *track, Mo float tilt_ctrl[2]; if (!outline) { - if (track->pat_flag & SELECT) - glColor3fv(scol); - else - glColor3fv(col); + immUniformColor3fv((track->pat_flag & SELECT) ? scol : col); } /* pattern's corners sliding squares */ for (i = 0; i < 4; i++) { draw_marker_slide_square(marker->pattern_corners[i][0], marker->pattern_corners[i][1], - patdx / 1.5f, patdy / 1.5f, outline, px); + patdx / 1.5f, patdy / 1.5f, outline, px, pos); } /* ** sliders to control overall pattern ** */ @@ -861,18 +986,16 @@ static void draw_marker_slide_zones(SpaceClip *sc, MovieTrackingTrack *track, Mo glLineWidth(outline ? 3.0f : 1.0f); - glBegin(GL_LINES); - glVertex2f(0.0f, 0.0f); - glVertex2fv(tilt_ctrl); - glEnd(); - - GPU_basic_shader_bind_disable(GPU_SHADER_LINE | GPU_SHADER_STIPPLE); + immBegin(PRIM_LINES, 2); + immVertex2f(pos, 0.0f, 0.0f); + immVertex2fv(pos, tilt_ctrl); + immEnd(); /* slider to control pattern tilt */ - draw_marker_slide_square(tilt_ctrl[0], tilt_ctrl[1], patdx, patdy, outline, px); + draw_marker_slide_square(tilt_ctrl[0], tilt_ctrl[1], patdx, patdy, outline, px, pos); } - glPopMatrix(); + gpuPopMatrix(); } static void draw_marker_texts(SpaceClip *sc, MovieTrackingTrack *track, MovieTrackingMarker *marker, @@ -890,16 +1013,17 @@ static void draw_marker_texts(SpaceClip *sc, MovieTrackingTrack *track, MovieTra fontsize = BLF_height_max(fontid); if (marker->flag & MARKER_DISABLED) { - if (act) - UI_ThemeColor(TH_ACT_MARKER); - else - UI_ThemeColorShade(TH_DIS_MARKER, 128); + if (act) { + UI_FontThemeColor(fontid, TH_ACT_MARKER); + } + else { + unsigned char color[4]; + UI_GetThemeColorShade4ubv(TH_DIS_MARKER, 128, color); + BLF_color4ubv(fontid, color); + } } else { - if (act) - UI_ThemeColor(TH_ACT_MARKER); - else - UI_ThemeColor(TH_SEL_MARKER); + UI_FontThemeColor(fontid, act ? TH_ACT_MARKER : TH_SEL_MARKER); } if ((sc->flag & SC_SHOW_MARKER_SEARCH) && @@ -960,10 +1084,7 @@ static void plane_track_colors(bool is_active, float color[3], float selected_co { UI_GetThemeColor3fv(TH_MARKER, color); - if (is_active) - UI_GetThemeColor3fv(TH_ACT_MARKER, selected_color); - else - UI_GetThemeColor3fv(TH_SEL_MARKER, selected_color); + UI_GetThemeColor3fv(is_active ? TH_ACT_MARKER : TH_SEL_MARKER, selected_color); } static void getArrowEndPoint(const int width, const int height, const float zoom, @@ -1060,9 +1181,6 @@ static void draw_plane_marker_image(Scene *scene, glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); } - glColor4f(1.0, 1.0, 1.0, plane_track->image_opacity); - - GPU_basic_shader_bind(GPU_SHADER_TEXTURE_2D | GPU_SHADER_USE_COLOR); glGenTextures(1, (GLuint *)&texid); glBindTexture(GL_TEXTURE_2D, texid); @@ -1073,20 +1191,38 @@ static void draw_plane_marker_image(Scene *scene, glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, ibuf->x, ibuf->y, 0, GL_RGBA, GL_UNSIGNED_BYTE, display_buffer); - glPushMatrix(); - glMultMatrixf(gl_matrix); + gpuPushMatrix(); + gpuMultMatrix(gl_matrix); + + VertexFormat *imm_format = immVertexFormat(); + unsigned int pos = VertexFormat_add_attrib(imm_format, "pos", COMP_F32, 2, KEEP_FLOAT); + unsigned int texCoord = VertexFormat_add_attrib(imm_format, "texCoord", COMP_F32, 2, KEEP_FLOAT); + + immBindBuiltinProgram(GPU_SHADER_2D_IMAGE_COLOR); + immUniformColor4f(1.0f, 1.0f, 1.0f, plane_track->image_opacity); + immUniform1i("image", GL_TEXTURE0); + + immBegin(PRIM_TRIANGLE_FAN, 4); + + immAttrib2f(texCoord, 0.0f, 0.0f); + immVertex2f(pos, 0.0f, 0.0f); + + immAttrib2f(texCoord, 1.0f, 0.0f); + immVertex2f(pos, 1.0f, 0.0f); + + immAttrib2f(texCoord, 1.0f, 1.0f); + immVertex2f(pos, 1.0f, 1.0f); + + immAttrib2f(texCoord, 0.0f, 1.0f); + immVertex2f(pos, 0.0f, 1.0f); - glBegin(GL_QUADS); - glTexCoord2f(0.0f, 0.0f); glVertex2f(0.0f, 0.0f); - glTexCoord2f(1.0f, 0.0f); glVertex2f(1.0f, 0.0f); - glTexCoord2f(1.0f, 1.0f); glVertex2f(1.0f, 1.0f); - glTexCoord2f(0.0f, 1.0f); glVertex2f(0.0f, 1.0f); - glEnd(); + immEnd(); - glPopMatrix(); + immUnbindProgram(); + + gpuPopMatrix(); glBindTexture(GL_TEXTURE_2D, 0); - GPU_basic_shader_bind(GPU_SHADER_USE_COLOR); if (transparent) { glDisable(GL_BLEND); @@ -1109,20 +1245,7 @@ static void draw_plane_marker_ex(SpaceClip *sc, Scene *scene, MovieTrackingPlane BKE_image_has_ibuf(plane_track->image, NULL); const bool draw_plane_quad = !has_image || plane_track->image_opacity == 0.0f; float px[2]; - - if (draw_outline) { - UI_ThemeColor(TH_MARKER_OUTLINE); - } - else { - float color[3], selected_color[3]; - plane_track_colors(is_active_track, color, selected_color); - if (is_selected_track) { - glColor3fv(selected_color); - } - else { - glColor3fv(color); - } - } + float *curr_color, other_color[3], color[3], selected_color[3]; px[0] = 1.0f / width / sc->zoom; px[1] = 1.0f / height / sc->zoom; @@ -1132,66 +1255,162 @@ static void draw_plane_marker_ex(SpaceClip *sc, Scene *scene, MovieTrackingPlane draw_plane_marker_image(scene, plane_track, plane_marker); } - if (draw_plane_quad) { + if (draw_plane_quad || is_selected_track) { + uint shdr_pos; + bool is_uniform_shader_defined = false; - const bool stipple = !draw_outline && tiny; - const bool thick = draw_outline && !tiny; + if (draw_plane_quad) { + const bool stipple = !draw_outline && tiny; + const bool thick = draw_outline && !tiny; - if (stipple) { - GPU_basic_shader_bind_enable(GPU_SHADER_LINE | GPU_SHADER_STIPPLE); - GPU_basic_shader_line_stipple(3, 0xAAAA); - } - else { - GPU_basic_shader_bind_enable(GPU_SHADER_LINE); - } + glLineWidth(thick ? 3.0f : 1.0f); - GPU_basic_shader_line_width(thick ? 3.0f : 1.0f); + if (draw_outline) { + UI_GetThemeColor3fv(TH_MARKER_OUTLINE, other_color); + curr_color = other_color; + } + else { + plane_track_colors(is_active_track, color, selected_color); + curr_color = is_selected_track ? selected_color : color; + } - /* Draw rectangle itself. */ - glBegin(GL_LINE_LOOP); - glVertex2fv(plane_marker->corners[0]); - glVertex2fv(plane_marker->corners[1]); - glVertex2fv(plane_marker->corners[2]); - glVertex2fv(plane_marker->corners[3]); - glEnd(); + if (stipple) { + glEnable(GL_BLEND); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - /* Draw axis. */ - if (!draw_outline) { - float end_point[2]; - glPushAttrib(GL_COLOR_BUFFER_BIT | GL_CURRENT_BIT); + VertexFormat *format = immVertexFormat(); + uint shdr_dashed_pos = VertexFormat_add_attrib(format, "pos", COMP_F32, 2, KEEP_FLOAT); + uint shdr_dashed_origin = VertexFormat_add_attrib(format, "line_origin", COMP_F32, 2, KEEP_FLOAT); - glBegin(GL_LINES); + immBindBuiltinProgram(GPU_SHADER_2D_LINE_DASHED_COLOR); - getArrowEndPoint(width, height, sc->zoom, plane_marker->corners[0], plane_marker->corners[1], end_point); - glColor3f(1.0, 0.0, 0.0f); - glVertex2fv(plane_marker->corners[0]); - glVertex2fv(end_point); + float viewport_size[4]; + glGetFloatv(GL_VIEWPORT, viewport_size); + immUniform2f("viewport_size", viewport_size[2] / UI_DPI_FAC, viewport_size[3] / UI_DPI_FAC); - getArrowEndPoint(width, height, sc->zoom, plane_marker->corners[0], plane_marker->corners[3], end_point); - glColor3f(0.0, 1.0, 0.0f); - glVertex2fv(plane_marker->corners[0]); - glVertex2fv(end_point); + immUniform4f("color1", curr_color[0], curr_color[1], curr_color[2], 1.0f); + immUniform4f("color2", 0.0f, 0.0f, 0.0f, 0.0f); + immUniform1f("dash_width", 6.0f); + immUniform1f("dash_width_on", 3.0f); - glEnd(); + /* Draw rectangle itself. */ + immBegin(PRIM_LINES, 8); + immAttrib2fv(shdr_dashed_origin, plane_marker->corners[0]); + immVertex2fv(shdr_dashed_pos, plane_marker->corners[0]); + immVertex2fv(shdr_dashed_pos, plane_marker->corners[1]); - glPopAttrib(); - } + immAttrib2fv(shdr_dashed_origin, plane_marker->corners[1]); + immVertex2fv(shdr_dashed_pos, plane_marker->corners[1]); + immVertex2fv(shdr_dashed_pos, plane_marker->corners[2]); + + immAttrib2fv(shdr_dashed_origin, plane_marker->corners[3]); + immVertex2fv(shdr_dashed_pos, plane_marker->corners[2]); + immVertex2fv(shdr_dashed_pos, plane_marker->corners[3]); + + immAttrib2fv(shdr_dashed_origin, plane_marker->corners[0]); + immVertex2fv(shdr_dashed_pos, plane_marker->corners[3]); + immVertex2fv(shdr_dashed_pos, plane_marker->corners[0]); + immEnd(); + + /* Draw axis. */ + if (!draw_outline) { + float end_point[2]; + + immUniform4f("color1", 1.0f, 0.0f, 0.0f, 1.0f); + + immBegin(PRIM_LINES, 2); - if (stipple) { - GPU_basic_shader_bind_disable(GPU_SHADER_LINE | GPU_SHADER_STIPPLE); + getArrowEndPoint(width, height, sc->zoom, plane_marker->corners[0], plane_marker->corners[1], end_point); + immAttrib2fv(shdr_dashed_origin, plane_marker->corners[0]); + immVertex2fv(shdr_dashed_pos, plane_marker->corners[0]); + immVertex2fv(shdr_dashed_pos, end_point); + + immEnd(); + + immUniform4f("color1", 0.0f, 1.0f, 0.0f, 1.0f); + + immBegin(PRIM_LINES, 2); + + getArrowEndPoint(width, height, sc->zoom, plane_marker->corners[0], plane_marker->corners[3], end_point); + immAttrib2fv(shdr_dashed_origin, plane_marker->corners[0]); + immVertex2fv(shdr_dashed_pos, plane_marker->corners[0]); + immVertex2fv(shdr_dashed_pos, end_point); + + immEnd(); + } + + immUnbindProgram(); + + glDisable(GL_BLEND); + } + + shdr_pos = VertexFormat_add_attrib(immVertexFormat(), "pos", COMP_F32, 2, KEEP_FLOAT); + + immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR); + is_uniform_shader_defined = true; + + immUniformColor3fv(curr_color); + + if (!stipple) { + /* Draw rectangle itself. */ + immBegin(PRIM_LINE_LOOP, 4); + immVertex2fv(shdr_pos, plane_marker->corners[0]); + immVertex2fv(shdr_pos, plane_marker->corners[1]); + immVertex2fv(shdr_pos, plane_marker->corners[2]); + immVertex2fv(shdr_pos, plane_marker->corners[3]); + immEnd(); + + /* Draw axis. */ + if (!draw_outline) { + float end_point[2]; + + immUniformColor3f(1.0f, 0.0f, 0.0f); + + immBegin(PRIM_LINES, 2); + + getArrowEndPoint(width, height, sc->zoom, plane_marker->corners[0], plane_marker->corners[1], end_point); + immVertex2fv(shdr_pos, plane_marker->corners[0]); + immVertex2fv(shdr_pos, end_point); + + immEnd(); + + immUniformColor3f(0.0f, 1.0f, 0.0f); + + immBegin(PRIM_LINES, 2); + + getArrowEndPoint(width, height, sc->zoom, plane_marker->corners[0], plane_marker->corners[3], end_point); + immVertex2fv(shdr_pos, plane_marker->corners[0]); + immVertex2fv(shdr_pos, end_point); + + immEnd(); + } + } } - else { - GPU_basic_shader_bind_disable(GPU_SHADER_LINE); + + if (!is_uniform_shader_defined) { + shdr_pos = VertexFormat_add_attrib(immVertexFormat(), "pos", COMP_F32, 2, KEEP_FLOAT); + + immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR); + is_uniform_shader_defined = true; } - } - /* Draw sliders. */ - if (is_selected_track) { - int i; - for (i = 0; i < 4; i++) { - draw_marker_slide_square(plane_marker->corners[i][0], plane_marker->corners[i][1], - 3.0f * px[0], 3.0f * px[1], draw_outline, px); + /* Draw sliders. */ + if (is_selected_track) { + if (draw_outline) { + immUniformThemeColor(TH_MARKER_OUTLINE); + } + else { + immUniformColor3fv(selected_color); + } + + int i; + for (i = 0; i < 4; i++) { + draw_marker_slide_square(plane_marker->corners[i][0], plane_marker->corners[i][1], + 3.0f * px[0], 3.0f * px[1], draw_outline, px, shdr_pos); + } } + + immUnbindProgram(); } } @@ -1243,13 +1462,13 @@ static void draw_tracking_tracks(SpaceClip *sc, Scene *scene, ARegion *ar, Movie UI_view2d_view_to_region_fl(&ar->v2d, 0.0f, 0.0f, &x, &y); - glPushMatrix(); - glTranslatef(x, y, 0); + gpuPushMatrix(); + gpuTranslate2f(x, y); - glPushMatrix(); - glScalef(zoomx, zoomy, 0); - glMultMatrixf(sc->stabmat); - glScalef(width, height, 0); + gpuPushMatrix(); + gpuScale2f(zoomx, zoomy); + gpuMultMatrix(sc->stabmat); + gpuScale2f(width, height); act_track = BKE_tracking_track_get_active(tracking); @@ -1315,6 +1534,10 @@ static void draw_tracking_tracks(SpaceClip *sc, Scene *scene, ARegion *ar, Movie } } + unsigned int position = VertexFormat_add_attrib(immVertexFormat(), "pos", COMP_F32, 2, KEEP_FLOAT); + + immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR); + /* markers outline and non-selected areas */ track = tracksbase->first; fp = marker_pos; @@ -1325,10 +1548,10 @@ static void draw_tracking_tracks(SpaceClip *sc, Scene *scene, ARegion *ar, Movie if (MARKER_VISIBLE(sc, track, marker)) { copy_v2_v2(cur_pos, fp ? fp : marker->pos); - draw_marker_outline(sc, track, marker, cur_pos, width, height); - draw_marker_areas(sc, track, marker, cur_pos, width, height, 0, 0); - draw_marker_slide_zones(sc, track, marker, cur_pos, 1, 0, 0, width, height); - draw_marker_slide_zones(sc, track, marker, cur_pos, 0, 0, 0, width, height); + draw_marker_outline(sc, track, marker, cur_pos, width, height, position); + draw_marker_areas(sc, track, marker, cur_pos, width, height, 0, 0, position); + draw_marker_slide_zones(sc, track, marker, cur_pos, 1, 0, 0, width, height, position); + draw_marker_slide_zones(sc, track, marker, cur_pos, 0, 0, 0, width, height, position); if (fp) fp += 2; @@ -1351,8 +1574,8 @@ static void draw_tracking_tracks(SpaceClip *sc, Scene *scene, ARegion *ar, Movie if (!act) { copy_v2_v2(cur_pos, fp ? fp : marker->pos); - draw_marker_areas(sc, track, marker, cur_pos, width, height, 0, 1); - draw_marker_slide_zones(sc, track, marker, cur_pos, 0, 1, 0, width, height); + draw_marker_areas(sc, track, marker, cur_pos, width, height, 0, 1, position); + draw_marker_slide_zones(sc, track, marker, cur_pos, 0, 1, 0, width, height, position); } if (fp) @@ -1371,8 +1594,8 @@ static void draw_tracking_tracks(SpaceClip *sc, Scene *scene, ARegion *ar, Movie if (MARKER_VISIBLE(sc, act_track, marker)) { copy_v2_v2(cur_pos, active_pos ? active_pos : marker->pos); - draw_marker_areas(sc, act_track, marker, cur_pos, width, height, 1, 1); - draw_marker_slide_zones(sc, act_track, marker, cur_pos, 0, 1, 1, width, height); + draw_marker_areas(sc, act_track, marker, cur_pos, width, height, 1, 1, position); + draw_marker_slide_zones(sc, act_track, marker, cur_pos, 0, 1, 1, width, height, position); } } } @@ -1381,7 +1604,6 @@ static void draw_tracking_tracks(SpaceClip *sc, Scene *scene, ARegion *ar, Movie MovieTrackingObject *object = BKE_tracking_object_get_active(tracking); float pos[4], vec[4], mat[4][4], aspy; - glEnable(GL_POINT_SMOOTH); glPointSize(3.0f); aspy = 1.0f / clip->tracking.camera.pixel_aspect; @@ -1410,28 +1632,34 @@ static void draw_tracking_tracks(SpaceClip *sc, Scene *scene, ARegion *ar, Movie sub_v2_v2(vec, npos); - if (len_squared_v2(vec) < (3.0f * 3.0f)) - glColor3f(0.0f, 1.0f, 0.0f); - else - glColor3f(1.0f, 0.0f, 0.0f); + if (len_squared_v2(vec) < (3.0f * 3.0f)) { + immUniformColor3f(0.0f, 1.0f, 0.0f); + } + else { + immUniformColor3f(1.0f, 0.0f, 0.0f); + } - glBegin(GL_POINTS); - if (undistort) - glVertex3f(pos[0] / width, pos[1] / (height * aspy), 0); - else - glVertex3f(npos[0] / width, npos[1] / (height * aspy), 0); - glEnd(); + immBegin(PRIM_POINTS, 1); + + if (undistort) { + immVertex2f(position, pos[0] / width, pos[1] / (height * aspy)); + } + else { + immVertex2f(position, npos[0] / width, npos[1] / (height * aspy)); + } + + immEnd(); } } } track = track->next; } - - glDisable(GL_POINT_SMOOTH); } - glPopMatrix(); + immUnbindProgram(); + + gpuPopMatrix(); if (sc->flag & SC_SHOW_NAMES) { /* scaling should be cleared before drawing texts, otherwise font would also be scaled */ @@ -1457,7 +1685,7 @@ static void draw_tracking_tracks(SpaceClip *sc, Scene *scene, ARegion *ar, Movie } } - glPopMatrix(); + gpuPopMatrix(); if (marker_pos) MEM_freeN(marker_pos); @@ -1484,11 +1712,15 @@ static void draw_distortion(SpaceClip *sc, ARegion *ar, MovieClip *clip, UI_view2d_view_to_region_fl(&ar->v2d, 0.0f, 0.0f, &x, &y); - glPushMatrix(); - glTranslatef(x, y, 0); - glScalef(zoomx, zoomy, 0); - glMultMatrixf(sc->stabmat); - glScalef(width, height, 0); + gpuPushMatrix(); + gpuTranslate2f(x, y); + gpuScale2f(zoomx, zoomy); + gpuMultMatrix(sc->stabmat); + gpuScale2f(width, height); + + unsigned int position = VertexFormat_add_attrib(immVertexFormat(), "pos", COMP_F32, 2, KEEP_FLOAT); + + immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR); /* grid */ if (sc->flag & SC_SHOW_GRID) { @@ -1560,22 +1792,26 @@ static void draw_distortion(SpaceClip *sc, ARegion *ar, MovieClip *clip, pos[1] += dy; } - glColor3f(1.0f, 0.0f, 0.0f); + immUniformColor3f(1.0f, 0.0f, 0.0f); for (i = 0; i <= n; i++) { - glBegin(GL_LINE_STRIP); + immBegin(PRIM_LINE_STRIP, n + 1); + for (j = 0; j <= n; j++) { - glVertex2fv(grid[i][j]); + immVertex2fv(position, grid[i][j]); } - glEnd(); + + immEnd(); } for (j = 0; j <= n; j++) { - glBegin(GL_LINE_STRIP); + immBegin(PRIM_LINE_STRIP, n + 1); + for (i = 0; i <= n; i++) { - glVertex2fv(grid[i][j]); + immVertex2fv(position, grid[i][j]); } - glEnd(); + + immEnd(); } } @@ -1594,7 +1830,8 @@ static void draw_distortion(SpaceClip *sc, ARegion *ar, MovieClip *clip, continue; } - glColor4fv(layer->color); + immUniformColor4fv(layer->color); + glLineWidth(layer->thickness); glPointSize((float)(layer->thickness + 2)); @@ -1604,7 +1841,6 @@ static void draw_distortion(SpaceClip *sc, ARegion *ar, MovieClip *clip, while (stroke) { if (stroke->flag & GP_STROKE_2DSPACE) { if (stroke->totpoints > 1) { - glBegin(GL_LINE_STRIP); for (i = 0; i < stroke->totpoints - 1; i++) { float npos[2], dpos[2], len; int steps; @@ -1627,19 +1863,22 @@ static void draw_distortion(SpaceClip *sc, ARegion *ar, MovieClip *clip, sub_v2_v2v2(dpos, npos, pos); mul_v2_fl(dpos, 1.0f / steps); + immBegin(PRIM_LINE_STRIP, steps + 1); + for (j = 0; j <= steps; j++) { BKE_tracking_distort_v2(tracking, pos, tpos); - glVertex2f(tpos[0] / width, tpos[1] / (height * aspy)); + immVertex2f(position, tpos[0] / width, tpos[1] / (height * aspy)); add_v2_v2(pos, dpos); } + + immEnd(); } - glEnd(); } else if (stroke->totpoints == 1) { - glBegin(GL_POINTS); - glVertex2f(stroke->points[0].x + offsx, stroke->points[0].y + offsy); - glEnd(); + immBegin(PRIM_POINTS, 1); + immVertex2f(position, stroke->points[0].x + offsx, stroke->points[0].y + offsy); + immEnd(); } } @@ -1653,7 +1892,9 @@ static void draw_distortion(SpaceClip *sc, ARegion *ar, MovieClip *clip, } } - glPopMatrix(); + immUnbindProgram(); + + gpuPopMatrix(); } void clip_draw_main(const bContext *C, SpaceClip *sc, ARegion *ar) @@ -1750,8 +1991,8 @@ void clip_draw_grease_pencil(bContext *C, int onlyv2d) * associated with the clip is already drawn in draw_distortion */ if ((sc->flag & SC_MANUAL_CALIBRATION) == 0 || is_track_source) { - glPushMatrix(); - glMultMatrixf(sc->unistabmat); + gpuPushMatrix(); + gpuMultMatrix(sc->unistabmat); if (is_track_source) { MovieTrackingTrack *track = BKE_tracking_track_get_active(&sc->clip->tracking); @@ -1760,13 +2001,13 @@ void clip_draw_grease_pencil(bContext *C, int onlyv2d) int framenr = ED_space_clip_get_clip_frame_number(sc); MovieTrackingMarker *marker = BKE_tracking_marker_get(track, framenr); - glTranslate2fv(marker->pos); + gpuTranslate2fv(marker->pos); } } ED_gpencil_draw_2dimage(C); - glPopMatrix(); + gpuPopMatrix(); } } else { |