Textureclass

A texture is an image used in rendering. Can be a static texture loaded from disk, or a dynamic texture rendered to by code. Can also be 2D, 3D (multiple slices), or a cube texture (6 slices).

objectResourceTexture
Namespace
Sandbox
Assembly
Sandbox.Engine
Declaration
public class Sandbox.Texture : Sandbox.Resource

Methods43

Showing 43 methods

public void Clear(Color color)PUBLIC

Clear this texture with a solid color

ParameterTypeDescription
colorColor
Returns:void

public static Sandbox.Texture2DBuilder Create(int width, int height, Sandbox.ImageFormat format = 0)PUBLICSTATIC

Begins creation of a custom texture. Finish by calling `Sandbox.Texture2DBuilder.Finish`.

ParameterTypeDescription
widthint
heightint
format = 0ImageFormat
Returns:Texture2DBuilder

public static Sandbox.TextureArrayBuilder CreateArray(int width = 1, int height = 1, int count = 1, Sandbox.ImageFormat format = 0)PUBLICSTATIC

Begins creation of a custom texture array. Finish by calling `Sandbox.TextureArrayBuilder.Finish`.

ParameterTypeDescription
width = 1int
height = 1int
count = 1int
format = 0ImageFormat

public static Sandbox.TextureCubeBuilder CreateCube(int width = 1, int height = 1, Sandbox.ImageFormat format = 0)PUBLICSTATIC

Begins creation of a custom cube texture. (A texture with 6 sides) Finish by calling `Sandbox.TextureCubeBuilder.Finish`.

ParameterTypeDescription
width = 1int
height = 1int
format = 0ImageFormat

public static Sandbox.TextureBuilder CreateCustom()PUBLICSTATIC

Begins creation of a custom texture. Finish by calling `Sandbox.TextureBuilder.Create(System.String,System.Boolean,System.ReadOnlySpan,System.Int32)`.

Returns:TextureBuilder

public static Sandbox.Texture CreateFromSvgSource(string svgContents, System.Nullable`1<int> width, System.Nullable`1<int> height, System.Nullable`1<Color> color)PUBLICSTATIC

ParameterTypeDescription
svgContentsstring
widthNullable<int>
heightNullable<int>
colorNullable<Color>
Returns:Texture

public static Sandbox.Texture3DBuilder CreateVolume(int width, int height, int depth, Sandbox.ImageFormat format = 0)PUBLICSTATIC

Begins creation of a custom 3D texture. Finish by calling `Sandbox.Texture3DBuilder.Finish`.

ParameterTypeDescription
widthint
heightint
depthint
format = 0ImageFormat
Returns:Texture3DBuilder

public virtual sealed void Dispose()PUBLICVIRTUAL

Will release the handle for this texture. If the texture isn't referenced by anything else it'll be released properly. This will happen anyway because it's called in the destructor. By calling it manually you're just telling the engine you're done with this texture right now instead of waiting for the garbage collector.

Returns:void

protected virtual override void Finalize()PROTECTEDVIRTUALOVERRIDE

Returns:void

public static Sandbox.Texture Find(string filepath)PUBLICSTATIC

Try to get an already loaded texture.

ParameterTypeDescription
filepathstringThe filename of the texture.
Returns:TextureThe already loaded texture, or null if it was not yet loaded.

public Sandbox.Bitmap GetBitmap(int mip)PUBLIC

ParameterTypeDescription
mipint
Returns:Bitmap

public void GetBitmapAsync(System.Action`1<Sandbox.Bitmap> callback, int mip = 0)PUBLIC

ParameterTypeDescription
callbackAction<Bitmap>
mip = 0int
Returns:void

public Color32 GetPixel(float x, float y, int mip = 0)PUBLIC

Reads a single pixel color.

ParameterTypeDescription
xfloat
yfloat
mip = 0int
Returns:Color32

public Color32 GetPixel3D(float x, float y, float z, int mip = 0)PUBLIC

Reads a single pixel color from a volume or array texture.

ParameterTypeDescription
xfloat
yfloat
zfloat
mip = 0int
Returns:Color32

public void GetPixels3D(System.ValueTuple`6<int,int,int,int,int,int> srcBox, int mip, System.Span`1<T> dstData, Sandbox.ImageFormat dstFormat, System.ValueTuple`3<int,int,int> dstSize = null)PUBLIC

ParameterTypeDescription
srcBoxValueTuple<int,int,int,int,int,int>
mipint
dstDataSpan<T>
dstFormatImageFormat
dstSize = nullValueTuple<int,int,int>
Returns:void

public void GetPixelsAsync3D(System.Action`1<System.ReadOnlySpan`1<T>> callback, Sandbox.ImageFormat dstFormat = -2, System.ValueTuple`6<int,int,int,int,int,int> srcBox = null, int mip = 0)PUBLIC

ParameterTypeDescription
callbackAction<ReadOnlySpan<T>>
dstFormat = -2ImageFormat
srcBox = nullValueTuple<int,int,int,int,int,int>
mip = 0int
Returns:void

public int GetSequenceFrameCount(int sequenceId)PUBLIC

Get the frame count for this sequence

ParameterTypeDescription
sequenceIdint
Returns:int

public static Sandbox.Texture LoadFromFileSystem(string filepath, Sandbox.BaseFileSystem filesystem, bool warnOnMissing = True)PUBLICSTATIC

Try to load a texture from given filesystem, by filename.

ParameterTypeDescription
filepathstring
filesystemBaseFileSystem
warnOnMissing = Truebool
Returns:Texture

public static System.Threading.Tasks.Task`1<Sandbox.Texture> LoadFromFileSystemAsync(string filepath, Sandbox.BaseFileSystem filesystem, bool warnOnMissing = True)PUBLICSTATIC

Load a texture asynchronously. Will return when the texture is loaded and valid. This is useful when loading textures from the web, or without any big loading hitches.

ParameterTypeDescription
filepathstring
filesystemBaseFileSystem
warnOnMissing = Truebool
Returns:Task<Texture>

public void MarkUsed(int requiredMipSize = 0)PUBLIC

Tells texture streaming this texture is being used. This is usually automatic, but useful for bindless pipelines.

ParameterTypeDescription
requiredMipSize = 0int
Returns:void

public byte[] SaveToVtex(System.Nullable`1<Sandbox.ImageFormat> formatOverride = null)PUBLIC

ParameterTypeDescription
formatOverride = nullNullable<ImageFormat>
Returns:byte[]

public System.Threading.Tasks.Task`1<byte[]> SaveToVtexAsync(System.Nullable`1<Sandbox.ImageFormat> format = null)PUBLIC

ParameterTypeDescription
format = nullNullable<ImageFormat>
Returns:Task<byte[]>

public void Update3D(System.ReadOnlySpan`1<byte> data, int x = 0, int y = 0, int z = 0, int width = 0, int height = 0, int depth = 0)PUBLICPER-FRAME

ParameterTypeDescription
dataReadOnlySpan<byte>
x = 0int
y = 0int
z = 0int
width = 0int
height = 0int
depth = 0int
Returns:void

Properties20

Showing 20 properties

public static Sandbox.Texture Sandbox.Texture.Black { get; set; }PUBLICSTATICGETSET

1x1 solid black opaque texture.

Returns:Texture

public int Sandbox.Texture.Depth { get; set; }PUBLICGETSET

Depth of a 3D texture in pixels, or slice count for 2D texture arrays, or 6 for slices of cubemap.

Returns:int

public bool Sandbox.Texture.HasAnimatedSequences { get; set; }PUBLICGETSET

Returns:bool

public int Sandbox.Texture.Height { get; set; }PUBLICGETSET

Height of the texture in pixels.

Returns:int

public int Sandbox.Texture.Index { get; set; }PUBLICGETSET

Texture index. Bit raw dog and needs a higher level abstraction.

Returns:int

public static Sandbox.Texture Sandbox.Texture.Invalid { get; set; }PUBLICSTATICGETSET

1x1 solid magenta colored texture.

Returns:Texture

public virtual bool Sandbox.Texture.IsError { get; set; }PUBLICVIRTUALGETSET

Whether this texture is an error or invalid or not.

Returns:bool

public bool Sandbox.Texture.IsLoaded { get; set; }PUBLICGETSET

Whether this texture has finished loading or not.

Returns:bool

public virtual bool Sandbox.Texture.IsValid { get; set; }PUBLICVIRTUALGETSET

Returns:bool

public int Sandbox.Texture.LastUsed { get; set; }PUBLICGETSET

Returns how many frames ago this texture was last used by the renderer

Returns:int

public int Sandbox.Texture.Mips { get; set; }PUBLICGETSET

Number of mip maps this texture has.

Returns:int

public int Sandbox.Texture.SequenceCount { get; set; }PUBLICGETSET

The count of sequences in this texture, if any. The rest of the sequence data is encoded into the texture itself.

Returns:int

public Vector4 Sandbox.Texture.SequenceData { get; set; }PUBLICGETSET

If this texture is a sprite sheet, will return information about the sheet, which is generally used in the shader. You don't really need to think about the contents.

Returns:Vector4

public Vector2 Sandbox.Texture.Size { get; set; }PUBLICGETSET

Returns a Vector2 representing the size of the texture (width, height)

Returns:Vector2

public static Sandbox.Texture Sandbox.Texture.Transparent { get; set; }PUBLICSTATICGETSET

1x1 fully transparent texture.

Returns:Texture

public bool Sandbox.Texture.UAVAccess { get; set; }PUBLICGETSET

Gets if the texture has UAV access

Returns:bool

public static Sandbox.Texture Sandbox.Texture.White { get; set; }PUBLICSTATICGETSET

1x1 solid white opaque texture.

Returns:Texture

public int Sandbox.Texture.Width { get; set; }PUBLICGETSET

Width of the texture in pixels.

Returns:int

On this page

Methodspublic System.Void Clear(Color color)public static Sandbox.Texture2DBuilder Create(System.Int32 width, System.Int32 height, Sandbox.ImageFormat format = 0)public static Sandbox.TextureArrayBuilder CreateArray(System.Int32 width = 1, System.Int32 height = 1, System.Int32 count = 1, Sandbox.ImageFormat format = 0)public static Sandbox.TextureCubeBuilder CreateCube(System.Int32 width = 1, System.Int32 height = 1, Sandbox.ImageFormat format = 0)public static Sandbox.TextureBuilder CreateCustom()public static Sandbox.Texture CreateFromSvgSource(System.String svgContents, System.Nullable`1<System.Int32> width, System.Nullable`1<System.Int32> height, System.Nullable`1<Color> color)public static Sandbox.TextureBuilder CreateRenderTarget()public static Sandbox.Texture CreateRenderTarget(System.String name, Sandbox.ImageFormat format, Vector2 size, Sandbox.Texture oldTexture = null)public static Sandbox.Texture CreateRenderTarget(System.String name, Sandbox.ImageFormat format, Vector2 size)public static Sandbox.Texture3DBuilder CreateVolume(System.Int32 width, System.Int32 height, System.Int32 depth, Sandbox.ImageFormat format = 0)public virtual sealed System.Void Dispose()protected virtual override System.Void Finalize()public static Sandbox.Texture Find(System.String filepath)public Sandbox.Bitmap GetBitmap(System.Int32 mip)public System.Void GetBitmapAsync(System.Action`1<Sandbox.Bitmap> callback, System.Int32 mip = 0)public Color32 GetPixel(System.Single x, System.Single y, System.Int32 mip = 0)public Color32 GetPixel3D(System.Single x, System.Single y, System.Single z, System.Int32 mip = 0)public Color32[] GetPixels(System.Int32 mip = 0)public System.Void GetPixels(System.ValueTuple`4<System.Int32,System.Int32,System.Int32,System.Int32> srcRect, System.Int32 slice, System.Int32 mip, System.Span`1<T> dstData, Sandbox.ImageFormat dstFormat, System.ValueTuple`2<System.Int32,System.Int32> dstSize = null)public System.Void GetPixels(System.ValueTuple`4<System.Int32,System.Int32,System.Int32,System.Int32> srcRect, System.Int32 slice, System.Int32 mip, System.Span`1<T> dstData, Sandbox.ImageFormat dstFormat, System.ValueTuple`4<System.Int32,System.Int32,System.Int32,System.Int32> dstRect, System.Int32 dstStride)public System.Void GetPixels3D(System.ValueTuple`6<System.Int32,System.Int32,System.Int32,System.Int32,System.Int32,System.Int32> srcBox, System.Int32 mip, System.Span`1<T> dstData, Sandbox.ImageFormat dstFormat, System.ValueTuple`3<System.Int32,System.Int32,System.Int32> dstSize = null)public System.Void GetPixelsAsync(System.Action`1<System.ReadOnlySpan`1<Color32>> callback, System.Int32 mip = 0)public System.Void GetPixelsAsync(System.Action`1<System.ReadOnlySpan`1<T>> callback, Sandbox.ImageFormat dstFormat = -2, System.ValueTuple`4<System.Int32,System.Int32,System.Int32,System.Int32> srcRect = null, System.Int32 slice = 0, System.Int32 mip = 0)public System.Void GetPixelsAsync3D(System.Action`1<System.ReadOnlySpan`1<T>> callback, Sandbox.ImageFormat dstFormat = -2, System.ValueTuple`6<System.Int32,System.Int32,System.Int32,System.Int32,System.Int32,System.Int32> srcBox = null, System.Int32 mip = 0)public System.Int32 GetSequenceFrameCount(System.Int32 sequenceId)public static Sandbox.Texture Load(Sandbox.BaseFileSystem filesystem, System.String filepath, System.Boolean warnOnMissing = True)public static Sandbox.Texture Load(System.String path_or_url, System.Boolean warnOnMissing = True)public static System.Threading.Tasks.Task`1<Sandbox.Texture> LoadAsync(Sandbox.BaseFileSystem filesystem, System.String filepath, System.Boolean warnOnMissing = True)public static System.Threading.Tasks.Task`1<Sandbox.Texture> LoadAsync(System.String filepath, System.Boolean warnOnMissing = True)public static Sandbox.Texture LoadAvatar(System.Int64 steamid, System.Int32 size = 64)public static Sandbox.Texture LoadAvatar(System.String steamid, System.Int32 size)public static Sandbox.Texture LoadFromFileSystem(System.String filepath, Sandbox.BaseFileSystem filesystem, System.Boolean warnOnMissing = True)public static System.Threading.Tasks.Task`1<Sandbox.Texture> LoadFromFileSystemAsync(System.String filepath, Sandbox.BaseFileSystem filesystem, System.Boolean warnOnMissing = True)public System.Void MarkUsed(System.Int32 requiredMipSize = 0)public System.Byte[] SaveToVtex(System.Nullable`1<Sandbox.ImageFormat> formatOverride = null)public System.Threading.Tasks.Task`1<System.Byte[]> SaveToVtexAsync(System.Nullable`1<Sandbox.ImageFormat> format = null)public System.Void Update(Color32 color, Sandbox.Rect rect)public System.Void Update(Color32 color, System.Single x, System.Single y)public System.Void Update(Sandbox.Bitmap source)public System.Void Update(System.ReadOnlySpan`1<Color32> data, System.Int32 x = 0, System.Int32 y = 0, System.Int32 width = 0, System.Int32 height = 0)public System.Void Update(System.ReadOnlySpan`1<System.Byte> data, System.Int32 x = 0, System.Int32 y = 0, System.Int32 width = 0, System.Int32 height = 0)public System.Void Update(System.ReadOnlySpan`1<T> data, System.Int32 x = 0, System.Int32 y = 0, System.Int32 width = 0, System.Int32 height = 0)public System.Void Update3D(System.ReadOnlySpan`1<System.Byte> data, System.Int32 x = 0, System.Int32 y = 0, System.Int32 z = 0, System.Int32 width = 0, System.Int32 height = 0, System.Int32 depth = 0)Propertiespublic static Sandbox.Texture Sandbox.Texture.Black { get; set; }public System.Int32 Sandbox.Texture.Depth { get; set; }public Sandbox.TextureFlags Sandbox.Texture.Flags { get; set; }public System.Boolean Sandbox.Texture.HasAnimatedSequences { get; set; }public System.Int32 Sandbox.Texture.Height { get; set; }public Sandbox.ImageFormat Sandbox.Texture.ImageFormat { get; set; }public System.Int32 Sandbox.Texture.Index { get; set; }public static Sandbox.Texture Sandbox.Texture.Invalid { get; set; }public virtual System.Boolean Sandbox.Texture.IsError { get; set; }public System.Boolean Sandbox.Texture.IsLoaded { get; set; }public virtual System.Boolean Sandbox.Texture.IsValid { get; set; }public System.Int32 Sandbox.Texture.LastUsed { get; set; }public System.Int32 Sandbox.Texture.Mips { get; set; }public System.Int32 Sandbox.Texture.SequenceCount { get; set; }public Vector4 Sandbox.Texture.SequenceData { get; set; }public Vector2 Sandbox.Texture.Size { get; set; }public static Sandbox.Texture Sandbox.Texture.Transparent { get; set; }public System.Boolean Sandbox.Texture.UAVAccess { get; set; }public static Sandbox.Texture Sandbox.Texture.White { get; set; }public System.Int32 Sandbox.Texture.Width { get; set; }Metadata