Esempio n. 1
0
        /// <summary>
        /// Function to create a vertex buffer.
        /// </summary>
        /// <param name="name">Name of the vertex buffer.</param>
        /// <param name="settings">The settings for the buffer.</param>
        /// <param name="initialData">[Optional] Initial data to populate the vertex buffer with.</param>
        /// <returns>A new vertex 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.GorgonBufferSettings.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.GorgonBufferSettings.SizeInBytes">SizeInBytes</see> property of the <paramref name="settings"/> parameter is less than 4.</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 GorgonVertexBuffer CreateVertexBuffer(string name, GorgonBufferSettings 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.Usage == BufferUsage.Immutable) && ((initialData == null) || (initialData.Length == 0)))
            {
                throw new GorgonException(GorgonResult.CannotCreate, Resources.GORGFX_BUFFER_IMMUTABLE_REQUIRES_DATA);
            }

            ValidateGenericBufferSettings(settings);

            var buffer = new GorgonVertexBuffer(_graphics, name, settings);

            buffer.Initialize(initialData);

            _graphics.AddTrackedObject(buffer);
            return(buffer);
        }
Esempio n. 2
0
        /// <summary>
        /// Function to create a generic buffer.
        /// </summary>
        /// <param name="name">Name of the buffer.</param>
        /// <param name="settings">The settings for the buffer.</param>
        /// <param name="stream">[Optional] Stream used to initialize the buffer.</param>
        /// <returns>A new generic buffer object.</returns>
        /// <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.GorgonBufferSettings.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.GorgonBufferSettings.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="stream"/> parameter is NULL (Nothing in VB.Net) or has no data.</para>
        /// </exception>
        /// <remarks>The generic buffer is intended to be used with the [RW]Buffer&lt;&gt; HLSL type.
        /// <para>Generic buffers are only available on video devices that are capable of SM4 or better.</para>
        /// <para>This method should only be called from an immediate graphics context, if it is called from a deferred context an exception will be thrown.</para>
        /// </remarks>
        public GorgonBuffer CreateBuffer(string name, GorgonBufferSettings settings, GorgonDataStream stream = null)
        {
            if (_graphics.IsDeferred)
            {
                throw new GorgonException(GorgonResult.CannotCreate, Resources.GORGFX_CANNOT_USE_DEFERRED_CONTEXT);
            }

            if (name == null)
            {
                throw new ArgumentNullException("name");
            }

            if (settings == null)
            {
                throw new ArgumentNullException("settings");
            }

            if (name.Length == 0)
            {
                throw new ArgumentException(Resources.GORGFX_PARAMETER_MUST_NOT_BE_EMPTY, "name");
            }

            if ((settings.Usage == BufferUsage.Immutable) && ((stream == null) || (stream.Length == 0)))
            {
                throw new GorgonException(GorgonResult.CannotCreate, Resources.GORGFX_BUFFER_IMMUTABLE_REQUIRES_DATA);
            }

            if ((settings.Usage == BufferUsage.Dynamic) && (!settings.AllowShaderViews))
            {
                throw new GorgonException(GorgonResult.CannotCreate, Resources.GORGFX_BUFFER_DYNAMIC_NEEDS_SHADER_VIEW);
            }

            // Validate our buffer settings.
            ValidateGenericBufferSettings(settings);

            var buffer = new GorgonBuffer(_graphics, name, settings);

            buffer.Initialize(stream);

            _graphics.AddTrackedObject(buffer);
            return(buffer);
        }
Esempio n. 3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="GorgonVertexBuffer"/> class.
 /// </summary>
 /// <param name="graphics">The graphics.</param>
 /// <param name="name">Name of the buffer.</param>
 /// <param name="settings">The settings for the vertex buffer.</param>
 internal GorgonVertexBuffer(GorgonGraphics graphics, string name, GorgonBufferSettings settings)
     : base(graphics, name, settings)
 {
 }