<blockquote>
  <p>Is it possible to change the buffer data uploaed directly without uploading the whole data again?</p>
</blockquote>

<p>"Again"? You didn't upload "the whole data" the <em>first time</em>:</p>

<blockquote>
<pre><code>glBufferSubData(GL_ARRAY_BUFFER, 0, vertex_data_size, data);
</code></pre>
</blockquote>

<p>That only affects the first <code>vertex_data_size</code> bytes of the buffer. And your second one only affects the data on the byte range [vertex_data_size, color_data_size + vertex_data_size).</p>

<p>There's no limit on how many bytes you can modify with a <code>glBufferSubData</code> call. Or more to the point, there's no limit on how <em>few</em> bytes you can modify. If you want to upload 12 bytes worth of data, you can.</p>

<p>Now, you <em>shouldn't</em>. You should avoid making lots of small uploads of data like that.</p>

<p>If you have access to <a href="https://www.khronos.org/opengl/wiki/Buffer_Object#Persistent_mapping" rel="nofollow noreferrer">persistent mapping</a>, it would be better to persistently map the buffer and simply modify the location(s) at the appropriate time (using <a href="https://www.khronos.org/opengl/wiki/Buffer_Object_Streaming#Persistent_mapped_streaming" rel="nofollow noreferrer">proper synchronization and multiple buffering</a>).</p>

CC BY-SA 3.0
2018-02-03T20:22:11.120Z
I know what you mean. But my question is how to modify the data. You said " You should avoid making lots of small uploads of data like that." Of course, we should avoid, but it's just a simple example to describe my question in detail.
shashack
CC BY-SA 3.0
2018-02-03T20:23:46.333Z
@shashack: "*But my question is how to modify the data.*" But you already know how to modify the data. That's how you put it there in the first place.
Nicol Bolas
CC BY-SA 3.0
2018-02-03T20:26:19.953Z
Ok what if the number of vertex size is 100000000 and I just need to modify just 1 vertex in the buffer data. Do I need to bind the buffer and upload data again? It would take so much time.
shashack
CC BY-SA 3.0
2018-02-03T20:27:46.983Z
@shashack: Then only upload what you need. Just like your two `glBufferSubData` calls each only uploaded part of the total buffer size. There's no limit on how much or ***how little*** data you can upload. I don't know how to make "If you want to upload 12 bytes worth of data, you can." more clear without literally writing the code for you.
Nicol Bolas
CC BY-SA 3.0
2018-02-03T20:33:52.820Z
Oh so you mean I can call glBufferSubData super many time? For example, If I have vertex 100000000 size, then  100000000 time?
shashack
CC BY-SA 3.0
2018-02-03T21:08:18.123Z
@shashack: "*I just need to modify just 1 vertex in the buffer data*" "*I have vertex 100000000 size, then 100000000 time?*" Pick a scenario. Either you need to update one vertex, or you need to update *all of them*.
Nicol Bolas
CC BY-SA 3.0
2018-02-03T21:26:31.587Z
I got it! Thank you for answering. I couldn't think to use glBuuferSubData so many. Good day!
shashack
CC BY-SA 3.0
2018-02-03T15:47:10.620Z
2018-02-03T15:47:10.620Z
Nicol Bolas
<p>After binding the data to the vertex buffer object as follows, how to modify the buffer data?</p>

<p>(Each subdata size is 3$*$ data size (three elements per index) </p>

<pre><code>glm::vec3 vertex;
vertex.push_back(glm::vec3(0.0f, 0.0f, 0.0f));
vertex.push_back(glm::vec3(0.0f, 0.0f, 1.0f));
vertex.push_back(glm::vec3(1.0f, 0.0f, 0.0f));

glm::vec3 color;
color.push_back(glm::vec3(1.0f, 0.0f, 0.0f));
color.push_back(glm::vec3(0.0f, 1.0f, 0.0f));
color.push_back(glm::vec3(0.0f, 0.0f, 1.0f));

glBufferData(GL_ATTRAY_BUFFER, vertex_data_size+color_data_size, NULL, GL_DYNAMIC_DRAW);
glBufferSubData(GL_ARRAY_BUFFER, 0, vertex_data_size, data);
glBufferSubData(GL_ARRAY_BUFFER, vertex_data_size, color_data_size, data);
glEnableVertexAttribArray(0);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, (void*)0);
glEnableVertexAttribArray(1);
glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 0, (void*)vertex_data_size);
</code></pre>

<p>In detail, supposing I want to change the second vertex element to (1.0f, 1.0f, 1.0f). I know it with compute shader, but I just wnat to know how to do it without compute shader or OpenCl.</p>

<p>Is it possible to change the buffer data uploaed directly without uploading the whole data again? </p>

<opengl><glsl><data-structure>
How to modify a part of VBO data without Compute Shader or OpenCL?
shashack
# How to modify a part of VBO data without Compute Shader or OpenCL?

(Asked by: username_0 on 2018-02-03)

After binding the data to the vertex buffer object as follows, how to modify the buffer data?
(Each subdata size is 3$*$ data size (three elements per index) 
glm::vec3 vertex;
vertex.push_back(glm::vec3(0.0f, 0.0f, 0.0f));
vertex.push_back(glm::vec3(0.0f, 0.0f, 1.0f));
vertex.push_back(glm::vec3(1.0f, 0.0f, 0.0f));

glm::vec3 color;
color.push_back(glm::vec3(1.0f, 0.0f, 0.0f));
color.push_back(glm::vec3(0.0f, 1.0f, 0.0f));
color.push_back(glm::vec3(0.0f, 0.0f, 1.0f));

glBufferData(GL_ATTRAY_BUFFER, vertex_data_size+color_data_size, NULL, GL_DYNAMIC_DRAW);
glBufferSubData(GL_ARRAY_BUFFER, 0, vertex_data_size, data);
glBufferSubData(GL_ARRAY_BUFFER, vertex_data_size, color_data_size, data);
glEnableVertexAttribArray(0);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, (void*)0);
glEnableVertexAttribArray(1);
glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 0, (void*)vertex_data_size);

In detail, supposing I want to change the second vertex element to (1.0f, 1.0f, 1.0f). I know it with compute shader, but I just wnat to know how to do it without compute shader or OpenCl.
Is it possible to change the buffer data uploaed directly without uploading the whole data again?

**Tags:** opengl, glsl, data-structure

---

## 1 answers

### Answer by username_1 on 2018-02-03. Score: 1 | Accepted answer

Is it possible to change the buffer data uploaed directly without uploading the whole data again?

"Again"? You didn't upload "the whole data" the first time:

glBufferSubData(GL_ARRAY_BUFFER, 0, vertex_data_size, data);


That only affects the first vertex_data_size bytes of the buffer. And your second one only affects the data on the byte range [vertex_data_size, color_data_size + vertex_data_size).
There's no limit on how many bytes you can modify with a glBufferSubData call. Or more to the point, there's no limit on how few bytes you can modify. If you want to upload 12 bytes worth of data, you can.
Now, you shouldn't. You should avoid making lots of small uploads of data like that.
If you have access to persistent mapping, it would be better to persistently map the buffer and simply modify the location(s) at the appropriate time (using proper synchronization and multiple buffering).

> **Comments:**
> **username_0**: I know what you mean. But my question is how to modify the data. You said " You should avoid making lots of small uploads of data like that." Of course, we should avoid, but it's just a simple example to describe my question in detail.  
> **username_1**: @shashack: "*But my question is how to modify the data.*" But you already know how to modify the data. That's how you put it there in the first place.  
> **username_0**: Ok what if the number of vertex size is 100000000 and I just need to modify just 1 vertex in the buffer data. Do I need to bind the buffer and upload data again? It would take so much time.  
> **username_1**: @shashack: Then only upload what you need. Just like your two `glBufferSubData` calls each only uploaded part of the total buffer size. There's no limit on how much or ***how little*** data you can upload. I don't know how to make "If you want to upload 12 bytes worth of data, you can." more clear without literally writing the code for you.  
> **username_0**: Oh so you mean I can call glBufferSubData super many time? For example, If I have vertex 100000000 size, then  100000000 time?  
> **username_1**: @shashack: "*I just need to modify just 1 vertex in the buffer data*" "*I have vertex 100000000 size, then 100000000 time?*" Pick a scenario. Either you need to update one vertex, or you need to update *all of them*.  
> **username_0**: I got it! Thank you for answering. I couldn't think to use glBuuferSubData so many. Good day!  

---

