Class TextureExtensions
Extension methods for Texture: a copy at another size or in another pixel format, drawn through a TextureCanvas, and the source file of a texture asset in a source checkout.
public static class TextureExtensions
- Inheritance
-
TextureExtensions
Methods
FindAssetSourceDir(string, string)
Finds the asset file named urlName and returns the path on its Source: !file line.
public static string FindAssetSourceDir(string urlName, string workDir)
Parameters
urlNamestringThe asset file name to search for, such as
Brick.sdtex.workDirstringThe folder to search, appended to the folder three levels above the executing assembly.
Returns
- string
The source path, or an empty string if the asset or its source line is not found.
Remarks
For tools, tests and drafting in a source checkout: the search starts three folders above the executing assembly, where the solution usually sits, which a shipped game does not have.
ReFormat(Texture, IServiceRegistry, PixelFormat)
A copy of the texture in another pixel format, at the same size: Resize(Texture, int, int, IServiceRegistry, PixelFormat) without the resize.
public static Texture ReFormat(this Texture texture, IServiceRegistry services, PixelFormat pixelFormat = PixelFormat.R8G8B8A8_UNorm)
Parameters
textureTextureThe texture to copy.
servicesIServiceRegistryThe game's services, which hold the render context the canvas draws with:
game.Services, or a script'sServices.pixelFormatPixelFormatThe pixel format of the copy; one a render target can have.
Returns
- Texture
A new texture the caller owns, to dispose when it is no longer needed.
Exceptions
- ArgumentNullException
If
textureorservicesis null.
Resize(Texture, int, int, IServiceRegistry, PixelFormat)
A copy of the texture at another size, and optionally in another pixel format, drawn through a TextureCanvas with linear sampling. Nothing is drawn on screen.
public static Texture Resize(this Texture texture, int width, int height, IServiceRegistry services, PixelFormat pixelFormat = PixelFormat.R8G8B8A8_UNorm)
Parameters
textureTextureThe texture to copy.
widthintThe width of the copy, in pixels.
heightintThe height of the copy, in pixels.
servicesIServiceRegistryThe game's services, which hold the render context the canvas draws with:
game.Services, or a script'sServices.pixelFormatPixelFormatThe pixel format of the copy; one a render target can have.
Returns
- Texture
A new texture the caller owns, to dispose when it is no longer needed.
Exceptions
- ArgumentNullException
If
textureorservicesis null.- ArgumentOutOfRangeException
If
widthorheightis not positive.