1 #include "vertexarray.h"
2 #include "vertexarraybuilder.h"
9 VertexArrayBuilder::VertexArrayBuilder(VertexArray &a):
13 void VertexArrayBuilder::vertex_(const Vector4 &vtx)
15 char *ptr = array.append();
16 const VertexFormat &format = array.get_format();
17 for(const UInt16 *a=format.begin(); a!=format.end(); ++a)
19 unsigned sem = get_attribute_semantic(*a);
20 bool integer = is_integer_attribute(*a);
21 DataType type = get_attribute_source_type(*a);
22 unsigned cc = get_attribute_component_count(*a);
26 const Vector4 &value = (sem==0 ? vtx : attr[sem]);
27 if(type==UNSIGNED_BYTE)
28 store_attribute<UInt8>(ptr, value, !integer, cc);
30 store_attribute<Int8>(ptr, value, !integer, cc);
31 else if(type==UNSIGNED_SHORT)
32 store_attribute<UInt16>(ptr, value, !integer, cc);
34 store_attribute<Int16>(ptr, value, !integer, cc);
35 else if(type==UNSIGNED_INT)
36 store_attribute<UInt32>(ptr, value, !integer, cc);
38 store_attribute<Int32>(ptr, value, !integer, cc);
40 store_attribute<float>(ptr, value, false, cc);
43 ptr += get_attribute_size(*a);
48 void VertexArrayBuilder::store_attribute(char *ptr, const Vector4 &value, bool normalize, unsigned count)
50 T *tptr = reinterpret_cast<T *>(ptr);
51 for(unsigned i=0; i<count; ++i)
53 if(!numeric_limits<T>::is_integer || !normalize)
55 else if(numeric_limits<T>::is_signed)
56 *tptr++ = round(min(max(value[i], -1.0f), 1.0f)*numeric_limits<T>::max());
58 *tptr++ = round(min(max(value[i], 0.0f), 1.0f)*numeric_limits<T>::max());