Merge branch 'master' into blender2.8
[blender.git] / source / blender / editors / transform / transform_constraints.c
index 08bd36fe95ca06c480f48cdd15dc05f3b04cebac..f612dc0e4749710db7ecec4878094a48b6e19990 100644 (file)
 #include "DNA_space_types.h"
 #include "DNA_view3d_types.h"
 
-#include "BIF_gl.h"
 #include "BIF_glutil.h"
 
+#include "GPU_immediate.h"
+#include "GPU_matrix.h"
+
 #include "BLI_math.h"
 #include "BLI_utildefines.h"
 #include "BLI_string.h"
@@ -651,7 +653,7 @@ void setLocalConstraint(TransInfo *t, int mode, const char text[])
  */
 void setUserConstraint(TransInfo *t, short orientation, int mode, const char ftext[])
 {
-       char text[40];
+       char text[256];
 
        switch (orientation) {
                case V3D_MANIP_GLOBAL:
@@ -683,10 +685,15 @@ void setUserConstraint(TransInfo *t, short orientation, int mode, const char fte
                        BLI_snprintf(text, sizeof(text), ftext, IFACE_("gimbal"));
                        setConstraint(t, t->spacemtx, mode, text);
                        break;
-               default: /* V3D_MANIP_CUSTOM */
-                       BLI_snprintf(text, sizeof(text), ftext, t->spacename);
+               case V3D_MANIP_CUSTOM:
+               {
+                       char orientation_str[128];
+                       BLI_snprintf(orientation_str, sizeof(orientation_str), "%s \"%s\"",
+                                    IFACE_("custom orientation"), t->custom_orientation->name);
+                       BLI_snprintf(text, sizeof(text), ftext, orientation_str);
                        setConstraint(t, t->spacemtx, mode, text);
                        break;
+               }
        }
 
        t->con.orientation = orientation;
@@ -704,8 +711,6 @@ void drawConstraint(TransInfo *t)
                return;
        if (!(tc->mode & CON_APPLY))
                return;
-       if (t->flag & T_USES_MANIPULATOR)
-               return;
        if (t->flag & T_NO_CONSTRAINT)
                return;
 
@@ -715,7 +720,6 @@ void drawConstraint(TransInfo *t)
        else {
                if (tc->mode & CON_SELECT) {
                        float vec[3];
-                       char col2[3] = {255, 255, 255};
                        int depth_test_enabled;
 
                        convertViewVec(t, vec, (t->mval[0] - t->con.imval[0]), (t->mval[1] - t->con.imval[1]));
@@ -725,18 +729,29 @@ void drawConstraint(TransInfo *t)
                        drawLine(t, t->center_global, tc->mtx[1], 'Y', 0);
                        drawLine(t, t->center_global, tc->mtx[2], 'Z', 0);
 
-                       glColor3ubv((GLubyte *)col2);
-
                        depth_test_enabled = glIsEnabled(GL_DEPTH_TEST);
                        if (depth_test_enabled)
                                glDisable(GL_DEPTH_TEST);
 
-                       setlinestyle(1);
-                       glBegin(GL_LINES);
-                       glVertex3fv(t->center_global);
-                       glVertex3fv(vec);
-                       glEnd();
-                       setlinestyle(0);
+                       const uint shdr_pos = GWN_vertformat_attr_add(immVertexFormat(), "pos", GWN_COMP_F32, 3, GWN_FETCH_FLOAT);
+
+                       immBindBuiltinProgram(GPU_SHADER_3D_LINE_DASHED_UNIFORM_COLOR);
+
+                       float viewport_size[4];
+                       glGetFloatv(GL_VIEWPORT, viewport_size);
+                       immUniform2f("viewport_size", viewport_size[2], viewport_size[3]);
+
+                       immUniform1i("num_colors", 0);  /* "simple" mode */
+                       immUniformColor4f(1.0f, 1.0f, 1.0f, 1.0f);
+                       immUniform1f("dash_width", 2.0f);
+                       immUniform1f("dash_factor", 0.5f);
+
+                       immBegin(GWN_PRIM_LINES, 2);
+                       immVertex3fv(shdr_pos, t->center_global);
+                       immVertex3fv(shdr_pos, vec);
+                       immEnd();
+
+                       immUnbindProgram();
 
                        if (depth_test_enabled)
                                glEnable(GL_DEPTH_TEST);
@@ -762,8 +777,6 @@ void drawPropCircle(const struct bContext *C, TransInfo *t)
                float tmat[4][4], imat[4][4];
                int depth_test_enabled;
 
-               UI_ThemeColor(TH_GRID);
-
                if (t->spacetype == SPACE_VIEW3D && rv3d != NULL) {
                        copy_m4_m4(tmat, rv3d->viewmat);
                        invert_m4_m4(imat, tmat);
@@ -773,13 +786,13 @@ void drawPropCircle(const struct bContext *C, TransInfo *t)
                        unit_m4(imat);
                }
 
-               glPushMatrix();
+               gpuPushMatrix();
 
                if (t->spacetype == SPACE_VIEW3D) {
                        /* pass */
                }
                else if (t->spacetype == SPACE_IMAGE) {
-                       glScalef(1.0f / t->aspect[0], 1.0f / t->aspect[1], 1.0f);
+                       gpuScale2f(1.0f / t->aspect[0], 1.0f / t->aspect[1]);
                }
                else if (ELEM(t->spacetype, SPACE_IPO, SPACE_ACTION)) {
                        /* only scale y */
@@ -789,21 +802,28 @@ void drawPropCircle(const struct bContext *C, TransInfo *t)
                        float ysize = BLI_rctf_size_y(datamask);
                        float xmask = BLI_rcti_size_x(mask);
                        float ymask = BLI_rcti_size_y(mask);
-                       glScalef(1.0f, (ysize / xsize) * (xmask / ymask), 1.0f);
+                       gpuScale2f(1.0f, (ysize / xsize) * (xmask / ymask));
                }
 
                depth_test_enabled = glIsEnabled(GL_DEPTH_TEST);
                if (depth_test_enabled)
                        glDisable(GL_DEPTH_TEST);
 
+               unsigned int pos = GWN_vertformat_attr_add(immVertexFormat(), "pos", GWN_COMP_F32, 3, GWN_FETCH_FLOAT);
+
+               immBindBuiltinProgram(GPU_SHADER_3D_UNIFORM_COLOR);
+               immUniformThemeColor(TH_GRID);
+
                set_inverted_drawing(1);
-               drawcircball(GL_LINE_LOOP, t->center_global, t->prop_size, imat);
+               imm_drawcircball(t->center_global, t->prop_size, imat, pos);
                set_inverted_drawing(0);
 
+               immUnbindProgram();
+
                if (depth_test_enabled)
                        glEnable(GL_DEPTH_TEST);
 
-               glPopMatrix();
+               gpuPopMatrix();
        }
 }