There is really nothing special else to add to what I already said. Let’s say I have a
mesh object available from my script, and a script function that is called every frame by the host program. In this function I might want to call
mesh.setVertices(vertices) and pass it an updated array
vertices to change the mesh (it is a procedural mesh; for instance, Unity3d works the same way: you assign vertices to a mesh every frame, which causes them to be re-uploaded to the GPU).
setVertices is defined as follows:
void Mesh::setVertices(const std::vector<Vector3>& vertices);
Somewhere inside this function there is a call:
glBufferData(..., vertices.data(), ...);
This of course bases on an assumption that a
Vector3 structs form a continuous chunk of memory and therefore can be safely passed to OpenGL as a buffer.
My concern is that an inevitable unboxing each time I pass an array to a function will cause a significant slowdown for arrays of a decent size. I could pass an array of
Boxed_Value into this function, but then I wouldn’t be able to pass this array data to OpenGL the way I do it now, so it needs to be unboxed beforehand.
On the other hand I can make a wrapper for mesh data and just pass a reference to it and call its methods to update particular mesh vertex positions.