CustomMesh and Mesh.setBuffer()

Hi,

I am creating an editable custom mesh and want to update the mesh.

For that I am using



m.setBuffer(Type.Position, 3, BufferUtils.createFloatBuffer(vertices));



(If I don’t use this, the mesh does not get updated)

This gives me the error “Data has already been sent. Cannot setupData again.” in Vertexbuffer.java



public void setupData(Usage usage, int components, Format format, Buffer data){

if (id != -1)

throw new UnsupportedOperationException(“Data has already been sent. Cannot setupData again.”);

if (usage == null || format == null || data == null)

throw new IllegalArgumentException(“None of the arguments can be null”);

if (components < 1 || components > 4)

throw new IllegalArgumentException(“components must be between 1 and 4”);

this.data = data;

this.components = components;

this.usage = usage;

this.format = format;

this.componentsLength = components * format.getComponentSize();

this.lastLimit = data.limit();

setUpdateNeeded();

}



When I comment the first two lines out, it works perfectly.

Can anyone tell me what those lines are for and what could happen, if I leave them commented out?

Thank you :slight_smile:

You should net use a new buffer on any change, but modify the contents and then call buffervariable. setUpdateNeeded();. This does not create a new opengl object, but updates the previous one.

Thank you Empire, it works :slight_smile: