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:
authorGermano <germano.costa@ig.com.br>2017-11-16 20:12:32 +0300
committerGermano <germano.costa@ig.com.br>2017-11-16 20:12:32 +0300
commit88c88c4610260ef3d00420c3e9fc3c1cd56aad14 (patch)
treeb9e49f253fd37c773c2098b583019e2240655885 /source/blender/draw/intern
parent562da211c21bc57e35d7b2dba2f36c2472de90a2 (diff)
Fix T51210: Draw Manager: Support for Metaball Drawing
Differential Revision: D2914
Diffstat (limited to 'source/blender/draw/intern')
-rw-r--r--source/blender/draw/intern/draw_cache.c15
-rw-r--r--source/blender/draw/intern/draw_cache.h3
-rw-r--r--source/blender/draw/intern/draw_cache_impl.h6
-rw-r--r--source/blender/draw/intern/draw_cache_impl_displist.c26
-rw-r--r--source/blender/draw/intern/draw_cache_impl_metaball.c196
-rw-r--r--source/blender/draw/intern/draw_common.c13
-rw-r--r--source/blender/draw/intern/draw_common.h1
-rw-r--r--source/blender/draw/intern/draw_manager.c7
8 files changed, 255 insertions, 12 deletions
diff --git a/source/blender/draw/intern/draw_cache.c b/source/blender/draw/intern/draw_cache.c
index 13df65cf741..8010a232f89 100644
--- a/source/blender/draw/intern/draw_cache.c
+++ b/source/blender/draw/intern/draw_cache.c
@@ -507,6 +507,8 @@ Gwn_Batch *DRW_cache_object_surface_get(Object *ob)
return DRW_cache_surf_surface_get(ob);
case OB_FONT:
return DRW_cache_text_surface_get(ob);
+ case OB_MBALL:
+ return DRW_cache_mball_surface_get(ob);
default:
return NULL;
}
@@ -2336,6 +2338,19 @@ Gwn_Batch *DRW_cache_curve_surface_get(Object *ob)
/* -------------------------------------------------------------------- */
+/** \name MetaBall
+ * \{ */
+
+Gwn_Batch *DRW_cache_mball_surface_get(Object *ob)
+{
+ BLI_assert(ob->type == OB_MBALL);
+ return DRW_metaball_batch_cache_get_triangles_with_normals(ob);
+}
+
+/** \} */
+
+/* -------------------------------------------------------------------- */
+
/** \name Font
* \{ */
diff --git a/source/blender/draw/intern/draw_cache.h b/source/blender/draw/intern/draw_cache.h
index 54b840edfe6..35ac8f4a35d 100644
--- a/source/blender/draw/intern/draw_cache.h
+++ b/source/blender/draw/intern/draw_cache.h
@@ -157,4 +157,7 @@ struct Gwn_Batch *DRW_cache_particles_get_hair(struct ParticleSystem *psys, stru
struct Gwn_Batch *DRW_cache_particles_get_dots(struct ParticleSystem *psys);
struct Gwn_Batch *DRW_cache_particles_get_prim(int type);
+/* Metaball */
+struct Gwn_Batch *DRW_cache_mball_surface_get(struct Object *ob);
+
#endif /* __DRAW_CACHE_H__ */
diff --git a/source/blender/draw/intern/draw_cache_impl.h b/source/blender/draw/intern/draw_cache_impl.h
index 82972b9f75b..e0da2227a77 100644
--- a/source/blender/draw/intern/draw_cache_impl.h
+++ b/source/blender/draw/intern/draw_cache_impl.h
@@ -38,6 +38,9 @@ struct Lattice;
struct Mesh;
/* Expose via BKE callbacks */
+void DRW_mball_batch_cache_dirty(struct MetaBall *mb, int mode);
+void DRW_mball_batch_cache_free(struct MetaBall *mb);
+
void DRW_curve_batch_cache_dirty(struct Curve *cu, int mode);
void DRW_curve_batch_cache_free(struct Curve *cu);
@@ -59,6 +62,9 @@ struct Gwn_Batch *DRW_curve_batch_cache_get_overlay_verts(struct Curve *cu);
struct Gwn_Batch *DRW_curve_batch_cache_get_triangles_with_normals(struct Curve *cu, struct CurveCache *ob_curve_cache);
+/* Metaball */
+struct Gwn_Batch *DRW_metaball_batch_cache_get_triangles_with_normals(struct Object *ob);
+
/* Curve (Font) */
struct Gwn_Batch *DRW_curve_batch_cache_get_overlay_cursor(struct Curve *cu);
struct Gwn_Batch *DRW_curve_batch_cache_get_overlay_select(struct Curve *cu);
diff --git a/source/blender/draw/intern/draw_cache_impl_displist.c b/source/blender/draw/intern/draw_cache_impl_displist.c
index e051d61d056..96386f82faf 100644
--- a/source/blender/draw/intern/draw_cache_impl_displist.c
+++ b/source/blender/draw/intern/draw_cache_impl_displist.c
@@ -136,27 +136,31 @@ Gwn_Batch *BLI_displist_batch_calc_surface(ListBase *lb)
GWN_indexbuf_init(&elb, GWN_PRIM_TRIS, 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)) {
+ const int *idx = dl->index;
if (dl->type == DL_INDEX3) {
- const int *idx = dl->index;
const int i_end = dl->parts;
- for (int i = 0; i < i_end; i++) {
+ for (int i = 0; i < i_end; i++, idx += 3) {
GWN_indexbuf_add_tri_verts(&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;
+ else if (dl->type == DL_SURF) {
const int i_end = dl->totindex;
- for (int i = 0; i < i_end; i++) {
+ for (int i = 0; i < i_end; i++, idx += 4) {
GWN_indexbuf_add_tri_verts(&elb, idx[0] + ofs, idx[1] + ofs, idx[2] + ofs);
- tri_len_used += 1;
GWN_indexbuf_add_tri_verts(&elb, idx[0] + ofs, idx[2] + ofs, idx[3] + ofs);
- tri_len_used += 1;
- idx += 4;
+ }
+ }
+ else {
+ BLI_assert(dl->type == DL_INDEX4);
+ const int i_end = dl->parts;
+ for (int i = 0; i < i_end; i++, idx += 4) {
+ GWN_indexbuf_add_tri_verts(&elb, idx[0] + ofs, idx[1] + ofs, idx[2] + ofs);
+
+ if (idx[2] != idx[3]) {
+ GWN_indexbuf_add_tri_verts(&elb, idx[0] + ofs, idx[2] + ofs, idx[3] + ofs);
+ }
}
}
ofs += dl_vert_len(dl);
diff --git a/source/blender/draw/intern/draw_cache_impl_metaball.c b/source/blender/draw/intern/draw_cache_impl_metaball.c
new file mode 100644
index 00000000000..cf7d2f84133
--- /dev/null
+++ b/source/blender/draw/intern/draw_cache_impl_metaball.c
@@ -0,0 +1,196 @@
+/*
+ * ***** 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 draw_cache_impl_metaball.c
+ * \ingroup draw
+ *
+ * \brief MetaBall API for render engines
+ */
+
+#include "MEM_guardedalloc.h"
+
+#include "BLI_utildefines.h"
+
+#include "DNA_meta_types.h"
+#include "DNA_object_types.h"
+
+#include "BKE_curve.h"
+#include "BKE_mball.h"
+
+#include "GPU_batch.h"
+
+#include "draw_cache_impl.h" /* own include */
+
+
+static void metaball_batch_cache_clear(MetaBall *mb);
+
+/* ---------------------------------------------------------------------- */
+/* MetaBall Interface, indirect, partially cached access to complex data. */
+
+typedef struct MetaBallRenderData {
+ int types;
+
+ /* borrow from 'Object' */
+ CurveCache *ob_curve_cache;
+} MetaBallRenderData;
+
+enum {
+ /* Geometry */
+ MBALL_DATATYPE_SURFACE = 1 << 0,
+// MBALL_DATATYPE_WIRE = 1 << 1,
+// MBALL_DATATYPE_SHADING = 1 << 2,
+};
+
+static MetaBallRenderData *metaball_render_data_create(MetaBall *mb, CurveCache *ob_curve_cache, const int types)
+{
+ MetaBallRenderData *rdata = MEM_callocN(sizeof(*rdata), __func__);
+ rdata->types = types;
+ rdata->ob_curve_cache = ob_curve_cache;
+
+/*
+ **TODO**
+ if (types & MBALL_DATATYPE_WIRE) {}
+ if (types & MBALL_DATATYPE_SHADING) {}
+*/
+
+ return rdata;
+}
+
+static void metaball_render_data_free(MetaBallRenderData *rdata)
+{
+ MEM_freeN(rdata);
+}
+
+/* ---------------------------------------------------------------------- */
+/* MetaBall Gwn_Batch Cache */
+
+typedef struct MetaBallBatchCache {
+ Gwn_Batch *batch;
+
+ /* settings to determine if cache is invalid */
+ bool is_dirty;
+} MetaBallBatchCache;
+
+/* Gwn_Batch cache management. */
+
+static bool metaball_batch_cache_valid(MetaBall *mb)
+{
+ MetaBallBatchCache *cache = mb->batch_cache;
+
+ if (cache == NULL) {
+ return false;
+ }
+
+ return cache->is_dirty == false;
+}
+
+static void metaball_batch_cache_init(MetaBall *mb)
+{
+ MetaBallBatchCache *cache = mb->batch_cache;
+
+ if (!cache) {
+ cache = mb->batch_cache = MEM_mallocN(sizeof(*cache), __func__);
+ }
+ cache->batch = NULL;
+ cache->is_dirty = false;
+}
+
+static MetaBallBatchCache *metaball_batch_cache_get(MetaBall *mb)
+{
+ if (!metaball_batch_cache_valid(mb)) {
+ metaball_batch_cache_clear(mb);
+ metaball_batch_cache_init(mb);
+ }
+ return mb->batch_cache;
+}
+
+void DRW_mball_batch_cache_dirty(MetaBall *mb, int mode)
+{
+ MetaBallBatchCache *cache = mb->batch_cache;
+ if (cache == NULL) {
+ return;
+ }
+ switch (mode) {
+ case BKE_MBALL_BATCH_DIRTY_ALL:
+ cache->is_dirty = true;
+ break;
+ default:
+ BLI_assert(0);
+ }
+}
+
+static void metaball_batch_cache_clear(MetaBall *mb)
+{
+ MetaBallBatchCache *cache = mb->batch_cache;
+ if (!cache) {
+ return;
+ }
+
+ GWN_BATCH_DISCARD_SAFE(cache->batch);
+}
+
+void DRW_mball_batch_cache_free(MetaBall *mb)
+{
+ metaball_batch_cache_clear(mb);
+ MEM_SAFE_FREE(mb->batch_cache);
+}
+
+/* -------------------------------------------------------------------- */
+
+/** \name Private MetaBall Cache API
+ * \{ */
+
+/* Gwn_Batch cache usage. */
+
+static Gwn_Batch *metaball_batch_cache_get_pos_and_normals(MetaBallRenderData *rdata, MetaBallBatchCache *cache)
+{
+ BLI_assert(rdata->types & MBALL_DATATYPE_SURFACE);
+ if (cache->batch == NULL) {
+ cache->batch = BLI_displist_batch_calc_surface(&rdata->ob_curve_cache->disp);
+ }
+ return cache->batch;
+}
+
+/** \} */
+
+/* -------------------------------------------------------------------- */
+
+/** \name Public Object/MetaBall API
+ * \{ */
+
+Gwn_Batch *DRW_metaball_batch_cache_get_triangles_with_normals(Object *ob)
+{
+ if (!BKE_mball_is_basis(ob))
+ return NULL;
+
+ MetaBall *mb = ob->data;
+ MetaBallBatchCache *cache = metaball_batch_cache_get(mb);
+
+ if (cache->batch == NULL) {
+ MetaBallRenderData *rdata = metaball_render_data_create(mb, ob->curve_cache, MBALL_DATATYPE_SURFACE);
+ metaball_batch_cache_get_pos_and_normals(rdata, cache);
+ metaball_render_data_free(rdata);
+ }
+
+ return cache->batch;
+}
diff --git a/source/blender/draw/intern/draw_common.c b/source/blender/draw/intern/draw_common.c
index 125edcbc5d2..bb7b4d7d513 100644
--- a/source/blender/draw/intern/draw_common.c
+++ b/source/blender/draw/intern/draw_common.c
@@ -352,6 +352,19 @@ DRWShadingGroup *shgroup_instance_bone_envelope_solid(DRWPass *pass, struct Gwn_
return grp;
}
+DRWShadingGroup *shgroup_instance_mball_helpers(DRWPass *pass, struct Gwn_Batch *geom)
+{
+ GPUShader *sh = GPU_shader_get_builtin_shader(GPU_SHADER_3D_INSTANCE_MBALL_HELPERS);
+
+ DRWShadingGroup *grp = DRW_shgroup_instance_create(sh, pass, geom);
+ DRW_shgroup_attrib_float(grp, "ScaleTranslationMatrix", 12);
+ DRW_shgroup_attrib_float(grp, "radius", 1);
+ DRW_shgroup_attrib_float(grp, "color", 3);
+ DRW_shgroup_uniform_vec3(grp, "screen_vecs[0]", DRW_viewport_screenvecs_get(), 2);
+
+ return grp;
+}
+
/* ******************************************** COLOR UTILS *********************************************** */
diff --git a/source/blender/draw/intern/draw_common.h b/source/blender/draw/intern/draw_common.h
index 41f5abfcb65..51b7a25490f 100644
--- a/source/blender/draw/intern/draw_common.h
+++ b/source/blender/draw/intern/draw_common.h
@@ -104,6 +104,7 @@ struct DRWShadingGroup *shgroup_distance_lines_instance(struct DRWPass *pass, st
struct DRWShadingGroup *shgroup_spot_instance(struct DRWPass *pass, struct Gwn_Batch *geom);
struct DRWShadingGroup *shgroup_instance_bone_envelope_wire(struct DRWPass *pass, struct Gwn_Batch *geom, float (*obmat)[4]);
struct DRWShadingGroup *shgroup_instance_bone_envelope_solid(struct DRWPass *pass, struct Gwn_Batch *geom, float (*obmat)[4]);
+struct DRWShadingGroup *shgroup_instance_mball_helpers(struct DRWPass *pass, struct Gwn_Batch *geom);
int DRW_object_wire_theme_get(struct Object *ob, struct SceneLayer *scene_layer, float **r_color);
float *DRW_color_background_blend_get(int theme_id);
diff --git a/source/blender/draw/intern/draw_manager.c b/source/blender/draw/intern/draw_manager.c
index 275edb9bf42..672149b9e43 100644
--- a/source/blender/draw/intern/draw_manager.c
+++ b/source/blender/draw/intern/draw_manager.c
@@ -3483,7 +3483,6 @@ void DRW_draw_select_loop(
int obedit_mode = 0;
if (scene->obedit && scene->obedit->type == OB_MBALL) {
use_obedit = true;
- DRW_engines_cache_populate(scene->obedit);
obedit_mode = CTX_MODE_EDIT_METABALL;
}
else if ((scene->obedit && scene->obedit->type == OB_ARMATURE)) {
@@ -3790,6 +3789,9 @@ void DRW_engines_register(void)
/* setup callbacks */
{
+ /* BKE: mball.c */
+ extern void *BKE_mball_batch_cache_dirty_cb;
+ extern void *BKE_mball_batch_cache_free_cb;
/* BKE: curve.c */
extern void *BKE_curve_batch_cache_dirty_cb;
extern void *BKE_curve_batch_cache_free_cb;
@@ -3803,6 +3805,9 @@ void DRW_engines_register(void)
extern void *BKE_particle_batch_cache_dirty_cb;
extern void *BKE_particle_batch_cache_free_cb;
+ BKE_mball_batch_cache_dirty_cb = DRW_mball_batch_cache_dirty;
+ BKE_mball_batch_cache_free_cb = DRW_mball_batch_cache_free;
+
BKE_curve_batch_cache_dirty_cb = DRW_curve_batch_cache_dirty;
BKE_curve_batch_cache_free_cb = DRW_curve_batch_cache_free;