예제 #1
0
		/// <summary>
		/// Creates texture
		/// </summary>
		/// <param name="device"></param>
		public VolumeRWTexture ( GraphicsDevice device, int width, int height, int depth, ColorFormat format, bool mips ) : base( device )
		{
			this.Width		=	width;
			this.Height		=	height;
			this.Depth		=	depth;
			this.format		=	format;
			this.mipCount	=	mips ? ShaderResource.CalculateMipLevels(Width,Height,Depth) : 1;

			var texDesc = new Texture3DDescription();
			texDesc.BindFlags		=	BindFlags.ShaderResource | BindFlags.UnorderedAccess;
			texDesc.CpuAccessFlags	=	CpuAccessFlags.None;
			texDesc.Format			=	Converter.Convert( format );
			texDesc.Height			=	Height;
			texDesc.MipLevels		=	mipCount;
			texDesc.OptionFlags		=	ResourceOptionFlags.None;
			texDesc.Usage			=	ResourceUsage.Default;
			texDesc.Width			=	Width;
			texDesc.Depth			=	Depth;

			var uavDesc = new UnorderedAccessViewDescription();
			uavDesc.Format		=	Converter.Convert( format );
			uavDesc.Dimension	=	UnorderedAccessViewDimension.Texture3D;
			uavDesc.Texture3D.FirstWSlice	=	0;
			uavDesc.Texture3D.MipSlice		=	0;
			uavDesc.Texture3D.WSize			=	depth;

			tex3D	=	new D3D.Texture3D( device.Device, texDesc );
			SRV		=	new D3D.ShaderResourceView( device.Device, tex3D );
			uav		=	new UnorderedAccessView( device.Device, tex3D, uavDesc );
		}
예제 #2
0
        public DX11RenderMip3D(DX11RenderContext context, int w, int h,int d, Format format) : base(context)
        {
            int levels = this.CountMipLevels(w,h,d);
            var texBufferDesc = new Texture3DDescription
            {
                BindFlags = BindFlags.RenderTarget | BindFlags.ShaderResource,
                CpuAccessFlags = CpuAccessFlags.None,
                Format = format,
                Height = h,
                Width = w,
                Depth = d,
                OptionFlags = ResourceOptionFlags.None,
                Usage = ResourceUsage.Default,
                MipLevels = levels,
            };

            this.Resource = new Texture3D(context.Device, texBufferDesc);
            this.Width = w;
            this.Height = h;
            this.Depth = d;

            this.SRV = new ShaderResourceView(context.Device, this.Resource);

            this.Slices = new DX11MipSliceRenderTarget[levels];

            int sw = w;
            int sh = h;
            int sd = d;

            for (int i = 0; i < levels; i++)
            {
                this.Slices[i] = new DX11MipSliceRenderTarget(this.context, this, i, w, h,d);
                w /= 2; h /= 2; d /= 2;
            }
        }
예제 #3
0
        public DX11RenderTexture3D(DX11RenderContext context, int w, int h, int d, Format format)
            : base(context)
        {
            Texture3DDescription desc = new Texture3DDescription()
            {
                BindFlags = BindFlags.UnorderedAccess | BindFlags.ShaderResource | BindFlags.RenderTarget,
                CpuAccessFlags = CpuAccessFlags.None,
                Depth = d,
                Format = format,
                Height = h,
                MipLevels = 1,
                OptionFlags = ResourceOptionFlags.None,
                Usage = ResourceUsage.Default,
                Width = w
            };

            RenderTargetViewDescription rtvd = new RenderTargetViewDescription();
            rtvd.Dimension = RenderTargetViewDimension.Texture3D;
            rtvd.MipSlice = 0;
            rtvd.FirstDepthSlice = 0;
            rtvd.DepthSliceCount = d;

            this.Resource = new Texture3D(context.Device, desc);
            this.SRV = new ShaderResourceView(context.Device, this.Resource);
            this.UAV = new UnorderedAccessView(context.Device, this.Resource);
            this.RTV = new RenderTargetView(context.Device, this.Resource, rtvd);

            this.Width = desc.Width;
            this.Height = desc.Height;
            this.Format = desc.Format;
            this.Depth = desc.Depth;
        }
예제 #4
0
        /// <summary>
        /// Creates texture
        /// </summary>
        /// <param name="device"></param>
        public Texture3D(GraphicsDevice device, int width, int height, int depth, ColorFormat format, bool mips, bool srgb = false) : base(device)
        {
            this.Width    = width;
            this.Height   = height;
            this.Depth    = depth;
            this.format   = format;
            this.mipCount = mips ? ShaderResource.CalculateMipLevels(Width, Height, Depth) : 1;

            var texDesc = new Texture3DDescription();

            texDesc.BindFlags      = BindFlags.ShaderResource;
            texDesc.CpuAccessFlags = CpuAccessFlags.None;
            texDesc.Format         = Converter.Convert(format);
            texDesc.Height         = Height;
            texDesc.MipLevels      = mipCount;
            texDesc.OptionFlags    = ResourceOptionFlags.None;
            texDesc.Usage          = ResourceUsage.Default;
            texDesc.Width          = Width;
            texDesc.Depth          = Depth;

            tex3D = new D3D.Texture3D(device.Device, texDesc);
            SRV   = new D3D.ShaderResourceView(device.Device, tex3D);
        }
예제 #5
0
        public ShaderResourceView ToTexture3D(Device graphicsDevice, Format format)
        {
            int sizeInBytes = sizeof(float) * width * height * depth;

            DataStream stream = new DataStream(sizeInBytes, true, true);

            for (int x = 0; x < width; x++)
            {
                for (int y = 0; y < height; y++)
                {
                    for (int z = 0; z < depth; z++)
                    {
                        stream.Write(values[x, y, z]);
                    }
                }
            }
            stream.Position = 0;

            DataBox dataBox = new DataBox(sizeof(float) * width, sizeof(float) * width * height, stream);
            Texture3DDescription description = new Texture3DDescription()
            {
                BindFlags      = BindFlags.ShaderResource,
                CpuAccessFlags = CpuAccessFlags.None,
                Depth          = depth,
                Format         = format,
                Height         = height,
                MipLevels      = 1,
                OptionFlags    = ResourceOptionFlags.None,
                Usage          = ResourceUsage.Default,
                Width          = width
            };
            Texture3D texture = new Texture3D(graphicsDevice, description, dataBox);

            stream.Dispose();

            return(new ShaderResourceView(graphicsDevice, texture));
        }
예제 #6
0
        public D3D11Texture(Device device, ref TextureDescription description)
        {
            _device     = device;
            Width       = description.Width;
            Height      = description.Height;
            Depth       = description.Depth;
            MipLevels   = description.MipLevels;
            ArrayLayers = description.ArrayLayers;
            Format      = description.Format;
            Usage       = description.Usage;
            Type        = description.Type;
            SampleCount = description.SampleCount;

            DxgiFormat = D3D11Formats.ToDxgiFormat(
                description.Format,
                (description.Usage & TextureUsage.DepthStencil) == TextureUsage.DepthStencil);

            CpuAccessFlags      cpuFlags      = CpuAccessFlags.None;
            ResourceUsage       resourceUsage = ResourceUsage.Default;
            BindFlags           bindFlags     = BindFlags.None;
            ResourceOptionFlags optionFlags   = ResourceOptionFlags.None;

            if ((description.Usage & TextureUsage.RenderTarget) == TextureUsage.RenderTarget)
            {
                bindFlags |= BindFlags.RenderTarget;
            }
            if ((description.Usage & TextureUsage.DepthStencil) == TextureUsage.DepthStencil)
            {
                bindFlags |= BindFlags.DepthStencil;
            }
            if ((description.Usage & TextureUsage.Sampled) == TextureUsage.Sampled)
            {
                bindFlags |= BindFlags.ShaderResource;
            }
            if ((description.Usage & TextureUsage.Storage) == TextureUsage.Storage)
            {
                bindFlags |= BindFlags.UnorderedAccess;
            }
            if ((description.Usage & TextureUsage.Staging) == TextureUsage.Staging)
            {
                cpuFlags      = CpuAccessFlags.Read | CpuAccessFlags.Write;
                resourceUsage = ResourceUsage.Staging;
            }

            if ((description.Usage & TextureUsage.GenerateMipmaps) != 0)
            {
                bindFlags   |= BindFlags.RenderTarget | BindFlags.ShaderResource;
                optionFlags |= ResourceOptionFlags.GenerateMipMaps;
            }

            int arraySize = (int)description.ArrayLayers;

            if ((description.Usage & TextureUsage.Cubemap) == TextureUsage.Cubemap)
            {
                optionFlags = ResourceOptionFlags.TextureCube;
                arraySize  *= 6;
            }

            if (Type == TextureType.Texture1D)
            {
                Texture1DDescription desc1D = new Texture1DDescription()
                {
                    Width          = (int)description.Width,
                    MipLevels      = (int)description.MipLevels,
                    ArraySize      = arraySize,
                    Format         = DxgiFormat,
                    BindFlags      = bindFlags,
                    CpuAccessFlags = cpuFlags,
                    Usage          = resourceUsage,
                    OptionFlags    = optionFlags,
                };

                DeviceTexture = new Texture1D(device, desc1D);
            }
            else if (Type == TextureType.Texture2D)
            {
                Texture2DDescription deviceDescription = new Texture2DDescription()
                {
                    Width             = (int)description.Width,
                    Height            = (int)description.Height,
                    MipLevels         = (int)description.MipLevels,
                    ArraySize         = arraySize,
                    Format            = DxgiFormat,
                    BindFlags         = bindFlags,
                    CpuAccessFlags    = cpuFlags,
                    Usage             = resourceUsage,
                    SampleDescription = new SharpDX.DXGI.SampleDescription((int)FormatHelpers.GetSampleCountUInt32(SampleCount), 0),
                    OptionFlags       = optionFlags,
                };

                DeviceTexture = new Texture2D(device, deviceDescription);
            }
            else
            {
                Debug.Assert(Type == TextureType.Texture3D);
                Texture3DDescription desc3D = new Texture3DDescription()
                {
                    Width          = (int)description.Width,
                    Height         = (int)description.Height,
                    Depth          = (int)description.Depth,
                    MipLevels      = (int)description.MipLevels,
                    Format         = DxgiFormat,
                    BindFlags      = bindFlags,
                    CpuAccessFlags = cpuFlags,
                    Usage          = resourceUsage,
                    OptionFlags    = optionFlags,
                };

                DeviceTexture = new Texture3D(device, desc3D);
            }
        }
예제 #7
0
        protected Texture3D(GraphicsDevice graphicsDevice, int width, int height, int depth, bool mipMap, SurfaceFormat format, bool renderTarget)
        {
            if (graphicsDevice == null)
            {
                throw new ArgumentNullException("graphicsDevice");
            }

            this.GraphicsDevice = graphicsDevice;
            this.width          = width;
            this.height         = height;
            this.depth          = depth;
            this._levelCount    = 1;
            this._format        = format;

#if OPENGL
            this.glTarget = TextureTarget.Texture3D;

            GL.GenTextures(1, out this.glTexture);
            GraphicsExtensions.CheckGLError();

            GL.BindTexture(glTarget, glTexture);
            GraphicsExtensions.CheckGLError();

            format.GetGLFormat(out glInternalFormat, out glFormat, out glType);

            GL.TexImage3D(glTarget, 0, glInternalFormat, width, height, depth, 0, glFormat, glType, IntPtr.Zero);
            GraphicsExtensions.CheckGLError();

            if (mipMap)
            {
                throw new NotImplementedException("Texture3D does not yet support mipmaps.");
            }
#elif DIRECTX
            if (mipMap)
            {
                this._levelCount = CalculateMipLevels(width, height, depth);
            }

            var description = new Texture3DDescription
            {
                Width          = width,
                Height         = height,
                Depth          = depth,
                MipLevels      = _levelCount,
                Format         = SharpDXHelper.ToFormat(format),
                BindFlags      = BindFlags.ShaderResource,
                CpuAccessFlags = CpuAccessFlags.None,
                Usage          = ResourceUsage.Default,
                OptionFlags    = ResourceOptionFlags.None,
            };

            if (renderTarget)
            {
                description.BindFlags |= BindFlags.RenderTarget;
                if (mipMap)
                {
                    // Note: XNA 4 does not have a method Texture.GenerateMipMaps()
                    // because generation of mipmaps is not supported on the Xbox 360.
                    // TODO: New method Texture.GenerateMipMaps() required.
                    description.OptionFlags |= ResourceOptionFlags.GenerateMipMaps;
                }
            }

            _texture = new SharpDX.Direct3D11.Texture3D(graphicsDevice._d3dDevice, description);
#endif
        }
예제 #8
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Texture3DBase" /> class.
 /// </summary>
 /// <param name="device">The <see cref="GraphicsDevice"/>.</param>
 /// <param name="description3D">The description.</param>
 /// <param name="dataRectangles">A variable-length parameters list containing data rectangles.</param>
 /// <msdn-id>ff476522</msdn-id>
 /// <unmanaged>HRESULT ID3D11Device::CreateTexture3D([In] const D3D11_TEXTURE3D_DESC* pDesc,[In, Buffer, Optional] const D3D11_SUBRESOURCE_DATA* pInitialData,[Out, Fast] ID3D11Texture3D** ppTexture3D)</unmanaged>
 /// <unmanaged-short>ID3D11Device::CreateTexture3D</unmanaged-short>
 protected internal Texture3DBase(GraphicsDevice device, Texture3DDescription description3D, DataBox[] dataRectangles)
     : base(device, description3D)
 {
     Resource = new Direct3D11.Texture3D(device, description3D, dataRectangles);
     Initialize(Resource);
 }
예제 #9
0
        public ShaderResourceView ToTexture3D(Device graphicsDevice, Format format)
        {
            int sizeInBytes = sizeof(float) * width * height * depth;

            DataStream stream = new DataStream(sizeInBytes, true, true);
            for (int x = 0; x < width; x++)
                for (int y = 0; y < height; y++)
                    for (int z = 0; z < depth; z++)
                        stream.Write(values[x, y, z]);
            stream.Position = 0;

            DataBox dataBox = new DataBox(sizeof(float) * width, sizeof(float) * width * height, stream);
            Texture3DDescription description = new Texture3DDescription()
            {
                BindFlags = BindFlags.ShaderResource,
                CpuAccessFlags = CpuAccessFlags.None,
                Depth = depth,
                Format = format,
                Height = height,
                MipLevels = 1,
                OptionFlags = ResourceOptionFlags.None,
                Usage = ResourceUsage.Default,
                Width = width
            };
            Texture3D texture = new Texture3D(graphicsDevice, description, dataBox);

            stream.Dispose();

            return new ShaderResourceView(graphicsDevice, texture);
        }
예제 #10
0
        public TextureD3D11(DeviceD3D11 device, ref TextureDescriptor descriptor)
            : base(device, ref descriptor)
        {
            // Create new one.
            DXGIFormat = descriptor.Format.ToDirectX();

            var cpuFlags      = CpuAccessFlags.None;
            var resourceUsage = Vortice.DirectX.Direct3D11.Usage.Default;
            var bindFlags     = descriptor.Usage.ToDirectX(descriptor.Format);
            var optionFlags   = ResourceOptionFlags.None;

            var arraySize = descriptor.ArrayLayers;

            if (descriptor.TextureType == TextureType.TextureCube)
            {
                arraySize  *= 6;
                optionFlags = ResourceOptionFlags.TextureCube;
            }

            switch (descriptor.TextureType)
            {
            case TextureType.Texture1D:
            {
                var d3dTextureDesc = new Texture1DDescription()
                {
                    Width          = descriptor.Width,
                    MipLevels      = descriptor.MipLevels,
                    ArraySize      = descriptor.ArrayLayers,
                    Format         = DXGIFormat,
                    BindFlags      = bindFlags,
                    CpuAccessFlags = cpuFlags,
                    Usage          = resourceUsage,
                    OptionFlags    = optionFlags,
                };

                Resource = device.D3D11Device.CreateTexture1D(d3dTextureDesc);
            }
            break;

            case TextureType.Texture2D:
            case TextureType.TextureCube:
            {
                var d3dTextureDesc = new Texture2DDescription()
                {
                    Width             = descriptor.Width,
                    Height            = descriptor.Height,
                    MipLevels         = descriptor.MipLevels,
                    ArraySize         = descriptor.ArrayLayers,
                    Format            = DXGIFormat,
                    BindFlags         = bindFlags,
                    CpuAccessFlags    = cpuFlags,
                    Usage             = resourceUsage,
                    SampleDescription = new SampleDescription((int)descriptor.Samples, 0),
                    OptionFlags       = optionFlags,
                };

                Resource = device.D3D11Device.CreateTexture2D(d3dTextureDesc);
            }
            break;

            case TextureType.Texture3D:
            {
                var d3dTextureDesc = new Texture3DDescription()
                {
                    Width          = descriptor.Width,
                    Height         = descriptor.Height,
                    Depth          = descriptor.Depth,
                    MipLevels      = descriptor.MipLevels,
                    Format         = DXGIFormat,
                    BindFlags      = bindFlags,
                    CpuAccessFlags = cpuFlags,
                    Usage          = resourceUsage,
                    OptionFlags    = optionFlags,
                };

                Resource = device.D3D11Device.CreateTexture3D(d3dTextureDesc);
            }
            break;
            }
        }
예제 #11
0
 public Texture3D CreateTexture3D(Texture3DDescription desc)
 {
     return(new Texture3D(_dx11Device, desc));
 }
예제 #12
0
        private static Result CreateD3DResources(Device d3dDevice,
                                                 ResourceDimension resourceDimension,
                                                 int width,
                                                 int height,
                                                 int depth,
                                                 int mipCount,
                                                 int arraySize,
                                                 DXGI.Format format,
                                                 ResourceUsage usage,
                                                 BindFlags bindFlags,
                                                 CpuAccessFlags cpuAccessFlags,
                                                 ResourceOptionFlags miscFlags,
                                                 bool forceSRGB,
                                                 bool isCubeMap,
                                                 DataBox[] initData,
                                                 out Resource texture,
                                                 out ShaderResourceView textureView)
        {
            texture     = null;
            textureView = null;
            if (d3dDevice == null)
            {
                return(Result.InvalidArg);
            }

            if (forceSRGB)
            {
                format = format.MakeSRgb();
            }

            ShaderResourceViewDescription SRVDesc = new ShaderResourceViewDescription {
                Format = format
            };

            switch (resourceDimension)
            {
            case ResourceDimension.Texture1D: {
                Texture1DDescription desc = new Texture1DDescription {
                    Width          = width,
                    MipLevels      = mipCount,
                    ArraySize      = arraySize,
                    Format         = format,
                    Usage          = usage,
                    BindFlags      = bindFlags,
                    CpuAccessFlags = cpuAccessFlags,
                    OptionFlags    = miscFlags & ~ResourceOptionFlags.TextureCube
                };

                Texture1D tex = new Texture1D(d3dDevice, desc, initData);

                if (tex != null)
                {
                    if (arraySize > 1)
                    {
                        SRVDesc.Dimension = ShaderResourceViewDimension.Texture1DArray;
                        SRVDesc.Texture1DArray.MipLevels = (mipCount == 0) ? -1 : desc.MipLevels;
                        SRVDesc.Texture1DArray.ArraySize = arraySize;
                    }
                    else
                    {
                        SRVDesc.Dimension           = ShaderResourceViewDimension.Texture1D;
                        SRVDesc.Texture1D.MipLevels = (mipCount == 0) ? -1 : desc.MipLevels;
                    }

                    textureView = new ShaderResourceView(d3dDevice, tex, SRVDesc);

                    if (textureView == null)
                    {
                        tex.Dispose();
                        texture = null;
                        return(Result.Fail);
                    }
                    texture = tex;
                }
                else
                {
                    return(Result.Fail);
                }
            }
            break;

            case ResourceDimension.Texture2D: {
                Texture2DDescription desc = new Texture2DDescription {
                    Width             = width,
                    Height            = height,
                    MipLevels         = mipCount,
                    ArraySize         = arraySize,
                    Format            = format,
                    SampleDescription = new SharpDX.DXGI.SampleDescription(1, 0),
                    Usage             = usage,
                    BindFlags         = bindFlags,
                    CpuAccessFlags    = cpuAccessFlags,
                };
                if (isCubeMap)
                {
                    desc.OptionFlags = miscFlags | ResourceOptionFlags.TextureCube;
                }
                else
                {
                    desc.OptionFlags = miscFlags & ~ResourceOptionFlags.TextureCube;
                }

                Texture2D tex = new Texture2D(d3dDevice, desc, initData);

                if (tex != null)
                {
                    if (isCubeMap)
                    {
                        if (arraySize > 6)
                        {
                            SRVDesc.Dimension = ShaderResourceViewDimension.TextureCubeArray;
                            SRVDesc.TextureCubeArray.MipLevels = (mipCount == 0) ? -1 : desc.MipLevels;
                            // Earlier we set arraySize to (NumCubes * 6)
                            SRVDesc.TextureCubeArray.CubeCount = arraySize / 6;
                        }
                        else
                        {
                            SRVDesc.Dimension             = ShaderResourceViewDimension.TextureCube;
                            SRVDesc.TextureCube.MipLevels = (mipCount == 0) ? -1 : desc.MipLevels;
                        }
                    }
                    else if (arraySize > 1)
                    {
                        SRVDesc.Dimension = ShaderResourceViewDimension.Texture2DArray;
                        SRVDesc.Texture2DArray.MipLevels = (mipCount == 0) ? -1 : desc.MipLevels;
                        SRVDesc.Texture2DArray.ArraySize = arraySize;
                    }
                    else
                    {
                        SRVDesc.Dimension           = ShaderResourceViewDimension.Texture2D;
                        SRVDesc.Texture2D.MipLevels = (mipCount == 0) ? -1 : desc.MipLevels;
                    }

                    textureView = new ShaderResourceView(d3dDevice, tex, SRVDesc);

                    if (textureView == null)
                    {
                        tex.Dispose();
                        texture = null;
                        return(Result.Fail);
                    }
                    texture = tex;
                }
                else
                {
                    return(Result.Fail);
                }
            }
            break;

            case ResourceDimension.Texture3D: {
                Texture3DDescription desc = new Texture3DDescription {
                    Width          = width,
                    Height         = height,
                    Depth          = depth,
                    MipLevels      = mipCount,
                    Format         = format,
                    Usage          = usage,
                    BindFlags      = bindFlags,
                    CpuAccessFlags = cpuAccessFlags,
                    OptionFlags    = miscFlags & ~ResourceOptionFlags.TextureCube
                };

                Texture3D tex = new Texture3D(d3dDevice, desc, initData);

                if (tex != null)
                {
                    SRVDesc.Dimension           = ShaderResourceViewDimension.Texture3D;
                    SRVDesc.Texture3D.MipLevels = (mipCount == 0) ? -1 : desc.MipLevels;

                    textureView = new ShaderResourceView(d3dDevice, tex, SRVDesc);

                    if (textureView == null)
                    {
                        tex.Dispose();
                        texture = null;
                        return(Result.Fail);
                    }
                    texture = tex;
                }
                else
                {
                    return(Result.Fail);
                }
            }
            break;
            }

            return(Result.Ok);
        }
예제 #13
0
        internal static RwTexId CreateUav3D(int width, int height, int depth, Format resourceFormat, string debugName = null)
        {
            var desc = new Texture3DDescription
            {
                BindFlags = BindFlags.ShaderResource | BindFlags.UnorderedAccess,
                CpuAccessFlags = CpuAccessFlags.None,
                Format = resourceFormat,
                MipLevels = 1,
                Usage = ResourceUsage.Default,
                Width = width,
                Height = height,
                Depth = depth
            };

            var handle = new RwTexId { Index = Textures.Allocate() };
            Textures.Data[handle.Index] = new MyRwTextureInfo { Description3D = desc };
            Textures.Data[handle.Index].Resource = new Texture3D(MyRender11.Device, desc);

            Srvs[handle] = new MySrvInfo { Description = null, View = new ShaderResourceView(MyRender11.Device, Textures.Data[handle.Index].Resource) };
            Uavs[handle] = new MyUavInfo { Description = null, View = new UnorderedAccessView(MyRender11.Device, Textures.Data[handle.Index].Resource) };
            Index.Add(handle);

            return handle;
        }
예제 #14
0
        // Simple DDS loader ported from http://msdn.microsoft.com/en-us/library/windows/apps/jj651550.aspx
        static void CreateD3DResources(
            SharpDX.Direct3D11.Device d3dDevice,
            TextureDimension resDim,
            int width,
            int height,
            int depth,
            int mipCount,
            int arraySize,
            Format format,
            bool isCubeMap,
            DataBox[] initData,
            //_In_reads_(mipCount*arraySize) D3D11_SUBRESOURCE_DATA* initData,
            out SharpDX.Direct3D11.Resource texture,
            out SharpDX.Direct3D11.ShaderResourceView textureView
            //_Out_opt_ ID3D11Resource** texture,
            //_Out_opt_ ID3D11ShaderResourceView** textureView
            )
        {
            texture     = null;
            textureView = null;

            if (d3dDevice == null || initData == null)
            {
                return;
            }

            switch (resDim)
            {
            case TextureDimension.Texture1D:    // D3D11_RESOURCE_DIMENSION_TEXTURE1D:
            {
                Texture1DDescription desc = new Texture1DDescription();
                //D3D11_TEXTURE1D_DESC desc;
                desc.Width          = width;
                desc.MipLevels      = mipCount;
                desc.ArraySize      = arraySize;
                desc.Format         = format;
                desc.Usage          = ResourceUsage.Default;
                desc.BindFlags      = BindFlags.ShaderResource;   // D3D11_BIND_SHADER_RESOURCE;
                desc.CpuAccessFlags = CpuAccessFlags.None;
                desc.OptionFlags    = ResourceOptionFlags.None;

                Texture1D tex = null;
                //ID3D11Texture1D* tex = nullptr;
                tex = new Texture1D(d3dDevice, desc, initData);
                //hr = d3dDevice->CreateTexture1D(&desc, initData, &tex);

                if (tex != null)
                {
                    ShaderResourceViewDescription SRVDesc = new ShaderResourceViewDescription();
                    //D3D11_SHADER_RESOURCE_VIEW_DESC SRVDesc;
                    //memset(&SRVDesc, 0, sizeof(SRVDesc));
                    SRVDesc.Format = format;

                    if (arraySize > 1)
                    {
                        SRVDesc.Dimension = SharpDX.Direct3D.ShaderResourceViewDimension.Texture1DArray;        // D3D_SRV_DIMENSION_TEXTURE1DARRAY;
                        SRVDesc.Texture1DArray.MipLevels = desc.MipLevels;
                        SRVDesc.Texture1DArray.ArraySize = arraySize;
                    }
                    else
                    {
                        SRVDesc.Dimension           = SharpDX.Direct3D.ShaderResourceViewDimension.Texture1D;// D3D_SRV_DIMENSION_TEXTURE1D;
                        SRVDesc.Texture1D.MipLevels = desc.MipLevels;
                    }

                    textureView = new ShaderResourceView(d3dDevice, tex, SRVDesc);
                    //hr = d3dDevice->CreateShaderResourceView(tex, &SRVDesc, textureView);

                    if (textureView == null)
                    {
                        tex.Dispose();
                        return;
                    }

                    texture = tex;
                }
            }
            break;

            case TextureDimension.TextureCube:
            case TextureDimension.Texture2D:    // D3D11_RESOURCE_DIMENSION_TEXTURE2D:
            {
                Texture2DDescription desc = new Texture2DDescription();
                desc.Width     = width;
                desc.Height    = height;
                desc.MipLevels = mipCount;
                desc.ArraySize = arraySize;
                desc.Format    = format;
                desc.SampleDescription.Count   = 1;
                desc.SampleDescription.Quality = 0;
                desc.Usage          = ResourceUsage.Default;
                desc.BindFlags      = BindFlags.ShaderResource;
                desc.CpuAccessFlags = CpuAccessFlags.None;
                desc.OptionFlags    = (isCubeMap) ? ResourceOptionFlags.TextureCube : ResourceOptionFlags.None;

                Texture2D tex = null;
                tex           = new Texture2D(d3dDevice, desc, initData);
                tex.DebugName = "Test";
                //hr = d3dDevice->CreateTexture2D(&desc, initData, &tex);

                if (tex != null)
                {
                    ShaderResourceViewDescription SRVDesc = new ShaderResourceViewDescription();
                    SRVDesc.Format = format;

                    if (isCubeMap)
                    {
                        if (arraySize > 6)
                        {
                            SRVDesc.Dimension = SharpDX.Direct3D.ShaderResourceViewDimension.TextureCubeArray;
                            SRVDesc.TextureCubeArray.MipLevels = desc.MipLevels;

                            // Earlier we set arraySize to (NumCubes * 6)
                            SRVDesc.TextureCubeArray.CubeCount = arraySize / 6;
                        }
                        else
                        {
                            SRVDesc.Dimension             = SharpDX.Direct3D.ShaderResourceViewDimension.TextureCube;
                            SRVDesc.TextureCube.MipLevels = desc.MipLevels;
                        }
                    }
                    else if (arraySize > 1)
                    {
                        SRVDesc.Dimension = SharpDX.Direct3D.ShaderResourceViewDimension.Texture2DArray;
                        SRVDesc.Texture2DArray.MipLevels = desc.MipLevels;
                        SRVDesc.Texture2DArray.ArraySize = arraySize;
                    }
                    else
                    {
                        SRVDesc.Dimension           = SharpDX.Direct3D.ShaderResourceViewDimension.Texture2D;
                        SRVDesc.Texture2D.MipLevels = desc.MipLevels;
                    }

                    textureView = new ShaderResourceView(d3dDevice, tex, SRVDesc);
                    //hr = d3dDevice->CreateShaderResourceView(tex, &SRVDesc, textureView);

                    texture = tex;
                }
            }
            break;

            case TextureDimension.Texture3D:
            {
                Texture3DDescription desc = new Texture3DDescription();
                desc.Width          = width;
                desc.Height         = height;
                desc.Depth          = depth;
                desc.MipLevels      = mipCount;
                desc.Format         = format;
                desc.Usage          = ResourceUsage.Default;
                desc.BindFlags      = BindFlags.ShaderResource;
                desc.CpuAccessFlags = CpuAccessFlags.None;
                desc.OptionFlags    = ResourceOptionFlags.None;

                Texture3D tex = null;
                tex = new Texture3D(d3dDevice, desc, initData);
                //hr = d3dDevice->CreateTexture3D(&desc, initData, &tex);

                if (tex != null)
                {
                    ShaderResourceViewDescription SRVDesc = new ShaderResourceViewDescription();
                    SRVDesc.Format              = format;
                    SRVDesc.Dimension           = SharpDX.Direct3D.ShaderResourceViewDimension.Texture3D;
                    SRVDesc.Texture3D.MipLevels = desc.MipLevels;

                    textureView = new ShaderResourceView(d3dDevice, tex, SRVDesc);
                    texture     = tex;
                }
            }
            break;
            }
        }
예제 #15
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Texture3DBase" /> class.
 /// </summary>
 /// <param name="device">The <see cref="DirectXDevice"/>.</param>
 /// <param name="description3D">The description.</param>
 /// <param name="dataRectangles">A variable-length parameters list containing data rectangles.</param>
 /// <msdn-id>ff476522</msdn-id>
 /// <unmanaged>HRESULT ID3D11Device::CreateTexture3D([In] const D3D11_TEXTURE3D_DESC* pDesc,[In, Buffer, Optional] const D3D11_SUBRESOURCE_DATA* pInitialData,[Out, Fast] ID3D11Texture3D** ppTexture3D)</unmanaged>
 /// <unmanaged-short>ID3D11Device::CreateTexture3D</unmanaged-short>
 protected internal Texture3DBase(DirectXDevice device, Texture3DDescription description3D, DataBox[] dataRectangles)
     : base(device, description3D)
 {
     Resource = new SharpDX.Direct3D11.Texture3D(device, description3D, dataRectangles);
 }
예제 #16
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Texture3DBase" /> class.
 /// </summary>
 /// <param name="device">The <see cref="DirectXDevice"/>.</param>
 /// <param name="description3D">The description.</param>
 /// <msdn-id>ff476522</msdn-id>
 /// <unmanaged>HRESULT ID3D11Device::CreateTexture3D([In] const D3D11_TEXTURE3D_DESC* pDesc,[In, Buffer, Optional] const D3D11_SUBRESOURCE_DATA* pInitialData,[Out, Fast] ID3D11Texture3D** ppTexture3D)</unmanaged>
 /// <unmanaged-short>ID3D11Device::CreateTexture3D</unmanaged-short>
 protected internal Texture3DBase(DirectXDevice device, Texture3DDescription description3D)
     : base(device, description3D)
 {
     Resource = new SharpDX.Direct3D11.Texture3D(device, description3D);
 }
예제 #17
0
 private static void GetPitch(Texture3DDescription descriptor, int mipLevel, out int rowPitch, out int depthPitch)
 {
     rowPitch = GetRowPitch(descriptor.Format, descriptor.Width, mipLevel);
     depthPitch = rowPitch * 6;
 }
예제 #18
0
파일: Texture3D.cs 프로젝트: Nezz/SharpDX
 /// <summary>
 ///   Initializes a new instance of the <see cref = "T:SharpDX.Direct3D11.Texture3D" /> class.
 /// </summary>
 /// <param name = "device">The device with which to associate the texture.</param>
 /// <param name = "description">The description of the texture.</param>
 public Texture3D(Device device, Texture3DDescription description)
     : base(IntPtr.Zero)
 {
     device.CreateTexture3D(ref description, null, this);
 }
예제 #19
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Texture3DBase" /> class.
 /// </summary>
 /// <param name="device">The <see cref="Direct3D11.Device"/>.</param>
 /// <param name="description3D">The description.</param>
 /// <msdn-id>ff476522</msdn-id>
 /// <unmanaged>HRESULT ID3D11Device::CreateTexture3D([In] const D3D11_TEXTURE3D_DESC* pDesc,[In, Buffer, Optional] const D3D11_SUBRESOURCE_DATA* pInitialData,[Out, Fast] ID3D11Texture3D** ppTexture3D)</unmanaged>
 /// <unmanaged-short>ID3D11Device::CreateTexture3D</unmanaged-short>
 protected internal Texture3DBase(Direct3D11.Device device, Texture3DDescription description3D)
     : base(device, description3D)
 {
     Resource = new Direct3D11.Texture3D(device, description3D);
     Initialize(Resource);
 }
        // Simple DDS loader ported from http://msdn.microsoft.com/en-us/library/windows/apps/jj651550.aspx
        static void CreateD3DResources(
            SharpDX.Direct3D11.Device d3dDevice,
            TextureDimension resDim,
            int width,
            int height,
            int depth,
            int mipCount,
            int arraySize,
            Format format,
            bool isCubeMap,
            DataBox[] initData,
            //_In_reads_(mipCount*arraySize) D3D11_SUBRESOURCE_DATA* initData,
            out SharpDX.Direct3D11.Resource texture,
            out SharpDX.Direct3D11.ShaderResourceView textureView
            //_Out_opt_ ID3D11Resource** texture,
            //_Out_opt_ ID3D11ShaderResourceView** textureView
            )
        {
            texture = null;
            textureView = null;

            if (d3dDevice == null || initData == null)
            {
                return;
            }

            switch (resDim)
            {
                case TextureDimension.Texture1D:// D3D11_RESOURCE_DIMENSION_TEXTURE1D:
                    {
                        Texture1DDescription desc = new Texture1DDescription();
                        //D3D11_TEXTURE1D_DESC desc;
                        desc.Width = width;
                        desc.MipLevels = mipCount;
                        desc.ArraySize = arraySize;
                        desc.Format = format;
                        desc.Usage = ResourceUsage.Default;
                        desc.BindFlags = BindFlags.ShaderResource;// D3D11_BIND_SHADER_RESOURCE;
                        desc.CpuAccessFlags = CpuAccessFlags.None;
                        desc.OptionFlags = ResourceOptionFlags.None;

                        Texture1D tex = null;
                        //ID3D11Texture1D* tex = nullptr;
                        tex = new Texture1D(d3dDevice, desc, initData);
                        //hr = d3dDevice->CreateTexture1D(&desc, initData, &tex);

                        if (tex != null)
                        {
                            ShaderResourceViewDescription SRVDesc = new ShaderResourceViewDescription();
                            //D3D11_SHADER_RESOURCE_VIEW_DESC SRVDesc;
                            //memset(&SRVDesc, 0, sizeof(SRVDesc));
                            SRVDesc.Format = format;

                            if (arraySize > 1)
                            {
                                SRVDesc.Dimension = SharpDX.Direct3D.ShaderResourceViewDimension.Texture1DArray;// D3D_SRV_DIMENSION_TEXTURE1DARRAY;
                                SRVDesc.Texture1DArray.MipLevels = desc.MipLevels;
                                SRVDesc.Texture1DArray.ArraySize = arraySize;
                            }
                            else
                            {
                                SRVDesc.Dimension = SharpDX.Direct3D.ShaderResourceViewDimension.Texture1D;// D3D_SRV_DIMENSION_TEXTURE1D;
                                SRVDesc.Texture1D.MipLevels = desc.MipLevels;
                            }

                            textureView = new ShaderResourceView(d3dDevice, tex, SRVDesc);
                            //hr = d3dDevice->CreateShaderResourceView(tex, &SRVDesc, textureView);

                            if (textureView == null)
                            {
                                tex.Dispose();
                                return;
                            }

                            texture = tex;
                        }
                    }
                    break;

                case TextureDimension.TextureCube:
                case TextureDimension.Texture2D:// D3D11_RESOURCE_DIMENSION_TEXTURE2D:
                    {
                        Texture2DDescription desc = new Texture2DDescription();
                        desc.Width = width;
                        desc.Height = height;
                        desc.MipLevels = mipCount;
                        desc.ArraySize = arraySize;
                        desc.Format = format;
                        desc.SampleDescription.Count = 1;
                        desc.SampleDescription.Quality = 0;
                        desc.Usage = ResourceUsage.Default;
                        desc.BindFlags = BindFlags.ShaderResource;
                        desc.CpuAccessFlags = CpuAccessFlags.None;
                        desc.OptionFlags = (isCubeMap) ? ResourceOptionFlags.TextureCube : ResourceOptionFlags.None;

                        Texture2D tex = null;
                        tex = new Texture2D(d3dDevice, desc, initData);
                        tex.DebugName = "Test";
                        //hr = d3dDevice->CreateTexture2D(&desc, initData, &tex);

                        if (tex != null)
                        {
                            ShaderResourceViewDescription SRVDesc = new ShaderResourceViewDescription();
                            SRVDesc.Format = format;

                            if (isCubeMap)
                            {
                                if (arraySize > 6)
                                {
                                    SRVDesc.Dimension = SharpDX.Direct3D.ShaderResourceViewDimension.TextureCubeArray;
                                    SRVDesc.TextureCubeArray.MipLevels = desc.MipLevels;

                                    // Earlier we set arraySize to (NumCubes * 6)
                                    SRVDesc.TextureCubeArray.CubeCount = arraySize / 6;
                                }
                                else
                                {
                                    SRVDesc.Dimension = SharpDX.Direct3D.ShaderResourceViewDimension.TextureCube;
                                    SRVDesc.TextureCube.MipLevels = desc.MipLevels;
                                }
                            }
                            else if (arraySize > 1)
                            {
                                SRVDesc.Dimension = SharpDX.Direct3D.ShaderResourceViewDimension.Texture2DArray;
                                SRVDesc.Texture2DArray.MipLevels = desc.MipLevels;
                                SRVDesc.Texture2DArray.ArraySize = arraySize;
                            }
                            else
                            {
                                SRVDesc.Dimension = SharpDX.Direct3D.ShaderResourceViewDimension.Texture2D;
                                SRVDesc.Texture2D.MipLevels = desc.MipLevels;
                            }

                            textureView = new ShaderResourceView(d3dDevice, tex, SRVDesc);
                            //hr = d3dDevice->CreateShaderResourceView(tex, &SRVDesc, textureView);

                            texture = tex;
                        }
                    }
                    break;

                case TextureDimension.Texture3D:
                    {
                        Texture3DDescription desc = new Texture3DDescription();
                        desc.Width = width;
                        desc.Height = height;
                        desc.Depth = depth;
                        desc.MipLevels = mipCount;
                        desc.Format = format;
                        desc.Usage = ResourceUsage.Default;
                        desc.BindFlags = BindFlags.ShaderResource;
                        desc.CpuAccessFlags = CpuAccessFlags.None;
                        desc.OptionFlags = ResourceOptionFlags.None;

                        Texture3D tex = null;
                        tex = new Texture3D(d3dDevice, desc, initData);
                        //hr = d3dDevice->CreateTexture3D(&desc, initData, &tex);

                        if (tex != null)
                        {
                            ShaderResourceViewDescription SRVDesc = new ShaderResourceViewDescription();
                            SRVDesc.Format = format;
                            SRVDesc.Dimension = SharpDX.Direct3D.ShaderResourceViewDimension.Texture3D;
                            SRVDesc.Texture3D.MipLevels = desc.MipLevels;

                            textureView = new ShaderResourceView(d3dDevice, tex, SRVDesc);
                            texture = tex;
                        }
                    }
                    break;
            }
        }
예제 #21
0
 internal RenderTarget3D(GraphicsDevice device, Texture3DDescription description3D)
     : base(device, description3D)
 {
 }
예제 #22
0
파일: Texture3D.cs 프로젝트: oeoen/SharpDX
 /// <summary>
 ///   Initializes a new instance of the <see cref = "T:SharpDX.Direct3D10.Texture3D" /> class.
 /// </summary>
 /// <param name = "device">The device with which to associate the texture.</param>
 /// <param name = "description">The description of the texture.</param>
 /// <param name = "data">An array of initial texture data for each subresource.</param>
 public Texture3D(Device device, Texture3DDescription description, DataBox[] data) : base(IntPtr.Zero)
 {
     device.CreateTexture3D(ref description, data, this);
 }
예제 #23
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ShaderResourceViewProxy"/> class.
 /// </summary>
 /// <param name="device">The device.</param>
 /// <param name="textureDesc">The texture desc.</param>
 public ShaderResourceViewProxy(Device device, Texture3DDescription textureDesc) : this(device)
 {
     resource      = new Texture3D(device, textureDesc);
     TextureFormat = textureDesc.Format;
 }
예제 #24
0
 /// <summary>
 /// Creates a new <see cref="RenderTarget3D"/> from a <see cref="Texture3DDescription"/>.
 /// </summary>
 /// <param name="device">The <see cref="GraphicsDevice"/>.</param>
 /// <param name="description">The description.</param>
 /// <returns>
 /// A new instance of <see cref="RenderTarget3D"/> class.
 /// </returns>
 /// <msdn-id>ff476521</msdn-id>	
 /// <unmanaged>HRESULT ID3D11Device::CreateTexture3D([In] const D3D11_TEXTURE3D_DESC* pDesc,[In, Buffer, Optional] const D3D11_SUBRESOURCE_DATA* pInitialData,[Out, Fast] ID3D11Texture3D** ppTexture3D)</unmanaged>	
 /// <unmanaged-short>ID3D11Device::CreateTexture3D</unmanaged-short>	
 public static RenderTarget3D New(GraphicsDevice device, Texture3DDescription description)
 {
     return new RenderTarget3D(device, description);
 }
예제 #25
0
 internal Texture3D(GraphicsDevice device, Texture3DDescription description3D, params DataBox[] dataBox)
     : base(device, description3D, dataBox)
 {
 }
예제 #26
0
 internal RenderTarget3D(DirectXDevice device, Texture3DDescription description3D)
     : base(device, description3D)
 {
 }
예제 #27
0
 /// <summary>
 /// Creates a new <see cref="RenderTarget3D"/> from a <see cref="Texture3DDescription"/>.
 /// </summary>
 /// <param name="device">The <see cref="GraphicsDevice"/>.</param>
 /// <param name="description">The description.</param>
 /// <returns>
 /// A new instance of <see cref="RenderTarget3D"/> class.
 /// </returns>
 /// <msdn-id>ff476521</msdn-id>
 /// <unmanaged>HRESULT ID3D11Device::CreateTexture3D([In] const D3D11_TEXTURE3D_DESC* pDesc,[In, Buffer, Optional] const D3D11_SUBRESOURCE_DATA* pInitialData,[Out, Fast] ID3D11Texture3D** ppTexture3D)</unmanaged>
 /// <unmanaged-short>ID3D11Device::CreateTexture3D</unmanaged-short>
 public static RenderTarget3D New(GraphicsDevice device, Texture3DDescription description)
 {
     return(new RenderTarget3D(device, description));
 }
예제 #28
0
 /// <summary>
 /// Creates a new texture from a <see cref="Texture3DDescription"/>.
 /// </summary>
 /// <param name="device">The <see cref="GraphicsDevice"/>.</param>
 /// <param name="description">The description.</param>
 /// <returns>
 /// A new instance of <see cref="Texture3D"/> class.
 /// </returns>
 /// <msdn-id>ff476522</msdn-id>
 /// <unmanaged>HRESULT ID3D11Device::CreateTexture3D([In] const D3D11_TEXTURE3D_DESC* pDesc,[In, Buffer, Optional] const D3D11_SUBRESOURCE_DATA* pInitialData,[Out, Fast] ID3D11Texture3D** ppTexture3D)</unmanaged>
 /// <unmanaged-short>ID3D11Device::CreateTexture3D</unmanaged-short>
 public static Texture3D New(GraphicsDevice device, Texture3DDescription description)
 {
     return(new Texture3D(device, description));
 }
예제 #29
0
 /// <summary>
 /// Creates a new texture from a <see cref="Texture3DDescription"/>.
 /// </summary>
 /// <param name="device">The <see cref="DirectXDevice"/>.</param>
 /// <param name="description">The description.</param>
 /// <returns>
 /// A new instance of <see cref="Texture3D"/> class.
 /// </returns>
 /// <msdn-id>ff476522</msdn-id>
 /// <unmanaged>HRESULT ID3D11Device::CreateTexture3D([In] const D3D11_TEXTURE3D_DESC* pDesc,[In, Buffer, Optional] const D3D11_SUBRESOURCE_DATA* pInitialData,[Out, Fast] ID3D11Texture3D** ppTexture3D)</unmanaged>
 /// <unmanaged-short>ID3D11Device::CreateTexture3D</unmanaged-short>
 public static Texture3D New(DirectXDevice device, Texture3DDescription description)
 {
     return(new Texture3D(device, description));
 }
예제 #30
0
 /// <summary>Initializes a new instance of the <see cref="Texture3DBase" /> class.</summary>
 /// <param name="device">The <see cref="GraphicsDevice" />.</param>
 /// <param name="description3D">The description.</param>
 /// <msdn-id>ff476522</msdn-id>
 ///   <unmanaged>HRESULT ID3D11Device::CreateTexture3D([In] const D3D11_TEXTURE3D_DESC* pDesc,[In, Buffer, Optional] const D3D11_SUBRESOURCE_DATA* pInitialData,[Out, Fast] ID3D11Texture3D** ppTexture3D)</unmanaged>
 ///   <unmanaged-short>ID3D11Device::CreateTexture3D</unmanaged-short>
 internal RenderTarget3D(GraphicsDevice device, Texture3DDescription description3D)
     : base(device, description3D)
 {
 }
예제 #31
0
            /// <summary>
            /// Generates the mip maps.
            /// </summary>
            /// <param name="device">The device.</param>
            /// <param name="texture">The texture.</param>
            /// <param name="textMip">Returns a new texture with mipmaps if succeeded. Otherwise returns the input texture</param>
            /// <returns>True succeed. False: Format not supported.</returns>
            /// <exception cref="InvalidDataException">Input texture is invalid.</exception>
            public static bool GenerateMipMaps(Device device, global::SharpDX.Toolkit.Graphics.Texture texture, out Resource textMip)
            {
                textMip = null;
                //Check texture format support: https://msdn.microsoft.com/en-us/library/windows/desktop/ff476426(v=vs.85).aspx
                switch (texture.Description.Format)
                {
                case global::SharpDX.DXGI.Format.R8G8B8A8_UNorm:
                case global::SharpDX.DXGI.Format.R8G8B8A8_UNorm_SRgb:
                case global::SharpDX.DXGI.Format.B5G6R5_UNorm:
                case global::SharpDX.DXGI.Format.B8G8R8A8_UNorm:
                case global::SharpDX.DXGI.Format.B8G8R8A8_UNorm_SRgb:
                case global::SharpDX.DXGI.Format.B8G8R8X8_UNorm:
                case global::SharpDX.DXGI.Format.B8G8R8X8_UNorm_SRgb:
                case global::SharpDX.DXGI.Format.R16G16B16A16_Float:
                case global::SharpDX.DXGI.Format.R16G16B16A16_UNorm:
                case global::SharpDX.DXGI.Format.R16G16_Float:
                case global::SharpDX.DXGI.Format.R16G16_UNorm:
                case global::SharpDX.DXGI.Format.R32_Float:
                case global::SharpDX.DXGI.Format.R32G32B32A32_Float:
                case global::SharpDX.DXGI.Format.B4G4R4A4_UNorm:
                case global::SharpDX.DXGI.Format.R32G32B32_Float:
                case global::SharpDX.DXGI.Format.R16G16B16A16_SNorm:
                case global::SharpDX.DXGI.Format.R32G32_Float:
                case global::SharpDX.DXGI.Format.R10G10B10A2_UNorm:
                case global::SharpDX.DXGI.Format.R11G11B10_Float:
                case global::SharpDX.DXGI.Format.R8G8B8A8_SNorm:
                case global::SharpDX.DXGI.Format.R16G16_SNorm:
                case global::SharpDX.DXGI.Format.R8G8_UNorm:
                case global::SharpDX.DXGI.Format.R8G8_SNorm:
                case global::SharpDX.DXGI.Format.R16_Float:
                case global::SharpDX.DXGI.Format.R16_UNorm:
                case global::SharpDX.DXGI.Format.R16_SNorm:
                case global::SharpDX.DXGI.Format.R8_UNorm:
                case global::SharpDX.DXGI.Format.R8_SNorm:
                case global::SharpDX.DXGI.Format.A8_UNorm:
                case global::SharpDX.DXGI.Format.B5G5R5A1_UNorm:
                    break;

                default:
                    textMip = texture.Resource.QueryInterface <Resource>();   //Format not support, return the original texture.
                    return(false);
                }
                switch (texture.Description.Dimension)
                {
                case global::SharpDX.Toolkit.Graphics.TextureDimension.Texture1D:
                    var desc1D = new Texture1DDescription()
                    {
                        Width          = texture.Description.Width,
                        MipLevels      = 0,
                        ArraySize      = 1,
                        BindFlags      = BindFlags.RenderTarget | BindFlags.ShaderResource,
                        CpuAccessFlags = CpuAccessFlags.None,
                        Usage          = ResourceUsage.Default,
                        OptionFlags    = ResourceOptionFlags.GenerateMipMaps,
                        Format         = texture.Description.Format
                    };
                    textMip = new Texture1D(device, desc1D);
                    break;

                case global::SharpDX.Toolkit.Graphics.TextureDimension.Texture2D:
                    var desc2D = new Texture2DDescription()
                    {
                        Width             = texture.Description.Width,
                        Height            = texture.Description.Height,
                        MipLevels         = 0,
                        ArraySize         = 1,
                        BindFlags         = BindFlags.RenderTarget | BindFlags.ShaderResource,
                        CpuAccessFlags    = CpuAccessFlags.None,
                        Usage             = ResourceUsage.Default,
                        SampleDescription = texture.Description.SampleDescription,
                        OptionFlags       = ResourceOptionFlags.GenerateMipMaps,
                        Format            = texture.Description.Format
                    };
                    textMip = new Texture2D(device, desc2D);
                    break;

                case global::SharpDX.Toolkit.Graphics.TextureDimension.Texture3D:
                    var desc3D = new Texture3DDescription()
                    {
                        Width          = texture.Description.Width,
                        Height         = texture.Description.Height,
                        Depth          = texture.Description.Depth,
                        MipLevels      = 0,
                        BindFlags      = BindFlags.RenderTarget | BindFlags.ShaderResource,
                        CpuAccessFlags = CpuAccessFlags.None,
                        Usage          = ResourceUsage.Default,
                        OptionFlags    = ResourceOptionFlags.GenerateMipMaps,
                        Format         = texture.Description.Format
                    };
                    textMip = new Texture3D(device, desc3D);
                    break;

                case global::SharpDX.Toolkit.Graphics.TextureDimension.TextureCube:
                    var descCube = new Texture3DDescription()
                    {
                        Width          = texture.Description.Width,
                        Height         = texture.Description.Height,
                        Depth          = texture.Description.ArraySize,
                        MipLevels      = 0,
                        BindFlags      = BindFlags.RenderTarget | BindFlags.ShaderResource,
                        CpuAccessFlags = CpuAccessFlags.None,
                        Usage          = ResourceUsage.Default,
                        OptionFlags    = ResourceOptionFlags.GenerateMipMaps,
                        Format         = texture.Description.Format
                    };
                    textMip = new Texture3D(device, descCube);
                    break;

                default:
                    throw new InvalidDataException("Input texture is invalid.");
                }

                using (var shaderRes = new ShaderResourceView(device, textMip))
                {
                    device.ImmediateContext.CopySubresourceRegion(texture, 0, null, textMip, 0);
                    device.ImmediateContext.GenerateMips(shaderRes);
                }
                return(true);
            }
예제 #32
0
        protected static Texture3DDescription NewDescription(int width, int height, int depth, PixelFormat format, TextureFlags textureFlags, int mipCount, ResourceUsage usage)
        {
            if ((textureFlags & TextureFlags.UnorderedAccess) != 0)
                usage = ResourceUsage.Default;
            
            var desc = new Texture3DDescription()
                           {
                               Width = width,
                               Height = height,
                               Depth = depth,
                               BindFlags = GetBindFlagsFromTextureFlags(textureFlags),
                               Format = format,
                               MipLevels = CalculateMipMapCount(mipCount, width, height, depth),
                               Usage = usage,
                               CpuAccessFlags = GetCpuAccessFlagsFromUsage(usage),
                               OptionFlags = ResourceOptionFlags.None
                           };

            // If the texture is a RenderTarget + ShaderResource + MipLevels > 1, then allow for GenerateMipMaps method
            if ((desc.BindFlags & BindFlags.RenderTarget) != 0 && (desc.BindFlags & BindFlags.ShaderResource) != 0 && desc.MipLevels > 1)
            {
                desc.OptionFlags |= ResourceOptionFlags.GenerateMipMaps;
            }

            return desc;
        }
예제 #33
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Texture3DBase" /> class.
 /// </summary>
 /// <param name="device">The <see cref="GraphicsDevice"/>.</param>
 /// <param name="description3D">The description.</param>
 /// <param name="dataRectangles">A variable-length parameters list containing data rectangles.</param>
 /// <msdn-id>ff476522</msdn-id>	
 /// <unmanaged>HRESULT ID3D11Device::CreateTexture3D([In] const D3D11_TEXTURE3D_DESC* pDesc,[In, Buffer, Optional] const D3D11_SUBRESOURCE_DATA* pInitialData,[Out, Fast] ID3D11Texture3D** ppTexture3D)</unmanaged>	
 /// <unmanaged-short>ID3D11Device::CreateTexture3D</unmanaged-short>	
 protected internal Texture3DBase(GraphicsDevice device, Texture3DDescription description3D, DataBox[] dataRectangles)
     : base(device, description3D)
 {
     Resource = new Direct3D11.Texture3D(device, description3D, dataRectangles);
     Initialize(Resource);
 }
예제 #34
0
 private Texture3DDescription ConvertToNativeDescription3D()
 {
     var desc = new Texture3DDescription()
     {
         Width = textureDescription.Width,
         Height = textureDescription.Height,
         Depth = textureDescription.Depth,
         BindFlags = GetBindFlagsFromTextureFlags(textureDescription.Flags),
         Format = (SharpDX.DXGI.Format)textureDescription.Format,
         MipLevels = textureDescription.MipLevels,
         Usage = (ResourceUsage)textureDescription.Usage,
         CpuAccessFlags = GetCpuAccessFlagsFromUsage(textureDescription.Usage),
         OptionFlags = ResourceOptionFlags.None
     };
     return desc;
 }
예제 #35
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ShaderResourceViewProxy"/> class.
 /// </summary>
 /// <param name="device">The device.</param>
 /// <param name="textureDesc">The texture desc.</param>
 public ShaderResourceViewProxy(Device device, Texture3DDescription textureDesc) : this(device)
 {
     resource = Collect(new Texture3D(device, textureDesc));
 }
예제 #36
0
        /// <summary>
        /// 3Dテクスチャの初期化
        /// </summary>
        /// <param name="desc"></param>
        public void Initialize3D(BufferDesc desc)
        {
            var device = GraphicsCore.D3D11Device;

            // 情報取得
            width_  = desc.width;
            height_ = desc.height;
            format_ = desc.format;
            mips_   = desc.mips;
            if (mips_ == 0)
            {
                mips_ = 1;
            }

            BindFlags bindFlags = BindFlags.ShaderResource;

            if (desc.IsRenderTarget)
            {
                bindFlags |= BindFlags.RenderTarget;
            }
            if (desc.IsUnorderedAccess)
            {
                bindFlags |= BindFlags.UnorderedAccess;
            }
            CpuAccessFlags acc_flag  = CpuAccessFlags.None;
            ResourceUsage  res_usage = ResourceUsage.Default;

            // 初期化データ
            DataBox databox = null;

            if (desc.initData != null)
            {
                int        size = desc.initData.Length * desc.initData[0].Length * desc.initData[0][0].Length;
                DataStream s    = new DataStream(size, true, true);
                foreach (var z in desc.initData)
                {
                    foreach (var y in z)
                    {
                        s.Write(y, 0, y.Length);
                    }
                }
                databox = new DataBox(desc.width, desc.width * desc.height, s);
            }
            if (desc.initStream != null)
            {
                int bpp = (int)desc.initStream.Length / (desc.width * desc.height * desc.depth);
                desc.initStream.Position = 0;
                databox = new DataBox(desc.width * bpp, desc.width * desc.height * bpp, desc.initStream);
            }

            // テクスチャオブジェクト
            Texture3DDescription textureDescription = new Texture3DDescription {
                BindFlags      = bindFlags,
                CpuAccessFlags = acc_flag,
                Format         = desc.format,
                Height         = desc.height,
                Width          = desc.width,
                Depth          = desc.depth,
                MipLevels      = mips_,
                OptionFlags    = desc.optionFlags,
                Usage          = res_usage
            };
            var texture3d = new Texture3D(device, textureDescription, databox);

            buffer_ = texture3d;

            // 初期データ解放
            if (databox != null)
            {
                databox.Data.Close();
            }

            Format srvFormat = desc.format;
            ShaderResourceViewDescription srvViewDesc = new ShaderResourceViewDescription {
                ArraySize       = 0,
                Format          = srvFormat,
                Dimension       = ShaderResourceViewDimension.Texture3D,
                Flags           = 0,
                FirstArraySlice = 0,
                MostDetailedMip = 0,
                MipLevels       = mips_
            };

            shaderResourceView_ = new ShaderResourceView(device, texture3d, srvViewDesc);

            // レンダーターゲットビュー
            if (desc.IsRenderTarget)
            {
                renderTargetView_ = new RenderTargetView(device, texture3d);
            }
            // UAV
            if (desc.IsUnorderedAccess)
            {
                unorderedAccessView_ = new UnorderedAccessView(device, texture3d);
            }
        }
예제 #37
0
파일: Device.cs 프로젝트: prepare/rasterizr
 public Texture3D CreateTexture3D(Texture3DDescription description)
 {
     DiagnosticUtilities.RaiseEvent(this, CreatingTexture3D, description);
     return(new Texture3D(this, description));
 }
예제 #38
0
        // Static functions
        static public TextureObject CreateTexture3D(Device device, int width, int height, int depth, Format format)
        {
            TextureObject newTexture = new TextureObject();

            // Variables
            newTexture.m_Width = width;
            newTexture.m_Height = height;
            newTexture.m_Depth = depth;
            newTexture.m_TexFormat = format;
            newTexture.m_Mips = 1;

            BindFlags bindFlags = BindFlags.ShaderResource | BindFlags.RenderTarget | BindFlags.UnorderedAccess;

            Texture3DDescription textureDescription = new Texture3DDescription
            {
                BindFlags = bindFlags,
                CpuAccessFlags = CpuAccessFlags.None,
                Format = format,
                Height = height,
                Width = width,
                Depth = depth,
                MipLevels = 1,
                OptionFlags = ResourceOptionFlags.None,
                Usage = ResourceUsage.Default
            };

            newTexture.m_TextureObject3D = new Texture3D(device, textureDescription);

            ShaderResourceViewDescription srvViewDesc = new ShaderResourceViewDescription
            {
                ArraySize = 0,
                Format = format,
                Dimension = ShaderResourceViewDimension.Texture3D,
                Flags = 0,
                FirstArraySlice = 0,
                MostDetailedMip = 0,
                MipLevels = 1,
            };

            newTexture.m_ShaderResourceView = new ShaderResourceView(device, newTexture.m_TextureObject3D, srvViewDesc);

            newTexture.m_RenderTargetView = new RenderTargetView(device, newTexture.m_TextureObject3D);
            newTexture.m_UnorderedAccessView = new UnorderedAccessView(device, newTexture.m_TextureObject3D);

            return newTexture;
        }
예제 #39
0
파일: Texture3D.cs 프로젝트: oeoen/SharpDX
 /// <summary>
 ///   Initializes a new instance of the <see cref = "T:SharpDX.Direct3D10.Texture3D" /> class.
 /// </summary>
 /// <param name = "device">The device with which to associate the texture.</param>
 /// <param name = "description">The description of the texture.</param>
 public Texture3D(Device device, Texture3DDescription description)
     : base(IntPtr.Zero)
 {
     device.CreateTexture3D(ref description, null, this);
 }
예제 #40
0
파일: Texture3D.cs 프로젝트: Nezz/SharpDX
 /// <summary>
 ///   Initializes a new instance of the <see cref = "T:SharpDX.Direct3D11.Texture3D" /> class.
 /// </summary>
 /// <param name = "device">The device with which to associate the texture.</param>
 /// <param name = "description">The description of the texture.</param>
 /// <param name = "data">An array of initial texture data for each subresource.</param>
 public Texture3D(Device device, Texture3DDescription description, DataBox[] data) : base(IntPtr.Zero)
 {
     device.CreateTexture3D(ref description, data, this);
 }
예제 #41
0
파일: Texture3D.cs 프로젝트: oeoen/SharpDX
 /// <summary>
 ///   Initializes a new instance of the <see cref = "T:SharpDX.Direct3D10.Texture3D" /> class.
 /// </summary>
 /// <param name = "device">The device with which to associate the texture.</param>
 /// <param name = "description">The description of the texture.</param>
 /// <param name = "data">The initial texture data.</param>
 public Texture3D(Device device, Texture3DDescription description, DataBox data)
     : this(device, description, new[] { data })
 {
 }
예제 #42
0
        /// <summary>
        /// Gets a copy of 3D texture data, specifying a mipmap level, source box, start index, and number of elements.
        /// </summary>
        /// <typeparam name="T">The type of the elements in the array.</typeparam>
        /// <param name="level">Mipmap level.</param>
        /// <param name="left">Position of the left side of the box on the x-axis.</param>
        /// <param name="top">Position of the top of the box on the y-axis.</param>
        /// <param name="right">Position of the right side of the box on the x-axis.</param>
        /// <param name="bottom">Position of the bottom of the box on the y-axis.</param>
        /// <param name="front">Position of the front of the box on the z-axis.</param>
        /// <param name="back">Position of the back of the box on the z-axis.</param>
        /// <param name="data">Array of data.</param>
        /// <param name="startIndex">Index of the first element to get.</param>
        /// <param name="elementCount">Number of elements to get.</param>
        public void GetData <T>(int level, int left, int top, int right, int bottom, int front, int back, T[] data, int startIndex, int elementCount) where T : struct
        {
            if (data == null || data.Length == 0)
            {
                throw new ArgumentException("data cannot be null");
            }
            if (data.Length < startIndex + elementCount)
            {
                throw new ArgumentException("The data passed has a length of " + data.Length + " but " + elementCount + " pixels have been requested.");
            }

            // Disallow negative box size
            if ((left < 0 || left >= right) ||
                (top < 0 || top >= bottom) ||
                (front < 0 || front >= back))
            {
                throw new ArgumentException("Neither box size nor box position can be negative");
            }
#if IOS
            // Reading back a texture from GPU memory is unsupported
            // in OpenGL ES 2.0 and no work around has been implemented.
            throw new NotSupportedException("OpenGL ES 2.0 does not support texture reads.");
#elif ANDROID
            throw new NotImplementedException();
#elif PSM
            throw new NotImplementedException();
#elif DIRECTX
            // Create a temp staging resource for copying the data.
            //
            // TODO: Like in Texture2D, we should probably be pooling these staging resources
            // and not creating a new one each time.
            //
            var desc = new Texture3DDescription
            {
                Width          = width,
                Height         = height,
                Depth          = depth,
                MipLevels      = 1,
                Format         = SharpDXHelper.ToFormat(_format),
                BindFlags      = BindFlags.None,
                CpuAccessFlags = CpuAccessFlags.Read,
                Usage          = ResourceUsage.Staging,
                OptionFlags    = ResourceOptionFlags.None,
            };

            var d3dContext = GraphicsDevice._d3dContext;
            using (var stagingTex = new SharpDX.Direct3D11.Texture3D(GraphicsDevice._d3dDevice, desc))
            {
                lock (d3dContext)
                {
                    // Copy the data from the GPU to the staging texture.
                    d3dContext.CopySubresourceRegion(GetTexture(), level, new ResourceRegion(left, top, front, right, bottom, back), stagingTex, 0);

                    // Copy the data to the array.
                    DataStream stream;
                    var        databox = d3dContext.MapSubresource(stagingTex, 0, MapMode.Read, MapFlags.None, out stream);

                    // Some drivers may add pitch to rows or slices.
                    // We need to copy each row separatly and skip trailing zeros.
                    var currentIndex  = startIndex;
                    var elementSize   = SharpDX.Utilities.SizeOf <T>();
                    var elementsInRow = right - left;
                    var rowsInSlice   = bottom - top;
                    for (var slice = front; slice < back; slice++)
                    {
                        for (var row = top; row < bottom; row++)
                        {
                            stream.ReadRange(data, currentIndex, elementsInRow);
                            stream.Seek(databox.RowPitch - (elementSize * elementsInRow), SeekOrigin.Current);
                            currentIndex += elementsInRow;
                        }
                        stream.Seek(databox.SlicePitch - (databox.RowPitch * rowsInSlice), SeekOrigin.Current);
                    }
                    stream.Dispose();
                }
            }
#else
            throw new NotImplementedException();
#endif
        }
예제 #43
0
 private static void GetPitch(Texture3DDescription descriptor, int mipLevel, out int rowPitch, out int depthPitch)
 {
     rowPitch   = GetRowPitch(descriptor.Format, descriptor.Width, mipLevel);
     depthPitch = rowPitch * 6;
 }