public void DrawPrimitives(PrimitiveType primitiveType, int vertexStart, int primitiveCount) { int elementCountArray = GraphicsDevice.GetElementCountArray(primitiveType, primitiveCount); this.ApplyState(true); this._vertexBuffer.VertexDeclaration.Apply(this._vertexShader, IntPtr.Zero); GL.DrawArrays(GraphicsDevice.PrimitiveTypeGL(primitiveType), vertexStart, elementCountArray); }
public void DrawIndexedPrimitives(PrimitiveType primitiveType, int baseVertex, int minVertexIndex, int numVertices, int startIndex, int primitiveCount) { this.ApplyState(true); bool flag = this._indexBuffer.IndexElementSize == IndexElementSize.SixteenBits; DrawElementsType type = flag ? DrawElementsType.UnsignedShort : DrawElementsType.UnsignedInt; int num = flag ? 2 : 4; IntPtr indices = (IntPtr)(startIndex * num); int elementCountArray = GraphicsDevice.GetElementCountArray(primitiveType, primitiveCount); BeginMode mode = GraphicsDevice.PrimitiveTypeGL(primitiveType); this._vertexBuffer.VertexDeclaration.Apply(this._vertexShader, (IntPtr)(this._vertexBuffer.VertexDeclaration.VertexStride * baseVertex)); GL.DrawElements(mode, elementCountArray, type, indices); }
public void DrawUserPrimitives <T>(PrimitiveType primitiveType, T[] vertexData, int vertexOffset, int primitiveCount, VertexDeclaration vertexDeclaration) where T : struct, IVertexType { int elementCountArray = GraphicsDevice.GetElementCountArray(primitiveType, primitiveCount); this.ApplyState(true); GL.BindBuffer(BufferTarget.ArrayBuffer, 0); GL.BindBuffer(BufferTarget.ElementArrayBuffer, 0); this._vertexBufferDirty = this._indexBufferDirty = true; GCHandle gcHandle = GCHandle.Alloc((object)vertexData, GCHandleType.Pinned); vertexDeclaration.GraphicsDevice = this; vertexDeclaration.Apply(this._vertexShader, gcHandle.AddrOfPinnedObject()); GL.DrawArrays(GraphicsDevice.PrimitiveTypeGL(primitiveType), vertexOffset, elementCountArray); gcHandle.Free(); }
public void DrawUserIndexedPrimitives <T>(PrimitiveType primitiveType, T[] vertexData, int vertexOffset, int numVertices, int[] indexData, int indexOffset, int primitiveCount, VertexDeclaration vertexDeclaration) where T : struct, IVertexType { this.ApplyState(true); GL.BindBuffer(BufferTarget.ArrayBuffer, 0); GL.BindBuffer(BufferTarget.ElementArrayBuffer, 0); this._vertexBufferDirty = this._indexBufferDirty = true; GCHandle gcHandle1 = GCHandle.Alloc((object)vertexData, GCHandleType.Pinned); GCHandle gcHandle2 = GCHandle.Alloc((object)indexData, GCHandleType.Pinned); vertexDeclaration.GraphicsDevice = this; vertexDeclaration.Apply(this._vertexShader, gcHandle1.AddrOfPinnedObject()); GL.DrawElements(GraphicsDevice.PrimitiveTypeGL(primitiveType), GraphicsDevice.GetElementCountArray(primitiveType, primitiveCount), DrawElementsType.UnsignedInt, (IntPtr)(gcHandle2.AddrOfPinnedObject().ToInt64() + (long)(indexOffset * 4))); gcHandle2.Free(); gcHandle1.Free(); }