3 #include "vertexarray.h"
4 #include "vertexsetup.h"
11 void VertexSetup::set_format(const VertexFormat &vfmt)
13 if(!verify_format(vfmt))
14 throw invalid_argument("VertexSetup::set_format");
15 if(!vertex_format.empty())
16 throw invalid_operation("VertexSetup::set_format");
18 require_format(vfmt, false);
23 void VertexSetup::set_format_instanced(const VertexFormat &vfmt, const VertexFormat &ifmt)
25 if(!verify_format(vfmt) || !verify_format(ifmt))
26 throw invalid_argument("VertexSetup::set_format_instanced");
27 if(!vertex_format.empty())
28 throw invalid_operation("VertexSetup::set_format_instanced");
30 require_format(vfmt, false);
31 require_format(ifmt, true);
37 void VertexSetup::set_vertex_array(const VertexArray &a)
39 if(vertex_format.empty())
40 throw invalid_operation("VertexSetup::set_vertex_array");
41 if(a.get_format()!=vertex_format)
42 throw incompatible_data("VertexSetup::set_vertex_array");
44 throw invalid_argument("VertexSetup::set_vertex_array");
47 dirty |= VERTEX_ARRAY;
50 void VertexSetup::set_instance_array(const VertexArray &a)
52 if(inst_format.empty())
53 throw invalid_operation("VertexSetup::set_instance_array");
54 if(a.get_format()!=inst_format)
55 throw incompatible_data("VertexSetup::set_instance_array");
57 throw invalid_argument("VertexSetup::set_instance_array");
60 dirty |= INSTANCE_ARRAY;
63 void VertexSetup::set_index_buffer(const Buffer &ibuf, DataType itype)
67 dirty |= INDEX_BUFFER;
70 bool VertexSetup::verify_format(const VertexFormat &fmt)
75 static unsigned max_attribs = Device::get_current().get_info().limits.max_vertex_attributes;
76 return all_of(fmt.begin(), fmt.end(), [](VertexAttribute a){ return get_attribute_semantic(a)<max_attribs; });
79 void VertexSetup::update() const
81 VertexSetupBackend::update(dirty);
85 void VertexSetup::unload()
87 VertexSetupBackend::unload();
90 vertex_format = VertexFormat();
92 inst_format = VertexFormat();