From: Mikko Rasa Date: Mon, 28 Oct 2019 23:57:53 +0000 (+0200) Subject: Always use VertexSetup in Mesh X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=e65e7dabfc1d3b2c87345df75fc942fb1fe47581;p=libs%2Fgl.git Always use VertexSetup in Mesh This means vertex array objects are now required. I don't think that's a problem since they've been supported even on mobile hardware for a long time. --- diff --git a/source/mesh.cpp b/source/mesh.cpp index 746b07d8..e9015365 100644 --- a/source/mesh.cpp +++ b/source/mesh.cpp @@ -29,7 +29,6 @@ void Mesh::init(ResourceManager *rm) { vbuf = 0; ibuf = 0; - vtx_setup = 0; disallow_rendering = false; winding = 0; @@ -40,7 +39,6 @@ void Mesh::init(ResourceManager *rm) Mesh::~Mesh() { set_manager(0); - delete vtx_setup; delete vbuf; delete ibuf; } @@ -53,6 +51,9 @@ void Mesh::clear() void Mesh::create_buffers() { + if(vbuf && ibuf) + return; + if(!vbuf) vbuf = new Buffer(ARRAY_BUFFER); vertices.use_buffer(vbuf); @@ -60,12 +61,8 @@ void Mesh::create_buffers() 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 @@ -130,8 +127,7 @@ void Mesh::draw() const return; } - if(!current()) - vertices.apply(); + BindRestore bind_vtxs(vtx_setup); BindRestore bind_ibuf(ibuf, ELEMENT_ARRAY_BUFFER); Bind bind_winding(winding); @@ -176,16 +172,9 @@ void Mesh::draw_instanced(Renderer &renderer, const VertexSetup &vs, unsigned co 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(); } } @@ -240,9 +229,9 @@ void Mesh::Loader::vertices(const vector &c) for(vector::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); } diff --git a/source/mesh.h b/source/mesh.h index c09fad6d..54ff2803 100644 --- a/source/mesh.h +++ b/source/mesh.h @@ -5,6 +5,7 @@ #include "batch.h" #include "resource.h" #include "vertexarray.h" +#include "vertexsetup.h" #include "windingtest.h" namespace Msp { @@ -12,7 +13,6 @@ namespace GL { class Buffer; class Renderer; -class VertexSetup; /** Raw mesh data, consisting of a VertexArray and one or more Batches. Though a @@ -56,7 +56,7 @@ private: std::vector batches; Buffer *vbuf; Buffer *ibuf; - VertexSetup *vtx_setup; + VertexSetup vtx_setup; bool defer_buffers; mutable bool dirty; bool disallow_rendering; @@ -76,7 +76,7 @@ private: 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);