@@ -430,6 +430,11 @@ void GeometryBuilder::renderFaces(
430430}
431431
432432
433+
434+ static size_t vboInsertionSize = 0 ;
435+ static size_t iboInsertionSize = 0 ;
436+ static size_t vboLastPrintSize = 0 ;
437+ static size_t iboLastPrintSize = 0 ;
433438void GeometryBuilder::renderFacesLinear (
434439 FieldHandle field,
435440 boost::optional<boost::shared_ptr<ColorMap>> colorMap,
@@ -439,20 +444,29 @@ void GeometryBuilder::renderFacesLinear(
439444 unsigned int approxDiv,
440445 const std::string& id)
441446{
447+ vboInsertionSize = 0 ;
448+ iboInsertionSize = 0 ;
449+ vboLastPrintSize = 0 ;
450+ iboLastPrintSize = 0 ;
451+
442452 VField* fld = field->vfield ();
443453 VMesh* mesh = field->vmesh ();
444454
445455 mesh->synchronize (Mesh::FACES_E);
446456
447457 VMesh::Face::size_type numFaces;
458+ int numAttributes = 3 ; // intially 3 because we will atleast be rendering verticies (vec3's)
448459
449460 mesh->size (numFaces);
450-
451461 if (numFaces == 0 )
452462 return ;
453463
454- bool withNormals = (state.get (RenderState::USE_NORMALS));
455- if (withNormals) { mesh->synchronize (Mesh::NORMALS_E); }
464+ bool withNormals = state.get (RenderState::USE_NORMALS);
465+ if (withNormals)
466+ {
467+ numAttributes += 3 ;
468+ mesh->synchronize (Mesh::NORMALS_E);
469+ }
456470
457471 bool invertNormals = state_->getValue (ShowField::FaceInvertNormals).toBool ();
458472 ColorScheme colorScheme = ColorScheme::COLOR_UNIFORM;
@@ -467,58 +481,58 @@ void GeometryBuilder::renderFacesLinear(
467481 }
468482 else if (state.get (RenderState::USE_COLORMAP))
469483 {
484+ numAttributes += 4 ;
470485 colorScheme = ColorScheme::COLOR_MAP;
471486 }
472487 else // if (fld->basis_order() >= 0)
473488 {
489+ numAttributes += 4 ;
474490 colorScheme = ColorScheme::COLOR_IN_SITU;
475491 }
476492
477- // Three 32 bit ints to index into the VBO
478- uint32_t iboSize = static_cast <uint32_t >(mesh->num_faces () * sizeof (uint32_t ) * 3 );
479- // Seven floats per VBO: Pos (3) XYZ, and Color (4) RGBA
480- uint32_t vboSize = static_cast <uint32_t >(mesh->num_faces () * sizeof (float ) * 7 );
481-
482- // Construct VBO and IBO that will be used to render the faces. Once again,
483- // IBOs are not strictly needed. But, we may be able to optimize this code
484- // somewhat.
485- // / \todo Switch to unique_ptrs and move semantics.
486- std::shared_ptr<spire::VarBuffer> iboBufferSPtr (
487- new spire::VarBuffer (vboSize));
488- std::shared_ptr<spire::VarBuffer> vboBufferSPtr (
489- new spire::VarBuffer (iboSize));
490-
491- // Accessing the pointers like this is contrived. We only do this for
492- // speed since we will be using the pointers in a tight inner loop.
493- auto iboBuffer = iboBufferSPtr.get ();
494- auto vboBuffer = vboBufferSPtr.get ();
495-
496- uint32_t iboIndex = 0 ;
497- int64_t numVBOElements = 0 ;
498-
493+ Point idpt;
499494 VMesh::Face::iterator fiter, fiterEnd;
500495 VMesh::Node::array_type nodes;
501-
502496 mesh->begin (fiter);
503497 mesh->end (fiterEnd);
504-
505- Point idpt;
506498 mesh->get_nodes (nodes, *fiter);
507499 mesh->get_point (idpt, nodes[0 ]);
508500
501+ std::cout << " Number of Attributes: " << numAttributes << " \n " ;
502+ // Three 32 bit ints for each triangle to index into the VBO (triangles = verticies - 2)
503+ size_t iboSize = static_cast <size_t >(mesh->num_faces () * sizeof (uint32_t ) * (nodes.size () - 2 ) * 3 );
504+ size_t vboSize = static_cast <size_t >(mesh->num_faces () * sizeof (float ) * nodes.size () * numAttributes);
505+
506+ // size_t vboSize = static_cast<size_t>(mesh->num_faces() * sizeof(uint32_t) * 3);
507+ // size_t iboSize = static_cast<size_t>(mesh->num_faces() * sizeof(float) * 7);
508+
509+ std::cout << " Faces: " << mesh->num_faces () << " \n " ;
510+ std::cout << " IBO buffer size: " << iboSize/1024 /1024 << " MiB\n " ;
511+ std::cout << " VBO buffer size: " << vboSize/1024 /1024 << " MiB\n " ;
512+
513+ // Construct VBO and IBO that will be used to render the faces. Once again, IBOs are not strictly
514+ // needed. But, we may be able to optimize this code somewhat.
515+ // todo Switch to unique_ptrs and move semantics.
516+ std::shared_ptr<spire::VarBuffer> iboBufferSPtr (new spire::VarBuffer (iboSize));
517+ std::shared_ptr<spire::VarBuffer> vboBufferSPtr (new spire::VarBuffer (vboSize));
518+
519+ // Accessing the pointers like this is contrived. We only do this for speed since we will be
520+ // using the pointers in a tight inner loop.
521+ auto iboBuffer = iboBufferSPtr.get ();
522+ auto vboBuffer = vboBufferSPtr.get ();
523+
524+ uint32_t iboIndex = 0 ;
525+ size_t numVBOElements = 0 ;
526+
509527 while (fiter != fiterEnd)
510528 {
511529 interruptible->checkForInterruption ();
512530
513531 mesh->get_nodes (nodes, *fiter);
514-
515532 std::vector<Point> points (nodes.size ());
516533 std::vector<Vector> normals (nodes.size ());
517-
518534 for (size_t i = 0 ; i < nodes.size (); i++)
519- {
520535 mesh->get_point (points[i], nodes[i]);
521- }
522536
523537 // TODO fix so the withNormals tp be woth lighting is called correctly, and the meshes are fixed.
524538 if (withNormals)
@@ -575,12 +589,14 @@ void GeometryBuilder::renderFacesLinear(
575589 }
576590 }
577591 }
592+
578593 // Default color single face no matter the element data.
579594 if (colorScheme == ColorScheme::COLOR_UNIFORM)
580595 {
581596 addFaceGeom (points, normals, withNormals, iboIndex, iboBuffer, vboBuffer,
582597 colorScheme, face_colors, state);
583598 }
599+
584600 // Element data (Cells) so two sided faces.
585601 else if (fld->basis_order () == 0 && mesh->dimensionality () == 3 )
586602 {
@@ -647,6 +663,7 @@ void GeometryBuilder::renderFacesLinear(
647663 addFaceGeom (points, normals, withNormals, iboIndex, iboBuffer, vboBuffer,
648664 colorScheme, face_colors, state);
649665 }
666+
650667 // Element data (faces)
651668 else if (fld->basis_order () == 0 && mesh->dimensionality () == 2 )
652669 {
@@ -855,19 +872,18 @@ void GeometryBuilder::renderFacesLinear(
855872 }
856873 }
857874
858- SpireVBO geomVBO (vboName, attribs, vboBufferSPtr,
859- numVBOElements, mesh->get_bounding_box (), true );
860-
875+ SpireVBO geomVBO (vboName, attribs, vboBufferSPtr, numVBOElements, mesh->get_bounding_box (), true );
861876 geom->vbos ().push_back (geomVBO);
862877
863- // Construct IBO.
864-
865878 SpireIBO geomIBO (iboName, SpireIBO::PRIMITIVE::TRIANGLES, sizeof (uint32_t ), iboBufferSPtr);
866-
867879 geom->ibos ().push_back (geomIBO);
868880
869- SpireText text;
881+ std::cout << " Actual IBO size: " << iboBufferSPtr->getBufferSize ()/1024 /1024 << " MiB\n " ;
882+ std::cout << " Allocated IBO size: " << iboBufferSPtr->getAllocatedSize ()/1024 /1024 << " MiB\n " ;
883+ std::cout << " Actual VBO size: " << vboBufferSPtr->getBufferSize ()/1024 /1024 << " MiB\n " ;
884+ std::cout << " Allocated VBO size: " << vboBufferSPtr->getAllocatedSize ()/1024 /1024 << " MiB\n " ;
870885
886+ SpireText text;
871887 SpireSubPass pass (passName, vboName, iboName, shader,
872888 colorScheme, state, RenderType::RENDER_VBO_IBO, geomVBO, geomIBO, text);
873889
@@ -880,6 +896,8 @@ void GeometryBuilder::renderFacesLinear(
880896 // / build up to geometry / tessellation shaders if support is present.
881897}
882898
899+
900+
883901// This function needs to be reorganized.
884902// The fact that we are only rendering triangles helps us dramatically and
885903// we get rid of the quads renderer pointers. Additionally, we can re-order
@@ -896,22 +914,26 @@ void GeometryBuilder::addFaceGeom(
896914 const std::vector<ColorRGB> &face_colors,
897915 const RenderState& state)
898916{
917+
899918 auto writeVBOPoint = [&vboBuffer](const Point& point)
900919 {
920+ vboInsertionSize += 3 *sizeof (float );
901921 vboBuffer->write (static_cast <float >(point.x ()));
902922 vboBuffer->write (static_cast <float >(point.y ()));
903923 vboBuffer->write (static_cast <float >(point.z ()));
904924 };
905925
906926 auto writeVBONormal = [&vboBuffer](const Vector& normal)
907927 {
928+ vboInsertionSize += 3 *sizeof (float );
908929 vboBuffer->write (static_cast <float >(normal.x ()));
909930 vboBuffer->write (static_cast <float >(normal.y ()));
910931 vboBuffer->write (static_cast <float >(normal.z ()));
911932 };
912933
913934 auto writeVBOColorValue = [&vboBuffer](ColorRGB value)
914935 {
936+ vboInsertionSize += 4 *sizeof (float );
915937 vboBuffer->write (static_cast <float >(value.r ()));
916938 vboBuffer->write (static_cast <float >(value.g ()));
917939 vboBuffer->write (static_cast <float >(value.b ()));
@@ -920,11 +942,14 @@ void GeometryBuilder::addFaceGeom(
920942
921943 auto writeIBOIndex = [&iboBuffer](uint32_t index)
922944 {
945+ iboInsertionSize += sizeof (uint32_t );
923946 iboBuffer->write (index);
924947 };
925948
949+
926950 bool doubleSided = state.get (RenderState::IS_DOUBLE_SIDED);
927951
952+
928953 if (colorScheme == ColorScheme::COLOR_UNIFORM)
929954 {
930955 if (points.size () == 4 )
@@ -1200,8 +1225,15 @@ void GeometryBuilder::addFaceGeom(
12001225 iboIndex += points.size ();
12011226 }
12021227 }
1228+
1229+ if ((vboInsertionSize - vboLastPrintSize) > (1024 * 1024 * 16 ))
1230+ std::cout << " VBO size: " << (vboLastPrintSize = vboInsertionSize)/1024 /1024 << " MiB\n " ;
1231+ if ((iboInsertionSize - iboLastPrintSize) > (1024 * 1024 * 16 ))
1232+ std::cout << " IBO size: " << (iboLastPrintSize = iboInsertionSize)/1024 /1024 << " MiB\n " ;
12031233}
12041234
1235+
1236+
12051237void GeometryBuilder::renderNodes (
12061238 FieldHandle field,
12071239 boost::optional<boost::shared_ptr<ColorMap>> colorMap,
0 commit comments