コード例 #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="GorgonBuffer" /> 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="info"/> parameter is <b>null</b>.</exception>
        /// <exception cref="ArgumentException">Thrown if the size of the buffer is less than 1 byte.</exception>
        /// <exception cref="GorgonException">Thrown if the buffer is created with a usage of <see cref="ResourceUsage.Immutable"/>, but the <paramref name="initialData"/> parameter is <b>null</b>.
        /// <para>-or-</para>
        /// <para>A value on the <paramref name="info"/> parameter is incorrect.</para>
        /// </exception>
        public GorgonBuffer(GorgonGraphics graphics, IGorgonBufferInfo info, GorgonNativeBuffer <byte> initialData = null)
            : base(graphics)
        {
            _info = new GorgonBufferInfo(info ?? throw new ArgumentNullException(nameof(info)));

            Initialize(initialData);
        }
コード例 #2
0
        /// <summary>
        /// Function to build the description structure used to create the buffer.
        /// </summary>
        /// <param name="bufferInfo">The parameters used to create the buffer.</param>
        /// <returns>A new D3D 11 buffer description used to create the buffer.</returns>
        private D3D11.BufferDescription BuildBufferDesc(GorgonBufferInfo bufferInfo)
        {
            D3D11.BindFlags bindFlags     = GetBindingFlags(bufferInfo.Binding);
            var             resourceUsage = (D3D11.ResourceUsage)bufferInfo.Usage;

            // Round up to the nearest multiple of 4.
            bufferInfo.StructureSize = (bufferInfo.StructureSize + 3) & ~3;

            if (bufferInfo.StructureSize > 2048)
            {
                throw new GorgonException(GorgonResult.CannotCreate, string.Format(Resources.GORGFX_ERR_BUFFER_STRUCTURE_SIZE_INVALID, bufferInfo.StructureSize));
            }

            if (bufferInfo.AllowRawView)
            {
                // Raw buffers use 4 byte alignment.
                bufferInfo.SizeInBytes = (bufferInfo.SizeInBytes + 3) & ~3;
            }

            ValidateBufferBindings(bufferInfo.Usage, bufferInfo.Binding, bufferInfo.StructureSize);

            D3D11.ResourceOptionFlags options = D3D11.ResourceOptionFlags.None;

            if (bufferInfo.IndirectArgs)
            {
                options |= D3D11.ResourceOptionFlags.DrawIndirectArguments;
            }

            if (bufferInfo.AllowRawView)
            {
                options |= D3D11.ResourceOptionFlags.BufferAllowRawViews;
            }

            if (bufferInfo.StructureSize > 0)
            {
                options |= D3D11.ResourceOptionFlags.BufferStructured;
            }

            return(new D3D11.BufferDescription
            {
                SizeInBytes = bufferInfo.SizeInBytes,
                Usage = resourceUsage,
                BindFlags = bindFlags,
                OptionFlags = options,
                CpuAccessFlags = GetCpuFlags(bufferInfo.Usage, bufferInfo.Binding, bufferInfo.IndirectArgs),
                StructureByteStride = bufferInfo.StructureSize
            });
        }