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;
45 PrimitiveType get_type() const { return prim_type; }
47 /** Sets the data type for indices. Allowed types are UNSIGNED_SHORT and
48 UNSIGNED_INT. It's an error to specify a type which can't hold the current
49 range of index values. */
50 void set_index_type(DataType);
52 DataType get_index_type() const { return index_type; }
54 /** Appends a single index. The data type is automatically adjusted if the
55 index is too large for the current data type. */
56 Batch &append(unsigned);
58 Batch &append(const std::vector<unsigned> &);
60 /** Checks if it's possible to append another Batch with a given primitive
62 bool can_append(PrimitiveType);
64 /** Appends another batch. Additional indices may be inserted in order to
65 join the primitives. */
66 Batch &append(const Batch &);
69 void append_index(unsigned);
70 virtual std::size_t get_data_size() const { return data.size(); }
71 virtual const void *get_data_pointer() const { return &data[0]; }
72 virtual std::size_t get_alignment() const { return get_index_size(); }
73 std::size_t get_index_size() const;
75 std::size_t size() const { return data.size()/get_index_size(); }
77 unsigned get_index(std::size_t) const;