Table of Contents

Class TextureExtensions

Namespace
Stride.CommunityToolkit.Rendering
Assembly
Stride.CommunityToolkit.dll

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

urlName string

The asset file name to search for, such as Brick.sdtex.

workDir string

The 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

texture Texture

The texture to copy.

services IServiceRegistry

The game's services, which hold the render context the canvas draws with: game.Services, or a script's Services.

pixelFormat PixelFormat

The 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 texture or services is 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

texture Texture

The texture to copy.

width int

The width of the copy, in pixels.

height int

The height of the copy, in pixels.

services IServiceRegistry

The game's services, which hold the render context the canvas draws with: game.Services, or a script's Services.

pixelFormat PixelFormat

The 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 texture or services is null.

ArgumentOutOfRangeException

If width or height is not positive.