Skip to content

GraphicsAPI reference

Class Texture

Namespace: MicroEngine.Graphics
Assembly: MicroEngine.Graphics2D.dll
Guide: Graphics

A GPU (or headless) texture owned by the active graphics device.

C#
public abstract class Texture : IDisposable

Inheritance

object ← Texture

Implements

IDisposable

Constructors

Texture(int, int, TextureFilter)

Records the size and filter of a texture created by a graphics device.

C#
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.

C#
protected Texture(IGraphicsDevice device, int width, int height, TextureFilter filter = TextureFilter.Nearest)

Parameters

device IGraphicsDevice

width int

height int

filter TextureFilter

Exceptions

ArgumentNullException

device is null.

Properties

Bounds

The whole texture as a source rectangle: (0, 0, Width, Height).

C#
public RectF Bounds { get; }

Property Value

RectF

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.

C#
public IGraphicsDevice? Device { get; }

Property Value

IGraphicsDevice?

Filter

How the texture is sampled; it can change at any time and applies to the next draws.

C#
public TextureFilter Filter { get; set; }

Property Value

TextureFilter

Height

Height in pixels.

C#
public int Height { get; }

Property Value

int

IsDisposed

Whether Dispose was called. Drawing a disposed texture throws ObjectDisposedException on every renderer, and nothing is drawn.

C#
public bool IsDisposed { get; }

Property Value

bool

SizeInBytes

Memory the texture’s pixels take on the device, in bytes (4 per pixel).

C#
public long SizeInBytes { get; }

Property Value

long

Width

Width in pixels.

C#
public int Width { get; }

Property Value

int

Methods

ApplyFilter(TextureFilter)

Applies a new filter on the device; called by Filter when it changes.

C#
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.

C#
public static TTexture CheckDrawable<TTexture>(Texture texture, IGraphicsDevice device) where TTexture : Texture

Parameters

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

ArgumentNullException

texture is null.

ObjectDisposedException

The texture was disposed.

ArgumentException

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.

C#
public void Dispose()

Release()

Frees the device resource; called once by Dispose.

C#
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.

C#
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

ArgumentOutOfRangeException

The rectangle leaves the texture.

ArgumentException

pixels holds fewer than width × height colours.

Update(PixelImage, int, int)

Copies a whole image into the texture at (x, y).

C#
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.

C#
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>