Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBastien Montagne <montagne29@wanadoo.fr>2017-05-01 17:21:53 +0300
committerBastien Montagne <montagne29@wanadoo.fr>2017-05-01 17:32:55 +0300
commitd7d4bca23be91ec5b0ce562d47a34ee49dd337b8 (patch)
tree6184684f5300324294dbaa103522e7e817e3d6bd /source/blender/editors/space_view3d
parent6ef497d401e5e7842d1e9d33e491672bb77d60e0 (diff)
Reworked version of dashed line shader.
Using geometry shader allows us to get rid of the 'line origin' extra vertex attribute, which means dashed shader no longer requires fiddling with those vertex attributes definition, and, most importantly, does not require anymore special drawing code! As you can see, this makes code much simpler, and much less verbose, especially in complex cases. In addition, changed how dashes are handled, to have two 'modes', a simple one with single color (using default "color" uniform name), and a more advanced one allowing more complex and multi-color patterns. Note that since GLSL 1.2 does not support geometry shaders, a hack was added for now (which gives solid lines, but at least does not make Blender crash).
Diffstat (limited to 'source/blender/editors/space_view3d')
-rw-r--r--source/blender/editors/space_view3d/drawarmature.c69
-rw-r--r--source/blender/editors/space_view3d/view3d_draw.c168
-rw-r--r--source/blender/editors/space_view3d/view3d_ruler.c69
3 files changed, 114 insertions, 192 deletions
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();