namespace Msp {
namespace GL {
-Mesh::Mesh(ResourceManager *rm):
- vertices(VERTEX3)
+Mesh::Mesh(ResourceManager *rm)
{
init(rm);
}
-Mesh::Mesh(const VertexFormat &f, ResourceManager *rm):
- vertices(f)
+Mesh::Mesh(const VertexFormat &f, ResourceManager *rm)
{
init(rm);
+ storage(f);
}
void Mesh::init(ResourceManager *rm)
delete ibuf;
}
+void Mesh::storage(const VertexFormat &fmt)
+{
+ if(!vertices.get_format().empty())
+ throw invalid_operation("Mesh::storage");
+
+ vertices.set_format(fmt);
+ vtx_setup.set_format(fmt);
+}
+
void Mesh::clear()
{
vertices.clear();
if(!vbuf || (vbuf->get_size()>0 && vbuf->get_size()<req_size))
{
delete vbuf;
- vbuf = new Buffer(ARRAY_BUFFER);
+ vbuf = new Buffer;
vertices.use_buffer(vbuf);
vtx_setup.set_vertex_array(vertices);
dirty |= VERTEX_BUFFER;
if(!ibuf || (ibuf->get_size()>0 && ibuf->get_size()<req_size))
{
delete ibuf;
- ibuf = new Buffer(ELEMENT_ARRAY_BUFFER);
+ ibuf = new Buffer;
if(!batches.empty())
batches.front().change_buffer(ibuf);
vtx_setup.set_index_buffer(*ibuf);
float *Mesh::modify_vertex(unsigned i)
{
+ if(vertices.get_format().empty())
+ throw invalid_operation("Mesh::modify_vertex");
return vertices.modify(i);
}
vertices.clear();
vertices.use_buffer(0);
batches.clear();
+ vtx_setup.unload();
delete vbuf;
delete ibuf;
vbuf = 0;
allow_gl_calls(g)
{
add("batch", &Loader::batch);
+ add("storage", &Loader::storage);
add("vertices", &Loader::vertices);
+ add("vertices", &Loader::vertices_with_format);
add("winding", &Loader::winding);
}
-void Mesh::Loader::vertices(const vector<VertexAttribute> &a)
+void Mesh::Loader::storage(const vector<VertexAttribute> &a)
{
if(a.empty())
throw invalid_argument("No vertex attributes");
VertexFormat fmt;
for(vector<VertexAttribute>::const_iterator i=a.begin(); i!=a.end(); ++i)
fmt = (fmt, *i);
- obj.vertices.reset(fmt);
+ obj.storage(fmt);
+}
+
+void Mesh::Loader::vertices()
+{
load_sub(obj.vertices);
if(allow_gl_calls)
- {
obj.check_buffers(VERTEX_BUFFER);
- obj.vtx_setup.refresh();
- }
+}
+
+void Mesh::Loader::vertices_with_format(const vector<VertexAttribute> &a)
+{
+ storage(a);
+ vertices();
}
void Mesh::Loader::batch(PrimitiveType p)
else if(phase==1)
{
mesh.resize_buffers();
- mesh.vtx_setup.refresh();
vertex_updater = mesh.vertices.refresh_async();
if(!mesh.batches.empty())
index_updater = mesh.batches.front().refresh_async();