doxygen: add newline after \file
[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, int subdivisionLevels, CCGAllocatorIFC *allocatorIFC, CCGAllocatorHDL allocator);
76 void            ccgSubSurf_free (CCGSubSurf *ss);
77
78 CCGError        ccgSubSurf_initFullSync         (CCGSubSurf *ss);
79 CCGError        ccgSubSurf_initPartialSync      (CCGSubSurf *ss);
80 #ifdef WITH_OPENSUBDIV
81 CCGError        ccgSubSurf_initOpenSubdivSync   (CCGSubSurf *ss);
82 #endif
83
84 CCGError        ccgSubSurf_syncVert             (CCGSubSurf *ss, CCGVertHDL vHDL, const void *vertData, int seam, CCGVert **v_r);
85 CCGError        ccgSubSurf_syncEdge             (CCGSubSurf *ss, CCGEdgeHDL eHDL, CCGVertHDL e_vHDL0, CCGVertHDL e_vHDL1, float crease, CCGEdge **e_r);
86 CCGError        ccgSubSurf_syncFace             (CCGSubSurf *ss, CCGFaceHDL fHDL, int numVerts, CCGVertHDL *vHDLs, CCGFace **f_r);
87
88 CCGError        ccgSubSurf_syncVertDel  (CCGSubSurf *ss, CCGVertHDL vHDL);
89 CCGError        ccgSubSurf_syncEdgeDel  (CCGSubSurf *ss, CCGEdgeHDL eHDL);
90 CCGError        ccgSubSurf_syncFaceDel  (CCGSubSurf *ss, CCGFaceHDL fHDL);
91
92 CCGError        ccgSubSurf_processSync  (CCGSubSurf *ss);
93
94 CCGError        ccgSubSurf_updateFromFaces(CCGSubSurf *ss, int lvl, CCGFace **faces, int numFaces);
95 CCGError        ccgSubSurf_updateToFaces(CCGSubSurf *ss, int lvl, CCGFace **faces, int numFaces);
96 CCGError        ccgSubSurf_updateNormals(CCGSubSurf *ss, CCGFace **faces, int numFaces);
97 CCGError        ccgSubSurf_updateLevels(CCGSubSurf *ss, int lvl, CCGFace **faces, int numFaces);
98 CCGError        ccgSubSurf_stitchFaces(CCGSubSurf *ss, int lvl, CCGFace **faces, int numFaces);
99
100 CCGError        ccgSubSurf_setSubdivisionLevels         (CCGSubSurf *ss, int subdivisionLevels);
101
102 CCGError        ccgSubSurf_setAllowEdgeCreation         (CCGSubSurf *ss, int allowEdgeCreation, float defaultCreaseValue, void *defaultUserData);
103 void            ccgSubSurf_getAllowEdgeCreation         (CCGSubSurf *ss, int *allowEdgeCreation_r, float *defaultCreaseValue_r, void *defaultUserData_r);
104
105 void            ccgSubSurf_getUseAgeCounts                      (CCGSubSurf *ss, int *useAgeCounts_r, int *vertUserOffset_r, int *edgeUserOffset_r, int *faceUserOffset_r);
106 CCGError        ccgSubSurf_setUseAgeCounts                      (CCGSubSurf *ss, int useAgeCounts, int vertUserOffset, int edgeUserOffset, int faceUserOffset);
107
108 CCGError        ccgSubSurf_setCalcVertexNormals         (CCGSubSurf *ss, int useVertNormals, int normalDataOffset);
109 void            ccgSubSurf_setAllocMask                         (CCGSubSurf *ss, int allocMask, int maskOffset);
110
111 void            ccgSubSurf_setNumLayers                         (CCGSubSurf *ss, int numLayers);
112
113 /***/
114
115 int                     ccgSubSurf_getNumVerts                          (const CCGSubSurf *ss);
116 int                     ccgSubSurf_getNumEdges                          (const CCGSubSurf *ss);
117 int                     ccgSubSurf_getNumFaces                          (const CCGSubSurf *ss);
118
119 int                     ccgSubSurf_getSubdivisionLevels         (const CCGSubSurf *ss);
120 int                     ccgSubSurf_getEdgeSize                          (const CCGSubSurf *ss);
121 int                     ccgSubSurf_getEdgeLevelSize                     (const CCGSubSurf *ss, int level);
122 int                     ccgSubSurf_getGridSize                          (const CCGSubSurf *ss);
123 int                     ccgSubSurf_getGridLevelSize                     (const CCGSubSurf *ss, int level);
124 int                     ccgSubSurf_getSimpleSubdiv                      (const CCGSubSurf *ss);
125
126 CCGVert*        ccgSubSurf_getVert                                      (CCGSubSurf *ss, CCGVertHDL v);
127 CCGVertHDL      ccgSubSurf_getVertVertHandle            (CCGVert *v);
128 int                     ccgSubSurf_getVertNumFaces                      (CCGVert *v);
129 CCGFace*        ccgSubSurf_getVertFace                          (CCGVert *v, int index);
130 int                     ccgSubSurf_getVertNumEdges                      (CCGVert *v);
131 CCGEdge*        ccgSubSurf_getVertEdge                          (CCGVert *v, int index);
132
133 int                     ccgSubSurf_getVertAge                           (CCGSubSurf *ss, CCGVert *v);
134 void*           ccgSubSurf_getVertUserData                      (CCGSubSurf *ss, CCGVert *v);
135 void*           ccgSubSurf_getVertData                          (CCGSubSurf *ss, CCGVert *v);
136 void*           ccgSubSurf_getVertLevelData                     (CCGSubSurf *ss, CCGVert *v, int level);
137
138 CCGEdge*        ccgSubSurf_getEdge                                      (CCGSubSurf *ss, CCGEdgeHDL e);
139 CCGEdgeHDL      ccgSubSurf_getEdgeEdgeHandle            (CCGEdge *e);
140 int                     ccgSubSurf_getEdgeNumFaces                      (CCGEdge *e);
141 CCGFace*        ccgSubSurf_getEdgeFace                          (CCGEdge *e, int index);
142 CCGVert*        ccgSubSurf_getEdgeVert0                         (CCGEdge *e);
143 CCGVert*        ccgSubSurf_getEdgeVert1                         (CCGEdge *e);
144 float           ccgSubSurf_getEdgeCrease                        (CCGEdge *e);
145
146 int                     ccgSubSurf_getEdgeAge                           (CCGSubSurf *ss, CCGEdge *e);
147 void*           ccgSubSurf_getEdgeUserData                      (CCGSubSurf *ss, CCGEdge *e);
148 void*           ccgSubSurf_getEdgeDataArray                     (CCGSubSurf *ss, CCGEdge *e);
149 void*           ccgSubSurf_getEdgeData                          (CCGSubSurf *ss, CCGEdge *e, int x);
150 void*           ccgSubSurf_getEdgeLevelData                     (CCGSubSurf *ss, CCGEdge *e, int x, int level);
151
152 CCGFace*        ccgSubSurf_getFace                                      (CCGSubSurf *ss, CCGFaceHDL f);
153 CCGFaceHDL      ccgSubSurf_getFaceFaceHandle            (CCGFace *f);
154 int                     ccgSubSurf_getFaceNumVerts                      (CCGFace *f);
155 CCGVert*        ccgSubSurf_getFaceVert                          (CCGFace *f, int index);
156 CCGEdge*        ccgSubSurf_getFaceEdge                          (CCGFace *f, int index);
157 int                     ccgSubSurf_getFaceEdgeIndex                     (CCGFace *f, CCGEdge *e);
158
159 int                     ccgSubSurf_getFaceAge                           (CCGSubSurf *ss, CCGFace *f);
160 void*           ccgSubSurf_getFaceUserData                      (CCGSubSurf *ss, CCGFace *f);
161 void*           ccgSubSurf_getFaceCenterData            (CCGFace *f);
162 void*           ccgSubSurf_getFaceGridEdgeDataArray     (CCGSubSurf *ss, CCGFace *f, int gridIndex);
163 void*           ccgSubSurf_getFaceGridEdgeData          (CCGSubSurf *ss, CCGFace *f, int gridIndex, int x);
164 void*           ccgSubSurf_getFaceGridDataArray         (CCGSubSurf *ss, CCGFace *f, int gridIndex);
165 void*           ccgSubSurf_getFaceGridData                      (CCGSubSurf *ss, CCGFace *f, int gridIndex, int x, int y);
166
167 int                     ccgSubSurf_getNumFinalVerts             (const CCGSubSurf *ss);
168 int                     ccgSubSurf_getNumFinalEdges             (const CCGSubSurf *ss);
169 int                     ccgSubSurf_getNumFinalFaces             (const CCGSubSurf *ss);
170
171 /***/
172
173 typedef struct _EHashIterator CCGEdgeIterator;
174 typedef struct _EHashIterator CCGFaceIterator;
175 typedef struct _EHashIterator CCGVertIterator;
176
177 void            ccgSubSurf_initVertIterator(CCGSubSurf *ss, CCGVertIterator *viter);
178 void            ccgSubSurf_initEdgeIterator(CCGSubSurf *ss, CCGEdgeIterator *eiter);
179 void            ccgSubSurf_initFaceIterator(CCGSubSurf *ss, CCGFaceIterator *fiter);
180
181 CCGVert*                        ccgVertIterator_getCurrent      (CCGVertIterator *vi);
182 int                                     ccgVertIterator_isStopped       (CCGVertIterator *vi);
183 void                            ccgVertIterator_next            (CCGVertIterator *vi);
184
185 CCGEdge*                        ccgEdgeIterator_getCurrent      (CCGEdgeIterator *ei);
186 int                                     ccgEdgeIterator_isStopped       (CCGEdgeIterator *ei);
187 void                            ccgEdgeIterator_next            (CCGEdgeIterator *ei);
188
189 CCGFace*                        ccgFaceIterator_getCurrent      (CCGFaceIterator *fi);
190 int                                     ccgFaceIterator_isStopped       (CCGFaceIterator *fi);
191 void                            ccgFaceIterator_next            (CCGFaceIterator *fi);
192
193 #ifdef WITH_OPENSUBDIV
194 struct DerivedMesh;
195
196 /* Check if topology changed and evaluators are to be re-created. */
197 void ccgSubSurf_checkTopologyChanged(CCGSubSurf *ss, struct DerivedMesh *dm);
198
199 /* Create topology refiner from give derived mesh which then later will be
200  * used for GL mesh creation.
201  */
202 void ccgSubSurf_prepareTopologyRefiner(CCGSubSurf *ss, struct DerivedMesh *dm);
203
204 /* Make sure GL mesh exists, up to date and ready to draw. */
205 bool ccgSubSurf_prepareGLMesh(CCGSubSurf *ss, bool use_osd_glsl, int active_uv_index);
206
207 /* Draw given partitions of the GL mesh.
208  *
209  * TODO(sergey): fill_quads is actually an invariant and should be part
210  * of the prepare routine.
211  */
212 void ccgSubSurf_drawGLMesh(CCGSubSurf *ss, bool fill_quads,
213                            int start_partition, int num_partitions);
214
215 /* Get number of base faces in a particular GL mesh. */
216 int ccgSubSurf_getNumGLMeshBaseFaces(CCGSubSurf *ss);
217
218 /* Get number of vertices in base faces in a particular GL mesh. */
219 int ccgSubSurf_getNumGLMeshBaseFaceVerts(CCGSubSurf *ss, int face);
220
221 /* Controls whether CCG are needed (Cmeaning CPU evaluation) or fully GPU compute
222  * and draw is allowed.
223  */
224 void ccgSubSurf_setSkipGrids(CCGSubSurf *ss, bool skip_grids);
225 bool ccgSubSurf_needGrids(CCGSubSurf *ss);
226
227 /* Set evaluator's face varying data from UV coordinates.
228  * Used for CPU evaluation.
229  */
230 void ccgSubSurf_evaluatorSetFVarUV(CCGSubSurf *ss,
231                                    struct DerivedMesh *dm,
232                                    int layer_index);
233
234 /* TODO(sergey): Temporary call to test things. */
235 void ccgSubSurf_evaluatorFVarUV(CCGSubSurf *ss,
236                                 int face_index, int S,
237                                 float grid_u, float grid_v,
238                                 float uv[2]);
239
240 void ccgSubSurf_free_osd_mesh(CCGSubSurf *ss);
241
242 void ccgSubSurf_getMinMax(CCGSubSurf *ss, float r_min[3], float r_max[3]);
243
244 void ccgSubSurf__sync_subdivUvs(CCGSubSurf *ss, bool subsurf_uvs);
245
246 #endif
247
248 #endif  /* __CCGSUBSURF_H__ */