Пример #1
0
        /// <summary>
        /// Function to create a <see cref="IGorgonVertexBufferInfo"/> based on a <see cref="GorgonInputLayout"/> and the intended slot for vertex data.
        /// </summary>
        /// <param name="layout">The <see cref="GorgonInputLayout"/> to evaluate.</param>
        /// <param name="count">The number of vertices to store in the buffer.</param>
        /// <param name="slot">The intended slot to use for the vertex data.</param>
        /// <param name="usage">[Optional] The usage parameter for the vertex buffer.</param>
        /// <returns>A new <see cref="IGorgonVertexBufferInfo"/> to use when creating a <see cref="GorgonVertexBuffer"/>.</returns>
        /// <exception cref="ArgumentOutOfRangeException">Thrown when the <paramref name="count"/> parameter is less than 1.
        /// <para>-or-</para>
        /// <para>Thrown when the <paramref name="slot"/> is not present in the <paramref name="layout"/>.</para>
        /// </exception>
        /// <remarks>
        /// <para>
        /// This method is offered as a convenience to simplify the creation of the required info for a <see cref="GorgonVertexBuffer"/>. It will automatically determine the size of a vertex based on the size
        /// of the specified <paramref name="slot"/> in the <paramref name="layout"/>.
        /// </para>
        /// </remarks>
        /// <seealso cref="GorgonInputLayout"/>
        public static IGorgonVertexBufferInfo CreateFromInputLayout(GorgonInputLayout layout, int slot, int count, ResourceUsage usage = ResourceUsage.Default)
        {
            if (layout == null)
            {
                throw new ArgumentNullException(nameof(layout));
            }

            if (count < 1)
            {
                throw new ArgumentOutOfRangeException(nameof(count));
            }

            int sizeInBytes = layout.GetSlotSize(slot);

            if (sizeInBytes < 1)
            {
                throw new ArgumentOutOfRangeException(nameof(slot));
            }

            return(new GorgonVertexBufferInfo
            {
                Usage = usage,
                SizeInBytes = sizeInBytes * count
            });
        }
        /// <summary>
        /// Function to set a vertex buffer binding for the draw call.
        /// </summary>
        /// <param name="layout">The input layout to use.</param>
        /// <param name="binding">The vertex buffer binding to set.</param>
        /// <param name="slot">[Optional] The slot for the binding.</param>
        /// <returns>The fluent builder interface.</returns>
        /// <exception cref="ArgumentNullException">Thrown when the <paramref name="layout"/> parameter is <b>null</b>.</exception>
        /// <exception cref="ArgumentOutOfRangeException">Thrown when the <paramref name="slot"/> parameter is less than 0, or greater than/equal to <see cref="GorgonVertexBufferBindings.MaximumVertexBufferCount"/>.</exception>
        public TB VertexBuffer(GorgonInputLayout layout, GorgonVertexBufferBinding binding, int slot = 0)
        {
            if ((slot < 0) || (slot >= GorgonVertexBufferBindings.MaximumVertexBufferCount))
            {
                throw new ArgumentOutOfRangeException(nameof(slot), string.Format(Resources.GORGFX_ERR_INVALID_VERTEXBUFFER_SLOT, GorgonVertexBufferBindings.MaximumVertexBufferCount));
            }

            if (DrawCall.D3DState.VertexBuffers == null)
            {
                DrawCall.D3DState.VertexBuffers = new GorgonVertexBufferBindings();
            }

            DrawCall.D3DState.VertexBuffers[slot]       = binding;
            DrawCall.D3DState.VertexBuffers.InputLayout = layout ?? throw new ArgumentNullException(nameof(layout));
            return((TB)this);
        }
Пример #3
0
        /// <summary>
        /// Function to create a <see cref="IGorgonVertexBufferInfo"/> based on the type representing a vertex.
        /// </summary>
        /// <typeparam name="T">The type of data representing a vertex. This must be an unmanaged value type.</typeparam>
        /// <param name="count">The number of vertices to store in the buffer.</param>
        /// <param name="usage">[Optional] The usage parameter for the vertex buffer.</param>
        /// <returns>A new <see cref="IGorgonVertexBufferInfo"/> to use when creating a <see cref="GorgonVertexBuffer"/>.</returns>
        /// <exception cref="ArgumentOutOfRangeException">Thrown when the <paramref name="count"/> parameter is less than 1.</exception>
        /// <exception cref="GorgonException">Thrown when the type specified by <typeparamref name="T"/> is not safe for use with native functions (see <see cref="GorgonReflectionExtensions.IsFieldSafeForNative"/>).
        /// <para>-or-</para>
        /// <para>Thrown when the type specified by <typeparamref name="T"/> does not contain any public members.</para>
        /// </exception>
        /// <remarks>
        /// <para>
        /// This method is offered as a convenience to simplify the creation of the required info for a <see cref="GorgonVertexBuffer"/>. It will automatically determine the size of a vertex based on the size
        /// of a type specified by <typeparamref name="T"/> and fill in the <see cref="SizeInBytes"/> with the correct size.
        /// </para>
        /// <para>
        /// This method requires that the type passed by <typeparamref name="T"/> have its members decorated with the <see cref="InputElementAttribute"/>. This is used to determine which members of the
        /// type are to be used in determining the size of the type.
        /// </para>
        /// </remarks>
        /// <seealso cref="GorgonReflectionExtensions.IsFieldSafeForNative"/>
        /// <seealso cref="GorgonReflectionExtensions.IsSafeForNative(Type)"/>
        /// <seealso cref="GorgonReflectionExtensions.IsSafeForNative(Type,out IReadOnlyList{FieldInfo})"/>
        public static IGorgonVertexBufferInfo CreateFromType <T>(int count, ResourceUsage usage = ResourceUsage.Default)
            where T : unmanaged
        {
            if (count < 1)
            {
                throw new ArgumentOutOfRangeException(nameof(count));
            }

            List <(FieldInfo, InputElementAttribute)> fields = GorgonInputLayout.GetFieldInfoList(typeof(T));

            if (fields.Count == 0)
            {
                throw new GorgonException(GorgonResult.CannotCreate, string.Format(Resources.GORGFX_ERR_VERTEX_NO_FIELDS, typeof(T).FullName));
            }

            return(new GorgonVertexBufferInfo
            {
                Usage = usage,
                SizeInBytes = count * Unsafe.SizeOf <T>()
            });
        }
Пример #4
0
        /// <summary>
        /// Function to copy vertex buffer bindings from one draw call to another
        /// </summary>
        /// <param name="destBindings">The bindings to update.</param>
        /// <param name="srcBindings">The bindings to copy.</param>
        /// <param name="layout">The input layout.</param>
        public static void CopyVertexBuffers(GorgonVertexBufferBindings destBindings, IReadOnlyList <GorgonVertexBufferBinding> srcBindings, GorgonInputLayout layout)
        {
            destBindings.Clear();
            destBindings.InputLayout = layout;

            if (srcBindings == null)
            {
                return;
            }

            int count = srcBindings.Count.Min(GorgonVertexBufferBindings.MaximumVertexBufferCount);

            for (int i = 0; i < count; ++i)
            {
                destBindings[i] = srcBindings[i];
            }
        }
 /// <summary>
 /// Function to set the vertex buffer bindings for the draw call.
 /// </summary>
 /// <param name="layout">The input layout to use.</param>
 /// <param name="bindings">The vertex buffer bindings to set.</param>
 /// <returns>The fluent builder interface.</returns>
 /// <exception cref="ArgumentNullException">Thrown when the <paramref name="layout"/> parameter is <b>null</b>.</exception>
 public TB VertexBuffers(GorgonInputLayout layout, IReadOnlyList <GorgonVertexBufferBinding> bindings)
 {
     StateCopy.CopyVertexBuffers(DrawCall.D3DState.VertexBuffers, bindings, layout ?? throw new ArgumentNullException(nameof(layout)));
     return((TB)this);
 }
Пример #6
0
 /// <summary>
 /// Function to set a vertex buffer binding for the draw call in slot 0.
 /// </summary>
 /// <param name="layout">The input layout to use.</param>
 /// <param name="binding">The vertex buffer binding to set.</param>
 /// <returns>The fluent builder interface.</returns>
 /// <exception cref="ArgumentNullException">Thrown when the <paramref name="layout"/> parameter is <b>null</b>.</exception>
 public GorgonStreamOutCallBuilder VertexBuffer(GorgonInputLayout layout, in GorgonVertexBufferBinding binding)