コード例 #1
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
            });
        }
コード例 #2
0
        public static Direct3D11.Texture2D CreateTexture2D(this Direct3D11.Device device,
                                                           int w, int h,
                                                           Direct3D11.BindFlags flags = Direct3D11.BindFlags.RenderTarget | Direct3D11.BindFlags.ShaderResource,
                                                           Format format = Format.B8G8R8A8_UNorm,
                                                           Direct3D11.ResourceOptionFlags options = Direct3D11.ResourceOptionFlags.Shared)
        {
            var colordesc = new Direct3D11.Texture2DDescription
            {
                BindFlags         = flags,
                Format            = format,
                Width             = w,
                Height            = h,
                MipLevels         = 1,
                SampleDescription = new SampleDescription(1, 0),
                Usage             = Direct3D11.ResourceUsage.Default,
                OptionFlags       = options,
                CpuAccessFlags    = Direct3D11.CpuAccessFlags.None,
                ArraySize         = 1
            };

            return(new Direct3D11.Texture2D(device, colordesc));
        }