Class Texture
Represents a texture that can be used in rendering.
public class Texture : IGraphicsResource, ISerialization, IIdentifier
- Inheritance
-
Texture
- Implements
- Inherited Members
Constructors
Texture()
Initializes a new instance of the Texture class with default values.
public Texture()
Texture(int, int, Vector4i)
Initializes a new instance of the Texture class with specified width, height, and solid color.
public Texture(int widt, int height, Vector4i color)
Parameters
Texture(int, int, byte[])
Initializes a new instance of the Texture class with specified width, height, and raw pixel data in RGBA format.
public Texture(int width, int height, byte[] pixeldata)
Parameters
Exceptions
Texture(string)
Initializes a new instance of the Texture class by loading texture data from a file path.
public Texture(string path)
Parameters
pathstring
Fields
DefaultUVScale
The default UV scale for a texture. Value: (1.0, 1.0)
public static readonly Vector2 DefaultUVScale
Field Value
DefaultUVTransform
The default UV transform for a texture. Scale: (1.0, 1.0), Offset: (0.0, 0.0)
public static readonly Vector4 DefaultUVTransform
Field Value
Properties
HasAlpha
Gets or sets a value indicating whether the image contains an alpha (transparency) channel.
public bool HasAlpha { get; set; }
Property Value
Height
The height of the texture in pixels.
public int Height { get; set; }
Property Value
ID
Gets the unique identifier for this instance.
public Guid ID { get; }
Property Value
IsInitialized
Gets a value indicating whether the object has been initialized.
public bool IsInitialized { get; }
Property Value
Name
public string Name { get; set; }
Property Value
TextureData
The raw texture data in RGBA format.
public byte[]? TextureData { get; set; }
Property Value
- byte[]
TextureId
The unique identifier for the texture.
public int TextureId { get; set; }
Property Value
TextureParameters
Gets or sets the parameters used to configure texture sampling and filtering. Must be set before initializing the texture with a render device.
public TextureParameters TextureParameters { get; set; }
Property Value
Width
The width of the texture in pixels.
public int Width { get; set; }
Property Value
Methods
Copy()
Creates a copy of the texture.
public Texture Copy()
Returns
Deserialize(JObject, SerializationContext, Func<JObject, bool>)
Constructs the texture from JSON data.
public void Deserialize(JObject obj, SerializationContext context, Func<JObject, bool> callback = null)
Parameters
objJObjectcontextSerializationContextcallbackFunc<JObject, bool>
Exceptions
- InvalidOperationException
- JsonException
Dispose(IRenderDevice)
Frees resources used by the texture within the gpu.
public void Dispose(IRenderDevice renderer)
Parameters
rendererIRenderDevice
FreeCPUResources()
Frees the CPU resources used by the texture.
public void FreeCPUResources()
GetSafeUVTransform(float, float, float, float)
Get a safe UV transform for a given area of the texture, avoiding edge artifacts. Used for tilemaps and similar scenarios where you want to avoid sampling the edges of the texture.
public Vector4 GetSafeUVTransform(float x, float y, float width, float height)
Parameters
Returns
GetSubImage(Rect)
Get the UV transform for a given area of the texture.
public Vector4 GetSubImage(Rect area)
Parameters
areaRect
Returns
GetSubImage(float, float, float, float)
Gets the sub-image UV transforms for a specified area of the texture.
public Vector4 GetSubImage(float x, float y, float width, float height)
Parameters
Returns
Init(IRenderDevice)
Initializes the texture with the specified render device.
public void Init(IRenderDevice renderer)
Parameters
rendererIRenderDevice
MirrorUVTransform(Vector4, TextureMirrorMode)
Mirror the UV transform based on the specified mirror mode.
public static Vector4 MirrorUVTransform(Vector4 uvTransform, TextureMirrorMode mode)
Parameters
uvTransformVector4modeTextureMirrorMode
Returns
Serialize(JsonWriter, SerializationContext, Action<JsonWriter>)
Serializes the texture to JSON.
public void Serialize(JsonWriter writer, SerializationContext context, Action<JsonWriter> callback = null)
Parameters
writerJsonWritercontextSerializationContextcallbackAction<JsonWriter>
ToBitmap()
Convert the texture data to a Bitmap.
public Bitmap ToBitmap()