Commit a39660f6 authored by Romain Pacanowski's avatar Romain Pacanowski

more memory tracking when loading mesh

parent 139005f7
Pipeline #106499 skipped with stage
......@@ -5,6 +5,7 @@
#include "mrf/io/ply_loader.hpp"
#include "mrf/math/math.hpp"
#include "mrf/util/precision_timer.hpp"
#include "mrf/util/cpu_memory.hpp"
using namespace Eigen;
......@@ -47,7 +48,7 @@ Viewer::Viewer(std::string const &full_path_to_mesh)
mrf::io::loadPLY(full_path_to_mesh, _vertices, _normals, _uvs, _color_per_vertex, _index_faces);
ply_timer.stop();
std::cout << " Ply loaded in ram preparing VBO " << ply_timer << std::endl;
std::cout << " Ply loaded in ram preparing VBO " << ply_timer << " available RAM Memory in MB is " << mrf::util::CPUMemory::availableMemory() << std::endl;
if( _normals.size() != _vertices.size() )
{
......@@ -56,43 +57,46 @@ Viewer::Viewer(std::string const &full_path_to_mesh)
mrf::geom::_Mesh<mrf::math::Vec3f>::computeTangents(_vertices, _normals, _tangents);
std::cout << " sizeof(mrf::math::Vec3f) = " << sizeof(mrf::math::Vec3f) << std::endl;
long unsigned int const mesh_memory_size_in_MB = ( (_vertices.size()+_normals.size()+_tangents.size())*sizeof(mrf::math::Vec3f) ) / 1024.0 / 1024.0;
long unsigned int mesh_memory_size_in_Bytes = ( (_vertices.size()+_normals.size()+_tangents.size())*sizeof(mrf::math::Vec3f) ) ;
std::cout << " CPU Required Memory for Mesh isx " << mesh_memory_size_in_MB << " MB " << std::endl;
std::cout << _index_faces[0] << " " << _index_faces[1] << " " << _index_faces[2] << std::endl;
_nb_bytes_between_two_vertex = 3 * sizeof(mrf::math::Vec3f);
if (_color_per_vertex.size() == _vertices.size())
{
std::cout << " color per vertex present " << std::endl;
_nb_bytes_between_two_vertex += sizeof(mrf::math::Vec3f);
mesh_memory_size_in_Bytes += _vertices.size() * sizeof(mrf::math::Vec3f);
}
if (_uvs.size() == _vertices.size())
{
std::cout << " uvs present " << std::endl;
_nb_bytes_between_two_vertex += sizeof(mrf::math::Vec3f);
mesh_memory_size_in_Bytes += _vertices.size() * sizeof(mrf::math::Vec3f);
}
long unsigned int const mesh_memory_size_in_MB = mesh_memory_size_in_Bytes / 1024.0 / 1024.0;
unsigned long long int const available_memory_in_bytes = mrf::util::CPUMemory::availableMemory() * 1024 * 1024;
std::cout << " CPU Required Memory for Mesh on GPU is " << mesh_memory_size_in_MB << " MB " << std::endl;
std::cout << " Available Memory on the system " << available_memory_in_bytes / 1024.0 / 1024.0 << std::endl;
std::cout << " Number of bytes to store one Vertex is: " << _nb_bytes_between_two_vertex << std::endl;
std::cout << " Nb vertex before erasing " << available_memory_in_bytes / _nb_bytes_between_two_vertex << std::endl;
bool const has_color_per_vertex = _color_per_vertex.size() == _vertices.size();
bool const has_uv_per_vertex = _uvs.size() == _vertices.size();
//Construct the linear VBO in CPU MEMORY
//for (unsigned int i = 0; i < _vertices.size(); i++)
auto it_uvs = _uvs.begin();
auto it_cpv = _color_per_vertex.begin();
// auto it_norm = _normals.begin();
// auto it_tang = _tangents.begin();
auto it_end = _vertices.end();
// auto it_end = _vertices.end();
// std::cout << " Vertices end = " << &it_end << std::endl;
unsigned int cpt = 0;
for( auto it_vert= _vertices.begin(), it_norm=_normals.begin(), it_tang=_tangents.begin(); it_vert != _vertices.end() ; ++it_vert, ++it_norm, ++it_tang )
{
// std::cout << "it_vert = " << &(*it_vert) << std::endl;
// std::cout << "before it_vert = " << *it_vert << std::endl;
//std::cout << " Vertex " << cpt << std::endl;
// _vboCPU.push_back( _vertices[i] );
// _vboCPU.push_back( _normals[i] );
......@@ -104,26 +108,24 @@ Viewer::Viewer(std::string const &full_path_to_mesh)
// it_vert = _vertices.erase(it_vert);
// it_end = _vertices.end();
// it_norm = _normals.erase(it_norm);
// it_tang = _tangents.erase(it_tang);
if (has_uv_per_vertex)
{
// _vboCPU.push_back(_color_per_vertex[i] );
_vboCPU.push_back( *it_uvs);
++it_uvs;
}
if (has_color_per_vertex)
{
// _vboCPU.push_back( _uvs[i]);
_vboCPU.push_back( *it_cpv);
++it_cpv;
}
cpt++;
}// enf of for loop VBO construction
......@@ -359,7 +361,6 @@ void Viewer::initVBA()
{
// Index Buffer
glGenBuffers(1, &mIndexBufferId);
std::cout << " mIndexBufferID = " << mIndexBufferId << std::endl;
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, mIndexBufferId);
_indexBufferDataIDs.push_back( std::make_pair<>(mIndexBufferId, MAX_TRIANGLES_PER_BATCH*3) );
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment