public void Init( string name, int width, int height, Format resourceFormat, Format srvFormat, BindFlags bindFlags, int samplesCount, int samplesQuality, ResourceOptionFlags roFlags, ResourceUsage ru, int mipmapLevels, CpuAccessFlags cpuAccessFlags) { m_name = name; m_size = new Vector2I(width, height); m_resourceFormat = resourceFormat; m_srvFormat = srvFormat; m_bindFlags = bindFlags; m_samplesCount = samplesCount; m_samplesQuality = samplesQuality; m_roFlags = roFlags; m_resourceUsage = ru; m_mipmapLevels = mipmapLevels; m_cpuAccessFlags = cpuAccessFlags; }
private void UpdateTexture(EvaluationContext context) { Int3 size = Size.GetValue(context); if (size.X < 1 || size.Y < 1 || size.Z < 1) { Log.Warning($"Requested invalid texture resolution: {size}"); return; } var texDesc = new Texture3DDescription { Width = size.X, Height = size.Y, Depth = size.Z, MipLevels = MipLevels.GetValue(context), Format = Format.GetValue(context), Usage = ResourceUsage.GetValue(context), BindFlags = BindFlags.GetValue(context), CpuAccessFlags = CpuAccessFlags.GetValue(context), OptionFlags = ResourceOptionFlags.GetValue(context) }; var rm = ResourceManager.Instance(); rm.CreateTexture3d(texDesc, "Texture3D", ref _textureResId, ref OutputTexture.Value.Texture); if ((BindFlags.Value & SharpDX.Direct3D11.BindFlags.ShaderResource) > 0) rm.CreateShaderResourceView(_textureResId, "", ref OutputTexture.Value.Srv); if ((BindFlags.Value & SharpDX.Direct3D11.BindFlags.RenderTarget) > 0) rm.CreateRenderTargetView(_textureResId, "", ref OutputTexture.Value.Rtv); if ((BindFlags.Value & SharpDX.Direct3D11.BindFlags.UnorderedAccess) > 0) rm.CreateUnorderedAccessView(_textureResId, "", ref OutputTexture.Value.Uav); }
/// <summary> /// Creates a new instance of the <see cref="T:SharpDX.Direct3D11.Buffer"/> class. /// </summary> /// <typeparam name="T">Type of the data to upload</typeparam> /// <param name="device">The device with which to associate the buffer.</param> /// <param name="bindFlags">Flags specifying how the buffer will be bound to the pipeline.</param> /// <param name="data">Initial data used to initialize the buffer.</param> /// <param name="sizeInBytes">The size, in bytes, of the buffer. If 0 is specified, sizeof(T) is used. </param> /// <param name="usage">The usage pattern for the buffer.</param> /// <param name="accessFlags">Flags specifying how the buffer will be accessible from the CPU.</param> /// <param name="optionFlags">Miscellaneous resource options.</param> /// <param name="structureByteStride">The size (in bytes) of the structure element for structured buffers.</param> /// <returns>An initialized buffer</returns> /// <msdn-id>ff476501</msdn-id> /// <unmanaged>HRESULT ID3D11Device::CreateBuffer([In] const D3D11_BUFFER_DESC* pDesc,[In, Optional] const D3D11_SUBRESOURCE_DATA* pInitialData,[Out, Fast] ID3D11Buffer** ppBuffer)</unmanaged> /// <unmanaged-short>ID3D11Device::CreateBuffer</unmanaged-short> public static Buffer Create <T>( Device device, BindFlags bindFlags, ref T data, int sizeInBytes = 0, ResourceUsage usage = ResourceUsage.Default, CpuAccessFlags accessFlags = CpuAccessFlags.None, ResourceOptionFlags optionFlags = ResourceOptionFlags.None, int structureByteStride = 0) where T : struct { var buffer = new Buffer(IntPtr.Zero); var description = new BufferDescription() { BindFlags = bindFlags, CpuAccessFlags = accessFlags, OptionFlags = optionFlags, SizeInBytes = sizeInBytes == 0 ? Utilities.SizeOf <T>() : sizeInBytes, Usage = usage, StructureByteStride = structureByteStride }; unsafe { device.CreateBuffer(ref description, new DataBox((IntPtr)Interop.Fixed(ref data)), buffer); } return(buffer); }
private void UpdateTexture(EvaluationContext context) { Size2 size = Size.GetValue(context); if (size.Height <= 0 || size.Width <= 0) { Log.Warning($"Requested invalid texture resolution: {size}"); return; } var texDesc = new Texture2DDescription { Width = size.Width, Height = size.Height, MipLevels = MipLevels.GetValue(context), ArraySize = ArraySize.GetValue(context), Format = Format.GetValue(context), //SampleDescription = SampleDescription.GetValue(context), SampleDescription = new SampleDescription(1, 0), Usage = ResourceUsage.GetValue(context), BindFlags = BindFlags.GetValue(context), CpuAccessFlags = CpuAccessFlags.GetValue(context), OptionFlags = ResourceOptionFlags.GetValue(context) }; try { ResourceManager.Instance().CreateTexture2d(texDesc, "Texture2D", ref _textureResId, ref Texture.Value); } catch (Exception e) { Log.Error($"Failed to create Texture2D: {e.Message}", SymbolChildId); } //ResourceManager.Instance().id .TestId = _textureResId; }
private static Texture2D LoadTexture(string filename, out ShaderResourceView view, int arraySize = 1, ResourceOptionFlags optFlags = ResourceOptionFlags.None) { var bitmap = new Bitmap(filename); if (bitmap.PixelFormat != PixelFormat.Format32bppArgb) { bitmap = bitmap.Clone(new System.Drawing.Rectangle(0, 0, bitmap.Width, bitmap.Height), PixelFormat.Format32bppArgb); } var data = bitmap.LockBits(new System.Drawing.Rectangle(0, 0, bitmap.Width, bitmap.Height), ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb); var ret = new Texture2D(Video.GraphicDevice, new Texture2DDescription() { Width = bitmap.Width, Height = bitmap.Height, ArraySize = 1, BindFlags = SharpDX.Direct3D11.BindFlags.ShaderResource, Usage = SharpDX.Direct3D11.ResourceUsage.Default, CpuAccessFlags = SharpDX.Direct3D11.CpuAccessFlags.None, Format = SharpDX.DXGI.Format.B8G8R8A8_UNorm, MipLevels = 1, OptionFlags = SharpDX.Direct3D11.ResourceOptionFlags.None, SampleDescription = new SharpDX.DXGI.SampleDescription(1, 0), }, new DataRectangle(data.Scan0, data.Stride)); bitmap.UnlockBits(data); bitmap.Dispose(); view = new ShaderResourceView(Video.GraphicDevice, ret); return(ret); }
/// <summary> /// Initializes a new instance of the <see cref="Texture1DDescription"/> struct. /// </summary> /// <param name="format">Texture format.</param> /// <param name="width">Texture width (in texels).</param> /// <param name="arraySize">Number of textures in the array.</param> /// <param name="mipLevels">The maximum number of mipmap levels in the texture.</param> /// <param name="bindFlags">The <see cref="Direct3D11.BindFlags"/> for binding to pipeline stages.</param> /// <param name="usage">Value that identifies how the texture is to be read from and written to.</param> /// <param name="cpuAccessFlags">The <see cref="Direct3D11.CpuAccessFlags"/> to specify the types of CPU access allowed.</param> /// <param name="optionFlags">The <see cref="ResourceOptionFlags"/> that identify other, less common resource options. </param> public Texture1DDescription( Format format, int width, int arraySize = 1, int mipLevels = 0, BindFlags bindFlags = BindFlags.ShaderResource, ResourceUsage usage = ResourceUsage.Default, CpuAccessFlags cpuAccessFlags = CpuAccessFlags.None, ResourceOptionFlags optionFlags = ResourceOptionFlags.None) { if (format == Format.Unknown) { throw new ArgumentException($"format need to be valid", nameof(format)); } if (width < 1 || width > ID3D11Resource.MaximumTexture1DSize) { throw new ArgumentException($"Width need to be in range 1-{ID3D11Resource.MaximumTexture1DSize}", nameof(width)); } if (arraySize < 1 || arraySize > ID3D11Resource.MaximumTexture1DArraySize) { throw new ArgumentException($"Array size need to be in range 1-{ID3D11Resource.MaximumTexture1DArraySize}", nameof(arraySize)); } Width = width; MipLevels = mipLevels; ArraySize = arraySize; Format = format; Usage = usage; BindFlags = bindFlags; CpuAccessFlags = cpuAccessFlags; OptionFlags = optionFlags; }
public static void CreateDDSTextureFromMemory(Device d3dDevice, byte[] ddsData, out Resource texture, out ShaderResourceView textureView, int maxsize = 0, ResourceUsage usage = ResourceUsage.Default, BindFlags bindFlags = BindFlags.ShaderResource, CpuAccessFlags cpuAccessFlags = CpuAccessFlags.None, ResourceOptionFlags miscFlags = ResourceOptionFlags.None, bool forceSRGB = false ) { GCHandle ddsDataHandle = GCHandle.Alloc(ddsData, GCHandleType.Pinned); try { CreateDDSTextureFromMemory( d3dDevice, new DataPointer(ddsDataHandle.AddrOfPinnedObject(), ddsData.Length), out texture, out textureView, maxsize, usage, bindFlags, cpuAccessFlags, miscFlags, forceSRGB); } finally { ddsDataHandle.Free(); } }
/// <summary> /// /// </summary> /// <param name="structureSize"></param> /// <param name="bindFlags"></param> /// <param name="optionFlags"></param> /// <param name="lazyResize">If existing data size is smaller than buffer size, reuse existing. Otherwise create a new buffer with exact same size</param> public DynamicBufferProxy(int structureSize, BindFlags bindFlags, ResourceOptionFlags optionFlags = ResourceOptionFlags.None, bool lazyResize = true) : base(structureSize, bindFlags) { CanOverwrite = (bindFlags & (BindFlags.VertexBuffer | BindFlags.IndexBuffer)) != 0; this.OptionFlags = optionFlags; LazyResize = lazyResize; }
/// <summary> /// Initializes a new instance of the <see cref="DynamicBufferProxy"/> class. /// </summary> /// <param name="structureSize">Size of the structure.</param> /// <param name="bindFlags">The bind flags.</param> /// <param name="optionFlags">The option flags.</param> /// <param name="lazyResize">if set to <c>true</c> [lazy resize].</param> /// <param name="canOverWrite">if set to <c>true</c> [can over write].</param> public DynamicBufferProxy(int structureSize, BindFlags bindFlags, bool canOverWrite, ResourceOptionFlags optionFlags = ResourceOptionFlags.None, bool lazyResize = true) : base(structureSize, bindFlags) { CanOverwrite = canOverWrite; this.OptionFlags = optionFlags; LazyResize = lazyResize; }
public StagingTexture(Device device, int width, int height, Format format = Format.B8G8R8A8_UNorm, ResourceOptionFlags optionFlags = ResourceOptionFlags.None) : base(new Texture2D(device, CreateTextureDescription(width, height, format, optionFlags))) { }
/// <summary> /// Initializes a new instance of the <see cref="BufferDescription"/> struct. /// </summary> /// <param name="sizeInBytes">The size in bytes.</param> /// <param name="usage">The usage.</param> /// <param name="bindFlags">The bind flags.</param> /// <param name="cpuAccessFlags">The CPU access flags.</param> /// <param name="optionFlags">The option flags.</param> public BufferDescription(int sizeInBytes, ResourceUsage usage, BindFlags bindFlags, CpuAccessFlags cpuAccessFlags, ResourceOptionFlags optionFlags) { SizeInBytes = sizeInBytes; Usage = usage; BindFlags = bindFlags; CpuAccessFlags = cpuAccessFlags; OptionFlags = optionFlags; }
/// <summary> /// Initializes a new instance of the <see cref="BufferDescription"/> struct. /// </summary> /// <param name="sizeInBytes">The size in bytes.</param> /// <param name="usage">The usage.</param> /// <param name="bindFlags">The bind flags.</param> /// <param name="cpuAccessFlags">The cpu access flags.</param> /// <param name="optionFlags">The option flags.</param> /// <param name="structureByteStride">The structure byte stride.</param> public BufferDescription(int sizeInBytes, ResourceUsage usage, BindFlags bindFlags, CpuAccessFlags cpuAccessFlags, ResourceOptionFlags optionFlags, int structureByteStride) { SizeInBytes = sizeInBytes; Usage = usage; BindFlags = bindFlags; CpuAccessFlags = cpuAccessFlags; OptionFlags = optionFlags; StructureByteStride = structureByteStride; }
/// <summary> /// Initializes a new instance of the <see cref="BufferDescription"/> struct. /// </summary> /// <param name="sizeInBytes">The size in bytes.</param> /// <param name="usage">The usage.</param> /// <param name="bindFlags">The bind flags.</param> /// <param name="cpuAccessFlags">The CPU access flags.</param> /// <param name="optionFlags">The option flags.</param> /// <param name="structureByteStride">The structure byte stride.</param> public BufferDescription(int sizeInBytes, ResourceUsage usage, BindFlags bindFlags, CpuAccessFlags cpuAccessFlags, ResourceOptionFlags optionFlags, int structureByteStride) { SizeInBytes = sizeInBytes; Usage = usage; BindFlags = bindFlags; CpuAccessFlags = cpuAccessFlags; OptionFlags = optionFlags; StructureByteStride = structureByteStride; }
public RenderTargetTexture(Device device, int width, int height, Format format = Format.B8G8R8A8_UNorm, ResourceOptionFlags optionFlags = ResourceOptionFlags.None) : base(new Texture2D(device, CreateTextureDescription(width, height, format, optionFlags))) { InternalRenderTargetView = new RenderTargetView(device, InternalTexture2D); }
public TextureDesc() { MipLevels = 1; Format = Graphics.Format.UNKNOWN; SamplerDesc = Multisampling.Disable; Usage = ResourceUsage.Default; BindFlags = Graphics.BindFlags.ShaderResource; CPUAccessFlags = CpuAccessFlags.None; Options = ResourceOptionFlags.None; }
/// <summary> /// Initializes a new instance of the <see cref="ImmutableBufferProxy"/> class. /// </summary> /// <param name="structureSize">Size of the structure.</param> /// <param name="bindFlags">The bind flags.</param> /// <param name="cpuAccess">The cpu access.</param> /// <param name="optionFlags">The option flags.</param> /// <param name="usage">The usage.</param> public ImmutableBufferProxy(int structureSize, BindFlags bindFlags, CpuAccessFlags cpuAccess, ResourceOptionFlags optionFlags = ResourceOptionFlags.None, ResourceUsage usage = ResourceUsage.Immutable) : base(structureSize, bindFlags) { OptionFlags = optionFlags; Usage = usage; CpuAccess = cpuAccess; }
public static ResourceDescription Texture1D(DXGI.Format format, long width, short arraySize = 1, short mipLevels = 0, ResourceOptionFlags flags = ResourceOptionFlags.None, TextureLayout layout = TextureLayout.Unknown, long alignment = 0) { return(new ResourceDescription(ResourceDimension.Texture1D, alignment, width, 1, arraySize, mipLevels, format, 1, 0, layout, flags)); }
public void SetDefaults() { MipLevels = 1; Format = Graphics.Format.UNKNOWN; Usage = ResourceUsage.Default; BindFlags = Graphics.BindFlags.ShaderResource; CPUAccessFlags = CpuAccessFlags.None; Options = ResourceOptionFlags.None; Width = 1; ArraySize = 1; }
public D3D11Texture(Device device, ref TextureDescription description) { Width = description.Width; Height = description.Height; Depth = description.Depth; MipLevels = description.MipLevels; ArrayLayers = description.ArrayLayers; Format = description.Format; Usage = description.Usage; SharpDX.DXGI.Format dxgiFormat = D3D11Formats.ToDxgiFormat( description.Format, (description.Usage & TextureUsage.DepthStencil) == TextureUsage.DepthStencil); BindFlags bindFlags = BindFlags.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; } ResourceOptionFlags optionFlags = ResourceOptionFlags.None; int arraySize = (int)description.ArrayLayers; if ((description.Usage & TextureUsage.Cubemap) == TextureUsage.Cubemap) { optionFlags = ResourceOptionFlags.TextureCube; arraySize *= 6; } Texture2DDescription deviceDescription = new Texture2DDescription() { Width = (int)description.Width, Height = (int)description.Height, MipLevels = (int)description.MipLevels, ArraySize = arraySize, Format = dxgiFormat, BindFlags = bindFlags, CpuAccessFlags = CpuAccessFlags.None, Usage = ResourceUsage.Default, SampleDescription = new SharpDX.DXGI.SampleDescription(1, 0), OptionFlags = optionFlags, }; DeviceTexture = new Texture2D(device, deviceDescription); }
public static ResourceDescription Texture2D(DXGI.Format format, long width, int height, short arraySize = 1, short mipLevels = 0, int sampleCount = 1, int sampleQuality = 0, ResourceOptionFlags flags = ResourceOptionFlags.None, TextureLayout layout = TextureLayout.Unknown, long alignment = 0) { return(new ResourceDescription(ResourceDimension.Texture1D, alignment, width, height, arraySize, mipLevels, format, sampleCount, sampleQuality, layout, flags)); }
public ResourceDescription(ResourceDimension dimension, long alignment, long width, int height, short depthOrArraySize, short mipLevels, Format format, int sampleCount, int sampleQuality, TextureLayout layout, ResourceOptionFlags optionFlags) { Dimension = dimension; Alignment = alignment; Width = width; Height = height; DepthOrArraySize = depthOrArraySize; MipLevels = mipLevels; Format = format; SampleDescription = new SampleDescription(sampleCount, sampleQuality); Layout = layout; OptionFlags = optionFlags; }
public IDepthTexture CreateDepth(string debugName, int width, int height, Format resourceFormat, Format srvFormat, Format dsvFormat, int samplesCount = 1, int samplesQuality = 0, ResourceOptionFlags roFlags = 0, int mipmapLevels = 1, CpuAccessFlags cpuAccessFlags = CpuAccessFlags.None) { MyDepthTexture tex; m_depthTextures.AllocateOrCreate(out tex); tex.Init(debugName, width, height, resourceFormat, srvFormat, dsvFormat, BindFlags.ShaderResource | BindFlags.DepthStencil, samplesCount, samplesQuality, roFlags, ResourceUsage.Default, mipmapLevels, cpuAccessFlags); if (m_isDeviceInit) tex.OnDeviceInit(); return tex; }
/// <summary> /// Initializes a new instance of the <see cref="BufferDescription"/> struct. /// </summary> /// <param name="byteWidth">The size in bytes.</param> /// <param name="bindFlags">The bind flags.</param> /// <param name="usage">The usage.</param> /// <param name="cpuAccessFlags">The CPU access flags.</param> /// <param name="miscFlags">The option flags.</param> /// <param name="structureByteStride">The structure byte stride.</param> public BufferDescription(int byteWidth, BindFlags bindFlags, ResourceUsage usage = ResourceUsage.Default, CpuAccessFlags cpuAccessFlags = CpuAccessFlags.None, ResourceOptionFlags miscFlags = ResourceOptionFlags.None, int structureByteStride = 0) { ByteWidth = byteWidth; BindFlags = bindFlags; Usage = usage; CPUAccessFlags = cpuAccessFlags; MiscFlags = miscFlags; StructureByteStride = structureByteStride; }
public ISrvTexture CreateSrv(string debugName, int width, int height, Format format, int samplesCount = 1, int samplesQuality = 0, ResourceOptionFlags optionFlags = 0, ResourceUsage resourceUsage = ResourceUsage.Default, int mipmapLevels = 1, CpuAccessFlags cpuAccessFlags = CpuAccessFlags.None) { MySrvTexture tex; m_srvTextures.AllocateOrCreate(out tex); tex.Init(debugName, width, height, format, format, BindFlags.ShaderResource, samplesCount, samplesQuality, optionFlags, resourceUsage, mipmapLevels, cpuAccessFlags); if (m_isDeviceInit) tex.OnDeviceInit(); return tex; }
public IUavTexture CreateUav(string debugName, int width, int height, Format format, int samplesCount = 1, int samplesQuality = 0, ResourceOptionFlags roFlags = 0, int mipmapLevels = 1, CpuAccessFlags cpuAccessFlags = CpuAccessFlags.None) { MyUavTexture tex; m_uavTextures.AllocateOrCreate(out tex); tex.Init(debugName, width, height, format, format, BindFlags.ShaderResource | BindFlags.RenderTarget | BindFlags.UnorderedAccess, samplesCount, samplesQuality, roFlags, ResourceUsage.Default, mipmapLevels, cpuAccessFlags); if (m_isDeviceInit) tex.OnDeviceInit(); return tex; }
/// <summary> /// Initializes a new instance of the <see cref = "T:SharpDX.Direct3D10.Buffer" /> class. /// </summary> /// <param name = "device">The device with which to associate the buffer.</param> /// <param name = "sizeInBytes">The size, in bytes, of the buffer.</param> /// <param name = "usage">The usage pattern for the buffer.</param> /// <param name = "bindFlags">Flags specifying how the buffer will be bound to the pipeline.</param> /// <param name = "accessFlags">Flags specifying how the buffer will be accessible from the CPU.</param> /// <param name = "optionFlags">Miscellaneous resource options.</param> public Buffer(Device device, int sizeInBytes, ResourceUsage usage, BindFlags bindFlags, CpuAccessFlags accessFlags, ResourceOptionFlags optionFlags) : base(IntPtr.Zero) { var description = new BufferDescription() { BindFlags = bindFlags, CpuAccessFlags = accessFlags, OptionFlags = optionFlags, SizeInBytes = sizeInBytes, Usage = usage, }; device.CreateBuffer(ref description, null, this); }
/// <summary> /// Initializes a new instance of the <see cref = "T:SharpDX.Direct3D10.Buffer" /> class. /// </summary> /// <param name = "device">The device with which to associate the buffer.</param> /// <param name = "data">Initial data used to initialize the buffer.</param> /// <param name = "sizeInBytes">The size, in bytes, of the buffer.</param> /// <param name = "usage">The usage pattern for the buffer.</param> /// <param name = "bindFlags">Flags specifying how the buffer will be bound to the pipeline.</param> /// <param name = "accessFlags">Flags specifying how the buffer will be accessible from the CPU.</param> /// <param name = "optionFlags">Miscellaneous resource options.</param> public Buffer(Device device, DataStream data, int sizeInBytes, ResourceUsage usage, BindFlags bindFlags, CpuAccessFlags accessFlags, ResourceOptionFlags optionFlags) : base(IntPtr.Zero) { var description = new BufferDescription() { BindFlags = bindFlags, CpuAccessFlags = accessFlags, OptionFlags = optionFlags, SizeInBytes = sizeInBytes, Usage = usage, }; device.CreateBuffer(ref description, new DataBox(data.PositionPointer, 0, 0), this); }
private static Texture2DDescription CreateTextureDescription(int width, int height, Format format, ResourceOptionFlags optionFlags) { return new Texture2DDescription { ArraySize = 1, BindFlags = BindFlags.None, CpuAccessFlags = CpuAccessFlags.Read | CpuAccessFlags.Write, Format = format, Height = height, Width = width, MipLevels = 1, SampleDescription = new SampleDescription(1, 0), Usage = ResourceUsage.Staging, OptionFlags = optionFlags }; }
public ISrvTexture CreateSrv(string debugName, int width, int height, Format format, int samplesCount = 1, int samplesQuality = 0, ResourceOptionFlags optionFlags = 0, ResourceUsage resourceUsage = ResourceUsage.Default, int mipmapLevels = 1, CpuAccessFlags cpuAccessFlags = CpuAccessFlags.None) { MySrvTexture tex; m_srvTextures.AllocateOrCreate(out tex); tex.Init(debugName, width, height, format, format, BindFlags.ShaderResource, samplesCount, samplesQuality, optionFlags, resourceUsage, mipmapLevels, cpuAccessFlags); if (m_isDeviceInit) { tex.OnDeviceInit(); } return(tex); }
/// <summary> /// Initializes a new instance of the <see cref="BufferDescription"/> struct. /// </summary> /// <param name="sizeInBytes">The size in bytes.</param> /// <param name="usage">The usage.</param> /// <param name="bindFlags">The bind flags.</param> /// <param name="optionFlags">The option flags.</param> /// <param name="structureByteStride">The structure byte stride.</param> public BufferDescription(int sizeInBytes, BindFlags bindFlags, Usage usage = Usage.Default, ResourceOptionFlags optionFlags = ResourceOptionFlags.None, int structureByteStride = 0) { SizeInBytes = sizeInBytes; Usage = usage; BindFlags = bindFlags; CpuAccessFlags = CpuAccessFlags.None; if (usage == Usage.Dynamic) { CpuAccessFlags = CpuAccessFlags.Write; } else if (usage == Usage.Staging) { CpuAccessFlags = CpuAccessFlags.Read | CpuAccessFlags.Write; } OptionFlags = optionFlags; StructureByteStride = structureByteStride; }
/// <summary> /// Initializes a new instance of the <see cref="Texture2DDescription1"/> struct. /// </summary> /// <param name="format">Texture format.</param> /// <param name="width">Texture width (in texels).</param> /// <param name="height">Texture height (in texels).</param> /// <param name="arraySize">Number of textures in the array.</param> /// <param name="mipLevels">The maximum number of mipmap levels in the texture.</param> /// <param name="bindFlags">The <see cref="Vortice.Direct3D11.BindFlags"/> for binding to pipeline stages.</param> /// <param name="usage">Value that identifies how the texture is to be read from and written to.</param> /// <param name="cpuAccessFlags">The <see cref="Direct3D11.CpuAccessFlags"/> to specify the types of CPU access allowed.</param> /// <param name="sampleCount">Specifies multisampling parameters for the texture.</param> /// <param name="sampleQuality">Specifies multisampling parameters for the texture.</param> /// <param name="optionFlags">The <see cref="ResourceOptionFlags"/> that identify other, less common resource options. </param> /// <param name="textureLayout">A <see cref="TextureLayout"/> value that identifies the layout of the texture.</param> public Texture2DDescription1( Format format, int width, int height, int arraySize = 1, int mipLevels = 0, BindFlags bindFlags = BindFlags.ShaderResource, ResourceUsage usage = ResourceUsage.Default, CpuAccessFlags cpuAccessFlags = CpuAccessFlags.None, int sampleCount = 1, int sampleQuality = 0, ResourceOptionFlags optionFlags = ResourceOptionFlags.None, TextureLayout textureLayout = TextureLayout.Undefined) { if (format == Format.Unknown) { throw new ArgumentException($"format need to be valid", nameof(format)); } if (width < 1 || width > ID3D11Resource.MaximumTexture2DSize) { throw new ArgumentException($"Width need to be in range 1-{ID3D11Resource.MaximumTexture2DSize}", nameof(width)); } if (height < 1 || height > ID3D11Resource.MaximumTexture2DSize) { throw new ArgumentException($"Height need to be in range 1-{ID3D11Resource.MaximumTexture2DSize}", nameof(height)); } if (arraySize < 1 || arraySize > ID3D11Resource.MaximumTexture2DArraySize) { throw new ArgumentException($"Array size need to be in range 1-{ID3D11Resource.MaximumTexture2DArraySize}", nameof(arraySize)); } Width = width; Height = height; MipLevels = mipLevels; ArraySize = arraySize; Format = format; SampleDescription = new SampleDescription(sampleCount, sampleQuality); Usage = usage; BindFlags = bindFlags; CpuAccessFlags = cpuAccessFlags; OptionFlags = optionFlags; TextureLayout = textureLayout; }
public IDepthTexture CreateDepth(string debugName, int width, int height, Format resourceFormat, Format srvFormat, Format dsvFormat, int samplesCount = 1, int samplesQuality = 0, ResourceOptionFlags roFlags = 0, int mipmapLevels = 1, CpuAccessFlags cpuAccessFlags = CpuAccessFlags.None) { MyDepthTexture tex; m_depthTextures.AllocateOrCreate(out tex); tex.Init(debugName, width, height, resourceFormat, srvFormat, dsvFormat, BindFlags.ShaderResource | BindFlags.DepthStencil, samplesCount, samplesQuality, roFlags, ResourceUsage.Default, mipmapLevels, cpuAccessFlags); if (m_isDeviceInit) { tex.OnDeviceInit(); } return(tex); }
public IUavTexture CreateUav(string debugName, int width, int height, Format format, int samplesCount = 1, int samplesQuality = 0, ResourceOptionFlags roFlags = 0, int mipmapLevels = 1, CpuAccessFlags cpuAccessFlags = CpuAccessFlags.None) { MyUavTexture tex; m_uavTextures.AllocateOrCreate(out tex); tex.Init(debugName, width, height, format, format, BindFlags.ShaderResource | BindFlags.RenderTarget | BindFlags.UnorderedAccess, samplesCount, samplesQuality, roFlags, ResourceUsage.Default, mipmapLevels, cpuAccessFlags); if (m_isDeviceInit) { tex.OnDeviceInit(); } return(tex); }
/// <summary> /// Initializes a new instance of the <see cref="Texture3DDescription1"/> struct. /// </summary> /// <param name="format">Texture format.</param> /// <param name="width">Texture width (in texels).</param> /// <param name="height">Texture height (in texels).</param> /// <param name="depth">Texture depth (in texels).</param> /// <param name="mipLevels">The maximum number of mipmap levels in the texture.</param> /// <param name="bindFlags">The <see cref="Vortice.Direct3D11.BindFlags"/> for binding to pipeline stages.</param> /// <param name="usage">Value that identifies how the texture is to be read from and written to.</param> /// <param name="cpuAccessFlags">The <see cref="Direct3D11.CpuAccessFlags"/> to specify the types of CPU access allowed.</param> /// <param name="miscFlags">The <see cref="ResourceOptionFlags"/> that identify other, less common resource options. </param> /// <param name="textureLayout">A <see cref="TextureLayout"/> value that identifies the layout of the texture.</param> public Texture3DDescription1( Format format, int width, int height, int depth, int mipLevels = 0, BindFlags bindFlags = BindFlags.ShaderResource, ResourceUsage usage = ResourceUsage.Default, CpuAccessFlags cpuAccessFlags = CpuAccessFlags.None, ResourceOptionFlags miscFlags = ResourceOptionFlags.None, TextureLayout textureLayout = TextureLayout.Undefined) { if (format == Format.Unknown) { throw new ArgumentException($"format need to be valid", nameof(format)); } if (width < 1 || width > ID3D11Resource.MaximumTexture3DSize) { throw new ArgumentException($"Width need to be in range 1-{ID3D11Resource.MaximumTexture3DSize}", nameof(width)); } if (height < 1 || height > ID3D11Resource.MaximumTexture3DSize) { throw new ArgumentException($"Height need to be in range 1-{ID3D11Resource.MaximumTexture3DSize}", nameof(height)); } if (depth < 1 || depth > ID3D11Resource.MaximumTexture3DSize) { throw new ArgumentException($"Depth need to be in range 1-{ID3D11Resource.MaximumTexture3DSize}", nameof(depth)); } Width = width; Height = height; Depth = depth; MipLevels = mipLevels; Format = format; Usage = usage; BindFlags = bindFlags; CPUAccessFlags = cpuAccessFlags; MiscFlags = miscFlags; TextureLayout = textureLayout; }
public void Init( string name, int width, int height, Format resourceFormat, Format srvFormat, Format dsvFormat, BindFlags bindFlags, int samplesCount, int samplesQuality, ResourceOptionFlags roFlags, ResourceUsage ru, int mipmapLevels, CpuAccessFlags cpuAccessFlags) { base.Init(name, width, height, resourceFormat, srvFormat, bindFlags, samplesCount, samplesQuality, roFlags, ru, mipmapLevels, cpuAccessFlags); m_dsvFormat = dsvFormat; }
public static Texture2DDescription Desc(int width, int height, Format format = Format.B8G8R8A8_UNorm, BindFlags bindFlags = BindFlags.ShaderResource | BindFlags.RenderTarget, ResourceUsage usage = ResourceUsage.Default, ResourceOptionFlags resourceOptionFlags = ResourceOptionFlags.None, CpuAccessFlags cpuAccessFlags = CpuAccessFlags.None) { return(new Texture2DDescription() { Usage = usage, BindFlags = bindFlags, Format = format, Width = width, Height = height, CpuAccessFlags = cpuAccessFlags, OptionFlags = resourceOptionFlags, SampleDescription = new SampleDescription(1, 0), ArraySize = 1, MipLevels = 1 }); }
public static void CreateDDSTextureFromMemoryEx(Device d3dDevice, DirectDrawSurface dds, int maxsize, ResourceUsage usage, BindFlags bindFlags, CpuAccessFlags cpuAccessFlags, ResourceOptionFlags miscFlags, bool forceSRGB, out Resource texture, out ShaderResourceView textureView, out DDS_AlphaMode alphaMode) { texture = null; textureView = null; alphaMode = DDS_AlphaMode.Unknown; if (d3dDevice == null) { throw new ArgumentNullException("d3dDevice"); } if (dds == null && !dds.Header.HasValue) { throw new ArgumentNullException("dds"); } try { var result = CreateTextureFromDDS(d3dDevice, null, dds.Header.Value, dds.HeaderDXT10, dds.Data, dds.DataLength, maxsize, usage, bindFlags, cpuAccessFlags, miscFlags, forceSRGB, out texture, out textureView); if (result.Success) { texture.DebugName = "DDSTextureLoader"; textureView.DebugName = "DDSTextureLoader"; alphaMode = dds.AlphaMode; } } finally { } }
/// <summary> /// Creates a new instance of the DrawingLayer /// </summary> /// <param name="directCanvasFactory">The factory that the DrawingLayer belongs to</param> /// <param name="width">The pixel size in width to make the D3D texture</param> /// <param name="height">The pixel size in height to make the D3D texture</param> /// <param name="format">The color format to make the D3D texture</param> /// <param name="optionFlags">Option flags to use on the creation of the D3D texture</param> internal DrawingLayer(DirectCanvasFactory directCanvasFactory, int width, int height, Format format = Format.B8G8R8A8_UNorm, ResourceOptionFlags optionFlags = ResourceOptionFlags.None) { m_directCanvasFactory = directCanvasFactory; m_format = format; m_drawStateManagement = new DrawStateManagement(); var device = m_directCanvasFactory.DeviceContext.Device; /* Create our Direct3D texture */ RenderTargetTexture = new RenderTargetTexture(device, width, height, m_format, optionFlags); /* Create the Direct2D render target, using our Direct3D texture we just created */ D2DRenderTarget = new Direct2DRenderTarget(m_directCanvasFactory.DeviceContext, m_renderTargetTexture.InternalDxgiSurface, m_format); }