Commit: 70391ff991a8ddae24700ed861e4101b86ff937e
Author: Dalai Felinto
Date:   Fri Apr 7 10:58:18 2017 +0200
Branches: custom-manipulators
https://developer.blender.org/rB70391ff991a8ddae24700ed861e4101b86ff937e

OpenGL: Port arrow_manipulator.c to gawain

The conversion of wm_manipulator_geometryinfo_draw is still pending.

===================================================================

M       
source/blender/windowmanager/manipulators/intern/manipulator_library/arrow_manipulator.c

===================================================================

diff --git 
a/source/blender/windowmanager/manipulators/intern/manipulator_library/arrow_manipulator.c
 
b/source/blender/windowmanager/manipulators/intern/manipulator_library/arrow_manipulator.c
index 3fb5059cae5..b013f9f241b 100644
--- 
a/source/blender/windowmanager/manipulators/intern/manipulator_library/arrow_manipulator.c
+++ 
b/source/blender/windowmanager/manipulators/intern/manipulator_library/arrow_manipulator.c
@@ -101,20 +101,19 @@ static void manipulator_arrow_get_final_pos(wmManipulator 
*manipulator, float r_
 
 static void arrow_draw_geom(const ArrowManipulator *arrow, const bool select, 
const float color[4])
 {
-       /* USE_IMM for other arrow types */
-       glColor4fv(color);
-
        if (arrow->style & MANIPULATOR_ARROW_STYLE_CROSS) {
-               glPushAttrib(GL_ENABLE_BIT);
-               glDisable(GL_LIGHTING);
-               glBegin(GL_LINES);
-               glVertex2f(-1.0, 0.f);
-               glVertex2f(1.0, 0.f);
-               glVertex2f(0.f, -1.0);
-               glVertex2f(0.f, 1.0);
-               glEnd();
-
-               glPopAttrib();
+               immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
+               unsigned int pos = VertexFormat_add_attrib(immVertexFormat(), 
"pos", COMP_F32, 2, KEEP_FLOAT);
+               immUniformColor4fv(color);
+
+               immBegin(GL_LINES, 4);
+               immVertex2f(pos, -1.0, 0.f);
+               immVertex2f(pos, 1.0, 0.f);
+               immVertex2f(pos, 0.f, -1.0);
+               immVertex2f(pos, 0.f, 1.0);
+               immEnd();
+
+               immUnbindProgram();
        }
        else if (arrow->style & MANIPULATOR_ARROW_STYLE_CONE) {
                const float unitx = arrow->aspect[0];
@@ -126,29 +125,48 @@ static void arrow_draw_geom(const ArrowManipulator 
*arrow, const bool select, co
                        {-unitx,  unity, 0},
                };
 
+               unsigned int pos = VertexFormat_add_attrib(immVertexFormat(), 
"pos", COMP_F32, 3, KEEP_FLOAT);
+
+               immBindBuiltinProgram(GPU_SHADER_3D_UNIFORM_COLOR);
+               immUniformColor4fv(color);
+
                glLineWidth(arrow->manipulator.line_width);
-               glEnableClientState(GL_VERTEX_ARRAY);
-               glVertexPointer(3, GL_FLOAT, 0, vec);
-               glDrawArrays(GL_LINE_LOOP, 0, ARRAY_SIZE(vec));
-               glDisableClientState(GL_VERTEX_ARRAY);
+
+               const int vec_size = ARRAY_SIZE(vec);
+               immBegin(PRIM_LINE_STRIP, vec_size);
+               for (int i = 0; i < vec_size; i++) {
+                       immVertex3fv(pos, vec[i]);
+               }
+               immEnd();
+
                glLineWidth(1.0);
+               immUnbindProgram();
+
        }
        else {
 #ifdef USE_MANIPULATOR_CUSTOM_ARROWS
                
wm_manipulator_geometryinfo_draw(&wm_manipulator_geom_data_arrow, select);
 #else
+               unsigned int pos = VertexFormat_add_attrib(immVertexFormat(), 
"pos", COMP_F32, 3, KEEP_FLOAT);
+
+               immBindBuiltinProgram(GPU_SHADER_3D_CLIPPED_UNIFORM_COLOR);
+               immUniformColor4fv(color);
+
                const float vec[2][3] = {
                        {0.0f, 0.0f, 0.0f},
                        {0.0f, 0.0f, arrow->len},
                };
 
                glLineWidth(arrow->manipulator.line_width);
-               glEnableClientState(GL_VERTEX_ARRAY);
-               glVertexPointer(3, GL_FLOAT, 0, vec);
-               glDrawArrays(GL_LINE_STRIP, 0, ARRAY_SIZE(vec));
-               glDisableClientState(GL_VERTEX_ARRAY);
-               glLineWidth(1.0);
 
+               const int vec_size = ARRAY_SIZE(vec);
+               immBegin(PRIM_LINE_STRIP, vec_size);
+               for (int i = 0; i < vec_size; i++) {
+                       immVertex3fv(pos, vec[i]);
+               }
+               immEnd();
+
+               glLineWidth(1.0);
 
                /* *** draw arrow head *** */
 
@@ -163,6 +181,7 @@ static void arrow_draw_geom(const ArrowManipulator *arrow, 
const bool select, co
                        gpuScale3f(size, size, size);
 
                        /* draw cube */
+                       immUnbindProgram();
                        
wm_manipulator_geometryinfo_draw(&wm_manipulator_geom_data_cube, select);
                }
                else {
@@ -171,12 +190,8 @@ static void arrow_draw_geom(const ArrowManipulator *arrow, 
const bool select, co
                        const bool use_lighting = select == false && 
((U.manipulator_flag & V3D_SHADED_MANIPULATORS) != 0);
 
                        /* translate to line end */
-                       unsigned int pos = 
VertexFormat_add_attrib(immVertexFormat(), "pos", GL_FLOAT, 3, KEEP_FLOAT);
                        gpuTranslate3f(0.0f, 0.0f, arrow->len);
 
-                       immBindBuiltinProgram(GPU_SHADER_3D_UNIFORM_COLOR);
-                       immUniformColor4fv(color);
-
                        if (use_lighting) {
                                glShadeModel(GL_SMOOTH);
                        }
@@ -184,15 +199,15 @@ static void arrow_draw_geom(const ArrowManipulator 
*arrow, const bool select, co
                        imm_draw_circle_fill_3d(pos, 0.0, 0.0, width, 8);
                        imm_draw_cylinder_fill_3d(pos, width, 0.0, len, 8, 1);
 
-                       immUnbindProgram();
-
                        if (use_lighting) {
                                glShadeModel(GL_FLAT);
                        }
+                       immUnbindProgram();
                }
 
                gpuPopMatrix();
 
+
 #endif  /* USE_MANIPULATOR_CUSTOM_ARROWS */
        }
 }

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to