Blender  V3.3
CCGSubSurf_intern.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 
7 #pragma once
8 
13 /* Define this to see dump of the grids after the subsurf applied. */
14 #undef DUMP_RESULT_GRIDS
15 
16 /* used for normalize_v3 in BLI_math_vector
17  * float.h's FLT_EPSILON causes trouble with subsurf normals - campbell */
18 #define EPSILON (1.0e-35f)
19 
20 /* With this limit a single triangle becomes over 3 million faces */
21 #define CCGSUBSURF_LEVEL_MAX 11
22 
27 typedef unsigned char byte;
28 
33 typedef struct _EHEntry {
34  struct _EHEntry *next;
35  void *key;
37 
38 typedef struct _EHash {
41 
45 
46 typedef void (*EHEntryFreeFP)(EHEntry *, void *);
47 
48 #define EHASH_alloc(eh, nb) ((eh)->allocatorIFC.alloc((eh)->allocator, nb))
49 #define EHASH_free(eh, ptr) ((eh)->allocatorIFC.free((eh)->allocator, ptr))
50 #define EHASH_hash(eh, item) (((uintptr_t)(item)) % ((unsigned int)(eh)->curSize))
51 
52 /* Generic hash functions. */
53 
54 EHash *ccg_ehash_new(int estimatedNumEntries,
55  CCGAllocatorIFC *allocatorIFC,
56  CCGAllocatorHDL allocator);
57 void ccg_ehash_free(EHash *eh, EHEntryFreeFP freeEntry, void *userData);
58 void ccg_ehash_insert(EHash *eh, EHEntry *entry);
59 void *ccg_ehash_lookupWithPrev(EHash *eh, void *key, void ***prevp_r);
60 void *ccg_ehash_lookup(EHash *eh, void *key);
61 
62 /* Hash elements iteration. */
63 
68 
74 
79 /* TODO(sergey): Get rid of this, it's more or less a bad level call. */
80 struct DerivedMesh;
81 
82 /* ** Data structures, constants. enums ** */
83 
84 enum {
85  Vert_eEffected = (1 << 0),
86  Vert_eChanged = (1 << 1),
87  Vert_eSeam = (1 << 2),
88 } /*VertFlags*/;
89 
90 enum {
91  Edge_eEffected = (1 << 0),
92 } /*CCGEdgeFlags*/;
93 
94 enum {
95  Face_eEffected = (1 << 0),
96 } /*FaceFlags*/;
97 
98 struct CCGVert {
99  CCGVert *next; /* EHData.next */
100  CCGVertHDL vHDL; /* EHData.key */
101 
103  int osd_index; /* Index of the vertex in the map, used by OSD. */
104 
107  /* byte *levelData; */
108  /* byte *userData; */
109 };
110 
111 struct CCGEdge {
112  CCGEdge *next; /* EHData.next */
113  CCGEdgeHDL eHDL; /* EHData.key */
114 
115  short numFaces, flags;
116  float crease;
117 
120 
121  /* byte *levelData; */
122  /* byte *userData; */
123 };
124 
125 struct CCGFace {
126  CCGFace *next; /* EHData.next */
127  CCGFaceHDL fHDL; /* EHData.key */
128 
129  short numVerts, flags;
131 
132  /* CCGVert **verts; */
133  /* CCGEdge **edges; */
134  /* byte *centerData; */
135  /* byte **gridData; */
136  /* byte *userData; */
137 };
138 
139 typedef enum {
145 } SyncState;
146 
147 struct CCGSubSurf {
148  EHash *vMap; /* map of CCGVertHDL -> Vert */
149  EHash *eMap; /* map of CCGEdgeHDL -> Edge */
150  EHash *fMap; /* map of CCGFaceHDL -> Face */
151 
153 
156 
158  int numGrids;
162 
163  void *q, *r;
164 
165  /* Data for calc vert normals. */
168 
169  /* Data for paint masks. */
172 
173  /* Data for age'ing (to debug sync). */
179 
180  /* Data used during syncing. */
182 
187 };
188 
189 /* ** Utility macros ** */
190 
191 #define CCGSUBSURF_alloc(ss, nb) ((ss)->allocatorIFC.alloc((ss)->allocator, nb))
192 #define CCGSUBSURF_realloc(ss, ptr, nb, ob) \
193  ((ss)->allocatorIFC.realloc((ss)->allocator, ptr, nb, ob))
194 #define CCGSUBSURF_free(ss, ptr) ((ss)->allocatorIFC.free((ss)->allocator, ptr))
195 
196 #define VERT_getCo(v, lvl) ccg_vert_getCo(v, lvl, vertDataSize)
197 #define VERT_getNo(v, lvl) ccg_vert_getNo(v, lvl, vertDataSize, normalDataOffset)
198 #define EDGE_getCo(e, lvl, x) ccg_edge_getCo(e, lvl, x, vertDataSize)
199 #define EDGE_getNo(e, lvl, x) ccg_edge_getNo(e, lvl, x, vertDataSize, normalDataOffset)
200 #define FACE_getIFNo(f, lvl, S, x, y) \
201  ccg_face_getIFNo(f, lvl, S, x, y, subdivLevels, vertDataSize, normalDataOffset)
202 #if 0
203 # define FACE_calcIFNo(f, lvl, S, x, y, no) \
204  _face_calcIFNo(f, lvl, S, x, y, no, subdivLevels, vertDataSize)
205 #endif
206 #define FACE_getIENo(f, lvl, S, x) \
207  ccg_face_getIENo(f, lvl, S, x, subdivLevels, vertDataSize, normalDataOffset)
208 #define FACE_getIECo(f, lvl, S, x) ccg_face_getIECo(f, lvl, S, x, subdivLevels, vertDataSize)
209 #define FACE_getIFCo(f, lvl, S, x, y) ccg_face_getIFCo(f, lvl, S, x, y, subdivLevels, vertDataSize)
210 
211 #define NormZero(av) \
212  { \
213  float *_a = (float *)av; \
214  _a[0] = _a[1] = _a[2] = 0.0f; \
215  } \
216  (void)0
217 #define NormCopy(av, bv) \
218  { \
219  float *_a = (float *)av, *_b = (float *)bv; \
220  _a[0] = _b[0]; \
221  _a[1] = _b[1]; \
222  _a[2] = _b[2]; \
223  } \
224  (void)0
225 #define NormAdd(av, bv) \
226  { \
227  float *_a = (float *)av, *_b = (float *)bv; \
228  _a[0] += _b[0]; \
229  _a[1] += _b[1]; \
230  _a[2] += _b[2]; \
231  } \
232  (void)0
233 
234 /* ** General purpose functions ** */
235 
236 /* * CCGSubSurf.c * */
237 
238 void ccgSubSurf__allFaces(CCGSubSurf *ss, CCGFace ***faces, int *numFaces, int *freeFaces);
240  CCGFace **faces,
241  int numFaces,
242  CCGVert ***verts,
243  int *numVerts,
244  CCGEdge ***edges,
245  int *numEdges);
246 
247 /* * CCGSubSurf_legacy.c * */
248 
250 
251 /* * CCGSubSurf_opensubdiv.c * */
252 
254 
255 /* * CCGSubSurf_opensubdiv_converter.c * */
256 
257 struct OpenSubdiv_Converter;
258 
260  struct DerivedMesh *dm,
261  struct OpenSubdiv_Converter *converter);
262 
264 
266 
267 /* * CCGSubSurf_util.c * */
268 
269 #ifdef DUMP_RESULT_GRIDS
270 void ccgSubSurf__dumpCoords(CCGSubSurf *ss);
271 #endif
272 
273 #include "CCGSubSurf_inline.h"
void * CCGFaceHDL
Definition: CCGSubSurf.h:12
void * CCGEdgeHDL
Definition: CCGSubSurf.h:11
void * CCGVertHDL
Definition: CCGSubSurf.h:10
void * CCGAllocatorHDL
Definition: CCGSubSurf.h:28
void * ccg_ehash_lookupWithPrev(EHash *eh, void *key, void ***prevp_r)
unsigned char byte
void ccgSubSurf_converter_setup_from_ccg(CCGSubSurf *ss, struct OpenSubdiv_Converter *converter)
void ccgSubSurf__effectedFaceNeighbors(CCGSubSurf *ss, CCGFace **faces, int numFaces, CCGVert ***verts, int *numVerts, CCGEdge ***edges, int *numEdges)
Definition: CCGSubSurf.c:867
void ccgSubSurf__sync_opensubdiv(CCGSubSurf *ss)
struct _EHash EHash
void ccg_ehashIterator_init(EHash *eh, EHashIterator *ehi)
void ccg_ehashIterator_next(EHashIterator *ehi)
void * ccg_ehash_lookup(EHash *eh, void *key)
void ccg_ehash_insert(EHash *eh, EHEntry *entry)
void ccgSubSurf__allFaces(CCGSubSurf *ss, CCGFace ***faces, int *numFaces, int *freeFaces)
Definition: CCGSubSurf.c:842
EHash * ccg_ehash_new(int estimatedNumEntries, CCGAllocatorIFC *allocatorIFC, CCGAllocatorHDL allocator)
void ccg_ehash_free(EHash *eh, EHEntryFreeFP freeEntry, void *userData)
void * ccg_ehashIterator_getCurrent(EHashIterator *ehi)
int ccg_ehashIterator_isStopped(EHashIterator *ehi)
@ Edge_eEffected
CCGAllocatorIFC * ccg_getStandardAllocatorIFC(void)
struct _EHEntry EHEntry
@ eSyncState_Edge
@ eSyncState_Vert
@ eSyncState_Face
@ eSyncState_None
@ eSyncState_Partial
@ Vert_eChanged
@ Vert_eEffected
@ Vert_eSeam
@ Face_eEffected
void ccgSubSurf_converter_setup_from_derivedmesh(CCGSubSurf *ss, struct DerivedMesh *dm, struct OpenSubdiv_Converter *converter)
void(* EHEntryFreeFP)(EHEntry *, void *)
void ccgSubSurf_converter_free(struct OpenSubdiv_Converter *converter)
void ccgSubSurf__sync_legacy(CCGSubSurf *ss)
SyclQueue void void size_t num_bytes void
static float verts[][3]
static char faces[256]
CCGVert * v1
CCGFace ** faces
CCGVert * v0
CCGEdge * next
CCGEdgeHDL eHDL
CCGFace * next
CCGFaceHDL fHDL
CCGAllocatorIFC allocatorIFC
void * defaultEdgeUserData
SyncState syncState
CCGMeshIFC meshIFC
CCGEdge ** tempEdges
CCGAllocatorHDL allocator
CCGVert ** tempVerts
float defaultCreaseValue
CCGVertHDL vHDL
CCGFace ** faces
CCGEdge ** edges
CCGVert * next
struct _EHEntry * next
EHEntry ** buckets
CCGAllocatorIFC allocatorIFC
CCGAllocatorHDL allocator