[Bf-blender-cvs] [383ed09] opensubdiv-modifier: OpenSubdiv: Initial wok over separation of legacy and new evaluators

Sergey Sharybin noreply at git.blender.org
Tue Jul 14 16:52:37 CEST 2015


Commit: 383ed09d3655d468e7e391a50993b97c1f1a0659
Author: Sergey Sharybin
Date:   Tue Jul 14 16:46:03 2015 +0200
Branches: opensubdiv-modifier
https://developer.blender.org/rB383ed09d3655d468e7e391a50993b97c1f1a0659

OpenSubdiv: Initial wok over separation of legacy and new evaluators

Since the CCGSubSurf.c file started to grow rather insanely and not being
possible at this moment to drop old evaluator it makes sense to split
evaluators into own files. This way code becomes a bit easier to follow,
plus in the future it should help isolating and removing code which is
no longer used.

Still some polishing is possible, but need to get started somewhere.

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

M	source/blender/blenkernel/CMakeLists.txt
M	source/blender/blenkernel/intern/CCGSubSurf.c
A	source/blender/blenkernel/intern/CCGSubSurf_inline.h
A	source/blender/blenkernel/intern/CCGSubSurf_intern.h
A	source/blender/blenkernel/intern/CCGSubSurf_legacy.c
A	source/blender/blenkernel/intern/CCGSubSurf_opensubdiv.c
A	source/blender/blenkernel/intern/CCGSubSurf_util.c

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

diff --git a/source/blender/blenkernel/CMakeLists.txt b/source/blender/blenkernel/CMakeLists.txt
index 5559ec3..3527f68 100644
--- a/source/blender/blenkernel/CMakeLists.txt
+++ b/source/blender/blenkernel/CMakeLists.txt
@@ -61,6 +61,9 @@ set(INC_SYS
 
 set(SRC
 	intern/CCGSubSurf.c
+	intern/CCGSubSurf_legacy.c
+	intern/CCGSubSurf_opensubdiv.c
+	intern/CCGSubSurf_util.c
 	intern/DerivedMesh.c
 	intern/action.c
 	intern/addon.c
@@ -285,6 +288,8 @@ set(SRC
 	nla_private.h
 	tracking_private.h
 	intern/CCGSubSurf.h
+	intern/CCGSubSurf_inline.h
+	intern/CCGSubSurf_intern.h
 	intern/pbvh_intern.h
 	intern/data_transfer_intern.h
 )
diff --git a/source/blender/blenkernel/intern/CCGSubSurf.c b/source/blender/blenkernel/intern/CCGSubSurf.c
index 248691f..77a2092 100644
--- a/source/blender/blenkernel/intern/CCGSubSurf.c
+++ b/source/blender/blenkernel/intern/CCGSubSurf.c
@@ -34,237 +34,17 @@
 
 #include "BKE_ccg.h"
 #include "CCGSubSurf.h"
+#include "CCGSubSurf_intern.h"
 #include "BKE_subsurf.h"
 
-#include "BKE_DerivedMesh.h"
-#include "BKE_subsurf.h"
-#include "BKE_global.h"
-#include "BKE_main.h"
-
-#include "DNA_userdef_types.h"
-#include "DNA_scene_types.h"
-
 #ifdef WITH_OPENSUBDIV
 #  include "opensubdiv_capi.h"
-//#  include <opensubdiv/osdutil/evaluator_capi.h>
 #endif
 
 #include "GL/glew.h"
 
-/* Define this to see dump of the grids after the subsurf applied. */
-#undef DUMP_RESULT_GRIDS
-
-/* used for normalize_v3 in BLI_math_vector
- * float.h's FLT_EPSILON causes trouble with subsurf normals - campbell */
-#define EPSILON (1.0e-35f)
-
-/* With this limit a single triangle becomes over 3 million faces */
-#define CCGSUBSURF_LEVEL_MAX 11
-
-/***/
-
-typedef unsigned char byte;
-
-/***/
-
-static int kHashSizes[] = {
-	1, 3, 5, 11, 17, 37, 67, 131, 257, 521, 1031, 2053, 4099, 8209, 
-	16411, 32771, 65537, 131101, 262147, 524309, 1048583, 2097169, 
-	4194319, 8388617, 16777259, 33554467, 67108879, 134217757, 268435459
-};
-
-typedef struct _EHEntry EHEntry;
-struct _EHEntry {
-	EHEntry *next;
-	void *key;
-};
-typedef struct _EHash {
-	EHEntry **buckets;
-	int numEntries, curSize, curSizeIdx;
-
-	CCGAllocatorIFC allocatorIFC;
-	CCGAllocatorHDL allocator;
-} EHash;
-
-#define EHASH_alloc(eh, nb)     ((eh)->allocatorIFC.alloc((eh)->allocator, nb))
-#define EHASH_free(eh, ptr)     ((eh)->allocatorIFC.free((eh)->allocator, ptr))
-
-#define EHASH_hash(eh, item)    (((uintptr_t) (item)) % ((unsigned int) (eh)->curSize))
-
-static void ccgSubSurf__sync(CCGSubSurf *ss);
-static int _edge_isBoundary(const CCGEdge *e);
-
-static EHash *_ehash_new(int estimatedNumEntries, CCGAllocatorIFC *allocatorIFC, CCGAllocatorHDL allocator)
-{
-	EHash *eh = allocatorIFC->alloc(allocator, sizeof(*eh));
-	eh->allocatorIFC = *allocatorIFC;
-	eh->allocator = allocator;
-	eh->numEntries = 0;
-	eh->curSizeIdx = 0;
-	while (kHashSizes[eh->curSizeIdx] < estimatedNumEntries)
-		eh->curSizeIdx++;
-	eh->curSize = kHashSizes[eh->curSizeIdx];
-	eh->buckets = EHASH_alloc(eh, eh->curSize * sizeof(*eh->buckets));
-	memset(eh->buckets, 0, eh->curSize * sizeof(*eh->buckets));
-
-	return eh;
-}
-typedef void (*EHEntryFreeFP)(EHEntry *, void *);
-static void _ehash_free(EHash *eh, EHEntryFreeFP freeEntry, void *userData)
-{
-	int numBuckets = eh->curSize;
-
-	while (numBuckets--) {
-		EHEntry *entry = eh->buckets[numBuckets];
-
-		while (entry) {
-			EHEntry *next = entry->next;
-
-			freeEntry(entry, userData);
-
-			entry = next;
-		}
-	}
-
-	EHASH_free(eh, eh->buckets);
-	EHASH_free(eh, eh);
-}
-
-static void _ehash_insert(EHash *eh, EHEntry *entry)
-{
-	int numBuckets = eh->curSize;
-	int hash = EHASH_hash(eh, entry->key);
-	entry->next = eh->buckets[hash];
-	eh->buckets[hash] = entry;
-	eh->numEntries++;
-
-	if (UNLIKELY(eh->numEntries > (numBuckets * 3))) {
-		EHEntry **oldBuckets = eh->buckets;
-		eh->curSize = kHashSizes[++eh->curSizeIdx];
-		
-		eh->buckets = EHASH_alloc(eh, eh->curSize * sizeof(*eh->buckets));
-		memset(eh->buckets, 0, eh->curSize * sizeof(*eh->buckets));
-
-		while (numBuckets--) {
-			for (entry = oldBuckets[numBuckets]; entry; ) {
-				EHEntry *next = entry->next;
-				
-				hash = EHASH_hash(eh, entry->key);
-				entry->next = eh->buckets[hash];
-				eh->buckets[hash] = entry;
-				
-				entry = next;
-			}
-		}
-
-		EHASH_free(eh, oldBuckets);
-	}
-}
-
-static void *_ehash_lookupWithPrev(EHash *eh, void *key, void ***prevp_r)
-{
-	int hash = EHASH_hash(eh, key);
-	void **prevp = (void **) &eh->buckets[hash];
-	EHEntry *entry;
-	
-	for (; (entry = *prevp); prevp = (void **) &entry->next) {
-		if (entry->key == key) {
-			*prevp_r = (void **) prevp;
-			return entry;
-		}
-	}
-	
-	return NULL;
-}
-
-static void *_ehash_lookup(EHash *eh, void *key)
-{
-	int hash = EHASH_hash(eh, key);
-	EHEntry *entry;
-	
-	for (entry = eh->buckets[hash]; entry; entry = entry->next)
-		if (entry->key == key)
-			break;
-	
-	return entry;
-}
-
-/**/
-
-static void _ehashIterator_init(EHash *eh, EHashIterator *ehi)
-{
-	/* fill all members */
-	ehi->eh = eh;
-	ehi->curBucket = -1;
-	ehi->curEntry = NULL;
-
-	while (!ehi->curEntry) {
-		ehi->curBucket++;
-		if (ehi->curBucket == ehi->eh->curSize)
-			break;
-		ehi->curEntry = ehi->eh->buckets[ehi->curBucket];
-	}
-}
-
-static void *_ehashIterator_getCurrent(EHashIterator *ehi)
-{
-	return ehi->curEntry;
-}
-
-static void _ehashIterator_next(EHashIterator *ehi)
-{
-	if (ehi->curEntry) {
-		ehi->curEntry = ehi->curEntry->next;
-		while (!ehi->curEntry) {
-			ehi->curBucket++;
-			if (ehi->curBucket == ehi->eh->curSize)
-				break;
-			ehi->curEntry = ehi->eh->buckets[ehi->curBucket];
-		}
-	}
-}
-static int _ehashIterator_isStopped(EHashIterator *ehi)
-{
-	return !ehi->curEntry;
-}
-
-/***/
-
-static void *_stdAllocator_alloc(CCGAllocatorHDL UNUSED(a), int numBytes)
-{
-	return MEM_mallocN(numBytes, "CCG standard alloc");
-}
-static void *_stdAllocator_realloc(CCGAllocatorHDL UNUSED(a), void *ptr, int newSize, int UNUSED(oldSize))
-{
-	return MEM_reallocN(ptr, newSize);
-}
-static void _stdAllocator_free(CCGAllocatorHDL UNUSED(a), void *ptr)
-{
-	MEM_freeN(ptr);
-}
-
-static CCGAllocatorIFC *_getStandardAllocatorIFC(void)
-{
-	static CCGAllocatorIFC ifc;
-
-	ifc.alloc = _stdAllocator_alloc;
-	ifc.realloc = _stdAllocator_realloc;
-	ifc.free = _stdAllocator_free;
-	ifc.release = NULL;
-
-	return &ifc;
-}
-
 /***/
 
-BLI_INLINE int ccg_gridsize(int level)
-{
-	BLI_assert(level > 0);
-	BLI_assert(level <= CCGSUBSURF_LEVEL_MAX + 1);
-
-	return (1 << (level - 1)) + 1;
-}
-
 int BKE_ccg_gridsize(int level)
 {
 	return ccg_gridsize(level);
@@ -278,259 +58,6 @@ int BKE_ccg_factor(int low_level, int high_level)
 	return 1 << (high_level - low_level);
 }
 
-BLI_INLINE int ccg_edgesize(int level)
-{
-	BLI_assert(level > 0);
-	BLI_assert(level <= CCGSUBSURF_LEVEL_MAX + 1);
-	
-	return 1 + (1 << level);
-}
-
-BLI_INLINE int ccg_spacing(int high_level, int low_level)
-{
-	BLI_assert(high_level > 0 && low_level > 0);
-	BLI_assert(high_level >= low_level);
-	BLI_assert((high_level - low_level) <= CCGSUBSURF_LEVEL_MAX);
-
-	return 1 << (high_level - low_level);
-}
-
-BLI_INLINE int ccg_edgebase(int level)
-{
-	BLI_assert(level > 0);
-	BLI_assert(level <= CCGSUBSURF_LEVEL_MAX + 1);
-
-	return level + (1 << level) - 1;
-}
-
-/***/
-
-#define NormZero(av)     { float *_a = (float *) av; _a[0] = _a[1] = _a[2] = 0.0f; } (void)0
-#define NormCopy(av, bv) { float *_a = (float *) av, *_b = (float *) bv; _a[0]  = _b[0]; _a[1]  = _b[1]; _a[2]  = _b[2]; } (void)0
-#define NormAdd(av, bv)  { float *_a = (float *) av, *_b = (float *) bv; _a[0] += _b[0]; _a[1] += _b[1]; _a[2] += _b[2]; } (void)0
-
-BLI_INLINE void Normalize(float no[3])
-{
-	const float length = sqrtf(no[0] * no[0] + no[1] * no[1] + no[2] * no[2]);
-
-	if (length > EPSILON) {
-		const float length_inv = 1.0f / length;
-
-		no[0] *= length_inv;
-		no[1] *= length_inv;
-		no[2] *= length_inv;
-	}
-	else {
-		NormZero(no);
-	}
-}
-
-/***/
-
-enum {
-	Vert_eEffected =    (1 << 0),
-	Vert_eChanged =     (1 << 1),
-	Vert_eSeam =        (1 << 2)
-} /*VertFlags*/;
-enum {
-	Edge_eEffected =    (1 << 0)
-} /*CCGEdgeFlags*/;
-enum {
-	Face_eEffected =    (1 << 0)
-} /*FaceFlags*/;
-
-struct CCGVert {
-	CCGVert     *next;  /* EHData.next */
-	CCGVertHDL vHDL;    /* EHData.key */
-
-	short numEdges, numFaces, flags;
-	int osd_index;  /* Index of the vertex in the map, used by OSD. */
-
-	CCGEdge **edges;
-	CCGFace **faces;
-//	byte *levelData;
-//	byte *userData;
-};
-
-BLI_INLINE byte *VERT_getLevelData(CCGVert *v)
-{
-	return (byte *)(&(v)[1]);
-}
-
-struct CCGEdge {
-	CCGEdge     *next;  /* EHData.next */
-	CCGEdgeHDL eHDL;    /* EHData.key */
-
-	short numFaces, flags;
-	float crease;
-
-	CCGVert *v0, *v1;
-	CCGFace **faces;
-
-//	byte *levelData;
-//	byte *userData;
-};
-
-BLI_INLINE byte *EDGE_getLevelData(CCGEdge *e)
-{
-	return (byte *)(&(e)[1]);
-}
-
-struct CCGFace {
-	CCGFace     *next;  /* EHData.next */
-	CCGFaceHDL fHDL;    /* EHData.key */
-
-	short numVerts, flags;
-	int osd_index;
-
-//	CCGVert **verts;
-//	CCGEdge **edges;
-//	byte *centerData;
-//	byte **gridData;
-//	byte *userData;
-};
-
-BLI_INLINE CCGVert **FACE_getVerts(CCGFace *f)
-{
-	return (CCGVert **)(&f[1]);
-}
-
-BLI_INLINE CCGEdge **FACE_getEdges(CCGFace *f)
-{
-	return (CCGEdge **)(&(FACE_getVerts(f)[f->numVerts]));
-}
-
-BLI_INLINE byte *FACE_getCenterData(CCGFace *f)
-{
-	return (byte *)(&(FACE_getEdges(f)[(f)->numVerts]));
-}
-
-typedef enum {
-	eSyncState_None = 0,
-	eSyncState_Vert,
-	eSyncState_Edge,
-	eSyncState_Face,
-	eSyncState_Partial
-} SyncState;
-
-struct CCGSubSurf {
-	EHash *vMap;    /* map of CCGVertHDL -> Vert */
-	EHash *eMap;    /* map of CCGEdgeHDL -> Edge */
-	EHash *fMap;    /* map of CCGFaceHDL -> Face */
-
-	CCGMeshIFC meshIFC;
-	
-	CCGAllocatorIFC allocatorIFC;
-	CCGAllocatorHDL allocator;
-
-	int subdivLevels;
-	int numGrids;
-	int allowEdgeCreation;
-	float defaultCreaseValue;
-	void *defaultEdgeUserData;
-
-	void *q, *r;
-		
-	/* data for calc vert normals */
-	int calcVertNormals;
-	int normalDataOffset;
-
-	/* data for paint masks */
-	int allocMask;
-	int maskDataOffset;
-
-	/* data for age'ing (to debug sync) */
-	int currentAge;
-	int useAgeCounts;
-	int vertUserAgeOffset;
-	int edgeUserA

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list