/// <summary> /// Function to create a index buffer. /// </summary> /// <param name="name">The name of the buffer.</param> /// <param name="settings">The settings for the buffer.</param> /// <param name="initialData">[Optional] Initial data to populate the index buffer with.</param> /// <returns>A new index buffer.</returns> /// <remarks>This method should only be called from an immediate graphics context, if it is called from a deferred context an exception will be thrown.</remarks> /// <exception cref="System.ArgumentNullException">Thrown when the <paramref name="name"/> parameter is NULL (Nothing in VB.Net). /// <para>-or-</para> /// <para>Thrown when the <paramref name="settings"/> parameter is NULL.</para> /// </exception> /// <exception cref="System.ArgumentException">Thrown when the <paramref name="name"/> parameter is empty.</exception> /// <exception cref="GorgonLibrary.GorgonException">Thrown when the <see cref="GorgonLibrary.Graphics.GorgonIndexBufferSettings.IsOutput">IsOutput</see> property is TRUE and has a usage that is not Default. /// <para>-or-</para> /// <para>Thrown when the <see cref="GorgonLibrary.Graphics.GorgonIndexBufferSettings.SizeInBytes">SizeInBytes</see> property of the <paramref name="settings"/> parameter is less than 1.</para> /// <para>-or-</para> /// <para>Thrown when the usage is set to immutable and the <paramref name="initialData"/> parameter is NULL (Nothing in VB.Net) or has no data.</para> /// </exception> public GorgonIndexBuffer CreateIndexBuffer(string name, GorgonIndexBufferSettings settings, GorgonDataStream initialData = null) { if (_graphics.IsDeferred) { throw new GorgonException(GorgonResult.CannotCreate, Resources.GORGFX_CANNOT_USE_DEFERRED_CONTEXT); } if (settings == null) { throw new ArgumentNullException("settings"); } if (settings.SizeInBytes < 1) { throw new GorgonException(GorgonResult.CannotCreate, string.Format(Resources.GORGFX_BUFFER_SIZE_TOO_SMALL, 1)); } if ((settings.Usage == BufferUsage.Immutable) && ((initialData == null) || (initialData.Length == 0))) { throw new GorgonException(GorgonResult.CannotCreate, Resources.GORGFX_BUFFER_IMMUTABLE_REQUIRES_DATA); } ValidateGenericBufferSettings(settings); var buffer = new GorgonIndexBuffer(_graphics, name, settings); buffer.Initialize(initialData); _graphics.AddTrackedObject(buffer); return(buffer); }
/// <summary> /// Initializes a new instance of the <see cref="GorgonIndexBuffer"/> class. /// </summary> /// <param name="graphics">The graphics.</param> /// <param name="name">Name for this index buffer.</param> /// <param name="settings">Settings for the buffer.</param> internal GorgonIndexBuffer(GorgonGraphics graphics, string name, GorgonIndexBufferSettings settings) : base(graphics, name, settings) { }