I have two question both related to modification of GeomVertexData. The use case is that I have a class which modifies a Geom each frame, that is rewrites its vertices and normals. To do so I want to store an additional “index” on each vertex.
b[/b]
First, I would like to ask for the recommended way of storing such a Geom. As far as I know there are two options:
COWPT(Geom) _geom;
PT(Geom) _geom;
When using the first on I would get a PT(Geom) each frame this way:
PT(Geom) geom = _geom.get_write_pointer();
Is there any advantage from using CopyOnWritePointerTo?
b[/b]
To store an integer index on each vertex want to “extend” the format of the (arbitrary) GeomVertexData this way:
PT(Geom) geom = _geom.get_write_pointer();
PT(GeomVertexData) vdata = geom->modify_vertex_data();
if (vdata->has_column(InternalName::get_index())) return;
PT(GeomVertexArrayFormat) array;
PT(GeomVertexFormat) format;
CPT(GeomVertexFormat) registered_format;
array = new GeomVertexArrayFormat();
array->add_column(InternalName::get_index(), 1, Geom::NT_uint16, Geom::C_index);
format = new GeomVertexFormat(*vdata->get_format());
format->add_array(array);
registered_format = GeomVertexFormat::register_format(format);
vdata->set_format(registered_format);
Considering performance, is it recommended to add a new array to the GeomVertexFormat, or should I try to modify the first array which is already contained within the GeomVertexFormat?
It seems that set_format() doesn’t loose the actual vertex/normal/… data. Or would it be better to use something like vdata2 = vdata->convert_to(new_format)?
Finally, is it ok to register a modified format even if a equal format has been registered already by a previous call of the function?