[Bf-blender-cvs] [cdba73c8faf] blender2.8: Draw Manager: curve support
Campbell Barton
noreply at git.blender.org
Wed Apr 19 16:39:52 CEST 2017
Commit: cdba73c8faf7ec28de66b380ed2952d42a2aac38
Author: Campbell Barton
Date: Sat Apr 15 16:46:17 2017 +1000
Branches: blender2.8
https://developer.blender.org/rBcdba73c8faf7ec28de66b380ed2952d42a2aac38
Draw Manager: curve support
Draws the curve centerline and editmode verts/handles.
Handle theme colors, and normal display still need adding.
===================================================================
A source/blender/blenkernel/BKE_curve_render.h
M source/blender/blenkernel/CMakeLists.txt
M source/blender/blenkernel/intern/curve.c
A source/blender/blenkernel/intern/curve_render.c
M source/blender/blenkernel/intern/object_update.c
M source/blender/blenloader/intern/readfile.c
M source/blender/draw/CMakeLists.txt
M source/blender/draw/intern/draw_cache.c
M source/blender/draw/intern/draw_cache.h
M source/blender/draw/modes/edit_curve_mode.c
M source/blender/draw/modes/object_mode.c
A source/blender/draw/modes/shaders/edit_curve_overlay_frag.glsl
A source/blender/draw/modes/shaders/edit_curve_overlay_loosevert_vert.glsl
M source/blender/editors/space_view3d/space_view3d.c
M source/blender/makesdna/DNA_curve_types.h
===================================================================
diff --git a/source/blender/blenkernel/BKE_curve_render.h b/source/blender/blenkernel/BKE_curve_render.h
new file mode 100644
index 00000000000..f05dc691d06
--- /dev/null
+++ b/source/blender/blenkernel/BKE_curve_render.h
@@ -0,0 +1,38 @@
+/*
+ * ***** 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 *****
+ */
+#ifndef __BKE_CURVE_RENDER_H__
+#define __BKE_CURVE_RENDER_H__
+
+/** \file BKE_curve_render.h
+ * \ingroup bke
+ */
+
+struct Batch;
+struct Curve;
+
+void BKE_curve_batch_cache_dirty(struct Curve *cu);
+void BKE_curve_batch_selection_dirty(struct Curve *cu);
+void BKE_curve_batch_cache_clear(struct Curve *cu);
+void BKE_curve_batch_cache_free(struct Curve *cu);
+struct Batch *BKE_curve_batch_cache_get_wire_edge(struct Curve *cu, struct CurveCache *ob_curve_cache);
+struct Batch *BKE_curve_batch_cache_get_overlay_edges(struct Curve *cu);
+struct Batch *BKE_curve_batch_cache_get_overlay_verts(struct Curve *cu);
+
+#endif /* __BKE_CURVE_RENDER_H__ */
diff --git a/source/blender/blenkernel/CMakeLists.txt b/source/blender/blenkernel/CMakeLists.txt
index 770e4ab3479..d8cba908f4a 100644
--- a/source/blender/blenkernel/CMakeLists.txt
+++ b/source/blender/blenkernel/CMakeLists.txt
@@ -93,6 +93,7 @@ set(SRC
intern/context.c
intern/crazyspace.c
intern/curve.c
+ intern/curve_render.c
intern/customdata.c
intern/customdata_file.c
intern/data_transfer.c
@@ -225,6 +226,7 @@ set(SRC
BKE_context.h
BKE_crazyspace.h
BKE_curve.h
+ BKE_curve_render.h
BKE_customdata.h
BKE_customdata_file.h
BKE_data_transfer.h
diff --git a/source/blender/blenkernel/intern/curve.c b/source/blender/blenkernel/intern/curve.c
index 8a08c32f31b..10da97f5761 100644
--- a/source/blender/blenkernel/intern/curve.c
+++ b/source/blender/blenkernel/intern/curve.c
@@ -52,6 +52,7 @@
#include "BKE_animsys.h"
#include "BKE_curve.h"
+#include "BKE_curve_render.h"
#include "BKE_displist.h"
#include "BKE_font.h"
#include "BKE_global.h"
@@ -127,6 +128,8 @@ void BKE_curve_free(Curve *cu)
{
BKE_animdata_free((ID *)cu, false);
+ BKE_curve_batch_cache_free(cu);
+
BKE_nurbList_free(&cu->nurb);
BKE_curve_editfont_free(cu);
diff --git a/source/blender/blenkernel/intern/curve_render.c b/source/blender/blenkernel/intern/curve_render.c
new file mode 100644
index 00000000000..36ddbc48131
--- /dev/null
+++ b/source/blender/blenkernel/intern/curve_render.c
@@ -0,0 +1,641 @@
+/*
+ * ***** 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) 2017 by Blender Foundation.
+ * All rights reserved.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file blender/blenkernel/intern/curve_render.c
+ * \ingroup bke
+ *
+ * \brief Curve API for render engines
+ */
+
+#include "MEM_guardedalloc.h"
+
+#include "BLI_utildefines.h"
+#include "BLI_math_vector.h"
+
+#include "DNA_curve_types.h"
+
+#include "BKE_curve.h"
+#include "BKE_curve_render.h"
+
+#include "GPU_batch.h"
+
+#define SELECT 1
+
+/**
+ * TODO
+ * - Ensure `CurveCache`, `SEQUENCER_DAG_WORKAROUND`.
+ * - Check number of verts/edges to see if cache is valid.
+ * - Check if 'overlay_edges' can use single attribyte per edge, not 2 (for selection drawing).
+ */
+
+/* ---------------------------------------------------------------------- */
+/* Curve Interface, direct access to basic data. */
+
+static void curve_render_overlay_verts_edges_len_get(
+ ListBase *lb, bool hide_handles,
+ int *r_vert_len, int *r_edge_len)
+{
+ BLI_assert(r_vert_len || r_edge_len);
+ int vert_len = 0;
+ int edge_len = 0;
+ for (Nurb *nu = lb->first; nu; nu = nu->next) {
+ if (nu->bezt) {
+ vert_len += hide_handles ? nu->pntsu : (nu->pntsu * 3);
+ /* 2x handles per point*/
+ edge_len += 2 * nu->pntsu;
+ }
+ else if (nu->bp) {
+ vert_len += nu->pntsu;
+ /* segments between points */
+ edge_len += nu->pntsu - 1;
+ }
+ }
+ if (r_vert_len) {
+ *r_vert_len = vert_len;
+ }
+ if (r_edge_len) {
+ *r_edge_len = edge_len;
+ }
+}
+
+static void curve_render_wire_verts_edges_len_get(
+ const CurveCache *ob_curve_cache,
+ int *r_vert_len, int *r_edge_len)
+{
+ BLI_assert(r_vert_len || r_edge_len);
+ int vert_len = 0;
+ int edge_len = 0;
+ for (const BevList *bl = ob_curve_cache->bev.first; bl; bl = bl->next) {
+ if (bl->nr > 0) {
+ const bool is_cyclic = bl->poly != -1;
+
+ /* verts */
+ vert_len += bl->nr;
+
+ /* edges */
+ edge_len += bl->nr;
+ if (!is_cyclic) {
+ edge_len -= 1;
+ }
+ }
+ }
+ if (r_vert_len) {
+ *r_vert_len = vert_len;
+ }
+ if (r_edge_len) {
+ *r_edge_len = edge_len;
+ }
+}
+
+/* ---------------------------------------------------------------------- */
+/* Curve Interface, indirect, partially cached access to complex data. */
+
+typedef struct CurveRenderData {
+ int types;
+
+ struct {
+ int vert_len;
+ int edge_len;
+ } overlay;
+
+ struct {
+ int vert_len;
+ int edge_len;
+ } wire;
+
+ bool hide_handles;
+
+ /* borrow from 'Object' */
+ CurveCache *ob_curve_cache;
+
+ /* borrow from 'Curve' */
+ struct EditNurb *edit_latt;
+ ListBase *nurbs;
+
+ /* edit, index in nurb list */
+ int actnu;
+ /* edit, index in active nurb (BPoint or BezTriple) */
+ int actvert;
+} CurveRenderData;
+
+enum {
+ /* Wire center-line */
+ CU_DATATYPE_WIRE = 1 << 0,
+ /* Edit-mode verts and optionally handles */
+ CU_DATATYPE_OVERLAY = 1 << 1,
+};
+
+/*
+ * ob_curve_cache can be NULL, only needed for CU_DATATYPE_WIRE
+ */
+static CurveRenderData *curve_render_data_create(Curve *cu, CurveCache *ob_curve_cache, const int types)
+{
+ CurveRenderData *lrdata = MEM_callocN(sizeof(*lrdata), __func__);
+ lrdata->types = types;
+ ListBase *nurbs;
+
+ lrdata->hide_handles = (cu->drawflag & CU_HIDE_HANDLES) != 0;
+ lrdata->actnu = cu->actnu;
+ lrdata->actvert = cu->actvert;
+
+ lrdata->ob_curve_cache = ob_curve_cache;
+
+ if (types & CU_DATATYPE_WIRE) {
+ curve_render_wire_verts_edges_len_get(
+ lrdata->ob_curve_cache,
+ &lrdata->wire.vert_len, &lrdata->wire.edge_len);
+ }
+
+ if (cu->editnurb) {
+ EditNurb *editnurb = cu->editnurb;
+ nurbs = &editnurb->nurbs;
+
+ lrdata->edit_latt = editnurb;
+
+ if (types & CU_DATATYPE_OVERLAY) {
+ curve_render_overlay_verts_edges_len_get(
+ nurbs, lrdata->hide_handles,
+ &lrdata->overlay.vert_len,
+ lrdata->hide_handles ? NULL : &lrdata->overlay.edge_len);
+
+ lrdata->actnu = cu->actnu;
+ lrdata->actvert = cu->actvert;
+ }
+ }
+ else {
+ nurbs = &cu->nurb;
+ }
+
+ lrdata->nurbs = nurbs;
+
+ return lrdata;
+}
+
+static void curve_render_data_free(CurveRenderData *lrdata)
+{
+#if 0
+ if (lrdata->loose_verts) {
+ MEM_freeN(lrdata->loose_verts);
+ }
+#endif
+ MEM_freeN(lrdata);
+}
+
+static int curve_render_data_overlay_verts_len_get(const CurveRenderData *lrdata)
+{
+ BLI_assert(lrdata->types & CU_DATATYPE_OVERLAY);
+ return lrdata->overlay.vert_len;
+}
+
+static int curve_render_data_overlay_edges_len_get(const CurveRenderData *lrdata)
+{
+ BLI_assert(lrdata->types & CU_DATATYPE_OVERLAY);
+ return lrdata->overlay.edge_len;
+}
+
+static int curve_render_data_wire_verts_len_get(const CurveRenderData *lrdata)
+{
+ BLI_assert(lrdata->types & CU_DATATYPE_WIRE);
+ return lrdata->wire.vert_len;
+}
+
+static int curve_render_data_wire_edges_len_get(const CurveRenderData *lrdata)
+{
+ BLI_assert(lrdata->types & CU_DATATYPE_WIRE);
+ return lrdata->wire.edge_len;
+}
+
+#if 0
+static const BPoint *curve_render_data_vert_bpoint(const CurveRenderData *lrdata, const int vert_idx)
+{
+ BLI_assert(lrdata->types & CU_DATATYPE_VERT);
+ return &lrdata->bp[vert_idx];
+}
+#endif
+
+enum {
+ VFLAG_VERTEX_SELECTED = 1 << 0,
+ VFLAG_VERTEX_ACTIVE = 1 << 1,
+};
+
+/* ---------------------------------------------------------------------- */
+/* Curve Batch Cache */
+
+typedef struct CurveBatchCache {
+ VertexBuffer *wire_verts;
+ VertexBuffer *wire_edges;
+ Batch *wire_batch;
+
+ ElementList *wire_elem;
+
+ /* control handles and vertices */
+ Batch *overlay_edges;
+ Batch *overlay_verts;
+
+ /* settings to determine if cache is invalid */
+ bool is_dirty;
+
+ bool hide_handles;
+
+ bool is_editmode;
+} CurveBatchCache;
+
+/* Batch cache management. */
+
+static bool curve_batch_cache_valid(Curve *cu)
+{
+ CurveBatchCache *cache = cu->batch_cache;
+
+ if (cache == NULL) {
+ return false;
+ }
+
+ if (cache->is_editmode != (cu->editnurb != NULL)) {
+ return false;
+ }
+
+ if (cache->is_dirty == false) {
+ return true;
+ }
+ else {
+ /* TODO: check number of vertices/edges? */
+ if (cache->is_editmode) {
+ return false;
+ }
+ else if ((cache->hide_handles != ((cu->drawflag & CU_HIDE_HANDLES) != 0))) {
+ return false;
+ }
+ }
+
+ return true;
+}
+
+static void curve_batch_cache_init(Curve *cu)
+{
+ CurveBatchCache *cache = cu
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list