class Tex

This is the texture asset class! This encapsulates 2D images, texture arrays, cubemaps, and rendertargets! It can load any image format that stb_image can, (jpg, png, tga, bmp, psd, gif, hdr, pic) plus more later on, and you can also create textures procedurally.

Instance Fields and Properties

   
TexAddress AddressMode When looking at a UV texture coordinate on this texture, how do we handle values larger than 1, or less than zero? Do we Wrap to the other side? Clamp it between 0-1, or just keep Mirroring back and forth? Wrap is the default.
int Anisoptropy When SampleMode is set to Anisotropic, this is the number of samples the GPU takes to figure out the correct color. Default is 4, and 16 is pretty high.
AssetState AssetState Textures are loaded asyncronously, so this tells you the current state of this texture! This also can tell if an error occured, and what type of error it may have been.
SphericalHarmonics CubemapLighting ONLY valid for cubemap textures! This will calculate a spherical harmonics representation of the cubemap for use with StereoKit’s lighting. First call may take a frame or two of time, but subsequent calls will pull from a cached value.
Tex FallbackOverride This will override the default fallback texutre that gets used before the Tex has finished loading. This is useful for textures with a specific purpose where the normal fallback texture would appear strange, such as a metal/rough map.
TexFormat Format The StereoKit format this texture was initialized with. This will be a blocking call if AssetState is less than LoadedMeta.
int Height The height of the texture, in pixels. This will be a blocking call if AssetState is less than LoadedMeta.
string Id Gets or sets the unique identifier of this asset resource! This can be helpful for debugging, managine your assets, or finding them later on!
int Mips The number of mip-map levels this texture has. This will be 1 if the texture doesn’t have mip mapping enabled. This will be a blocking call if AssetState is less than LoadedMeta.
TexSample SampleMode When sampling a texture that’s stretched, or shrunk beyond its screen size, how do we handle figuring out which color to grab from the texture? Default is Linear.
int Width The width of the texture, in pixels. This will be a blocking call if AssetState is less than LoadedMeta.

Instance Methods

   
Tex Sets up an empty texture container! Fill it with data using SetColors next! Creates a default unique asset Id.
AddZBuffer Only applicable if this texture is a rendertarget! This creates and attaches a zbuffer surface to the texture for use when rendering to it.
GetColorData Retrieve the color data of the texture from the GPU. This can be a very slow operation, so use it cautiously.
GetColors Retrieve the color data of the texture from the GPU. This can be a very slow operation, so use it cautiously. If the color array is the correct size, it will not be re-allocated.
GetNativeSurface This will return the texture’s native resource for use with external libraries. For D3D, this will be an ID3D11Texture2D*, and for GL, this will be a uint32_t from a glGenTexture call, coerced into the IntPtr. This call will block execution until the texture is loaded, if it is not already.
SetColors Set the texture’s pixels using a pointer to a chunk of memory! This is great if you’re pulling in some color data from native code, and don’t want to pay the cost of trying to marshal that data around.
SetMemory Loads an image file stored in memory directly into the created texture! Supported formats are: jpg, png, tga, bmp, psd, gif, hdr, pic. This method introduces a blocking boolean parameter, which allows you to specify whether this method blocks until the image fully loads! The default case is to have it as part of the asynchronous asset pipeline, in which the Asset Id will be the same as the filename.
SetNativeSurface This function is dependent on the graphics backend! It will take a texture resource for the current graphics backend (D3D or GL) and wrap it in a StereoKit texture for use within StereoKit. This is a bit of an advanced feature.
SetSize Set the texture’s size without providing any color data. In most cases, you should probably just call SetColors instead, but this can be useful if you’re adding color data some other way, such as when blitting or rendering to it.

Static Fields and Properties

   
Tex Black Default 2x2 black opaque texture, this is the texture referred to as ‘black’ in the shader texture defaults.
Tex DevTex This is a white checkered grid texture used to easily add visual features to materials. By default, this is used for the loading fallback texture for all Tex objects.
Tex Error This is a red checkered grid texture used to indicate some sort of error has occurred. By default, this is used for the error fallback texture for all Tex objects.
Tex Flat Default 2x2 flat normal texture, this is a normal that faces out from the, face, and has a color value of (0.5,0.5,1). This is the texture referred to as ‘flat’ in the shader texture defaults.
Tex Gray Default 2x2 middle gray (0.5,0.5,0.5) opaque texture, this is the texture referred to as ‘gray’ in the shader texture defaults.
Tex Rough Default 2x2 roughness color (1,1,0,1) texture, this is the texture referred to as ‘rough’ in the shader texture defaults.
Tex White Default 2x2 white opaque texture, this is the texture referred to as ‘white’ in the shader texture defaults.

Static Methods

   
Find Finds a texture that matches the given Id! Check out the DefaultIds static class for some built-in ids.
FromColors Creates a texture and sets the texture’s pixels using a color array! This will be an image of type TexType.Image, and a format of TexFormat.Rgba32 or TexFormat.Rgba32Linear depending on the value of the sRGBData parameter.
FromCubemapEquirectangular Creates a cubemap texture from a single equirectangular image! You know, the ones that look like an unwrapped globe with the poles all stretched out. It uses some fancy shaders and texture blitting to create 6 faces from the equirectangular image.
FromCubemapFile Creates a cubemap texture from 6 different image files! If you have a single equirectangular image, use Tex.FromEquirectangular instead. Asset Id will be the first filename.
FromFile Loads an image file directly into a texture! Supported formats are: jpg, png, tga, bmp, psd, gif, hdr, pic. Asset Id will be the same as the filename.
FromFiles Loads an array of image files directly into a single array texture! Array textures are often useful for shader effects, layering, material merging, weird stuff, and will generally need a specific shader to support it. Supported formats are: jpg, png, tga, bmp, psd, gif, hdr, pic. Asset Id will be the hash of all the filenames merged consecutively.
FromMemory Loads an image file stored in memory directly into a texture! Supported formats are: jpg, png, tga, bmp, psd, gif, hdr, pic. Asset Id will be the same as the filename.
GenColor This generates a solid color texture of the given dimensions. Can be quite nice for creating placeholder textures! Make sure to match linear/gamma colors with the correct format.
GenCubemap Generates a cubemap texture from a gradient and a direction! These are entirely suitable for skyboxes, which you can set via Renderer.SkyTex.
GenParticle Generates a ‘radial’ gradient that works well for particles, blob shadows, glows, or various other things. The roundness can be used to change the shape from round, ‘1’, to star-like, ‘0’. Default color is transparent white to opaque white, but this can be configured by providing a Gradient of your own.
SetErrorFallback This is the texture that all Tex objects with errors will fall back to. Assigning a texture here that isn’t fully loaded will cause the app to block until it is loaded.
SetLoadingFallback This is the texture that all Tex objects will fall back to by default if they are still loading. Assigning a texture here that isn’t fully loaded will cause the app to block until it is loaded.




Found an issue with these docs, or have some additional questions? Create an Issue on Github!