Besides being a minor optimization, this fixes a crash if update gets
called before both vertex array and index buffer are set.
namespace GL {
VertexSetup::VertexSetup():
namespace GL {
VertexSetup::VertexSetup():
array(0),
index_buffer(0)
{
array(0),
index_buffer(0)
{
void VertexSetup::set_vertex_array(const VertexArray &a)
{
array = &a;
void VertexSetup::set_vertex_array(const VertexArray &a)
{
array = &a;
}
void VertexSetup::set_index_buffer(const Buffer &ibuf)
{
index_buffer = &ibuf;
}
void VertexSetup::set_index_buffer(const Buffer &ibuf)
{
index_buffer = &ibuf;
-void VertexSetup::update() const
+void VertexSetup::update(unsigned mask) const
+ 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();
Bind bind_vbuf(array->get_buffer(), ARRAY_BUFFER);
const VertexFormat &fmt = array->get_format();
glEnableVertexAttribArray(t);
ptr += sz;
}
glEnableVertexAttribArray(t);
ptr += sz;
}
-
- glBindBuffer(ELEMENT_ARRAY_BUFFER, index_buffer->get_id());
}
void VertexSetup::bind() const
}
void VertexSetup::bind() const
glBindVertexArray(id);
if(dirty)
{
glBindVertexArray(id);
if(dirty)
{
- update();
- dirty = false;
+ update(dirty);
+ dirty = 0;
class VertexSetup: public Bindable<VertexSetup>
{
private:
class VertexSetup: public Bindable<VertexSetup>
{
private:
+ enum ComponentMask
+ {
+ VERTEX_ARRAY = 1,
+ INDEX_BUFFER = 2
+ };
+
+ mutable unsigned dirty;
const VertexArray *array;
const Buffer *index_buffer;
const VertexArray *array;
const Buffer *index_buffer;
~VertexSetup();
void set_vertex_array(const VertexArray &);
~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 set_index_buffer(const Buffer &);
const Buffer *get_index_buffer() const { return index_buffer; }
private:
+ void update(unsigned) const;
+ void update_vertex_array() const;
public:
void bind() const;
public:
void bind() const;