title: consecutive calls to glDrawElements
body: <p>I am trying to draw a mesh with multiple textures. To do that, I seprate model in to sub models based on the textures.</p>
  
  <p>Here is the code and explanation:</p>
  
  <ul>
  <li>Set up render program by line RenderCommon and SetProjectViewModel functions</li>
  <li><p>Render common only initializes buffers if they are not already.</p>
  
  <pre><code> RenderCommon(object);
   SetProjectViewModel(m_basicProgramHandle, object, cam);
  </code></pre></li>
  <li><p>Collect mesh and its submeshes by the fallowing for loop</p>
  
  <pre><code>std::vector&lt;Mesh*&gt; meshes;
  meshes.push_back(object-&gt;m_mesh.get());
  for (int i = 0; i &lt; (int)object-&gt;m_mesh-&gt;m_subMeshes.size(); i++)
    meshes.push_back(object-&gt;m_mesh-&gt;m_subMeshes[i]);
  </code></pre></li>
  <li><p>Than the fallowing code is fore drawing each submesh with glDrawElements</p>
  
  <pre><code>  for (auto mesh : meshes)
    {
      GLuint offset = 0;
      glEnableVertexAttribArray(0); // Vertex
      glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, object-&gt;m_mesh-  &gt;GetVertexSize(), 0);
  
      offset += 3 * sizeof(float);
      glEnableVertexAttribArray(1); // Normal
      glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, object-&gt;m_mesh-&gt;GetVertexSize(), (const void*)offset);
  
      offset += 3 * sizeof(float);
      glEnableVertexAttribArray(2); // Texture
      glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, object-&gt;m_mesh-&gt;GetVertexSize(), (const void*)offset);
  
      glBindBuffer(GL_ARRAY_BUFFER, mesh-&gt;m_vboVertexId);
  
      RenderState rs = mesh-&gt;m_material-&gt;m_renderState;
      glBindTexture(GL_TEXTURE_2D, rs.m_diffuseTexture);
  
      if (mesh-&gt;m_indexCount != 0)
      {
        glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, mesh-&gt;m_vboIndexId);
        glDrawElements(GL_TRIANGLES, mesh-&gt;m_indexCount, GL_UNSIGNED_INT, nullptr);
      }
      else
      {
        glDrawArrays(GL_TRIANGLES, 0, mesh-&gt;m_vertexCount);
      } 
  </code></pre></li>
  </ul>
  
  <p>Lets say there is a cube and two textures for its 6 faces. 1 face has a texture of 1 on it and other texture has 0 on it. With this setup if I draw only one item. Its fine. However if for loop draws 2 items than I saw only front and back faces with two different textures. Instead of 6 faces. That is each object is drawn but partially.</p>
  
  <p>I check buffer and texture ids a hundred times ! they are correct. If I draw each buffer one by one than they are ok aswell. But if I draw them consecutively than they appears partially.</p>