/// <summary> /// Draw the elements instances /// </summary> /// <param name="ctx"> /// The <see cref="GraphicsContext"/> used for drawing. /// </param> /// <param name="instances"> /// A <see cref="UInt32"/> that specify the number of instances to draw. /// </param> public override void DrawInstanced(GraphicsContext ctx, uint instances) { 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)) { // Enable primitive restart PrimitiveRestart.EnablePrimitiveRestart(ctx, ArrayIndices.ElementsType); // Draw elements as usual DrawElementsInstanced(ctx, arraySection.Pointer, instances); // Disable primitive restart PrimitiveRestart.DisablePrimitiveRestart(ctx); } else { throw new NotSupportedException(); } } 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 DrawElementsInstanced(ctx, arraySection.Pointer, instances); } }
/// <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); } }