From 2dda82ef5608ee07cf79db7e7bb118a62957678b Mon Sep 17 00:00:00 2001 From: Alessandro Muntoni Date: Thu, 23 Nov 2023 14:01:38 +0100 Subject: [PATCH] small fixes --- include/vclib/io/image.h | 2 +- include/vclib/render/mesh_render_buffers.h | 26 +++++++++++++--------- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/include/vclib/io/image.h b/include/vclib/io/image.h index 321130c2a..2caa58a55 100644 --- a/include/vclib/io/image.h +++ b/include/vclib/io/image.h @@ -38,7 +38,7 @@ namespace vcl { -std::shared_ptr loadImageData( +inline std::shared_ptr loadImageData( const std::string& filename, int& w, int& h) diff --git a/include/vclib/render/mesh_render_buffers.h b/include/vclib/render/mesh_render_buffers.h index 4a894a298..bdeb1bfa7 100644 --- a/include/vclib/render/mesh_render_buffers.h +++ b/include/vclib/render/mesh_render_buffers.h @@ -37,9 +37,6 @@ namespace vcl { template class MeshRenderBuffers { - uint nv = 0; - uint nt = 0; - std::vector verts; std::vector tris; std::vector vNormals; @@ -66,9 +63,9 @@ class MeshRenderBuffers fillMeshAttribs(m); } - uint vertexNumber() const { return nv; } + uint vertexNumber() const { return verts.size() / 3; } - uint triangleNumber() const { return nt; } + uint triangleNumber() const { return tris.size() / 3; } uint textureNumber() const { return textures.size(); } @@ -88,6 +85,11 @@ class MeshRenderBuffers return verts.data(); } + const uint vertexBufferSize() const + { + return verts.size(); + } + const uint32_t* triangleBufferData() const { if (tris.empty()) @@ -95,6 +97,11 @@ class MeshRenderBuffers return tris.data(); } + const uint triangleBufferSize() const + { + return tris.size(); + } + const float* vertexNormalBufferData() const { if (vNormals.empty()) @@ -181,8 +188,7 @@ class MeshRenderBuffers std::numeric_limits::lowest()); } - nv = m.vertexNumber(); - verts.resize(nv * 3); + verts.resize(m.vertexNumber() * 3); if constexpr (vcl::HasPerVertexNormal) { if (vcl::isPerVertexNormalAvailable(m)) { @@ -249,9 +255,7 @@ class MeshRenderBuffers std::vector> vinds; // necessary for wedge attribs if constexpr (vcl::HasTriangles) { - nt = m.faceNumber(); - - tris.resize(nt * 3); + tris.resize(m.faceNumber() * 3); uint i = 0; for (const auto& f : m.faces()) { @@ -266,7 +270,7 @@ class MeshRenderBuffers triPolyMap.reserve(m.faceNumber(), m.faceNumber()); tris.reserve(m.faceNumber()); - nt = 0; + uint nt = 0; for (const auto& f : m.faces()) { if (f.vertexNumber() == 3) { triPolyMap.insert(nt, m.faceIndexIfCompact(m.index(f)));