Setting data precision for ofVboMesh

Hi everyone,

I’m currently running into memory issues when loading pointclouds into a ofVboMesh… So I thought it may be a great idea to reduce the precision of my vertices and normals.
I don’t really need them super precise anyways, I just need lots of them!
Somehow I can’t figure it out and always end up with 0 vertices/normals… :frowning:

Here is my code to parse a wavefront obj file into a ofVboMesh.

#define SCALING = 10.0f
void loadMeshLevel(ofVboMesh& mesh, string path) { 
     ofVboMesh mesh;
     // i only render points, so..
      mesh.setMode(OF_PRIMITIVE_POINTS);
        mesh.enableColors();
        mesh.enableNormals();
        mesh.disableIndices();
        mesh.disableTextures();
        auto meshLines = ofSplitString(ofBufferFromFile(path).getText(), "\n");

        // i don't know beforehand how many normals/vertices i have, so i use vectors instead of arrays
        vector<glm::lowp_float> vNormals;
        vector<glm::mediump_float> vVertices;
        for (string& line : meshLines) {
            if (line.empty()) { 
                continue; 
            }
          if (line[0] == 'v' && line[1] == 'n') {
                std::vector<string> vec = ofSplitString(line, " ");
                vNormals.push_back(glm::lowp_float(ofToFloat(vec[1])));
                vNormals.push_back(glm::lowp_float(ofToFloat(vec[2])));
                vNormals.push_back(glm::lowp_float(ofToFloat(vec[3])));

                // the following line worked
                //mesh.addNormal(glm::vec3(ofToFloat(vec[1]),ofToFloat(vec[2]),ofToFloat(vec[3])));
            } else if (line[0] == 'v' && line[1] == ' ') {
                std::vector<string> vec = ofSplitString(line, " ");

                vVertices.push_back(glm::mediump_float(ofToFloat(vec[1]) * SCALING));
                vVertices.push_back(glm::mediump_float(ofToFloat(vec[2]) * SCALING));
                vVertices.push_back(glm::mediump_float(ofToFloat(vec[3]) * SCALING));

                // again, the following line worked perfectly
                //mesh.addVertex(glm::vec3(ofToFloat(vec[1]) * SCALING,ofToFloat(vec[2]) * SCALING,ofToFloat(vec[3]) * SCALING));

                // i store the colors normally for now, babysteps..
                mesh.addColor( ofColor(ofToFloat(vec[4]) * 255,ofToFloat(vec[5]) * 255, ofToFloat(vec[6]) * 255));
            }
        }
       
        // here I try to set the data in the vbo... somehow it doesn't want to be there though
        mesh.getVbo().setNormalData(&vNormals[0], vNormals.size(), GL_STATIC_DRAW, sizeof(glm::lowp_float)*3);
        mesh.getVbo().setVertexData(&vVertices[0], vVertices.size(), GL_STATIC_DRAW, sizeof(glm::mediump_float)*3);
}

am I overcomplicating this?
Is there an easier way?

This types in glm don’t make any difference they are just typedefs for float, except glm::highp_float which is a typedef to double. One way to test it is to printout the output of sizeof(float), sizeof(glm::lowp_float)

Probably what you want is to specify the precision in the shader not in the data. That will only make processing it faster but not save any memory…

In any case ofVbo only has support for floats right now and although you could use ofBufferObject to store something like half_floats using some library that supports them like: http://half.sourceforge.net/, ofVbo always binds attributes as GL_FLOAT so it wouldn’t work right away you would need to manage the vao and vbo creation manually and bind the corresponding buffer objects

thanks for your answer!
I get it, so there is no easy way.
I’d have to pretty much set it up manually.