<p>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.</p>
<pre><code>GLint size = 0;
GLuint bufferTest = 0;
glGenBuffers(1, &amp;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, &amp;size); //get buffer size
glBindBuffer(GL_SHADER_STORAGE_BUFFER, 0); //unbind buffer
</code></pre>
<p><code>size</code> will be 16!</p>
<pre><code>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, &amp;size); //get new buffer size
glBindBuffer(GL_SHADER_STORAGE_BUFFER, 0); //unbind buffer
</code></pre>
<p><code>size</code>will be 24</p>

CC BY-SA 4.0
2023-06-25T16:55:45.527Z
2023-06-26T06:57:17.500Z
2023-06-26T06:57:17.500Z
Thomas
<p>Firstly the VBO was initialized like below:</p>
<pre><code>GLuint vertex_buffer;
glGenBuffers(1, &amp;vertex_buffer);
glBindBuffer(GL_ARRAY_BUFFER, vertex_buffer);
glBufferData(GL_ARRAY_BUFFER, data_size_in_bytes, data_vertices, GL_STATIC_DRAW);
</code></pre>
<p>data_vertices store some points data, then I push back another points into it and data_vertices will be resized(larger).</p>
<p>If glDeleteBuffers/glGenBuffers needed to be called again or only just glBindBuffer the new data?</p>
<pre><code>glDeleteBuffers(1, &amp;vertex_buffer); // is this necessary?
glGenBuffers(1, &amp;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);
</code></pre>
<p>Now I did not call glDeleteBuffers/glGenBuffers in every update frame, and on some computers the points maybe disappear...</p>

<opengl><opengl-es>
Is glDeleteBuffers/glGenBuffers needed if I want to resize the buffer?
wayright
# Is glDeleteBuffers/glGenBuffers needed if I want to resize the buffer?

(Asked by: username_0 on 2023-06-25)

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...

**Tags:** opengl, opengl-es


---

## 1 answers

### Answer by username_1 on 2023-06-25. Score: 0 | Accepted answer

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

```

`size`will be 24


---

