]> git.tdb.fi Git - libs/gl.git/blobdiff - source/vertexarray.h
Present Mesh's index buffer as current while the Mesh is bound
[libs/gl.git] / source / vertexarray.h
index 26204b312134e4bc1c5ebf2ebe845c19ff205304..e38f0afff910b20500b750983fcf957db934d741 100644 (file)
@@ -6,6 +6,7 @@
 #include <msp/core/refptr.h>
 #include <msp/datafile/loader.h>
 #include "bindable.h"
+#include "bufferable.h"
 #include "datatype.h"
 #include "primitivetype.h"
 #include "vertexarraybuilder.h"
@@ -16,7 +17,7 @@ namespace GL {
 
 class Buffer;
 
-class VertexArray: public Bindable<VertexArray>
+class VertexArray: public Bindable<VertexArray>, public Bufferable
 {
 public:
        class Loader: public DataFile::Loader, public VertexArrayBuilder
@@ -26,13 +27,18 @@ public:
        };
 
 private:
+       struct Array
+       {
+               unsigned char component;
+               unsigned char offset;
+
+               Array();
+       };
+
        VertexFormat format;
        std::vector<float> data;
        unsigned stride;
-       std::vector<unsigned char> arrays;
-       RefPtr<Buffer> vbuf;
-       bool defer_vbuf;
-       mutable bool dirty;
+       std::vector<Array> arrays;
 
        VertexArray(const VertexArray &);
        VertexArray &operator=(const VertexArray &);
@@ -46,15 +52,16 @@ private:
        static unsigned get_array_slot(unsigned char);
 
 public:
-       void use_vertex_buffer();
-       void use_vertex_buffer(Buffer *);
+       /// Deprecated alias for use_buffer
+       void use_vertex_buffer(Buffer *b) { use_buffer(b); }
 
        void clear();
        void reserve(unsigned);
        float *append();
        float *modify(unsigned);
 private:
-       void set_dirty();
+       virtual unsigned get_data_size() const;
+       virtual void upload_data() const;
 
 public:
        unsigned size() const { return data.size()/stride; }
@@ -62,6 +69,8 @@ public:
        const float *operator[](unsigned i) const { return &data[0]+i*stride; }
 
        void apply() const;
+private:
+       static void apply_arrays(const std::vector<Array> *, const std::vector<Array> *, const float *, unsigned);
 };
 
 } // namespace GL