2
* ***** BEGIN GPL LICENSE BLOCK *****
4
* This program is free software; you can redistribute it and/or
5
* modify it under the terms of the GNU General Public License
6
* as published by the Free Software Foundation; either version 2
7
* of the License, or (at your option) any later version.
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
14
* You should have received a copy of the GNU General Public License
15
* along with this program; if not, write to the Free Software Foundation,
16
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18
* The Original Code is Copyright (C) 2012 by Nicholas Bishop.
19
* All rights reserved.
21
* The Original Code is: all of this file.
23
* Contributor(s): none yet.
25
* ***** END GPL LICENSE BLOCK *****
31
/* defines BLI_INLINE */
32
#include "BLI_utildefines.h"
34
/* declares fprintf() and abort(), needed for BLI_assert */
40
/* Each CCGElem is CCGSubSurf's representation of a subdivided
41
* vertex. All CCGElems in a particular CCGSubSurf have the same
42
* layout, but the layout can vary from one CCGSubSurf to another. For
43
* this reason, CCGElem is presented as an opaque pointer, and
44
* elements should always be accompanied by a CCGKey, which provides
45
* the necessary offsets to access components of a CCGElem.
47
typedef struct CCGElem CCGElem;
49
typedef struct CCGKey {
52
/* number of bytes in each element (one float per layer, plus
53
* three floats for normals if enabled) */
56
/* number of elements along each side of grid */
58
/* number of elements in the grid (grid size squared) */
60
/* number of bytes in each grid (grid_area * elem_size) */
63
/* currently always the last three floats, unless normals are
67
/* offset in bytes of mask value; only valid if 'has_mask' is
76
/* initialize 'key' at the specified level */
77
void CCG_key(CCGKey *key, const struct CCGSubSurf *ss, int level);
78
void CCG_key_top_level(CCGKey *key, const struct CCGSubSurf *ss);
80
/* get a pointer to the coordinate, normal, or mask components */
81
BLI_INLINE float *CCG_elem_co(const CCGKey *key, CCGElem *elem);
82
BLI_INLINE float *CCG_elem_no(const CCGKey *key, CCGElem *elem);
83
BLI_INLINE float *CCG_elem_mask(const CCGKey *key, CCGElem *elem);
85
/* get the element at 'offset' in an array */
86
BLI_INLINE CCGElem *CCG_elem_offset(const CCGKey *key, CCGElem *elem, int offset);
88
/* get the element at coordinate (x,y) in a face-grid array */
89
BLI_INLINE CCGElem *CCG_grid_elem(const CCGKey *key, CCGElem *elem, int x, int y);
91
/* combinations of above functions */
92
BLI_INLINE float *CCG_grid_elem_co(const CCGKey *key, CCGElem *elem, int x, int y);
93
BLI_INLINE float *CCG_grid_elem_no(const CCGKey *key, CCGElem *elem, int x, int y);
94
BLI_INLINE float *CCG_grid_elem_mask(const CCGKey *key, CCGElem *elem, int x, int y);
95
BLI_INLINE float *CCG_elem_offset_co(const CCGKey *key, CCGElem *elem, int offset);
96
BLI_INLINE float *CCG_elem_offset_no(const CCGKey *key, CCGElem *elem, int offset);
97
BLI_INLINE float *CCG_elem_offset_mask(const CCGKey *key, CCGElem *elem, int offset);
99
/* for iteration, get a pointer to the next element in an array */
100
BLI_INLINE CCGElem *CCG_elem_next(const CCGKey *key, CCGElem *elem);
103
/* inline definitions follow */
105
BLI_INLINE float *CCG_elem_co(const CCGKey *UNUSED(key), CCGElem *elem)
107
return (float *)elem;
110
BLI_INLINE float *CCG_elem_no(const CCGKey *key, CCGElem *elem)
112
BLI_assert(key->has_normals);
113
return (float *)((char *)elem + key->normal_offset);
116
BLI_INLINE float *CCG_elem_mask(const CCGKey *key, CCGElem *elem)
118
BLI_assert(key->has_mask);
119
return (float *)((char *)elem + (key->mask_offset));
122
BLI_INLINE CCGElem *CCG_elem_offset(const CCGKey *key, CCGElem *elem, int offset)
124
return (CCGElem *)(((char *)elem) + key->elem_size * offset);
127
BLI_INLINE CCGElem *CCG_grid_elem(const CCGKey *key, CCGElem *elem, int x, int y)
129
BLI_assert(x < key->grid_size && y < key->grid_size);
130
return CCG_elem_offset(key, elem, (y * key->grid_size + x));
133
BLI_INLINE float *CCG_grid_elem_co(const CCGKey *key, CCGElem *elem, int x, int y)
135
return CCG_elem_co(key, CCG_grid_elem(key, elem, x, y));
138
BLI_INLINE float *CCG_grid_elem_no(const CCGKey *key, CCGElem *elem, int x, int y)
140
return CCG_elem_no(key, CCG_grid_elem(key, elem, x, y));
143
BLI_INLINE float *CCG_grid_elem_mask(const CCGKey *key, CCGElem *elem, int x, int y)
145
return CCG_elem_mask(key, CCG_grid_elem(key, elem, x, y));
148
BLI_INLINE float *CCG_elem_offset_co(const CCGKey *key, CCGElem *elem, int offset)
150
return CCG_elem_co(key, CCG_elem_offset(key, elem, offset));
153
BLI_INLINE float *CCG_elem_offset_no(const CCGKey *key, CCGElem *elem, int offset)
155
return CCG_elem_no(key, CCG_elem_offset(key, elem, offset));
158
BLI_INLINE float *CCG_elem_offset_mask(const CCGKey *key, CCGElem *elem, int offset)
160
return CCG_elem_mask(key, CCG_elem_offset(key, elem, offset));
163
BLI_INLINE CCGElem *CCG_elem_next(const CCGKey *key, CCGElem *elem)
165
return CCG_elem_offset(key, elem, 1);