title: Porting OpenGL app to Metal API
body: <p>In OpenGL I got this ( shortened code )</p>
  
  <pre><code>void Mesh::CreateBuffer() { 
      glBindBuffer( GL_ARRAY_BUFFER, m_Buffers[POS_VB] );
      glBufferData( GL_ARRAY_BUFFER, sizeof(Positions[0] /*vec3*/) * iVerticeNum, &amp;Positions[0], GL_STATIC_DRAW );
      glEnableVertexAttribArray( POSITION_LOCATION );
      glVertexAttribPointer( POSITION_LOCATION, 3, GL_FLOAT, GL_FALSE, 0, 0 );
  
      // Fill index buffer.
      glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, m_Buffers[INDEX_BUFFER] );
      glBufferData( GL_ELEMENT_ARRAY_BUFFER, sizeof(Indices[0] /*unsigned int*/) * iIndiceNum, &amp;Indices[0], GL_STATIC_DRAW );
  
  }
  
  void Mesh::Render() {
  
      // bind vertex arrays here!
      .....
  
      glDrawElements( GL_TRIANGLES, this-&gt;NumIndices, GL_UNSIGNED_INT, 0);
      ....
  }
  </code></pre>
  
  <p>The code above is working perfectly in my engine. But when I've decided to port it to Metal API I got some problems, - it just renders half of model using <strong>index data</strong>, there are <strong>NO</strong> groups in its mesh, it's just simple mesh. But when I try to render it using vertice data ( drawPrimitives ) it renders fine.</p>
  
  <p>Here's Metal code I am using to initialize and render my mesh:</p>
  
  <pre><code>    INIT
      ....
      // Initialize mesh.
      MetalMesh mesh;
  
      mesh.vertexBuffer = [MetalDataBase-&gt;device newBufferWithBytes:Positions/* Vertice data */
                                              length:sizeof(vec3) * iNumVertices
                                             options:MTLResourceOptionCPUCacheModeDefault];
      mesh.indexBuffer = [MetalDataBase-&gt;device newBufferWithBytes:Indices
                                             length:sizeof(unsigned int) * iNumIndices
                                            options:MTLResourceOptionCPUCacheModeDefault];
  
      DRAW
      // Drawing..
      [MetalDataBase-&gt;commandEncoder setVertexBuffer:metalResource-&gt;metalMeshes[index].vertexBuffer offset:0 atIndex:0];
  
      // DrawPrimitives renders mesh **fine**, as it should.
      //[MetalDataBase-&gt;commandEncoder drawPrimitives:MTLPrimitiveTypeTriangle vertexStart:0 vertexCount:iVerticeNum]; 
  
      // But it doesn't, it just renders half of model,
      // while **iIndiceNum** is right number with its data.
      [MetalDataBase-&gt;commandEncoder drawIndexedPrimitives:MTLPrimitiveTypeTriangle indexCount:iIndiceNum indexType:MTLIndexTypeUInt32 indexBuffer:metalResource-&gt;metalMeshes[index].indexBuffer indexBufferOffset:0];
  </code></pre>