6 #include <msp/datafile/objectloader.h>
10 #include "vertexarray.h"
11 #include "vertexsetup.h"
20 Stores mesh data using a VertexArray and one or more Batches.
22 Meshes can be created at runtime using the MeshBuilder class.
24 The Object class provides a higher-level interface which associates a Mesh with
25 a Technique and is usually the appropriate way to of rendering geometry.
27 class Mesh: public Resource
29 friend class MeshBuilder;
33 class Loader: public DataFile::ObjectLoader<Mesh>
35 friend class AsyncLoader;
38 bool allow_gl_calls = true;
43 void storage(const std::vector<VertexAttribute> &);
45 void vertices_with_format(const std::vector<VertexAttribute> &);
46 void batch(PrimitiveType);
50 class AsyncLoader: public Resource::AsyncLoader
55 Bufferable::AsyncUpdater *vertex_updater = 0;
56 Bufferable::AsyncUpdater *index_updater = 0;
60 AsyncLoader(Mesh &, IO::Seekable &);
63 virtual bool needs_sync() const;
64 virtual bool process();
74 std::vector<Batch> batches;
77 VertexSetup vtx_setup;
78 mutable unsigned short dirty = 0;
79 bool disallow_rendering = false;
80 FaceWinding face_winding = NON_MANIFOLD;
81 std::string debug_name;
85 Mesh(const VertexFormat &);
89 /** Sets the vertex format for the mesh. It cannot be changed once set. */
90 void storage(const VertexFormat &);
92 /** Clears all vertices and batches. Vertex format is retained. */
95 void check_buffers(unsigned);
98 const VertexArray &get_vertices() const { return vertices; }
99 const VertexSetup &get_vertex_setup() const { return vtx_setup; }
100 const Buffer *get_index_buffer() const { return ibuf; }
101 std::size_t get_n_vertices() const;
103 /** Returns a pointer to a vertex. Offsets of individual attributes can be
104 queried from VertexFormat. */
105 char *modify_vertex(std::size_t);
107 /** Adds a batch to the mesh. It may be combined with the last existing
108 batch if the primitive types are compatible. */
109 void add_batch(Batch &&b);
111 const std::vector<Batch> &get_batches() const { return batches; }
113 void set_winding(FaceWinding);
115 void draw(Renderer &) const;
117 /** Draws multiple instances of the mesh. The supplied VertexSetup must use
118 the mesh's vertex array. */
119 void draw_instanced(Renderer &, const VertexSetup &, unsigned) const;
122 void draw(Renderer &, const VertexSetup *, unsigned) const;
123 void resize_buffers() const;
126 virtual int get_load_priority() const { return 1; }
127 virtual Resource::AsyncLoader *load(IO::Seekable &, const Resources * = 0);
128 virtual std::uint64_t get_data_size() const;
129 virtual void unload();
131 void set_debug_name(const std::string &);