]> git.tdb.fi Git - libs/gl.git/blobdiff - source/core/batch.h
Rearrange soucre files into subdirectories
[libs/gl.git] / source / core / batch.h
diff --git a/source/core/batch.h b/source/core/batch.h
new file mode 100644 (file)
index 0000000..2e4ad9e
--- /dev/null
@@ -0,0 +1,79 @@
+#ifndef MSP_GL_BATCH_H_
+#define MSP_GL_BATCH_H_
+
+#include <vector>
+#include <msp/datafile/objectloader.h>
+#include "bufferable.h"
+#include "datatype.h"
+#include "primitivetype.h"
+
+namespace Msp {
+namespace GL {
+
+class Buffer;
+
+/**
+Stores primitive type and element indices for a single GL draw call.  Data
+type for indices is automatically chosen to accommodate the largest index in
+the Batch.
+
+This is a pretty low-level class and mainly intended to be used by the Mesh
+class.
+*/
+class Batch: public Bufferable
+{
+public:
+       class Loader: public DataFile::ObjectLoader<Batch>
+       {
+       public:
+               Loader(Batch &);
+       private:
+               void indices(const std::vector<unsigned> &);
+       };
+
+private:
+       PrimitiveType prim_type;
+       DataType index_type;
+       std::vector<UInt8> data;
+       unsigned max_index;
+       bool restart;
+
+       static unsigned restart_index;
+
+public:
+       Batch(PrimitiveType t);
+       ~Batch();
+
+       PrimitiveType get_type() const { return prim_type; }
+       void set_index_type(DataType);
+       DataType get_index_type() const { return index_type; }
+
+       DEPRECATED void set_data_type(DataType t) { set_index_type(t); }
+       DEPRECATED DataType get_data_type() const { return index_type; }
+
+       Batch &append(unsigned);
+       Batch &append(const std::vector<unsigned> &);
+       bool can_append(PrimitiveType);
+       Batch &append(const Batch &);
+private:
+       void append_index(unsigned);
+       virtual unsigned get_data_size() const { return data.size(); }
+       virtual const void *get_data_pointer() const { return &data[0]; }
+       virtual unsigned get_alignment() const { return get_index_size(); }
+       unsigned get_index_size() const;
+public:
+       unsigned size() const { return data.size()/get_index_size(); }
+
+       unsigned get_index(unsigned) const;
+
+       void draw() const;
+       void draw_instanced(unsigned) const;
+private:
+       const void *setup_draw() const;
+       static void set_restart_index(unsigned);
+};
+
+} // namespace GL
+} // namespace Msp
+
+#endif