Texture Class
Namespace: Stride.GraphicsAssembly: Stride.Graphics.dll
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
Name | Description | |
---|---|---|
Constructors | ||
Texture() | ||
Properties | ||
ArraySize | Number of textures in the array. |
|
ArraySlice | The array index of this texture view. |
|
Depth | The depth of the texture. |
|
Description | Common description for the original texture. See remarks. |
|
Dimension | The dimension of a texture. |
|
Flags | Texture flags. |
|
Format | Texture format (see PixelFormat) |
|
FullQualitySize | When texture streaming is activated, the size of the texture when loaded at full quality. |
|
Height | The height of the texture. |
|
IsBlockCompressed | Gets a boolean indicating whether this Texture is a using a block compress format (BC1, BC2, BC3, BC4, BC5, BC6H, BC7). |
|
IsDepthStencil | Gets a value indicating whether this instance is a depth stencil. |
|
IsDepthStencilReadOnly | Gets a value indicating whether this instance is a depth stencil readonly. |
|
IsMultisample | Gets a value indicating whether this instance is a multi sample texture. |
|
IsRenderTarget | Gets a value indicating whether this instance is a render target. |
|
IsShaderResource | Gets a value indicating whether this instance is a shader resource. |
|
IsUnorderedAccess | Gets a value indicating whether this instance is a shader resource. |
|
MipLevel | The miplevel index of this texture view. |
|
MipLevels | The maximum number of mipmap levels in the texture. |
|
MultisampleCount | Structure that specifies multisampling parameters for the texture. |
|
Options | Resource options for DirectX 11 textures. |
|
SharedHandle | The shared handle if created with TextureOption.Shared or TextureOption.SharedNthandle, IntPtr.Zero otherwise. |
|
SharedNtHandleName | Gets the name of the shared Nt handle when created with TextureOption.SharedNthandle. |
|
Size | Gets the size of this texture. |
|
Usage | Value that identifies how the texture is to be read from and written to. |
|
ViewDepth | The depth of this texture view. |
|
ViewDescription | Gets the view description. |
|
ViewDimension | The dimension of the texture view. |
|
ViewFlags | The format of this texture view. |
|
ViewFormat | The format of this texture view. |
|
ViewHeight | The height of this texture view. |
|
ViewType | The format of this texture view. |
|
ViewWidth | The width of this texture view. |
|
Width | The width of the texture. |
|
Methods | ||
CalculateMipLevels(Int32, MipMapCount) | Calculates the number of miplevels for a Texture 1D. |
|
CalculateMipLevels(Int32, Int32, MipMapCount) | Calculates the number of miplevels for a Texture 2D. |
|
CalculateMipLevels(Int32, Int32, Int32, MipMapCount) | Calculates the number of miplevels for a Texture 2D. |
|
CalculateMipSize(Int32, Int32) | Calculates the size of a particular mip. |
|
CalculatePixelDataCount<TData>(Int32) | Calculates the number of pixel data this texture is requiring for a particular mip level. |
|
CalculateWidth<TData>(Int32) | Calculates the expected width of a texture using a specified type. |
|
Clone() | Makes a copy of this texture. |
|
CountMips(Int32) | ||
CountMips(Int32, Int32) | ||
CountMips(Int32, Int32, Int32) | ||
Destroy() | ||
GetData(CommandList, Texture, DataPointer, Int32, Int32, Boolean) | Copies the content of this texture from GPU memory to a pointer on CPU memory using a specific staging resource. |
|
GetData<TData>(CommandList, TData[], Int32, Int32, Boolean) | Copies the content of this texture to an array of data. |
|
GetData<TData>(CommandList, Texture, TData[], Int32, Int32, Boolean) | Copies the content of this texture from GPU memory to an array of data on CPU memory using a specific staging resource. |
|
GetData<TData>(CommandList, Int32, Int32) | Gets the content of this texture to an array of data. |
|
GetDataAsImage(CommandList) | Gets the GPU content of this texture as an Image on the CPU. |
|
GetDataAsImage(CommandList, Texture) | Gets the GPU content of this texture to an Image on the CPU. |
|
GetMipMapDescription(Int32) | Gets the mipmap description of this instance for the specified mipmap level. |
|
GetSubResourceIndex(Int32, Int32) | Gets the absolute sub-resource index from the array and mip slice. |
|
IsDepthStencilReadOnlySupported(GraphicsDevice) | ||
Load(GraphicsDevice, Stream, TextureFlags, GraphicsResourceUsage, Boolean) | Loads a texture from a stream. |
|
New(GraphicsDevice, Image, TextureFlags, GraphicsResourceUsage) | Loads a texture from a stream. |
|
New(GraphicsDevice, TextureDescription, DataBox[]) | Creates a new texture with the specified generic texture description. |
|
New(GraphicsDevice, TextureDescription, TextureViewDescription, DataBox[]) | Creates a new texture with the specified generic texture description. |
|
New1D(GraphicsDevice, Int32, MipMapCount, PixelFormat, TextureFlags, Int32, GraphicsResourceUsage) | Creates a new 1D Texture. |
|
New1D(GraphicsDevice, Int32, PixelFormat, TextureFlags, Int32, GraphicsResourceUsage) | Creates a new 1D Texture with a single mipmap. |
|
New1D(GraphicsDevice, Int32, PixelFormat, IntPtr, TextureFlags, GraphicsResourceUsage) | Creates a new 1D Texture with a single level of mipmap. |
|
New1D<T>(GraphicsDevice, Int32, PixelFormat, T[], TextureFlags, GraphicsResourceUsage) | Creates a new 1D Texture with a single level of mipmap. |
|
New2D(GraphicsDevice, Int32, Int32, MipMapCount, PixelFormat, DataBox[], TextureFlags, Int32, GraphicsResourceUsage, MultisampleCount, TextureOptions) | Creates a new 2D Texture. |
|
New2D(GraphicsDevice, Int32, Int32, MipMapCount, PixelFormat, TextureFlags, Int32, GraphicsResourceUsage, TextureOptions) | Creates a new 2D Texture. |
|
New2D(GraphicsDevice, Int32, Int32, PixelFormat, TextureFlags, Int32, GraphicsResourceUsage, TextureOptions) | Creates a new 2D Texture with a single mipmap. |
|
New2D<T>(GraphicsDevice, Int32, Int32, PixelFormat, T[], TextureFlags, GraphicsResourceUsage, TextureOptions) | Creates a new 2D Texture with a single level of mipmap. |
|
New3D(GraphicsDevice, Int32, Int32, Int32, MipMapCount, PixelFormat, DataBox[], TextureFlags, GraphicsResourceUsage) | Creates a new 3D Texture. |
|
New3D(GraphicsDevice, Int32, Int32, Int32, MipMapCount, PixelFormat, TextureFlags, GraphicsResourceUsage) | Creates a new 3D Texture. |
|
New3D(GraphicsDevice, Int32, Int32, Int32, PixelFormat, TextureFlags, GraphicsResourceUsage) | Creates a new 3D Texture with a single mipmap. |
|
New3D<T>(GraphicsDevice, Int32, Int32, Int32, PixelFormat, T[], TextureFlags, GraphicsResourceUsage) | Creates a new 3D Texture with texture data for the firs map. |
|
NewCube(GraphicsDevice, Int32, MipMapCount, PixelFormat, TextureFlags, GraphicsResourceUsage) | Creates a new Cube Texture. |
|
NewCube(GraphicsDevice, Int32, PixelFormat, DataBox[], TextureFlags, GraphicsResourceUsage) | Creates a new Cube Texture from a initial data.. |
|
NewCube(GraphicsDevice, Int32, PixelFormat, TextureFlags, GraphicsResourceUsage) | Creates a new Cube Texture. |
|
NewCube<T>(GraphicsDevice, Int32, PixelFormat, T[][], TextureFlags, GraphicsResourceUsage) | Creates a new Cube Texture from a initial data.. |
|
OnDestroyed() | ||
OnRecreate() | ||
Recreate(DataBox[]) | ||
ReleaseData() | Releases the texture data. |
|
Save(CommandList, Stream, ImageFileType) | Saves this texture to a stream with a specified format. |
|
Save(CommandList, Stream, Texture, ImageFileType) | Saves this texture to a stream with a specified format. |
|
SetData(CommandList, DataPointer, Int32, Int32, Nullable<ResourceRegion>) | Copies the content an data on CPU memory to this texture into GPU memory. |
|
SetData<TData>(CommandList, TData[], Int32, Int32, Nullable<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). |
|
ToStaging() | Return an equivalent staging texture CPU read-writable from this instance. |
|
ToTextureView(TextureViewDescription) | Gets a view on this texture for a particular ViewType, array index (or zIndex for Texture3D), and mipmap index. |
Constructors
Texture()
public Texture()
Properties
ArraySize
Number of textures in the array.
public int ArraySize { get; }
Property Value
Type | Description |
---|---|
System.Int32 | 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
Type | Description |
---|---|
System.Int32 | The array slice. |
Depth
The depth of the texture.
public int Depth { get; }
Property Value
Type | Description |
---|---|
System.Int32 | The depth. |
Description
Common description for the original texture. See remarks.
public TextureDescription Description { get; }
Property Value
Type | Description |
---|---|
TextureDescription |
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
Type | Description |
---|---|
TextureDimension |
Flags
Texture flags.
public TextureFlags Flags { get; }
Property Value
Type | Description |
---|---|
TextureFlags |
Format
Texture format (see PixelFormat)
public PixelFormat Format { get; }
Property Value
Type | Description |
---|---|
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
Type | Description |
---|---|
Size3 |
Height
The height of the texture.
public int Height { get; }
Property Value
Type | Description |
---|---|
System.Int32 | 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
Type | Description |
---|---|
System.Boolean |
IsDepthStencil
Gets a value indicating whether this instance is a depth stencil.
public bool IsDepthStencil { get; }
Property Value
Type | Description |
---|---|
System.Boolean |
|
IsDepthStencilReadOnly
Gets a value indicating whether this instance is a depth stencil readonly.
public bool IsDepthStencilReadOnly { get; }
Property Value
Type | Description |
---|---|
System.Boolean |
|
IsMultisample
Gets a value indicating whether this instance is a multi sample texture.
public bool IsMultisample { get; }
Property Value
Type | Description |
---|---|
System.Boolean |
|
IsRenderTarget
Gets a value indicating whether this instance is a render target.
public bool IsRenderTarget { get; }
Property Value
Type | Description |
---|---|
System.Boolean |
|
IsShaderResource
Gets a value indicating whether this instance is a shader resource.
public bool IsShaderResource { get; }
Property Value
Type | Description |
---|---|
System.Boolean |
|
IsUnorderedAccess
Gets a value indicating whether this instance is a shader resource.
public bool IsUnorderedAccess { get; }
Property Value
Type | Description |
---|---|
System.Boolean |
|
MipLevel
The miplevel index of this texture view.
public int MipLevel { get; }
Property Value
Type | Description |
---|---|
System.Int32 | The mip level. |
MipLevels
The maximum number of mipmap levels in the texture.
public int MipLevels { get; }
Property Value
Type | Description |
---|---|
System.Int32 | The mip levels. |
MultisampleCount
Structure that specifies multisampling parameters for the texture.
public MultisampleCount MultisampleCount { get; }
Property Value
Type | Description |
---|---|
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
Type | Description |
---|---|
TextureOptions |
SharedHandle
The shared handle if created with TextureOption.Shared or TextureOption.SharedNthandle, IntPtr.Zero otherwise.
public IntPtr SharedHandle { get; }
Property Value
Type | Description |
---|---|
System.IntPtr |
SharedNtHandleName
Gets the name of the shared Nt handle when created with TextureOption.SharedNthandle.
public string SharedNtHandleName { get; }
Property Value
Type | Description |
---|---|
System.String |
Size
Gets the size of this texture.
public Size3 Size { get; }
Property Value
Type | Description |
---|---|
Size3 | The size. |
Usage
Value that identifies how the texture is to be read from and written to.
public GraphicsResourceUsage Usage { get; }
Property Value
Type | Description |
---|---|
GraphicsResourceUsage |
ViewDepth
The depth of this texture view.
public int ViewDepth { get; }
Property Value
Type | Description |
---|---|
System.Int32 | The view depth. |
ViewDescription
Gets the view description.
public TextureViewDescription ViewDescription { get; }
Property Value
Type | Description |
---|---|
TextureViewDescription | The view description. |
ViewDimension
The dimension of the texture view.
public TextureDimension ViewDimension { get; }
Property Value
Type | Description |
---|---|
TextureDimension |
ViewFlags
The format of this texture view.
public TextureFlags ViewFlags { get; }
Property Value
Type | Description |
---|---|
TextureFlags | The type of the view. |
ViewFormat
The format of this texture view.
public PixelFormat ViewFormat { get; }
Property Value
Type | Description |
---|---|
PixelFormat | The view format. |
ViewHeight
The height of this texture view.
public int ViewHeight { get; }
Property Value
Type | Description |
---|---|
System.Int32 | The height of the view. |
ViewType
The format of this texture view.
public ViewType ViewType { get; }
Property Value
Type | Description |
---|---|
ViewType | The type of the view. |
ViewWidth
The width of this texture view.
public int ViewWidth { get; }
Property Value
Type | Description |
---|---|
System.Int32 | The width of the view. |
Width
The width of the texture.
public int Width { get; }
Property Value
Type | Description |
---|---|
System.Int32 | The width. |
Methods
CalculateMipLevels(Int32, MipMapCount)
Calculates the number of miplevels for a Texture 1D.
public static int CalculateMipLevels(int width, MipMapCount mipLevels)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | width | The width of the texture. |
MipMapCount | mipLevels | A 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
Type | Description |
---|---|
System.Int32 | The number of miplevels. |
CalculateMipLevels(Int32, Int32, MipMapCount)
Calculates the number of miplevels for a Texture 2D.
public static int CalculateMipLevels(int width, int height, MipMapCount mipLevels)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | width | The width of the texture. |
System.Int32 | height | The height of the texture. |
MipMapCount | mipLevels | A 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
Type | Description |
---|---|
System.Int32 | The number of miplevels. |
CalculateMipLevels(Int32, Int32, Int32, MipMapCount)
Calculates the number of miplevels for a Texture 2D.
public static int CalculateMipLevels(int width, int height, int depth, MipMapCount mipLevels)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | width | The width of the texture. |
System.Int32 | height | The height of the texture. |
System.Int32 | depth | The depth of the texture. |
MipMapCount | mipLevels | A 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
Type | Description |
---|---|
System.Int32 | The number of miplevels. |
CalculateMipSize(Int32, Int32)
Calculates the size of a particular mip.
public static int CalculateMipSize(int size, int mipLevel)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | size | The size. |
System.Int32 | mipLevel | The mip level. |
Returns
Type | Description |
---|---|
System.Int32 | System.Int32. |
CalculatePixelDataCount<TData>(Int32)
Calculates the number of pixel data this texture is requiring for a particular mip level.
public int CalculatePixelDataCount<TData>(int mipLevel = 0)
where TData : struct
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | mipLevel | The mip level. |
Returns
Type | Description |
---|---|
System.Int32 | The number of pixel data. |
Type Parameters
Name | Description |
---|---|
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>(Int32)
Calculates the expected width of a texture using a specified type.
public int CalculateWidth<TData>(int mipLevel = 0)
where TData : struct
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | mipLevel |
Returns
Type | Description |
---|---|
System.Int32 | The expected width |
Type Parameters
Name | Description |
---|---|
TData | The type of the T pixel data. |
Exceptions
Type | Condition |
---|---|
System.ArgumentException | If the size is invalid |
Clone()
Makes a copy of this texture.
public Texture Clone()
Returns
Type | Description |
---|---|
Texture | A copy of this texture. |
Remarks
This method doesn't copy the content of the texture.
CountMips(Int32)
public static int CountMips(int width)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | width |
Returns
Type | Description |
---|---|
System.Int32 |
CountMips(Int32, Int32)
public static int CountMips(int width, int height)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | width | |
System.Int32 | height |
Returns
Type | Description |
---|---|
System.Int32 |
CountMips(Int32, Int32, Int32)
public static int CountMips(int width, int height, int depth)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | width | |
System.Int32 | height | |
System.Int32 | depth |
Returns
Type | Description |
---|---|
System.Int32 |
Destroy()
protected override void Destroy()
Overrides
GetData(CommandList, Texture, DataPointer, Int32, Int32, Boolean)
Copies the content of this texture from GPU memory to a pointer on CPU memory using a specific staging resource.
public bool GetData(CommandList commandList, Texture stagingTexture, DataPointer toData, int arraySlice = 0, int mipSlice = 0, bool doNotWait = false)
Parameters
Type | Name | Description |
---|---|---|
CommandList | commandList | The command list. |
Texture | stagingTexture | The staging texture used to transfer the texture to. |
DataPointer | toData | The pointer to data in CPU memory. |
System.Int32 | arraySlice | The array slice index. This value must be set to 0 for Texture 3D. |
System.Int32 | mipSlice | The mip slice index. |
System.Boolean | doNotWait | if set to |
Returns
Type | Description |
---|---|
System.Boolean |
|
Remarks
This method is only working when called from the main thread that is accessing the main GraphicsDevice.
Exceptions
Type | Condition |
---|---|
System.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, TData[], Int32, Int32, Boolean)
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 : struct
Parameters
Type | Name | Description |
---|---|---|
CommandList | commandList | The command list. |
TData[] | toData | The destination buffer to receive a copy of the texture datas. |
System.Int32 | arraySlice | The array slice index. This value must be set to 0 for Texture 3D. |
System.Int32 | mipSlice | The mip slice index. |
System.Boolean | doNotWait | if set to |
Returns
Type | Description |
---|---|
System.Boolean |
|
Type Parameters
Name | Description |
---|---|
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.
GetData<TData>(CommandList, Texture, TData[], Int32, Int32, Boolean)
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 : struct
Parameters
Type | Name | Description |
---|---|---|
CommandList | commandList | The command list. |
Texture | stagingTexture | The staging texture used to transfer the texture to. |
TData[] | toData | To data. |
System.Int32 | arraySlice | The array slice index. This value must be set to 0 for Texture 3D. |
System.Int32 | mipSlice | The mip slice index. |
System.Boolean | doNotWait | if set to |
Returns
Type | Description |
---|---|
System.Boolean |
|
Type Parameters
Name | Description |
---|---|
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
Type | Condition |
---|---|
System.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, Int32, Int32)
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 : struct
Parameters
Type | Name | Description |
---|---|---|
CommandList | commandList | The command list. |
System.Int32 | arraySlice | The array slice index. This value must be set to 0 for Texture 3D. |
System.Int32 | mipSlice | The mip slice index. |
Returns
Type | Description |
---|---|
TData[] | The texture data. |
Type Parameters
Name | Description |
---|---|
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.
GetDataAsImage(CommandList)
Gets the GPU content of this texture as an Image on the CPU.
public Image GetDataAsImage(CommandList commandList)
Parameters
Type | Name | Description |
---|---|---|
CommandList | commandList |
Returns
Type | Description |
---|---|
Image |
GetDataAsImage(CommandList, Texture)
Gets the GPU content of this texture to an Image on the CPU.
public Image GetDataAsImage(CommandList commandList, Texture stagingTexture)
Parameters
Type | Name | Description |
---|---|---|
CommandList | commandList | The command list. |
Texture | stagingTexture | The staging texture used to temporary transfer the image from the GPU to CPU. |
Returns
Type | Description |
---|---|
Image |
Exceptions
Type | Condition |
---|---|
System.ArgumentException | If stagingTexture is not a staging texture. |
GetMipMapDescription(Int32)
Gets the mipmap description of this instance for the specified mipmap level.
public MipMapDescription GetMipMapDescription(int mipmap)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | mipmap | The mipmap. |
Returns
Type | Description |
---|---|
MipMapDescription | A description of a particular mipmap for this texture. |
GetSubResourceIndex(Int32, Int32)
Gets the absolute sub-resource index from the array and mip slice.
public int GetSubResourceIndex(int arraySlice, int mipSlice)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | arraySlice | The array slice index. |
System.Int32 | mipSlice | The mip slice index. |
Returns
Type | Description |
---|---|
System.Int32 | A value equals to arraySlice * Description.MipLevels + mipSlice. |
IsDepthStencilReadOnlySupported(GraphicsDevice)
public static bool IsDepthStencilReadOnlySupported(GraphicsDevice device)
Parameters
Type | Name | Description |
---|---|---|
GraphicsDevice | device |
Returns
Type | Description |
---|---|
System.Boolean |
Load(GraphicsDevice, Stream, TextureFlags, GraphicsResourceUsage, Boolean)
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
Type | Name | Description |
---|---|---|
GraphicsDevice | device | The GraphicsDevice. |
System.IO.Stream | stream | The stream to load the texture from. |
TextureFlags | textureFlags | True to load the texture with unordered access enabled. Default is false. |
GraphicsResourceUsage | usage | Usage of the resource. Default is Immutable |
System.Boolean | loadAsSRGB | Indicate if the texture should be loaded as an sRGB texture. If false, the texture is load in its default format. |
Returns
Type | Description |
---|---|
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
Type | Name | Description |
---|---|---|
GraphicsDevice | device | The GraphicsDevice. |
Image | image | The image. |
TextureFlags | textureFlags | True to load the texture with unordered access enabled. Default is false. |
GraphicsResourceUsage | usage | Usage of the resource. Default is Immutable |
Returns
Type | Description |
---|---|
Texture | A texture |
Exceptions
Type | Condition |
---|---|
System.InvalidOperationException | Dimension not supported |
New(GraphicsDevice, TextureDescription, DataBox[])
Creates a new texture with the specified generic texture description.
public static Texture New(GraphicsDevice graphicsDevice, TextureDescription description, params DataBox[] boxes)
Parameters
Type | Name | Description |
---|---|---|
GraphicsDevice | graphicsDevice | The graphics device. |
TextureDescription | description | The description. |
DataBox[] | boxes | The data boxes. |
Returns
Type | Description |
---|---|
Texture | A Texture instance, either a RenderTarget or DepthStencilBuffer or Texture, depending on Binding flags. |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | graphicsDevice |
New(GraphicsDevice, TextureDescription, TextureViewDescription, 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
Type | Name | Description |
---|---|---|
GraphicsDevice | graphicsDevice | The graphics device. |
TextureDescription | description | The description. |
TextureViewDescription | viewDescription | The view description. |
DataBox[] | boxes | The data boxes. |
Returns
Type | Description |
---|---|
Texture | A Texture instance, either a RenderTarget or DepthStencilBuffer or Texture, depending on Binding flags. |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | graphicsDevice |
New1D(GraphicsDevice, Int32, MipMapCount, PixelFormat, TextureFlags, Int32, 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
Type | Name | Description |
---|---|---|
GraphicsDevice | device | The GraphicsDevice. |
System.Int32 | width | The width. |
MipMapCount | mipCount | Number of mipmaps, set to true to have all mipmaps, set to an int >=1 for a particular mipmap count. |
PixelFormat | format | Describes the format to use. |
TextureFlags | textureFlags | true if the texture needs to support unordered read write. |
System.Int32 | arraySize | Size of the texture 2D array, default to 1. |
GraphicsResourceUsage | usage | The usage. |
Returns
Type | Description |
---|---|
Texture | A new instance of 1D Texture class. |
New1D(GraphicsDevice, Int32, PixelFormat, TextureFlags, Int32, 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
Type | Name | Description |
---|---|---|
GraphicsDevice | device | The GraphicsDevice. |
System.Int32 | width | The width. |
PixelFormat | format | Describes the format to use. |
TextureFlags | textureFlags | true if the texture needs to support unordered read write. |
System.Int32 | arraySize | Size of the texture 2D array, default to 1. |
GraphicsResourceUsage | usage | The usage. |
Returns
Type | Description |
---|---|
Texture | A new instance of 1D Texture class. |
New1D(GraphicsDevice, Int32, PixelFormat, IntPtr, TextureFlags, GraphicsResourceUsage)
Creates a new 1D Texture with a single level of mipmap.
public static Texture New1D(GraphicsDevice device, int width, PixelFormat format, IntPtr dataPtr, TextureFlags textureFlags = TextureFlags.ShaderResource, GraphicsResourceUsage usage = GraphicsResourceUsage.Immutable)
Parameters
Type | Name | Description |
---|---|---|
GraphicsDevice | device | The GraphicsDevice. |
System.Int32 | width | The width. |
PixelFormat | format | Describes the format to use. |
System.IntPtr | dataPtr | Data ptr |
TextureFlags | textureFlags | true if the texture needs to support unordered read write. |
GraphicsResourceUsage | usage | The usage. |
Returns
Type | Description |
---|---|
Texture | A new instance of 1D Texture class. |
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, Int32, 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 : struct
Parameters
Type | Name | Description |
---|---|---|
GraphicsDevice | device | The GraphicsDevice. |
System.Int32 | width | The width. |
PixelFormat | format | Describes the format to use. |
T[] | textureData | Texture data. Size of must be equal to sizeof(Format) * width |
TextureFlags | textureFlags | true if the texture needs to support unordered read write. |
GraphicsResourceUsage | usage | The usage. |
Returns
Type | Description |
---|---|
Texture | A new instance of Texture class. |
Type Parameters
Name | Description |
---|---|
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, Int32, Int32, MipMapCount, PixelFormat, DataBox[], TextureFlags, Int32, 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
Type | Name | Description |
---|---|---|
GraphicsDevice | device | The GraphicsDevice. |
System.Int32 | width | The width. |
System.Int32 | height | The height. |
MipMapCount | mipCount | Number of mipmaps, set to true to have all mipmaps, set to an int >=1 for a particular mipmap count. |
PixelFormat | format | Describes the format to use. |
DataBox[] | textureData | Texture datas through an array of DataBox |
TextureFlags | textureFlags | true if the texture needs to support unordered read write. |
System.Int32 | arraySize | Size of the texture 2D array, default to 1. |
GraphicsResourceUsage | usage | The usage. |
MultisampleCount | multisampleCount | The multisample count. |
TextureOptions | options | The options, e.g. sharing |
Returns
Type | Description |
---|---|
Texture | A new instance of 2D Texture class. |
New2D(GraphicsDevice, Int32, Int32, MipMapCount, PixelFormat, TextureFlags, Int32, 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
Type | Name | Description |
---|---|---|
GraphicsDevice | device | The GraphicsDevice. |
System.Int32 | width | The width. |
System.Int32 | height | The height. |
MipMapCount | mipCount | Number of mipmaps, set to true to have all mipmaps, set to an int >=1 for a particular mipmap count. |
PixelFormat | format | Describes the format to use. |
TextureFlags | textureFlags | true if the texture needs to support unordered read write. |
System.Int32 | arraySize | Size of the texture 2D array, default to 1. |
GraphicsResourceUsage | usage | The usage. |
TextureOptions | options |
Returns
Type | Description |
---|---|
Texture | A new instance of 2D Texture class. |
New2D(GraphicsDevice, Int32, Int32, PixelFormat, TextureFlags, Int32, 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
Type | Name | Description |
---|---|---|
GraphicsDevice | device | The GraphicsDevice. |
System.Int32 | width | The width. |
System.Int32 | height | The height. |
PixelFormat | format | Describes the format to use. |
TextureFlags | textureFlags | true if the texture needs to support unordered read write. |
System.Int32 | arraySize | Size of the texture 2D array, default to 1. |
GraphicsResourceUsage | usage | The usage. |
TextureOptions | options |
Returns
Type | Description |
---|---|
Texture | A new instance of 2D Texture class. |
New2D<T>(GraphicsDevice, Int32, Int32, 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 : struct
Parameters
Type | Name | Description |
---|---|---|
GraphicsDevice | device | The GraphicsDevice. |
System.Int32 | width | The width. |
System.Int32 | height | The height. |
PixelFormat | format | Describes the format to use. |
T[] | textureData | The texture data for a single mipmap and a single array slice. See remarks |
TextureFlags | textureFlags | true if the texture needs to support unordered read write. |
GraphicsResourceUsage | usage | The usage. |
TextureOptions | options |
Returns
Type | Description |
---|---|
Texture | A new instance of 2D Texture class. |
Type Parameters
Name | Description |
---|---|
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, Int32, Int32, Int32, 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
Type | Name | Description |
---|---|---|
GraphicsDevice | device | The GraphicsDevice. |
System.Int32 | width | The width. |
System.Int32 | height | The height. |
System.Int32 | depth | The depth. |
MipMapCount | mipCount | Number of mipmaps, set to true to have all mipmaps, set to an int >=1 for a particular mipmap count. |
PixelFormat | format | Describes the format to use. |
DataBox[] | textureData | |
TextureFlags | textureFlags | true if the texture needs to support unordered read write. |
GraphicsResourceUsage | usage | The usage. |
Returns
Type | Description |
---|---|
Texture | A new instance of 3D Texture class. |
New3D(GraphicsDevice, Int32, Int32, Int32, 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
Type | Name | Description |
---|---|---|
GraphicsDevice | device | The GraphicsDevice. |
System.Int32 | width | The width. |
System.Int32 | height | The height. |
System.Int32 | depth | The depth. |
MipMapCount | mipCount | Number of mipmaps, set to true to have all mipmaps, set to an int >=1 for a particular mipmap count. |
PixelFormat | format | Describes the format to use. |
TextureFlags | textureFlags | true if the texture needs to support unordered read write. |
GraphicsResourceUsage | usage | The usage. |
Returns
Type | Description |
---|---|
Texture | A new instance of 3D Texture class. |
New3D(GraphicsDevice, Int32, Int32, Int32, 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
Type | Name | Description |
---|---|---|
GraphicsDevice | device | The GraphicsDevice. |
System.Int32 | width | The width. |
System.Int32 | height | The height. |
System.Int32 | depth | The depth. |
PixelFormat | format | Describes the format to use. |
TextureFlags | textureFlags | true if the texture needs to support unordered read write. |
GraphicsResourceUsage | usage | The usage. |
Returns
Type | Description |
---|---|
Texture | A new instance of 3D Texture class. |
New3D<T>(GraphicsDevice, Int32, Int32, Int32, 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 : struct
Parameters
Type | Name | Description |
---|---|---|
GraphicsDevice | device | The GraphicsDevice. |
System.Int32 | width | The width. |
System.Int32 | height | The height. |
System.Int32 | depth | The depth. |
PixelFormat | format | Describes the format to use. |
T[] | textureData | The texture data, width * height * depth datas |
TextureFlags | textureFlags | true if the texture needs to support unordered read write. |
GraphicsResourceUsage | usage | The usage. |
Returns
Type | Description |
---|---|
Texture | A new instance of 3D Texture class. |
Type Parameters
Name | Description |
---|---|
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, Int32, 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
Type | Name | Description |
---|---|---|
GraphicsDevice | device | The GraphicsDevice. |
System.Int32 | size | The size (in pixels) of the top-level faces of the cube texture. |
MipMapCount | mipCount | Number of mipmaps, set to true to have all mipmaps, set to an int >=1 for a particular mipmap count. |
PixelFormat | format | Describes the format to use. |
TextureFlags | textureFlags | The texture flags. |
GraphicsResourceUsage | usage | The usage. |
Returns
Type | Description |
---|---|
Texture | A new instance of 2D Texture class. |
NewCube(GraphicsDevice, Int32, 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
Type | Name | Description |
---|---|---|
GraphicsDevice | device | The GraphicsDevice. |
System.Int32 | size | The size (in pixels) of the top-level faces of the cube texture. |
PixelFormat | format | Describes the format to use. |
DataBox[] | textureData | an array of 6 textures. See remarks |
TextureFlags | textureFlags | The texture flags. |
GraphicsResourceUsage | usage | The usage. |
Returns
Type | Description |
---|---|
Texture | A new instance of Cube Texture class. |
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
Type | Condition |
---|---|
System.ArgumentException | Invalid texture datas. First dimension must be equal to 6;textureData |
NewCube(GraphicsDevice, Int32, 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
Type | Name | Description |
---|---|---|
GraphicsDevice | device | The GraphicsDevice. |
System.Int32 | size | The size (in pixels) of the top-level faces of the cube texture. |
PixelFormat | format | Describes the format to use. |
TextureFlags | textureFlags | The texture flags. |
GraphicsResourceUsage | usage | The usage. |
Returns
Type | Description |
---|---|
Texture | A new instance of 2D Texture class. |
NewCube<T>(GraphicsDevice, Int32, 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 : struct
Parameters
Type | Name | Description |
---|---|---|
GraphicsDevice | device | The GraphicsDevice. |
System.Int32 | size | The size (in pixels) of the top-level faces of the cube texture. |
PixelFormat | format | Describes the format to use. |
T[][] | textureData | an array of 6 textures. See remarks |
TextureFlags | textureFlags | The texture flags. |
GraphicsResourceUsage | usage | The usage. |
Returns
Type | Description |
---|---|
Texture | A new instance of Cube Texture class. |
Type Parameters
Name | Description |
---|---|
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
Type | Condition |
---|---|
System.ArgumentException | Invalid texture datas. First dimension must be equal to 6;textureData |
OnDestroyed()
protected override void OnDestroyed()
Overrides
OnRecreate()
protected override bool OnRecreate()
Returns
Type | Description |
---|---|
System.Boolean |
Overrides
Recreate(DataBox[])
public void Recreate(DataBox[] dataBoxes = null)
Parameters
Type | Name | Description |
---|---|---|
DataBox[] | dataBoxes |
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
Type | Name | Description |
---|---|---|
CommandList | commandList | The command list. |
System.IO.Stream | stream | The stream. |
ImageFileType | fileType | Type 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
Type | Name | Description |
---|---|---|
CommandList | commandList | The command list. |
System.IO.Stream | stream | The stream. |
Texture | stagingTexture | The staging texture used to temporary transfer the image from the GPU to CPU. |
ImageFileType | fileType | Type of the image file. |
Exceptions
Type | Condition |
---|---|
System.ArgumentException | If stagingTexture is not a staging texture. |
SetData(CommandList, DataPointer, Int32, Int32, Nullable<ResourceRegion>)
Copies the content an data on CPU memory to this texture into GPU memory.
public void SetData(CommandList commandList, DataPointer fromData, int arraySlice = 0, int mipSlice = 0, ResourceRegion? region = null)
Parameters
Type | Name | Description |
---|---|---|
CommandList | commandList | The CommandList. |
DataPointer | fromData | The data to copy from. |
System.Int32 | arraySlice | The array slice index. This value must be set to 0 for Texture 3D. |
System.Int32 | mipSlice | The mip slice index. |
System.Nullable<ResourceRegion> | region | Destination region |
Remarks
See unmanaged documentation for usage and restrictions.
Exceptions
Type | Condition |
---|---|
System.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[], Int32, Int32, Nullable<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 : struct
Parameters
Type | Name | Description |
---|---|---|
CommandList | commandList | The command list. |
TData[] | fromData | The data to copy from. |
System.Int32 | arraySlice | The array slice index. This value must be set to 0 for Texture 3D. |
System.Int32 | mipSlice | The mip slice index. |
System.Nullable<ResourceRegion> | region | Destination region |
Type Parameters
Name | Description |
---|---|
TData | The type of the T data. |
Remarks
See unmanaged documentation for usage and restrictions.
Exceptions
Type | Condition |
---|---|
System.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
Type | Description |
---|---|
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
Type | Name | Description |
---|---|---|
TextureViewDescription | viewDescription | The view description. |
Returns
Type | Description |
---|---|
Texture | A new texture object that is bouded to the requested view. |