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> &);
33 void patch_size(unsigned);
37 PrimitiveType prim_type;
39 std::vector<std::uint8_t> data;
40 unsigned max_index = 0;
41 unsigned patch_size = 3;
46 PrimitiveType get_type() const { return prim_type; }
48 /** Sets the data type for indices. Allowed types are UNSIGNED_SHORT and
49 UNSIGNED_INT. It's an error to specify a type which can't hold the current
50 range of index values. */
51 void set_index_type(DataType);
53 DataType get_index_type() const { return index_type; }
55 /** Sets the number of control points per patch. Only available if the
56 primitive type is PATCHES. */
57 void set_patch_size(unsigned);
59 unsigned get_patch_size() const { return patch_size; }
61 /** Appends a single index. The data type is automatically adjusted if the
62 index is too large for the current data type. */
63 Batch &append(unsigned);
65 Batch &append(const std::vector<unsigned> &);
67 /** Checks if it's possible to append another Batch with a given primitive
69 bool can_append(PrimitiveType);
71 /** Appends another batch. Additional indices may be inserted in order to
72 join the primitives. */
73 Batch &append(const Batch &);
76 void append_index(unsigned);
77 virtual std::size_t get_data_size() const { return data.size(); }
78 virtual const void *get_data_pointer() const { return &data[0]; }
79 virtual std::size_t get_alignment() const { return get_index_size(); }
81 std::size_t get_index_size() const { return get_type_size(index_type); }
82 std::size_t size() const { return data.size()/get_index_size(); }
84 unsigned get_index(std::size_t) const;