Firstly the VBO was initialized like below:

GLuint vertex_buffer;
glGenBuffers(1, &vertex_buffer);
glBindBuffer(GL_ARRAY_BUFFER, vertex_buffer);
glBufferData(GL_ARRAY_BUFFER, data_size_in_bytes, data_vertices, GL_STATIC_DRAW);

data_vertices store some points data, then I push back another points into it and data_vertices will be resized(larger).

If glDeleteBuffers/glGenBuffers needed to be called again or only just glBindBuffer the new data?

glDeleteBuffers(1, &vertex_buffer); // is this necessary?
glGenBuffers(1, &vertex_buffer); // is this necessary?
glBindBuffer(GL_ARRAY_BUFFER, vertex_buffer);
glBufferData(GL_ARRAY_BUFFER, new_data_size_in_bytes, new_data_vertices, GL_STATIC_DRAW);

Now I did not call glDeleteBuffers/glGenBuffers in every update frame, and on some computers the points maybe disappear...


1 Answer 1


glbufferData is the command which initializes the buffer size. So you can bind the old buffer with wrong size and use glbufferData to resize it. You don't have to delete and recreate the buffer.

GLint size = 0;
GLuint bufferTest = 0;
glGenBuffers(1, &bufferTest); //generate buffer item
glBindBuffer(GL_SHADER_STORAGE_BUFFER, bufferTest);
glBufferData(GL_SHADER_STORAGE_BUFFER, 16, nullptr, GL_STATIC_DRAW); //initialize buffer with size 16 bytes
glGetBufferParameteriv(GL_SHADER_STORAGE_BUFFER, GL_BUFFER_SIZE, &size); //get buffer size
glBindBuffer(GL_SHADER_STORAGE_BUFFER, 0); //unbind buffer

size will be 16!

glBindBuffer(GL_SHADER_STORAGE_BUFFER, bufferTest); 
glBufferData(GL_SHADER_STORAGE_BUFFER, 24, nullptr, GL_STATIC_DRAW); //reinitialize buffer with size 24 bytes
glGetBufferParameteriv(GL_SHADER_STORAGE_BUFFER, GL_BUFFER_SIZE, &size); //get new buffer size
glBindBuffer(GL_SHADER_STORAGE_BUFFER, 0); //unbind buffer

sizewill be 24


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.