Example #1
0
        /// <summary>
        ///		空のテクスチャとそのシェーダーリソースビューを作成し、返す。
        /// </summary>
        public static (SharpDX.Direct3D11.ShaderResourceView srv, SharpDX.Direct3D11.Texture2D texture) CreateShaderResourceView(
            SharpDX.Direct3D11.Device d3dDevice,
            SharpDX.Direct3D11.BindFlags bindFlags,
            Size2 サイズ)
        {
            var textureDesc = new SharpDX.Direct3D11.Texture2DDescription()
            {
                ArraySize         = 1,
                BindFlags         = bindFlags,
                CpuAccessFlags    = SharpDX.Direct3D11.CpuAccessFlags.None,
                Format            = SharpDX.DXGI.Format.B8G8R8A8_UNorm,
                Height            = サイズ.Height,
                Width             = サイズ.Width,
                MipLevels         = 1,
                OptionFlags       = SharpDX.Direct3D11.ResourceOptionFlags.None,
                SampleDescription = new SharpDX.DXGI.SampleDescription(1, 0),
                Usage             = SharpDX.Direct3D11.ResourceUsage.Default
            };

            var 出力 = (srv : (SharpDX.Direct3D11.ShaderResourceView)null, texture : (SharpDX.Direct3D11.Texture2D)null);

            出力.texture = new SharpDX.Direct3D11.Texture2D(d3dDevice, textureDesc);
            出力.srv     = new SharpDX.Direct3D11.ShaderResourceView(d3dDevice, 出力.texture);

            return(出力);
        }
Example #2
0
        // グラフィック

        /// <summary>
        ///		画像ファイルからシェーダリソースビューを作成して返す。
        /// </summary>
        /// <remarks>
        ///		(参考: http://qiita.com/oguna/items/c516e09ee57d931892b6 )
        /// </remarks>
        public static (SharpDX.Direct3D11.ShaderResourceView srv, Size2F viewSize, SharpDX.Direct3D11.Texture2D texture) CreateShaderResourceViewFromFile(
            SharpDX.Direct3D11.Device d3dDevice,
            SharpDX.Direct3D11.BindFlags bindFlags,
            VariablePath 画像ファイルパス)
        {
            var 出力 = (
                srv : (SharpDX.Direct3D11.ShaderResourceView)null,
                viewSize : new Size2F(0, 0),
                texture : (SharpDX.Direct3D11.Texture2D)null);

            using (var image = new System.Drawing.Bitmap(画像ファイルパス.数なしパス))
            {
                var 画像の矩形 = new System.Drawing.Rectangle(0, 0, image.Width, image.Height);

                using (var bitmap = image.Clone(画像の矩形, System.Drawing.Imaging.PixelFormat.Format32bppArgb))
                {
                    var ロック領域       = bitmap.LockBits(画像の矩形, System.Drawing.Imaging.ImageLockMode.ReadOnly, bitmap.PixelFormat);
                    var dataBox     = new[] { new DataBox(ロック領域.Scan0, bitmap.Width * 4, bitmap.Height) };
                    var textureDesc = new SharpDX.Direct3D11.Texture2DDescription()
                    {
                        ArraySize         = 1,
                        BindFlags         = bindFlags,
                        CpuAccessFlags    = SharpDX.Direct3D11.CpuAccessFlags.None,
                        Format            = SharpDX.DXGI.Format.B8G8R8A8_UNorm,
                        Height            = bitmap.Height,
                        Width             = bitmap.Width,
                        MipLevels         = 1,
                        OptionFlags       = SharpDX.Direct3D11.ResourceOptionFlags.None,
                        SampleDescription = new SharpDX.DXGI.SampleDescription(1, 0),
                        Usage             = SharpDX.Direct3D11.ResourceUsage.Default
                    };
                    var texture = new SharpDX.Direct3D11.Texture2D(d3dDevice, textureDesc, dataBox);
                    bitmap.UnlockBits(ロック領域);
                    出力.srv     = new SharpDX.Direct3D11.ShaderResourceView(d3dDevice, texture);
                    出力.texture = texture;
                }

                出力.viewSize = new Size2F(画像の矩形.Width, 画像の矩形.Height);
            }

            return(出力);
        }
Example #3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="device"></param>
        /// <param name="w"></param>
        /// <param name="h"></param>
        /// <param name="flags"></param>
        /// <param name="format"></param>
        /// <param name="options"></param>
        /// <returns></returns>
        public static SharpDX.Direct3D11.Texture2D CreateTexture2D(this SharpDX.Direct3D11.Device device,
                                                                   int w, int h,
                                                                   SharpDX.Direct3D11.BindFlags flags = SharpDX.Direct3D11.BindFlags.RenderTarget | SharpDX.Direct3D11.BindFlags.ShaderResource,
                                                                   Format format = Format.B8G8R8A8_UNorm,
                                                                   SharpDX.Direct3D11.ResourceOptionFlags options = SharpDX.Direct3D11.ResourceOptionFlags.Shared)
        {
            var colordesc = new SharpDX.Direct3D11.Texture2DDescription
            {
                BindFlags         = flags,
                Format            = format,
                Width             = w,
                Height            = h,
                MipLevels         = 1,
                SampleDescription = new SampleDescription(1, 0),
                Usage             = SharpDX.Direct3D11.ResourceUsage.Default,
                OptionFlags       = options,
                CpuAccessFlags    = SharpDX.Direct3D11.CpuAccessFlags.None,
                ArraySize         = 1
            };

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