[Bf-blender-cvs] [636ed94] temp-derivedmesh-looptri: Move MLoopTri access behind API calls
Campbell Barton
noreply at git.blender.org
Thu Jul 16 16:09:42 CEST 2015
Commit: 636ed94ad50a2842c2e3293c5237abd1737049ce
Author: Campbell Barton
Date: Fri Jul 17 00:04:59 2015 +1000
Branches: temp-derivedmesh-looptri
https://developer.blender.org/rB636ed94ad50a2842c2e3293c5237abd1737049ce
Move MLoopTri access behind API calls
===================================================================
M source/blender/blenkernel/BKE_DerivedMesh.h
M source/blender/blenkernel/intern/DerivedMesh.c
M source/blender/blenkernel/intern/cdderivedmesh.c
M source/blender/blenkernel/intern/editderivedmesh.c
M source/blender/blenkernel/intern/subsurf_ccg.c
===================================================================
diff --git a/source/blender/blenkernel/BKE_DerivedMesh.h b/source/blender/blenkernel/BKE_DerivedMesh.h
index 81ccc5d..511e831 100644
--- a/source/blender/blenkernel/BKE_DerivedMesh.h
+++ b/source/blender/blenkernel/BKE_DerivedMesh.h
@@ -185,6 +185,9 @@ struct DerivedMesh {
int totmat; /* total materials. Will be valid only before object drawing. */
struct Material **mat; /* material array. Will be valid only before object drawing */
+ /**
+ * \warning Typical access is done via #getLoopTriArray, #getNumLoopTri.
+ */
struct {
struct MLoopTri *array;
int num;
@@ -207,7 +210,7 @@ struct DerivedMesh {
/** Recalculates mesh tessellation */
void (*recalcTessellation)(DerivedMesh *dm);
- void (*recalcLooptri)(DerivedMesh *dm);
+ void (*recalcLoopTri)(DerivedMesh *dm);
/* Misc. Queries */
@@ -238,6 +241,10 @@ struct DerivedMesh {
struct MLoop *(*getLoopArray)(DerivedMesh * dm);
struct MPoly *(*getPolyArray)(DerivedMesh * dm);
+ /** Loop tessellation cache */
+ const struct MLoopTri *(*getLoopTriArray)(DerivedMesh * dm);
+ int (*getNumLoopTri)(DerivedMesh *dm);
+
/** Copy all verts/edges/faces from the derived mesh into
* *{vert/edge/face}_r (must point to a buffer large enough)
*/
diff --git a/source/blender/blenkernel/intern/DerivedMesh.c b/source/blender/blenkernel/intern/DerivedMesh.c
index 94f3489..336a346 100644
--- a/source/blender/blenkernel/intern/DerivedMesh.c
+++ b/source/blender/blenkernel/intern/DerivedMesh.c
@@ -220,6 +220,11 @@ static MPoly *dm_dupPolyArray(DerivedMesh *dm)
return tmp;
}
+static int dm_getNumLoopTri(DerivedMesh *dm)
+{
+ return dm->looptris.num;
+}
+
static CustomData *dm_getVertCData(DerivedMesh *dm)
{
return &dm->vertData;
@@ -263,6 +268,9 @@ void DM_init_funcs(DerivedMesh *dm)
dm->dupLoopArray = dm_dupLoopArray;
dm->dupPolyArray = dm_dupPolyArray;
+ /* subtypes handle getting actual data */
+ dm->getNumLoopTri = dm_getNumLoopTri;
+
dm->getVertDataLayout = dm_getVertCData;
dm->getEdgeDataLayout = dm_getEdgeCData;
dm->getTessFaceDataLayout = dm_getTessFaceCData;
@@ -449,7 +457,9 @@ void DM_ensure_tessface(DerivedMesh *dm)
DM_ensure_looptri(dm);
}
-/* ensure the array is large enough */
+/**
+ * Ensure the array is large enough
+ */
void DM_ensure_looptri_data(DerivedMesh *dm)
{
const unsigned int totpoly = dm->numPolyData;
@@ -475,12 +485,16 @@ void DM_ensure_looptri_data(DerivedMesh *dm)
}
}
+/**
+ * The purpose of this function is that we can call:
+ * `dm->getLoopTriArray(dm)` and get the array returned.
+ */
void DM_ensure_looptri(DerivedMesh *dm)
{
const int numPolys = dm->getNumPolys(dm);
if ((dm->looptris.num == 0) && (numPolys != 0)) {
- dm->recalcLooptri(dm);
+ dm->recalcLoopTri(dm);
}
}
diff --git a/source/blender/blenkernel/intern/cdderivedmesh.c b/source/blender/blenkernel/intern/cdderivedmesh.c
index 549cc81..e66049a 100644
--- a/source/blender/blenkernel/intern/cdderivedmesh.c
+++ b/source/blender/blenkernel/intern/cdderivedmesh.c
@@ -837,7 +837,8 @@ static void cdDM_drawMappedFacesGLSL(
const MVert *mvert = cddm->mvert;
const MPoly *mpoly = cddm->mpoly;
const MLoop *mloop = cddm->mloop;
- const MLoopTri *lt = dm->looptris.array;
+ const MLoopTri *lt = dm->getLoopTriArray(dm);
+ const int tottri = dm->getNumLoopTri(dm);
/* MTFace *tf = dm->getTessFaceDataArray(dm, CD_MTFACE); */ /* UNUSED */
const float (*nors)[3] = dm->getPolyDataArray(dm, CD_NORMAL);
const float (*lnors)[3] = dm->getLoopDataArray(dm, CD_NORMAL);
@@ -878,7 +879,7 @@ static void cdDM_drawMappedFacesGLSL(
glBegin(GL_TRIANGLES);
- for (a = 0; a < dm->looptris.num; a++, lt++) {
+ for (a = 0; a < tottri; a++, lt++) {
const MPoly *mp = &mpoly[lt->poly];
const unsigned int vtri[3] = {mloop[lt->tri[0]].v, mloop[lt->tri[1]].v, mloop[lt->tri[2]].v};
const unsigned int *ltri = lt->tri;
@@ -1110,7 +1111,8 @@ static void cdDM_drawMappedFacesMat(
MVert *mvert = cddm->mvert;
const MPoly *mpoly = cddm->mpoly;
const MLoop *mloop = cddm->mloop;
- const MLoopTri *lt = dm->looptris.array;
+ const MLoopTri *lt = dm->getLoopTriArray(dm);
+ const int tottri = dm->getNumLoopTri(dm);
const float (*nors)[3] = dm->getPolyDataArray(dm, CD_NORMAL);
const float (*lnors)[3] = dm->getLoopDataArray(dm, CD_NORMAL);
int a, matnr, new_matnr;
@@ -1141,7 +1143,7 @@ static void cdDM_drawMappedFacesMat(
glBegin(GL_TRIANGLES);
- for (a = 0; a < dm->looptris.num; a++, lt++) {
+ for (a = 0; a < tottri; a++, lt++) {
const MPoly *mp = &mpoly[lt->poly];
const unsigned int vtri[3] = {mloop[lt->tri[0]].v, mloop[lt->tri[1]].v, mloop[lt->tri[2]].v};
const unsigned int *ltri = lt->tri;
@@ -1225,14 +1227,13 @@ static void cdDM_buffer_copy_triangles(
const int *mat_orig_to_new)
{
GPUBufferMaterial *gpumat;
- int i, tottri, findex = 0;
+ int i, findex = 0;
const MPoly *mpoly;
- const MLoopTri *lt;
+ const MLoopTri *lt = dm->getLoopTriArray(dm);
+ const int tottri = dm->getNumLoopTri(dm);
mpoly = dm->getPolyArray(dm);
- lt = dm->looptris.array;
- tottri = dm->looptris.num;
for (i = 0; i < tottri; i++, lt++) {
int start;
@@ -1892,6 +1893,19 @@ void CDDM_recalc_looptri(DerivedMesh *dm)
cddm->dm.looptris.array);
}
+static const MLoopTri *cdDM_getLoopTriArray(DerivedMesh *dm)
+{
+ if (dm->looptris.array) {
+ BLI_assert(poly_to_tri_count(dm->numPolyData, dm->numLoopData) == dm->looptris.num);
+ }
+ else {
+ dm->recalcLoopTri(dm);
+
+ /* ccdm is an exception here, that recalcLoopTri will fill in the array too */
+ }
+ return dm->looptris.array;
+}
+
static void cdDM_free_internal(CDDerivedMesh *cddm)
{
if (cddm->pmap) MEM_freeN(cddm->pmap);
@@ -1942,11 +1956,13 @@ static CDDerivedMesh *cdDM_create(const char *desc)
dm->getEdgeDataArray = DM_get_edge_data_layer;
dm->getTessFaceDataArray = DM_get_tessface_data_layer;
+ dm->getLoopTriArray = cdDM_getLoopTriArray;
+
dm->calcNormals = CDDM_calc_normals;
dm->calcLoopNormals = CDDM_calc_loop_normals;
dm->calcLoopNormalsSpaceArray = CDDM_calc_loop_normals_spacearr;
dm->recalcTessellation = CDDM_recalc_tessellation;
- dm->recalcLooptri = CDDM_recalc_looptri;
+ dm->recalcLoopTri = CDDM_recalc_looptri;
dm->getVertCos = cdDM_getVertCos;
dm->getVertCo = cdDM_getVertCo;
diff --git a/source/blender/blenkernel/intern/editderivedmesh.c b/source/blender/blenkernel/intern/editderivedmesh.c
index 58f2517..c1b4c70e 100644
--- a/source/blender/blenkernel/intern/editderivedmesh.c
+++ b/source/blender/blenkernel/intern/editderivedmesh.c
@@ -242,6 +242,47 @@ static void emDM_recalcTessellation(DerivedMesh *UNUSED(dm))
/* do nothing */
}
+static void emDM_recalcLoopTri(DerivedMesh *UNUSED(dm))
+{
+ /* Nothing to do: emDM tessellation is known,
+ * allocate and fill in with emDM_getLoopTriArray */
+}
+
+static const MLoopTri *emDM_getLoopTriArray(DerivedMesh *dm)
+{
+ if (dm->looptris.array) {
+ BLI_assert(poly_to_tri_count(dm->numPolyData, dm->numLoopData) == dm->looptris.num);
+ }
+ else {
+ EditDerivedBMesh *bmdm = (EditDerivedBMesh *)dm;
+ BMLoop *(*looptris)[3] = bmdm->em->looptris;
+ MLoopTri *mlooptri;
+ const int tottri = bmdm->em->tottri;
+ int i;
+
+ DM_ensure_looptri_data(dm);
+ mlooptri = dm->looptris.array;
+
+ BLI_assert(poly_to_tri_count(dm->numPolyData, dm->numLoopData) == dm->looptris.num);
+ BLI_assert(tottri == dm->looptris.num);
+
+ BM_mesh_elem_index_ensure(bmdm->em->bm, BM_FACE | BM_LOOP);
+
+ for (i = 0; i < tottri; i++) {
+ BMLoop **ltri = looptris[i];
+ MLoopTri *lt = &mlooptri[i];
+
+ ARRAY_SET_ITEMS(
+ lt->tri,
+ BM_elem_index_get(ltri[0]),
+ BM_elem_index_get(ltri[1]),
+ BM_elem_index_get(ltri[2]));
+ lt->poly = BM_elem_index_get(ltri[0]->f);
+ }
+ }
+ return dm->looptris.array;
+}
+
static void emDM_foreachMappedVert(
DerivedMesh *dm,
void (*func)(void *userData, int index, const float co[3], const float no_f[3], const short no_s[3]),
@@ -1794,6 +1835,8 @@ DerivedMesh *getEditDerivedBMesh(BMEditMesh *em,
bmdm->dm.getNumLoops = emDM_getNumLoops;
bmdm->dm.getNumPolys = emDM_getNumPolys;
+ bmdm->dm.getLoopTriArray = emDM_getLoopTriArray;
+
bmdm->dm.getVert = emDM_getVert;
bmdm->dm.getVertCo = emDM_getVertCo;
bmdm->dm.getVertNo = emDM_getVertNo;
@@ -1812,6 +1855,7 @@ DerivedMesh *getEditDerivedBMesh(BMEditMesh *em,
bmdm->dm.calcLoopNormals = emDM_calcLoopNormals;
bmdm->dm.calcLoopNormalsSpaceArray = emDM_calcLoopNormalsSpaceArray;
bmdm->dm.recalcTessellation = emDM_recalcTessellation;
+ bmdm->dm.recalcTessellation = emDM_recalcLoopTri;
bmdm->dm.foreachMappedVert = emDM_foreachMappedVert;
bmdm->dm.foreachMappedLoop = emDM_foreachMappedLoop;
diff --git a/source/blender/blenkernel/intern/subsurf_ccg.c b/source/blender/blenkernel/intern/subsurf_ccg.c
index 4c05367..0e5d043 100644
--- a/source/blender/blenkernel/intern/subsurf_ccg.c
+++ b/source/blender/blenkernel/intern/subsurf_ccg.c
@@ -3584,9 +3584,45 @@ static void ccgDM_recalcTessellation(DerivedMesh *UNUSED(dm))
/* Nothing to do: CCG handles creating its own tessfaces */
}
-static void ccgDM_recalcLooptri(DerivedMesh *UNUSED(dm))
+static void ccgDM_recalcLoopTri(DerivedMesh *UNUSED(dm))
{
- /* Nothing to do: CCG handles creating its own tessfaces */
+ /* Nothing to do: CCG tessellation is known,
+ * allocate and fill in with ccgDM_getLoopTriArray */
+}
+
+static const MLoopTri *ccgDM_getLoopTriArray(DerivedMesh *dm)
+{
+ if (dm->looptris.array) {
+ BLI_assert(poly_to_tri_count(dm->numPolyData, dm->numLoopData) == dm->looptris.num);
+ }
+ else {
+ MLoopTri *mlooptri;
+ const int tottri = dm->numTessFaceData * 2;
+ int i, poly_index;
+
+ DM_ensure_looptri_data(dm);
+ mlooptri = dm->looptris.array;
+
+ BLI_assert(poly_to_tri_count(dm->numPolyData, dm->numLoopData) == dm->looptris.num);
+ BLI_assert(tottri == dm->looptris.num);
+
+ for (i = 0, poly_index = 0; i < tottri; i += 2, poly_index += 1) {
+ MLoopTri *lt;
+ lt = &mlooptri[i];
+ /* quad is (0, 3, 2, 1) */
+ lt->tri[0] = (i * 4) + 0;
+ lt->tri[1] = (i * 4) + 3;
+ lt->tri[2] = (i * 4) + 2;
+ lt->poly = poly_index;
+
+ lt = &mlooptri[i + 1];
+ lt->tri[0] = (i * 4) + 0;
+ lt->tri[1] = (i *
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list