Hi,
just to briefly summarize how to use the VboMesh
class: it’s simply a set of arrays, describing the position of every vertex, as well as other vertex attributes like color, texture coordinate, normal, tangent, etc. The data is initialized and constructed on the CPU, then sent to GPU memory.
If the mesh does not change, you only have to send it once and then you can draw it an infinite amount of times. If the mesh does change, however, you can replace the data with a new copy, or iterate over the existing data to update it using the mapAttrib*()
functions. The latter is more efficient, especially when using the orphanExisting = true
flag. Because when this flag is set to true, the GPU allocates a second buffer for the new data, so that it can keep using the original buffer while the data is being updated. Updating the data usually takes a while and this way the GPU does not have to wait at all. For more in-depth info, see this presentation.
Cinder defines a bunch of default attributes: COLOR, TEX_COORD_0 / 1 / 2 / 3, NORMAL, TANGENT, BITANGENT, BONE_INDEX and BONE_WEIGHT. All of these are optional. Additionally, you can add up to 10 custom attributes using the CUSTOM_0 to CUSTOM_9 enums. Each attribute can store up to 4 floats (e.g. float
, vec2
, vec3
, vec4
).
You can then access those attributes in your vertex shader:
in vec4 ciPosition;
in vec4 ciColor;
in vec2 ciTexCoord0;
in vec3 ciNormal;
in vec3 ciTangent;
in vec3 ciBitangent;
in ivec4 ciBoneIndex;
in vec4 ciBoneWeight;
Edit: since the custom attributes can be used for anything at all, Cinder does not provide an automatic ciCustom0
mapping. Instead, specify the name either in gl::GlslProg::Format().attrib( geom::CUSTOM_0, "myAttributeName" )
or when creating the batch: auto batch = gl::Batch::create( mesh, glsl, { { geom::CUSTOM_0, "myAttributeName" } } );
To learn more about how to setup a mesh, have a look at this sample. The sample uses a vertex shader to update the mesh, which is slightly more advanced. But to learn how to update from the CPU, see this Cinder sample. Edit: to see a use case of custom attributes, check out this sample.
-Paul