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 for(VertexAttribute a: array.get_format())
18 unsigned sem = get_attribute_semantic(a);
19 if(!is_padding(a) && sem<attr.size())
21 bool integer = is_integer_attribute(a);
22 DataType type = get_attribute_source_type(a);
23 unsigned cc = get_attribute_component_count(a);
25 const Vector4 &value = (sem==0 ? vtx : attr[sem]);
26 if(type==UNSIGNED_BYTE)
27 store_attribute<uint8_t>(ptr, value, !integer, cc);
29 store_attribute<int8_t>(ptr, value, !integer, cc);
30 else if(type==UNSIGNED_SHORT)
31 store_attribute<uint16_t>(ptr, value, !integer, cc);
33 store_attribute<int16_t>(ptr, value, !integer, cc);
34 else if(type==UNSIGNED_INT)
35 store_attribute<uint32_t>(ptr, value, !integer, cc);
37 store_attribute<int32_t>(ptr, value, !integer, cc);
39 store_attribute<float>(ptr, value, false, cc);
42 ptr += get_attribute_size(a);
47 void VertexArrayBuilder::store_attribute(char *ptr, const Vector4 &value, bool normalize, unsigned count)
49 T *tptr = reinterpret_cast<T *>(ptr);
50 for(unsigned i=0; i<count; ++i)
52 if(!numeric_limits<T>::is_integer || !normalize)
54 else if(numeric_limits<T>::is_signed)
55 *tptr++ = round(min(max(value[i], -1.0f), 1.0f)*numeric_limits<T>::max());
57 *tptr++ = round(min(max(value[i], 0.0f), 1.0f)*numeric_limits<T>::max());