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/view3d_ruler.c
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/view3d_ruler.c')
-rw-r--r--source/blender/editors/space_view3d/view3d_ruler.c69
1 files changed, 27 insertions, 42 deletions
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();