Blender  V2.93
attribute.h
Go to the documentation of this file.
1 /*
2  * Copyright 2011-2013 Blender Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef __ATTRIBUTE_H__
18 #define __ATTRIBUTE_H__
19 
20 #include "render/image.h"
21 
22 #include "kernel/kernel_types.h"
23 
24 #include "util/util_list.h"
25 #include "util/util_param.h"
26 #include "util/util_set.h"
27 #include "util/util_types.h"
28 #include "util/util_vector.h"
29 
31 
32 class Attribute;
33 class AttributeRequest;
35 class AttributeSet;
36 class ImageHandle;
37 class Geometry;
38 class Hair;
39 class Mesh;
40 struct Transform;
41 
42 /* Attribute
43  *
44  * Arbitrary data layers on meshes.
45  * Supported types: Float, Color, Vector, Normal, Point */
46 
47 class Attribute {
48  public:
49  ustring name;
51 
52  TypeDesc type;
55  uint flags; /* enum AttributeFlag */
56 
57  bool modified;
58 
59  Attribute(ustring name,
60  TypeDesc type,
62  Geometry *geom,
63  AttributePrimitive prim);
64  Attribute(Attribute &&other) = default;
65  Attribute(const Attribute &other) = delete;
66  Attribute &operator=(const Attribute &other) = delete;
67  ~Attribute();
68 
69  void set(ustring name, TypeDesc type, AttributeElement element);
70  void resize(Geometry *geom, AttributePrimitive prim, bool reserve_only);
71  void resize(size_t num_elements);
72 
73  size_t data_sizeof() const;
74  size_t element_size(Geometry *geom, AttributePrimitive prim) const;
75  size_t buffer_size(Geometry *geom, AttributePrimitive prim) const;
76 
77  char *data()
78  {
79  return (buffer.size()) ? &buffer[0] : NULL;
80  }
82  {
83  assert(data_sizeof() == sizeof(float2));
84  return (float2 *)data();
85  }
87  {
88  assert(data_sizeof() == sizeof(float3));
89  return (float3 *)data();
90  }
91  float4 *data_float4()
92  {
93  assert(data_sizeof() == sizeof(float4));
94  return (float4 *)data();
95  }
96  float *data_float()
97  {
98  assert(data_sizeof() == sizeof(float));
99  return (float *)data();
100  }
102  {
103  assert(data_sizeof() == sizeof(uchar4));
104  return (uchar4 *)data();
105  }
107  {
108  assert(data_sizeof() == sizeof(Transform));
109  return (Transform *)data();
110  }
111 
112  /* Attributes for voxels are images */
114  {
115  assert(data_sizeof() == sizeof(ImageHandle));
116  return *(ImageHandle *)data();
117  }
118 
119  const char *data() const
120  {
121  return (buffer.size()) ? &buffer[0] : NULL;
122  }
123  const float2 *data_float2() const
124  {
125  assert(data_sizeof() == sizeof(float2));
126  return (const float2 *)data();
127  }
128  const float3 *data_float3() const
129  {
130  assert(data_sizeof() == sizeof(float3));
131  return (const float3 *)data();
132  }
133  const float4 *data_float4() const
134  {
135  assert(data_sizeof() == sizeof(float4));
136  return (const float4 *)data();
137  }
138  const float *data_float() const
139  {
140  assert(data_sizeof() == sizeof(float));
141  return (const float *)data();
142  }
143  const Transform *data_transform() const
144  {
145  assert(data_sizeof() == sizeof(Transform));
146  return (const Transform *)data();
147  }
148  const ImageHandle &data_voxel() const
149  {
150  assert(data_sizeof() == sizeof(ImageHandle));
151  return *(const ImageHandle *)data();
152  }
153 
154  void zero_data(void *dst);
155  void add_with_weight(void *dst, void *src, float weight);
156 
157  void add(const float &f);
158  void add(const float2 &f);
159  void add(const float3 &f);
160  void add(const uchar4 &f);
161  void add(const Transform &tfm);
162  void add(const char *data);
163 
164  void set_data_from(Attribute &&other);
165 
166  static bool same_storage(TypeDesc a, TypeDesc b);
167  static const char *standard_name(AttributeStandard std);
168  static AttributeStandard name_standard(const char *name);
169 
170  void get_uv_tiles(Geometry *geom, AttributePrimitive prim, unordered_set<int> &tiles) const;
171 };
172 
173 /* Attribute Set
174  *
175  * Set of attributes on a mesh. */
176 
178  public:
181  list<Attribute> attributes;
182  bool modified = true;
183 
185  AttributeSet(AttributeSet &&) = default;
186  ~AttributeSet();
187 
188  Attribute *add(ustring name, TypeDesc type, AttributeElement element);
189  Attribute *find(ustring name) const;
190  void remove(ustring name);
191 
192  Attribute *add(AttributeStandard std, ustring name = ustring());
195 
197 
198  void remove(Attribute *attribute);
199 
200  void resize(bool reserve_only = false);
201  void clear(bool preserve_voxel_data = false);
202 
203  /* Update the attributes in this AttributeSet with the ones from the new set,
204  * and remove any attribute not found on the new set from this. */
205  void update(AttributeSet &&new_attributes);
206 
207  void clear_modified();
208 };
209 
210 /* AttributeRequest
211  *
212  * Request from a shader to use a certain attribute, so we can figure out
213  * which ones we need to export from the host app end store for the kernel.
214  * The attribute is found either by name or by standard attribute type. */
215 
217  public:
218  ustring name;
220 
221  /* temporary variables used by GeometryManager */
222  TypeDesc type, subd_type;
224 
225  explicit AttributeRequest(ustring name_);
227 };
228 
229 /* AttributeRequestSet
230  *
231  * Set of attributes requested by a shader. */
232 
234  public:
236 
239 
240  void add(ustring name);
241  void add(AttributeStandard std);
242  void add(AttributeRequestSet &reqs);
243  void add_standard(ustring name);
244 
245  bool find(ustring name);
246  bool find(AttributeStandard std);
247 
248  size_t size();
249  void clear();
250 
251  bool modified(const AttributeRequestSet &other);
252 };
253 
255 
256 #endif /* __ATTRIBUTE_H__ */
unsigned int uint
Definition: BLI_sys_types.h:83
_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 type
ATTR_WARN_UNUSED_RESULT const void * element
vector< AttributeRequest > requests
Definition: attribute.h:235
bool find(ustring name)
Definition: attribute.cpp:816
void add(ustring name)
Definition: attribute.cpp:770
bool modified(const AttributeRequestSet &other)
Definition: attribute.cpp:749
void add_standard(ustring name)
Definition: attribute.cpp:800
TypeDesc subd_type
Definition: attribute.h:222
AttributeRequest(ustring name_)
Definition: attribute.cpp:707
TypeDesc type
Definition: attribute.h:222
AttributeDescriptor subd_desc
Definition: attribute.h:223
AttributeDescriptor desc
Definition: attribute.h:223
AttributeStandard std
Definition: attribute.h:219
Geometry * geometry
Definition: attribute.h:179
Attribute * add(ustring name, TypeDesc type, AttributeElement element)
Definition: attribute.cpp:428
void update(AttributeSet &&new_attributes)
Definition: attribute.cpp:663
AttributeSet(AttributeSet &&)=default
list< Attribute > attributes
Definition: attribute.h:181
Attribute * find(ustring name) const
Definition: attribute.cpp:447
void remove(ustring name)
Definition: attribute.cpp:456
void clear_modified()
Definition: attribute.cpp:697
AttributeSet(Geometry *geometry, AttributePrimitive prim)
Definition: attribute.cpp:419
bool modified
Definition: attribute.h:182
void resize(bool reserve_only=false)
Definition: attribute.cpp:637
void clear(bool preserve_voxel_data=false)
Definition: attribute.cpp:644
AttributePrimitive prim
Definition: attribute.h:180
ImageHandle & data_voxel()
Definition: attribute.h:113
AttributeElement element
Definition: attribute.h:54
const ImageHandle & data_voxel() const
Definition: attribute.h:148
static bool same_storage(TypeDesc a, TypeDesc b)
Definition: attribute.cpp:270
void add_with_weight(void *dst, void *src, float weight)
Definition: attribute.cpp:290
Attribute & operator=(const Attribute &other)=delete
const float4 * data_float4() const
Definition: attribute.h:133
float * data_float()
Definition: attribute.h:96
uchar4 * data_uchar4()
Definition: attribute.h:101
void set(ustring name, TypeDesc type, AttributeElement element)
const float2 * data_float2() const
Definition: attribute.h:123
static AttributeStandard name_standard(const char *name)
Definition: attribute.cpp:373
Attribute(const Attribute &other)=delete
Transform * data_transform()
Definition: attribute.h:106
TypeDesc type
Definition: attribute.h:52
const float3 * data_float3() const
Definition: attribute.h:128
void resize(Geometry *geom, AttributePrimitive prim, bool reserve_only)
Definition: attribute.cpp:57
size_t element_size(Geometry *geom, AttributePrimitive prim) const
Definition: attribute.cpp:185
float4 * data_float4()
Definition: attribute.h:91
void get_uv_tiles(Geometry *geom, AttributePrimitive prim, unordered_set< int > &tiles) const
Definition: attribute.cpp:386
char * data()
Definition: attribute.h:77
vector< char > buffer
Definition: attribute.h:53
void set_data_from(Attribute &&other)
Definition: attribute.cpp:151
bool modified
Definition: attribute.h:57
void zero_data(void *dst)
Definition: attribute.cpp:285
Attribute(ustring name, TypeDesc type, AttributeElement element, Geometry *geom, AttributePrimitive prim)
Definition: attribute.cpp:29
static const char * standard_name(AttributeStandard std)
Definition: attribute.cpp:311
Attribute(Attribute &&other)=default
uint flags
Definition: attribute.h:55
size_t buffer_size(Geometry *geom, AttributePrimitive prim) const
Definition: attribute.cpp:265
AttributeStandard std
Definition: attribute.h:50
ustring name
Definition: attribute.h:49
const Transform * data_transform() const
Definition: attribute.h:143
size_t data_sizeof() const
Definition: attribute.cpp:169
const float * data_float() const
Definition: attribute.h:138
void add(const float &f)
Definition: attribute.cpp:76
float3 * data_float3()
Definition: attribute.h:86
const char * data() const
Definition: attribute.h:119
float2 * data_float2()
Definition: attribute.h:81
#define CCL_NAMESPACE_END
AttributeStandard
Definition: kernel_types.h:744
AttributeElement
Definition: kernel_types.h:729
AttributePrimitive
Definition: kernel_types.h:722
static unsigned a[3]
Definition: RandGen.cpp:92