Buffer create / release

I use a buffer created with buffer.create to draw a strip of triangles that is calculated at runtime. In particular I use buffer.create, resource.create_buffer and go.set to set the resource as vertices of a mesh.

At the moment, I predefine the size of the buffer at start-up and fill it with degenerate triangles when I need fewer triangles than the maximum number the buffer can store.

Does it make sense to create such a buffer (and create/release the corresponding resource) every frame? That way I don’t have to predefine a sufficiently large buffer and use degenerate triangles. Or should buffer.create and resource.create_buffer / resource.release not be used every frame?

I hope my question is clear enough.

Thanks for any help!

Ciao!

There’s quite a bit of code running in resource.create_buffer() (defold/engine/gamesys/src/gamesys/scripts/script_resource.cpp at dev · defold/defold · GitHub) and in the creation of a buffer, with the internals allocating and then later releasing memory (defold/engine/dlib/src/dlib/buffer.cpp at dev · defold/defold · GitHub).

I suppose you would have to do some measurements of both approaches to know if it is acceptable or not in terms of memory and CPU usage, but I would probably create the buffer once and then keep it around.

1 Like