{
vbuf = 0;
ibuf = 0;
- vtx_setup = 0;
disallow_rendering = false;
winding = 0;
Mesh::~Mesh()
{
set_manager(0);
- delete vtx_setup;
delete vbuf;
delete ibuf;
}
void Mesh::create_buffers()
{
+ if(vbuf && ibuf)
+ return;
+
if(!vbuf)
vbuf = new Buffer(ARRAY_BUFFER);
vertices.use_buffer(vbuf);
if(!ibuf)
ibuf = new Buffer(ELEMENT_ARRAY_BUFFER);
- if(ARB_vertex_array_object && !vtx_setup)
- {
- vtx_setup = new VertexSetup;
- vtx_setup->set_vertex_array(vertices);
- vtx_setup->set_index_buffer(*ibuf);
- }
+ vtx_setup.set_vertex_array(vertices);
+ vtx_setup.set_index_buffer(*ibuf);
}
unsigned Mesh::get_n_vertices() const
return;
}
- if(!current())
- vertices.apply();
+ BindRestore bind_vtxs(vtx_setup);
BindRestore bind_ibuf(ibuf, ELEMENT_ARRAY_BUFFER);
Bind bind_winding(winding);
void Mesh::bind() const
{
- /* If VAOs are not supported, vtx_setup is zero and set_current won't get
- called. Thus unbind won't try to call a null function either. */
- if(!vtx_setup)
- {
- unbind();
- vertices.apply();
- }
- else if(set_current(this))
+ if(set_current(this))
{
- vtx_setup->bind();
+ vtx_setup.bind();
vertices.refresh();
}
}
for(vector<VertexComponent>::const_iterator i=c.begin(); i!=c.end(); ++i)
fmt = (fmt, *i);
obj.vertices.reset(fmt);
- if(obj.vtx_setup)
+ if(obj.vbuf)
// Set it again to force the vertex setup to update
- obj.vtx_setup->set_vertex_array(obj.vertices);
+ obj.vtx_setup.set_vertex_array(obj.vertices);
load_sub(obj.vertices);
}
#include "batch.h"
#include "resource.h"
#include "vertexarray.h"
+#include "vertexsetup.h"
#include "windingtest.h"
namespace Msp {
class Buffer;
class Renderer;
-class VertexSetup;
/**
Raw mesh data, consisting of a VertexArray and one or more Batches. Though a
std::vector<Batch> batches;
Buffer *vbuf;
Buffer *ibuf;
- VertexSetup *vtx_setup;
+ VertexSetup vtx_setup;
bool defer_buffers;
mutable bool dirty;
bool disallow_rendering;
public:
const VertexArray &get_vertices() const { return vertices; }
- const VertexSetup *get_vertex_setup() const { return vtx_setup; }
+ const VertexSetup &get_vertex_setup() const { return vtx_setup; }
const Buffer *get_index_buffer() const { return ibuf; }
unsigned get_n_vertices() const;
float *modify_vertex(unsigned);