]> git.tdb.fi Git - libs/gl.git/blobdiff - source/core/mesh.h
Check the flat qualifier from the correct member
[libs/gl.git] / source / core / mesh.h
index 39bf55b22d5129f0725f11a44233f48be28556d9..ba2aebc76c1fd35254f66429f5035e4370d587b5 100644 (file)
@@ -17,22 +17,28 @@ class Buffer;
 class Renderer;
 
 /**
-Raw mesh data, consisting of a VertexArray and one or more Batches.  Though a
-Mesh can draw itself, it's usually used as part of Renderables rather than on
-its own.
+Stores mesh data using a VertexArray and one or more Batches.
+
+Meshes can be created at runtime using the MeshBuilder class.
+
+The Object class provides a higher-level interface which associates a Mesh with
+a Technique and is usually the appropriate way to of rendering geometry.
 */
 class Mesh: public Resource
 {
        friend class MeshBuilder;
+       class AsyncLoader;
 
 public:
        class Loader: public DataFile::ObjectLoader<Mesh>
        {
+               friend class AsyncLoader;
+
        private:
-               bool allow_gl_calls;
+               bool allow_gl_calls = true;
 
        public:
-               Loader(Mesh &, bool = true);
+               Loader(Mesh &);
        private:
                void storage(const std::vector<VertexAttribute> &);
                void vertices();
@@ -46,9 +52,9 @@ private:
        private:
                Mesh &mesh;
                IO::Seekable &io;
-               Bufferable::AsyncUpdater *vertex_updater;
-               Bufferable::AsyncUpdater *index_updater;
-               unsigned phase;
+               Bufferable::AsyncUpdater *vertex_updater = 0;
+               Bufferable::AsyncUpdater *index_updater = 0;
+               unsigned phase = 0;
 
        public:
                AsyncLoader(Mesh &, IO::Seekable &);
@@ -66,21 +72,24 @@ private:
 
        VertexArray vertices;
        std::vector<Batch> batches;
-       Buffer *vbuf;
-       Buffer *ibuf;
+       Buffer *vbuf = 0;
+       Buffer *ibuf = 0;
        VertexSetup vtx_setup;
-       mutable unsigned short dirty;
-       bool disallow_rendering;
-       FaceWinding face_winding;
+       mutable unsigned short dirty = 0;
+       bool disallow_rendering = false;
+       FaceWinding face_winding = NON_MANIFOLD;
        std::string debug_name;
 
 public:
-       Mesh(ResourceManager * = 0);
-       Mesh(const VertexFormat &, ResourceManager * = 0);
+       Mesh() = default;
+       Mesh(const VertexFormat &);
+       Mesh(Mesh &&);
        ~Mesh();
 
+       /** Sets the vertex format for the mesh.  It cannot be changed once set. */
        void storage(const VertexFormat &);
 
+       /** Clears all vertices and batches.  Vertex format is retained. */
        void clear();
 private:
        void check_buffers(unsigned);
@@ -89,16 +98,26 @@ public:
        const VertexArray &get_vertices() const { return vertices; }
        const VertexSetup &get_vertex_setup() const { return vtx_setup; }
        const Buffer *get_index_buffer() const { return ibuf; }
-       unsigned get_n_vertices() const;
-       char *modify_vertex(unsigned);
+       std::size_t get_n_vertices() const;
+
+       /** Returns a pointer to a vertex.  Offsets of individual attributes can be
+       queried from VertexFormat. */
+       char *modify_vertex(std::size_t);
+
+       /** Adds a batch to the mesh.  It may be combined with the last existing
+       batch if the primitive types are compatible. */
+       void add_batch(Batch &&b);
 
-       void add_batch(const Batch &b);
        const std::vector<Batch> &get_batches() const { return batches; }
 
        void set_winding(FaceWinding);
 
        void draw(Renderer &) const;
+       
+       /** Draws multiple instances of the mesh.  The supplied VertexSetup must use
+       the mesh's vertex array. */
        void draw_instanced(Renderer &, const VertexSetup &, unsigned) const;
+
 private:
        void draw(Renderer &, const VertexSetup *, unsigned) const;
        void resize_buffers() const;