GraphicsAPI reference
Class Texture
Namespace: MicroEngine.Graphics
Assembly: MicroEngine.Graphics2D.dll
Guide: Graphics
A GPU (or headless) texture owned by the active graphics device.
public abstract class Texture : IDisposableInheritance
Implements
Constructors
Texture(int, int, TextureFilter)
Records the size and filter of a texture created by a graphics device.
protected Texture(int width, int height, TextureFilter filter = TextureFilter.Nearest)Parameters
width int
height int
filter TextureFilter
Texture(IGraphicsDevice, int, int, TextureFilter)
Records the size, filter and creating device of a texture.
protected Texture(IGraphicsDevice device, int width, int height, TextureFilter filter = TextureFilter.Nearest)Parameters
device IGraphicsDevice
width int
height int
filter TextureFilter
Exceptions
device is null.
Properties
Bounds
The whole texture as a source rectangle: (0, 0, Width, Height).
public RectF Bounds { get; }Property Value
Device
The graphics device that created the texture, or null for a texture whose device did not say (one made with the constructor that takes no device). Renderers draw only the textures of their own device.
public IGraphicsDevice? Device { get; }Property Value
Filter
How the texture is sampled; it can change at any time and applies to the next draws.
public TextureFilter Filter { get; set; }Property Value
Height
Height in pixels.
public int Height { get; }Property Value
IsDisposed
Whether Dispose was called. Drawing a disposed texture throws ObjectDisposedException
on every renderer, and nothing is drawn.
public bool IsDisposed { get; }Property Value
SizeInBytes
Memory the texture’s pixels take on the device, in bytes (4 per pixel).
public long SizeInBytes { get; }Property Value
Width
Width in pixels.
public int Width { get; }Property Value
Methods
ApplyFilter(TextureFilter)
Applies a new filter on the device; called by Filter when it changes.
protected abstract void ApplyFilter(TextureFilter filter)Parameters
filter TextureFilter
CheckDrawable<TTexture>(Texture, IGraphicsDevice)
The checks every renderer makes before it draws texture, so that all backends fail alike: a
disposed texture throws ObjectDisposedException, and a texture another graphics device created (one
that is not a TTexture, or whose Device is not device)
throws ArgumentException. Backend authors call it first in every drawing method that takes a texture.
public static TTexture CheckDrawable<TTexture>(Texture texture, IGraphicsDevice device) where TTexture : TextureParameters
texture Texture
The texture a game asked to draw.
device IGraphicsDevice
The renderer’s graphics device.
Returns
TTexture
texture as the device’s own type.
Type Parameters
TTexture
The texture type of the renderer’s device.
Exceptions
texture is null.
The texture was disposed.
Another graphics device created the texture.
Dispose()
Releases the device texture. Safe to call more than once. Whoever created the texture (or the atlas or font that owns it) disposes it.
public void Dispose()Release()
Frees the device resource; called once by Dispose.
protected abstract void Release()Update(int, int, int, int, ReadOnlySpan<Color>)
Replaces the pixels of a rectangle of the texture (glyphs added to a font page, a painted canvas). The pixels are
row-major, width per row.
public void Update(int x, int y, int width, int height, ReadOnlySpan<Color> pixels)Parameters
x int
y int
width int
height int
pixels ReadOnlySpan<Color>
Exceptions
The rectangle leaves the texture.
pixels holds fewer than width × height colours.
Update(PixelImage, int, int)
Copies a whole image into the texture at (x, y).
public void Update(PixelImage image, int x = 0, int y = 0)Parameters
image PixelImage
x int
y int
Upload(int, int, int, int, ReadOnlySpan<Color>)
Sends pixels (exactly width × height, already checked) to the device.
protected abstract void Upload(int x, int y, int width, int height, ReadOnlySpan<Color> pixels)Parameters
x int
y int
width int
height int
pixels ReadOnlySpan<Color>