Blender  V3.3
BKE_ccg.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later
2  * Copyright 2012 by Nicholas Bishop. All rights reserved. */
3 
4 #pragma once
5 
10 /* defines BLI_INLINE */
11 #include "BLI_compiler_compat.h"
12 
13 /* declares fprintf() and abort(), needed for BLI_assert */
14 #include <stdio.h>
15 #include <stdlib.h>
16 
17 #ifdef __cplusplus
18 extern "C" {
19 #endif
20 
21 struct CCGSubSurf;
22 
23 /* Each CCGElem is CCGSubSurf's representation of a subdivided
24  * vertex. All CCGElems in a particular CCGSubSurf have the same
25  * layout, but the layout can vary from one CCGSubSurf to another. For
26  * this reason, CCGElem is presented as an opaque pointer, and
27  * elements should always be accompanied by a CCGKey, which provides
28  * the necessary offsets to access components of a CCGElem.
29  */
30 typedef struct CCGElem CCGElem;
31 
32 typedef struct CCGKey {
33  int level;
34 
35  /* number of bytes in each element (one float per layer, plus
36  * three floats for normals if enabled) */
37  int elem_size;
38 
39  /* number of elements along each side of grid */
40  int grid_size;
41  /* number of elements in the grid (grid size squared) */
42  int grid_area;
43  /* number of bytes in each grid (grid_area * elem_size) */
45 
46  /* currently always the last three floats, unless normals are
47  * disabled */
49 
50  /* offset in bytes of mask value; only valid if 'has_mask' is
51  * true */
53 
55  int has_mask;
57 
58 /* initialize 'key' at the specified level */
59 void CCG_key(CCGKey *key, const struct CCGSubSurf *ss, int level);
60 void CCG_key_top_level(CCGKey *key, const struct CCGSubSurf *ss);
61 
62 /* get a pointer to the coordinate, normal, or mask components */
63 BLI_INLINE float *CCG_elem_co(const CCGKey *key, CCGElem *elem);
64 BLI_INLINE float *CCG_elem_no(const CCGKey *key, CCGElem *elem);
65 BLI_INLINE float *CCG_elem_mask(const CCGKey *key, CCGElem *elem);
66 
67 /* get the element at 'offset' in an array */
68 BLI_INLINE CCGElem *CCG_elem_offset(const CCGKey *key, CCGElem *elem, int offset);
69 
70 /* get the element at coordinate (x,y) in a face-grid array */
71 BLI_INLINE CCGElem *CCG_grid_elem(const CCGKey *key, CCGElem *elem, int x, int y);
72 
73 /* combinations of above functions */
74 BLI_INLINE float *CCG_grid_elem_co(const CCGKey *key, CCGElem *elem, int x, int y);
75 BLI_INLINE float *CCG_grid_elem_no(const CCGKey *key, CCGElem *elem, int x, int y);
76 BLI_INLINE float *CCG_grid_elem_mask(const CCGKey *key, CCGElem *elem, int x, int y);
77 BLI_INLINE float *CCG_elem_offset_co(const CCGKey *key, CCGElem *elem, int offset);
78 BLI_INLINE float *CCG_elem_offset_no(const CCGKey *key, CCGElem *elem, int offset);
79 BLI_INLINE float *CCG_elem_offset_mask(const CCGKey *key, CCGElem *elem, int offset);
80 
81 /* for iteration, get a pointer to the next element in an array */
82 BLI_INLINE CCGElem *CCG_elem_next(const CCGKey *key, CCGElem *elem);
83 
84 /* inline definitions follow */
85 
86 BLI_INLINE float *CCG_elem_co(const CCGKey *UNUSED(key), CCGElem *elem)
87 {
88  return (float *)elem;
89 }
90 
91 BLI_INLINE float *CCG_elem_no(const CCGKey *key, CCGElem *elem)
92 {
93  BLI_assert(key->has_normals);
94  return (float *)((char *)elem + key->normal_offset);
95 }
96 
97 BLI_INLINE float *CCG_elem_mask(const CCGKey *key, CCGElem *elem)
98 {
99  BLI_assert(key->has_mask);
100  return (float *)((char *)elem + (key->mask_offset));
101 }
102 
104 {
105  return (CCGElem *)(((char *)elem) + key->elem_size * offset);
106 }
107 
108 BLI_INLINE CCGElem *CCG_grid_elem(const CCGKey *key, CCGElem *elem, int x, int y)
109 {
110  // BLI_assert(x < key->grid_size && y < key->grid_size);
111  return CCG_elem_offset(key, elem, (y * key->grid_size + x));
112 }
113 
114 BLI_INLINE float *CCG_grid_elem_co(const CCGKey *key, CCGElem *elem, int x, int y)
115 {
116  return CCG_elem_co(key, CCG_grid_elem(key, elem, x, y));
117 }
118 
119 BLI_INLINE float *CCG_grid_elem_no(const CCGKey *key, CCGElem *elem, int x, int y)
120 {
121  return CCG_elem_no(key, CCG_grid_elem(key, elem, x, y));
122 }
123 
124 BLI_INLINE float *CCG_grid_elem_mask(const CCGKey *key, CCGElem *elem, int x, int y)
125 {
126  return CCG_elem_mask(key, CCG_grid_elem(key, elem, x, y));
127 }
128 
129 BLI_INLINE float *CCG_elem_offset_co(const CCGKey *key, CCGElem *elem, int offset)
130 {
131  return CCG_elem_co(key, CCG_elem_offset(key, elem, offset));
132 }
133 
134 BLI_INLINE float *CCG_elem_offset_no(const CCGKey *key, CCGElem *elem, int offset)
135 {
136  return CCG_elem_no(key, CCG_elem_offset(key, elem, offset));
137 }
138 
139 BLI_INLINE float *CCG_elem_offset_mask(const CCGKey *key, CCGElem *elem, int offset)
140 {
141  return CCG_elem_mask(key, CCG_elem_offset(key, elem, offset));
142 }
143 
145 {
146  return CCG_elem_offset(key, elem, 1);
147 }
148 
149 #ifdef __cplusplus
150 }
151 #endif
void CCG_key_top_level(CCGKey *key, const struct CCGSubSurf *ss)
void CCG_key(CCGKey *key, const struct CCGSubSurf *ss, int level)
BLI_INLINE CCGElem * CCG_elem_next(const CCGKey *key, CCGElem *elem)
Definition: BKE_ccg.h:144
BLI_INLINE CCGElem * CCG_grid_elem(const CCGKey *key, CCGElem *elem, int x, int y)
Definition: BKE_ccg.h:108
BLI_INLINE float * CCG_grid_elem_co(const CCGKey *key, CCGElem *elem, int x, int y)
Definition: BKE_ccg.h:114
BLI_INLINE float * CCG_elem_mask(const CCGKey *key, CCGElem *elem)
Definition: BKE_ccg.h:97
struct CCGKey CCGKey
BLI_INLINE CCGElem * CCG_elem_offset(const CCGKey *key, CCGElem *elem, int offset)
Definition: BKE_ccg.h:103
BLI_INLINE float * CCG_grid_elem_no(const CCGKey *key, CCGElem *elem, int x, int y)
Definition: BKE_ccg.h:119
BLI_INLINE float * CCG_elem_no(const CCGKey *key, CCGElem *elem)
Definition: BKE_ccg.h:91
struct CCGElem CCGElem
Definition: BKE_ccg.h:30
BLI_INLINE float * CCG_elem_offset_co(const CCGKey *key, CCGElem *elem, int offset)
Definition: BKE_ccg.h:129
BLI_INLINE float * CCG_grid_elem_mask(const CCGKey *key, CCGElem *elem, int x, int y)
Definition: BKE_ccg.h:124
BLI_INLINE float * CCG_elem_offset_no(const CCGKey *key, CCGElem *elem, int offset)
Definition: BKE_ccg.h:134
BLI_INLINE float * CCG_elem_co(const CCGKey *key, CCGElem *elem)
BLI_INLINE float * CCG_elem_offset_mask(const CCGKey *key, CCGElem *elem, int offset)
Definition: BKE_ccg.h:139
#define BLI_assert(a)
Definition: BLI_assert.h:46
#define BLI_INLINE
#define UNUSED(x)
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint y
ccl_gpu_kernel_postfix ccl_global float int int int int float bool int offset
Definition: BKE_ccg.h:32
int has_mask
Definition: BKE_ccg.h:55
int mask_offset
Definition: BKE_ccg.h:52
int grid_size
Definition: BKE_ccg.h:40
int grid_bytes
Definition: BKE_ccg.h:44
int grid_area
Definition: BKE_ccg.h:42
int level
Definition: BKE_ccg.h:33
int normal_offset
Definition: BKE_ccg.h:48
int elem_size
Definition: BKE_ccg.h:37
int has_normals
Definition: BKE_ccg.h:54