namespace GL {
VertexSetup::VertexSetup():
- dirty(false),
+ dirty(0),
array(0),
index_buffer(0)
{
void VertexSetup::set_vertex_array(const VertexArray &a)
{
array = &a;
- update();
+ update(VERTEX_ARRAY);
}
void VertexSetup::set_index_buffer(const Buffer &ibuf)
{
index_buffer = &ibuf;
- update();
+ update(INDEX_BUFFER);
}
-void VertexSetup::update() const
+void VertexSetup::update(unsigned mask) const
{
if(current()!=this)
{
- dirty = true;
+ dirty |= mask;
return;
}
+ if(mask&VERTEX_ARRAY)
+ update_vertex_array();
+
+ if(mask&INDEX_BUFFER)
+ glBindBuffer(ELEMENT_ARRAY_BUFFER, index_buffer->get_id());
+}
+
+void VertexSetup::update_vertex_array() const
+{
Bind bind_vbuf(array->get_buffer(), ARRAY_BUFFER);
const VertexFormat &fmt = array->get_format();
glEnableVertexAttribArray(t);
ptr += sz;
}
-
- glBindBuffer(ELEMENT_ARRAY_BUFFER, index_buffer->get_id());
}
void VertexSetup::bind() const
glBindVertexArray(id);
if(dirty)
{
- update();
- dirty = false;
+ update(dirty);
+ dirty = 0;
}
}
}
class VertexSetup: public Bindable<VertexSetup>
{
private:
+ enum ComponentMask
+ {
+ VERTEX_ARRAY = 1,
+ INDEX_BUFFER = 2
+ };
+
unsigned id;
- mutable bool dirty;
+ mutable unsigned dirty;
const VertexArray *array;
const Buffer *index_buffer;
~VertexSetup();
void set_vertex_array(const VertexArray &);
+ void set_instance_array(const VertexArray &);
void set_index_buffer(const Buffer &);
const Buffer *get_index_buffer() const { return index_buffer; }
private:
- void update() const;
+ void update(unsigned) const;
+ void update_vertex_array() const;
public:
void bind() const;