Modify GeomVertexData inplace

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.

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?

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());

registered_format = GeomVertexFormat::register_format(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?

(1) PT(Geom) is sufficient for your purposes. COWPT(Geom) would be used for objects that may or may not store a shared pointer, and want to be able to automatically duplicate the Geom if they make any local changes that they don’t want to appear in the other instances.

(2) What you’re doing is reasonable. Whether you should add a separate array, or extend the existing array, may depend largely on your graphics card; but adding a new array has the advantage that your auxiliary data won’t be sent unnecessarily to the GPU, so it may be the better choice overall.

There’s no difference, performance-wise, between set_format() and convert_to(); and it’s perfectly OK to register a new format even if the equivalent format has already been registered.


Ok, I think I understand. And having the additional data not sent to the graphics card is perfectly fine in my case. Thank you for helping.