I am following WebGL tutorials. I have an initialized vertex buffer with buffer data's purpose is set to gl.STATIC_DRAW. As far as I have read from the MDN's documentation which describes usage, gl.STATIC_DRAW is used if my vertex data
is not change throughout the application. As they state:
The contents are intended to be specified once by the application, and used many times as the source for WebGL drawing and image specification commands.
I currently have this piece of code to initialize my vertex buffer:
const vertices = new Float32Array([
-1.0, 1.0, -1.0, -1.0, 1.0, 1.0, 1.0, -1.0
]);
const n = 4;
const vertexBuffer = gl.createBuffer();
gl.bindBuffer(gl.ARRAY_BUFFER, vertexBuffer);
gl.bufferData(gl.ARRAY_BUFFER, vertices, gl.STATIC_DRAW);
const aPosition = gl.getAttribLocation(program, 'aPosition');
gl.vertexAttribPointer(aPosition, 2, gl.FLOAT, false, 0, 0);
gl.enableVertexAttribArray(aPosition);
I want to alter the content of this buffer, for example add new vertex coordinates to be drawn. I don't want to re-initialize the whole vertex buffer as it would be, I assume, wouldn't be good in performance wise.
I have the idea of using the usage as gl.DYNAMIC_DRAW, as they state in the MDN documentation:
The contents are intended to be respecified repeatedly by the application, and used many times as the source for WebGL drawing and image specification commands.
But if I use this value as my usage, how will I provide new vertices to the current buffer and redraw? I couldn't find any example that shows this.
Thank you in advance.