diff options
Diffstat (limited to 'source/blender/editors')
17 files changed, 338 insertions, 698 deletions
diff --git a/source/blender/editors/animation/anim_markers.c b/source/blender/editors/animation/anim_markers.c index dcf52404a88..4566f0d9837 100644 --- a/source/blender/editors/animation/anim_markers.c +++ b/source/blender/editors/animation/anim_markers.c @@ -353,7 +353,6 @@ static void draw_marker( { VertexFormat *format = immVertexFormat(); uint pos = VertexFormat_add_attrib(format, "pos", COMP_F32, 2, KEEP_FLOAT); - uint line_origin = VertexFormat_add_attrib(format, "line_origin", COMP_F32, 2, KEEP_FLOAT); immBindBuiltinProgram(GPU_SHADER_2D_LINE_DASHED_COLOR); @@ -362,17 +361,15 @@ static void draw_marker( immUniform2f("viewport_size", viewport_size[2] / UI_DPI_FAC, viewport_size[3] / UI_DPI_FAC); if (marker->flag & SELECT) { - immUniform4f("color1", 1.0f, 1.0f, 1.0f, 0.38f); + immUniformColor4f(1.0f, 1.0f, 1.0f, 0.38f); } else { - immUniform4f("color1", 0.0f, 0.0f, 0.0f, 0.38f); + immUniformColor4f(0.0f, 0.0f, 0.0f, 0.38f); } - immUniform4f("color2", 0.0f, 0.0f, 0.0f, 0.0f); immUniform1f("dash_width", 6.0f); - immUniform1f("dash_width_on", 3.0f); + immUniform1f("dash_factor", 0.5f); immBegin(PRIM_LINES, 2); - immAttrib2f(line_origin, xpos + 0.5f, 12.0f); immVertex2f(pos, xpos + 0.5f, 12.0f); immVertex2f(pos, xpos + 0.5f, (v2d->cur.ymax + 12.0f) * yscale); immEnd(); diff --git a/source/blender/editors/gpencil/gpencil_paint.c b/source/blender/editors/gpencil/gpencil_paint.c index b4092a73df8..6659510c6cc 100644 --- a/source/blender/editors/gpencil/gpencil_paint.c +++ b/source/blender/editors/gpencil/gpencil_paint.c @@ -1862,25 +1862,21 @@ static void gpencil_draw_eraser(bContext *UNUSED(C), int x, int y, void *p_ptr) immUnbindProgram(); - 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); - immBindBuiltinProgram(GPU_SHADER_2D_LINE_DASHED_COLOR); float viewport_size[4]; glGetFloatv(GL_VIEWPORT, viewport_size); immUniform2f("viewport_size", viewport_size[2], viewport_size[3]); - immUniform4f("color1", 1.0f, 0.39f, 0.39f, 0.78f); - immUniform4f("color2", 0.0f, 0.0f, 0.0f, 0.0f); + immUniformColor4f(1.0f, 0.39f, 0.39f, 0.78f); + immUniform1i("num_colors", 0); /* "simple" mode */ immUniform1f("dash_width", 12.0f); - immUniform1f("dash_width_on", 6.0f); + immUniform1f("dash_factor", 0.5f); - imm_draw_circle_wire_dashed(shdr_dashed_pos, shdr_dashed_origin, x, y, p->radius, - /* XXX Dashed shader gives bad results with sets of small segments currently, - * temp hack around the issue. :( */ - max_ii(8, p->radius / 2)); /* was fixed 40 */ + imm_draw_circle_wire(shdr_pos, x, y, p->radius, + /* XXX Dashed shader gives bad results with sets of small segments currently, + * temp hack around the issue. :( */ + max_ii(8, p->radius / 2)); /* was fixed 40 */ immUnbindProgram(); diff --git a/source/blender/editors/include/UI_interface.h b/source/blender/editors/include/UI_interface.h index 3293b061e76..904067839e2 100644 --- a/source/blender/editors/include/UI_interface.h +++ b/source/blender/editors/include/UI_interface.h @@ -323,8 +323,7 @@ void UI_draw_roundbox_shade_y(bool filled, float minx, float miny, float maxx, f void UI_draw_box_shadow(unsigned char alpha, float minx, float miny, float maxx, float maxy); void UI_draw_text_underline(int pos_x, int pos_y, int len, int height, const float color[4]); -void UI_draw_safe_areas( - uint pos, uint line_origin, float x1, float x2, float y1, float y2, +void UI_draw_safe_areas(uint pos, float x1, float x2, float y1, float y2, const float title_aspect[2], const float action_aspect[2]); /* state for scrolldrawing */ diff --git a/source/blender/editors/interface/interface_draw.c b/source/blender/editors/interface/interface_draw.c index bf821c082f2..3553b5f4d4b 100644 --- a/source/blender/editors/interface/interface_draw.c +++ b/source/blender/editors/interface/interface_draw.c @@ -585,7 +585,7 @@ void ui_draw_but_IMAGE(ARegion *UNUSED(ar), uiBut *but, uiWidgetColors *UNUSED(w * The next 4 parameters are the offsets for the view, not the zones. */ void UI_draw_safe_areas( - uint pos, uint line_origin, float x1, float x2, float y1, float y2, + uint pos, float x1, float x2, float y1, float y2, const float title_aspect[2], const float action_aspect[2]) { const float size_x_half = (x2 - x1) * 0.5f; @@ -604,7 +604,7 @@ void UI_draw_safe_areas( float maxx = x2 - margin_x; float maxy = y2 - margin_y; - imm_draw_line_box_dashed(pos, line_origin, minx, miny, maxx, maxy); + imm_draw_line_box(pos, minx, miny, maxx, maxy); } } } @@ -1223,33 +1223,23 @@ static void ui_draw_colorband_handle( if (active || half_width < min_width) { immUnbindProgram(); - 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); - 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", 0.8f, 0.8f, 0.8f, 1.0f); - immUniform4f("color2", 0.0f, 0.0f, 0.0f, 0.0f); + immUniform1i("num_colors", 2); /* "advanced" mode */ + immUniformArray4fv("colors", (float *)(float[][4]){{0.8f, 0.8f, 0.8f, 1.0f}, {0.0f, 0.0f, 0.0f, 1.0f}}, 2); immUniform1f("dash_width", active ? 4.0f : 2.0f); - immUniform1f("dash_width_on", active ? 2.0f : 1.0f); immBegin(PRIM_LINES, 2); - immAttrib2f(shdr_dashed_origin, x, y1); - immVertex2f(shdr_dashed_pos, x, y1); - immVertex2f(shdr_dashed_pos, x, y2); + immVertex2f(shdr_pos, x, y1); + immVertex2f(shdr_pos, x, y2); immEnd(); immUnbindProgram(); - const 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); /* hide handles when zoomed out too far */ diff --git a/source/blender/editors/sculpt_paint/paint_stroke.c b/source/blender/editors/sculpt_paint/paint_stroke.c index b6c4febe607..e53cf05bb15 100644 --- a/source/blender/editors/sculpt_paint/paint_stroke.c +++ b/source/blender/editors/sculpt_paint/paint_stroke.c @@ -169,9 +169,7 @@ static void paint_draw_line_cursor(bContext *C, int x, int y, void *customdata) glEnable(GL_LINE_SMOOTH); - VertexFormat *format = immVertexFormat(); - unsigned int pos = VertexFormat_add_attrib(format, "pos", COMP_F32, 2, KEEP_FLOAT); - unsigned int line_origin = VertexFormat_add_attrib(format, "line_origin", COMP_F32, 2, KEEP_FLOAT); + uint shdr_pos = VertexFormat_add_attrib(immVertexFormat(), "pos", COMP_F32, 2, KEEP_FLOAT); immBindBuiltinProgram(GPU_SHADER_2D_LINE_DASHED_COLOR); @@ -179,23 +177,20 @@ static void paint_draw_line_cursor(bContext *C, int x, int y, void *customdata) glGetFloatv(GL_VIEWPORT, viewport_size); immUniform2f("viewport_size", viewport_size[2], viewport_size[3]); + immUniform1i("num_colors", 2); /* "advanced" mode */ const float alpha = (float)paint->paint_cursor_col[3] / 255.0f; - immUniform4f("color1", 0.0f, 0.0f, 0.0f, alpha); - immUniform4f("color2", 1.0f, 1.0f, 1.0f, alpha); + immUniformArray4fv("colors", (float *)(float[][4]){{0.0f, 0.0f, 0.0f, alpha}, {1.0f, 1.0f, 1.0f, alpha}}, 2); immUniform1f("dash_width", 6.0f); - immUniform1f("dash_width_on", 3.0f); immBegin(PRIM_LINES, 2); if (stroke->constrain_line) { - immAttrib2f(line_origin, stroke->last_mouse_position[0], stroke->last_mouse_position[1]); - immVertex2f(pos, stroke->last_mouse_position[0], stroke->last_mouse_position[1]); - immVertex2f(pos, stroke->constrained_pos[0], stroke->constrained_pos[1]); + immVertex2f(shdr_pos, stroke->last_mouse_position[0], stroke->last_mouse_position[1]); + immVertex2f(shdr_pos, stroke->constrained_pos[0], stroke->constrained_pos[1]); } else { - immAttrib2f(line_origin, stroke->last_mouse_position[0], stroke->last_mouse_position[1]); - immVertex2f(pos, stroke->last_mouse_position[0], stroke->last_mouse_position[1]); - immVertex2f(pos, x, y); + immVertex2f(shdr_pos, stroke->last_mouse_position[0], stroke->last_mouse_position[1]); + immVertex2f(shdr_pos, x, y); } immEnd(); diff --git a/source/blender/editors/space_clip/clip_draw.c b/source/blender/editors/space_clip/clip_draw.c index 7edd5ca45d1..0108e23af02 100644 --- a/source/blender/editors/space_clip/clip_draw.c +++ b/source/blender/editors/space_clip/clip_draw.c @@ -348,9 +348,7 @@ 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) { - 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); + const uint shdr_pos = VertexFormat_add_attrib(immVertexFormat(), "pos", 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. */ @@ -369,12 +367,12 @@ static void draw_stabilization_border(SpaceClip *sc, ARegion *ar, int width, int 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); + immUniform1i("num_colors", 0); /* "simple" mode */ + immUniformColor4f(1.0f, 1.0f, 1.0f, 0.0f); immUniform1f("dash_width", 6.0f); - immUniform1f("dash_width_on", 3.0f); + immUniform1f("dash_factor", 0.5f); - imm_draw_line_box_dashed(shdr_dashed_pos, shdr_dashed_origin, 0.0f, 0.0f, width, height); + imm_draw_line_box(shdr_pos, 0.0f, 0.0f, width, height); immUnbindProgram(); @@ -640,12 +638,8 @@ static void draw_marker_areas(SpaceClip *sc, MovieTrackingTrack *track, MovieTra { int tiny = sc->flag & SC_SHOW_TINY_MARKER; bool show_search = false; - float *curr_col, other_col[3], col[3], scol[3]; + float 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); @@ -654,26 +648,35 @@ static void draw_marker_areas(SpaceClip *sc, MovieTrackingTrack *track, MovieTra glLineWidth(1.0f); + /* Since we are switching solid and dashed lines in rather complex logic here, just always go with dashed shader. */ + immUnbindProgram(); + + 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); + + immUniform1i("num_colors", 0); /* "simple" mode */ + /* marker position and offset position */ if ((track->flag & SELECT) == sel && (marker->flag & MARKER_DISABLED) == 0) { float pos[2], p[2]; if (track->flag & TRACK_LOCKED) { if (act) { - UI_GetThemeColor3fv(TH_ACT_MARKER, other_col); + immUniformThemeColor(TH_ACT_MARKER); } else if (track->flag & SELECT) { - UI_GetThemeColorShade3fv(TH_LOCK_MARKER, 64, other_col); + immUniformThemeColorShade(TH_LOCK_MARKER, 64); } else { - UI_GetThemeColor3fv(TH_LOCK_MARKER, other_col); + immUniformThemeColor(TH_LOCK_MARKER); } - curr_col = other_col; } else { - curr_col = (track->flag & SELECT) ? scol : col; + immUniformColor3fv((track->flag & SELECT) ? scol : col); } - immUniformColor3fv(curr_col); add_v2_v2v2(pos, marker->pos, track->offset); ED_clip_point_undistorted_pos(sc, pos, pos); @@ -685,11 +688,15 @@ static void draw_marker_areas(SpaceClip *sc, MovieTrackingTrack *track, MovieTra { glPointSize(tiny ? 1.0f : 2.0f); + immUniform1f("dash_factor", 2.0f); /* Solid "line" */ + immBegin(PRIM_POINTS, 1); immVertex2f(shdr_pos, pos[0], pos[1]); immEnd(); } else { + immUniform1f("dash_factor", 2.0f); /* Solid line */ + immBegin(PRIM_LINES, 8); immVertex2f(shdr_pos, pos[0] + px[0] * 3, pos[1]); @@ -706,31 +713,16 @@ static void draw_marker_areas(SpaceClip *sc, MovieTrackingTrack *track, MovieTra immEnd(); - 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); - - 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); + immUniformColor4f(1.0f, 1.0f, 1.0f, 0.0f); immUniform1f("dash_width", 6.0f); - immUniform1f("dash_width_on", 3.0f); + immUniform1f("dash_factor", 0.5f); glEnable(GL_COLOR_LOGIC_OP); glLogicOp(GL_XOR); immBegin(PRIM_LINES, 2); - immAttrib2fv(shdr_dashed_origin, pos); - immVertex2fv(shdr_dashed_pos, pos); - immVertex2fv(shdr_dashed_pos, marker_pos); + immVertex2fv(shdr_pos, pos); + immVertex2fv(shdr_pos, marker_pos); immEnd(); glDisable(GL_COLOR_LOGIC_OP); @@ -743,124 +735,66 @@ static void draw_marker_areas(SpaceClip *sc, MovieTrackingTrack *track, MovieTra if (track->flag & TRACK_LOCKED) { if (act) { - UI_GetThemeColor3fv(TH_ACT_MARKER, other_col); + immUniformThemeColor(TH_ACT_MARKER); } else if (track->pat_flag & SELECT) { - UI_GetThemeColorShade3fv(TH_LOCK_MARKER, 64, other_col); + immUniformThemeColorShade(TH_LOCK_MARKER, 64); } else { - UI_GetThemeColor3fv(TH_LOCK_MARKER, other_col); + immUniformThemeColor(TH_LOCK_MARKER); } - curr_col = other_col; } else if (marker->flag & MARKER_DISABLED) { if (act) { - UI_GetThemeColor3fv(TH_ACT_MARKER, other_col); + immUniformThemeColor(TH_ACT_MARKER); } else if (track->pat_flag & SELECT) { - UI_GetThemeColorShade3fv(TH_DIS_MARKER, 128, other_col); + immUniformThemeColorShade(TH_DIS_MARKER, 128); } else { - UI_GetThemeColor3fv(TH_DIS_MARKER, other_col); + immUniformThemeColor(TH_DIS_MARKER); } - curr_col = other_col; } else { - curr_col = (track->pat_flag & SELECT) ? scol : col; + immUniformColor3fv((track->pat_flag & SELECT) ? scol : col); } 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); - } - - 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(); - } - - /* 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]); - } - - glDisable(GL_BLEND); + immUniform1f("dash_factor", 0.5f); + } + else { + immUniform1f("dash_factor", 2.0f); /* Solid line */ } - if (is_dashed_shader) { - immUnbindProgram(); + 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(); + } - uint pos = VertexFormat_add_attrib(immVertexFormat(), "pos", COMP_F32, 2, KEEP_FLOAT); - BLI_assert(pos == shdr_pos); - UNUSED_VARS_NDEBUG(pos); + /* search */ + show_search = (TRACK_VIEW_SELECTED(sc, track) && + ((marker->flag & MARKER_DISABLED) == 0 || (sc->flag & SC_SHOW_MARKER_PATTERN) == 0)) != 0; - immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR); - is_dashed_shader = false; + 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]); } - 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(); - } + gpuPopMatrix(); - /* search */ - show_search = (TRACK_VIEW_SELECTED(sc, track) && - ((marker->flag & MARKER_DISABLED) == 0 || (sc->flag & SC_SHOW_MARKER_PATTERN) == 0)) != 0; + /* Restore default shader */ + immUnbindProgram(); - 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]); - } - } + const uint pos = VertexFormat_add_attrib(immVertexFormat(), "pos", COMP_F32, 2, KEEP_FLOAT); + BLI_assert(pos == shdr_pos); + UNUSED_VARS_NDEBUG(pos); - gpuPopMatrix(); + immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR); } static float get_shortest_pattern_side(MovieTrackingMarker *marker) @@ -1245,7 +1179,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]; - float *curr_color, other_color[3], color[3], selected_color[3]; + float color[3], selected_color[3]; px[0] = 1.0f / width / sc->zoom; px[1] = 1.0f / height / sc->zoom; @@ -1256,8 +1190,15 @@ static void draw_plane_marker_ex(SpaceClip *sc, Scene *scene, MovieTrackingPlane } if (draw_plane_quad || is_selected_track) { - uint shdr_pos; - bool is_uniform_shader_defined = false; + const uint shdr_pos = VertexFormat_add_attrib(immVertexFormat(), "pos", COMP_F32, 2, KEEP_FLOAT); + + 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); + + immUniform1i("num_colors", 0); /* "simple" mode */ if (draw_plane_quad) { const bool stipple = !draw_outline && tiny; @@ -1265,137 +1206,60 @@ static void draw_plane_marker_ex(SpaceClip *sc, Scene *scene, MovieTrackingPlane glLineWidth(thick ? 3.0f : 1.0f); + if (stipple) { + immUniform1f("dash_width", 6.0f); + immUniform1f("dash_factor", 0.5f); + } + else { + immUniform1f("dash_factor", 2.0f); /* Solid line */ + } + if (draw_outline) { - UI_GetThemeColor3fv(TH_MARKER_OUTLINE, other_color); - curr_color = other_color; + immUniformThemeColor(TH_MARKER_OUTLINE); } else { plane_track_colors(is_active_track, color, selected_color); - curr_color = is_selected_track ? selected_color : color; + immUniformColor3fv(is_selected_track ? selected_color : color); } - if (stipple) { - glEnable(GL_BLEND); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - - 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); - - 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); + /* 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(); - 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); + /* Draw axis. */ + if (!draw_outline) { + float end_point[2]; - /* 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]); + immUniformColor3f(1.0f, 0.0f, 0.0f); - immAttrib2fv(shdr_dashed_origin, plane_marker->corners[1]); - immVertex2fv(shdr_dashed_pos, plane_marker->corners[1]); - immVertex2fv(shdr_dashed_pos, plane_marker->corners[2]); + immBegin(PRIM_LINES, 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]); + 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); - 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); - - 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); + immUniformColor3f(0.0f, 1.0f, 0.0f); - immEnd(); + immBegin(PRIM_LINES, 2); - 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); + 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, 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]; + immVertex2fv(shdr_pos, end_point); - 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(); - } + immEnd(); } } - 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) { + immUniform1f("dash_factor", 2.0f); /* Solid line */ + if (draw_outline) { immUniformThemeColor(TH_MARKER_OUTLINE); } diff --git a/source/blender/editors/space_image/image_draw.c b/source/blender/editors/space_image/image_draw.c index 7c888860375..259dc124d37 100644 --- a/source/blender/editors/space_image/image_draw.c +++ b/source/blender/editors/space_image/image_draw.c @@ -688,7 +688,6 @@ void draw_image_sample_line(SpaceImage *sima) VertexFormat *format = immVertexFormat(); unsigned int shdr_dashed_pos = VertexFormat_add_attrib(format, "pos", COMP_F32, 2, KEEP_FLOAT); - unsigned int shdr_dashed_origin = VertexFormat_add_attrib(format, "line_origin", COMP_F32, 2, KEEP_FLOAT); immBindBuiltinProgram(GPU_SHADER_2D_LINE_DASHED_COLOR); @@ -696,13 +695,11 @@ void draw_image_sample_line(SpaceImage *sima) 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, 1.0f); - immUniform4f("color2", 0.0f, 0.0f, 0.0f, 1.0f); + immUniform1i("num_colors", 2); /* Advanced dashes. */ + immUniformArray4fv("colors", (float *)(float[][4]){{1.0f, 1.0f, 1.0f, 1.0f}, {0.0f, 0.0f, 0.0f, 1.0f}}, 2); immUniform1f("dash_width", 2.0f); - immUniform1f("dash_width_on", 1.0f); immBegin(PRIM_LINES, 2); - immAttrib2fv(shdr_dashed_origin, hist->co[0]); immVertex2fv(shdr_dashed_pos, hist->co[0]); immVertex2fv(shdr_dashed_pos, hist->co[1]); immEnd(); diff --git a/source/blender/editors/space_nla/nla_draw.c b/source/blender/editors/space_nla/nla_draw.c index 8121bfe9dc8..623646040d8 100644 --- a/source/blender/editors/space_nla/nla_draw.c +++ b/source/blender/editors/space_nla/nla_draw.c @@ -121,6 +121,8 @@ static void nla_action_draw_keyframes(AnimData *adt, bAction *act, float y, floa VertexFormat *format = immVertexFormat(); unsigned int pos_id = VertexFormat_add_attrib(format, "pos", COMP_F32, 2, KEEP_FLOAT); + immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR); + immUniformColor4fv(color); /* - draw a rect from the first to the last frame (no extra overlaps for now) @@ -175,67 +177,37 @@ static void nla_actionclip_draw_markers(NlaStrip *strip, float yminc, float ymax if (!(act && act->markers.first)) return; - float color[4]; - UI_GetThemeColorShade4fv(TH_STRIP_SELECT, shade, color); - + const uint shdr_pos = VertexFormat_add_attrib(immVertexFormat(), "pos", COMP_F32, 2, KEEP_FLOAT); if (dashed) { - 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); - - glEnable(GL_BLEND); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - 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); - immUniform4fv("color1", color); - immUniform4f("color2", 0.0f, 0.0f, 0.0f, 0.0f); + immUniform1i("num_colors", 0); /* "simple" mode */ immUniform1f("dash_width", 6.0f); - immUniform1f("dash_width_on", 3.0f); - - immBeginAtMost(PRIM_LINES, BLI_listbase_count(&act->markers) * 2); - for (TimeMarker *marker = act->markers.first; marker; marker = marker->next) { - if ((marker->frame > strip->actstart) && (marker->frame < strip->actend)) { - float frame = nlastrip_get_frame(strip, marker->frame, NLATIME_CONVERT_MAP); - - /* just a simple line for now */ - /* XXX: draw a triangle instead... */ - immAttrib2f(shdr_dashed_origin, frame, yminc + 1); - immVertex2f(shdr_dashed_pos, frame, yminc + 1); - immVertex2f(shdr_dashed_pos, frame, ymaxc - 1); - } - } - immEnd(); - - immUnbindProgram(); - - glDisable(GL_BLEND); + immUniform1f("dash_factor", 0.5f); } else { - const uint shdr_pos = VertexFormat_add_attrib(immVertexFormat(), "pos", COMP_F32, 2, KEEP_FLOAT); immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR); + } + immUniformThemeColorShade(TH_STRIP_SELECT, shade); - immUniformColor4fv(color); - - immBeginAtMost(PRIM_LINES, BLI_listbase_count(&act->markers) * 2); - for (TimeMarker *marker = act->markers.first; marker; marker = marker->next) { - if ((marker->frame > strip->actstart) && (marker->frame < strip->actend)) { - float frame = nlastrip_get_frame(strip, marker->frame, NLATIME_CONVERT_MAP); + immBeginAtMost(PRIM_LINES, BLI_listbase_count(&act->markers) * 2); + for (TimeMarker *marker = act->markers.first; marker; marker = marker->next) { + if ((marker->frame > strip->actstart) && (marker->frame < strip->actend)) { + float frame = nlastrip_get_frame(strip, marker->frame, NLATIME_CONVERT_MAP); - /* just a simple line for now */ - /* XXX: draw a triangle instead... */ - immVertex2f(shdr_pos, frame, yminc + 1); - immVertex2f(shdr_pos, frame, ymaxc - 1); - } + /* just a simple line for now */ + /* XXX: draw a triangle instead... */ + immVertex2f(shdr_pos, frame, yminc + 1); + immVertex2f(shdr_pos, frame, ymaxc - 1); } - immEnd(); - - immUnbindProgram(); } + immEnd(); + + immUnbindProgram(); } /* Markers inside a NLA-Strip */ diff --git a/source/blender/editors/space_sequencer/sequencer_draw.c b/source/blender/editors/space_sequencer/sequencer_draw.c index 6a9437bb892..e7c7b3d67b9 100644 --- a/source/blender/editors/space_sequencer/sequencer_draw.c +++ b/source/blender/editors/space_sequencer/sequencer_draw.c @@ -1033,13 +1033,7 @@ static void sequencer_draw_borders(const SpaceSeq *sseq, const View2D *v2d, cons glLineWidth(1.0f); /* border */ - VertexFormat *format = immVertexFormat(); - unsigned int pos = VertexFormat_add_attrib(format, "pos", COMP_F32, 2, KEEP_FLOAT); - unsigned int line_origin = VertexFormat_add_attrib(format, "line_origin", COMP_F32, 2, KEEP_FLOAT); - float color1[4]; - - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - glEnable(GL_BLEND); + const uint shdr_pos = VertexFormat_add_attrib(immVertexFormat(), "pos", COMP_F32, 2, KEEP_FLOAT); immBindBuiltinProgram(GPU_SHADER_2D_LINE_DASHED_COLOR); @@ -1047,36 +1041,31 @@ static void sequencer_draw_borders(const SpaceSeq *sseq, const View2D *v2d, cons glGetFloatv(GL_VIEWPORT, viewport_size); immUniform2f("viewport_size", viewport_size[2] / UI_DPI_FAC, viewport_size[3] / UI_DPI_FAC); - UI_GetThemeColor4fv(TH_BACK, color1); - immUniform4fv("color1", color1); - immUniform4f("color2", 0.0f, 0.0f, 0.0f, 0.0f); + immUniformThemeColor(TH_BACK); + immUniform1i("num_colors", 0); /* Simple dashes. */ immUniform1f("dash_width", 6.0f); - immUniform1f("dash_width_on", 3.0f); + immUniform1f("dash_factor", 0.5f); - imm_draw_line_box_dashed(pos, line_origin, x1 - 0.5f, y1 - 0.5f, x2 + 0.5f, y2 + 0.5f); + imm_draw_line_box(shdr_pos, x1 - 0.5f, y1 - 0.5f, x2 + 0.5f, y2 + 0.5f); /* safety border */ if (sseq->flag & SEQ_SHOW_SAFE_MARGINS) { - UI_GetThemeColorBlend3f(TH_VIEW_OVERLAY, TH_BACK, 0.25f, color1); - color1[3] = 1.0f; - immUniform4fv("color1", color1); + immUniformThemeColorBlend(TH_VIEW_OVERLAY, TH_BACK, 0.25f); UI_draw_safe_areas( - pos, line_origin, x1, x2, y1, y2, + shdr_pos, x1, x2, y1, y2, scene->safe_areas.title, scene->safe_areas.action); if (sseq->flag & SEQ_SHOW_SAFE_CENTER) { UI_draw_safe_areas( - pos, line_origin, x1, x2, y1, y2, + shdr_pos, x1, x2, y1, y2, scene->safe_areas.title_center, scene->safe_areas.action_center); } } immUnbindProgram(); - - glDisable(GL_BLEND); } /* draws checkerboard background for transparent content */ diff --git a/source/blender/editors/space_text/text_draw.c b/source/blender/editors/space_text/text_draw.c index c4e6dde2a64..79607bf88cb 100644 --- a/source/blender/editors/space_text/text_draw.c +++ b/source/blender/editors/space_text/text_draw.c @@ -1501,12 +1501,7 @@ void draw_text_main(SpaceText *st, ARegion *ar) margin_column_x = x + st->cwidth * (st->margin_column - st->left); if (margin_column_x >= x) { - VertexFormat *format = immVertexFormat(); - uint shdr_dashed_pos = VertexFormat_add_attrib(format, "pos", COMP_I32, 2, CONVERT_INT_TO_FLOAT); - uint shdr_dashed_origin = VertexFormat_add_attrib(format, "line_origin", COMP_I32, 2, CONVERT_INT_TO_FLOAT); - - glEnable(GL_BLEND); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + const uint shdr_pos = VertexFormat_add_attrib(immVertexFormat(), "pos", COMP_I32, 2, CONVERT_INT_TO_FLOAT); immBindBuiltinProgram(GPU_SHADER_2D_LINE_DASHED_COLOR); @@ -1514,21 +1509,16 @@ void draw_text_main(SpaceText *st, ARegion *ar) glGetFloatv(GL_VIEWPORT, viewport_size); immUniform2f("viewport_size", viewport_size[2] / UI_DPI_FAC, viewport_size[3] / UI_DPI_FAC); - float color1[4]; - UI_GetThemeColor4fv(TH_GRID, color1); /* same color as line number background */ - immUniform4fv("color1", color1); - immUniform4f("color2", 0.0f, 0.0f, 0.0f, 0.0f); + immUniform1i("num_colors", 0); /* "simple" mode */ + immUniformThemeColor(TH_GRID); /* same color as line number background */ immUniform1f("dash_width", 2.0f); - immUniform1f("dash_width_on", 1.0f); + immUniform1f("dash_factor", 0.5f); immBegin(PRIM_LINES, 2); - immAttrib2i(shdr_dashed_origin, margin_column_x, 0); - immVertex2i(shdr_dashed_pos, margin_column_x, 0); - immVertex2i(shdr_dashed_pos, margin_column_x, ar->winy - 2); + immVertex2i(shdr_pos, margin_column_x, 0); + immVertex2i(shdr_pos, margin_column_x, ar->winy - 2); immEnd(); immUnbindProgram(); - - glDisable(GL_BLEND); } } diff --git a/source/blender/editors/space_view3d/drawarmature.c b/source/blender/editors/space_view3d/drawarmature.c index 7b553b15aa8..621c217fd89 100644 --- a/source/blender/editors/space_view3d/drawarmature.c +++ b/source/blender/editors/space_view3d/drawarmature.c @@ -1632,12 +1632,7 @@ static void pchan_draw_IK_root_lines(bPoseChannel *pchan, short only_temp) bConstraint *con; bPoseChannel *parchan; - VertexFormat *format = immVertexFormat(); - unsigned int pos = VertexFormat_add_attrib(format, "pos", COMP_F32, 3, KEEP_FLOAT); - unsigned int line_origin = VertexFormat_add_attrib(format, "line_origin", COMP_F32, 3, KEEP_FLOAT); - - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - glEnable(GL_BLEND); + const uint shdr_pos = VertexFormat_add_attrib(immVertexFormat(), "pos", COMP_F32, 3, KEEP_FLOAT); immBindBuiltinProgram(GPU_SHADER_3D_LINE_DASHED_COLOR); @@ -1645,10 +1640,10 @@ static void pchan_draw_IK_root_lines(bPoseChannel *pchan, short only_temp) glGetFloatv(GL_VIEWPORT, viewport_size); immUniform2f("viewport_size", viewport_size[2], viewport_size[3]); - immUniform4fv("color1", fcolor); - immUniform4f("color2", 0.0f, 0.0f, 0.0f, 0.0f); + immUniform1i("num_colors", 0); /* "simple" mode */ + immUniformColor4fv(fcolor); immUniform1f("dash_width", 6.0f); - immUniform1f("dash_width_on", 3.0f); + immUniform1f("dash_factor", 0.5f); for (con = pchan->constraints.first; con; con = con->next) { if (con->enforce == 0.0f) @@ -1683,9 +1678,8 @@ static void pchan_draw_IK_root_lines(bPoseChannel *pchan, short only_temp) if (parchan) { immBegin(PRIM_LINES, 2); - immAttrib3fv(line_origin, ik_tip); - immVertex3fv(pos, ik_tip); - immVertex3fv(pos, parchan->pose_head); + immVertex3fv(shdr_pos, ik_tip); + immVertex3fv(shdr_pos, parchan->pose_head); immEnd(); } @@ -1710,9 +1704,8 @@ static void pchan_draw_IK_root_lines(bPoseChannel *pchan, short only_temp) /* Only draw line in case our chain is more than one bone long! */ if (parchan != pchan) { /* XXX revise the breaking conditions to only stop at the tail? */ immBegin(PRIM_LINES, 2); - immAttrib3fv(line_origin, ik_tip); - immVertex3fv(pos, ik_tip); - immVertex3fv(pos, parchan->pose_head); + immVertex3fv(shdr_pos, ik_tip); + immVertex3fv(shdr_pos, parchan->pose_head); immEnd(); } break; @@ -1721,8 +1714,6 @@ static void pchan_draw_IK_root_lines(bPoseChannel *pchan, short only_temp) } immUnbindProgram(); - - glDisable(GL_BLEND); } static void imm_sphere_project(unsigned int pos, float ax, float az) @@ -2216,12 +2207,7 @@ static void draw_pose_bones(Scene *scene, SceneLayer *sl, View3D *v3d, ARegion * * - only if V3D_HIDE_HELPLINES is enabled... */ if ((do_dashed & DASH_HELP_LINES) && ((bone->flag & BONE_CONNECTED) == 0)) { - VertexFormat *format = immVertexFormat(); - unsigned int pos = VertexFormat_add_attrib(format, "pos", COMP_F32, 3, KEEP_FLOAT); - unsigned int line_origin = VertexFormat_add_attrib(format, "line_origin", COMP_F32, 3, KEEP_FLOAT); - - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - glEnable(GL_BLEND); + const uint shdr_pos = VertexFormat_add_attrib(immVertexFormat(), "pos", COMP_F32, 3, KEEP_FLOAT); immBindBuiltinProgram(GPU_SHADER_3D_LINE_DASHED_COLOR); @@ -2229,26 +2215,22 @@ static void draw_pose_bones(Scene *scene, SceneLayer *sl, View3D *v3d, ARegion * glGetFloatv(GL_VIEWPORT, viewport_size); immUniform2f("viewport_size", viewport_size[2], viewport_size[3]); - immUniform4fv("color1", fcolor); - immUniform4f("color2", 0.0f, 0.0f, 0.0f, 0.0f); + immUniform1i("num_colors", 0); /* "simple" mode */ + immUniformColor4fv(fcolor); immUniform1f("dash_width", 6.0f); - immUniform1f("dash_width_on", 3.0f); + immUniform1f("dash_factor", 0.5f); if (arm->flag & ARM_POSEMODE) { GPU_select_load_id(index & 0xFFFF); /* object tag, for bordersel optim */ - UI_GetThemeColor4fv(TH_WIRE, fcolor); - immUniform4fv("color1", fcolor); + immUniformThemeColor(TH_WIRE); } immBegin(PRIM_LINES, 2); - immAttrib3fv(line_origin, pchan->parent->pose_tail); - immVertex3fv(pos, pchan->parent->pose_tail); - immVertex3fv(pos, pchan->pose_head); + immVertex3fv(shdr_pos, pchan->parent->pose_tail); + immVertex3fv(shdr_pos, pchan->pose_head); immEnd(); immUnbindProgram(); - - glDisable(GL_BLEND); } /* Draw a line to IK root bone @@ -2530,12 +2512,7 @@ static void draw_ebones(View3D *v3d, ARegion *ar, Object *ob, const short dt) /* offset to parent */ if (eBone->parent) { - VertexFormat *format = immVertexFormat(); - unsigned int pos = VertexFormat_add_attrib(format, "pos", COMP_F32, 3, KEEP_FLOAT); - unsigned int line_origin = VertexFormat_add_attrib(format, "line_origin", COMP_F32, 3, KEEP_FLOAT); - - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - glEnable(GL_BLEND); + const uint shdr_pos = VertexFormat_add_attrib(immVertexFormat(), "pos", COMP_F32, 3, KEEP_FLOAT); GPU_select_load_id(-1); /* -1 here is OK! */ @@ -2545,21 +2522,17 @@ static void draw_ebones(View3D *v3d, ARegion *ar, Object *ob, const short dt) glGetFloatv(GL_VIEWPORT, viewport_size); immUniform2f("viewport_size", viewport_size[2], viewport_size[3]); - UI_GetThemeColor4fv(TH_WIRE_EDIT, fcolor); - immUniform4fv("color1", fcolor); - immUniform4f("color2", 0.0f, 0.0f, 0.0f, 0.0f); + immUniform1i("num_colors", 0); /* "simple" mode */ + immUniformThemeColor(TH_WIRE_EDIT); immUniform1f("dash_width", 6.0f); - immUniform1f("dash_width_on", 3.0f); + immUniform1f("dash_factor", 0.5f); immBegin(PRIM_LINES, 2); - immAttrib3fv(line_origin, eBone->parent->tail); - immVertex3fv(pos, eBone->parent->tail); - immVertex3fv(pos, eBone->head); + immVertex3fv(shdr_pos, eBone->parent->tail); + immVertex3fv(shdr_pos, eBone->head); immEnd(); immUnbindProgram(); - - glDisable(GL_BLEND); } } } diff --git a/source/blender/editors/space_view3d/view3d_draw.c b/source/blender/editors/space_view3d/view3d_draw.c index 62d8f771b8c..08b15957dbb 100644 --- a/source/blender/editors/space_view3d/view3d_draw.c +++ b/source/blender/editors/space_view3d/view3d_draw.c @@ -417,7 +417,7 @@ void ED_view3d_calc_camera_border( view3d_camera_border(scene, ar, v3d, rv3d, r_viewborder, no_shift, false); } -static void drawviewborder_grid3(uint pos, uint line_origin, float x1, float x2, float y1, float y2, float fac) +static void drawviewborder_grid3(uint shdr_pos, float x1, float x2, float y1, float y2, float fac) { float x3, y3, x4, y4; @@ -428,28 +428,24 @@ static void drawviewborder_grid3(uint pos, uint line_origin, float x1, float x2, immBegin(PRIM_LINES, 8); - immAttrib2f(line_origin, x1, y3); - immVertex2f(pos, x1, y3); - immVertex2f(pos, x2, y3); + immVertex2f(shdr_pos, x1, y3); + immVertex2f(shdr_pos, x2, y3); - immAttrib2f(line_origin, x1, y4); - immVertex2f(pos, x1, y4); - immVertex2f(pos, x2, y4); + immVertex2f(shdr_pos, x1, y4); + immVertex2f(shdr_pos, x2, y4); - immAttrib2f(line_origin, x3, y1); - immVertex2f(pos, x3, y1); - immVertex2f(pos, x3, y2); + immVertex2f(shdr_pos, x3, y1); + immVertex2f(shdr_pos, x3, y2); - immAttrib2f(line_origin, x4, y1); - immVertex2f(pos, x4, y1); - immVertex2f(pos, x4, y2); + immVertex2f(shdr_pos, x4, y1); + immVertex2f(shdr_pos, x4, y2); immEnd(); } /* harmonious triangle */ static void drawviewborder_triangle( - uint pos, uint line_origin, float x1, float x2, float y1, float y2, const char golden, const char dir) + uint shdr_pos, float x1, float x2, float y1, float y2, const char golden, const char dir) { float ofs; float w = x2 - x1; @@ -466,17 +462,14 @@ static void drawviewborder_triangle( } if (dir == 'B') SWAP(float, y1, y2); - immAttrib2f(line_origin, x1, y1); - immVertex2f(pos, x1, y1); - immVertex2f(pos, x2, y2); + immVertex2f(shdr_pos, x1, y1); + immVertex2f(shdr_pos, x2, y2); - immAttrib2f(line_origin, x2, y1); - immVertex2f(pos, x2, y1); - immVertex2f(pos, x1 + (w - ofs), y2); + immVertex2f(shdr_pos, x2, y1); + immVertex2f(shdr_pos, x1 + (w - ofs), y2); - immAttrib2f(line_origin, x1, y2); - immVertex2f(pos, x1, y2); - immVertex2f(pos, x1 + ofs, y1); + immVertex2f(shdr_pos, x1, y2); + immVertex2f(shdr_pos, x1 + ofs, y1); } else { if (golden) { @@ -487,17 +480,14 @@ static void drawviewborder_triangle( } if (dir == 'B') SWAP(float, x1, x2); - immAttrib2f(line_origin, x1, y1); - immVertex2f(pos, x1, y1); - immVertex2f(pos, x2, y2); + immVertex2f(shdr_pos, x1, y1); + immVertex2f(shdr_pos, x2, y2); - immAttrib2f(line_origin, x2, y1); - immVertex2f(pos, x2, y1); - immVertex2f(pos, x1, y1 + ofs); + immVertex2f(shdr_pos, x2, y1); + immVertex2f(shdr_pos, x1, y1 + ofs); - immAttrib2f(line_origin, x1, y2); - immVertex2f(pos, x1, y2); - immVertex2f(pos, x2, y1 + (h - ofs)); + immVertex2f(shdr_pos, x1, y2); + immVertex2f(shdr_pos, x2, y1 + (h - ofs)); } immEnd(); @@ -538,9 +528,10 @@ static void drawviewborder(Scene *scene, ARegion *ar, View3D *v3d) x2i = (int)(x2 + (1.0f - 0.0001f)); y2i = (int)(y2 + (1.0f - 0.0001f)); + uint shdr_pos = VertexFormat_add_attrib(immVertexFormat(), "pos", COMP_F32, 2, KEEP_FLOAT); + /* First, solid lines. */ { - unsigned int pos = VertexFormat_add_attrib(immVertexFormat(), "pos", COMP_F32, 2, KEEP_FLOAT); immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR); /* passepartout, specified in camera edit buttons */ @@ -559,24 +550,24 @@ static void drawviewborder(Scene *scene, ARegion *ar, View3D *v3d) immUniformColor4f(0.0f, 0.0f, 0.0f, alpha); if (x1i > 0.0f) - immRectf(pos, 0.0f, winy, x1i, 0.0f); + immRectf(shdr_pos, 0.0f, winy, x1i, 0.0f); if (x2i < winx) - immRectf(pos, x2i, winy, winx, 0.0f); + immRectf(shdr_pos, x2i, winy, winx, 0.0f); if (y2i < winy) - immRectf(pos, x1i, winy, x2i, y2i); + immRectf(shdr_pos, x1i, winy, x2i, y2i); if (y2i > 0.0f) - immRectf(pos, x1i, y1i, x2i, 0.0f); + immRectf(shdr_pos, x1i, y1i, x2i, 0.0f); glDisable(GL_BLEND); } immUniformThemeColor(TH_BACK); - imm_draw_line_box(pos, x1i, y1i, x2i, y2i); + imm_draw_line_box(shdr_pos, x1i, y1i, x2i, y2i); #ifdef VIEW3D_CAMERA_BORDER_HACK if (view3d_camera_border_hack_test == true) { immUniformColor3ubv(view3d_camera_border_hack_col); - imm_draw_line_box(pos, x1i + 1, y1i + 1, x2i - 1, y2i - 1); + imm_draw_line_box(shdr_pos, x1i + 1, y1i + 1, x2i - 1, y2i - 1); view3d_camera_border_hack_test = false; } #endif @@ -586,34 +577,24 @@ static void drawviewborder(Scene *scene, ARegion *ar, View3D *v3d) /* And now, the dashed lines! */ { - VertexFormat *format = immVertexFormat(); - unsigned int pos = VertexFormat_add_attrib(format, "pos", COMP_F32, 2, KEEP_FLOAT); - unsigned int line_origin = VertexFormat_add_attrib(format, "line_origin", COMP_F32, 2, KEEP_FLOAT); - float color1[4] = {1.0f, 1.0f, 1.0f, 1.0f}; - - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - glEnable(GL_BLEND); - immBindBuiltinProgram(GPU_SHADER_2D_LINE_DASHED_COLOR); float viewport_size[4]; glGetFloatv(GL_VIEWPORT, viewport_size); immUniform2f("viewport_size", viewport_size[2], viewport_size[3]); - immUniform4f("color2", 0.0f, 0.0f, 0.0f, 0.0f); + immUniform1i("num_colors", 0); /* "simple" mode */ immUniform1f("dash_width", 6.0f); - immUniform1f("dash_width_on", 3.0f); + immUniform1f("dash_factor", 0.5f); /* outer line not to confuse with object selection */ if (v3d->flag2 & V3D_LOCK_CAMERA) { - UI_GetThemeColor4fv(TH_REDALERT, color1); - immUniform4fv("color1", color1); - imm_draw_line_box_dashed(pos, line_origin, x1i - 1, y1i - 1, x2i + 1, y2i + 1); + immUniformThemeColor(TH_REDALERT); + imm_draw_line_box(shdr_pos, x1i - 1, y1i - 1, x2i + 1, y2i + 1); } - UI_GetThemeColor4fv(TH_VIEW_OVERLAY, color1); - immUniform4fv("color1", color1); - imm_draw_line_box_dashed(pos, line_origin, x1i, y1i, x2i, y2i); + immUniformThemeColor(TH_VIEW_OVERLAY); + imm_draw_line_box(shdr_pos, x1i, y1i, x2i, y2i); /* border */ if (scene->r.mode & R_BORDER) { @@ -624,15 +605,13 @@ static void drawviewborder(Scene *scene, ARegion *ar, View3D *v3d) x4 = floorf(x1 + (scene->r.border.xmax * (x2 - x1))) + (U.pixelsize - 1); y4 = floorf(y1 + (scene->r.border.ymax * (y2 - y1))) + (U.pixelsize - 1); - immUniform4f("color1", 1.0f, 0.25f, 0.25f, 1.0f); - imm_draw_line_box_dashed(pos, line_origin, x3, y3, x4, y4); + immUniformColor3f(1.0f, 0.25f, 0.25f); + imm_draw_line_box(shdr_pos, x3, y3, x4, y4); } /* safety border */ if (ca) { - UI_GetThemeColorBlend3f(TH_VIEW_OVERLAY, TH_BACK, 0.25f, color1); - color1[3] = 1.0f; - immUniform4fv("color1", color1); + immUniformThemeColorBlend(TH_VIEW_OVERLAY, TH_BACK, 0.25f); if (ca->dtx & CAM_DTX_CENTER) { float x3, y3; @@ -642,13 +621,11 @@ static void drawviewborder(Scene *scene, ARegion *ar, View3D *v3d) immBegin(PRIM_LINES, 4); - immAttrib2f(line_origin, x1, y3); - immVertex2f(pos, x1, y3); - immVertex2f(pos, x2, y3); + immVertex2f(shdr_pos, x1, y3); + immVertex2f(shdr_pos, x2, y3); - immAttrib2f(line_origin, x3, y1); - immVertex2f(pos, x3, y1); - immVertex2f(pos, x3, y2); + immVertex2f(shdr_pos, x3, y1); + immVertex2f(shdr_pos, x3, y2); immEnd(); } @@ -656,52 +633,46 @@ static void drawviewborder(Scene *scene, ARegion *ar, View3D *v3d) if (ca->dtx & CAM_DTX_CENTER_DIAG) { immBegin(PRIM_LINES, 4); - immAttrib2f(line_origin, x1, y1); - immVertex2f(pos, x1, y1); - immVertex2f(pos, x2, y2); + immVertex2f(shdr_pos, x1, y1); + immVertex2f(shdr_pos, x2, y2); - immAttrib2f(line_origin, x1, y2); - immVertex2f(pos, x1, y2); - immVertex2f(pos, x2, y1); + immVertex2f(shdr_pos, x1, y2); + immVertex2f(shdr_pos, x2, y1); immEnd(); } if (ca->dtx & CAM_DTX_THIRDS) { - drawviewborder_grid3(pos, line_origin, x1, x2, y1, y2, 1.0f / 3.0f); + drawviewborder_grid3(shdr_pos, x1, x2, y1, y2, 1.0f / 3.0f); } if (ca->dtx & CAM_DTX_GOLDEN) { - drawviewborder_grid3(pos, line_origin, x1, x2, y1, y2, 1.0f - (1.0f / 1.61803399f)); + drawviewborder_grid3(shdr_pos, x1, x2, y1, y2, 1.0f - (1.0f / 1.61803399f)); } if (ca->dtx & CAM_DTX_GOLDEN_TRI_A) { - drawviewborder_triangle(pos, line_origin, x1, x2, y1, y2, 0, 'A'); + drawviewborder_triangle(shdr_pos, x1, x2, y1, y2, 0, 'A'); } if (ca->dtx & CAM_DTX_GOLDEN_TRI_B) { - drawviewborder_triangle(pos, line_origin, x1, x2, y1, y2, 0, 'B'); + drawviewborder_triangle(shdr_pos, x1, x2, y1, y2, 0, 'B'); } if (ca->dtx & CAM_DTX_HARMONY_TRI_A) { - drawviewborder_triangle(pos, line_origin, x1, x2, y1, y2, 1, 'A'); + drawviewborder_triangle(shdr_pos, x1, x2, y1, y2, 1, 'A'); } if (ca->dtx & CAM_DTX_HARMONY_TRI_B) { - drawviewborder_triangle(pos, line_origin, x1, x2, y1, y2, 1, 'B'); + drawviewborder_triangle(shdr_pos, x1, x2, y1, y2, 1, 'B'); } if (ca->flag & CAM_SHOW_SAFE_MARGINS) { - UI_draw_safe_areas( - pos, line_origin, x1, x2, y1, y2, - scene->safe_areas.title, - scene->safe_areas.action); + UI_draw_safe_areas(shdr_pos, x1, x2, y1, y2, + scene->safe_areas.title, scene->safe_areas.action); if (ca->flag & CAM_SHOW_SAFE_CENTER) { - UI_draw_safe_areas( - pos, line_origin, x1, x2, y1, y2, - scene->safe_areas.title_center, - scene->safe_areas.action_center); + UI_draw_safe_areas(shdr_pos, x1, x2, y1, y2, + scene->safe_areas.title_center, scene->safe_areas.action_center); } } } @@ -738,18 +709,15 @@ static void drawviewborder(Scene *scene, ARegion *ar, View3D *v3d) } /* draw */ - UI_GetThemeColorShade4fv(TH_VIEW_OVERLAY, 100, color1); - immUniform4fv("color1", color1); + immUniformThemeColorShade(TH_VIEW_OVERLAY, 100); /* TODO Was using UI_draw_roundbox_4fv(false, rect.xmin, rect.ymin, rect.xmax, rect.ymax, 2.0f, color). * We'll probably need a new imm_draw_line_roundbox_dashed dor that - though in practice the * 2.0f round corner effect was nearly not visible anyway... */ - imm_draw_line_box_dashed(pos, line_origin, rect.xmin, rect.ymin, rect.xmax, rect.ymax); + imm_draw_line_box(shdr_pos, rect.xmin, rect.ymin, rect.xmax, rect.ymax); } immUnbindProgram(); - - glDisable(GL_BLEND); } /* camera name - draw in highlighted text color */ @@ -763,13 +731,9 @@ static void drawviewborder(Scene *scene, ARegion *ar, View3D *v3d) static void drawrenderborder(ARegion *ar, View3D *v3d) { /* use the same program for everything */ - VertexFormat *format = immVertexFormat(); - unsigned int pos = VertexFormat_add_attrib(format, "pos", COMP_F32, 2, KEEP_FLOAT); - unsigned int line_origin = VertexFormat_add_attrib(format, "line_origin", COMP_F32, 2, KEEP_FLOAT); + uint shdr_pos = VertexFormat_add_attrib(immVertexFormat(), "pos", COMP_F32, 2, KEEP_FLOAT); glLineWidth(1.0f); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - glEnable(GL_BLEND); immBindBuiltinProgram(GPU_SHADER_2D_LINE_DASHED_COLOR); @@ -777,14 +741,14 @@ static void drawrenderborder(ARegion *ar, View3D *v3d) glGetFloatv(GL_VIEWPORT, viewport_size); immUniform2f("viewport_size", viewport_size[2], viewport_size[3]); - immUniform4f("color1", 1.0f, 0.25f, 0.25f, 1.0f); - immUniform4f("color2", 0.0f, 0.0f, 0.0f, 0.0f); + immUniform1i("num_colors", 0); /* "simple" mode */ + immUniform4f("color", 1.0f, 0.25f, 0.25f, 1.0f); immUniform1f("dash_width", 6.0f); - immUniform1f("dash_width_on", 3.0f); + immUniform1f("dash_factor", 0.5f); - imm_draw_line_box_dashed(pos, line_origin, - v3d->render_border.xmin * ar->winx, v3d->render_border.ymin * ar->winy, - v3d->render_border.xmax * ar->winx, v3d->render_border.ymax * ar->winy); + imm_draw_line_box(shdr_pos, + v3d->render_border.xmin * ar->winx, v3d->render_border.ymin * ar->winy, + v3d->render_border.xmax * ar->winx, v3d->render_border.ymax * ar->winy); immUnbindProgram(); } diff --git a/source/blender/editors/space_view3d/view3d_ruler.c b/source/blender/editors/space_view3d/view3d_ruler.c index 9bdc75802ba..aecde1b1657 100644 --- a/source/blender/editors/space_view3d/view3d_ruler.c +++ b/source/blender/editors/space_view3d/view3d_ruler.c @@ -458,38 +458,30 @@ static void ruler_info_draw_pixel(const struct bContext *C, ARegion *ar, void *a glEnable(GL_BLEND); - if (ruler_item->flag & RULERITEM_USE_ANGLE) { - VertexFormat *format = immVertexFormat(); - uint pos = VertexFormat_add_attrib(format, "pos", COMP_F32, 2, KEEP_FLOAT); - uint line_origin = VertexFormat_add_attrib(format, "line_origin", COMP_F32, 2, KEEP_FLOAT); + const uint shdr_pos = VertexFormat_add_attrib(immVertexFormat(), "pos", COMP_F32, 2, KEEP_FLOAT); + if (ruler_item->flag & RULERITEM_USE_ANGLE) { immBindBuiltinProgram(GPU_SHADER_2D_LINE_DASHED_COLOR); float viewport_size[4]; glGetFloatv(GL_VIEWPORT, viewport_size); immUniform2f("viewport_size", viewport_size[2], viewport_size[3]); - immUniform4f("color1", 0.67f, 0.67f, 0.67f, 1.0f); - immUniform4fv("color2", is_act ? color_act : color_base); + immUniform1i("num_colors", 2); /* "advanced" mode */ + const float *col = is_act ? color_act : color_base; + immUniformArray4fv("colors", (float *)(float[][4]){{0.67f, 0.67f, 0.67f, 1.0f}, {col[0], col[1], col[2], col[3]}}, 2); immUniform1f("dash_width", 6.0f); - immUniform1f("dash_width_on", 3.0f); - - immBegin(PRIM_LINES, 4); - immAttrib2fv(line_origin, co_ss[0]); - immVertex2fv(pos, co_ss[0]); - immVertex2fv(pos, co_ss[1]); + immBegin(PRIM_LINE_STRIP, 3); - immAttrib2fv(line_origin, co_ss[1]); - immVertex2fv(pos, co_ss[1]); - immVertex2fv(pos, co_ss[2]); + immVertex2fv(shdr_pos, co_ss[0]); + immVertex2fv(shdr_pos, co_ss[1]); + immVertex2fv(shdr_pos, co_ss[2]); immEnd(); immUnbindProgram(); - pos = VertexFormat_add_attrib(immVertexFormat(), "pos", COMP_F32, 2, KEEP_FLOAT); - immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR); /* arc */ @@ -529,7 +521,7 @@ static void ruler_info_draw_pixel(const struct bContext *C, ARegion *ar, void *a ED_view3d_project_float_global(ar, co_tmp, arc_ss_coord, V3D_PROJ_TEST_NOP); mul_qt_v3(quat, dir_tmp); - immVertex2fv(pos, arc_ss_coord); + immVertex2fv(shdr_pos, arc_ss_coord); } immEnd(); @@ -558,20 +550,20 @@ static void ruler_info_draw_pixel(const struct bContext *C, ARegion *ar, void *a immBegin(PRIM_LINES, 8); madd_v2_v2v2fl(cap, co_ss[0], rot_90_vec_a, cap_size); - immVertex2fv(pos, cap); + immVertex2fv(shdr_pos, cap); madd_v2_v2v2fl(cap, co_ss[0], rot_90_vec_a, -cap_size); - immVertex2fv(pos, cap); + immVertex2fv(shdr_pos, cap); madd_v2_v2v2fl(cap, co_ss[2], rot_90_vec_b, cap_size); - immVertex2fv(pos, cap); + immVertex2fv(shdr_pos, cap); madd_v2_v2v2fl(cap, co_ss[2], rot_90_vec_b, -cap_size); - immVertex2fv(pos, cap); + immVertex2fv(shdr_pos, cap); /* angle vertex */ - immVertex2f(pos, co_ss[1][0] - cap_size, co_ss[1][1] - cap_size); - immVertex2f(pos, co_ss[1][0] + cap_size, co_ss[1][1] + cap_size); - immVertex2f(pos, co_ss[1][0] - cap_size, co_ss[1][1] + cap_size); - immVertex2f(pos, co_ss[1][0] + cap_size, co_ss[1][1] - cap_size); + immVertex2f(shdr_pos, co_ss[1][0] - cap_size, co_ss[1][1] - cap_size); + immVertex2f(shdr_pos, co_ss[1][0] + cap_size, co_ss[1][1] + cap_size); + immVertex2f(shdr_pos, co_ss[1][0] - cap_size, co_ss[1][1] + cap_size); + immVertex2f(shdr_pos, co_ss[1][0] + cap_size, co_ss[1][1] - cap_size); immEnd(); @@ -608,33 +600,26 @@ static void ruler_info_draw_pixel(const struct bContext *C, ARegion *ar, void *a } } else { - VertexFormat *format = immVertexFormat(); - uint pos = VertexFormat_add_attrib(format, "pos", COMP_F32, 2, KEEP_FLOAT); - uint line_origin = VertexFormat_add_attrib(format, "line_origin", COMP_F32, 2, KEEP_FLOAT); - immBindBuiltinProgram(GPU_SHADER_2D_LINE_DASHED_COLOR); float viewport_size[4]; glGetFloatv(GL_VIEWPORT, viewport_size); immUniform2f("viewport_size", viewport_size[2], viewport_size[3]); - immUniform4f("color1", 0.67f, 0.67f, 0.67f, 1.0f); - immUniform4fv("color2", is_act ? color_act : color_base); + immUniform1i("num_colors", 2); /* "advanced" mode */ + const float *col = is_act ? color_act : color_base; + immUniformArray4fv("colors", (float *)(float[][4]){{0.67f, 0.67f, 0.67f, 1.0f}, {col[0], col[1], col[2], col[3]}}, 2); immUniform1f("dash_width", 6.0f); - immUniform1f("dash_width_on", 3.0f); immBegin(PRIM_LINES, 2); - immAttrib2fv(line_origin, co_ss[0]); - immVertex2fv(pos, co_ss[0]); - immVertex2fv(pos, co_ss[2]); + immVertex2fv(shdr_pos, co_ss[0]); + immVertex2fv(shdr_pos, co_ss[2]); immEnd(); immUnbindProgram(); - pos = VertexFormat_add_attrib(immVertexFormat(), "pos", COMP_F32, 2, KEEP_FLOAT); - immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR); sub_v2_v2v2(dir_ruler, co_ss[0], co_ss[2]); @@ -653,14 +638,14 @@ static void ruler_info_draw_pixel(const struct bContext *C, ARegion *ar, void *a immBegin(PRIM_LINES, 4); madd_v2_v2v2fl(cap, co_ss[0], rot_90_vec, cap_size); - immVertex2fv(pos, cap); + immVertex2fv(shdr_pos, cap); madd_v2_v2v2fl(cap, co_ss[0], rot_90_vec, -cap_size); - immVertex2fv(pos, cap); + immVertex2fv(shdr_pos, cap); madd_v2_v2v2fl(cap, co_ss[2], rot_90_vec, cap_size); - immVertex2fv(pos, cap); + immVertex2fv(shdr_pos, cap); madd_v2_v2v2fl(cap, co_ss[2], rot_90_vec, -cap_size); - immVertex2fv(pos, cap); + immVertex2fv(shdr_pos, cap); immEnd(); diff --git a/source/blender/editors/transform/transform.c b/source/blender/editors/transform/transform.c index 1c194a06005..02ad292e5c1 100644 --- a/source/blender/editors/transform/transform.c +++ b/source/blender/editors/transform/transform.c @@ -1722,15 +1722,11 @@ static void drawHelpline(bContext *UNUSED(C), int x, int y, void *customdata) /* Dashed lines first. */ if (ELEM(t->helpline, HLP_SPRING, HLP_ANGLE)) { - VertexFormat *format = immVertexFormat(); - uint pos = VertexFormat_add_attrib(format, "pos", COMP_F32, 2, KEEP_FLOAT); - uint line_origin = VertexFormat_add_attrib(format, "line_origin", COMP_F32, 2, KEEP_FLOAT); + const uint shdr_pos = VertexFormat_add_attrib(immVertexFormat(), "pos", COMP_F32, 2, KEEP_FLOAT); - UNUSED_VARS_NDEBUG(pos); /* silence warning */ - BLI_assert(pos == POS_INDEX); + UNUSED_VARS_NDEBUG(shdr_pos); /* silence warning */ + BLI_assert(shdr_pos == POS_INDEX); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - glEnable(GL_BLEND); glLineWidth(1.0f); immBindBuiltinProgram(GPU_SHADER_2D_LINE_DASHED_COLOR); @@ -1739,22 +1735,17 @@ static void drawHelpline(bContext *UNUSED(C), int x, int y, void *customdata) glGetFloatv(GL_VIEWPORT, viewport_size); immUniform2f("viewport_size", viewport_size[2], viewport_size[3]); - float color1[4]; - UI_GetThemeColor4fv(TH_VIEW_OVERLAY, color1); - immUniform4fv("color1", color1); - immUniform4f("color2", 0.0f, 0.0f, 0.0f, 0.0f); + immUniform1i("num_colors", 0); /* "simple" mode */ + immUniformThemeColor(TH_VIEW_OVERLAY); immUniform1f("dash_width", 6.0f); - immUniform1f("dash_width_on", 3.0f); + immUniform1f("dash_factor", 0.5f); immBegin(PRIM_LINES, 2); - immAttrib2fv(line_origin, cent); immVertex2fv(POS_INDEX, cent); immVertex2f(POS_INDEX, (float)t->mval[0], (float)t->mval[1]); immEnd(); immUnbindProgram(); - - glDisable(GL_BLEND); } /* And now, solid lines. */ @@ -7495,7 +7486,7 @@ static void drawVertSlide(TransInfo *t) glLineWidth(line_size); - uint pos = VertexFormat_add_attrib(immVertexFormat(), "pos", COMP_F32, 3, KEEP_FLOAT); + const uint shdr_pos = VertexFormat_add_attrib(immVertexFormat(), "pos", COMP_F32, 3, KEEP_FLOAT); immBindBuiltinProgram(GPU_SHADER_3D_UNIFORM_COLOR); immUniformThemeColorShadeAlpha(TH_EDGE_SELECT, 80, alpha_shade); @@ -7504,8 +7495,8 @@ static void drawVertSlide(TransInfo *t) if (is_clamp) { sv = sld->sv; for (i = 0; i < sld->totsv; i++, sv++) { - immVertex3fv(pos, sv->co_orig_3d); - immVertex3fv(pos, sv->co_link_orig_3d[sv->co_link_curr]); + immVertex3fv(shdr_pos, sv->co_orig_3d); + immVertex3fv(shdr_pos, sv->co_link_orig_3d[sv->co_link_curr]); } } else { @@ -7518,8 +7509,8 @@ static void drawVertSlide(TransInfo *t) add_v3_v3(a, sv->co_orig_3d); add_v3_v3(b, sv->co_orig_3d); - immVertex3fv(pos, a); - immVertex3fv(pos, b); + immVertex3fv(shdr_pos, a); + immVertex3fv(shdr_pos, b); } } immEnd(); @@ -7527,7 +7518,7 @@ static void drawVertSlide(TransInfo *t) glPointSize(ctrl_size); immBegin(PRIM_POINTS, 1); - immVertex3fv(pos, (sld->flipped && sld->use_even) ? + immVertex3fv(shdr_pos, (sld->flipped && sld->use_even) ? curr_sv->co_link_orig_3d[curr_sv->co_link_curr] : curr_sv->co_orig_3d); immEnd(); @@ -7558,32 +7549,25 @@ static void drawVertSlide(TransInfo *t) glLineWidth(1.0f); - VertexFormat *format = immVertexFormat(); - pos = VertexFormat_add_attrib(format, "pos", COMP_F32, 3, KEEP_FLOAT); - uint line_origin = VertexFormat_add_attrib(format, "line_origin", COMP_F32, 3, KEEP_FLOAT); - immBindBuiltinProgram(GPU_SHADER_3D_LINE_DASHED_COLOR); float viewport_size[4]; glGetFloatv(GL_VIEWPORT, viewport_size); immUniform2f("viewport_size", viewport_size[2], viewport_size[3]); - immUniform4f("color1", 1.0f, 1.0f, 1.0f, 1.0f); - immUniform4f("color2", 0.0f, 0.0f, 0.0f, 0.0f); + immUniform1i("num_colors", 0); /* "simple" mode */ + immUniformColor4f(1.0f, 1.0f, 1.0f, 1.0f); immUniform1f("dash_width", 6.0f); - immUniform1f("dash_width_on", 3.0f); + immUniform1f("dash_factor", 0.5f); immBegin(PRIM_LINES, 2); - immAttrib3fv(line_origin, curr_sv->co_orig_3d); - immVertex3fv(pos, curr_sv->co_orig_3d); - immVertex3fv(pos, co_dest_3d); + immVertex3fv(shdr_pos, curr_sv->co_orig_3d); + immVertex3fv(shdr_pos, co_dest_3d); immEnd(); immUnbindProgram(); } - glDisable(GL_BLEND); - gpuPopMatrix(); if (v3d && v3d->zbuf) diff --git a/source/blender/editors/transform/transform_constraints.c b/source/blender/editors/transform/transform_constraints.c index a2cb1bdd6d0..7b658d9c636 100644 --- a/source/blender/editors/transform/transform_constraints.c +++ b/source/blender/editors/transform/transform_constraints.c @@ -728,12 +728,7 @@ void drawConstraint(TransInfo *t) if (depth_test_enabled) glDisable(GL_DEPTH_TEST); - VertexFormat *format = immVertexFormat(); - unsigned int pos = VertexFormat_add_attrib(format, "pos", COMP_F32, 3, KEEP_FLOAT); - unsigned int line_origin = VertexFormat_add_attrib(format, "line_origin", COMP_F32, 3, KEEP_FLOAT); - - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - glEnable(GL_BLEND); + const uint shdr_pos = VertexFormat_add_attrib(immVertexFormat(), "pos", COMP_F32, 3, KEEP_FLOAT); immBindBuiltinProgram(GPU_SHADER_3D_LINE_DASHED_COLOR); @@ -741,21 +736,18 @@ void drawConstraint(TransInfo *t) glGetFloatv(GL_VIEWPORT, viewport_size); immUniform2f("viewport_size", viewport_size[2], viewport_size[3]); - immUniform4f("color1", 1.0f, 1.0f, 1.0f, 1.0f); - immUniform4f("color2", 0.0f, 0.0f, 0.0f, 0.0f); + immUniform1i("num_colors", 0); /* "simple" mode */ + immUniformColor4f(1.0f, 1.0f, 1.0f, 1.0f); immUniform1f("dash_width", 2.0f); - immUniform1f("dash_width_on", 1.0f); + immUniform1f("dash_factor", 0.5f); immBegin(PRIM_LINES, 2); - immAttrib3fv(line_origin, t->center_global); - immVertex3fv(pos, t->center_global); - immVertex3fv(pos, vec); + immVertex3fv(shdr_pos, t->center_global); + immVertex3fv(shdr_pos, vec); immEnd(); immUnbindProgram(); - glDisable(GL_BLEND); - if (depth_test_enabled) glEnable(GL_DEPTH_TEST); } diff --git a/source/blender/editors/util/ed_util.c b/source/blender/editors/util/ed_util.c index aa0d0faf4f5..490683e9360 100644 --- a/source/blender/editors/util/ed_util.c +++ b/source/blender/editors/util/ed_util.c @@ -318,13 +318,7 @@ void ED_region_draw_mouse_line_cb(const bContext *C, ARegion *ar, void *arg_info const float mval_dst[2] = {win->eventstate->x - ar->winrct.xmin, win->eventstate->y - ar->winrct.ymin}; - 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); - float color1[4]; - - glEnable(GL_BLEND); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + const uint shdr_pos = VertexFormat_add_attrib(immVertexFormat(), "pos", COMP_F32, 2, KEEP_FLOAT); immBindBuiltinProgram(GPU_SHADER_2D_LINE_DASHED_COLOR); @@ -332,21 +326,17 @@ void ED_region_draw_mouse_line_cb(const bContext *C, ARegion *ar, void *arg_info glGetFloatv(GL_VIEWPORT, viewport_size); immUniform2f("viewport_size", viewport_size[2] / UI_DPI_FAC, viewport_size[3] / UI_DPI_FAC); - UI_GetThemeColor4fv(TH_VIEW_OVERLAY, color1); - immUniform4fv("color1", color1); - immUniform4f("color2", 0.0f, 0.0f, 0.0f, 0.0f); + immUniform1i("num_colors", 0); /* "simple" mode */ + immUniformThemeColor(TH_VIEW_OVERLAY); immUniform1f("dash_width", 6.0f); - immUniform1f("dash_width_on", 3.0f); + immUniform1f("dash_factor", 0.5f); immBegin(PRIM_LINES, 2); - immAttrib2fv(shdr_dashed_origin, mval_src); - immVertex2fv(shdr_dashed_pos, mval_src); - immVertex2fv(shdr_dashed_pos, mval_dst); + immVertex2fv(shdr_pos, mval_src); + immVertex2fv(shdr_pos, mval_dst); immEnd(); immUnbindProgram(); - - glDisable(GL_BLEND); } /** diff --git a/source/blender/editors/uvedit/uvedit_draw.c b/source/blender/editors/uvedit/uvedit_draw.c index 53b2bd1ae67..3dc6ed8194b 100644 --- a/source/blender/editors/uvedit/uvedit_draw.c +++ b/source/blender/editors/uvedit/uvedit_draw.c @@ -71,8 +71,7 @@ #include "uvedit_intern.h" -static void draw_uvs_lineloop_bmface( - BMFace *efa, const int cd_loop_uv_offset, uint shdr_pos, const bool use_dashed, uint shdr_dashed_origin); +static void draw_uvs_lineloop_bmface(BMFace *efa, const int cd_loop_uv_offset, const uint shdr_pos); void ED_image_draw_cursor(ARegion *ar, const float cursor[2]) { @@ -86,9 +85,7 @@ void ED_image_draw_cursor(ARegion *ar, const float cursor[2]) gpuTranslate2fv(cursor); - 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); + const uint shdr_pos = VertexFormat_add_attrib(immVertexFormat(), "pos", COMP_F32, 2, KEEP_FLOAT); immBindBuiltinProgram(GPU_SHADER_2D_LINE_DASHED_COLOR); @@ -96,53 +93,42 @@ void ED_image_draw_cursor(ARegion *ar, const float cursor[2]) glGetFloatv(GL_VIEWPORT, viewport_size); immUniform2f("viewport_size", viewport_size[2] / UI_DPI_FAC, viewport_size[3] / UI_DPI_FAC); - immUniform4f("color1", 1.0f, 0.0f, 0.0f, 1.0f); - immUniform4f("color2", 1.0f, 1.0f, 1.0f, 1.0f); + immUniform1i("num_colors", 2); /* "advanced" mode */ + immUniformArray4fv("colors", (float *)(float[][4]){{1.0f, 0.0f, 0.0f, 1.0f}, {1.0f, 1.0f, 1.0f, 1.0f}}, 2); immUniform1f("dash_width", 8.0f); - immUniform1f("dash_width_on", 4.0f); immBegin(PRIM_LINES, 8); - immAttrib2f(shdr_dashed_origin, -0.05f * x_fac, 0.0f); - immVertex2f(shdr_dashed_pos, -0.05f * x_fac, 0.0f); - immVertex2f(shdr_dashed_pos, 0.0f, 0.05f * y_fac); + immVertex2f(shdr_pos, -0.05f * x_fac, 0.0f); + immVertex2f(shdr_pos, 0.0f, 0.05f * y_fac); - immAttrib2f(shdr_dashed_origin, 0.0f, 0.05f * y_fac); - immVertex2f(shdr_dashed_pos, 0.0f, 0.05f * y_fac); - immVertex2f(shdr_dashed_pos, 0.05f * x_fac, 0.0f); + immVertex2f(shdr_pos, 0.0f, 0.05f * y_fac); + immVertex2f(shdr_pos, 0.05f * x_fac, 0.0f); - immAttrib2f(shdr_dashed_origin, 0.05f * x_fac, 0.0f); - immVertex2f(shdr_dashed_pos, 0.05f * x_fac, 0.0f); - immVertex2f(shdr_dashed_pos, 0.0f, -0.05f * y_fac); + immVertex2f(shdr_pos, 0.05f * x_fac, 0.0f); + immVertex2f(shdr_pos, 0.0f, -0.05f * y_fac); - immAttrib2f(shdr_dashed_origin, 0.0f, -0.05f * y_fac); - immVertex2f(shdr_dashed_pos, 0.0f, -0.05f * y_fac); - immVertex2f(shdr_dashed_pos, -0.05f * x_fac, 0.0f); + immVertex2f(shdr_pos, 0.0f, -0.05f * y_fac); + immVertex2f(shdr_pos, -0.05f * x_fac, 0.0f); immEnd(); - immUniform4f("color1", 1.0f, 1.0f, 1.0f, 1.0f); - immUniform4f("color2", 0.0f, 0.0f, 0.0f, 1.0f); + immUniformArray4fv("colors", (float *)(float[][4]){{1.0f, 1.0f, 1.0f, 1.0f}, {0.0f, 0.0f, 0.0f, 1.0f}}, 2); immUniform1f("dash_width", 2.0f); - immUniform1f("dash_width_on", 1.0f); immBegin(PRIM_LINES, 8); - immAttrib2f(shdr_dashed_origin, -0.020f * x_fac, 0.0f); - immVertex2f(shdr_dashed_pos, -0.020f * x_fac, 0.0f); - immVertex2f(shdr_dashed_pos, -0.1f * x_fac, 0.0f); + immVertex2f(shdr_pos, -0.020f * x_fac, 0.0f); + immVertex2f(shdr_pos, -0.1f * x_fac, 0.0f); - immAttrib2f(shdr_dashed_origin, 0.1f * x_fac, 0.0f); - immVertex2f(shdr_dashed_pos, 0.1f * x_fac, 0.0f); - immVertex2f(shdr_dashed_pos, 0.020f * x_fac, 0.0f); + immVertex2f(shdr_pos, 0.1f * x_fac, 0.0f); + immVertex2f(shdr_pos, 0.020f * x_fac, 0.0f); - immAttrib2f(shdr_dashed_origin, 0.0f, -0.020f * y_fac); - immVertex2f(shdr_dashed_pos, 0.0f, -0.020f * y_fac); - immVertex2f(shdr_dashed_pos, 0.0f, -0.1f * y_fac); + immVertex2f(shdr_pos, 0.0f, -0.020f * y_fac); + immVertex2f(shdr_pos, 0.0f, -0.1f * y_fac); - immAttrib2f(shdr_dashed_origin, 0.0f, 0.1f * y_fac); - immVertex2f(shdr_dashed_pos, 0.0f, 0.1f * y_fac); - immVertex2f(shdr_dashed_pos, 0.0f, 0.020f * y_fac); + immVertex2f(shdr_pos, 0.0f, 0.1f * y_fac); + immVertex2f(shdr_pos, 0.0f, 0.020f * y_fac); immEnd(); @@ -185,7 +171,7 @@ static void draw_uvs_shadow(Object *obedit) immUniformThemeColor(TH_UV_SHADOW); BM_ITER_MESH (efa, &iter, bm, BM_FACES_OF_MESH) { - draw_uvs_lineloop_bmface(efa, cd_loop_uv_offset, pos, false, 0); + draw_uvs_lineloop_bmface(efa, cd_loop_uv_offset, pos); } immUnbindProgram(); @@ -400,37 +386,17 @@ static void draw_uvs_stretch(SpaceImage *sima, Scene *scene, BMEditMesh *em, MTe BLI_buffer_free(&tf_uvorig_buf); } -static void draw_uvs_lineloop_bmface( - BMFace *efa, const int cd_loop_uv_offset, uint shdr_pos, const bool use_dashed, uint shdr_dashed_origin) +static void draw_uvs_lineloop_bmface(BMFace *efa, const int cd_loop_uv_offset, const uint shdr_pos) { BMIter liter; BMLoop *l; MLoopUV *luv; - if (use_dashed) { - immBegin(PRIM_LINES, efa->len * 2); + immBegin(PRIM_LINE_LOOP, efa->len); - const float *prev_uv = NULL; - BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) { - if (prev_uv == NULL) { - luv = BM_ELEM_CD_GET_VOID_P(l->prev, cd_loop_uv_offset); - prev_uv = luv->uv; - } - luv = BM_ELEM_CD_GET_VOID_P(l, cd_loop_uv_offset); - - immAttrib2fv(shdr_dashed_origin, prev_uv); - immVertex2fv(shdr_pos, prev_uv); - immVertex2fv(shdr_pos, luv->uv); - prev_uv = luv->uv; - } - } - else { - immBegin(PRIM_LINE_LOOP, efa->len); - - BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) { - luv = BM_ELEM_CD_GET_VOID_P(l, cd_loop_uv_offset); - immVertex2fv(shdr_pos, luv->uv); - } + BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) { + luv = BM_ELEM_CD_GET_VOID_P(l, cd_loop_uv_offset); + immVertex2fv(shdr_pos, luv->uv); } immEnd(); @@ -770,9 +736,7 @@ static void draw_uvs(SpaceImage *sima, Scene *scene, SceneLayer *sl, Object *obe switch (sima->dt_uv) { case SI_UVDT_DASH: { - 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); + const uint shdr_pos = VertexFormat_add_attrib(immVertexFormat(), "pos", COMP_F32, 2, KEEP_FLOAT); immBindBuiltinProgram(GPU_SHADER_2D_LINE_DASHED_COLOR); @@ -780,10 +744,9 @@ static void draw_uvs(SpaceImage *sima, Scene *scene, SceneLayer *sl, Object *obe glGetFloatv(GL_VIEWPORT, viewport_size); immUniform2f("viewport_size", viewport_size[2] / UI_DPI_FAC, viewport_size[3] / UI_DPI_FAC); - immUniform4f("color1", 0.56f, 0.56f, 0.56f, 1.0f); - immUniform4f("color2", 0.07f, 0.07f, 0.07f, 1.0f); + immUniform1i("num_colors", 2); /* "advanced" mode */ + immUniformArray4fv("colors", (float *)(float[][4]){{0.56f, 0.56f, 0.56f, 1.0f}, {0.07f, 0.07f, 0.07f, 1.0f}}, 2); immUniform1f("dash_width", 4.0f); - immUniform1f("dash_width_on", 2.0f); BM_ITER_MESH (efa, &iter, bm, BM_FACES_OF_MESH) { if (!BM_elem_flag_test(efa, BM_ELEM_TAG)) @@ -791,7 +754,7 @@ static void draw_uvs(SpaceImage *sima, Scene *scene, SceneLayer *sl, Object *obe tf = BM_ELEM_CD_GET_VOID_P(efa, cd_poly_tex_offset); if (tf) { - draw_uvs_lineloop_bmface(efa, cd_loop_uv_offset, shdr_dashed_pos, true, shdr_dashed_origin); + draw_uvs_lineloop_bmface(efa, cd_loop_uv_offset, shdr_pos); } } @@ -816,7 +779,7 @@ static void draw_uvs(SpaceImage *sima, Scene *scene, SceneLayer *sl, Object *obe if (!BM_elem_flag_test(efa, BM_ELEM_TAG)) continue; - draw_uvs_lineloop_bmface(efa, cd_loop_uv_offset, pos, false, 0); + draw_uvs_lineloop_bmface(efa, cd_loop_uv_offset, pos); } immUnbindProgram(); @@ -834,7 +797,7 @@ static void draw_uvs(SpaceImage *sima, Scene *scene, SceneLayer *sl, Object *obe if (!BM_elem_flag_test(efa, BM_ELEM_TAG)) continue; - draw_uvs_lineloop_bmface(efa, cd_loop_uv_offset, pos, false, 0); + draw_uvs_lineloop_bmface(efa, cd_loop_uv_offset, pos); } immUnbindProgram(); @@ -913,7 +876,7 @@ static void draw_uvs(SpaceImage *sima, Scene *scene, SceneLayer *sl, Object *obe if (!BM_elem_flag_test(efa, BM_ELEM_TAG)) continue; - draw_uvs_lineloop_bmface(efa, cd_loop_uv_offset, pos, false, 0); + draw_uvs_lineloop_bmface(efa, cd_loop_uv_offset, pos); } immUnbindProgram(); |