| ␉␉␉int primitiveCount,␊ |
| ␉␉␉IndexBuffer indices␊ |
| ␉␉) {␊ |
| ␉␉␉// Unsigned short or unsigned int?␊ |
| ␉␉␉bool shortIndices = indices.IndexElementSize == IndexElementSize.SixteenBits;␊ |
| ␊ |
| ␉␉␉// Bind the index buffer␊ |
| ␉␉␉BindIndexBuffer(indices.buffer);␊ |
| ␊ |
|
| ␉␉␉␉minVertexIndex,␊ |
| ␉␉␉␉minVertexIndex + numVertices - 1,␊ |
| ␉␉␉␉XNAToGL.PrimitiveVerts(primitiveType, primitiveCount),␊ |
| ␉␉␉␉shortIndices ?␊ |
| ␉␉␉␉␉GLenum.GL_UNSIGNED_SHORT :␊ |
| ␉␉␉␉␉GLenum.GL_UNSIGNED_INT,␊ |
| ␉␉␉␉(IntPtr) (startIndex * (shortIndices ? 2 : 4)),␊ |
| ␉␉␉␉XNAToGL.IndexType[(int) indices.IndexElementSize],␊ |
| ␉␉␉␉(IntPtr) (startIndex * XNAToGL.IndexSize[(int) indices.IndexElementSize]),␊ |
| ␉␉␉␉baseVertex␊ |
| ␉␉␉);␊ |
| ␉␉}␊ |
|
| ␉␉␉// Bind the index buffer␊ |
| ␉␉␉BindIndexBuffer(indices.buffer);␊ |
| ␊ |
| ␉␉␉// Unsigned short or unsigned int?␊ |
| ␉␉␉bool shortIndices = indices.IndexElementSize == IndexElementSize.SixteenBits;␊ |
| ␊ |
| ␉␉␉// Draw!␊ |
| ␉␉␉glDrawElementsInstancedBaseVertex(␊ |
| ␉␉␉␉XNAToGL.Primitive[(int) primitiveType],␊ |
| ␉␉␉␉XNAToGL.PrimitiveVerts(primitiveType, primitiveCount),␊ |
| ␉␉␉␉shortIndices ?␊ |
| ␉␉␉␉␉GLenum.GL_UNSIGNED_SHORT :␊ |
| ␉␉␉␉␉GLenum.GL_UNSIGNED_INT,␊ |
| ␉␉␉␉(IntPtr) (startIndex * (shortIndices ? 2 : 4)),␊ |
| ␉␉␉␉XNAToGL.IndexType[(int) indices.IndexElementSize],␊ |
| ␉␉␉␉(IntPtr) (startIndex * XNAToGL.IndexSize[(int) indices.IndexElementSize]),␊ |
| ␉␉␉␉instanceCount,␊ |
| ␉␉␉␉baseVertex␊ |
| ␉␉␉);␊ |
|
| ␉␉␉// Unbind current index buffer.␊ |
| ␉␉␉BindIndexBuffer(OpenGLBuffer.NullBuffer);␊ |
| ␊ |
| ␉␉␉// Unsigned short or unsigned int?␊ |
| ␉␉␉bool shortIndices = indexElementSize == IndexElementSize.SixteenBits;␊ |
| ␊ |
| ␉␉␉// Draw!␊ |
| ␉␉␉glDrawRangeElements(␊ |
| ␉␉␉␉XNAToGL.Primitive[(int) primitiveType],␊ |
| ␉␉␉␉0,␊ |
| ␉␉␉␉numVertices - 1,␊ |
| ␉␉␉␉XNAToGL.PrimitiveVerts(primitiveType, primitiveCount),␊ |
| ␉␉␉␉shortIndices ?␊ |
| ␉␉␉␉␉GLenum.GL_UNSIGNED_SHORT :␊ |
| ␉␉␉␉␉GLenum.GL_UNSIGNED_INT,␊ |
| ␉␉␉␉XNAToGL.IndexType[(int) indexElementSize],␊ |
| ␉␉␉␉(IntPtr) (␊ |
| ␉␉␉␉␉indexData.ToInt64() +␊ |
| ␉␉␉␉␉(indexOffset * (shortIndices ? 2 : 4))␊ |
| ␉␉␉␉␉(indexOffset * XNAToGL.IndexSize[(int) indexElementSize])␊ |
| ␉␉␉␉)␊ |
| ␉␉␉);␊ |
| ␉␉}␊ |
|
| ␊ |
| ␉␉␉result = new OpenGLBuffer(␊ |
| ␉␉␉␉handle,␊ |
| ␉␉␉␉(IntPtr) (indexCount * (indexElementSize == IndexElementSize.SixteenBits ? 2 : 4)),␊ |
| ␉␉␉␉(IntPtr) (indexCount * XNAToGL.IndexSize[(int) indexElementSize]),␊ |
| ␉␉␉␉dynamic ? GLenum.GL_STREAM_DRAW : GLenum.GL_STATIC_DRAW␊ |
| ␉␉␉);␊ |
| ␊ |
|
| ␉␉␉␉␉␉element.VertexElementFormat == VertexElementFormat.NormalizedShort4␉);␊ |
| ␉␉␉}␊ |
| ␊ |
| ␉␉␉public static readonly GLenum[] IndexType = new GLenum[]␊ |
| ␉␉␉{␊ |
| ␉␉␉␉GLenum.GL_UNSIGNED_SHORT,␉// IndexElementSize.SixteenBits␊ |
| ␉␉␉␉GLenum.GL_UNSIGNED_INT␉␉// IndexElementSize.ThirtyTwoBits␊ |
| ␉␉␉};␊ |
| ␊ |
| ␉␉␉public static readonly int[] IndexSize = new int[]␊ |
| ␉␉␉{␊ |
| ␉␉␉␉2,␉// IndexElementSize.SixteenBits␊ |
| ␉␉␉␉4␉// IndexElementSize.ThirtyTwoBits␊ |
| ␉␉␉};␊ |
| ␊ |
| ␉␉␉public static readonly GLenum[] Primitive = new GLenum[]␊ |
| ␉␉␉{␊ |
| ␉␉␉␉GLenum.GL_TRIANGLES,␉␉// PrimitiveType.TriangleList␊ |