X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fcore%2Fmesh.h;h=5544ed1f55e0e5cdf772cf9194d26bc9eabbd775;hb=190a7e11237351f6b730c28f7b16f183e8adc69c;hp=acf2910cb7ea208f3ce2fbab9c74bc182b781928;hpb=fcde8390ad577fe434dcd4b29e0f410d29f867c9;p=libs%2Fgl.git diff --git a/source/core/mesh.h b/source/core/mesh.h index acf2910c..5544ed1f 100644 --- a/source/core/mesh.h +++ b/source/core/mesh.h @@ -1,12 +1,14 @@ #ifndef MSP_GL_MESH_H_ #define MSP_GL_MESH_H_ +#include +#include #include #include "batch.h" +#include "cullface.h" #include "resource.h" #include "vertexarray.h" #include "vertexsetup.h" -#include "windingtest.h" namespace Msp { namespace GL { @@ -15,9 +17,12 @@ 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 { @@ -32,9 +37,10 @@ public: public: Loader(Mesh &, bool = true); private: - void vertices(const std::vector &); + void storage(const std::vector &); + void vertices(); + void vertices_with_format(const std::vector &); void batch(PrimitiveType); - void winding(FaceWinding); }; private: @@ -63,22 +69,23 @@ private: VertexArray vertices; std::vector batches; - Buffer *vbuf; - Buffer *ibuf; + Buffer *vbuf = 0; + Buffer *ibuf = 0; VertexSetup vtx_setup; - mutable unsigned short dirty; - bool disallow_rendering; - const WindingTest *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); -private: - void init(ResourceManager *); -public: + Mesh() = default; + Mesh(const VertexFormat &); ~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); @@ -87,16 +94,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; - float *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(const Batch &b); + const std::vector &get_batches() const { return batches; } - void set_winding(const WindingTest *); + 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; @@ -104,7 +121,7 @@ private: public: virtual int get_load_priority() const { return 1; } virtual Resource::AsyncLoader *load(IO::Seekable &, const Resources * = 0); - virtual UInt64 get_data_size() const; + virtual std::uint64_t get_data_size() const; virtual void unload(); void set_debug_name(const std::string &);