ofVbo / ofVboMesh generic attributes?

At the risk of missing something obvious and currently existing, It would be super nice to be able to handle generic VBO attributes cleanly within the ofVbo and ofVboMesh objects. Generics are going to be the way forward anyway, and are actually useful in many ways (shaders, etc).

I’m aware of ways you can sort of get it to work, but it would be nice to have some cleaner access in the API, no?

Also, it would be nice to have ofVec4 support for adding verts, texcoords and normals, as those other components can be useful.

At the moment i don’t see any OF method to handle VBO attributes with ofVbo and ofVboMesh obiects.
You need to use standard OpenGL calls. I agree with you, should be fine a direct access to attributes within OF. Estremely useful if you need to store tangents attributes for a mesh for example.( yes you could to this also with a GLSL shader but if you can precalculate them , you have perfo improvement.)

Yes, I’m using standard OpenGL calls. There are some issues however when using ofVBO and needing to load, or bind the VBOs, since the assumption is you want to draw, not handle attribs, thus incorrect state is set up, causing all sorts of issues.

I was surprised to see that the feature wasn’t in there as well. I went ahead and added attribute functionality to ofVbo.

I’ve attached my additions and a horrible sample project. Hopefully it’s of use to someone!

cheers,
james

vboAttributes.zip

This is very useful, could be added to the OF core?

Hello everyone!

I’m also interested in defining custom vertex attributes in a mesh but I can’t find any resource/example that shows how to do this with OF. I’ve tried to download the example that @james provided, but the link is broken.

Things have changed in OF since this topic was posted and now the ofVbo class has a setAttributeData method. The problem is that the docs don’t provide any clue on how to use this method. Is there a way I can use ofVbo::setAttributeData to define custom attributes and then use those attributes in my shader? If that’s not possible, do you know of any resource/example showing how to do it?

Thanks!
Nes

let’s say you want to pass point size along with a mesh with vertices:

ofVboMesh mesh:
vector<float> pointSize;
ofShader shader;

// for each vertex
mesh.addVertex(v);
pointSize.push_back(psize);
mesh.getVbo().setAttributeData(shader.getAttributeLocation("point_size"), &pointSize[0], 1, pointSize.size(), GL_DRAW_STATIC, sizeof(float));

the 3rd parameter is 1 cause we are passing an attribute with one coordinate, if you want to pass a vector of ofVec2f you would have passed 2 there.

the last paramter is the stride, the default parameter will be incorrect except for 1D float attributes so be sure to pass the correct value, sizeof(ofVec2f) for example if you are passing a vector of ofVec2f.

6 Likes

Thanks Arturo, this is just what I needed!