/// <summary> /// Draw geometry by indexing into the vertex buffer. /// </summary> /// <param name="primitiveType">The type of primitives in the index buffer.</param> /// <param name="baseVertex"> /// Used to offset the vertex range indexed from the vertex buffer. /// </param> /// <param name="minVertexIndex"> /// A hint of the lowest vertex indexed relative to baseVertex. /// </param> /// <param name="numVertices">An hint of the maximum vertex indexed.</param> /// <param name="startIndex"> /// The index within the index buffer to start drawing from. /// </param> /// <param name="primitiveCount"> /// The number of primitives to render from the index buffer. /// </param> /// <remarks> /// Note that minVertexIndex and numVertices are unused in MonoGame and will be ignored. /// </remarks> public void DrawIndexedPrimitives( PrimitiveType primitiveType, int baseVertex, int minVertexIndex, int numVertices, int startIndex, int primitiveCount ) { // Flush the GL state before moving on! ApplyState(); // Unsigned short or unsigned int? bool shortIndices = Indices.IndexElementSize == IndexElementSize.SixteenBits; // Set up the vertex buffers. for (int i = 0; i < vertexBufferCount; i += 1) { GLDevice.BindVertexBuffer( vertexBufferBindings[i].VertexBuffer.Handle ); vertexBufferBindings[i].VertexBuffer.VertexDeclaration.Apply( VertexShader, (IntPtr)( vertexBufferBindings[i].VertexBuffer.VertexDeclaration.VertexStride * (vertexBufferBindings[i].VertexOffset + baseVertex) ) ); } // Enable the appropriate vertex attributes. GLDevice.FlushGLVertexAttributes(); // Bind the index buffer GLDevice.BindIndexBuffer(Indices.Handle); // Draw! GLDevice.glDrawElements( PrimitiveTypeGL(primitiveType), //minVertexIndex, //minVertexIndex + numVertices - 1, GetElementCountArray(primitiveType, primitiveCount), shortIndices ? OpenGLDevice.GLenum.GL_UNSIGNED_SHORT : OpenGLDevice.GLenum.GL_UNSIGNED_INT, (startIndex * (shortIndices ? 2 : 4)) ); }