ClangFormat: apply to source, most of intern
[blender.git] / source / blender / blenkernel / intern / CCGSubSurf.h
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  */
16
17 #ifndef __CCGSUBSURF_H__
18 #define __CCGSUBSURF_H__
19
20 /** \file
21  * \ingroup bke
22  */
23
24 typedef void *CCGMeshHDL;
25 typedef void *CCGVertHDL;
26 typedef void *CCGEdgeHDL;
27 typedef void *CCGFaceHDL;
28
29 typedef struct CCGEdge CCGEdge;
30 typedef struct CCGFace CCGFace;
31 typedef struct CCGSubSurf CCGSubSurf;
32 typedef struct CCGVert CCGVert;
33
34 typedef struct CCGMeshIFC {
35   int vertUserSize, edgeUserSize, faceUserSize;
36   int numLayers;
37   int vertDataSize;
38   int simpleSubdiv;
39 } CCGMeshIFC;
40
41 /***/
42
43 typedef void *CCGAllocatorHDL;
44
45 typedef struct CCGAllocatorIFC {
46   void *(*alloc)(CCGAllocatorHDL a, int numBytes);
47   void *(*realloc)(CCGAllocatorHDL a, void *ptr, int newSize, int oldSize);
48   void (*free)(CCGAllocatorHDL a, void *ptr);
49   void (*release)(CCGAllocatorHDL a);
50 } CCGAllocatorIFC;
51
52 /* private, so we can allocate on the stack */
53 typedef struct _EHashIterator {
54   struct _EHash *eh;
55   int curBucket;
56   struct _EHEntry *curEntry;
57 } EHashIterator;
58
59 /***/
60
61 typedef enum {
62   eCCGError_None = 0,
63
64   eCCGError_InvalidSyncState,
65   eCCGError_InvalidValue,
66 } CCGError;
67
68 /***/
69
70 /* TODO(sergey): This actually depends on subsurf level as well. */
71 #define CCG_TASK_LIMIT 16
72
73 /***/
74
75 CCGSubSurf *ccgSubSurf_new(CCGMeshIFC *ifc,
76                            int subdivisionLevels,
77                            CCGAllocatorIFC *allocatorIFC,
78                            CCGAllocatorHDL allocator);
79 void ccgSubSurf_free(CCGSubSurf *ss);
80
81 CCGError ccgSubSurf_initFullSync(CCGSubSurf *ss);
82 CCGError ccgSubSurf_initPartialSync(CCGSubSurf *ss);
83 #ifdef WITH_OPENSUBDIV
84 CCGError ccgSubSurf_initOpenSubdivSync(CCGSubSurf *ss);
85 #endif
86
87 CCGError ccgSubSurf_syncVert(
88     CCGSubSurf *ss, CCGVertHDL vHDL, const void *vertData, int seam, CCGVert **v_r);
89 CCGError ccgSubSurf_syncEdge(CCGSubSurf *ss,
90                              CCGEdgeHDL eHDL,
91                              CCGVertHDL e_vHDL0,
92                              CCGVertHDL e_vHDL1,
93                              float crease,
94                              CCGEdge **e_r);
95 CCGError ccgSubSurf_syncFace(
96     CCGSubSurf *ss, CCGFaceHDL fHDL, int numVerts, CCGVertHDL *vHDLs, CCGFace **f_r);
97
98 CCGError ccgSubSurf_syncVertDel(CCGSubSurf *ss, CCGVertHDL vHDL);
99 CCGError ccgSubSurf_syncEdgeDel(CCGSubSurf *ss, CCGEdgeHDL eHDL);
100 CCGError ccgSubSurf_syncFaceDel(CCGSubSurf *ss, CCGFaceHDL fHDL);
101
102 CCGError ccgSubSurf_processSync(CCGSubSurf *ss);
103
104 CCGError ccgSubSurf_updateFromFaces(CCGSubSurf *ss, int lvl, CCGFace **faces, int numFaces);
105 CCGError ccgSubSurf_updateToFaces(CCGSubSurf *ss, int lvl, CCGFace **faces, int numFaces);
106 CCGError ccgSubSurf_updateNormals(CCGSubSurf *ss, CCGFace **faces, int numFaces);
107 CCGError ccgSubSurf_updateLevels(CCGSubSurf *ss, int lvl, CCGFace **faces, int numFaces);
108 CCGError ccgSubSurf_stitchFaces(CCGSubSurf *ss, int lvl, CCGFace **faces, int numFaces);
109
110 CCGError ccgSubSurf_setSubdivisionLevels(CCGSubSurf *ss, int subdivisionLevels);
111
112 CCGError ccgSubSurf_setAllowEdgeCreation(CCGSubSurf *ss,
113                                          int allowEdgeCreation,
114                                          float defaultCreaseValue,
115                                          void *defaultUserData);
116 void ccgSubSurf_getAllowEdgeCreation(CCGSubSurf *ss,
117                                      int *allowEdgeCreation_r,
118                                      float *defaultCreaseValue_r,
119                                      void *defaultUserData_r);
120
121 void ccgSubSurf_getUseAgeCounts(CCGSubSurf *ss,
122                                 int *useAgeCounts_r,
123                                 int *vertUserOffset_r,
124                                 int *edgeUserOffset_r,
125                                 int *faceUserOffset_r);
126 CCGError ccgSubSurf_setUseAgeCounts(
127     CCGSubSurf *ss, int useAgeCounts, int vertUserOffset, int edgeUserOffset, int faceUserOffset);
128
129 CCGError ccgSubSurf_setCalcVertexNormals(CCGSubSurf *ss, int useVertNormals, int normalDataOffset);
130 void ccgSubSurf_setAllocMask(CCGSubSurf *ss, int allocMask, int maskOffset);
131
132 void ccgSubSurf_setNumLayers(CCGSubSurf *ss, int numLayers);
133
134 /***/
135
136 int ccgSubSurf_getNumVerts(const CCGSubSurf *ss);
137 int ccgSubSurf_getNumEdges(const CCGSubSurf *ss);
138 int ccgSubSurf_getNumFaces(const CCGSubSurf *ss);
139
140 int ccgSubSurf_getSubdivisionLevels(const CCGSubSurf *ss);
141 int ccgSubSurf_getEdgeSize(const CCGSubSurf *ss);
142 int ccgSubSurf_getEdgeLevelSize(const CCGSubSurf *ss, int level);
143 int ccgSubSurf_getGridSize(const CCGSubSurf *ss);
144 int ccgSubSurf_getGridLevelSize(const CCGSubSurf *ss, int level);
145 int ccgSubSurf_getSimpleSubdiv(const CCGSubSurf *ss);
146
147 CCGVert *ccgSubSurf_getVert(CCGSubSurf *ss, CCGVertHDL v);
148 CCGVertHDL ccgSubSurf_getVertVertHandle(CCGVert *v);
149 int ccgSubSurf_getVertNumFaces(CCGVert *v);
150 CCGFace *ccgSubSurf_getVertFace(CCGVert *v, int index);
151 int ccgSubSurf_getVertNumEdges(CCGVert *v);
152 CCGEdge *ccgSubSurf_getVertEdge(CCGVert *v, int index);
153
154 int ccgSubSurf_getVertAge(CCGSubSurf *ss, CCGVert *v);
155 void *ccgSubSurf_getVertUserData(CCGSubSurf *ss, CCGVert *v);
156 void *ccgSubSurf_getVertData(CCGSubSurf *ss, CCGVert *v);
157 void *ccgSubSurf_getVertLevelData(CCGSubSurf *ss, CCGVert *v, int level);
158
159 CCGEdge *ccgSubSurf_getEdge(CCGSubSurf *ss, CCGEdgeHDL e);
160 CCGEdgeHDL ccgSubSurf_getEdgeEdgeHandle(CCGEdge *e);
161 int ccgSubSurf_getEdgeNumFaces(CCGEdge *e);
162 CCGFace *ccgSubSurf_getEdgeFace(CCGEdge *e, int index);
163 CCGVert *ccgSubSurf_getEdgeVert0(CCGEdge *e);
164 CCGVert *ccgSubSurf_getEdgeVert1(CCGEdge *e);
165 float ccgSubSurf_getEdgeCrease(CCGEdge *e);
166
167 int ccgSubSurf_getEdgeAge(CCGSubSurf *ss, CCGEdge *e);
168 void *ccgSubSurf_getEdgeUserData(CCGSubSurf *ss, CCGEdge *e);
169 void *ccgSubSurf_getEdgeDataArray(CCGSubSurf *ss, CCGEdge *e);
170 void *ccgSubSurf_getEdgeData(CCGSubSurf *ss, CCGEdge *e, int x);
171 void *ccgSubSurf_getEdgeLevelData(CCGSubSurf *ss, CCGEdge *e, int x, int level);
172
173 CCGFace *ccgSubSurf_getFace(CCGSubSurf *ss, CCGFaceHDL f);
174 CCGFaceHDL ccgSubSurf_getFaceFaceHandle(CCGFace *f);
175 int ccgSubSurf_getFaceNumVerts(CCGFace *f);
176 CCGVert *ccgSubSurf_getFaceVert(CCGFace *f, int index);
177 CCGEdge *ccgSubSurf_getFaceEdge(CCGFace *f, int index);
178 int ccgSubSurf_getFaceEdgeIndex(CCGFace *f, CCGEdge *e);
179
180 int ccgSubSurf_getFaceAge(CCGSubSurf *ss, CCGFace *f);
181 void *ccgSubSurf_getFaceUserData(CCGSubSurf *ss, CCGFace *f);
182 void *ccgSubSurf_getFaceCenterData(CCGFace *f);
183 void *ccgSubSurf_getFaceGridEdgeDataArray(CCGSubSurf *ss, CCGFace *f, int gridIndex);
184 void *ccgSubSurf_getFaceGridEdgeData(CCGSubSurf *ss, CCGFace *f, int gridIndex, int x);
185 void *ccgSubSurf_getFaceGridDataArray(CCGSubSurf *ss, CCGFace *f, int gridIndex);
186 void *ccgSubSurf_getFaceGridData(CCGSubSurf *ss, CCGFace *f, int gridIndex, int x, int y);
187
188 int ccgSubSurf_getNumFinalVerts(const CCGSubSurf *ss);
189 int ccgSubSurf_getNumFinalEdges(const CCGSubSurf *ss);
190 int ccgSubSurf_getNumFinalFaces(const CCGSubSurf *ss);
191
192 /***/
193
194 typedef struct _EHashIterator CCGEdgeIterator;
195 typedef struct _EHashIterator CCGFaceIterator;
196 typedef struct _EHashIterator CCGVertIterator;
197
198 void ccgSubSurf_initVertIterator(CCGSubSurf *ss, CCGVertIterator *viter);
199 void ccgSubSurf_initEdgeIterator(CCGSubSurf *ss, CCGEdgeIterator *eiter);
200 void ccgSubSurf_initFaceIterator(CCGSubSurf *ss, CCGFaceIterator *fiter);
201
202 CCGVert *ccgVertIterator_getCurrent(CCGVertIterator *vi);
203 int ccgVertIterator_isStopped(CCGVertIterator *vi);
204 void ccgVertIterator_next(CCGVertIterator *vi);
205
206 CCGEdge *ccgEdgeIterator_getCurrent(CCGEdgeIterator *ei);
207 int ccgEdgeIterator_isStopped(CCGEdgeIterator *ei);
208 void ccgEdgeIterator_next(CCGEdgeIterator *ei);
209
210 CCGFace *ccgFaceIterator_getCurrent(CCGFaceIterator *fi);
211 int ccgFaceIterator_isStopped(CCGFaceIterator *fi);
212 void ccgFaceIterator_next(CCGFaceIterator *fi);
213
214 #ifdef WITH_OPENSUBDIV
215 struct DerivedMesh;
216
217 /* Check if topology changed and evaluators are to be re-created. */
218 void ccgSubSurf_checkTopologyChanged(CCGSubSurf *ss, struct DerivedMesh *dm);
219
220 /* Create topology refiner from give derived mesh which then later will be
221  * used for GL mesh creation.
222  */
223 void ccgSubSurf_prepareTopologyRefiner(CCGSubSurf *ss, struct DerivedMesh *dm);
224
225 /* Make sure GL mesh exists, up to date and ready to draw. */
226 bool ccgSubSurf_prepareGLMesh(CCGSubSurf *ss, bool use_osd_glsl, int active_uv_index);
227
228 /* Draw given partitions of the GL mesh.
229  *
230  * TODO(sergey): fill_quads is actually an invariant and should be part
231  * of the prepare routine.
232  */
233 void ccgSubSurf_drawGLMesh(CCGSubSurf *ss,
234                            bool fill_quads,
235                            int start_partition,
236                            int num_partitions);
237
238 /* Get number of base faces in a particular GL mesh. */
239 int ccgSubSurf_getNumGLMeshBaseFaces(CCGSubSurf *ss);
240
241 /* Get number of vertices in base faces in a particular GL mesh. */
242 int ccgSubSurf_getNumGLMeshBaseFaceVerts(CCGSubSurf *ss, int face);
243
244 /* Controls whether CCG are needed (Cmeaning CPU evaluation) or fully GPU compute
245  * and draw is allowed.
246  */
247 void ccgSubSurf_setSkipGrids(CCGSubSurf *ss, bool skip_grids);
248 bool ccgSubSurf_needGrids(CCGSubSurf *ss);
249
250 /* Set evaluator's face varying data from UV coordinates.
251  * Used for CPU evaluation.
252  */
253 void ccgSubSurf_evaluatorSetFVarUV(CCGSubSurf *ss, struct DerivedMesh *dm, int layer_index);
254
255 /* TODO(sergey): Temporary call to test things. */
256 void ccgSubSurf_evaluatorFVarUV(
257     CCGSubSurf *ss, int face_index, int S, float grid_u, float grid_v, float uv[2]);
258
259 void ccgSubSurf_free_osd_mesh(CCGSubSurf *ss);
260
261 void ccgSubSurf_getMinMax(CCGSubSurf *ss, float r_min[3], float r_max[3]);
262
263 void ccgSubSurf__sync_subdivUvs(CCGSubSurf *ss, bool subsurf_uvs);
264
265 #endif
266
267 #endif /* __CCGSUBSURF_H__ */