1 #ifndef MSP_GL_BATCH_H_
2 #define MSP_GL_BATCH_H_
5 #include <msp/datafile/objectloader.h>
6 #include "batch_backend.h"
7 #include "bufferable.h"
9 #include "primitivetype.h"
17 Stores primitive type and element indices for a single draw call.
19 Data type for indices is automatically chosen to accommodate the largest
20 index, but can also be manually overridden.
22 Batches are normally contained in a Mesh.
24 class Batch: public BatchBackend, public Bufferable
27 class Loader: public DataFile::ObjectLoader<Batch>
32 void indices(const std::vector<unsigned> &);
36 PrimitiveType prim_type;
38 std::vector<std::uint8_t> data;
44 PrimitiveType get_type() const { return prim_type; }
46 /** Sets the data type for indices. Allowed types are UNSIGNED_SHORT and
47 UNSIGNED_INT. It's an error to specify a type which can't hold the current
48 range of index values. */
49 void set_index_type(DataType);
51 DataType get_index_type() const { return index_type; }
53 /** Appends a single index. The data type is automatically adjusted if the
54 index is too large for the current data type. */
55 Batch &append(unsigned);
57 Batch &append(const std::vector<unsigned> &);
59 /** Checks if it's possible to append another Batch with a given primitive
61 bool can_append(PrimitiveType);
63 /** Appends another batch. Additional indices may be inserted in order to
64 join the primitives. */
65 Batch &append(const Batch &);
68 void append_index(unsigned);
69 virtual std::size_t get_data_size() const { return data.size(); }
70 virtual const void *get_data_pointer() const { return &data[0]; }
71 virtual std::size_t get_alignment() const { return get_index_size(); }
73 std::size_t get_index_size() const { return get_type_size(index_type); }
74 std::size_t size() const { return data.size()/get_index_size(); }
76 unsigned get_index(std::size_t) const;