title: Is it possible to use Index Buffer Objects (IBO) with the function 'glMultiDrawElements'?
body: <p>I develop a small 3D engine using OpenGL and GLSL. </p>
  
  <p>I have incorporated a vertex data batching system which the goal is to gather all the geometry (all the objects) sharing the same shader program and same transformations in a unique Vertex Buffer Object (VBO) thereby minimizing the state changes (binding) and draw calls too. </p>
  
  <p>I currently use the function 'glMultiDrawElements' to render a specific batch of data (so a single draw call). So, for instance, if I have in my batch 3 meshes, I have 3 arrays of indices too (one for each mesh) organized in a 'GLvoid **' array (a double array). So to render my 3 meshes I have a unique call of glMultiDrawElements but I have to pass directly to the function the double array of elements in parameter. </p>
  
  <p>But I wonder (for a question of performance) if it's possible to store all the elements (the double array of elements) in a Index Buffer Object (IBO)(like it's possible to do with glDrawElements -> here a simple array of elements) and bind it before the glMultiDrawElements call... I don't think so because it's a double array and not a simple array but maybe (and I hope so) I'm wrong.</p>
  
  <p>Here's an example using glDrawElements (pseudo code):</p>
  
  <pre><code>[...]
  
  //Setup data
  
  [...]
  
  #define OFFSET_BUFFER(offset) ((char*)NULL + offset)
  
  foreach (pMeshGeometry from meshes) //iterates for each mesh of the scene
  {
      pMeshGeometry-&gt;GetIndexBuffer().Lock(); //Bind IBO
      {
           glDrawElements(pMeshGeometry-&gt;GetPrimitiveType(),       
               pMeshGeometry-&gt;GetIndexBufferSize(), pMeshGeometry-&gt;GetIndexBuffer().GetType(), OFFSET_BUFFER(0)); //Render a specific mesh eccording to indices
      }
  }
  </code></pre>
  
  <p>For the moment I use glMultiDrawElement this way:</p>
  
  <pre><code>glMultiDrawElements(GL_TRIANGLES, &amp;this-&gt;m_CountElementArray[0], GL_UNSIGNED_INT,
                      (const GLvoid **)&amp;this-&gt;m_IndexAttribArray[0], this-&gt;m_CountElementArray.size()); //I enter the array of pointer directly in parameter
  </code></pre>
  
  <p>So, maybe to following example should be possible:</p>
  
  <pre><code>#define OFFSET_BUFFER(offset) ((char**)NULL + offset) //Something like this
  
  glMultiDrawElements(GL_TRIANGLES, &amp;this-&gt;m_CountElementArray[0], GL_UNSIGNED_INT,
                      OFFSET_BUFFER(0), this-&gt;m_CountElementArray.size()); //Something like this
  </code></pre>
  
  <p>So if it's not possible to do this, I've thought to the function 'glDrawRangeElements'. For my example of 3 meshes into a unique VBO, I'll just have to bind an IBO before each glDrawRangeElements call (here, 3 draw calls for each mesh -> so a loop of glDrawRangeElements). So here it's clearly possible to use IBO. </p>
  
  <p>This method will work for sure but I don't think it's the best one! I think it's possible to do this using glMultiDrawElements with an IBO but I don't know how to do this. </p>
  
  <p>Or maybe it's really impossible. Maybe the fact to enter directy in parameter an array of indices is faster than the method using glDrawRangeElements and its IBO and so the usage of IBO in this case is maybe deprecated and so not adapted. </p>
  
  <p>What do you think of that ?</p>