Commit 7641fe1a authored by Romain Pacanowski's avatar Romain Pacanowski

WIP.

parent a3976e6b
Pipeline #105885 skipped with stage
......@@ -4,6 +4,7 @@
#include "mrf/io/ply_loader.hpp"
#include "mrf/math/math.hpp"
#include "mrf/util/precision_timer.hpp"
using namespace Eigen;
......@@ -39,7 +40,14 @@ Viewer::Viewer(std::string const &full_path_to_mesh)
_vboCPU.clear();
try
{
mrf::util::PrecisionTimer ply_timer;
ply_timer.start() ;
std::cout << " Loading Ply .... " << std::endl;
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;
if( _normals.size() != _vertices.size() )
{
......@@ -51,53 +59,77 @@ Viewer::Viewer(std::string const &full_path_to_mesh)
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;
std::cout << " CPU Required Memory for Mesh is " << mesh_memory_size_in_MB << " MB " << std::endl;
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);
}
if (_uvs.size() == _vertices.size())
{
std::cout << " uvs present " << std::endl;
_nb_bytes_between_two_vertex += sizeof(mrf::math::Vec3f);
}
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++)
//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();
// std::cout << " Vertices end = " << &it_end << std::endl;
for( auto it_vert= _vertices.begin(), it_norm=_normals.begin(), it_tang=_tangents.begin(); it_vert != _vertices.end() ; ++it_vert, ++it_norm, ++it_tang )
{
_vboCPU.push_back( _vertices[i] );
_vboCPU.push_back( _normals[i] );
_vboCPU.push_back(_tangents[i]);
// std::cout << " i = " << i << std::endl;
// if( i ==0 )
// {
// std::cout << " VBO CPU at 0 = " << _vboCPU[0] << " Normals = " << _vboCPU[1] << " Tangents " << _vboCPU[2]
// << _vboCPU[3] << " " << _vboCPU[4] << " " << _vboCPU[5] << std::endl;
// std::cout << " Vertices[0] = " << _vertices[0] << " Normals[0] = " << _normals[0] << " Tangents[0]=" << _tangents[0] << std::endl;
// }
if (_color_per_vertex.size() == _vertices.size() )
// std::cout << "it_vert = " << &(*it_vert) << std::endl;
// std::cout << "before it_vert = " << *it_vert << std::endl;
// _vboCPU.push_back( _vertices[i] );
// _vboCPU.push_back( _normals[i] );
// _vboCPU.push_back(_tangents[i]);
_vboCPU.push_back( *it_vert );
_vboCPU.push_back( *it_norm );
_vboCPU.push_back( *it_tang );
// 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(_color_per_vertex[i] );
_vboCPU.push_back( *it_uvs);
++it_uvs;
}
if( _uvs.size() == _vertices.size() )
if (has_color_per_vertex)
{
_vboCPU.push_back( _uvs[i]);
// _vboCPU.push_back( _uvs[i]);
_vboCPU.push_back( *it_cpv);
++it_cpv;
}
}
_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);
}
if(_uvs.size() == _vertices.size() )
{
std::cout << " uvs present " << std::endl;
_nb_bytes_between_two_vertex += sizeof(mrf::math::Vec3f);
}
}// enf of for loop VBO construction
std::cout << " Linear indexes computed with " << _vboCPU.size() << " elements " << std::endl;
std::cout << " _nb Bytes between two vertices = " << _nb_bytes_between_two_vertex << std::endl;
}
catch (const std::exception &e)
{
......@@ -110,7 +142,6 @@ Viewer::Viewer(std::string const &full_path_to_mesh)
_normals.clear();
_uvs.clear();
_tangents.clear();
//_index_faces.clear();
_color_per_vertex.clear();
}
......@@ -313,15 +344,15 @@ void Viewer::initVBA()
// // std::vector<mrf::uint> const & faces = _mesh->faces();
// glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(unsigned int) * _index_faces.size(), _index_faces.data(), GL_STATIC_DRAW);
unsigned int const MAX_TRIANGLES_PER_BATCH = 10000000;
unsigned int const MAX_TRIANGLES_PER_BATCH = 1000000;
unsigned int const nb_triangles = (_index_faces.size() / 3 ) ;
unsigned int const nb_index_buffer = nb_triangles / MAX_TRIANGLES_PER_BATCH;
unsigned int const nb_triangles_remaining = nb_triangles - nb_index_buffer*MAX_TRIANGLES_PER_BATCH;
std::cout << "MAX_TRIANGLES_PER_BATCH" << MAX_TRIANGLES_PER_BATCH << " nb_triangles = " << nb_triangles << " nb_index_buffer = " << nb_index_buffer << " nb_triangles_remaining " << nb_triangles_remaining << std::endl;
GLuint* index_faces_ptr = (GLuint*) _index_faces.data();
for(unsigned int i=0; i< nb_index_buffer; i++)
......@@ -424,9 +455,9 @@ Viewer::draw(Shader const & shd)
// Send the geometry. Original Code
// glDrawElements(GL_TRIANGLES, 3*mFaces.size(), GL_UNSIGNED_INT, 0);
// One Draw Call
// One Draw Call
//glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, mIndexBufferId);
//glDrawElements(GL_TRIANGLES, _index_faces.size(), GL_UNSIGNED_INT, 0);
......
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