Hello,
I'm trying to access the glBufferData of a geometry by extending GeometryInstance (C++).
In the code i'm working on, the number of faces and vertices is constant, i would just like to update the vertices in an efficient way from the CPU, without cleaning and recreating an immediate geometry at each frame.
My initialisation is looking like this (working fine in the engine):
im = VisualServer::get_singleton()->immediate_create();
set_base(im);
// generation of dots and the indices of faces
// ...
// and finishing with the Immediate structure generation
VisualServer::get_singleton()->immediate_begin(
im,
(VisualServer::PrimitiveType) Mesh::PRIMITIVE_TRIANGLES,
RID());
for ( uint32_t i = 0; i < faces_num; ++i ) {
const Vector3& vert = dots[faces[i]].vert();
if ( i == 0 ) {
aabb.position = vert;
aabb.size = Vector3();
} else {
aabb.expand_to( vert );
}
VisualServer::get_singleton()->immediate_vertex(im, vert );
}
VisualServer::get_singleton()->immediate_end(im);
I found the implementation of immediate_begin, immediate_vertex & immediate_end in RasterizerStorageGLES3, as well as the definition of struct Immediate. Therefore, at each frame, I tried to do this:
RasterizerStorageGLES3::Immediate* imm = (RasterizerStorageGLES3::Immediate*) im.get_data();
Vector<Vector3>& vs = imm->chunks[0].vertices;
// update of my custom class
for( uint32_t i = 0; i < dots_num; ++i ) {
dots[i].update( delta );
}
// copying
for ( uint32_t i = 0; i < faces_num; ++i ) {
vs[i].x = dots[faces[i]].vert().x;
vs[i].y = dots[faces[i]].vert().y;
vs[i].z = dots[faces[i]].vert().z;
}
imm->instance_change_notify();
The mesh is updated, it is avoiding the creation of a new Immediate chunk at each frame, but I still don't have access to the glBuffer... I will optimise the code to avoid copying the vertices position, obviously.
The mesh I will process will be quite large, so I'm trying to avoid regeneration of buffers as much as possible.
If anybody could give me some info about the management of meshes and geometries, it would be very helpful :)
All the best!
git repo is here, by the way: https://github.com/frankiezafe/SoftSkin