/// <summary>
        /// Initializes a new instance of the <see cref="GorgonConstantBufferInfo"/> class.
        /// </summary>
        /// <param name="info">A <see cref="IGorgonConstantBufferInfo"/> to copy settings from.</param>
        /// <param name="newName">[Optional] The new name for the buffer.</param>
        /// <exception cref="ArgumentNullException">Thrown when the <paramref name="info"/> parameter is <b>null</b>.</exception>
        public GorgonConstantBufferInfo(IGorgonConstantBufferInfo info, string newName = null)
        {
            if (info == null)
            {
                throw new ArgumentNullException(nameof(info));
            }

            Name        = string.IsNullOrEmpty(newName) ? info.Name : newName;
            SizeInBytes = info.SizeInBytes;
            Usage       = info.Usage;
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="GorgonConstantBuffer" /> class.
        /// </summary>
        /// <param name="graphics">The <see cref="GorgonGraphics"/> object used to create and manipulate the buffer.</param>
        /// <param name="info">Information used to create the buffer.</param>
        /// <param name="initialData">[Optional] The initial data used to populate the buffer.</param>
        /// <exception cref="ArgumentNullException">Thrown when the <paramref name="graphics"/>, or <paramref name="info"/> parameters are <b>null</b>.</exception>
        /// <exception cref="GorgonException">
        /// Thrown when the size of the constant buffer exceeds the maximum constant buffer size. See <see cref="IGorgonVideoAdapterInfo.MaxConstantBufferSize"/> to determine the maximum size of a constant buffer.
        /// </exception>
        public GorgonConstantBuffer(GorgonGraphics graphics, IGorgonConstantBufferInfo info, GorgonNativeBuffer <byte> initialData = null)
            : base(graphics)
        {
            if (info == null)
            {
                throw new ArgumentNullException(nameof(info));
            }

            _info = new GorgonConstantBufferInfo(info);

            Initialize(initialData);
        }
Example #3
0
        /// <summary>
        /// Function to create a constant buffer and an associated view.
        /// </summary>
        /// <param name="graphics">The graphics interface to use when creating the target.</param>
        /// <param name="info">The information about the texture.</param>
        /// <param name="startConstant">[Optional] The index of the first constant within the buffer to view.</param>
        /// <param name="constantCount">[Optional] The number of constants in the buffer to view.</param>
        /// <returns>A new <see cref="GorgonConstantBufferView"/>.</returns>
        /// <exception cref="ArgumentNullException">Thrown when the <paramref name="graphics"/>, or <paramref name="info"/> parameter is <b>null</b>.</exception>
        /// <remarks>
        /// <para>
        /// This is a convenience method that will create a <see cref="GorgonConstantBuffer"/> and a <see cref="GorgonConstantBufferView"/> as a single object that can be used to pass constant information
        /// to a shader.
        /// </para>
        /// <para>
        /// Since the <see cref="GorgonConstantBuffer"/> created by this method is linked to the <see cref="GorgonConstantBufferView"/> returned, disposal of either one will dispose of the other on your
        /// behalf. If the user created a <see cref="GorgonConstantBufferView"/> from the <see cref="GorgonConstantBuffer.GetView"/> method on the <see cref="GorgonConstantBuffer"/>, then it's assumed the
        /// user knows what they are doing and will handle the disposal of the buffer and view on their own.
        /// </para>
        /// <para>
        /// If provided, the <paramref name="startConstant"/> parameter must be between 0 and the total number of constants in the buffer.  If it is not it will be constrained to those values to ensure there
        /// is no out of bounds access to the buffer.
        /// </para>
        /// <para>
        /// If the <paramref name="constantCount"/> parameter is omitted (or equal to or less than 0), then the remainder of the buffer is mapped to the view up to 4096 constants. If it is provided, then the
        /// number of constants will be mapped to the view, up to a maximum of 4096 constants.  If the value exceeds 4096, then it will be constrained to 4096.
        /// </para>
        /// <para>
        /// A constant buffer constant is a single float4 value (4 floating point values).
        /// </para>
        /// </remarks>
        /// <seealso cref="GorgonConstantBuffer"/>
        public static GorgonConstantBufferView CreateConstantBuffer(GorgonGraphics graphics, IGorgonConstantBufferInfo info, int startConstant = 0, int constantCount = 0)
        {
            if (graphics == null)
            {
                throw new ArgumentNullException(nameof(graphics));
            }

            if (info == null)
            {
                throw new ArgumentNullException(nameof(info));
            }

            var buffer = new GorgonConstantBuffer(graphics, info);
            GorgonConstantBufferView view = buffer.GetView(startConstant, constantCount);

            view._ownsBuffer = true;
            return(view);
        }