Blender V4.3
BKE_ccg.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2012 by Nicholas Bishop. All rights reserved.
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
5#pragma once
6
11#include "BLI_assert.h"
13
14struct CCGSubSurf;
15
16/* Each CCGElem is CCGSubSurf's representation of a subdivided
17 * vertex. All CCGElems in a particular CCGSubSurf have the same
18 * layout, but the layout can vary from one CCGSubSurf to another. For
19 * this reason, CCGElem is presented as an opaque pointer, and
20 * elements should always be accompanied by a CCGKey, which provides
21 * the necessary offsets to access components of a CCGElem.
22 */
23struct CCGElem;
24
25struct CCGKey {
26 int level;
27
28 /* number of bytes in each element (one float per layer, plus
29 * three floats for normals if enabled) */
31
32 /* number of elements along each side of grid */
34 /* number of elements in the grid (grid size squared) */
36 /* number of bytes in each grid (grid_area * elem_size) */
38
39 /* currently always the last three floats, unless normals are
40 * disabled */
42
43 /* offset in bytes of mask value; only valid if 'has_mask' is
44 * true */
46
49};
50
51/* initialize 'key' at the specified level */
52void CCG_key(CCGKey *key, const CCGSubSurf *ss, int level);
53void CCG_key_top_level(CCGKey *key, const CCGSubSurf *ss);
54
55inline blender::float3 &CCG_elem_co(const CCGKey & /*key*/, CCGElem *elem)
56{
57 return *reinterpret_cast<blender::float3 *>(elem);
58}
59
60inline blender::float3 &CCG_elem_no(const CCGKey &key, CCGElem *elem)
61{
63 return *reinterpret_cast<blender::float3 *>(reinterpret_cast<char *>(elem) + key.normal_offset);
64}
65
66inline float &CCG_elem_mask(const CCGKey &key, CCGElem *elem)
67{
69 return *reinterpret_cast<float *>(reinterpret_cast<char *>(elem) + (key.mask_offset));
70}
71
72inline CCGElem *CCG_elem_offset(const CCGKey &key, CCGElem *elem, int offset)
73{
74 return reinterpret_cast<CCGElem *>((reinterpret_cast<char *>(elem)) + key.elem_size * offset);
75}
76
77inline int CCG_grid_xy_to_index(const int grid_size, const int x, const int y)
78{
79 return y * grid_size + x;
80}
81
82inline CCGElem *CCG_grid_elem(const CCGKey &key, CCGElem *elem, int x, int y)
83{
84 // BLI_assert(x < key.grid_size && y < key.grid_size);
85 return CCG_elem_offset(key, elem, CCG_grid_xy_to_index(key.grid_size, x, y));
86}
87
88inline blender::float3 &CCG_grid_elem_co(const CCGKey &key, CCGElem *elem, int x, int y)
89{
90 return CCG_elem_co(key, CCG_grid_elem(key, elem, x, y));
91}
92
93inline blender::float3 &CCG_grid_elem_no(const CCGKey &key, CCGElem *elem, int x, int y)
94{
95 return CCG_elem_no(key, CCG_grid_elem(key, elem, x, y));
96}
97
98inline float &CCG_grid_elem_mask(const CCGKey &key, CCGElem *elem, int x, int y)
99{
100 return CCG_elem_mask(key, CCG_grid_elem(key, elem, x, y));
101}
102
103inline blender::float3 &CCG_elem_offset_co(const CCGKey &key, CCGElem *elem, int offset)
104{
105 return CCG_elem_co(key, CCG_elem_offset(key, elem, offset));
106}
void CCG_key_top_level(CCGKey *key, const CCGSubSurf *ss)
void CCG_key(CCGKey *key, const CCGSubSurf *ss, int level)
blender::float3 & CCG_grid_elem_no(const CCGKey &key, CCGElem *elem, int x, int y)
Definition BKE_ccg.hh:93
blender::float3 & CCG_grid_elem_co(const CCGKey &key, CCGElem *elem, int x, int y)
Definition BKE_ccg.hh:88
int CCG_grid_xy_to_index(const int grid_size, const int x, const int y)
Definition BKE_ccg.hh:77
CCGElem * CCG_grid_elem(const CCGKey &key, CCGElem *elem, int x, int y)
Definition BKE_ccg.hh:82
blender::float3 & CCG_elem_offset_co(const CCGKey &key, CCGElem *elem, int offset)
Definition BKE_ccg.hh:103
float & CCG_elem_mask(const CCGKey &key, CCGElem *elem)
Definition BKE_ccg.hh:66
blender::float3 & CCG_elem_no(const CCGKey &key, CCGElem *elem)
Definition BKE_ccg.hh:60
blender::float3 & CCG_elem_co(const CCGKey &, CCGElem *elem)
Definition BKE_ccg.hh:55
CCGElem * CCG_elem_offset(const CCGKey &key, CCGElem *elem, int offset)
Definition BKE_ccg.hh:72
float & CCG_grid_elem_mask(const CCGKey &key, CCGElem *elem, int x, int y)
Definition BKE_ccg.hh:98
#define BLI_assert(a)
Definition BLI_assert.h:50
int has_mask
Definition BKE_ccg.hh:48
int mask_offset
Definition BKE_ccg.hh:45
int grid_size
Definition BKE_ccg.hh:33
int grid_bytes
Definition BKE_ccg.hh:37
int grid_area
Definition BKE_ccg.hh:35
int level
Definition BKE_ccg.hh:26
int normal_offset
Definition BKE_ccg.hh:41
int elem_size
Definition BKE_ccg.hh:30
int has_normals
Definition BKE_ccg.hh:47