-#include <msp/gl/extensions/arb_vertex_array_object.h>
-#include <msp/gl/extensions/arb_vertex_buffer_object.h>
-#include <msp/gl/extensions/arb_vertex_shader.h>
-#include <msp/gl/extensions/khr_debug.h>
#include "buffer.h"
#include "error.h"
#include "mesh.h"
#include "renderer.h"
#include "resourcemanager.h"
-#include "vertexsetup.h"
using namespace std;
namespace Msp {
namespace GL {
-Mesh::Mesh(ResourceManager *rm)
+Mesh::Mesh(const VertexFormat &f):
+ Mesh()
{
- init(rm);
-}
-
-Mesh::Mesh(const VertexFormat &f, ResourceManager *rm)
-{
- init(rm);
storage(f);
}
-void Mesh::init(ResourceManager *rm)
-{
- vbuf = 0;
- ibuf = 0;
- dirty = 0;
- disallow_rendering = false;
- face_winding = NON_MANIFOLD;
-
- if(rm)
- set_manager(rm);
-}
-
Mesh::~Mesh()
{
set_manager(0);
ibuf = new Buffer;
if(!batches.empty())
batches.front().change_buffer(ibuf);
- vtx_setup.set_index_buffer(*ibuf);
dirty |= INDEX_BUFFER;
#ifdef DEBUG
vbuf->set_debug_name(debug_name+" [IBO]");
#endif
}
+
+ if(!batches.empty())
+ vtx_setup.set_index_buffer(*ibuf, batches.front().get_index_type());
}
}
return vertices.size();
}
-float *Mesh::modify_vertex(unsigned i)
+char *Mesh::modify_vertex(unsigned i)
{
if(vertices.get_format().empty())
throw invalid_operation("Mesh::modify_vertex");
bool reallocate = (batches.size()==batches.capacity());
if(reallocate)
{
- for(vector<Batch>::iterator i=batches.end(); i!=batches.begin(); )
+ for(auto i=batches.end(); i!=batches.begin(); )
(--i)->use_buffer(0);
}
if(reallocate)
{
prev = 0;
- for(vector<Batch>::iterator i=batches.begin(); i!=batches.end(); ++i)
+ for(Batch &a: batches)
{
- i->use_buffer(ibuf, prev);
- prev = &*i;
+ a.use_buffer(ibuf, prev);
+ prev = &a;
}
}
else
batches.back().use_buffer(ibuf, prev);
}
+ DataType existing_type = batches.front().get_index_type();
+ DataType added_type = batches.back().get_index_type();
+ if(existing_type!=added_type)
+ {
+ if(get_type_size(existing_type)>get_type_size(added_type))
+ batches.back().set_index_type(existing_type);
+ else
+ {
+ for(Batch &a: batches)
+ a.set_index_type(added_type);
+ }
+ }
+
check_buffers(INDEX_BUFFER);
}
if(!count)
{
- for(vector<Batch>::const_iterator i=batches.begin(); i!=batches.end(); ++i)
- renderer.draw(*i);
+ for(const Batch &b: batches)
+ renderer.draw(b);
}
else
{
- for(vector<Batch>::const_iterator i=batches.begin(); i!=batches.end(); ++i)
- renderer.draw_instanced(*i, count);
+ for(const Batch &b: batches)
+ renderer.draw_instanced(b, count);
}
}
return new AsyncLoader(*this, io);
}
-UInt64 Mesh::get_data_size() const
+uint64_t Mesh::get_data_size() const
{
- UInt64 size = 0;
+ uint64_t size = 0;
if(vbuf)
size += vbuf->get_size();
if(ibuf)
add("winding", &Mesh::face_winding);
}
-void Mesh::Loader::storage(const vector<VertexAttribute> &a)
+void Mesh::Loader::storage(const vector<VertexAttribute> &attrs)
{
- if(a.empty())
+ if(attrs.empty())
throw invalid_argument("No vertex attributes");
VertexFormat fmt;
- for(vector<VertexAttribute>::const_iterator i=a.begin(); i!=a.end(); ++i)
- fmt = (fmt, *i);
+ for(VertexAttribute a: attrs)
+ fmt = (fmt, a);
obj.storage(fmt);
}