Blender V2.61 - r43446
|
00001 /* 00002 * Copyright 2011, Blender Foundation. 00003 * 00004 * This program is free software; you can redistribute it and/or 00005 * modify it under the terms of the GNU General Public License 00006 * as published by the Free Software Foundation; either version 2 00007 * of the License, or (at your option) any later version. 00008 * 00009 * This program is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 * GNU General Public License for more details. 00013 * 00014 * You should have received a copy of the GNU General Public License 00015 * along with this program; if not, write to the Free Software Foundation, 00016 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00017 */ 00018 00019 #ifndef __ATTRIBUTE_H__ 00020 #define __ATTRIBUTE_H__ 00021 00022 #include "kernel_types.h" 00023 00024 #include "util_list.h" 00025 #include "util_param.h" 00026 #include "util_types.h" 00027 #include "util_vector.h" 00028 00029 CCL_NAMESPACE_BEGIN 00030 00031 class Attribute; 00032 class AttributeSet; 00033 class AttributeRequest; 00034 class AttributeRequestSet; 00035 class Mesh; 00036 00037 /* Attribute 00038 * 00039 * Arbitrary data layers on meshes. 00040 * Supported types: Float, Color, Vector, Normal, Point */ 00041 00042 class Attribute { 00043 public: 00044 enum Element { 00045 VERTEX, 00046 FACE, 00047 CORNER 00048 }; 00049 00050 enum Standard { 00051 STD_NONE = 0, 00052 STD_VERTEX_NORMAL, 00053 STD_FACE_NORMAL, 00054 STD_UV, 00055 STD_GENERATED, 00056 STD_POSITION_UNDEFORMED, 00057 STD_POSITION_UNDISPLACED, 00058 STD_NUM 00059 }; 00060 00061 ustring name; 00062 Standard std; 00063 00064 TypeDesc type; 00065 vector<char> buffer; 00066 Element element; 00067 00068 Attribute() {} 00069 void set(ustring name, TypeDesc type, Element element); 00070 void reserve(int numverts, int numfaces); 00071 00072 size_t data_sizeof(); 00073 size_t element_size(int numverts, int numfaces); 00074 size_t buffer_size(int numverts, int numfaces); 00075 00076 char *data() { return (buffer.size())? &buffer[0]: NULL; }; 00077 float3 *data_float3() { return (float3*)data(); } 00078 float *data_float() { return (float*)data(); } 00079 00080 const char *data() const { return (buffer.size())? &buffer[0]: NULL; } 00081 const float3 *data_float3() const { return (float3*)data(); } 00082 const float *data_float() const { return (float*)data(); } 00083 00084 static bool same_storage(TypeDesc a, TypeDesc b); 00085 static ustring standard_name(Attribute::Standard std); 00086 }; 00087 00088 /* Attribute Set 00089 * 00090 * Set of attributes on a mesh. */ 00091 00092 class AttributeSet { 00093 public: 00094 Mesh *mesh; 00095 list<Attribute> attributes; 00096 00097 AttributeSet(Mesh *mesh); 00098 ~AttributeSet(); 00099 00100 Attribute *add(ustring name, TypeDesc type, Attribute::Element element); 00101 Attribute *find(ustring name); 00102 void remove(ustring name); 00103 00104 Attribute *add(Attribute::Standard std, ustring name = ustring()); 00105 Attribute *find(Attribute::Standard std); 00106 void remove(Attribute::Standard std); 00107 00108 Attribute *find(AttributeRequest& req); 00109 00110 void reserve(int numverts, int numfaces); 00111 void clear(); 00112 }; 00113 00114 /* AttributeRequest 00115 * 00116 * Request from a shader to use a certain attribute, so we can figure out 00117 * which ones we need to export from the host app end store for the kernel. 00118 * The attribute is found either by name or by standard. */ 00119 00120 class AttributeRequest { 00121 public: 00122 ustring name; 00123 Attribute::Standard std; 00124 00125 /* temporary variables used by MeshManager */ 00126 TypeDesc type; 00127 AttributeElement element; 00128 int offset; 00129 00130 AttributeRequest(ustring name_); 00131 AttributeRequest(Attribute::Standard std); 00132 }; 00133 00134 /* AttributeRequestSet 00135 * 00136 * Set of attributes requested by a shader. */ 00137 00138 class AttributeRequestSet { 00139 public: 00140 vector<AttributeRequest> requests; 00141 00142 AttributeRequestSet(); 00143 ~AttributeRequestSet(); 00144 00145 void add(ustring name); 00146 void add(Attribute::Standard std); 00147 void add(AttributeRequestSet& reqs); 00148 00149 bool find(ustring name); 00150 bool find(Attribute::Standard std); 00151 00152 size_t size(); 00153 void clear(); 00154 00155 bool modified(const AttributeRequestSet& other); 00156 }; 00157 00158 CCL_NAMESPACE_END 00159 00160 #endif /* __ATTRIBUTE_H__ */ 00161