2 * Copyright 2011, Blender Foundation.
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.
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.
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.
19 #ifndef __ATTRIBUTE_H__
20 #define __ATTRIBUTE_H__
22 #include "kernel_types.h"
24 #include "util_list.h"
25 #include "util_param.h"
26 #include "util_types.h"
27 #include "util_vector.h"
33 class AttributeRequest;
34 class AttributeRequestSet;
39 * Arbitrary data layers on meshes.
40 * Supported types: Float, Color, Vector, Normal, Point */
56 STD_POSITION_UNDEFORMED,
57 STD_POSITION_UNDISPLACED,
69 void set(ustring name, TypeDesc type, Element element);
70 void reserve(int numverts, int numfaces);
73 size_t element_size(int numverts, int numfaces);
74 size_t buffer_size(int numverts, int numfaces);
76 char *data() { return &buffer[0]; };
77 float3 *data_float3() { return (float3*)&buffer[0]; }
78 float *data_float() { return (float*)&buffer[0]; }
80 const char *data() const { return &buffer[0]; }
81 const float3 *data_float3() const { return (float3*)&buffer[0]; }
82 const float *data_float() const { return (float*)&buffer[0]; }
84 static bool same_storage(TypeDesc a, TypeDesc b);
85 static ustring standard_name(Attribute::Standard std);
90 * Set of attributes on a mesh. */
95 list<Attribute> attributes;
97 AttributeSet(Mesh *mesh);
100 Attribute *add(ustring name, TypeDesc type, Attribute::Element element);
101 Attribute *find(ustring name);
102 void remove(ustring name);
104 Attribute *add(Attribute::Standard std, ustring name = ustring());
105 Attribute *find(Attribute::Standard std);
106 void remove(Attribute::Standard std);
108 Attribute *find(AttributeRequest& req);
110 void reserve(int numverts, int numfaces);
116 * Request from a shader to use a certain attribute, so we can figure out
117 * which ones we need to export from the host app end store for the kernel.
118 * The attribute is found either by name or by standard. */
120 class AttributeRequest {
123 Attribute::Standard std;
125 /* temporary variables used by MeshManager */
127 AttributeElement element;
130 AttributeRequest(ustring name_);
131 AttributeRequest(Attribute::Standard std);
134 /* AttributeRequestSet
136 * Set of attributes requested by a shader. */
138 class AttributeRequestSet {
140 vector<AttributeRequest> requests;
142 AttributeRequestSet();
143 ~AttributeRequestSet();
145 void add(ustring name);
146 void add(Attribute::Standard std);
147 void add(AttributeRequestSet& reqs);
149 bool find(ustring name);
150 bool find(Attribute::Standard std);
155 bool modified(const AttributeRequestSet& other);
160 #endif /* __ATTRIBUTE_H__ */