X-Git-Url: http://git.tdb.fi/?p=libs%2Fgl.git;a=blobdiff_plain;f=source%2Fcore%2Fmesh.cpp;h=ea14d590b3012815526247555a4d4a2c74d473d1;hp=f63b32933c64245f988004df8fbca9377d62541c;hb=d40673bd28c4b4524d3642b949d9d109dc6f9f24;hpb=11266e8093e56524a68de1d0a08d275de95c56a0 diff --git a/source/core/mesh.cpp b/source/core/mesh.cpp index f63b3293..ea14d590 100644 --- a/source/core/mesh.cpp +++ b/source/core/mesh.cpp @@ -14,16 +14,15 @@ using namespace std; 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) @@ -46,6 +45,15 @@ Mesh::~Mesh() 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(); @@ -99,6 +107,8 @@ unsigned Mesh::get_n_vertices() const float *Mesh::modify_vertex(unsigned i) { + if(vertices.get_format().empty()) + throw invalid_operation("Mesh::modify_vertex"); return vertices.modify(i); } @@ -243,11 +253,13 @@ Mesh::Loader::Loader(Mesh &m, bool g): 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 &a) +void Mesh::Loader::storage(const vector &a) { if(a.empty()) throw invalid_argument("No vertex attributes"); @@ -255,13 +267,20 @@ void Mesh::Loader::vertices(const vector &a) VertexFormat fmt; for(vector::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 &a) +{ + storage(a); + vertices(); } void Mesh::Loader::batch(PrimitiveType p) @@ -315,7 +334,6 @@ bool Mesh::AsyncLoader::process() 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();