OpenGL immediate mode: transform_snap.c and part of drawnode.c
authorLuca Rood <dev@lucarood.com>
Thu, 2 Feb 2017 05:14:52 +0000 (03:14 -0200)
committerLuca Rood <dev@lucarood.com>
Thu, 2 Feb 2017 16:28:46 +0000 (14:28 -0200)
Also converted ED_node_draw_snap from drawnode.c
Committing these together, as they are inter-dependent.

Part of T49043

source/blender/editors/include/ED_node.h
source/blender/editors/space_node/drawnode.c
source/blender/editors/transform/transform_snap.c

index f7b9d6b4f9e483b08b28eb2a8b3aefa90f7faafe..b4cf96f27bff169ba6b27d1ee8274b97b7500bbc 100644 (file)
@@ -75,7 +75,7 @@ void ED_init_custom_node_socket_type(struct bNodeSocketType *stype);
 void ED_init_standard_node_socket_type(struct bNodeSocketType *stype);
 void ED_init_node_socket_type_virtual(struct bNodeSocketType *stype);
 void ED_node_sample_set(const float col[4]);
-void ED_node_draw_snap(struct View2D *v2d, const float cent[2], float size, NodeBorder border);
+void ED_node_draw_snap(struct View2D *v2d, const float cent[2], float size, NodeBorder border, unsigned pos);
 
 /* node_draw.c */
 void ED_node_tree_update(const struct bContext *C);
index e02c69ea85728d6bd16a663c32e2a950fdbf9762..5940ed5f0c1fefb59c0ebca2338a6b847f4631c6 100644 (file)
@@ -3619,27 +3619,27 @@ void node_draw_link(View2D *v2d, SpaceNode *snode, bNodeLink *link)
 //     node_draw_link_straight(v2d, snode, link, th_col1, do_shaded, th_col2, do_triple, th_col3);
 }
 
-void ED_node_draw_snap(View2D *v2d, const float cent[2], float size, NodeBorder border)
+void ED_node_draw_snap(View2D *v2d, const float cent[2], float size, NodeBorder border, unsigned pos)
 {
-       glBegin(GL_LINES);
+       immBegin(GL_LINES, 4);
        
        if (border & (NODE_LEFT | NODE_RIGHT)) {
-               glVertex2f(cent[0], v2d->cur.ymin);
-               glVertex2f(cent[0], v2d->cur.ymax);
+               immVertex2f(pos, cent[0], v2d->cur.ymin);
+               immVertex2f(pos, cent[0], v2d->cur.ymax);
        }
        else {
-               glVertex2f(cent[0], cent[1] - size);
-               glVertex2f(cent[0], cent[1] + size);
+               immVertex2f(pos, cent[0], cent[1] - size);
+               immVertex2f(pos, cent[0], cent[1] + size);
        }
        
        if (border & (NODE_TOP | NODE_BOTTOM)) {
-               glVertex2f(v2d->cur.xmin, cent[1]);
-               glVertex2f(v2d->cur.xmax, cent[1]);
+               immVertex2f(pos, v2d->cur.xmin, cent[1]);
+               immVertex2f(pos, v2d->cur.xmax, cent[1]);
        }
        else {
-               glVertex2f(cent[0] - size, cent[1]);
-               glVertex2f(cent[0] + size, cent[1]);
+               immVertex2f(pos, cent[0] - size, cent[1]);
+               immVertex2f(pos, cent[0] + size, cent[1]);
        }
        
-       glEnd();
+       immEnd();
 }
index 87ac54b2bd9ebf76681180224b169700ba4c8171..6ca963bc0e32ace392d8458c1d4486d9235cfafe 100644 (file)
@@ -49,7 +49,7 @@
 #include "BLI_blenlib.h"
 #include "BLI_utildefines.h"
 
-#include "BIF_gl.h"
+#include "GPU_immediate.h"
 
 #include "BKE_DerivedMesh.h"
 #include "BKE_global.h"
@@ -163,36 +163,42 @@ void drawSnapping(const struct bContext *C, TransInfo *t)
                        size = 2.5f * UI_GetThemeValuef(TH_VERTEX_SIZE);
                        
                        invert_m4_m4(imat, rv3d->viewmat);
-                       
+
+                       unsigned pos = add_attrib(immVertexFormat(), "pos", GL_FLOAT, 3, KEEP_FLOAT);
+
+                       immBindBuiltinProgram(GPU_SHADER_3D_UNIFORM_COLOR);
+
                        for (p = t->tsnap.points.first; p; p = p->next) {
                                if (p == t->tsnap.selectedPoint) {
-                                       glColor4ubv(selectedCol);
+                                       immUniformColor4ubv(selectedCol);
                                }
                                else {
-                                       glColor4ubv(col);
+                                       immUniformColor4ubv(col);
                                }
                                
-                               drawcircball(GL_LINE_LOOP, p->co, ED_view3d_pixel_size(rv3d, p->co) * size * 0.75f, imat);
+                               imm_drawcircball(p->co, ED_view3d_pixel_size(rv3d, p->co) * size * 0.75f, imat, pos);
                        }
                        
                        if (t->tsnap.status & POINT_INIT) {
-                               glColor4ubv(activeCol);
+                               immUniformColor4ubv(activeCol);
                                
-                               drawcircball(GL_LINE_LOOP, t->tsnap.snapPoint, ED_view3d_pixel_size(rv3d, t->tsnap.snapPoint) * size, imat);
+                               imm_drawcircball(t->tsnap.snapPoint, ED_view3d_pixel_size(rv3d, t->tsnap.snapPoint) * size, imat, pos);
                        }
                        
                        /* draw normal if needed */
                        if (usingSnappingNormal(t) && validSnappingNormal(t)) {
-                               glColor4ubv(activeCol);
+                               immUniformColor4ubv(activeCol);
                                
-                               glBegin(GL_LINES);
-                               glVertex3f(t->tsnap.snapPoint[0], t->tsnap.snapPoint[1], t->tsnap.snapPoint[2]);
-                               glVertex3f(t->tsnap.snapPoint[0] + t->tsnap.snapNormal[0],
-                                          t->tsnap.snapPoint[1] + t->tsnap.snapNormal[1],
-                                          t->tsnap.snapPoint[2] + t->tsnap.snapNormal[2]);
-                               glEnd();
+                               immBegin(GL_LINES, 2);
+                               immVertex3f(pos, t->tsnap.snapPoint[0], t->tsnap.snapPoint[1], t->tsnap.snapPoint[2]);
+                               immVertex3f(pos, t->tsnap.snapPoint[0] + t->tsnap.snapNormal[0],
+                                           t->tsnap.snapPoint[1] + t->tsnap.snapNormal[1],
+                                           t->tsnap.snapPoint[2] + t->tsnap.snapNormal[2]);
+                               immEnd();
                        }
-                       
+
+                       immUnbindProgram();
+
                        if (v3d->zbuf)
                                glEnable(GL_DEPTH_TEST);
                }
@@ -241,23 +247,29 @@ void drawSnapping(const struct bContext *C, TransInfo *t)
                        
                        glEnable(GL_BLEND);
                        
+                       unsigned pos = add_attrib(immVertexFormat(), "pos", GL_FLOAT, 2, KEEP_FLOAT);
+
+                       immBindBuiltinProgram(GPU_SHADER_3D_UNIFORM_COLOR);
+
                        for (p = t->tsnap.points.first; p; p = p->next) {
                                if (p == t->tsnap.selectedPoint) {
-                                       glColor4ubv(selectedCol);
+                                       immUniformColor4ubv(selectedCol);
                                }
                                else {
-                                       glColor4ubv(col);
+                                       immUniformColor4ubv(col);
                                }
                                
-                               ED_node_draw_snap(&ar->v2d, p->co, size, 0);
+                               ED_node_draw_snap(&ar->v2d, p->co, size, 0, pos);
                        }
                        
                        if (t->tsnap.status & POINT_INIT) {
-                               glColor4ubv(activeCol);
+                               immUniformColor4ubv(activeCol);
                                
-                               ED_node_draw_snap(&ar->v2d, t->tsnap.snapPoint, size, t->tsnap.snapNodeBorder);
+                               ED_node_draw_snap(&ar->v2d, t->tsnap.snapPoint, size, t->tsnap.snapNodeBorder, pos);
                        }
-                       
+
+                       immUnbindProgram();
+
                        glDisable(GL_BLEND);
                }
        }