/// <summary> /// Draw the elements. /// </summary> /// <param name="ctx"> /// The <see cref="GraphicsContext"/> used for drawing. /// </param> public override void Draw(GraphicsContext ctx) { CheckCurrentContext(ctx); ArrayBufferObjectBase.IArraySection arraySection = ArrayIndices.GetArraySection(0); Debug.Assert(arraySection != null); // Element array must be (re)bound ctx.Bind(ArrayIndices, true); // Enable restart primitive? if (ArrayIndices.RestartIndexEnabled) { if (PrimitiveRestart.IsPrimitiveRestartSupported(ctx)) { // Draw elements with primitive restart PrimitiveRestart.EnablePrimitiveRestart(ctx, ArrayIndices.ElementsType); DrawElements(ctx, arraySection.Pointer); PrimitiveRestart.DisablePrimitiveRestart(ctx); } else { // Note: uses MultiDrawElements to emulate the primitive restart feature; PrimitiveRestartOffsets and // PrimitiveRestartCounts are computed at element buffer creation time Gl.MultiDrawElements(ElementsMode, ArrayIndices.PrimitiveRestartOffsets, ArrayIndices.ElementsType, ArrayIndices.PrimitiveRestartCounts, ArrayIndices.PrimitiveRestartOffsets.Length); } } else { uint count = (ElementCount == 0) ? ArrayIndices.ItemCount : ElementCount; Debug.Assert(count - ElementOffset <= ArrayIndices.ItemCount, "element indices array out of bounds"); // Draw vertex arrays by indices DrawElements(ctx, arraySection.Pointer); } }