Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2017-06-08 00:16:47 +0300
committerCampbell Barton <ideasman42@gmail.com>2017-06-08 00:42:17 +0300
commit7f480352caaa14a20c0438ae0ed1c2607b6c2c00 (patch)
tree6e938c6173a15d54c681458e361fd61b32fb8cf7 /source/blender/editors/manipulator_library/manipulator_draw_utils.c
parentbfa5efeebecb24d52bd63d79d6fc08518568f5e6 (diff)
WM: move manipulator library into editors
As with operators, the window-manager has the API for defining, the editor can implement and register its own manipulators. This exposes wmManipulator, keeping it opaque isn't practical if editors and Python are to implement their own.
Diffstat (limited to 'source/blender/editors/manipulator_library/manipulator_draw_utils.c')
-rw-r--r--source/blender/editors/manipulator_library/manipulator_draw_utils.c127
1 files changed, 127 insertions, 0 deletions
diff --git a/source/blender/editors/manipulator_library/manipulator_draw_utils.c b/source/blender/editors/manipulator_library/manipulator_draw_utils.c
new file mode 100644
index 00000000000..fc7b22ac0f0
--- /dev/null
+++ b/source/blender/editors/manipulator_library/manipulator_draw_utils.c
@@ -0,0 +1,127 @@
+/*
+ * ***** 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) 2014 Blender Foundation.
+ * All rights reserved.
+ *
+ * Contributor(s): Blender Foundation
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file manipulator_draw_utils.c
+ * \ingroup wm
+ */
+
+#include "BKE_context.h"
+
+#include "BLI_listbase.h"
+#include "BLI_ghash.h"
+#include "BLI_math.h"
+#include "BLI_string.h"
+#include "BLI_string_utils.h"
+
+#include "DNA_manipulator_types.h"
+
+#include "ED_screen.h"
+#include "ED_view3d.h"
+
+#include "GPU_batch.h"
+#include "GPU_glew.h"
+#include "GPU_immediate.h"
+
+#include "MEM_guardedalloc.h"
+
+#include "RNA_access.h"
+
+#include "WM_api.h"
+#include "WM_types.h"
+
+/* only for own init/exit calls (wm_manipulatortype_init/wm_manipulatortype_free) */
+#include "wm.h"
+
+/* own includes */
+#include "manipulator_library_intern.h"
+
+/**
+ * Main draw call for ManipulatorGeomInfo data
+ */
+void wm_manipulator_geometryinfo_draw(const ManipulatorGeomInfo *info, const bool select, const float color[4])
+{
+ /* TODO store the Batches inside the ManipulatorGeomInfo and updated it when geom changes
+ * So we don't need to re-created and discard it every time */
+
+ const bool use_lighting = true || (!select && ((U.manipulator_flag & V3D_SHADED_MANIPULATORS) != 0));
+ VertexBuffer *vbo;
+ ElementList *el;
+ Batch *batch;
+ ElementListBuilder elb = {0};
+
+ VertexFormat format = {0};
+ unsigned int pos_id = VertexFormat_add_attrib(&format, "pos", COMP_F32, 3, KEEP_FLOAT);
+ unsigned int nor_id;
+
+ if (use_lighting) {
+ nor_id = VertexFormat_add_attrib(&format, "nor", COMP_I16, 3, NORMALIZE_INT_TO_FLOAT);
+ }
+
+ /* Elements */
+ ElementListBuilder_init(&elb, PRIM_TRIANGLES, info->ntris, info->nverts);
+ for (int i = 0; i < info->ntris; ++i) {
+ const unsigned short *idx = &info->indices[i * 3];
+ add_triangle_vertices(&elb, idx[0], idx[1], idx[2]);
+ }
+ el = ElementList_build(&elb);
+
+ vbo = VertexBuffer_create_with_format(&format);
+ VertexBuffer_allocate_data(vbo, info->nverts);
+
+ VertexBuffer_fill_attrib(vbo, pos_id, info->verts);
+
+ if (use_lighting) {
+ /* Normals are expected to be smooth. */
+ VertexBuffer_fill_attrib(vbo, nor_id, info->normals);
+ }
+
+ batch = Batch_create(PRIM_TRIANGLES, vbo, el);
+ Batch_set_builtin_program(batch, GPU_SHADER_3D_UNIFORM_COLOR);
+
+ Batch_Uniform4fv(batch, "color", color);
+
+ glEnable(GL_CULL_FACE);
+ // glEnable(GL_DEPTH_TEST);
+
+ Batch_draw(batch);
+
+ glDisable(GL_DEPTH_TEST);
+ // glDisable(GL_CULL_FACE);
+
+
+ Batch_discard_all(batch);
+}
+
+void wm_manipulator_vec_draw(
+ const float color[4], const float (*verts)[3], unsigned int vert_count,
+ unsigned int pos, unsigned int primitive_type)
+{
+ immUniformColor4fv(color);
+ immBegin(primitive_type, vert_count);
+ for (int i = 0; i < vert_count; i++) {
+ immVertex3fv(pos, verts[i]);
+ }
+ immEnd();
+}