OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * ***** BEGIN GPL LICENSE BLOCK ***** |
| 3 * |
| 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. |
| 8 * |
| 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. |
| 13 * |
| 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. |
| 17 * |
| 18 * The Original Code is Copyright (C) 2012 by Nicholas Bishop. |
| 19 * All rights reserved. |
| 20 * |
| 21 * The Original Code is: all of this file. |
| 22 * |
| 23 * Contributor(s): none yet. |
| 24 * |
| 25 * ***** END GPL LICENSE BLOCK ***** |
| 26 */ |
| 27 |
| 28 #ifndef __BKE_CCG_H__ |
| 29 #define __BKE_CCG_H__ |
| 30 |
| 31 /* defines BLI_INLINE */ |
| 32 #include "BLI_utildefines.h" |
| 33 |
| 34 /* declares fprintf(), needed for BLI_assert */ |
| 35 #if !defined NDEBUG |
| 36 #include <stdio.h> |
| 37 #endif |
| 38 |
| 39 struct CCGSubSurf; |
| 40 |
| 41 /* Each CCGElem is CCGSubSurf's representation of a subdivided |
| 42 vertex. All CCGElems in a particular CCGSubSurf have the same |
| 43 layout, but the layout can vary from one CCGSubSurf to another. For |
| 44 this reason, CCGElem is presented as an opaque pointer, and |
| 45 elements should always be accompanied by a CCGKey, which provides |
| 46 the necessary offsets to access components of a CCGElem. |
| 47 */ |
| 48 typedef struct CCGElem CCGElem; |
| 49 |
| 50 typedef struct CCGKey { |
| 51 int level; |
| 52 |
| 53 /* number of bytes in each element (one float per layer, plus |
| 54 three floats for normals if enabled) */ |
| 55 int elem_size; |
| 56 |
| 57 /* number of elements along each side of grid */ |
| 58 int grid_size; |
| 59 /* number of elements in the grid (grid size squared) */ |
| 60 int grid_area; |
| 61 /* number of bytes in each grid (grid_area * elem_size) */ |
| 62 int grid_bytes; |
| 63 |
| 64 /* currently always the last three floats, unless normals are |
| 65 disabled */ |
| 66 int normal_offset; |
| 67 |
| 68 /* offset in bytes of mask value; only valid if 'has_mask' is |
| 69 true */ |
| 70 int mask_offset; |
| 71 |
| 72 int num_layers; |
| 73 int has_normals; |
| 74 int has_mask; |
| 75 } CCGKey; |
| 76 |
| 77 /* initialize 'key' at the specified level */ |
| 78 void CCG_key(CCGKey *key, const struct CCGSubSurf *ss, int level); |
| 79 void CCG_key_top_level(CCGKey *key, const struct CCGSubSurf *ss); |
| 80 |
| 81 /* get a pointer to the coordinate, normal, or mask components */ |
| 82 BLI_INLINE float *CCG_elem_co(const CCGKey *key, CCGElem *elem); |
| 83 BLI_INLINE float *CCG_elem_no(const CCGKey *key, CCGElem *elem); |
| 84 BLI_INLINE float *CCG_elem_mask(const CCGKey *key, CCGElem *elem); |
| 85 |
| 86 /* get the element at 'offset' in an array */ |
| 87 BLI_INLINE CCGElem *CCG_elem_offset(const CCGKey *key, CCGElem *elem, int offset
); |
| 88 |
| 89 /* get the element at coordinate (x,y) in a face-grid array */ |
| 90 BLI_INLINE CCGElem *CCG_grid_elem(const CCGKey *key, CCGElem *elem, int x, int y
); |
| 91 |
| 92 /* combinations of above functions */ |
| 93 BLI_INLINE float *CCG_grid_elem_co(const CCGKey *key, CCGElem *elem, int x, int
y); |
| 94 BLI_INLINE float *CCG_grid_elem_no(const CCGKey *key, CCGElem *elem, int x, int
y); |
| 95 BLI_INLINE float *CCG_grid_elem_mask(const CCGKey *key, CCGElem *elem, int x, in
t y); |
| 96 BLI_INLINE float *CCG_elem_offset_co(const CCGKey *key, CCGElem *elem, int offse
t); |
| 97 BLI_INLINE float *CCG_elem_offset_no(const CCGKey *key, CCGElem *elem, int offse
t); |
| 98 BLI_INLINE float *CCG_elem_offset_mask(const CCGKey *key, CCGElem *elem, int off
set); |
| 99 |
| 100 /* for iteration, get a pointer to the next element in an array */ |
| 101 BLI_INLINE CCGElem *CCG_elem_next(const CCGKey *key, CCGElem *elem); |
| 102 |
| 103 |
| 104 /* inline definitions follow */ |
| 105 |
| 106 BLI_INLINE float *CCG_elem_co(const CCGKey *UNUSED(key), CCGElem *elem) |
| 107 { |
| 108 return (float*)elem; |
| 109 } |
| 110 |
| 111 BLI_INLINE float *CCG_elem_no(const CCGKey *key, CCGElem *elem) |
| 112 { |
| 113 BLI_assert(key->has_normals); |
| 114 return (float*)((char*)elem + key->normal_offset); |
| 115 } |
| 116 |
| 117 BLI_INLINE float *CCG_elem_mask(const CCGKey *key, CCGElem *elem) |
| 118 { |
| 119 BLI_assert(key->has_mask); |
| 120 return (float*)((char*)elem + (key->mask_offset)); |
| 121 } |
| 122 |
| 123 BLI_INLINE CCGElem *CCG_elem_offset(const CCGKey *key, CCGElem *elem, int offset
) |
| 124 { |
| 125 return (CCGElem*)(((char*)elem) + key->elem_size * offset); |
| 126 } |
| 127 |
| 128 BLI_INLINE CCGElem *CCG_grid_elem(const CCGKey *key, CCGElem *elem, int x, int y
) |
| 129 { |
| 130 BLI_assert(x < key->grid_size && y < key->grid_size); |
| 131 return CCG_elem_offset(key, elem, (y * key->grid_size + x)); |
| 132 } |
| 133 |
| 134 BLI_INLINE float *CCG_grid_elem_co(const CCGKey *key, CCGElem *elem, int x, int
y) |
| 135 { |
| 136 return CCG_elem_co(key, CCG_grid_elem(key, elem, x, y)); |
| 137 } |
| 138 |
| 139 BLI_INLINE float *CCG_grid_elem_no(const CCGKey *key, CCGElem *elem, int x, int
y) |
| 140 { |
| 141 return CCG_elem_no(key, CCG_grid_elem(key, elem, x, y)); |
| 142 } |
| 143 |
| 144 BLI_INLINE float *CCG_grid_elem_mask(const CCGKey *key, CCGElem *elem, int x, in
t y) |
| 145 { |
| 146 return CCG_elem_mask(key, CCG_grid_elem(key, elem, x, y)); |
| 147 } |
| 148 |
| 149 BLI_INLINE float *CCG_elem_offset_co(const CCGKey *key, CCGElem *elem, int offse
t) |
| 150 { |
| 151 return CCG_elem_co(key, CCG_elem_offset(key, elem, offset)); |
| 152 } |
| 153 |
| 154 BLI_INLINE float *CCG_elem_offset_no(const CCGKey *key, CCGElem *elem, int offse
t) |
| 155 { |
| 156 return CCG_elem_no(key, CCG_elem_offset(key, elem, offset)); |
| 157 } |
| 158 |
| 159 BLI_INLINE float *CCG_elem_offset_mask(const CCGKey *key, CCGElem *elem, int off
set) |
| 160 { |
| 161 return CCG_elem_mask(key, CCG_elem_offset(key, elem, offset)); |
| 162 } |
| 163 |
| 164 BLI_INLINE CCGElem *CCG_elem_next(const CCGKey *key, CCGElem *elem) |
| 165 { |
| 166 return CCG_elem_offset(key, elem, 1); |
| 167 } |
| 168 |
| 169 #endif |
OLD | NEW |