~ubuntu-branches/ubuntu/trusty/blender/trusty

« back to all changes in this revision

Viewing changes to source/blender/blenkernel/BKE_ccg.h

  • Committer: Package Import Robot
  • Author(s): Jeremy Bicha
  • Date: 2013-03-06 12:08:47 UTC
  • mfrom: (1.5.1) (14.1.8 experimental)
  • Revision ID: package-import@ubuntu.com-20130306120847-frjfaryb2zrotwcg
Tags: 2.66a-1ubuntu1
* Resynchronize with Debian (LP: #1076930, #1089256, #1052743, #999024,
  #1122888, #1147084)
* debian/control:
  - Lower build-depends on libavcodec-dev since we're not
    doing the libav9 transition in Ubuntu yet

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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() and abort(), needed for BLI_assert */
 
35
#include <stdio.h>
 
36
#include <stdlib.h>
 
37
 
 
38
struct CCGSubSurf;
 
39
 
 
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.
 
46
 */
 
47
typedef struct CCGElem CCGElem;
 
48
 
 
49
typedef struct CCGKey {
 
50
        int level;
 
51
 
 
52
        /* number of bytes in each element (one float per layer, plus
 
53
         * three floats for normals if enabled) */
 
54
        int elem_size;
 
55
 
 
56
        /* number of elements along each side of grid */
 
57
        int grid_size;
 
58
        /* number of elements in the grid (grid size squared) */
 
59
        int grid_area;
 
60
        /* number of bytes in each grid (grid_area * elem_size) */
 
61
        int grid_bytes;
 
62
 
 
63
        /* currently always the last three floats, unless normals are
 
64
         * disabled */
 
65
        int normal_offset;
 
66
 
 
67
        /* offset in bytes of mask value; only valid if 'has_mask' is
 
68
         * true */
 
69
        int mask_offset;
 
70
 
 
71
        int num_layers;
 
72
        int has_normals;
 
73
        int has_mask;
 
74
} CCGKey;
 
75
 
 
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);
 
79
 
 
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);
 
84
 
 
85
/* get the element at 'offset' in an array */
 
86
BLI_INLINE CCGElem *CCG_elem_offset(const CCGKey *key, CCGElem *elem, int offset);
 
87
 
 
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);
 
90
 
 
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);
 
98
 
 
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);
 
101
 
 
102
 
 
103
/* inline definitions follow */
 
104
 
 
105
BLI_INLINE float *CCG_elem_co(const CCGKey *UNUSED(key), CCGElem *elem)
 
106
{
 
107
        return (float *)elem;
 
108
}
 
109
 
 
110
BLI_INLINE float *CCG_elem_no(const CCGKey *key, CCGElem *elem)
 
111
{
 
112
        BLI_assert(key->has_normals);
 
113
        return (float *)((char *)elem + key->normal_offset);
 
114
}
 
115
 
 
116
BLI_INLINE float *CCG_elem_mask(const CCGKey *key, CCGElem *elem)
 
117
{
 
118
        BLI_assert(key->has_mask);
 
119
        return (float *)((char *)elem + (key->mask_offset));
 
120
}
 
121
 
 
122
BLI_INLINE CCGElem *CCG_elem_offset(const CCGKey *key, CCGElem *elem, int offset)
 
123
{
 
124
        return (CCGElem *)(((char *)elem) + key->elem_size * offset);
 
125
}
 
126
 
 
127
BLI_INLINE CCGElem *CCG_grid_elem(const CCGKey *key, CCGElem *elem, int x, int y)
 
128
{
 
129
        BLI_assert(x < key->grid_size && y < key->grid_size);
 
130
        return CCG_elem_offset(key, elem, (y * key->grid_size + x));
 
131
}
 
132
 
 
133
BLI_INLINE float *CCG_grid_elem_co(const CCGKey *key, CCGElem *elem, int x, int y)
 
134
{
 
135
        return CCG_elem_co(key, CCG_grid_elem(key, elem, x, y));
 
136
}
 
137
 
 
138
BLI_INLINE float *CCG_grid_elem_no(const CCGKey *key, CCGElem *elem, int x, int y)
 
139
{
 
140
        return CCG_elem_no(key, CCG_grid_elem(key, elem, x, y));
 
141
}
 
142
 
 
143
BLI_INLINE float *CCG_grid_elem_mask(const CCGKey *key, CCGElem *elem, int x, int y)
 
144
{
 
145
        return CCG_elem_mask(key, CCG_grid_elem(key, elem, x, y));
 
146
}
 
147
 
 
148
BLI_INLINE float *CCG_elem_offset_co(const CCGKey *key, CCGElem *elem, int offset)
 
149
{
 
150
        return CCG_elem_co(key, CCG_elem_offset(key, elem, offset));
 
151
}
 
152
 
 
153
BLI_INLINE float *CCG_elem_offset_no(const CCGKey *key, CCGElem *elem, int offset)
 
154
{
 
155
        return CCG_elem_no(key, CCG_elem_offset(key, elem, offset));
 
156
}
 
157
 
 
158
BLI_INLINE float *CCG_elem_offset_mask(const CCGKey *key, CCGElem *elem, int offset)
 
159
{
 
160
        return CCG_elem_mask(key, CCG_elem_offset(key, elem, offset));
 
161
}
 
162
 
 
163
BLI_INLINE CCGElem *CCG_elem_next(const CCGKey *key, CCGElem *elem)
 
164
{
 
165
        return CCG_elem_offset(key, elem, 1);
 
166
}
 
167
 
 
168
#endif