Skip to content
Snippets Groups Projects
Commit 30cc1751 authored by Christophe Geuzaine's avatar Christophe Geuzaine
Browse files

limit vertex array prealloc to reasonable values

parent 2798ed59
No related branches found
No related tags found
No related merge requests found
Pipeline #3027 passed
......@@ -9,6 +9,7 @@
#include "VertexArray.h"
#include "Context.h"
#include "Numeric.h"
#include "OS.h"
template<int N> float ElementDataLessThan<N>::tolerance = 0.0F;
float BarycenterLessThan::tolerance = 0.0F;
......@@ -17,11 +18,27 @@ VertexArray::VertexArray(int numVerticesPerElement, int numElements)
: _numVerticesPerElement(numVerticesPerElement)
{
int nb = (numElements ? numElements : 1) * _numVerticesPerElement;
double memv = (nb * 3. * sizeof(float)) / 1024. / 1024.;
double memmax = TotalRam() / 3.;
if(memv > memmax){
int old = nb;
nb = memmax / (3. * sizeof(float)) * 1024 * 1024;
Msg::Debug("Reduce preallocation of vertex array (%d -> %d)", old, nb);
}
_vertices.reserve(nb * 3);
_normals.reserve(nb * 3);
_colors.reserve(nb * 4);
}
double VertexArray::getMemoryInMb()
{
int bytes = _vertices.size() * sizeof(float) +
_normals.size() * sizeof(normal_type) +
_colors.size() * sizeof(unsigned char);
return (double)bytes / 1024. / 1024.;
}
void VertexArray::_addVertex(float x, float y, float z)
{
_vertices.push_back(x);
......@@ -214,14 +231,6 @@ void VertexArray::sort(double x, double y, double z)
_colors = sortedColors;
}
double VertexArray::getMemoryInMb()
{
int bytes = _vertices.size() * sizeof(float) +
_normals.size() * sizeof(normal_type) +
_colors.size() * sizeof(unsigned char);
return (double)bytes / 1024. / 1024.;
}
char *VertexArray::toChar(int num, const std::string &name, int type,
double min, double max, int numsteps, double time,
const SBoundingBox3d &bbox, int &len)
......
......@@ -360,12 +360,19 @@ private:
bool _curved;
int _estimateIfClipped(int num)
{
if(CTX::instance()->clipWholeElements &&
CTX::instance()->clipOnlyDrawIntersectingVolume) {
if(CTX::instance()->clipWholeElements) {
for(int clip = 0; clip < 6; clip++) {
if(CTX::instance()->mesh.clip & (1 << clip))
if(CTX::instance()->mesh.clip & (1 << clip)){
if(CTX::instance()->clipOnlyDrawIntersectingVolume){
// let be more aggressive than num^{2/3}
return (int)sqrt((double)num);
}
else{
// why not :-)
return num / 4;
}
}
}
}
return num;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment