[Bf-blender-cvs] [ccc3c2d] master: CCGSubSurf: Split file into several smaller ones
Sergey Sharybin
noreply at git.blender.org
Mon Jul 20 22:30:50 CEST 2015
Commit: ccc3c2dbda36f00e74064e993d7e98bf8ab32a58
Author: Sergey Sharybin
Date: Mon Jul 20 15:05:16 2015 +0200
Branches: master
https://developer.blender.org/rBccc3c2dbda36f00e74064e993d7e98bf8ab32a58
CCGSubSurf: Split file into several smaller ones
This is a preparation commit for having OpenSubdiv integrated into Blender
and new layout is the following:
- CCGSubSurf.c contains implementation of common functions used by both
legacy subdivisions code and by the new code in the future.
- CCGSubSurf_inline.h contains internal functions which are to be inlined
due to the performance reasons. Those functions are only ment to be used
bu CCGSubSurf* files.
- CCGSubSurf_intern.h contains declarations of private functions and data
structures used by CCGSubSurf module.
- CCGSubSurf_legacy.c contains legacy implementation of subdivision algorithm.
- CCHSubSurf_util.c contains utility functions which are not directly related
on the subdivision code (i.e. debug functions, hash implementation etc).
There should be no functional changes so far.
===================================================================
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_util.c
===================================================================
diff --git a/source/blender/blenkernel/CMakeLists.txt b/source/blender/blenkernel/CMakeLists.txt
index 4f19c27..4b489a0 100644
--- a/source/blender/blenkernel/CMakeLists.txt
+++ b/source/blender/blenkernel/CMakeLists.txt
@@ -61,6 +61,8 @@ set(INC_SYS
set(SRC
intern/CCGSubSurf.c
+ intern/CCGSubSurf_legacy.c
+ intern/CCGSubSurf_util.c
intern/DerivedMesh.c
intern/action.c
intern/addon.c
@@ -285,6 +287,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 cadca6b..a60e1fa 100644
--- a/source/blender/blenkernel/intern/CCGSubSurf.c
+++ b/source/blender/blenkernel/intern/CCGSubSurf.c
@@ -30,222 +30,17 @@
#include "BLI_sys_types.h" // for intptr_t support
#include "BLI_utildefines.h" /* for BLI_assert */
+#include "BLI_math.h"
#include "BKE_ccg.h"
#include "CCGSubSurf.h"
+#include "CCGSubSurf_intern.h"
#include "BKE_subsurf.h"
-/* 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;
-}
+#include "GL/glew.h"
/***/
-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);
@@ -259,240 +54,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, pad;
-
- 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, pad1, pad2;
-
-// 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 edgeUserAgeOffset;
- int faceUserAgeOffset;
-
- /* data used during syncing */
- SyncState syncState;
-
- EHash *oldVMap, *oldEMap, *oldFMap;
- int lenTempArrays;
- CCGVert **tempVerts;
- CCGEdge **tempEdges;
-};
-
-#define CCGSUBSURF_alloc(ss, nb) ((ss)->allocatorIFC.alloc((ss)->allocator, nb))
-#define CCGSUBSURF_realloc(ss, ptr, nb, ob) ((ss)->allocatorIFC
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list