]> git.tdb.fi Git - libs/gl.git/blobdiff - source/core/vertexarray.cpp
Only allow VertexArray's format to be set once
[libs/gl.git] / source / core / vertexarray.cpp
index 347e42595a1387bf7630a87344a6dc96f7425ac3..2bb6a6677b9ef5e2099a1a5922b1d2990910708c 100644 (file)
@@ -11,14 +11,19 @@ using namespace std;
 namespace Msp {
 namespace GL {
 
+VertexArray::VertexArray():
+       stride(0)
+{ }
+
 VertexArray::VertexArray(const VertexFormat &f)
 {
-       reset(f);
+       set_format(f);
 }
 
-void VertexArray::reset(const VertexFormat &f)
+void VertexArray::set_format(const VertexFormat &f)
 {
-       clear();
+       if(!format.empty())
+               throw invalid_operation("VertexArray::set_format");
        format = f;
        stride = format.stride();
 }
@@ -30,11 +35,15 @@ void VertexArray::clear()
 
 void VertexArray::reserve(unsigned n)
 {
+       if(format.empty())
+               throw invalid_operation("VertexArray::reserve");
        data.reserve(n*stride);
 }
 
 float *VertexArray::append()
 {
+       if(format.empty())
+               throw invalid_operation("VertexArray::append");
        data.insert(data.end(), stride, 0.0f);
        update_offset();
        dirty = true;
@@ -43,6 +52,8 @@ float *VertexArray::append()
 
 float *VertexArray::modify(unsigned i)
 {
+       if(format.empty())
+               throw invalid_operation("VertexArray::modify");
        dirty = true;
        return &data[0]+i*stride;
 }