4 #include <msp/datafile/objectloader.h>
8 #include "vertexarray.h"
9 #include "vertexsetup.h"
18 Raw mesh data, consisting of a VertexArray and one or more Batches. Though a
19 Mesh can draw itself, it's usually used as part of Renderables rather than on
22 class Mesh: public Resource
24 friend class MeshBuilder;
27 class Loader: public DataFile::ObjectLoader<Mesh>
33 Loader(Mesh &, bool = true);
35 void storage(const std::vector<VertexAttribute> &);
37 void vertices_with_format(const std::vector<VertexAttribute> &);
38 void batch(PrimitiveType);
42 class AsyncLoader: public Resource::AsyncLoader
47 Bufferable::AsyncUpdater *vertex_updater;
48 Bufferable::AsyncUpdater *index_updater;
52 AsyncLoader(Mesh &, IO::Seekable &);
55 virtual bool needs_sync() const;
56 virtual bool process();
66 std::vector<Batch> batches;
69 VertexSetup vtx_setup;
70 mutable unsigned short dirty;
71 bool disallow_rendering;
72 FaceWinding face_winding;
73 std::string debug_name;
76 Mesh(ResourceManager * = 0);
77 Mesh(const VertexFormat &, ResourceManager * = 0);
79 void init(ResourceManager *);
83 void storage(const VertexFormat &);
87 void check_buffers(unsigned);
90 const VertexArray &get_vertices() const { return vertices; }
91 const VertexSetup &get_vertex_setup() const { return vtx_setup; }
92 const Buffer *get_index_buffer() const { return ibuf; }
93 unsigned get_n_vertices() const;
94 char *modify_vertex(unsigned);
96 void add_batch(const Batch &b);
97 const std::vector<Batch> &get_batches() const { return batches; }
99 void set_winding(FaceWinding);
101 void draw(Renderer &) const;
102 void draw_instanced(Renderer &, const VertexSetup &, unsigned) const;
104 void draw(Renderer &, const VertexSetup *, unsigned) const;
105 void resize_buffers() const;
108 virtual int get_load_priority() const { return 1; }
109 virtual Resource::AsyncLoader *load(IO::Seekable &, const Resources * = 0);
110 virtual std::uint64_t get_data_size() const;
111 virtual void unload();
113 void set_debug_name(const std::string &);