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
-
Texture
- 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
true
if 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
true
if 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
true
if 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
true
if 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
true
if 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
true
if 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
width
intThe width of the texture.
mipLevels
MipMapCountA 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
width
intThe width of the texture.
height
intThe height of the texture.
mipLevels
MipMapCountA 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
width
intThe width of the texture.
height
intThe height of the texture.
depth
intThe depth of the texture.
mipLevels
MipMapCountA 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
mipLevel
intThe mip level.
Returns
- int
The number of pixel data.
Type Parameters
TData
The 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
mipLevel
int
Returns
- int
The expected width
Type Parameters
TData
The 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
width
int
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
commandList
CommandListThe command list.
stagingTexture
TextureThe staging texture used to transfer the texture to.
toData
DataPointerThe pointer to data in CPU memory.
arraySlice
intThe array slice index. This value must be set to 0 for Texture 3D.
mipSlice
intThe mip slice index.
doNotWait
boolif set to
true
this method will return immediately if the resource is still being used by the GPU for writing. Default is false
Returns
- bool
true
if data was correctly retrieved,false
ifdoNotWait
flag 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
commandList
CommandList
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
commandList
CommandListThe command list.
stagingTexture
TextureThe 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
commandList
CommandListThe command list.
stagingTexture
TextureThe staging texture used to transfer the texture to.
toData
Span<T>The pointer to data in CPU memory.
arraySlice
intThe array slice index. This value must be set to 0 for Texture 3D.
mipSlice
intThe mip slice index.
doNotWait
boolif set to
true
this method will return immediately if the resource is still being used by the GPU for writing. Default is false
Returns
- bool
true
if data was correctly retrieved,false
ifdoNotWait
flag 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
commandList
CommandListThe command list.
stagingTexture
TextureThe staging texture used to transfer the texture to.
toData
TData[]To data.
arraySlice
intThe array slice index. This value must be set to 0 for Texture 3D.
mipSlice
intThe mip slice index.
doNotWait
boolif set to
true
this method will return immediately if the resource is still being used by the GPU for writing. Default is false
Returns
- bool
true
if data was correctly retrieved,false
ifdoNotWait
flag was true and the resource is still being used by the GPU for writing.
Type Parameters
TData
The 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
commandList
CommandListThe command list.
arraySlice
intThe array slice index. This value must be set to 0 for Texture 3D.
mipSlice
intThe mip slice index.
Returns
- TData[]
The texture data.
Type Parameters
TData
The 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
commandList
CommandListThe command list.
toData
TData[]The destination buffer to receive a copy of the texture datas.
arraySlice
intThe array slice index. This value must be set to 0 for Texture 3D.
mipSlice
intThe mip slice index.
doNotWait
boolif set to
true
this method will return immediately if the resource is still being used by the GPU for writing. Default is false
Returns
- bool
true
if data was correctly retrieved,false
ifdoNotWait
flag was true and the resource is still being used by the GPU for writing.
Type Parameters
TData
The 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
mipmap
intThe 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
device
GraphicsDevice
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
device
GraphicsDeviceThe GraphicsDevice.
stream
StreamThe stream to load the texture from.
textureFlags
TextureFlagsTrue to load the texture with unordered access enabled. Default is false.
usage
GraphicsResourceUsageUsage of the resource. Default is Immutable
loadAsSRGB
boolIndicate 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
device
GraphicsDeviceThe GraphicsDevice.
image
ImageThe image.
textureFlags
TextureFlagsTrue to load the texture with unordered access enabled. Default is false.
usage
GraphicsResourceUsageUsage 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
graphicsDevice
GraphicsDeviceThe graphics device.
description
TextureDescriptionThe description.
boxes
DataBox[]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
graphicsDevice
GraphicsDeviceThe graphics device.
description
TextureDescriptionThe description.
viewDescription
TextureViewDescriptionThe view description.
boxes
DataBox[]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
device
GraphicsDeviceThe GraphicsDevice.
width
intThe width.
mipCount
MipMapCountNumber of mipmaps, set to true to have all mipmaps, set to an int >=1 for a particular mipmap count.
format
PixelFormatDescribes the format to use.
textureFlags
TextureFlagstrue if the texture needs to support unordered read write.
arraySize
intSize of the texture 2D array, default to 1.
usage
GraphicsResourceUsageThe 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
device
GraphicsDeviceThe GraphicsDevice.
width
intThe width.
format
PixelFormatDescribes the format to use.
textureFlags
TextureFlagstrue if the texture needs to support unordered read write.
arraySize
intSize of the texture 2D array, default to 1.
usage
GraphicsResourceUsageThe 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
device
GraphicsDeviceThe GraphicsDevice.
width
intThe width.
format
PixelFormatDescribes the format to use.
dataPtr
nintData ptr
textureFlags
TextureFlagstrue if the texture needs to support unordered read write.
usage
GraphicsResourceUsageThe 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
device
GraphicsDeviceThe GraphicsDevice.
width
intThe width.
format
PixelFormatDescribes the format to use.
textureData
T[]Texture data. Size of must be equal to sizeof(Format) * width
textureFlags
TextureFlagstrue if the texture needs to support unordered read write.
usage
GraphicsResourceUsageThe usage.
Returns
Type Parameters
T
Type 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
device
GraphicsDeviceThe GraphicsDevice.
width
intThe width.
height
intThe height.
mipCount
MipMapCountNumber of mipmaps, set to true to have all mipmaps, set to an int >=1 for a particular mipmap count.
format
PixelFormatDescribes the format to use.
textureData
DataBox[]Texture datas through an array of DataBox
textureFlags
TextureFlagstrue if the texture needs to support unordered read write.
arraySize
intSize of the texture 2D array, default to 1.
usage
GraphicsResourceUsageThe usage.
multisampleCount
MultisampleCountThe multisample count.
options
TextureOptionsThe 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
device
GraphicsDeviceThe GraphicsDevice.
width
intThe width.
height
intThe height.
mipCount
MipMapCountNumber of mipmaps, set to true to have all mipmaps, set to an int >=1 for a particular mipmap count.
format
PixelFormatDescribes the format to use.
textureFlags
TextureFlagstrue if the texture needs to support unordered read write.
arraySize
intSize of the texture 2D array, default to 1.
usage
GraphicsResourceUsageThe usage.
options
TextureOptions
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
device
GraphicsDeviceThe GraphicsDevice.
width
intThe width.
height
intThe height.
format
PixelFormatDescribes the format to use.
textureFlags
TextureFlagstrue if the texture needs to support unordered read write.
arraySize
intSize of the texture 2D array, default to 1.
usage
GraphicsResourceUsageThe usage.
options
TextureOptions
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
device
GraphicsDeviceThe GraphicsDevice.
width
intThe width.
height
intThe height.
format
PixelFormatDescribes the format to use.
textureData
T[]The texture data for a single mipmap and a single array slice. See remarks
textureFlags
TextureFlagstrue if the texture needs to support unordered read write.
usage
GraphicsResourceUsageThe usage.
options
TextureOptions
Returns
Type Parameters
T
Type 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
device
GraphicsDeviceThe GraphicsDevice.
width
intThe width.
height
intThe height.
depth
intThe depth.
mipCount
MipMapCountNumber of mipmaps, set to true to have all mipmaps, set to an int >=1 for a particular mipmap count.
format
PixelFormatDescribes the format to use.
textureData
DataBox[]textureFlags
TextureFlagstrue if the texture needs to support unordered read write.
usage
GraphicsResourceUsageThe 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
device
GraphicsDeviceThe GraphicsDevice.
width
intThe width.
height
intThe height.
depth
intThe depth.
mipCount
MipMapCountNumber of mipmaps, set to true to have all mipmaps, set to an int >=1 for a particular mipmap count.
format
PixelFormatDescribes the format to use.
textureFlags
TextureFlagstrue if the texture needs to support unordered read write.
usage
GraphicsResourceUsageThe 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
device
GraphicsDeviceThe GraphicsDevice.
width
intThe width.
height
intThe height.
depth
intThe depth.
format
PixelFormatDescribes the format to use.
textureFlags
TextureFlagstrue if the texture needs to support unordered read write.
usage
GraphicsResourceUsageThe 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
device
GraphicsDeviceThe GraphicsDevice.
width
intThe width.
height
intThe height.
depth
intThe depth.
format
PixelFormatDescribes the format to use.
textureData
T[]The texture data, width * height * depth datas
textureFlags
TextureFlagstrue if the texture needs to support unordered read write.
usage
GraphicsResourceUsageThe usage.
Returns
Type Parameters
T
Type 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
device
GraphicsDeviceThe GraphicsDevice.
size
intThe size (in pixels) of the top-level faces of the cube texture.
mipCount
MipMapCountNumber of mipmaps, set to true to have all mipmaps, set to an int >=1 for a particular mipmap count.
format
PixelFormatDescribes the format to use.
textureFlags
TextureFlagsThe texture flags.
usage
GraphicsResourceUsageThe 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
device
GraphicsDeviceThe GraphicsDevice.
size
intThe size (in pixels) of the top-level faces of the cube texture.
format
PixelFormatDescribes the format to use.
textureData
DataBox[]an array of 6 textures. See remarks
textureFlags
TextureFlagsThe texture flags.
usage
GraphicsResourceUsageThe 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
device
GraphicsDeviceThe GraphicsDevice.
size
intThe size (in pixels) of the top-level faces of the cube texture.
format
PixelFormatDescribes the format to use.
textureFlags
TextureFlagsThe texture flags.
usage
GraphicsResourceUsageThe 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
device
GraphicsDeviceThe GraphicsDevice.
size
intThe size (in pixels) of the top-level faces of the cube texture.
format
PixelFormatDescribes the format to use.
textureData
T[][]an array of 6 textures. See remarks
textureFlags
TextureFlagsThe texture flags.
usage
GraphicsResourceUsageThe usage.
Returns
Type Parameters
T
Type 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
dataBoxes
DataBox[]
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
commandList
CommandListThe command list.
stream
StreamThe stream.
fileType
ImageFileTypeType 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
commandList
CommandListThe command list.
stream
StreamThe stream.
stagingTexture
TextureThe staging texture used to temporary transfer the image from the GPU to CPU.
fileType
ImageFileTypeType 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
commandList
CommandListThe CommandList.
fromData
DataPointerThe data to copy from.
arraySlice
intThe array slice index. This value must be set to 0 for Texture 3D.
mipSlice
intThe mip slice index.
region
ResourceRegion?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
commandList
CommandListThe CommandList.
fromData
Span<T>The data to copy from.
arraySlice
intThe array slice index. This value must be set to 0 for Texture 3D.
mipSlice
intThe mip slice index.
region
ResourceRegion?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
commandList
CommandListThe command list.
fromData
TData[]The data to copy from.
arraySlice
intThe array slice index. This value must be set to 0 for Texture 3D.
mipSlice
intThe mip slice index.
region
ResourceRegion?Destination region
Type Parameters
TData
The 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
viewDescription
TextureViewDescriptionThe view description.
Returns
- Texture
A new texture object that is bouded to the requested view.