VertexArray::~VertexArray()
{ }
+void VertexArray::reset(const VertexFormat &f)
+{
+ clear();
+ format = f;
+ stride = get_stride(format);
+
+ bool has_multitex = false;
+ bool has_gen_attrs = false;
+ for(const unsigned char *c=format.begin(); c!=format.end(); ++c)
+ {
+ if(*c>=TEXCOORD1+4 && *c<ATTRIB1)
+ has_multitex = true;
+ if(*c>=ATTRIB1)
+ has_gen_attrs = true;
+ }
+ if(has_multitex)
+ static Require _req(ARB_multitexture);
+ if(has_gen_attrs)
+ static Require _req(ARB_vertex_shader);
+}
+
void VertexArray::use_vertex_buffer()
{
if(vbuf)
dirty = true;
}
+void VertexArray::clear()
+{
+ data.clear();
+}
+
void VertexArray::reserve(unsigned n)
{
data.reserve(n*stride);
}
-void VertexArray::clear()
+float *VertexArray::append()
{
- data.clear();
+ data.insert(data.end(), stride, 0.0f);
+ set_dirty();
+ return &*(data.end()-stride);
}
-void VertexArray::reset(const VertexFormat &f)
+float *VertexArray::modify(unsigned i)
{
- clear();
- format = f;
- stride = get_stride(format);
+ set_dirty();
+ return &data[0]+i*stride;
+}
- bool has_multitex = false;
- bool has_gen_attrs = false;
- for(const unsigned char *c=format.begin(); c!=format.end(); ++c)
+void VertexArray::set_dirty()
+{
+ dirty = true;
+ if(defer_vbuf)
{
- if(*c>=TEXCOORD1+4 && *c<ATTRIB1)
- has_multitex = true;
- if(*c>=ATTRIB1)
- has_gen_attrs = true;
+ vbuf = new Buffer(ARRAY_BUFFER);
+ defer_vbuf = false;
}
- if(has_multitex)
- static Require _req(ARB_multitexture);
- if(has_gen_attrs)
- static Require _req(ARB_vertex_shader);
}
void VertexArray::apply() const
Buffer::unbind_from(ARRAY_BUFFER);
}
-float *VertexArray::append()
-{
- data.insert(data.end(), stride, 0.0f);
- set_dirty();
- return &*(data.end()-stride);
-}
-
-float *VertexArray::modify(unsigned i)
-{
- set_dirty();
- return &data[0]+i*stride;
-}
-
-void VertexArray::set_dirty()
-{
- dirty = true;
- if(defer_vbuf)
- {
- vbuf = new Buffer(ARRAY_BUFFER);
- defer_vbuf = false;
- }
-}
-
VertexArray::ArrayMask::ArrayMask()
{
VertexArray(const VertexFormat &);
~VertexArray();
+ void reset(const VertexFormat &);
const VertexFormat &get_format() const { return format; }
- const std::vector<float> &get_data() const { return data; }
+
void use_vertex_buffer();
void use_vertex_buffer(Buffer *);
- void reserve(unsigned);
- unsigned size() const { return data.size()/stride; }
+
void clear();
- void reset(const VertexFormat &);
- void apply() const;
+ void reserve(unsigned);
float *append();
float *modify(unsigned);
- const float *operator[](unsigned i) const { return &data[0]+i*stride; }
-
private:
void set_dirty();
+
+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;
};
} // namespace GL