Commit: 677aa36632c6ed61815e9cbe04e317b290620b59
Author: Campbell Barton
Date:   Fri Apr 21 02:18:14 2017 +1000
Branches: blender2.8
https://developer.blender.org/rB677aa36632c6ed61815e9cbe04e317b290620b59

Curve: draw curve/surface/text geometry

Note that displists will be removed, but this wont be hard to replace.

Signed-off-by: Campbell Barton <ideasma...@gmail.com>

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

M       source/blender/blenkernel/BKE_curve_render.h
A       source/blender/blenkernel/BKE_displist_render.h
M       source/blender/blenkernel/CMakeLists.txt
M       source/blender/blenkernel/intern/curve_render.c
A       source/blender/blenkernel/intern/displist_render.c
M       source/blender/blenkernel/intern/object_update.c
M       source/blender/draw/engines/clay/clay.c
M       source/blender/draw/engines/eevee/eevee.c
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

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

diff --git a/source/blender/blenkernel/BKE_curve_render.h 
b/source/blender/blenkernel/BKE_curve_render.h
index 6c37b6e875b..79152c92979 100644
--- a/source/blender/blenkernel/BKE_curve_render.h
+++ b/source/blender/blenkernel/BKE_curve_render.h
@@ -37,4 +37,6 @@ struct Batch *BKE_curve_batch_cache_get_normal_edge(
 struct Batch *BKE_curve_batch_cache_get_overlay_edges(struct Curve *cu);
 struct Batch *BKE_curve_batch_cache_get_overlay_verts(struct Curve *cu);
 
+struct Batch *BKE_curve_batch_cache_get_triangles_with_normals(struct Curve 
*cu, struct CurveCache *ob_curve_cache);
+
 #endif /* __BKE_CURVE_RENDER_H__ */
diff --git a/source/blender/blenkernel/BKE_curve_render.h 
b/source/blender/blenkernel/BKE_displist_render.h
similarity index 53%
copy from source/blender/blenkernel/BKE_curve_render.h
copy to source/blender/blenkernel/BKE_displist_render.h
index 6c37b6e875b..0724bdd29cd 100644
--- a/source/blender/blenkernel/BKE_curve_render.h
+++ b/source/blender/blenkernel/BKE_displist_render.h
@@ -17,24 +17,17 @@
  *
  * ***** END GPL LICENSE BLOCK *****
  */
-#ifndef __BKE_CURVE_RENDER_H__
-#define __BKE_CURVE_RENDER_H__
+#ifndef __BKE_DISPLIST_RENDER_H__
+#define __BKE_DISPLIST_RENDER_H__
 
-/** \file BKE_curve_render.h
+/** \file BKE_displist_render.h
  *  \ingroup bke
  */
 
 struct Batch;
-struct Curve;
+struct ListBase;
+struct VertexBuffer;
 
-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_normal_edge(
-        struct Curve *cu, struct CurveCache *ob_curve_cache, float 
normal_size);
-struct Batch *BKE_curve_batch_cache_get_overlay_edges(struct Curve *cu);
-struct Batch *BKE_curve_batch_cache_get_overlay_verts(struct Curve *cu);
+struct Batch *BLI_displist_batch_calc_surface(struct ListBase *lb);
 
-#endif /* __BKE_CURVE_RENDER_H__ */
+#endif /* __BKE_DISPLIST_RENDER_H__ */
diff --git a/source/blender/blenkernel/CMakeLists.txt 
b/source/blender/blenkernel/CMakeLists.txt
index d8cba908f4a..fb35c08fd42 100644
--- a/source/blender/blenkernel/CMakeLists.txt
+++ b/source/blender/blenkernel/CMakeLists.txt
@@ -100,6 +100,7 @@ set(SRC
        intern/deform.c
        intern/depsgraph.c
        intern/displist.c
+       intern/displist_render.c
        intern/dynamicpaint.c
        intern/editderivedmesh.c
        intern/editmesh.c
@@ -233,6 +234,7 @@ set(SRC
        BKE_deform.h
        BKE_depsgraph.h
        BKE_displist.h
+       BKE_displist_render.h
        BKE_dynamicpaint.h
        BKE_editmesh.h
        BKE_editmesh_bvh.h
diff --git a/source/blender/blenkernel/intern/curve_render.c 
b/source/blender/blenkernel/intern/curve_render.c
index 0dcee01f9d7..0543d833fad 100644
--- a/source/blender/blenkernel/intern/curve_render.c
+++ b/source/blender/blenkernel/intern/curve_render.c
@@ -37,6 +37,8 @@
 #include "BKE_curve.h"
 #include "BKE_curve_render.h"
 
+#include "BKE_displist_render.h"
+
 #include "GPU_batch.h"
 
 #define SELECT   1
@@ -173,6 +175,8 @@ enum {
        CU_DATATYPE_OVERLAY     = 1 << 1,
        /* Edit-mode normals */
        CU_DATATYPE_NORMAL      = 1 << 2,
+       /* Geometry */
+       CU_DATATYPE_SURFACE     = 1 << 3,
 };
 
 /*
@@ -297,6 +301,10 @@ typedef struct CurveBatchCache {
                Batch *verts;
        } overlay;
 
+       struct {
+               Batch *batch;
+       } surface;
+
        /* settings to determine if cache is invalid */
        bool is_dirty;
 
@@ -410,6 +418,10 @@ void BKE_curve_batch_cache_clear(Curve *cu)
        BATCH_DISCARD_ALL_SAFE(cache->overlay.verts);
        BATCH_DISCARD_ALL_SAFE(cache->overlay.edges);
 
+       if (cache->surface.batch) {
+               BATCH_DISCARD_ALL_SAFE(cache->surface.batch);
+       }
+
        if (cache->wire.batch) {
                BATCH_DISCARD_ALL_SAFE(cache->wire.batch);
                cache->wire.verts = NULL;
@@ -759,6 +771,15 @@ static void curve_batch_cache_create_overlay_batches(Curve 
*cu)
        curve_render_data_free(rdata);
 }
 
+static Batch *curve_batch_cache_get_pos_and_normals(CurveRenderData *rdata, 
CurveBatchCache *cache)
+{
+       BLI_assert(rdata->types & CU_DATATYPE_SURFACE);
+       if (cache->surface.batch == NULL) {
+               cache->surface.batch = 
BLI_displist_batch_calc_surface(&rdata->ob_curve_cache->disp);
+       }
+       return cache->surface.batch;
+}
+
 Batch *BKE_curve_batch_cache_get_wire_edge(Curve *cu, CurveCache 
*ob_curve_cache)
 {
        CurveBatchCache *cache = curve_batch_cache_get(cu);
@@ -825,3 +846,19 @@ Batch *BKE_curve_batch_cache_get_overlay_verts(Curve *cu)
 
        return cache->overlay.verts;
 }
+
+struct Batch *BKE_curve_batch_cache_get_triangles_with_normals(
+        struct Curve *cu, struct CurveCache *ob_curve_cache)
+{
+       CurveBatchCache *cache = curve_batch_cache_get(cu);
+
+       if (cache->surface.batch == NULL) {
+               CurveRenderData *rdata = curve_render_data_create(cu, 
ob_curve_cache, CU_DATATYPE_SURFACE);
+
+               curve_batch_cache_get_pos_and_normals(rdata, cache);
+
+               curve_render_data_free(rdata);
+       }
+
+       return cache->surface.batch;
+}
diff --git a/source/blender/blenkernel/intern/displist_render.c 
b/source/blender/blenkernel/intern/displist_render.c
new file mode 100644
index 00000000000..01aa0c1217e
--- /dev/null
+++ b/source/blender/blenkernel/intern/displist_render.c
@@ -0,0 +1,167 @@
+/*
+ * ***** 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/displist_render.c
+ *  \ingroup bke
+ *
+ * \brief DispList API for render engines
+ *
+ * \note DispList may be removed soon! This is a utility for object types that 
use render.
+ */
+
+#include "MEM_guardedalloc.h"
+
+#include "BLI_utildefines.h"
+#include "BLI_math_vector.h"
+
+#include "DNA_curve_types.h"
+
+#include "BKE_displist.h"
+#include "BKE_displist_render.h"
+
+#include "GPU_batch.h"
+
+static int dl_vert_len(const DispList *dl)
+{
+       switch (dl->type) {
+               case DL_INDEX3:
+               case DL_INDEX4:
+                       return dl->nr;
+               case DL_SURF:
+                       return dl->parts * dl->nr;
+       }
+       return 0;
+}
+
+static int dl_tri_len(const DispList *dl)
+{
+       switch (dl->type) {
+               case DL_INDEX3:
+                       return dl->parts;
+               case DL_INDEX4:
+                       return dl->parts * 2;
+               case DL_SURF:
+                       return dl->totindex * 2;
+       }
+       return 0;
+}
+
+/* see: displist_get_allverts */
+static int curve_render_surface_vert_len_get(const ListBase *lb)
+{
+       int vert_len = 0;
+       for (const DispList *dl = lb->first; dl; dl = dl->next) {
+               vert_len += dl_vert_len(dl);
+       }
+       return vert_len;
+}
+
+static int curve_render_surface_tri_len_get(const ListBase *lb)
+{
+       int tri_len = 0;
+       for (const DispList *dl = lb->first; dl; dl = dl->next) {
+               tri_len += dl_tri_len(dl);
+       }
+       return tri_len;
+}
+
+Batch *BLI_displist_batch_calc_surface(ListBase *lb)
+{
+       const int tri_len = curve_render_surface_tri_len_get(lb);
+       if (tri_len == 0) {
+               return NULL;
+       }
+
+       static VertexFormat format = { 0 };
+       static unsigned int pos_id, nor_id;
+       if (format.attrib_ct == 0) {
+               /* initialize vertex format */
+               pos_id = VertexFormat_add_attrib(&format, "pos", COMP_F32, 3, 
KEEP_FLOAT);
+               nor_id = VertexFormat_add_attrib(&format, "nor", COMP_F32, 3, 
KEEP_FLOAT);
+       }
+
+       const int vert_len = curve_render_surface_vert_len_get(lb);
+       VertexBuffer *vbo = VertexBuffer_create_with_format(&format);
+       {
+               const int vbo_len_capacity = vert_len;
+               int vbo_len_used = 0;
+               VertexBuffer_allocate_data(vbo, vbo_len_capacity);
+
+               BKE_displist_normals_add(lb);
+
+               for (const DispList *dl = lb->first; dl; dl = dl->next) {
+                       const bool ndata_is_single = dl->type == DL_INDEX3;
+                       if (ELEM(dl->type, DL_INDEX3, DL_INDEX4, DL_SURF)) {
+                               const float *fp_co = dl->verts;
+                               const float *fp_no = dl->nors;
+                               const int vbo_end = vbo_len_used + 
dl_vert_len(dl);
+                               while (vbo_len_used < vbo_end) {
+                                       VertexBuffer_set_attrib(vbo, pos_id, 
vbo_len_used, fp_co);
+                                       if (fp_no) {
+                                               VertexBuffer_set_attrib(vbo, 
nor_id, vbo_len_used, fp_no);
+                                               if (ndata_is_single == false) {
+                                                       fp_no += 3;
+                                               }
+                                       }
+                                       fp_co += 3;
+                                       vbo_len_used += 1;
+                               }
+                       }
+               }
+       }
+
+       {
+               ElementListBuilder elb;
+               ElementListBuilder_init(&elb, PRIM_TRIANGLES, tri_len, 
vert_len);
+
+               int ofs = 0;
+               int tri_len_used = 0;
+               for (const DispList *dl = lb->first; dl; dl = dl->next) {
+                       if (ELEM(dl->type, DL_INDEX3, DL_INDEX4, DL_SURF)) {
+                               if (dl->type == DL_INDEX3) {
+                                       const int *idx = dl->index;
+                                       const int i_end = dl->parts;
+                                       for (int i = 0; i < i_end; i++) {
+                                               add_triangle_vertices(&elb, 
idx[0] + ofs, idx[1] + ofs, idx[2] + ofs);
+                                               tri_len_used += 1;
+                                               idx += 3;
+                                       }
+                               }
+                               else if (ELEM(dl->type, DL_INDEX4, DL_SURF)) {
+                                       const int *idx = dl->index;
+                                       const int i_end = dl->totindex;
+                                       for (int i = 0; i < i_end; i++) {
+                                               add_triangle_vertices(&elb, 
idx[0] + ofs, idx[1] + ofs, idx[2] + ofs);
+                                               tri_len_used += 1;
+                                               add_triangle_vertices(&elb, 
idx[0] + ofs, idx[2] + ofs, idx[3] + ofs);
+                                               tri_len_used += 1;
+                                               idx += 4;
+                                       }
+                               }
+                               ofs += dl_vert_len(dl);
+                       }
+               }
+
+               return Batch_create(PRIM_TRIANGLES, vbo, 
ElementList_build(&elb));
+       }
+}
diff --git a/source/blender/blenkernel/intern/object_update.c 
b/source/blender/blenkernel/intern/object_update.c
index 495857bc21b..3d9bbc338ea 100644
--- a/source/blender/blenkernel/intern/object_update.c
+++ b/source/blender/blenkernel/intern/object_update.c
@@ -353,6 +353,8 @@ void BKE_object_eval_uber

@@ Diff output truncated at 10240 characters. @@

_______________________________________________
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to