title: glBufferSubData has peaks with small buffer sizes
body: <p>I am making a simple 2D game engine with OpenGL, and my <code>SpriteRenderer</code> class makes batches of sprites which use the same shader or texture. Once I sort them first by texture, then by shader, and then by depth, the <code>uploadData()</code> method of my <code>SpriteRenderer</code> class uploads the CPU generated vertex data to the GPU. For this I am using the orphaning method, which is said to be faster than a simple <code>glBufferData</code> call.</p>
  
  <p>My problem is, when I have small numbers of sprites (&lt;15), I have frames with huge stalls, but with numbers >20 up to 10 000 it runs smoothly. I wrapped opengl function into c++ classes. If I replace the <code>VertexBufferObject::uploadOrphaned()</code> method by the <code>VertexBufferObject::upload()</code> method, the stall goes away. Here is my vbo class:</p>
  
  <pre><code>    //vbo.h
      class VertexBufferObject
      {
      public:
          VertexBufferObject();
          VertexBufferObject(size_t allocSize);
          ~VertexBufferObject();
  
          inline ui32     id(){ return    (ui32)m_id; }
  
          template &lt;class T&gt;
          void    addData(const T&amp; data)
          {
              const byte* convertedData = reinterpret_cast&lt;const byte*&gt;(&amp;data);
              size_t size = sizeof(T);
              for (ui32 i = 0; i &lt; size; i++)m_data.add(convertedData[i]);
          }
  
          void    initialize();
  
          void    resetData();
          void    upload(GLenum drawType);
          void    uploadOrphaned(GLenum drawType);
  
          inline  void    bind()  { ::glBindBuffer(GL_ARRAY_BUFFER, m_id); }
          inline  void    unbind(){ ::glBindBuffer(GL_ARRAY_BUFFER, 0); }
  
  
      private:
          GLuint      m_id;
          //this is my custom dynamic array class, this is a hobby project
          //and I enjoy reinventing the wheel :)
          Array&lt;byte&gt; m_data;
  </code></pre>
  
  <p>and below is the cpp file:</p>
  
  <pre><code>    VertexBufferObject::VertexBufferObject() :m_id(0)
      {
  
      }
  
      VertexBufferObject::VertexBufferObject(size_t allocSize) : m_id(0), m_data(allocSize)
      {
  
      }
  
      VertexBufferObject::~VertexBufferObject()
      {
          if (m_id != 0) ::glDeleteBuffers(1, &amp;m_id);
      }
  
      void    VertexBufferObject::initialize()
      {
          if (m_id == 0) ::glGenBuffers(1, &amp;m_id);
      }
  
      void VertexBufferObject::upload(GLenum drawType)
      {
          glBufferData(GL_ARRAY_BUFFER, m_data.size(), &amp;m_data[0], drawType);
      }
  
      void VertexBufferObject::uploadOrphaned(GLenum drawType)
      {
          glBufferData(GL_ARRAY_BUFFER, m_data.size() * 2, NULL, drawType);
          glBufferSubData(GL_ARRAY_BUFFER, 0, m_data.size(), &amp;m_data[0]);
      }
  
  
      void VertexBufferObject::resetData()
      {
          m_data.strip();
      }
  </code></pre>
  
  <p>I am learning opengl, so my VertexBufferObject class contains what I already know. I know there are other methods to upload data, but I want to understand the reason of the current problem with this simple method. I looked around forums including here, and nobody had a similar issue that I found of. Maybe my class has some errors?</p>