]> git.tdb.fi Git - libs/gl.git/blobdiff - source/vertexarray.h
Allow applying a VertexArray in non-legacy mode
[libs/gl.git] / source / vertexarray.h
index af1817b18461893591bc72c001db80c1dd72c0ce..d6dee7dd59ce3a9f3c81185aed2a405fa571277a 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
@@ -38,8 +39,9 @@ private:
        std::vector<float> data;
        unsigned stride;
        std::vector<Array> arrays;
-       Buffer *vbuf;
-       mutable bool dirty;
+       bool legacy;
+
+       static bool legacy_used;
 
        VertexArray(const VertexArray &);
        VertexArray &operator=(const VertexArray &);
@@ -53,23 +55,28 @@ private:
        static unsigned get_array_slot(unsigned char);
 
 public:
-       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 const void *get_data_pointer() const { return &data[0]; }
 
 public:
        unsigned size() const { return data.size()/stride; }
        const std::vector<float> &get_data() const { return data; }
        const float *operator[](unsigned i) const { return &data[0]+i*stride; }
 
-       void apply() const;
+       void bind() const { apply(); }
+       void apply(bool = true) const;
 private:
-       static void apply_arrays(const std::vector<Array> *, const std::vector<Array> *, const float *, unsigned);
+       static void apply_arrays(const std::vector<Array> *, const std::vector<Array> *, const float *, unsigned, bool);
+public:
+       static void unbind();
 };
 
 } // namespace GL