It was getting in the way of implementing vertex array objects.
Mesh::Mesh():
vertices(VERTEX3),
+ vbuf(0),
ibuf(0),
- defer_ibuf(true),
+ defer_buffers(true),
winding(0)
{ }
Mesh::Mesh(const VertexFormat &f):
vertices(f),
+ vbuf(0),
ibuf(0),
- defer_ibuf(true),
+ defer_buffers(true),
winding(0)
{ }
Mesh::~Mesh()
{
+ delete vbuf;
delete ibuf;
}
void Mesh::use_buffers(bool b)
{
+ defer_buffers = false;
if(b)
- {
- vertices.use_vertex_buffer();
- if(!ibuf)
- ibuf = new Buffer(ELEMENT_ARRAY_BUFFER);
- defer_ibuf = false;
- }
+ create_buffers();
else
{
vertices.use_vertex_buffer(0);
+ delete vbuf;
+ vbuf = 0;
delete ibuf;
ibuf = 0;
- defer_ibuf = false;
}
}
+void Mesh::create_buffers()
+{
+ defer_buffers = false;
+
+ if(!vbuf)
+ vbuf = new Buffer(ARRAY_BUFFER);
+ vertices.use_vertex_buffer(vbuf);
+
+ if(!ibuf)
+ ibuf = new Buffer(ELEMENT_ARRAY_BUFFER);
+}
+
unsigned Mesh::get_n_vertices() const
{
return vertices.size();
void Mesh::add_batch(const Batch &b)
{
- if(defer_ibuf)
- {
- ibuf = new Buffer(ELEMENT_ARRAY_BUFFER);
- defer_ibuf = false;
- }
+ if(defer_buffers)
+ create_buffers();
if(!batches.empty() && batches.back().can_append(b.get_type()))
batches.back().append(b);
private:
VertexArray vertices;
std::list<Batch> batches;
+ Buffer *vbuf;
Buffer *ibuf;
- bool defer_ibuf;
+ bool defer_buffers;
const WindingTest *winding;
public:
void clear();
void use_buffers(bool);
+private:
+ void create_buffers();
+public:
const VertexArray &get_vertices() const { return vertices; }
unsigned get_n_vertices() const;
float *modify_vertex(unsigned);
namespace GL {
VertexArray::VertexArray(const VertexFormat &f):
- defer_vbuf(true),
dirty(false)
{
reset(f);
}
}
-void VertexArray::use_vertex_buffer()
-{
- if(vbuf)
- return;
-
- vbuf = new Buffer(ARRAY_BUFFER);
- defer_vbuf = false;
- dirty = true;
-}
-
void VertexArray::use_vertex_buffer(Buffer *b)
{
vbuf = b;
- vbuf.keep();
- defer_vbuf = false;
dirty = true;
}
void VertexArray::set_dirty()
{
dirty = true;
- if(defer_vbuf)
- {
- vbuf = new Buffer(ARRAY_BUFFER);
- defer_vbuf = false;
- }
}
void VertexArray::apply() const
std::vector<float> data;
unsigned stride;
std::vector<Array> arrays;
- RefPtr<Buffer> vbuf;
- bool defer_vbuf;
+ Buffer *vbuf;
mutable bool dirty;
VertexArray(const VertexArray &);
static unsigned get_array_slot(unsigned char);
public:
- void use_vertex_buffer();
void use_vertex_buffer(Buffer *);
void clear();