Class Texture
Class used for all Textures (1D, 2D, 3D, DepthStencil, RenderTargets...etc.)
[DataSerializerGlobal(typeof(ReferenceSerializer<Texture>), null, DataSerializerGenericMode.None, false, false, Profile = "Content")]
[ContentSerializer(typeof(TextureContentSerializer))]
[ContentSerializer(typeof(TextureImageSerializer))]
[DataSerializer(typeof(TextureSerializer))]
public sealed class Texture : GraphicsResource, IDisposable, IComponent, IReferencable, ICollectorHolder
- Inheritance
-
objectTexture
- Implements
- Inherited Members
- Extension Methods
Constructors
Texture()
public Texture()
Properties
ArraySize
Number of textures in the array.
public int ArraySize { get; }
Property Value
- int
The size of the array.
Remarks
This field is only valid for 1D, 2D and Cube Texture.
ArraySlice
The array index of this texture view.
public int ArraySlice { get; }
Property Value
- int
The array slice.
Depth
The depth of the texture.
public int Depth { get; }
Property Value
- int
The depth.
Description
Common description for the original texture. See remarks.
public TextureDescription Description { get; }
Property Value
Remarks
This field and the properties in TextureDessciption must be considered as readonly when accessing from this instance.
Dimension
The dimension of a texture.
public TextureDimension Dimension { get; }
Property Value
Flags
Texture flags.
public TextureFlags Flags { get; }
Property Value
Format
Texture format (see PixelFormat)
public PixelFormat Format { get; }
Property Value
- PixelFormat
The format.
FullQualitySize
When texture streaming is activated, the size of the texture when loaded at full quality.
public Size3 FullQualitySize { get; }
Property Value
Height
The height of the texture.
public int Height { get; }
Property Value
- int
The height.
IsBlockCompressed
Gets a boolean indicating whether this Texture is a using a block compress format (BC1, BC2, BC3, BC4, BC5, BC6H, BC7).
public bool IsBlockCompressed { get; }
Property Value
IsDepthStencil
Gets a value indicating whether this instance is a depth stencil.
public bool IsDepthStencil { get; }
Property Value
- bool
trueif this instance is a depth stencil; otherwise,false.
IsDepthStencilReadOnly
Gets a value indicating whether this instance is a depth stencil readonly.
public bool IsDepthStencilReadOnly { get; }
Property Value
- bool
trueif this instance is a depth stencil readonly; otherwise,false.
IsMultisample
Gets a value indicating whether this instance is a multi sample texture.
public bool IsMultisample { get; }
Property Value
- bool
trueif this instance is multi sample texture; otherwise,false.
IsRenderTarget
Gets a value indicating whether this instance is a render target.
public bool IsRenderTarget { get; }
Property Value
- bool
trueif this instance is render target; otherwise,false.
IsShaderResource
Gets a value indicating whether this instance is a shader resource.
public bool IsShaderResource { get; }
Property Value
- bool
trueif this instance is a shader resource; otherwise,false.
IsUnorderedAccess
Gets a value indicating whether this instance is a shader resource.
public bool IsUnorderedAccess { get; }
Property Value
- bool
trueif this instance is a shader resource; otherwise,false.
MipLevel
The miplevel index of this texture view.
public int MipLevel { get; }
Property Value
- int
The mip level.
MipLevels
The maximum number of mipmap levels in the texture.
public int MipLevels { get; }
Property Value
- int
The mip levels.
MultisampleCount
Structure that specifies multisampling parameters for the texture.
public MultisampleCount MultisampleCount { get; }
Property Value
- MultisampleCount
The multi sample level.
Remarks
This field is only valid for a 2D Texture.
Options
Resource options for DirectX 11 textures.
public TextureOptions Options { get; }
Property Value
SharedHandle
The shared handle if created with TextureOption.Shared or TextureOption.SharedNthandle, IntPtr.Zero otherwise.
public nint SharedHandle { get; }
Property Value
SharedNtHandleName
Gets the name of the shared Nt handle when created with TextureOption.SharedNthandle.
public string SharedNtHandleName { get; }
Property Value
Size
Gets the size of this texture.
public Size3 Size { get; }
Property Value
- Size3
The size.
Usage
Value that identifies how the texture is to be read from and written to.
public GraphicsResourceUsage Usage { get; }
Property Value
ViewDepth
The depth of this texture view.
public int ViewDepth { get; }
Property Value
- int
The view depth.
ViewDescription
Gets the view description.
public TextureViewDescription ViewDescription { get; }
Property Value
- TextureViewDescription
The view description.
ViewDimension
The dimension of the texture view.
public TextureDimension ViewDimension { get; }
Property Value
ViewFlags
The format of this texture view.
public TextureFlags ViewFlags { get; }
Property Value
- TextureFlags
The type of the view.
ViewFormat
The format of this texture view.
public PixelFormat ViewFormat { get; }
Property Value
- PixelFormat
The view format.
ViewHeight
The height of this texture view.
public int ViewHeight { get; }
Property Value
- int
The height of the view.
ViewType
The format of this texture view.
public ViewType ViewType { get; }
Property Value
- ViewType
The type of the view.
ViewWidth
The width of this texture view.
public int ViewWidth { get; }
Property Value
- int
The width of the view.
Width
The width of the texture.
public int Width { get; }
Property Value
- int
The width.
Methods
CalculateMipLevels(int, MipMapCount)
Calculates the number of miplevels for a Texture 1D.
public static int CalculateMipLevels(int width, MipMapCount mipLevels)
Parameters
widthintThe width of the texture.
mipLevelsMipMapCountA MipMapCount, set to true to calculates all mipmaps, to false to calculate only 1 miplevel, or > 1 to calculate a specific amount of levels.
Returns
- int
The number of miplevels.
CalculateMipLevels(int, int, MipMapCount)
Calculates the number of miplevels for a Texture 2D.
public static int CalculateMipLevels(int width, int height, MipMapCount mipLevels)
Parameters
widthintThe width of the texture.
heightintThe height of the texture.
mipLevelsMipMapCountA MipMapCount, set to true to calculates all mipmaps, to false to calculate only 1 miplevel, or > 1 to calculate a specific amount of levels.
Returns
- int
The number of miplevels.
CalculateMipLevels(int, int, int, MipMapCount)
Calculates the number of miplevels for a Texture 2D.
public static int CalculateMipLevels(int width, int height, int depth, MipMapCount mipLevels)
Parameters
widthintThe width of the texture.
heightintThe height of the texture.
depthintThe depth of the texture.
mipLevelsMipMapCountA MipMapCount, set to true to calculates all mipmaps, to false to calculate only 1 miplevel, or > 1 to calculate a specific amount of levels.
Returns
- int
The number of miplevels.
CalculateMipSize(int, int)
Calculates the size of a particular mip.
public static int CalculateMipSize(int size, int mipLevel)
Parameters
Returns
- int
System.Int32.
CalculatePixelDataCount<TData>(int)
Calculates the number of pixel data this texture is requiring for a particular mip level.
public int CalculatePixelDataCount<TData>(int mipLevel = 0) where TData : unmanaged
Parameters
mipLevelintThe mip level.
Returns
- int
The number of pixel data.
Type Parameters
TDataThe type of the T pixel data.
Remarks
This method is used to allocated a texture data buffer to hold pixel datas: var textureData = new T[ texture.CalculatePixelCount<T>() ] ;.
CalculateWidth<TData>(int)
Calculates the expected width of a texture using a specified type.
public int CalculateWidth<TData>(int mipLevel = 0) where TData : unmanaged
Parameters
mipLevelint
Returns
- int
The expected width
Type Parameters
TDataThe type of the T pixel data.
Exceptions
- ArgumentException
If the size is invalid
Clone()
Makes a copy of this texture.
public Texture Clone()
Returns
- Texture
A copy of this texture.
Remarks
This method doesn't copy the content of the texture.
CountMips(int)
public static int CountMips(int width)
Parameters
widthint
Returns
CountMips(int, int)
public static int CountMips(int width, int height)
Parameters
Returns
CountMips(int, int, int)
public static int CountMips(int width, int height, int depth)
Parameters
Returns
Destroy()
Disposes of object resources.
protected override void Destroy()
GetData(CommandList, Texture, DataPointer, int, int, bool)
Copies the content of this texture from GPU memory to a pointer on CPU memory using a specific staging resource.
[Obsolete("Use span instead")]
public bool GetData(CommandList commandList, Texture stagingTexture, DataPointer toData, int arraySlice = 0, int mipSlice = 0, bool doNotWait = false)
Parameters
commandListCommandListThe command list.
stagingTextureTextureThe staging texture used to transfer the texture to.
toDataDataPointerThe pointer to data in CPU memory.
arraySliceintThe array slice index. This value must be set to 0 for Texture 3D.
mipSliceintThe mip slice index.
doNotWaitboolif set to
truethis method will return immediately if the resource is still being used by the GPU for writing. Default is false
Returns
- bool
trueif data was correctly retrieved,falseifdoNotWaitflag was true and the resource is still being used by the GPU for writing.
Remarks
This method is only working when called from the main thread that is accessing the main GraphicsDevice.
Exceptions
- ArgumentException
When strides is different from optimal strides, and TData is not the same size as the pixel format, or Width * Height != toData.Length
GetDataAsImage(CommandList)
Gets the GPU content of this texture as an Image on the CPU.
public Image GetDataAsImage(CommandList commandList)
Parameters
commandListCommandList
Returns
GetDataAsImage(CommandList, Texture)
Gets the GPU content of this texture to an Image on the CPU.
public Image GetDataAsImage(CommandList commandList, Texture stagingTexture)
Parameters
commandListCommandListThe command list.
stagingTextureTextureThe staging texture used to temporary transfer the image from the GPU to CPU.
Returns
Exceptions
- ArgumentException
If stagingTexture is not a staging texture.
GetData<T>(CommandList, Texture, Span<T>, int, int, bool)
Copies the content of this texture from GPU memory to a pointer on CPU memory using a specific staging resource.
public bool GetData<T>(CommandList commandList, Texture stagingTexture, Span<T> toData, int arraySlice = 0, int mipSlice = 0, bool doNotWait = false) where T : unmanaged
Parameters
commandListCommandListThe command list.
stagingTextureTextureThe staging texture used to transfer the texture to.
toDataSpan<T>The pointer to data in CPU memory.
arraySliceintThe array slice index. This value must be set to 0 for Texture 3D.
mipSliceintThe mip slice index.
doNotWaitboolif set to
truethis method will return immediately if the resource is still being used by the GPU for writing. Default is false
Returns
- bool
trueif data was correctly retrieved,falseifdoNotWaitflag was true and the resource is still being used by the GPU for writing.
Type Parameters
T
Remarks
This method is only working when called from the main thread that is accessing the main GraphicsDevice.
Exceptions
- ArgumentException
When strides is different from optimal strides, and TData is not the same size as the pixel format, or Width * Height != toData.Length
GetData<TData>(CommandList, Texture, TData[], int, int, bool)
Copies the content of this texture from GPU memory to an array of data on CPU memory using a specific staging resource.
public bool GetData<TData>(CommandList commandList, Texture stagingTexture, TData[] toData, int arraySlice = 0, int mipSlice = 0, bool doNotWait = false) where TData : unmanaged
Parameters
commandListCommandListThe command list.
stagingTextureTextureThe staging texture used to transfer the texture to.
toDataTData[]To data.
arraySliceintThe array slice index. This value must be set to 0 for Texture 3D.
mipSliceintThe mip slice index.
doNotWaitboolif set to
truethis method will return immediately if the resource is still being used by the GPU for writing. Default is false
Returns
- bool
trueif data was correctly retrieved,falseifdoNotWaitflag was true and the resource is still being used by the GPU for writing.
Type Parameters
TDataThe type of the T data.
Remarks
This method is only working when called from the main thread that is accessing the main GraphicsDevice.
Exceptions
- ArgumentException
When strides is different from optimal strides, and TData is not the same size as the pixel format, or Width * Height != toData.Length
GetData<TData>(CommandList, int, int)
Gets the content of this texture to an array of data.
public TData[] GetData<TData>(CommandList commandList, int arraySlice = 0, int mipSlice = 0) where TData : unmanaged
Parameters
commandListCommandListThe command list.
arraySliceintThe array slice index. This value must be set to 0 for Texture 3D.
mipSliceintThe mip slice index.
Returns
- TData[]
The texture data.
Type Parameters
TDataThe type of the T data.
Remarks
This method is only working when called from the main thread that is accessing the main GraphicsDevice. This method creates internally a stagging resource, copies to it and map it to memory. Use method with explicit staging resource for optimal performances.
GetData<TData>(CommandList, TData[], int, int, bool)
Copies the content of this texture to an array of data.
public bool GetData<TData>(CommandList commandList, TData[] toData, int arraySlice = 0, int mipSlice = 0, bool doNotWait = false) where TData : unmanaged
Parameters
commandListCommandListThe command list.
toDataTData[]The destination buffer to receive a copy of the texture datas.
arraySliceintThe array slice index. This value must be set to 0 for Texture 3D.
mipSliceintThe mip slice index.
doNotWaitboolif set to
truethis method will return immediately if the resource is still being used by the GPU for writing. Default is false
Returns
- bool
trueif data was correctly retrieved,falseifdoNotWaitflag was true and the resource is still being used by the GPU for writing.
Type Parameters
TDataThe type of the T data.
Remarks
This method is only working when called from the main thread that is accessing the main GraphicsDevice. This method creates internally a stagging resource if this texture is not already a stagging resouce, copies to it and map it to memory. Use method with explicit staging resource for optimal performances.
GetMipMapDescription(int)
Gets the mipmap description of this instance for the specified mipmap level.
public MipMapDescription GetMipMapDescription(int mipmap)
Parameters
mipmapintThe mipmap.
Returns
- MipMapDescription
A description of a particular mipmap for this texture.
GetSubResourceIndex(int, int)
Gets the absolute sub-resource index from the array and mip slice.
public int GetSubResourceIndex(int arraySlice, int mipSlice)
Parameters
Returns
- int
A value equals to arraySlice * Description.MipLevels + mipSlice.
IsDepthStencilReadOnlySupported(GraphicsDevice)
public static bool IsDepthStencilReadOnlySupported(GraphicsDevice device)
Parameters
deviceGraphicsDevice
Returns
Load(GraphicsDevice, Stream, TextureFlags, GraphicsResourceUsage, bool)
Loads a texture from a stream.
public static Texture Load(GraphicsDevice device, Stream stream, TextureFlags textureFlags = TextureFlags.ShaderResource, GraphicsResourceUsage usage = GraphicsResourceUsage.Immutable, bool loadAsSRGB = false)
Parameters
deviceGraphicsDeviceThe GraphicsDevice.
streamStreamThe stream to load the texture from.
textureFlagsTextureFlagsTrue to load the texture with unordered access enabled. Default is false.
usageGraphicsResourceUsageUsage of the resource. Default is Immutable
loadAsSRGBboolIndicate if the texture should be loaded as an sRGB texture. If false, the texture is load in its default format.
Returns
- Texture
A texture
New(GraphicsDevice, Image, TextureFlags, GraphicsResourceUsage)
Loads a texture from a stream.
public static Texture New(GraphicsDevice device, Image image, TextureFlags textureFlags = TextureFlags.ShaderResource, GraphicsResourceUsage usage = GraphicsResourceUsage.Immutable)
Parameters
deviceGraphicsDeviceThe GraphicsDevice.
imageImageThe image.
textureFlagsTextureFlagsTrue to load the texture with unordered access enabled. Default is false.
usageGraphicsResourceUsageUsage of the resource. Default is Immutable
Returns
- Texture
A texture
Exceptions
- InvalidOperationException
Dimension not supported
New(GraphicsDevice, TextureDescription, params DataBox[])
Creates a new texture with the specified generic texture description.
public static Texture New(GraphicsDevice graphicsDevice, TextureDescription description, params DataBox[] boxes)
Parameters
graphicsDeviceGraphicsDeviceThe graphics device.
descriptionTextureDescriptionThe description.
boxesDataBox[]The data boxes.
Returns
- Texture
A Texture instance, either a RenderTarget or DepthStencilBuffer or Texture, depending on Binding flags.
Exceptions
- ArgumentNullException
graphicsDevice
New(GraphicsDevice, TextureDescription, TextureViewDescription, params DataBox[])
Creates a new texture with the specified generic texture description.
public static Texture New(GraphicsDevice graphicsDevice, TextureDescription description, TextureViewDescription viewDescription, params DataBox[] boxes)
Parameters
graphicsDeviceGraphicsDeviceThe graphics device.
descriptionTextureDescriptionThe description.
viewDescriptionTextureViewDescriptionThe view description.
boxesDataBox[]The data boxes.
Returns
- Texture
A Texture instance, either a RenderTarget or DepthStencilBuffer or Texture, depending on Binding flags.
Exceptions
- ArgumentNullException
graphicsDevice
New1D(GraphicsDevice, int, MipMapCount, PixelFormat, TextureFlags, int, GraphicsResourceUsage)
Creates a new 1D Texture.
public static Texture New1D(GraphicsDevice device, int width, MipMapCount mipCount, PixelFormat format, TextureFlags textureFlags = TextureFlags.ShaderResource, int arraySize = 1, GraphicsResourceUsage usage = GraphicsResourceUsage.Default)
Parameters
deviceGraphicsDeviceThe GraphicsDevice.
widthintThe width.
mipCountMipMapCountNumber of mipmaps, set to true to have all mipmaps, set to an int >=1 for a particular mipmap count.
formatPixelFormatDescribes the format to use.
textureFlagsTextureFlagstrue if the texture needs to support unordered read write.
arraySizeintSize of the texture 2D array, default to 1.
usageGraphicsResourceUsageThe usage.
Returns
New1D(GraphicsDevice, int, PixelFormat, TextureFlags, int, GraphicsResourceUsage)
Creates a new 1D Texture with a single mipmap.
public static Texture New1D(GraphicsDevice device, int width, PixelFormat format, TextureFlags textureFlags = TextureFlags.ShaderResource, int arraySize = 1, GraphicsResourceUsage usage = GraphicsResourceUsage.Default)
Parameters
deviceGraphicsDeviceThe GraphicsDevice.
widthintThe width.
formatPixelFormatDescribes the format to use.
textureFlagsTextureFlagstrue if the texture needs to support unordered read write.
arraySizeintSize of the texture 2D array, default to 1.
usageGraphicsResourceUsageThe usage.
Returns
New1D(GraphicsDevice, int, PixelFormat, nint, TextureFlags, GraphicsResourceUsage)
Creates a new 1D Texture with a single level of mipmap.
public static Texture New1D(GraphicsDevice device, int width, PixelFormat format, nint dataPtr, TextureFlags textureFlags = TextureFlags.ShaderResource, GraphicsResourceUsage usage = GraphicsResourceUsage.Immutable)
Parameters
deviceGraphicsDeviceThe GraphicsDevice.
widthintThe width.
formatPixelFormatDescribes the format to use.
dataPtrnintData ptr
textureFlagsTextureFlagstrue if the texture needs to support unordered read write.
usageGraphicsResourceUsageThe usage.
Returns
Remarks
The first dimension of mipMapTextures describes the number of array (Texture Array), second dimension is the mipmap, the third is the texture data for a particular mipmap.
New1D<T>(GraphicsDevice, int, PixelFormat, T[], TextureFlags, GraphicsResourceUsage)
Creates a new 1D Texture with a single level of mipmap.
public static Texture New1D<T>(GraphicsDevice device, int width, PixelFormat format, T[] textureData, TextureFlags textureFlags = TextureFlags.ShaderResource, GraphicsResourceUsage usage = GraphicsResourceUsage.Immutable) where T : unmanaged
Parameters
deviceGraphicsDeviceThe GraphicsDevice.
widthintThe width.
formatPixelFormatDescribes the format to use.
textureDataT[]Texture data. Size of must be equal to sizeof(Format) * width
textureFlagsTextureFlagstrue if the texture needs to support unordered read write.
usageGraphicsResourceUsageThe usage.
Returns
Type Parameters
TType of the initial data to upload to the texture
Remarks
The first dimension of mipMapTextures describes the number of array (Texture Array), second dimension is the mipmap, the third is the texture data for a particular mipmap.
New2D(GraphicsDevice, int, int, MipMapCount, PixelFormat, DataBox[], TextureFlags, int, GraphicsResourceUsage, MultisampleCount, TextureOptions)
Creates a new 2D Texture.
public static Texture New2D(GraphicsDevice device, int width, int height, MipMapCount mipCount, PixelFormat format, DataBox[] textureData, TextureFlags textureFlags = TextureFlags.ShaderResource, int arraySize = 1, GraphicsResourceUsage usage = GraphicsResourceUsage.Default, MultisampleCount multisampleCount = MultisampleCount.None, TextureOptions options = TextureOptions.None)
Parameters
deviceGraphicsDeviceThe GraphicsDevice.
widthintThe width.
heightintThe height.
mipCountMipMapCountNumber of mipmaps, set to true to have all mipmaps, set to an int >=1 for a particular mipmap count.
formatPixelFormatDescribes the format to use.
textureDataDataBox[]Texture datas through an array of DataBox
textureFlagsTextureFlagstrue if the texture needs to support unordered read write.
arraySizeintSize of the texture 2D array, default to 1.
usageGraphicsResourceUsageThe usage.
multisampleCountMultisampleCountThe multisample count.
optionsTextureOptionsThe options, e.g. sharing
Returns
New2D(GraphicsDevice, int, int, MipMapCount, PixelFormat, TextureFlags, int, GraphicsResourceUsage, TextureOptions)
Creates a new 2D Texture.
public static Texture New2D(GraphicsDevice device, int width, int height, MipMapCount mipCount, PixelFormat format, TextureFlags textureFlags = TextureFlags.ShaderResource, int arraySize = 1, GraphicsResourceUsage usage = GraphicsResourceUsage.Default, TextureOptions options = TextureOptions.None)
Parameters
deviceGraphicsDeviceThe GraphicsDevice.
widthintThe width.
heightintThe height.
mipCountMipMapCountNumber of mipmaps, set to true to have all mipmaps, set to an int >=1 for a particular mipmap count.
formatPixelFormatDescribes the format to use.
textureFlagsTextureFlagstrue if the texture needs to support unordered read write.
arraySizeintSize of the texture 2D array, default to 1.
usageGraphicsResourceUsageThe usage.
optionsTextureOptions
Returns
New2D(GraphicsDevice, int, int, PixelFormat, TextureFlags, int, GraphicsResourceUsage, TextureOptions)
Creates a new 2D Texture with a single mipmap.
public static Texture New2D(GraphicsDevice device, int width, int height, PixelFormat format, TextureFlags textureFlags = TextureFlags.ShaderResource, int arraySize = 1, GraphicsResourceUsage usage = GraphicsResourceUsage.Default, TextureOptions options = TextureOptions.None)
Parameters
deviceGraphicsDeviceThe GraphicsDevice.
widthintThe width.
heightintThe height.
formatPixelFormatDescribes the format to use.
textureFlagsTextureFlagstrue if the texture needs to support unordered read write.
arraySizeintSize of the texture 2D array, default to 1.
usageGraphicsResourceUsageThe usage.
optionsTextureOptions
Returns
New2D<T>(GraphicsDevice, int, int, PixelFormat, T[], TextureFlags, GraphicsResourceUsage, TextureOptions)
Creates a new 2D Texture with a single level of mipmap.
public static Texture New2D<T>(GraphicsDevice device, int width, int height, PixelFormat format, T[] textureData, TextureFlags textureFlags = TextureFlags.ShaderResource, GraphicsResourceUsage usage = GraphicsResourceUsage.Immutable, TextureOptions options = TextureOptions.None) where T : unmanaged
Parameters
deviceGraphicsDeviceThe GraphicsDevice.
widthintThe width.
heightintThe height.
formatPixelFormatDescribes the format to use.
textureDataT[]The texture data for a single mipmap and a single array slice. See remarks
textureFlagsTextureFlagstrue if the texture needs to support unordered read write.
usageGraphicsResourceUsageThe usage.
optionsTextureOptions
Returns
Type Parameters
TType of the pixel data to upload to the texture.
Remarks
Each value in textureData is a pixel in the destination texture.
New3D(GraphicsDevice, int, int, int, MipMapCount, PixelFormat, DataBox[], TextureFlags, GraphicsResourceUsage)
Creates a new 3D Texture.
public static Texture New3D(GraphicsDevice device, int width, int height, int depth, MipMapCount mipCount, PixelFormat format, DataBox[] textureData, TextureFlags textureFlags = TextureFlags.ShaderResource, GraphicsResourceUsage usage = GraphicsResourceUsage.Default)
Parameters
deviceGraphicsDeviceThe GraphicsDevice.
widthintThe width.
heightintThe height.
depthintThe depth.
mipCountMipMapCountNumber of mipmaps, set to true to have all mipmaps, set to an int >=1 for a particular mipmap count.
formatPixelFormatDescribes the format to use.
textureDataDataBox[]textureFlagsTextureFlagstrue if the texture needs to support unordered read write.
usageGraphicsResourceUsageThe usage.
Returns
New3D(GraphicsDevice, int, int, int, MipMapCount, PixelFormat, TextureFlags, GraphicsResourceUsage)
Creates a new 3D Texture.
public static Texture New3D(GraphicsDevice device, int width, int height, int depth, MipMapCount mipCount, PixelFormat format, TextureFlags textureFlags = TextureFlags.ShaderResource, GraphicsResourceUsage usage = GraphicsResourceUsage.Default)
Parameters
deviceGraphicsDeviceThe GraphicsDevice.
widthintThe width.
heightintThe height.
depthintThe depth.
mipCountMipMapCountNumber of mipmaps, set to true to have all mipmaps, set to an int >=1 for a particular mipmap count.
formatPixelFormatDescribes the format to use.
textureFlagsTextureFlagstrue if the texture needs to support unordered read write.
usageGraphicsResourceUsageThe usage.
Returns
New3D(GraphicsDevice, int, int, int, PixelFormat, TextureFlags, GraphicsResourceUsage)
Creates a new 3D Texture with a single mipmap.
public static Texture New3D(GraphicsDevice device, int width, int height, int depth, PixelFormat format, TextureFlags textureFlags = TextureFlags.ShaderResource, GraphicsResourceUsage usage = GraphicsResourceUsage.Default)
Parameters
deviceGraphicsDeviceThe GraphicsDevice.
widthintThe width.
heightintThe height.
depthintThe depth.
formatPixelFormatDescribes the format to use.
textureFlagsTextureFlagstrue if the texture needs to support unordered read write.
usageGraphicsResourceUsageThe usage.
Returns
New3D<T>(GraphicsDevice, int, int, int, PixelFormat, T[], TextureFlags, GraphicsResourceUsage)
Creates a new 3D Texture with texture data for the firs map.
public static Texture New3D<T>(GraphicsDevice device, int width, int height, int depth, PixelFormat format, T[] textureData, TextureFlags textureFlags = TextureFlags.ShaderResource, GraphicsResourceUsage usage = GraphicsResourceUsage.Immutable) where T : unmanaged
Parameters
deviceGraphicsDeviceThe GraphicsDevice.
widthintThe width.
heightintThe height.
depthintThe depth.
formatPixelFormatDescribes the format to use.
textureDataT[]The texture data, width * height * depth datas
textureFlagsTextureFlagstrue if the texture needs to support unordered read write.
usageGraphicsResourceUsageThe usage.
Returns
Type Parameters
TType of the data to upload to the texture
Remarks
The first dimension of mipMapTextures describes the number of is an array ot Texture3D Array
NewCube(GraphicsDevice, int, MipMapCount, PixelFormat, TextureFlags, GraphicsResourceUsage)
Creates a new Cube Texture.
public static Texture NewCube(GraphicsDevice device, int size, MipMapCount mipCount, PixelFormat format, TextureFlags textureFlags = TextureFlags.ShaderResource, GraphicsResourceUsage usage = GraphicsResourceUsage.Default)
Parameters
deviceGraphicsDeviceThe GraphicsDevice.
sizeintThe size (in pixels) of the top-level faces of the cube texture.
mipCountMipMapCountNumber of mipmaps, set to true to have all mipmaps, set to an int >=1 for a particular mipmap count.
formatPixelFormatDescribes the format to use.
textureFlagsTextureFlagsThe texture flags.
usageGraphicsResourceUsageThe usage.
Returns
NewCube(GraphicsDevice, int, PixelFormat, DataBox[], TextureFlags, GraphicsResourceUsage)
Creates a new Cube Texture from a initial data..
public static Texture NewCube(GraphicsDevice device, int size, PixelFormat format, DataBox[] textureData, TextureFlags textureFlags = TextureFlags.ShaderResource, GraphicsResourceUsage usage = GraphicsResourceUsage.Immutable)
Parameters
deviceGraphicsDeviceThe GraphicsDevice.
sizeintThe size (in pixels) of the top-level faces of the cube texture.
formatPixelFormatDescribes the format to use.
textureDataDataBox[]an array of 6 textures. See remarks
textureFlagsTextureFlagsThe texture flags.
usageGraphicsResourceUsageThe usage.
Returns
Remarks
The first dimension of mipMapTextures describes the number of array (TextureCube Array), the second is the texture data for a particular cube face.
Exceptions
- ArgumentException
Invalid texture datas. First dimension must be equal to 6;textureData
NewCube(GraphicsDevice, int, PixelFormat, TextureFlags, GraphicsResourceUsage)
Creates a new Cube Texture.
public static Texture NewCube(GraphicsDevice device, int size, PixelFormat format, TextureFlags textureFlags = TextureFlags.ShaderResource, GraphicsResourceUsage usage = GraphicsResourceUsage.Default)
Parameters
deviceGraphicsDeviceThe GraphicsDevice.
sizeintThe size (in pixels) of the top-level faces of the cube texture.
formatPixelFormatDescribes the format to use.
textureFlagsTextureFlagsThe texture flags.
usageGraphicsResourceUsageThe usage.
Returns
NewCube<T>(GraphicsDevice, int, PixelFormat, T[][], TextureFlags, GraphicsResourceUsage)
Creates a new Cube Texture from a initial data..
public static Texture NewCube<T>(GraphicsDevice device, int size, PixelFormat format, T[][] textureData, TextureFlags textureFlags = TextureFlags.ShaderResource, GraphicsResourceUsage usage = GraphicsResourceUsage.Immutable) where T : unmanaged
Parameters
deviceGraphicsDeviceThe GraphicsDevice.
sizeintThe size (in pixels) of the top-level faces of the cube texture.
formatPixelFormatDescribes the format to use.
textureDataT[][]an array of 6 textures. See remarks
textureFlagsTextureFlagsThe texture flags.
usageGraphicsResourceUsageThe usage.
Returns
Type Parameters
TType of a pixel data
Remarks
The first dimension of mipMapTextures describes the number of array (TextureCube Array), the second is the texture data for a particular cube face.
Exceptions
- ArgumentException
Invalid texture datas. First dimension must be equal to 6;textureData
OnDestroyed()
Called when graphics device has been detected to be internally destroyed.
protected override void OnDestroyed()
OnRecreate()
Called when graphics device has been recreated.
protected override bool OnRecreate()
Returns
Recreate(DataBox[])
public void Recreate(DataBox[] dataBoxes = null)
Parameters
dataBoxesDataBox[]
ReleaseData()
Releases the texture data.
public void ReleaseData()
Save(CommandList, Stream, ImageFileType)
Saves this texture to a stream with a specified format.
public void Save(CommandList commandList, Stream stream, ImageFileType fileType)
Parameters
commandListCommandListThe command list.
streamStreamThe stream.
fileTypeImageFileTypeType of the image file.
Save(CommandList, Stream, Texture, ImageFileType)
Saves this texture to a stream with a specified format.
public void Save(CommandList commandList, Stream stream, Texture stagingTexture, ImageFileType fileType)
Parameters
commandListCommandListThe command list.
streamStreamThe stream.
stagingTextureTextureThe staging texture used to temporary transfer the image from the GPU to CPU.
fileTypeImageFileTypeType of the image file.
Exceptions
- ArgumentException
If stagingTexture is not a staging texture.
SetData(CommandList, DataPointer, int, int, ResourceRegion?)
Copies the content an data on CPU memory to this texture into GPU memory.
[Obsolete("Use span instead")]
public void SetData(CommandList commandList, DataPointer fromData, int arraySlice = 0, int mipSlice = 0, ResourceRegion? region = null)
Parameters
commandListCommandListThe CommandList.
fromDataDataPointerThe data to copy from.
arraySliceintThe array slice index. This value must be set to 0 for Texture 3D.
mipSliceintThe mip slice index.
regionResourceRegion?Destination region
Remarks
See unmanaged documentation for usage and restrictions.
Exceptions
- ArgumentException
When strides is different from optimal strides, and TData is not the same size as the pixel format, or Width * Height != toData.Length
SetData<T>(CommandList, Span<T>, int, int, ResourceRegion?)
Copies the content an data on CPU memory to this texture into GPU memory.
public void SetData<T>(CommandList commandList, Span<T> fromData, int arraySlice = 0, int mipSlice = 0, ResourceRegion? region = null) where T : unmanaged
Parameters
commandListCommandListThe CommandList.
fromDataSpan<T>The data to copy from.
arraySliceintThe array slice index. This value must be set to 0 for Texture 3D.
mipSliceintThe mip slice index.
regionResourceRegion?Destination region
Type Parameters
T
Remarks
See unmanaged documentation for usage and restrictions.
Exceptions
- ArgumentException
When strides is different from optimal strides, and TData is not the same size as the pixel format, or Width * Height != toData.Length
SetData<TData>(CommandList, TData[], int, int, ResourceRegion?)
Copies the content an array of data on CPU memory to this texture into GPU memory using the specified GraphicsDevice (The graphics device could be deffered).
public void SetData<TData>(CommandList commandList, TData[] fromData, int arraySlice = 0, int mipSlice = 0, ResourceRegion? region = null) where TData : unmanaged
Parameters
commandListCommandListThe command list.
fromDataTData[]The data to copy from.
arraySliceintThe array slice index. This value must be set to 0 for Texture 3D.
mipSliceintThe mip slice index.
regionResourceRegion?Destination region
Type Parameters
TDataThe type of the T data.
Remarks
See unmanaged documentation for usage and restrictions.
Exceptions
- ArgumentException
When strides is different from optimal strides, and TData is not the same size as the pixel format, or Width * Height != toData.Length
ToStaging()
Return an equivalent staging texture CPU read-writable from this instance.
public Texture ToStaging()
Returns
- Texture
The equivalent staging texture.
ToTextureView(TextureViewDescription)
Gets a view on this texture for a particular ViewType, array index (or zIndex for Texture3D), and mipmap index.
public Texture ToTextureView(TextureViewDescription viewDescription)
Parameters
viewDescriptionTextureViewDescriptionThe view description.
Returns
- Texture
A new texture object that is bouded to the requested view.