title: What's the best way to keep adding new points to glBufferData?
body: <p>I am making an experiment with OpenGL to find what's the best/most efficient way to very frequently add new data to glBufferData.</p>
  
  <p>To do this, I wrote a small 2D paint program and simply keep adding points when I move the mouse.</p>
  
  <p>The whole function looks like this:</p>
  
  <pre><code>void addPoint(double x, double y)
  {
      glBindBuffer(GL_ARRAY_BUFFER, pointVertBuffObj);
      if (arrayOfPointCapacity &lt; numOfPoints + 1) {
          U32 size = (arrayOfPointCapacity + 8) * sizeof(Point2);
          Point2 *tmp = (Point2*)realloc(arrayOfPoints, size);
          arrayOfPoints = tmp;
          arrayOfPointCapacity += 8;
      }
      arrayOfPoints[numOfPoints].x = x, 
      arrayOfPoints[numOfPoints].y = y;
      U32 offset = numOfPoints * sizeof(Point2);
      glBufferData(GL_ARRAY_BUFFER, numOfPoints * sizeof(Point2), arrayOfPoints, GL_DYNAMIC_DRAW);
      numOfPoints++;
  }
  </code></pre>
  
  <p>Having to reset glBufferData with new data each time I add a point seems absolutely crazy. I thought about using <code>glBufferData</code> to allocate a large array of points and setting these points up with <code>glBufferSubData</code>. When the size of the buffer becomes too small, then I call <code>glBufferData</code> again increasing the size of the buffer, and copying back existing points to it.</p>
  
  <p>Ideally, I would prefer to avoid storing the point data in the computer memory and keep everything in the GPU memory. But when I would resize the buffer, I would have to copy the data back from the buffer to the CPU, then resize the buffer, and finally copy the data back to the buffer from the CPU. All this, also seems inefficient.</p>
  
  <p>Any idea? What's best practice?</p>