[Bf-blender-cvs] [693265e] transform-manipulators: Use more modern OpenGL for arrow manipulator drawing
Julian Eisel
noreply at git.blender.org
Thu Oct 20 22:11:45 CEST 2016
Commit: 693265e1e9b8c945ab748dab1619e65329a3b737
Author: Julian Eisel
Date: Thu Oct 20 21:12:34 2016 +0200
Branches: transform-manipulators
https://developer.blender.org/rB693265e1e9b8c945ab748dab1619e65329a3b737
Use more modern OpenGL for arrow manipulator drawing
Could/should do hings like sharing VBOs between manipulators, using own shader, use GPU_matrix API, etc but would need to figure out requirements some more first.
===================================================================
M source/blender/windowmanager/CMakeLists.txt
M source/blender/windowmanager/manipulators/intern/manipulator_library/arrow_manipulator.c
A source/blender/windowmanager/manipulators/intern/manipulator_library/geom_cone.c
A source/blender/windowmanager/manipulators/intern/manipulator_library/manipulator_geometry.h
M source/blender/windowmanager/manipulators/intern/manipulator_library/manipulator_library_intern.h
M source/blender/windowmanager/manipulators/intern/manipulator_library/manipulator_library_utils.c
M source/blender/windowmanager/manipulators/intern/wm_manipulator_intern.h
===================================================================
diff --git a/source/blender/windowmanager/CMakeLists.txt b/source/blender/windowmanager/CMakeLists.txt
index 03172d3..94b7d55 100644
--- a/source/blender/windowmanager/CMakeLists.txt
+++ b/source/blender/windowmanager/CMakeLists.txt
@@ -74,6 +74,7 @@ set(SRC
manipulators/intern/wm_manipulatorgroup.c
manipulators/intern/wm_manipulatormap.c
manipulators/intern/manipulator_library/arrow_manipulator.c
+ manipulators/intern/manipulator_library/geom_cone.c
manipulators/intern/manipulator_library/manipulator_library_utils.c
WM_api.h
@@ -92,6 +93,7 @@ set(SRC
manipulators/WM_manipulator_types.h
manipulators/wm_manipulator_wmapi.h
manipulators/intern/wm_manipulator_intern.h
+ manipulators/intern/manipulator_library/manipulator_geometry.h
manipulators/intern/manipulator_library/manipulator_library_intern.h
)
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 5d5e401..cc14699 100644
--- a/source/blender/windowmanager/manipulators/intern/manipulator_library/arrow_manipulator.c
+++ b/source/blender/windowmanager/manipulators/intern/manipulator_library/arrow_manipulator.c
@@ -34,6 +34,9 @@
#include "DNA_userdef_types.h"
#include "DNA_windowmanager_types.h"
+#include "GPU_basic_shader.h"
+#include "GPU_immediate.h"
+#include "GPU_matrix.h"
#include "GPU_select.h"
#include "MEM_guardedalloc.h"
@@ -42,6 +45,7 @@
#include "WM_types.h"
+#include "manipulator_geometry.h"
#include "manipulator_library_intern.h"
#include "WM_manipulator_types.h"
#include "wm_manipulator_wmapi.h"
@@ -55,49 +59,65 @@ typedef struct ArrowManipulator {
} ArrowManipulator;
-static void arrow_draw_geom(const ArrowManipulator *arrow, const bool UNUSED(select))
+static void arrow_draw_line(const ArrowManipulator *arrow, const float col[4], const float len)
{
- const float len = 1.0f; /* TODO arrow->len */
- const float vec[2][3] = {
- {0.0f, 0.0f, 0.0f},
- {0.0f, 0.0f, len},
- };
+ VertexFormat *format = immVertexFormat();
+ unsigned int pos = add_attrib(format, "pos", GL_FLOAT, 3, KEEP_FLOAT);
+
+ immBindBuiltinProgram(GPU_SHADER_3D_UNIFORM_COLOR);
+ immUniformColor4fv(col);
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);
+ immBegin(GL_LINES, 2);
+ immVertex3f(pos, 0.0f, 0.0f, 0.0f);
+ immVertex3f(pos, 0.0f, 0.0f, len);
+ immEnd();
- /* *** draw arrow head *** */
+ immUnbindProgram();
+}
- glPushMatrix();
+static void arrow_draw_cone(const bool select)
+{
+ const ManipulatorGeometryInfo cone_geo = {
+ _MANIPULATOR_nverts_Cone,
+ _MANIPULATOR_ntris_Cone,
+ _MANIPULATOR_verts_Cone,
+ _MANIPULATOR_normals_Cone,
+ _MANIPULATOR_indices_Cone,
+ true,
+ };
+ const float scale = 0.25f;
- const float head_len = 0.25f;
- const float width = 0.06f;
+ glScalef(scale, scale, scale);
+ wm_manipulator_geometryinfo_draw(&cone_geo, select);
+}
+
+static void arrow_draw_geom(const ArrowManipulator *arrow, const float col[4], const bool select)
+{
+ const float len = 1.0f; /* TODO arrow->len */
const bool use_lighting = /*select == false && ((U.manipulator_flag & V3D_SHADED_MANIPULATORS) != 0)*/ false;
+ glColor4fv(col);
+ glTranslate3fv(arrow->manipulator.offset);
+
+ arrow_draw_line(arrow, col, len);
+
+ /* *** draw arrow head *** */
+
/* translate to line end */
+ glPushMatrix();
glTranslatef(0.0f, 0.0f, len);
if (use_lighting) {
glShadeModel(GL_SMOOTH);
}
- GLUquadricObj *qobj = gluNewQuadric();
- gluQuadricDrawStyle(qobj, GLU_FILL);
- gluQuadricOrientation(qobj, GLU_INSIDE);
- gluDisk(qobj, 0.0, width, 8, 1);
- gluQuadricOrientation(qobj, GLU_OUTSIDE);
- gluCylinder(qobj, width, 0.0, head_len, 8, 1);
- gluDeleteQuadric(qobj);
+ arrow_draw_cone(select);
if (use_lighting) {
glShadeModel(GL_FLAT);
}
-
glPopMatrix();
}
@@ -124,16 +144,15 @@ static void arrow_draw_intern(const ArrowManipulator *arrow, const bool select,
glPushMatrix();
glMultMatrixf(mat);
- glColor4fv(col);
glEnable(GL_BLEND);
- glTranslate3fv(arrow->manipulator.offset);
- arrow_draw_geom(arrow, select);
+ arrow_draw_geom(arrow, col, select);
glDisable(GL_BLEND);
glPopMatrix();
if (arrow->manipulator.interaction_data) {
ManipulatorInteraction *inter = arrow->manipulator.interaction_data;
+ const float ghost_col[] = {0.5f, 0.5f, 0.5f, 0.5f};
copy_m4_m3(mat, rot);
copy_v3_v3(mat[3], inter->init_origin);
@@ -143,9 +162,7 @@ static void arrow_draw_intern(const ArrowManipulator *arrow, const bool select,
glMultMatrixf(mat);
glEnable(GL_BLEND);
- glColor4f(0.5f, 0.5f, 0.5f, 0.5f);
- glTranslate3fv(arrow->manipulator.offset);
- arrow_draw_geom(arrow, select);
+ arrow_draw_geom(arrow, ghost_col, select);
glDisable(GL_BLEND);
glPopMatrix();
diff --git a/source/blender/windowmanager/manipulators/intern/manipulator_library/geom_cone.c b/source/blender/windowmanager/manipulators/intern/manipulator_library/geom_cone.c
new file mode 100644
index 0000000..701bffa
--- /dev/null
+++ b/source/blender/windowmanager/manipulators/intern/manipulator_library/geom_cone.c
@@ -0,0 +1,71 @@
+/*
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file blender/windowmanager/manipulators/intern/manipulator_library/geom_cone.c
+ * \ingroup wm
+ */
+
+int _MANIPULATOR_nverts_Cone = 10;
+int _MANIPULATOR_ntris_Cone = 16;
+
+float _MANIPULATOR_verts_Cone[][3] = {
+ {0.000000, 0.000000, 0.000000},
+ {0.000000, 0.000000, 1.000000},
+ {0.000000, 0.270000, 0.000000},
+ {0.190919, 0.190919, 0.000000},
+ {0.270000, -0.000000, 0.000000},
+ {0.190919, -0.190919, 0.000000},
+ {-0.000000, -0.270000, 0.000000},
+ {-0.190919, -0.190919, 0.000000},
+ {-0.270000, 0.000000, 0.000000},
+ {-0.190919, 0.190919, 0.000000},
+};
+
+float _MANIPULATOR_normals_Cone[][3] = {
+ {0.000000, 0.000000, -1.000000},
+ {0.000000, 0.000000, 0.999969},
+ {0.000000, 0.848567, -0.529069},
+ {0.600024, 0.600024, -0.529069},
+ {0.848567, 0.000000, -0.529069},
+ {0.600024, -0.600024, -0.529069},
+ {0.000000, -0.848567, -0.529069},
+ {-0.600024, -0.600024, -0.529069},
+ {-0.848567, 0.000000, -0.529069},
+ {-0.600024, 0.600024, -0.529069},
+};
+
+unsigned short _MANIPULATOR_indices_Cone[] = {
+ 0, 2, 3,
+ 2, 1, 3,
+ 0, 3, 4,
+ 3, 1, 4,
+ 0, 4, 5,
+ 4, 1, 5,
+ 0, 5, 6,
+ 5, 1, 6,
+ 0, 6, 7,
+ 6, 1, 7,
+ 0, 7, 8,
+ 7, 1, 8,
+ 0, 8, 9,
+ 8, 1, 9,
+ 0, 9, 2,
+ 9, 1, 2,
+};
diff --git a/source/blender/windowmanager/manipulators/intern/manipulator_library/manipulator_geometry.h b/source/blender/windowmanager/manipulators/intern/manipulator_library/manipulator_geometry.h
new file mode 100644
index 0000000..2462bec
--- /dev/null
+++ b/source/blender/windowmanager/manipulators/intern/manipulator_library/manipulator_geometry.h
@@ -0,0 +1,49 @@
+/*
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) 2016 Blender Foundation.
+ * All rights reserved.
+ *
+ * Contributor(s): none yet.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file blender/windowmanager/manipulators/intern/manipulator_library/manipulator_geometry.h
+ * \ingroup wm
+ *
+ * \name Manipulator Geometry
+ *
+ * \brief Prototypes for arrays defining the manipulator geometry. The actual definitions can be found in files usually
+ * called geom_xxx.c
+ */
+
+
+#ifndef __MANIPULATOR_GEOMETRY_H__
+#define __MANIPULATOR_GEOMETRY_H__
+
+
+/* cone */
+extern int _MANIPULATOR_nverts_Cone;
+extern int _MANIPULATOR_ntris_Cone;
+
+extern float _MANIPULATOR_verts_Cone[][3];
+extern float _MANIPULATOR_normals_Cone[][3];
+extern unsigned short _MANIPULATOR_indices_Cone[];
+
+#endif /* __MANIPULATOR_GEOMETRY_H__ */
+
diff --git a/source/blender/windowmanager/manipulators/intern/manipulator_library/manipulator_library_intern.h b/source/blender/windowmanager/manipulators/intern/manipulator_library/manipulator_library_intern.h
index b1c0749..b790e3d 100644
--- a/source/blender/windowmanager/manipulators/intern/manipulator_library/manipulator_library_intern.h
+++ b/source/blender/windowmanager/manipulators/intern/manipulator_library/manipulator_library_intern.h
@@ -33,6 +33,23 @@
struct wmManipulator;
+/* -------------------------------------------------------------------- */
+/* Manipulator drawing */
+
+typedef struct ManipulatorGeometryInfo {
+ int nverts;
+ int ntris;
+ float (*verts)[3];
+ float (*normals)[3];
+ unsigned short *indices;
+ bool init;
+} ManipulatorGeometryInfo;
+
+void wm_manipulator_geometryinfo_draw(const ManipulatorGeometryInfo *info, const bool se
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list