public class Sandbox.Texture : Sandbox.Resource
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).
Related Guides
Broader workflow and conceptual references connected to this API.
If you want a specific file/asset type to have a custom Thumbnail/Inspector Preview, you can simply create an AssetPreview. An AssetPreview initializes a SceneWorld and SceneCamera, rendering the Camera to the Preview output, so all you need to do is populate it and/or position the Camera to your liking.
The fancy new way to do things in Vulkan / DX12 is bindless. This removes the limitations of the binding model allowing you to have access to far more textures and other resources within a shader and the ability to sample them from a dynamically provided identifier from buffers, vertex input, etc.
The mount system is extensible - anyone can write a mount to add support for a new game or engine and contribute it to s&box via pull request. A mount detects a game's install directory via Steam, scans its files, and converts assets into s&box compatible assets, all at runtime.
Much like SSAO, you can composite dynamic specular reflections on your object, whether they are SSR or eventually Raytraced Reflections
Input glyphs are an easy way to show users which buttons to press for actions, they automatically adjust for whatever device you're using and return appropriate textures.
If you want to access lighting information directly you can use this.
Methods
Showing 43 methods
public static Sandbox.Texture2DBuilder Create(int width, int height, Sandbox.ImageFormat format = 0)
Begins creation of a custom texture. Finish by calling `Sandbox.Texture2DBuilder.Finish`.
Parameters
format: Default: 0
public static Sandbox.TextureArrayBuilder CreateArray(int width = 1, int height = 1, int count = 1, Sandbox.ImageFormat format = 0)
Begins creation of a custom texture array. Finish by calling `Sandbox.TextureArrayBuilder.Finish`.
Parameters
width: Default: 1height: Default: 1count: Default: 1format: Default: 0
public static Sandbox.TextureCubeBuilder CreateCube(int width = 1, int height = 1, Sandbox.ImageFormat format = 0)
Begins creation of a custom cube texture. (A texture with 6 sides) Finish by calling `Sandbox.TextureCubeBuilder.Finish`.
Parameters
width: Default: 1height: Default: 1format: Default: 0
public static Sandbox.TextureBuilder CreateCustom()
Begins creation of a custom texture. Finish by calling `Sandbox.TextureBuilder.Create(System.String,System.Boolean,System.ReadOnlySpan,System.Int32)`.
public static Sandbox.Texture CreateFromSvgSource(string svgContents, System.Nullable`1<int> width, System.Nullable`1<int> height, System.Nullable`1<Color> color)
public static Sandbox.Texture3DBuilder CreateVolume(int width, int height, int depth, Sandbox.ImageFormat format = 0)
Begins creation of a custom 3D texture. Finish by calling `Sandbox.Texture3DBuilder.Finish`.
Parameters
format: Default: 0
public virtual sealed void Dispose()
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.
protected virtual override void Finalize()
public static Sandbox.Texture Find(string filepath)
Try to get an already loaded texture.
Parameters
filepath: The filename of the texture.
Returns
The already loaded texture, or null if it was not yet loaded.
public Sandbox.Bitmap GetBitmap(int mip)
public void GetBitmapAsync(System.Action`1<Sandbox.Bitmap> callback, int mip = 0)
Parameters
mip: Default: 0
public Color32 GetPixel(float x, float y, int mip = 0)
Reads a single pixel color.
Parameters
mip: Default: 0
public Color32 GetPixel3D(float x, float y, float z, int mip = 0)
Reads a single pixel color from a volume or array texture.
Parameters
mip: Default: 0
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)
Parameters
dstSize: Default: null
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)
Parameters
dstFormat: Default: -2srcBox: Default: nullmip: Default: 0
public int GetSequenceFrameCount(int sequenceId)
Get the frame count for this sequence
public static Sandbox.Texture LoadFromFileSystem(string filepath, Sandbox.BaseFileSystem filesystem, bool warnOnMissing = True)
Try to load a texture from given filesystem, by filename.
Parameters
warnOnMissing: Default: True
public static System.Threading.Tasks.Task`1<Sandbox.Texture> LoadFromFileSystemAsync(string filepath, Sandbox.BaseFileSystem filesystem, bool warnOnMissing = True)
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.
Parameters
warnOnMissing: Default: True
public void MarkUsed(int requiredMipSize = 0)
Tells texture streaming this texture is being used. This is usually automatic, but useful for bindless pipelines.
Parameters
requiredMipSize: Default: 0
public byte[] SaveToVtex(System.Nullable`1<Sandbox.ImageFormat> formatOverride = null)
Parameters
formatOverride: Default: null
public System.Threading.Tasks.Task`1<byte[]> SaveToVtexAsync(System.Nullable`1<Sandbox.ImageFormat> format = null)
Parameters
format: Default: null
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)
Parameters
x: Default: 0y: Default: 0z: Default: 0width: Default: 0height: Default: 0depth: Default: 0
No results match this filter.
Properties
Showing 20 properties
public int Sandbox.Texture.Depth { get; set; }
Depth of a 3D texture in pixels, or slice count for 2D texture arrays, or 6 for slices of cubemap.
public Sandbox.TextureFlags Sandbox.Texture.Flags { get; set; }
Flags providing hints about this texture
public bool Sandbox.Texture.HasAnimatedSequences { get; set; }
public int Sandbox.Texture.Height { get; set; }
Height of the texture in pixels.
public Sandbox.ImageFormat Sandbox.Texture.ImageFormat { get; set; }
Image format of this texture.
public int Sandbox.Texture.Index { get; set; }
Texture index. Bit raw dog and needs a higher level abstraction.
public static Sandbox.Texture Sandbox.Texture.Invalid { get; set; }
1x1 solid magenta colored texture.
public bool Sandbox.Texture.IsError { get; set; }
Whether this texture is an error or invalid or not.
public bool Sandbox.Texture.IsLoaded { get; set; }
Whether this texture has finished loading or not.
public virtual bool Sandbox.Texture.IsValid { get; set; }
public int Sandbox.Texture.LastUsed { get; set; }
Returns how many frames ago this texture was last used by the renderer
public int Sandbox.Texture.Mips { get; set; }
Number of mip maps this texture has.
public int Sandbox.Texture.SequenceCount { get; set; }
The count of sequences in this texture, if any. The rest of the sequence data is encoded into the texture itself.
public Vector4 Sandbox.Texture.SequenceData { get; set; }
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.
public Vector2 Sandbox.Texture.Size { get; set; }
Returns a Vector2 representing the size of the texture (width, height)
public static Sandbox.Texture Sandbox.Texture.Transparent { get; set; }
1x1 fully transparent texture.
public bool Sandbox.Texture.UAVAccess { get; set; }
Gets if the texture has UAV access
public int Sandbox.Texture.Width { get; set; }
Width of the texture in pixels.
No results match this filter.
Metadata
| Field | Value |
|---|---|
| Namespace | Sandbox |
| Type | class |
| Assembly | Sandbox.Engine |
| Doc ID | T:Sandbox.Texture |