1 #include "deviceinfo.h"
3 #include "vertexarray.h"
4 #include "vertexsetup.h"
11 VertexSetup::VertexSetup():
16 index_type(UNSIGNED_SHORT)
19 void VertexSetup::set_format(const VertexFormat &vfmt)
21 if(!verify_format(vfmt))
22 throw invalid_argument("VertexSetup::set_format");
23 if(!vertex_format.empty())
24 throw invalid_operation("VertexSetup::set_format");
26 require_format(vfmt, false);
31 void VertexSetup::set_format_instanced(const VertexFormat &vfmt, const VertexFormat &ifmt)
33 if(!verify_format(vfmt) || !verify_format(ifmt))
34 throw invalid_argument("VertexSetup::set_format");
35 if(!vertex_format.empty())
36 throw invalid_operation("VertexSetup::set_format");
38 require_format(vfmt, false);
39 require_format(ifmt, true);
45 void VertexSetup::set_vertex_array(const VertexArray &a)
47 if(vertex_format.empty())
48 throw invalid_operation("VertexSetup::set_vertex_array");
49 if(a.get_format()!=vertex_format)
50 throw incompatible_data("VertexSetup::set_vertex_array");
52 throw invalid_argument("VertexSetup::set_vertex_array");
55 dirty |= VERTEX_ARRAY;
58 void VertexSetup::set_instance_array(const VertexArray &a)
60 if(inst_format.empty())
61 throw invalid_operation("VertexSetup::set_instance_array");
62 if(a.get_format()!=inst_format)
63 throw incompatible_data("VertexSetup::set_instance_array");
65 throw invalid_argument("VertexSetup::set_instance_array");
68 dirty |= INSTANCE_ARRAY;
71 void VertexSetup::set_index_buffer(const Buffer &ibuf, DataType itype)
75 dirty |= INDEX_BUFFER;
78 bool VertexSetup::verify_format(const VertexFormat &fmt)
83 static unsigned max_attribs = DeviceInfo::get_global().limits.max_vertex_attributes;
84 return all_of(fmt.begin(), fmt.end(), [](VertexAttribute a){ return get_attribute_semantic(a)<max_attribs; });
87 void VertexSetup::update() const
89 VertexSetupBackend::update(dirty);
93 void VertexSetup::unload()
95 VertexSetupBackend::unload();
98 vertex_format = VertexFormat();
100 inst_format = VertexFormat();