protected static Texture1DDescription NewDescription(int width, PixelFormat format, TextureFlags textureFlags, int mipCount, int arraySize, ResourceUsage usage) { if ((textureFlags & TextureFlags.UnorderedAccess) != 0) { usage = ResourceUsage.Default; } var desc = new Texture1DDescription { Width = width, ArraySize = arraySize, BindFlags = GetBindFlagsFromTextureFlags(textureFlags), Format = format, MipLevels = CalculateMipMapCount(mipCount, width), 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); }
public static ShaderResourceView CreateRandomTexture1DSRV(Device device) { var randomValues = new List <Vector4>(); for (int i = 0; i < 1024; i++) { randomValues.Add(new Vector4(MathF.Rand(-1.0f, 1.0f), MathF.Rand(-1.0f, 1.0f), MathF.Rand(-1.0f, 1.0f), MathF.Rand(-1.0f, 1.0f))); } var texDesc = new Texture1DDescription() { ArraySize = 1, BindFlags = BindFlags.ShaderResource, CpuAccessFlags = CpuAccessFlags.None, Format = Format.R32G32B32A32_Float, MipLevels = 1, OptionFlags = ResourceOptionFlags.None, Usage = ResourceUsage.Immutable, Width = 1024 }; var randTex = new Texture1D(device, texDesc, new DataStream(randomValues.ToArray(), false, false)); var viewDesc = new ShaderResourceViewDescription() { Format = texDesc.Format, Dimension = ShaderResourceViewDimension.Texture1D, MipLevels = texDesc.MipLevels, MostDetailedMip = 0 }; var randTexSRV = new ShaderResourceView(device, randTex, viewDesc); ReleaseCom(ref randTex); return(randTexSRV); }
public void Resize( int length ) { if( Length == length || length == 0 ) { return; } Length = length; if( Texture != null ) { View.Dispose(); Texture.Dispose(); } var desc = new Texture1DDescription { Width = length, MipLevels = 1, ArraySize = 1, Format = Format.R32G32B32A32_Float, Usage = ResourceUsage.Dynamic, BindFlags = BindFlags.ShaderResource, CpuAccessFlags = CpuAccessFlags.Write, OptionFlags = ResourceOptionFlags.None }; Texture = new Texture1D( D3D10Wrapper.Instance.Device, desc ); View = new ShaderResourceView( D3D10Wrapper.Instance.Device, Texture ); }
/// <summary> /// Function to initialize the texture with optional initial data. /// </summary> /// <param name="initialData">Data used to populate the image.</param> protected override void OnInitialize(GorgonImageData initialData) { var shaderBind = Settings.AllowShaderView ? BindFlags.ShaderResource : BindFlags.None; var desc = new Texture1DDescription { ArraySize = Settings.ArrayCount, BindFlags = GetBindFlags(true, false) | shaderBind, CpuAccessFlags = CpuAccessFlags.None, Format = Settings.AllowShaderView ? (Format)Settings.TextureFormat : (Format)Settings.Format, Width = Settings.Width, MipLevels = Settings.MipCount, OptionFlags = ResourceOptionFlags.None }; Gorgon.Log.Print("{0} {1}: Creating 1D depth/stencil texture...", LoggingLevel.Verbose, GetType().Name, Name); // Create the texture. D3DResource = initialData != null ? new Texture1D(Graphics.D3DDevice, desc, initialData.Buffers.DataBoxes) : new Texture1D(Graphics.D3DDevice, desc); GorgonRenderStatistics.DepthBufferCount++; GorgonRenderStatistics.DepthBufferSize += SizeInBytes; _defaultView = GetDepthStencilView(Settings.Format, 0, 0, 1, Settings.DefaultDepthStencilViewFlags); }
/// <summary> /// Initializes a new instance of the <see cref="Texture1DBase" /> class. /// </summary> /// <param name="device">The <see cref="GraphicsDevice"/>.</param> /// <param name="description1D">The description.</param> protected internal Texture1D(GraphicsDevice device, TextureDescription description1D, DataBox[] dataBox = null) : base(device, description1D, ViewType.Full, 0, 0) { NativeDescription = ConvertToNativeDescription(description1D); Resource = new SharpDX.Direct3D11.Texture1D(device.NativeDevice, NativeDescription, ConvertDataBoxes(dataBox)); NativeDeviceChild = Resource; NativeShaderResourceView = GetShaderResourceView(ViewType, ArraySlice, MipLevel); NativeUnorderedAccessView = GetUnorderedAccessView(ArraySlice, MipLevel); }
/// <summary> /// Initializes a new instance of the <see cref="Texture1DBase" /> class. /// </summary> /// <param name="device">The <see cref="GraphicsDevice"/>.</param> /// <param name="description1D">The description.</param> protected internal Texture1D(GraphicsDevice device, Texture1D texture, ViewType viewType, int arraySlice, int mipMapSlice, PixelFormat viewFormat = PixelFormat.None) : base(device, texture, viewType, arraySlice, mipMapSlice, viewFormat) { // Copy the device child, but don't use NativeDeviceChild, as it is registering it for disposing. _nativeDeviceChild = texture._nativeDeviceChild; Resource = texture.Resource; NativeDescription = texture.NativeDescription; dxgiSurface = texture.dxgiSurface; NativeShaderResourceView = GetShaderResourceView(ViewType, ArraySlice, MipLevel); NativeUnorderedAccessView = GetUnorderedAccessView(ArraySlice, MipLevel); }
/// <summary> /// Initializes a new instance of the <see cref = "T:SharpDX.Direct3D10.Texture1D" /> 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 Texture1D(Device device, Texture1DDescription description, DataStream[] data) : base(IntPtr.Zero) { var subResourceDatas = new DataBox[data.Length]; for (int i = 0; i < subResourceDatas.Length; i++) { subResourceDatas[i].DataPointer = data[i].DataPointer; } device.CreateTexture1D(ref description, subResourceDatas, this); }
protected DX11Texture1DArray(DxDevice device, Texture1DDescription desc) { this.device = device; this.description = desc; this.Texture = new Texture1D(device.Device, desc); this.ShaderView = new ShaderResourceView(device.Device, this.Texture); if (desc.BindFlags.HasFlag(BindFlags.UnorderedAccess)) { this.UnorderedView = new UnorderedAccessView(device.Device, this.Texture); } }
/// <summary> /// Initializes a new instance of the <see cref = "T:SharpDX.Direct3D11.Texture1D" /> 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> /// <msdn-id>ff476520</msdn-id> /// <unmanaged>HRESULT ID3D11Device::CreateTexture1D([In] const D3D11_TEXTURE1D_DESC* pDesc,[In, Buffer, Optional] const D3D11_SUBRESOURCE_DATA* pInitialData,[Out, Fast] ID3D11Texture1D** ppTexture1D)</unmanaged> /// <unmanaged-short>ID3D11Device::CreateTexture1D</unmanaged-short> public Texture1D(Device device, Texture1DDescription description, params IntPtr[] data) : base(IntPtr.Zero) { DataBox[] subResourceDatas = null; if (data != null && data.Length > 0) { subResourceDatas = new DataBox[data.Length]; for (int i = 0; i < subResourceDatas.Length; i++) subResourceDatas[i].DataPointer = data[i]; } device.CreateTexture1D(ref description, subResourceDatas, this); }
private void BuildRandomTexture() { // // Create the random data. // var rand = new Random(); var randomValues = new Vector4[1024]; for (int i = 0; i < 1024; ++i) { randomValues[i] = new Vector4(rand.RandF(-1.0f, 1.0f), rand.RandF(-1.0f, 1.0f), rand.RandF(-1.0f, 1.0f), rand.RandF(-1.0f, 1.0f)); } // // Create the texture. // var texDesc = new Texture1DDescription { Width = 1024, MipLevels = 1, Format = Format.R32G32B32A32_Float, Usage = ResourceUsage.Immutable, BindFlags = BindFlags.ShaderResource, CpuAccessFlags = CpuAccessFlags.None, OptionFlags = ResourceOptionFlags.None, ArraySize = 1 }; var ds = new DataStream(randomValues, true, false); var randomTex = new Texture1D(_dxDevice, texDesc, ds); ds.Close(); // // Create the resource view. // var viewDesc = new ShaderResourceViewDescription { Format = texDesc.Format, Dimension = ShaderResourceViewDimension.Texture1D, MipLevels = texDesc.MipLevels, MostDetailedMip = 0 }; _randomTexRV = new ShaderResourceView(_dxDevice, randomTex, viewDesc); randomTex.Dispose(); }
/// <summary> /// 1DテクスチャーDescの簡単な初期化 /// </summary> /// <param name="w"></param> /// <param name="desc"></param> public static void SimpleD1DescInit(int w, out Texture1DDescription desc) { desc = new Texture1DDescription() { Width = w, MipLevels = 1, ArraySize = 1, Format = Format.R8G8B8A8_UNorm, Usage = ResourceUsage.Default, BindFlags = BindFlags.ShaderResource, CpuAccessFlags = CpuAccessFlags.None, OptionFlags = ResourceOptionFlags.None }; }
/// <summary> /// Initializes a new instance of the <see cref = "T:SharpDX.Direct3D10.Texture1D" /> 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 Texture1D(Device device, Texture1DDescription description, DataStream[] data) : base(IntPtr.Zero) { System.Diagnostics.Debug.Assert(data != null); var subResourceDatas = new DataBox[data.Length]; for (int i = 0; i < subResourceDatas.Length; i++) { subResourceDatas[i].DataPointer = data[i].DataPointer; } device.CreateTexture1D(ref description, subResourceDatas, this); }
/// <summary> /// Initializes a new instance of the <see cref = "T:SharpDX.Direct3D11.Texture1D" /> 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> /// <msdn-id>ff476520</msdn-id> /// <unmanaged>HRESULT ID3D11Device::CreateTexture1D([In] const D3D11_TEXTURE1D_DESC* pDesc,[In, Buffer, Optional] const D3D11_SUBRESOURCE_DATA* pInitialData,[Out, Fast] ID3D11Texture1D** ppTexture1D)</unmanaged> /// <unmanaged-short>ID3D11Device::CreateTexture1D</unmanaged-short> public Texture1D(Device device, Texture1DDescription description, params IntPtr[] data) : base(IntPtr.Zero) { DataBox[] subResourceDatas = null; if (data != null && data.Length > 0) { subResourceDatas = new DataBox[data.Length]; for (int i = 0; i < subResourceDatas.Length; i++) { subResourceDatas[i].DataPointer = data[i]; } } device.CreateTexture1D(ref description, subResourceDatas, this); }
public void Evaluate(int SpreadMax) { if (this.FTextureIn.IsConnected) { if (this.RenderRequest != null) { this.RenderRequest(this, this.FHost); } if (this.AssignedContext == null) { this.SetNull(); return; } //Do NOT cache this, assignment done by the host this.FOutWidth.SliceCount = this.FTextureIn.SliceCount; this.FOutMipLevels.SliceCount = this.FTextureIn.SliceCount; this.FOutFormat.SliceCount = this.FTextureIn.SliceCount; this.FOutArraySize.SliceCount = this.FTextureIn.SliceCount; this.FOutPointer.SliceCount = this.FTextureIn.SliceCount; for (int i = 0; i < this.FTextureIn.SliceCount; i++) { try { if (this.FTextureIn[i].Contains(this.AssignedContext)) { Texture1DDescription tdesc = this.FTextureIn[i][this.AssignedContext].Resource.Description; this.FOutWidth[i] = tdesc.Width; this.FOutFormat[i] = tdesc.Format; this.FOutMipLevels[i] = tdesc.MipLevels; this.FOutArraySize[i] = tdesc.ArraySize; this.FOutPointer[i] = this.FTextureIn[i][this.AssignedContext].Resource.ComPointer.ToInt32(); } else { this.SetDefault(i); } } catch { this.SetDefault(i); } } } else { this.SetNull(); } }
public ShaderResourceViewDescription( ID3D11Texture1D texture, bool isArray, Format format = Format.Unknown, int mostDetailedMip = 0, int mipLevels = -1, int firstArraySlice = 0, int arraySize = -1) : this() { ViewDimension = isArray ? ShaderResourceViewDimension.Texture1DArray : ShaderResourceViewDimension.Texture1D; if (format == Format.Unknown || mipLevels == -1 || (arraySize == -1 && ShaderResourceViewDimension.Texture1DArray == ViewDimension)) { Texture1DDescription textureDesc = texture.Description; if (format == Format.Unknown) { format = textureDesc.Format; } if (mipLevels == -1) { mipLevels = textureDesc.MipLevels - mostDetailedMip; } if (arraySize == -1) { arraySize = textureDesc.ArraySize - firstArraySlice; } } Format = format; switch (ViewDimension) { case ShaderResourceViewDimension.Texture1D: Texture1D.MostDetailedMip = mostDetailedMip; Texture1D.MipLevels = mipLevels; break; case ShaderResourceViewDimension.Texture1DArray: Texture1DArray.MostDetailedMip = mostDetailedMip; Texture1DArray.MipLevels = mipLevels; Texture1DArray.FirstArraySlice = firstArraySlice; Texture1DArray.ArraySize = arraySize; break; default: break; } }
public static DX11Texture1DArray CreateWriteable(DxDevice device, int width, int elementcount, SharpDX.DXGI.Format format) { Texture1DDescription desc = new Texture1DDescription() { BindFlags = BindFlags.ShaderResource | BindFlags.UnorderedAccess, CpuAccessFlags = CpuAccessFlags.None, OptionFlags = ResourceOptionFlags.None, Width = width, ArraySize = elementcount, MipLevels = 1, Format = format, Usage = ResourceUsage.Default }; return(new DX11Texture1DArray(device, desc)); }
private Texture1DDescription ConvertToNativeDescription1D() { var desc = new Texture1DDescription() { Width = textureDescription.Width, ArraySize = 1, BindFlags = GetBindFlagsFromTextureFlags(textureDescription.Flags), Format = (SharpDX.DXGI.Format)textureDescription.Format, MipLevels = textureDescription.MipLevels, Usage = (ResourceUsage)textureDescription.Usage, CpuAccessFlags = GetCpuAccessFlagsFromUsage(textureDescription.Usage), OptionFlags = (ResourceOptionFlags)textureDescription.Options, }; return(desc); }
protected static Texture1DDescription ConvertToNativeDescription(TextureDescription description) { var desc = new Texture1DDescription() { Width = description.Width, ArraySize = 1, BindFlags = GetBindFlagsFromTextureFlags(description.Flags), Format = (Format)description.Format, MipLevels = description.MipLevels, Usage = (ResourceUsage)description.Usage, CpuAccessFlags = GetCpuAccessFlagsFromUsage(description.Usage), OptionFlags = ResourceOptionFlags.None }; return(desc); }
public static DX11Texture1D CreateDynamic(DxDevice device, int width, SharpDX.DXGI.Format format) { Texture1DDescription desc = new Texture1DDescription() { ArraySize = 1, BindFlags = BindFlags.ShaderResource, CpuAccessFlags = CpuAccessFlags.Write, OptionFlags = ResourceOptionFlags.None, Width = width, Format = format, MipLevels = 1, Usage = ResourceUsage.Dynamic }; return(new DX11Texture1D(device, desc)); }
public DX11DynamicTexture1D(DX11RenderContext context, int width, Format format) : base(context) { Texture1DDescription desc = new Texture1DDescription() { ArraySize = 1, BindFlags = BindFlags.ShaderResource, CpuAccessFlags = CpuAccessFlags.Write, Format = format, MipLevels = 1, OptionFlags = ResourceOptionFlags.None, Usage = ResourceUsage.Dynamic, Width = width, }; this.Resource = new Texture1D(context.Device, desc); this.SRV = new ShaderResourceView(context.Device, this.Resource); }
public DX11WriteableTexture1d(DX11RenderContext context, int width, Format format) : base(context) { Texture1DDescription desc = new Texture1DDescription() { ArraySize = 1, BindFlags = BindFlags.ShaderResource | BindFlags.UnorderedAccess, CpuAccessFlags = CpuAccessFlags.None, Format = format, MipLevels = 1, OptionFlags = ResourceOptionFlags.None, Usage = ResourceUsage.Default, Width = width, }; this.Resource = new Texture1D(context.Device, desc); this.SRV = new ShaderResourceView(context.Device, this.Resource); this.UAV = new UnorderedAccessView(context.Device, this.Resource); }
public DX11WriteableTexture1dArray(DX11RenderContext context, int width,int arraySize, Format format) : base(context) { Texture1DDescription desc = new Texture1DDescription() { ArraySize = arraySize, BindFlags = BindFlags.ShaderResource | BindFlags.UnorderedAccess, CpuAccessFlags = CpuAccessFlags.None, Format = format, MipLevels = 1, OptionFlags = ResourceOptionFlags.None, Usage = ResourceUsage.Default, Width = width, }; this.Resource = new Texture1D(context.Device, desc); this.SRV = new ShaderResourceView(context.Device, this.Resource); this.UAV = new UnorderedAccessView(context.Device, this.Resource); }
private void BindTextureFor1DColorProviders() { _descriptionTextureFor1DColorProvider = new Texture1DDescription() { ArraySize = 1, BindFlags = BindFlags.ShaderResource, CpuAccessFlags = CpuAccessFlags.Write, Format = Format.R32G32B32A32_Float, MipLevels = 1, OptionFlags = ResourceOptionFlags.None, Usage = ResourceUsage.Dynamic, Width = 1024 }; _textureFor1DColorProvider = new Texture1D(_cachedDevice, _descriptionTextureFor1DColorProvider); _textureFor1DColorProviderView = new ShaderResourceView(_cachedDevice, _textureFor1DColorProvider); _textureFor1DColorProviderVariable = _lightingEffect.GetVariableByName("ColorGradient1DTexture"); _textureFor1DColorProviderShaderResourceVariable = _textureFor1DColorProviderVariable.AsShaderResource(); _textureFor1DColorProviderShaderResourceVariable.SetResource(_textureFor1DColorProviderView); }
/// <summary> /// Initializes a new instance of the <see cref="UnorderedAccessViewDescription"/> struct. /// </summary> /// <param name="texture"></param> /// <param name="isArray"></param> /// <param name="format"></param> /// <param name="mipSlice"></param> /// <param name="firstArraySlice"></param> /// <param name="arraySize"></param> public UnorderedAccessViewDescription( ID3D11Texture1D texture, bool isArray, Format format = Format.Unknown, int mipSlice = 0, int firstArraySlice = 0, int arraySize = -1) : this() { ViewDimension = isArray ? UnorderedAccessViewDimension.Texture1DArray : UnorderedAccessViewDimension.Texture1D; if (format == Format.Unknown || (-1 == arraySize && (UnorderedAccessViewDimension.Texture1DArray == ViewDimension))) { Texture1DDescription textureDesc = texture.Description; if (format == Format.Unknown) { format = textureDesc.Format; } if (arraySize == -1) { arraySize = textureDesc.ArraySize - firstArraySlice; } } Format = format; switch (ViewDimension) { case UnorderedAccessViewDimension.Texture1D: Texture1D.MipSlice = mipSlice; break; case UnorderedAccessViewDimension.Texture1DArray: Texture1DArray.MipSlice = mipSlice; Texture1DArray.FirstArraySlice = firstArraySlice; Texture1DArray.ArraySize = arraySize; break; } }
/// <summary> /// Initializes a new instance of the <see cref = "T:SharpDX.Direct3D11.Texture1D" /> class. /// </summary> /// <param name = "device">The device with which to associate the texture.</param> /// <param name = "description">The description of the texture.</param> /// <msdn-id>ff476520</msdn-id> /// <unmanaged>HRESULT ID3D11Device::CreateTexture1D([In] const D3D11_TEXTURE1D_DESC* pDesc,[In, Buffer, Optional] const D3D11_SUBRESOURCE_DATA* pInitialData,[Out, Fast] ID3D11Texture1D** ppTexture1D)</unmanaged> /// <unmanaged-short>ID3D11Device::CreateTexture1D</unmanaged-short> public Texture1D(Device device, Texture1DDescription description) : base(IntPtr.Zero) { device.CreateTexture1D(ref description, null, this); }
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); } }
/// <summary> /// Creates a new <see cref="RenderTarget1D"/> from a <see cref="Texture1DDescription"/>. /// </summary> /// <param name="device">The <see cref="GraphicsDevice"/>.</param> /// <param name="description">The description.</param> /// <returns> /// A new instance of <see cref="RenderTarget1D"/> class. /// </returns> /// <msdn-id>ff476520</msdn-id> /// <unmanaged>HRESULT ID3D11Device::CreateTexture1D([In] const D3D11_TEXTURE1D_DESC* pDesc,[In, Buffer, Optional] const D3D11_SUBRESOURCE_DATA* pInitialData,[Out, Fast] ID3D11Texture1D** ppTexture1D)</unmanaged> /// <unmanaged-short>ID3D11Device::CreateTexture1D</unmanaged-short> public static RenderTarget1D New(GraphicsDevice device, Texture1DDescription description) { return new RenderTarget1D(device, description); }
/// <summary> /// Initializes a new instance of the <see cref="Texture1DBase" /> class. /// </summary> /// <param name="device">The <see cref="Direct3D11.Device"/>.</param> /// <param name="description1D">The description.</param> /// <msdn-id>ff476520</msdn-id> /// <unmanaged>HRESULT ID3D11Device::CreateTexture1D([In] const D3D11_TEXTURE1D_DESC* pDesc,[In, Buffer, Optional] const D3D11_SUBRESOURCE_DATA* pInitialData,[Out, Fast] ID3D11Texture1D** ppTexture1D)</unmanaged> /// <unmanaged-short>ID3D11Device::CreateTexture1D</unmanaged-short> protected internal Texture1DBase(Direct3D11.Device device, Texture1DDescription description1D) : base(device, description1D) { Resource = new Direct3D11.Texture1D(device, description1D); Initialize(Resource); }
internal RenderTarget1D(GraphicsDevice device, Texture1DDescription description1D) : base(device, description1D) { }
/// <summary> /// Initializes a new instance of the <see cref="Texture1DBase" /> class. /// </summary> /// <param name="device">The <see cref="GraphicsDevice"/>.</param> /// <param name="description1D">The description.</param> /// <param name="dataBox">A variable-length parameters list containing data rectangles.</param> /// <msdn-id>ff476520</msdn-id> /// <unmanaged>HRESULT ID3D11Device::CreateTexture1D([In] const D3D11_TEXTURE1D_DESC* pDesc,[In, Buffer, Optional] const D3D11_SUBRESOURCE_DATA* pInitialData,[Out, Fast] ID3D11Texture1D** ppTexture1D)</unmanaged> /// <unmanaged-short>ID3D11Device::CreateTexture1D</unmanaged-short> protected internal Texture1DBase(GraphicsDevice device, Texture1DDescription description1D, DataBox[] dataBox) : base(device, description1D) { Resource = new Direct3D11.Texture1D(device, description1D, dataBox); Initialize(Resource); }
/// <summary> /// Initializes a new instance of the <see cref="Texture1DBase" /> class. /// </summary> /// <param name="device">The <see cref="DirectXDevice"/>.</param> /// <param name="description1D">The description.</param> /// <param name="dataBox">A variable-length parameters list containing data rectangles.</param> /// <msdn-id>ff476520</msdn-id> /// <unmanaged>HRESULT ID3D11Device::CreateTexture1D([In] const D3D11_TEXTURE1D_DESC* pDesc,[In, Buffer, Optional] const D3D11_SUBRESOURCE_DATA* pInitialData,[Out, Fast] ID3D11Texture1D** ppTexture1D)</unmanaged> /// <unmanaged-short>ID3D11Device::CreateTexture1D</unmanaged-short> protected internal Texture1DBase(DirectXDevice device, Texture1DDescription description1D, DataBox[] dataBox) : base(device, description1D) { Resource = new SharpDX.Direct3D11.Texture1D(device, description1D, dataBox); }
public void Update(IPluginIO pin, DX11RenderContext context) { if (this.FInvalidate) { SlimDX.DXGI.Format fmt; switch (this.FInChannels[0]) { case 1: fmt = SlimDX.DXGI.Format.R32_Float; break; case 2: fmt = SlimDX.DXGI.Format.R32G32_Float; break; case 3: fmt = SlimDX.DXGI.Format.R32G32B32_Float; break; case 4: fmt = SlimDX.DXGI.Format.R32G32B32A32_Float; break; default: fmt = SlimDX.DXGI.Format.R32_Float; break; } if (this.FTextureOutput[0].Contains(context)) { Texture1DDescription td = this.FTextureOutput[0][context].Resource.Description; if (td.Width != this.FInWidth[0] || td.Format != fmt) { this.FTextureOutput[0].Dispose(context); this.FTextureOutput[0][context] = new DX11DynamicTexture1D(context, this.FInWidth[0], fmt); } } else { this.FTextureOutput[0][context] = new DX11DynamicTexture1D(context, this.FInWidth[0], fmt); } DX11DynamicTexture1D tex = this.FTextureOutput[0][context]; int chans = this.FInChannels[0]; chans = Math.Min(chans, 4); chans = Math.Max(chans, 1); float[] data = new float[this.FInWidth[0] * chans]; for (int i = 0; i < data.Length; i++) { data[i] = this.FInData[i % data.Length]; } tex.WriteData(data); } }
public static ShaderResourceView CreateRandomTexture1D(Device device) { var randomValues = new List<Vector4>(); for (var i = 0; i < 1024; i++) { randomValues.Add(new Vector4(MathF.Rand.NextFloat(-1.0f, 1.0f), MathF.Rand.NextFloat(-1.0f, 1.0f), MathF.Rand.NextFloat(-1.0f, 1.0f), MathF.Rand.NextFloat(-1.0f, 1.0f))); } var texDesc = new Texture1DDescription() { ArraySize = 1, BindFlags = BindFlags.ShaderResource, CpuAccessFlags = CpuAccessFlags.None, Format = Format.R32G32B32A32_Float, MipLevels = 1, OptionFlags = ResourceOptionFlags.None, Usage = ResourceUsage.Immutable, Width = 1024 }; var randTex = new Texture1D(device, texDesc, DataStream.Create(randomValues.ToArray(), false, false)); var viewDesc = new ShaderResourceViewDescription() { Format = texDesc.Format, Dimension = ShaderResourceViewDimension.Texture1D, Texture1D = new ShaderResourceViewDescription.Texture1DResource() { MipLevels = texDesc.MipLevels, MostDetailedMip = 0 } }; var randTexSRV = new ShaderResourceView(device, randTex, viewDesc); Utilities.Dispose(ref randTex); return randTexSRV; }
internal static RwTexId CreateUav1D(int width, Format resourceFormat, string debugName = null) { var desc = new Texture1DDescription { ArraySize = 1, BindFlags = BindFlags.ShaderResource | BindFlags.UnorderedAccess, CpuAccessFlags = CpuAccessFlags.None, Format = resourceFormat, MipLevels = 1, Usage = ResourceUsage.Default, Width = width }; var handle = new RwTexId { Index = Textures.Allocate() }; Textures.Data[handle.Index] = new MyRwTextureInfo { Description1D = desc }; Textures.Data[handle.Index].Resource = new Texture1D(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; }
/// <summary> /// Initializes a new instance of the <see cref = "T:SharpDX.Direct3D11.Texture1D" /> 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> /// <msdn-id>ff476520</msdn-id> /// <unmanaged>HRESULT ID3D11Device::CreateTexture1D([In] const D3D11_TEXTURE1D_DESC* pDesc,[In, Buffer, Optional] const D3D11_SUBRESOURCE_DATA* pInitialData,[Out, Fast] ID3D11Texture1D** ppTexture1D)</unmanaged> /// <unmanaged-short>ID3D11Device::CreateTexture1D</unmanaged-short> public Texture1D(Device device, Texture1DDescription description, DataBox[] data) : base(IntPtr.Zero) { device.CreateTexture1D(ref description, data, this); }
internal Texture1D(GraphicsDevice device, Texture1DDescription description1D, params DataBox[] dataBox) : base(device, description1D, dataBox) { }
/// <summary> /// Creates a new <see cref="RenderTarget1D"/> from a <see cref="Texture1DDescription"/>. /// </summary> /// <param name="device">The <see cref="GraphicsDevice"/>.</param> /// <param name="description">The description.</param> /// <returns> /// A new instance of <see cref="RenderTarget1D"/> class. /// </returns> /// <msdn-id>ff476520</msdn-id> /// <unmanaged>HRESULT ID3D11Device::CreateTexture1D([In] const D3D11_TEXTURE1D_DESC* pDesc,[In, Buffer, Optional] const D3D11_SUBRESOURCE_DATA* pInitialData,[Out, Fast] ID3D11Texture1D** ppTexture1D)</unmanaged> /// <unmanaged-short>ID3D11Device::CreateTexture1D</unmanaged-short> public static RenderTarget1D New(GraphicsDevice device, Texture1DDescription description) { return(new RenderTarget1D(device, description)); }
/// <summary> /// Creates a new texture from a <see cref="Texture1DDescription"/>. /// </summary> /// <param name="device">The <see cref="GraphicsDevice"/>.</param> /// <param name="description">The description.</param> /// <returns> /// A new instance of <see cref="Texture1D"/> class. /// </returns> /// <msdn-id>ff476520</msdn-id> /// <unmanaged>HRESULT ID3D11Device::CreateTexture1D([In] const D3D11_TEXTURE1D_DESC* pDesc,[In, Buffer, Optional] const D3D11_SUBRESOURCE_DATA* pInitialData,[Out, Fast] ID3D11Texture1D** ppTexture1D)</unmanaged> /// <unmanaged-short>ID3D11Device::CreateTexture1D</unmanaged-short> public static Texture1D New(GraphicsDevice device, Texture1DDescription description) { return(new Texture1D(device, description)); }
private Texture1DDescription ConvertToNativeDescription1D() { var desc = new Texture1DDescription() { Width = textureDescription.Width, ArraySize = 1, 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; }
private void SetRandomTex(int Seed) { // set the seed _Seed = Seed; // set the random size int RandNum_Size = 256; // set the description of the texture Texture1DDescription RandomTex_Desc = new Texture1DDescription(); RandomTex_Desc.Format = Format.R8_UInt; RandomTex_Desc.CpuAccessFlags = CpuAccessFlags.None; RandomTex_Desc.Width = RandNum_Size * 2; RandomTex_Desc.Usage = ResourceUsage.Default; RandomTex_Desc.OptionFlags = ResourceOptionFlags.None; RandomTex_Desc.MipLevels = 1; RandomTex_Desc.BindFlags = BindFlags.ShaderResource; RandomTex_Desc.ArraySize = 1; // start the stream DataStream stream = new DataStream(RandNum_Size * 2, true, true); // Initialize the random generator Random generator = new Random(Seed); // allocate the random values byte[] RandNum_Host = new byte[RandNum_Size * 2]; // Copy the source data twice to the generator array for (int i = 0; i < RandNum_Size; i++) { RandNum_Host[i] = (byte)generator.Next(256); RandNum_Host[i + RandNum_Size] = RandNum_Host[i]; } // pass the randoms to the stream stream.WriteRange<byte>(RandNum_Host); stream.Position = 0; // create the texture and pass the data Texture1D RandomTex = new Texture1D(Engine.g_device, RandomTex_Desc, stream); // close the stream we don't need it any more stream.Close(); // create the resource view to be able to pass it to the shader ShaderResourceView RandomResourceView = new ShaderResourceView(Engine.g_device, RandomTex); // set the Resource to the shader RandomTex_Variable.SetResource(RandomResourceView); }
// 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; } }
protected static Texture1DDescription NewDescription(int width, PixelFormat format, TextureFlags textureFlags, int mipCount, int arraySize, ResourceUsage usage) { if ((textureFlags & TextureFlags.UnorderedAccess) != 0) usage = ResourceUsage.Default; var desc = new Texture1DDescription() { Width = width, ArraySize = arraySize, BindFlags = GetBindFlagsFromTextureFlags(textureFlags), Format = format, MipLevels = CalculateMipMapCount(mipCount, width), Usage = usage, CpuAccessFlags = GetCputAccessFlagsFromUsage(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; }