Table of Contents

Class PieUtils

Namespace
Pie
Assembly
Pie.dll

Various handy utilities you may use when developing with Pie.

public static class PieUtils
Inheritance
PieUtils
Inherited Members

Methods

Assert(bool, string)

Assert even in release mode.

public static void Assert(bool condition, string message)

Parameters

condition bool

The condition to assert.

message string

The message if the assertion fails.

Exceptions

PieException

Thrown if the assertion fails.

BitsPerPixel(Format)

Gets the bits per pixel of the given format. (For example, R8G8B8A8_UNorm would be 32-bits).

public static int BitsPerPixel(this Format format)

Parameters

format Format

Returns

int

Exceptions

ArgumentOutOfRangeException

CalculateMipLevels(int, int, int)

Calculate the total number of mipmap levels (including the most detailed mip) from the given width, height, and depth.

public static int CalculateMipLevels(int width, int height, int depth)

Parameters

width int

The width of the texture.

height int

The height of the texture.

depth int

The depth of the texture.

Returns

int

The number of mip levels.

Remarks

For the result to be accurate, you should use the width and height of the most detailed mip level.

Combine<T>(params T[][])

Combine multiple textures into one array. Pie texture functions only support a single byte array, however certain texture types (array textures, cubemaps) require you to have multiple of these byte arrays. This function performs a fast block copy of the arrays into a single array.

public static T[] Combine<T>(params T[][] data) where T : unmanaged

Parameters

data T[][]

The data arrays to combine.

Returns

T[]

The combined data.

Type Parameters

T

The data type.

CopyToUnmanaged<T>(nint, int, uint, T)

Copy the given data to a section in unmanaged memory (useful for copying data to a mapped buffer in a safe context.)

public static void CopyToUnmanaged<T>(nint unmanagedPtr, int offsetInBytes, uint sizeInBytes, T data) where T : unmanaged

Parameters

unmanagedPtr nint

The pointer to unmanaged memory.

offsetInBytes int

The offset in bytes.

sizeInBytes uint

The size of the data in bytes.

data T

The data itself.

Type Parameters

T

Any unmanaged type.

CopyToUnmanaged<T>(nint, int, uint, T[])

Copy the given data to a section in unmanaged memory (useful for copying data to a mapped buffer in a safe context.)

public static void CopyToUnmanaged<T>(nint unmanagedPtr, int offsetInBytes, uint dataLengthInBytes, T[] data) where T : unmanaged

Parameters

unmanagedPtr nint

The pointer to unmanaged memory.

offsetInBytes int

The offset in bytes.

dataLengthInBytes uint

The data length in bytes.

data T[]

The data itself.

Type Parameters

T

Any unmanaged type.

CopyToUnmanaged<T>(nint, int, T)

Copy the given data to a section in unmanaged memory (useful for copying data to a mapped buffer in a safe context.)

public static void CopyToUnmanaged<T>(nint unmanagedPtr, int offsetInBytes, T data) where T : unmanaged

Parameters

unmanagedPtr nint

The pointer to unmanaged memory.

offsetInBytes int

The offset in bytes.

data T

The data itself.

Type Parameters

T

Any unmanaged type.

CopyToUnmanaged<T>(nint, int, T[])

Copy the given data to a section in unmanaged memory (useful for copying data to a mapped buffer in a safe context.)

public static void CopyToUnmanaged<T>(nint unmanagedPtr, int offsetInBytes, T[] data) where T : unmanaged

Parameters

unmanagedPtr nint

The pointer to unmanaged memory.

offsetInBytes int

The offset in bytes.

data T[]

The data itself.

Type Parameters

T

Any unmanaged type.

Normalize(Color)

Normalize a Color for use in a shader.

public static Vector4 Normalize(this Color color)

Parameters

color Color

The color to normalize.

Returns

Vector4

The normalized color.