diff options
author | Campbell Barton <ideasman42@gmail.com> | 2017-04-13 15:09:59 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2017-04-13 15:09:59 +0300 |
commit | 2128e26d86a8dcc25287de4bfc39f065fefd3ce3 (patch) | |
tree | e808dc1c06137d2a9a5640b4dc03ded33ec0fa5a | |
parent | b96777b3e152bb48f9f86effc3bd4510d17ef571 (diff) |
Draw Manager: initial lattice support
Still misses support for edit-mode selection & weight drawing.
-rw-r--r-- | source/blender/blenkernel/BKE_lattice_render.h | 37 | ||||
-rw-r--r-- | source/blender/blenkernel/CMakeLists.txt | 2 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/lattice.c | 3 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/lattice_render.c | 494 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/object_update.c | 13 | ||||
-rw-r--r-- | source/blender/blenloader/intern/readfile.c | 1 | ||||
-rw-r--r-- | source/blender/draw/intern/draw_cache.c | 27 | ||||
-rw-r--r-- | source/blender/draw/intern/draw_cache.h | 4 | ||||
-rw-r--r-- | source/blender/draw/modes/edit_lattice_mode.c | 47 | ||||
-rw-r--r-- | source/blender/draw/modes/object_mode.c | 72 | ||||
-rw-r--r-- | source/blender/makesdna/DNA_lattice_types.h | 1 |
11 files changed, 676 insertions, 25 deletions
diff --git a/source/blender/blenkernel/BKE_lattice_render.h b/source/blender/blenkernel/BKE_lattice_render.h new file mode 100644 index 00000000000..aceb5b5eace --- /dev/null +++ b/source/blender/blenkernel/BKE_lattice_render.h @@ -0,0 +1,37 @@ +/* + * ***** 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_LATTICE_RENDER_H__ +#define __BKE_LATTICE_RENDER_H__ + +/** \file BKE_lattice_render.h + * \ingroup bke + */ + +struct Batch; +struct Lattice; + +void BKE_lattice_batch_cache_dirty(struct Lattice *lt); +void BKE_lattice_batch_selection_dirty(struct Lattice *lt); +void BKE_lattice_batch_cache_clear(struct Lattice *lt); +void BKE_lattice_batch_cache_free(struct Lattice *lt); +struct Batch *BKE_lattice_batch_cache_get_all_edges(struct Lattice *lt); +struct Batch *BKE_lattice_batch_cache_get_all_verts(struct Lattice *lt); + +#endif /* __BKE_LATTICE_RENDER_H__ */ diff --git a/source/blender/blenkernel/CMakeLists.txt b/source/blender/blenkernel/CMakeLists.txt index 2d595e0e3c5..770e4ab3479 100644 --- a/source/blender/blenkernel/CMakeLists.txt +++ b/source/blender/blenkernel/CMakeLists.txt @@ -120,6 +120,7 @@ set(SRC intern/key.c intern/lamp.c intern/lattice.c + intern/lattice_render.c intern/library.c intern/library_idmap.c intern/library_query.c @@ -249,6 +250,7 @@ set(SRC BKE_key.h BKE_lamp.h BKE_lattice.h + BKE_lattice_render.h BKE_library.h BKE_library_idmap.h BKE_library_query.h diff --git a/source/blender/blenkernel/intern/lattice.c b/source/blender/blenkernel/intern/lattice.c index 104d1389428..c567f9b0d6f 100644 --- a/source/blender/blenkernel/intern/lattice.c +++ b/source/blender/blenkernel/intern/lattice.c @@ -57,6 +57,7 @@ #include "BKE_global.h" #include "BKE_key.h" #include "BKE_lattice.h" +#include "BKE_lattice_render.h" #include "BKE_library.h" #include "BKE_library_query.h" #include "BKE_library_remap.h" @@ -306,6 +307,8 @@ void BKE_lattice_free(Lattice *lt) { BKE_animdata_free(<->id, false); + BKE_lattice_batch_cache_free(lt); + MEM_SAFE_FREE(lt->def); if (lt->dvert) { BKE_defvert_array_free(lt->dvert, lt->pntsu * lt->pntsv * lt->pntsw); diff --git a/source/blender/blenkernel/intern/lattice_render.c b/source/blender/blenkernel/intern/lattice_render.c new file mode 100644 index 00000000000..9967daacb80 --- /dev/null +++ b/source/blender/blenkernel/intern/lattice_render.c @@ -0,0 +1,494 @@ +/* + * ***** 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. + * + * Contributor(s): Blender Foundation, Mike Erwin, Dalai Felinto + * + * ***** END GPL LICENSE BLOCK ***** + */ + +/** \file blender/blenkernel/intern/lattice_render.c + * \ingroup bke + * + * \brief Lattice API for render engines + */ + +#include "MEM_guardedalloc.h" + +#include "BLI_utildefines.h" +#include "BLI_math_vector.h" + +#include "DNA_curve_types.h" +#include "DNA_lattice_types.h" + +#include "BKE_customdata.h" +#include "BKE_DerivedMesh.h" +#include "BKE_editmesh.h" +#include "BKE_mesh.h" +#include "BKE_lattice_render.h" + +#include "bmesh.h" + +#include "GPU_batch.h" + +#define SELECT 1 + +/** + * TODO + * - 'DispList' is currently not used + * (we could avoid using since it will be removed) + */ + +/* ---------------------------------------------------------------------- */ +/* Lattice Interface, direct access to basic data. */ + +static int vert_tot(int u, int v, int w) +{ + if (u <= 0 || v <= 0 || w <= 0) { + return 0; + } + return u * v * w; +} + +static int edge_tot(int u, int v, int w) +{ + if (u <= 0 || v <= 0 || w <= 0) { + return 0; + } + return (((((u - 1) * v) + + ((v - 1) * u)) * w) + + ((w - 1) * (u * v))); +} + +static int lattice_render_verts_num_get(Lattice *lt) +{ + if (lt->editlatt) { + lt = lt->editlatt->latt; + } + + const int u = lt->pntsu; + const int v = lt->pntsv; + const int w = lt->pntsw; + + if ((lt->flag & LT_OUTSIDE) == 0) { + return vert_tot(u, v, w); + } + else { + /* TODO remove internal coords */ + return vert_tot(u, v, w); + } +} + +static int lattice_render_edges_num_get(Lattice *lt) +{ + if (lt->editlatt) { + lt = lt->editlatt->latt; + } + + const int u = lt->pntsu; + const int v = lt->pntsv; + const int w = lt->pntsw; + + if ((lt->flag & LT_OUTSIDE) == 0) { + return edge_tot(u, v, w); + } + else { + /* TODO remove internal coords */ + return edge_tot(u, v, w); + } +} + +/* ---------------------------------------------------------------------- */ +/* Lattice Interface, indirect, partially cached access to complex data. */ + +typedef struct LatticeRenderData { + int types; + + int totvert; + int totedge; + + struct { + int u_len, v_len, w_len; + } dims; + bool show_only_outside; + + struct EditLatt *edit_latt; + struct BPoint *bp; + + int actbp; +} LatticeRenderData; + +enum { + MR_DATATYPE_VERT = 1 << 0, + MR_DATATYPE_EDGE = 1 << 1, + MR_DATATYPE_OVERLAY = 1 << 2, +}; + +static LatticeRenderData *lattice_render_data_create(Lattice *lt, const int types) +{ + LatticeRenderData *lrdata = MEM_callocN(sizeof(*lrdata), __func__); + lrdata->types = types; + + if (lt->editlatt) { + EditLatt *editlatt = lt->editlatt; + lt = editlatt->latt; + + lrdata->edit_latt = editlatt; + + if (types & (MR_DATATYPE_VERT)) { + lrdata->totvert = lattice_render_verts_num_get(lt); + } + if (types & (MR_DATATYPE_EDGE)) { + lrdata->totedge = lattice_render_edges_num_get(lt); + } + if (types & MR_DATATYPE_OVERLAY) { + lrdata->actbp = lt->actbp; + } + } + else { + if (types & (MR_DATATYPE_VERT)) { + lrdata->totvert = lattice_render_verts_num_get(lt); + lrdata->bp = lt->def; + } + if (types & (MR_DATATYPE_EDGE)) { + lrdata->totedge = lattice_render_edges_num_get(lt); + lrdata->bp = lt->def; + /*no edge data */ + } + } + + lrdata->dims.u_len = lt->pntsu; + lrdata->dims.v_len = lt->pntsv; + lrdata->dims.w_len = lt->pntsw; + + lrdata->show_only_outside = (lt->flag & LT_OUTSIDE) != 0; + + return lrdata; +} + +static void lattice_render_data_free(LatticeRenderData *lrdata) +{ +#if 0 + if (lrdata->loose_verts) { + MEM_freeN(lrdata->loose_verts); + } +#endif + MEM_freeN(lrdata); +} + +static int lattice_render_data_verts_num_get(const LatticeRenderData *lrdata) +{ + BLI_assert(lrdata->types & MR_DATATYPE_VERT); + return lrdata->totvert; +} + +static int lattice_render_data_edges_num_get(const LatticeRenderData *lrdata) +{ + BLI_assert(lrdata->types & MR_DATATYPE_EDGE); + return lrdata->totedge; +} + +static float *lattice_render_data_vert_co(const LatticeRenderData *lrdata, const int vert_idx) +{ + BLI_assert(lrdata->types & MR_DATATYPE_VERT); + + if (lrdata->edit_latt) { + Lattice *lt = lrdata->edit_latt->latt; + BPoint *bp = <->def[vert_idx]; + return bp->vec; + } + else { + return lrdata->bp[vert_idx].vec; + } +} + +/* First 2 bytes are bit flags + * 3rd is for sharp edges + * 4rd is for creased edges */ +enum { + VFLAG_VERTEX_ACTIVE = 1 << 0, + VFLAG_VERTEX_SELECTED = 1 << 1, +}; + +#if 0 +static unsigned char lattice_render_data_vertex_flag(LatticeRenderData *lrdata, const int v) +{ + + unsigned char vflag = 0; + + if (lrdata->edit_latt) { + Lattice *lt = lrdata->edit_latt->latt; + BPoint *bp = <->def[v]; + + /* Current vertex */ + if (v == lrdata->actbp) { + vflag |= VFLAG_VERTEX_ACTIVE; + } + + if (bp->f1 & SELECT) { + vflag |= VFLAG_VERTEX_SELECTED; + } + } + + return vflag; +} +#endif + +/* ---------------------------------------------------------------------- */ +/* Lattice Batch Cache */ + +typedef struct LatticeBatchCache { + VertexBuffer *pos; + ElementList *edges; + + Batch *all_verts; + Batch *all_edges; + + /* settings to determine if cache is invalid */ + bool is_dirty; + + struct { + int u_len, v_len, w_len; + } dims; + bool show_only_outside; + + bool is_editmode; +} LatticeBatchCache; + +/* Batch cache management. */ + +static bool lattice_batch_cache_valid(Lattice *lt) +{ + LatticeBatchCache *cache = lt->batch_cache; + + if (cache == NULL) { + return false; + } + + if (cache->is_editmode != (lt->editlatt != NULL)) { + return false; + } + + if (cache->is_dirty == false) { + return true; + } + else { + if (cache->is_editmode) { + return false; + } + else if ((cache->dims.u_len != lt->pntsu) || + (cache->dims.v_len != lt->pntsv) || + (cache->dims.w_len != lt->pntsw) || + ((cache->show_only_outside != ((lt->flag & LT_OUTSIDE) != 0)))) + { + return false; + } + } + + return true; +} + +static void lattice_batch_cache_init(Lattice *lt) +{ + LatticeBatchCache *cache = lt->batch_cache; + + if (!cache) { + cache = lt->batch_cache = MEM_callocN(sizeof(*cache), __func__); + } + else { + memset(cache, 0, sizeof(*cache)); + } + + cache->dims.u_len = lt->pntsu; + cache->dims.v_len = lt->pntsv; + cache->dims.w_len = lt->pntsw; + cache->show_only_outside = (lt->flag & LT_OUTSIDE) != 0; + + cache->is_editmode = lt->editlatt != NULL; + + cache->is_dirty = false; +} + +static LatticeBatchCache *lattice_batch_cache_get(Lattice *lt) +{ + if (!lattice_batch_cache_valid(lt)) { + BKE_lattice_batch_cache_clear(lt); + lattice_batch_cache_init(lt); + } + return lt->batch_cache; +} + +void BKE_lattice_batch_cache_dirty(struct Lattice *lt) +{ + LatticeBatchCache *cache = lt->batch_cache; + if (cache) { + cache->is_dirty = true; + } +} + +void BKE_lattice_batch_selection_dirty(struct Lattice *lt) +{ + LatticeBatchCache *cache = lt->batch_cache; + if (cache) { + /* TODO Separate Flag vbo */ +#if 0 + if (cache->overlay_loose_verts) { + Batch_discard_all(cache->overlay_loose_verts); + cache->overlay_loose_verts = NULL; + } +#endif + } +} + +void BKE_lattice_batch_cache_clear(Lattice *lt) +{ + LatticeBatchCache *cache = lt->batch_cache; + if (!cache) { + return; + } + + BATCH_DISCARD_SAFE(cache->all_verts); + BATCH_DISCARD_SAFE(cache->all_edges); + + VERTEXBUFFER_DISCARD_SAFE(cache->pos); + ELEMENTLIST_DISCARD_SAFE(cache->edges); +} + +void BKE_lattice_batch_cache_free(Lattice *lt) +{ + BKE_lattice_batch_cache_clear(lt); + MEM_SAFE_FREE(lt->batch_cache); +} + +/* Batch cache usage. */ +static VertexBuffer *lattice_batch_cache_get_pos(LatticeRenderData *lrdata, LatticeBatchCache *cache) +{ + BLI_assert(lrdata->types & MR_DATATYPE_VERT); + + if (cache->pos == NULL) { + static VertexFormat format = { 0 }; + static unsigned pos_id; + if (format.attrib_ct == 0) { + /* initialize vertex format */ + pos_id = VertexFormat_add_attrib(&format, "pos", COMP_F32, 3, KEEP_FLOAT); + } + + const int vertex_ct = lattice_render_data_verts_num_get(lrdata); + + cache->pos = VertexBuffer_create_with_format(&format); + VertexBuffer_allocate_data(cache->pos, vertex_ct); + for (int i = 0; i < vertex_ct; ++i) { + VertexBuffer_set_attrib(cache->pos, pos_id, i, lattice_render_data_vert_co(lrdata, i)); + } + } + + return cache->pos; +} + +static ElementList *lattice_batch_cache_get_edges(LatticeRenderData *lrdata, LatticeBatchCache *cache) +{ + BLI_assert(lrdata->types & (MR_DATATYPE_VERT | MR_DATATYPE_EDGE)); + + if (cache->edges == NULL) { + printf("Caching edges in order...\n"); + const int vertex_ct = lattice_render_data_verts_num_get(lrdata); + const int edge_len = lattice_render_data_edges_num_get(lrdata); + int edge_len_real = 0; + + ElementListBuilder elb; + ElementListBuilder_init(&elb, PRIM_LINES, edge_len, vertex_ct); + +#define LATT_INDEX(u, v, w) \ + ((((w) * lrdata->dims.v_len + (v)) * lrdata->dims.u_len) + (u)) + + for (int w = 0; w < lrdata->dims.w_len; w++) { + int wxt = (w == 0 || w == lrdata->dims.w_len - 1); + for (int v = 0; v < lrdata->dims.v_len; v++) { + int vxt = (v == 0 || v == lrdata->dims.v_len - 1); + for (int u = 0; u < lrdata->dims.u_len; u++) { + int uxt = (u == 0 || u == lrdata->dims.u_len - 1); + + if (w && ((uxt || vxt) || !lrdata->show_only_outside)) { + add_line_vertices(&elb, LATT_INDEX(u, v, w - 1), LATT_INDEX(u, v, w)); + BLI_assert(edge_len_real <= edge_len); + edge_len_real++; + } + if (v && ((uxt || wxt) || !lrdata->show_only_outside)) { + add_line_vertices(&elb, LATT_INDEX(u, v - 1, w), LATT_INDEX(u, v, w)); + BLI_assert(edge_len_real <= edge_len); + edge_len_real++; + } + if (u && ((vxt || wxt) || !lrdata->show_only_outside)) { + add_line_vertices(&elb, LATT_INDEX(u - 1, v, w), LATT_INDEX(u, v, w)); + BLI_assert(edge_len_real <= edge_len); + edge_len_real++; + } + } + } + } + +#undef LATT_INDEX + + if (lrdata->show_only_outside) { + BLI_assert(edge_len_real <= edge_len); + } + else { + BLI_assert(edge_len_real == edge_len); + } + + cache->edges = ElementList_build(&elb); + } + + return cache->edges; +} + +Batch *BKE_lattice_batch_cache_get_all_edges(Lattice *lt) +{ + LatticeBatchCache *cache = lattice_batch_cache_get(lt); + + if (cache->all_edges == NULL) { + /* create batch from Lattice */ + LatticeRenderData *lrdata = lattice_render_data_create(lt, MR_DATATYPE_VERT | MR_DATATYPE_EDGE); + + cache->all_edges = Batch_create(PRIM_LINES, lattice_batch_cache_get_pos(lrdata, cache), + lattice_batch_cache_get_edges(lrdata, cache)); + + lattice_render_data_free(lrdata); + } + + return cache->all_edges; +} + +Batch *BKE_lattice_batch_cache_get_all_verts(Lattice *lt) +{ + LatticeBatchCache *cache = lattice_batch_cache_get(lt); + + if (cache->all_verts == NULL) { + /* create batch from DM */ + LatticeRenderData *lrdata = lattice_render_data_create(lt, MR_DATATYPE_VERT); + + cache->all_verts = Batch_create(PRIM_POINTS, lattice_batch_cache_get_pos(lrdata, cache), NULL); + + lattice_render_data_free(lrdata); + } + + return cache->all_verts; +} + +#undef MESH_RENDER_FUNCTION diff --git a/source/blender/blenkernel/intern/object_update.c b/source/blender/blenkernel/intern/object_update.c index 238f5f3b205..374da48c648 100644 --- a/source/blender/blenkernel/intern/object_update.c +++ b/source/blender/blenkernel/intern/object_update.c @@ -50,7 +50,6 @@ #include "BKE_key.h" #include "BKE_lamp.h" #include "BKE_lattice.h" -#include "BKE_mesh_render.h" #include "BKE_editmesh.h" #include "BKE_object.h" #include "BKE_particle.h" @@ -59,6 +58,9 @@ #include "BKE_material.h" #include "BKE_image.h" +#include "BKE_mesh_render.h" +#include "BKE_lattice_render.h" + #include "DEG_depsgraph.h" #define DEBUG_PRINT if (G.debug & G_DEBUG_DEPSGRAPH) printf @@ -342,8 +344,13 @@ void BKE_object_eval_uber_data(EvaluationContext *eval_ctx, BLI_assert(ob->type != OB_ARMATURE); BKE_object_handle_data_update(eval_ctx, scene, ob); - if (ob->type == OB_MESH) { - BKE_mesh_batch_cache_dirty(ob->data); + switch (ob->type) { + case OB_MESH: + BKE_mesh_batch_cache_dirty(ob->data); + break; + case OB_LATTICE: + BKE_lattice_batch_cache_dirty(ob->data); + break; } ob->recalc &= ~(OB_RECALC_DATA | OB_RECALC_TIME); diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c index c81d591af59..a1718b5d84d 100644 --- a/source/blender/blenloader/intern/readfile.c +++ b/source/blender/blenloader/intern/readfile.c @@ -4714,6 +4714,7 @@ static void direct_link_latt(FileData *fd, Lattice *lt) direct_link_dverts(fd, lt->pntsu*lt->pntsv*lt->pntsw, lt->dvert); lt->editlatt = NULL; + lt->batch_cache = NULL; lt->adt = newdataadr(fd, lt->adt); direct_link_animdata(fd, lt->adt); diff --git a/source/blender/draw/intern/draw_cache.c b/source/blender/draw/intern/draw_cache.c index 2cb5aa374fd..7d5e6c60adc 100644 --- a/source/blender/draw/intern/draw_cache.c +++ b/source/blender/draw/intern/draw_cache.c @@ -32,6 +32,7 @@ #include "BLI_math.h" #include "BKE_mesh_render.h" +#include "BKE_lattice_render.h" #include "GPU_batch.h" @@ -1531,6 +1532,32 @@ Batch *DRW_cache_mesh_verts_get(Object *ob) return surface; } +/* Lattice */ + +Batch *DRW_cache_lattice_verts_get(Object *ob) +{ + Batch *surface = NULL; + + BLI_assert(ob->type == OB_LATTICE); + + struct Lattice *lt = ob->data; + surface = BKE_lattice_batch_cache_get_all_verts(lt); + + return surface; +} + +Batch *DRW_cache_lattice_wire_get(Object *ob) +{ + Batch *surface = NULL; + + BLI_assert(ob->type == OB_LATTICE); + + struct Lattice *lt = ob->data; + surface = BKE_lattice_batch_cache_get_all_edges(lt); + + return surface; +} + #if 0 /* TODO */ struct Batch *DRW_cache_surface_material_get(Object *ob, int nr) { /* TODO */ diff --git a/source/blender/draw/intern/draw_cache.h b/source/blender/draw/intern/draw_cache.h index 26412c54c9c..eac6495e182 100644 --- a/source/blender/draw/intern/draw_cache.h +++ b/source/blender/draw/intern/draw_cache.h @@ -87,4 +87,8 @@ struct Batch *DRW_cache_mesh_surface_get(struct Object *ob); struct Batch *DRW_cache_mesh_surface_verts_get(struct Object *ob); struct Batch *DRW_cache_mesh_verts_get(struct Object *ob); +/* Lattice */ +struct Batch *DRW_cache_lattice_verts_get(struct Object *ob); +struct Batch *DRW_cache_lattice_wire_get(struct Object *ob); + #endif /* __DRAW_CACHE_H__ */
\ No newline at end of file diff --git a/source/blender/draw/modes/edit_lattice_mode.c b/source/blender/draw/modes/edit_lattice_mode.c index 473f9074536..ea6dbb65475 100644 --- a/source/blender/draw/modes/edit_lattice_mode.c +++ b/source/blender/draw/modes/edit_lattice_mode.c @@ -99,7 +99,8 @@ static struct { typedef struct g_data { /* This keeps the references of the shading groups for * easy access in EDIT_LATTICE_cache_populate() */ - DRWShadingGroup *group; + DRWShadingGroup *wire_shgrp; + DRWShadingGroup *vert_shgrp; } g_data; /* Transient data */ /* *********** FUNCTIONS *********** */ @@ -149,23 +150,16 @@ static void EDIT_LATTICE_cache_init(void *vedata) { /* Create a pass */ - DRWState state = DRW_STATE_WRITE_COLOR | DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_LESS | DRW_STATE_BLEND | DRW_STATE_WIRE; + DRWState state = DRW_STATE_WRITE_COLOR | DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_LESS | DRW_STATE_WIRE; psl->pass = DRW_pass_create("My Pass", state); - /* Create a shadingGroup using a function in draw_common.c or custom one */ - /* - * stl->g_data->group = shgroup_dynlines_uniform_color(psl->pass, ts.colorWire); - * -- or -- - * stl->g_data->group = DRW_shgroup_create(e_data.custom_shader, psl->pass); - */ - stl->g_data->group = DRW_shgroup_create(e_data.custom_shader, psl->pass); - - /* Uniforms need a pointer to it's value so be sure it's accessible at - * any given time (i.e. use static vars) */ - static float color[4] = {1.0f, 0.0f, 0.0f, 1.0}; - DRW_shgroup_uniform_vec4(stl->g_data->group, "color", color, 1); - } + stl->g_data->wire_shgrp = DRW_shgroup_create(e_data.custom_shader, psl->pass); + + DRW_shgroup_uniform_vec4(stl->g_data->wire_shgrp, "color", ts.colorWireEdit, 1); + stl->g_data->vert_shgrp = DRW_shgroup_create(e_data.custom_shader, psl->pass); + DRW_shgroup_uniform_vec4(stl->g_data->vert_shgrp, "color", ts.colorVertexSelect, 1); + } } /* Add geometry to shadingGroups. Execute for each objects */ @@ -173,15 +167,23 @@ static void EDIT_LATTICE_cache_populate(void *vedata, Object *ob) { EDIT_LATTICE_PassList *psl = ((EDIT_LATTICE_Data *)vedata)->psl; EDIT_LATTICE_StorageList *stl = ((EDIT_LATTICE_Data *)vedata)->stl; + const struct bContext *C = DRW_get_context(); + Scene *scene = CTX_data_scene(C); + Object *obedit = scene->obedit; - UNUSED_VARS(psl, stl); + UNUSED_VARS(psl); + + if (ob->type == OB_LATTICE) { + if (ob == obedit) { + /* Get geometry cache */ + struct Batch *geom; - if (ob->type == OB_MESH) { - /* Get geometry cache */ - struct Batch *geom = DRW_cache_mesh_surface_get(ob); + geom = DRW_cache_lattice_wire_get(ob); + DRW_shgroup_call_add(stl->g_data->wire_shgrp, geom, ob->obmat); - /* Add geom to a shading group */ - DRW_shgroup_call_add(stl->g_data->group, geom, ob->obmat); + geom = DRW_cache_lattice_verts_get(ob); + DRW_shgroup_call_add(stl->g_data->vert_shgrp, geom, ob->obmat); + } } } @@ -228,7 +230,8 @@ static void EDIT_LATTICE_draw_scene(void *vedata) * Mostly used for freeing shaders */ static void EDIT_LATTICE_engine_free(void) { - // DRW_SHADER_FREE_SAFE(custom_shader); + // Currently built-in, dont free + // DRW_SHADER_FREE_SAFE(e_data.custom_shader); } /* Create collection settings here. diff --git a/source/blender/draw/modes/object_mode.c b/source/blender/draw/modes/object_mode.c index 080ca7f3ead..6ea4774d624 100644 --- a/source/blender/draw/modes/object_mode.c +++ b/source/blender/draw/modes/object_mode.c @@ -170,6 +170,14 @@ typedef struct g_data{ DRWShadingGroup *outlines_select_group; DRWShadingGroup *outlines_transform; + /* Wire */ + DRWShadingGroup *wire; + DRWShadingGroup *wire_active; + DRWShadingGroup *wire_active_group; + DRWShadingGroup *wire_select; + DRWShadingGroup *wire_select_group; + DRWShadingGroup *wire_transform; + } g_data; /* Transient data */ static struct { @@ -385,6 +393,15 @@ static DRWShadingGroup *shgroup_outline(DRWPass *pass, const float col[4], struc return grp; } +/* currently same as 'shgroup_outline', new function to avoid confustion */ +static DRWShadingGroup *shgroup_wire(DRWPass *pass, const float col[4], struct GPUShader *sh) +{ + DRWShadingGroup *grp = DRW_shgroup_create(sh, pass); + DRW_shgroup_uniform_vec4(grp, "color", col, 1); + + return grp; +} + static void OBJECT_cache_init(void *vedata) { OBJECT_PassList *psl = ((OBJECT_Data *)vedata)->psl; @@ -614,10 +631,32 @@ static void OBJECT_cache_init(void *vedata) stl->g_data->camera_clip_points = shgroup_distance_lines_instance(psl->non_meshes, geom); stl->g_data->camera_mist_points = shgroup_distance_lines_instance(psl->non_meshes, geom); + } + + { + struct GPUShader *sh = GPU_shader_get_builtin_shader(GPU_SHADER_3D_UNIFORM_COLOR); + + /* Unselected */ + stl->g_data->wire = shgroup_wire(psl->non_meshes, ts.colorWire, sh); + + /* Select */ + stl->g_data->wire_select = shgroup_wire(psl->non_meshes, ts.colorSelect, sh); + stl->g_data->wire_select_group = shgroup_wire(psl->non_meshes, ts.colorGroupActive, sh); + + /* Transform */ + stl->g_data->wire_transform = shgroup_wire(psl->non_meshes, ts.colorTransform, sh); + + /* Active */ + stl->g_data->wire_active = shgroup_wire(psl->non_meshes, ts.colorActive, sh); + stl->g_data->wire_active_group = shgroup_wire(psl->non_meshes, ts.colorGroupActive, sh); + } + + { /* Lamps */ /* TODO * for now we create multiple times the same VBO with only lamp center coordinates * but ideally we would only create it once */ + struct Batch *geom; /* start with buflimit because we don't want stipples */ geom = DRW_cache_single_line_get(); @@ -659,9 +698,12 @@ static void OBJECT_cache_init(void *vedata) geom = DRW_cache_square_get(); stl->g_data->lamp_spot_blend_rect = shgroup_instance(psl->non_meshes, geom); + } + { /* -------- STIPPLES ------- */ /* TODO port to shader stipple */ + struct Batch *geom; /* Relationship Lines */ stl->g_data->relationship_lines = shgroup_dynlines_uniform_color(psl->non_meshes, ts.colorWire); @@ -1116,6 +1158,36 @@ static void OBJECT_cache_populate(void *vedata, Object *ob) } break; } + case OB_LATTICE: + { + Object *obedit = scene->obedit; + if (ob != obedit) { + struct Batch *geom = DRW_cache_lattice_wire_get(ob); + int theme_id = DRW_object_wire_theme_get(ob, sl, NULL); + + DRWShadingGroup *shgroup; + switch (theme_id) { + case TH_ACTIVE: + shgroup = stl->g_data->wire_active; + break; + case TH_SELECT: + shgroup = stl->g_data->wire_select; + break; + case TH_GROUP_ACTIVE: + shgroup = stl->g_data->wire_select_group; + break; + case TH_TRANSFORM: + shgroup = stl->g_data->wire_transform; + break; + default: + shgroup = stl->g_data->wire; + break; + } + + DRW_shgroup_call_add(shgroup, geom, ob->obmat); + } + break; + } case OB_LAMP: DRW_shgroup_lamp(stl, ob, sl); break; diff --git a/source/blender/makesdna/DNA_lattice_types.h b/source/blender/makesdna/DNA_lattice_types.h index 242d6f0feeb..28a401676fc 100644 --- a/source/blender/makesdna/DNA_lattice_types.h +++ b/source/blender/makesdna/DNA_lattice_types.h @@ -69,6 +69,7 @@ typedef struct Lattice { char vgroup[64]; /* multiply the influence, MAX_VGROUP_NAME */ struct EditLatt *editlatt; + void *batch_cache; } Lattice; /* ***************** LATTICE ********************* */ |