Getting rid of setlinestyle: 3DView ruler.
authorBastien Montagne <montagne29@wanadoo.fr>
Wed, 26 Apr 2017 13:16:15 +0000 (15:16 +0200)
committerBastien Montagne <montagne29@wanadoo.fr>
Wed, 26 Apr 2017 13:19:03 +0000 (15:19 +0200)
source/blender/editors/space_view3d/view3d_ruler.c

index b3ecc2419a6393a2bed984f7c12f217db3c53533..11579e6a670b2fad7b4b2d91d06a4519f9c3fd2d 100644 (file)
@@ -429,9 +429,8 @@ static void ruler_info_draw_pixel(const struct bContext *C, ARegion *ar, void *a
 #define ARC_STEPS 24
        const int arc_steps = ARC_STEPS;
        int i;
-       //unsigned int color_act = 0x666600;
-       unsigned int color_act = 0xffffff;
-       unsigned int color_base = 0x0;
+       const float color_act[4] = {1.0f, 1.0f, 1.0f, 1.0f};
+       const float color_base[4] = {0.0f, 0.0f, 0.0f, 1.0f};
        unsigned char color_text[3];
        unsigned char color_wire[3];
        float color_back[4] = {1.0f, 1.0f, 1.0f, 0.5f};
@@ -460,31 +459,35 @@ static void ruler_info_draw_pixel(const struct bContext *C, ARegion *ar, void *a
                glEnable(GL_BLEND);
 
                if (ruler_item->flag & RULERITEM_USE_ANGLE) {
-                       unsigned int pos = VertexFormat_add_attrib(immVertexFormat(), "pos", COMP_F32, 2, KEEP_FLOAT);
+                       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_UNIFORM_COLOR);
-                       imm_cpack(is_act ? color_act : color_base);
+                       immBindBuiltinProgram(GPU_SHADER_2D_LINE_DASHED_COLOR);
 
-                       immBegin(PRIM_LINE_STRIP, 3);
+                       immUniform1f("view_scale", 1.0f);
+                       immUniform4f("color1", 0.67f, 0.67f, 0.67f, 1.0f);
+                       immUniform4fv("color2", is_act ? color_act : color_base);
+                       immUniform1f("dash_width", 8.0f);
+                       immUniform1f("dash_width_on", 4.0f);
 
-                       for (j = 0; j < 3; j++) {
-                               immVertex2fv(pos, co_ss[j]);
-                       }
+                       immBegin(PRIM_LINES, 4);
 
-                       immEnd();
+                       immAttrib2fv(line_origin, co_ss[0]);
+                       immVertex2fv(pos, co_ss[0]);
+                       immVertex2fv(pos, co_ss[1]);
 
-                       imm_cpack(0xaaaaaa);
-                       setlinestyle(3);
+                       immAttrib2fv(line_origin, co_ss[1]);
+                       immVertex2fv(pos, co_ss[1]);
+                       immVertex2fv(pos, co_ss[2]);
 
-                       immBegin(PRIM_LINE_STRIP, 3);
+                       immEnd();
 
-                       for (j = 0; j < 3; j++) {
-                               immVertex2fv(pos, co_ss[j]);
-                       }
+                       immUnbindProgram();
 
-                       immEnd();
+                       pos = VertexFormat_add_attrib(immVertexFormat(), "pos", COMP_F32, 2, KEEP_FLOAT);
 
-                       setlinestyle(0);
+                       immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
 
                        /* arc */
                        {
@@ -602,31 +605,31 @@ static void ruler_info_draw_pixel(const struct bContext *C, ARegion *ar, void *a
                        }
                }
                else {
-                       unsigned int pos = VertexFormat_add_attrib(immVertexFormat(), "pos", COMP_F32, 2, KEEP_FLOAT);
+                       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_UNIFORM_COLOR);
-                       imm_cpack(is_act ? color_act : color_base);
-
-                       immBegin(PRIM_LINE_STRIP, 2);
+                       immBindBuiltinProgram(GPU_SHADER_2D_LINE_DASHED_COLOR);
 
-                       for (j = 0; j < 3; j += 2) {
-                               immVertex2fv(pos, co_ss[j]);
-                       }
+                       immUniform1f("view_scale", 1.0f);
+                       immUniform4f("color1", 0.67f, 0.67f, 0.67f, 1.0f);
+                       immUniform4fv("color2", is_act ? color_act : color_base);
+                       immUniform1f("dash_width", 8.0f);
+                       immUniform1f("dash_width_on", 4.0f);
 
-                       immEnd();
+                       immBegin(PRIM_LINES, 2);
 
-                       imm_cpack(0xaaaaaa);
-                       setlinestyle(3);
+                       immAttrib2fv(line_origin, co_ss[0]);
+                       immVertex2fv(pos, co_ss[0]);
+                       immVertex2fv(pos, co_ss[2]);
 
-                       immBegin(PRIM_LINE_STRIP, 2);
+                       immEnd();
 
-                       for (j = 0; j < 3; j += 2) {
-                               immVertex2fv(pos, co_ss[j]);
-                       }
+                       immUnbindProgram();
 
-                       immEnd();
+                       pos = VertexFormat_add_attrib(immVertexFormat(), "pos", COMP_F32, 2, KEEP_FLOAT);
 
-                       setlinestyle(0);
+                       immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
 
                        sub_v2_v2v2(dir_ruler, co_ss[0], co_ss[2]);
 
@@ -709,7 +712,7 @@ static void ruler_info_draw_pixel(const struct bContext *C, ARegion *ar, void *a
                        unsigned int pos = VertexFormat_add_attrib(immVertexFormat(), "pos", COMP_F32, 2, KEEP_FLOAT);
 
                        immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
-                       imm_cpack(color_act);
+                       immUniformColor4fv(color_act);
 
                        imm_draw_circle_wire(pos, co_ss[0], co_ss[1], size * U.pixelsize, 32);