Textures Scripting API
Module:
engine.resources.texture_resource
Handle Type:
TextureId
Enumerations
- AnisotropyLevel
Anisotropy level enumeration. For more information see: https://en.wikipedia.org/wiki/Anisotropic_filtering
- Values:
x1 = 0x1
x2 = 0x2
x4 = 0x4
x8 = 0x8
x16 = 0x10
- TextureAddress
Texture address enumeration
- Values:
Wrap = 0x1 - Wrap texture addressing mode.
Mirror = 0x2 - Mirror texture addressing mode.
Clamp = 0x3 - Clamp texture addressing mode.
Border = 0x4 - Border texture addressing mode.
MirrorOnce = 0x5 - Mirror once texture addressing mode.
- TextureFilter
Texture filter enumeration
- Values:
Point = 0x1 - Point texture filter.
Bilinear = 0x2 - Bilinear texture filter.
Anisotropic = 0x3 - Anisotropic texture filter.
- TextureFormat
Texture format enumeration
- Values:
A8R8G8B8 = 0x0 - 32-bit ARGB pixel format with alpha, using 8 bits per channel.
A2R10G10B10 = 0x1000000 - 32-bit ARGB pixel format using 10 bits for each color channel and 2 bits for alpha.
A2B10G10R10 = 0x2000000 - 32-bit ABGR pixel format using 10 bits for each color channel and 2 bits for alpha.
A16B16G16R16 = 0x3000000 - 64-bit ARGB pixel format using 16 bits for each channel.
G16R16 = 0x6000000 - 32-bit RG pixel format using 16 bits for each channel.
R8 = 0x12000000 - 8-bit red channel only.
A8 = 0x11000000 - 8-bit alpha channel only.
A32B32G32R32F = 0x5000000 - 128-bit ARGB pixel format using 32 bits for each channel (float).
G32R32F = 0x8000000 - 64-bit RG pixel format using 32 bits for each channel (float).
R32F = 0xa000000 - 32-bit red channel only (float).
A16B16G16R16F = 0x4000000 - 64-bit ARGB pixel format using 16 bits for each channel (half).
G16R16F = 0x7000000 - 32-bit RG pixel format using 16 bits for each channel (half).
R16F = 0x9000000 - 16-bit red channel only (half).
A32B32G32R32UI = 0x19000000 - 128-bit ARGB pixel format using 32 bits for each channel (unsigned int).
R32G32UI = 0xe000000 - 64-bit RG pixel format using 32 bits for each channel (unsigned int).
R32UI = 0x1d000000 - 32-bit red channel only (unsigned int).
A16B16G16R16UI = 0x18000000 - 64-bit ARGB pixel format using 16 bits for each channel (unsigned int).
R8UI = 0x25000000 - 8-bit red channel only (unsigned int).
DXT1 = 0xb000000 - DXT1 compressed format. Doestn’t support alpha. Compression ratio 6:1.
DXT3 = 0xc000000 - DXT3 compressed format. Has sharp alpha. Compression ratio 4:1.
DXT5 = 0xd000000 - DXT5 compressed format. Has gradient alpha. Compression ratio 4:1.
ATI1N = 0x1a000000 - ATI1N compressed format, Also known as BC4. Single red channel map. Compression ratio 8:1.
ATI2N = 0x1b000000 - ATI2N compressed format, Also known as BC5. Two channel map. Compression ratio 4:1.
Structures
- TextureDeclaration
Texture declaration. This structure is used to describe Texture2D properties for GPU.
- Fields:
filter : TextureFilter = texture_resource::TextureFilter.Bilinear - Texture filtration mode
addressing : TextureAddress = texture_resource::TextureAddress.Wrap - Texture addressing mode
anisotropicLevel : AnisotropyLevel = texture_resource::AnisotropyLevel.x4 - Texture anisotropic level. Works only with filter = TextureFilter Anisotropic.
sRGB : bool = true - Use sRGB color space for texture
generateMipLevels : bool = true - Generate mip levels for texture
format : TextureFormat = texture_resource::TextureFormat.A8R8G8B8 - Texture format
- Bitmap
Bitmap for work with color32 texture
- Fields:
pixels : array<uint> - pixels array
w : int - width
h : int - height
- Texture2Dfloat4
Texture for work with float4 texture
- Fields:
pixels : array<float4> - pixels array
w : int - width
h : int - height
- Texture2Dfloat2
Texture for work with float2 texture
- Fields:
pixels : array<float2> - pixels array
w : int - width
h : int - height
- Texture2Dfloat
Texture for work with float texture
- Fields:
pixels : array<float> - pixels array
w : int - width
h : int - height
- Texture2Duint4
Texture for work with uint4 texture
- Fields:
pixels : array<uint4> - pixels array
w : int - width
h : int - height
- Texture2Duint2
Texture for work with uint2 texture
- Fields:
pixels : array<uint2> - pixels array
w : int - width
h : int - height
- Texture2Duint
Texture for work with uint texture
- Fields:
pixels : array<uint> - pixels array
w : int - width
h : int - height
Functions
create_render_target (w: int; h: int; declaration: TextureDeclaration) : TextureId
create_texture (color: uint; declaration: TextureDeclaration = TextureDeclaration()) : TextureId
create_texture (color: float4; declaration: TextureDeclaration = TextureDeclaration()) : TextureId
get_image_content (path: string; cb: block<(var bitmap:Bitmap):void>) : bool
get_texture_size (textureId: TextureId; blk: block<(size:int2):void>) : bool
- request_texture(path_to_texture: string): TextureId
Request texture asset located in the ‘path_to_texture’ multiple request calls with same path and other properties will return same TextureId
- Arguments:
path_to_texture : string
- Bitmap(w: int; h: int): Bitmap
Create Bitmap with size ‘w’x’h’, filled with zeros
- Arguments:
w : int
h : int
- Texture2Dfloat4(w: int; h: int): Texture2Dfloat4
Create Texture2Dfloat4 with size ‘w’x’h’, filled with zeros
- Arguments:
w : int
h : int
- Texture2Dfloat2(w: int; h: int): Texture2Dfloat2
Create Texture2Dfloat2 with size ‘w’x’h’, filled with zeros
- Arguments:
w : int
h : int
- Texture2Dfloat(w: int; h: int): Texture2Dfloat
Create Texture2Dfloat with size ‘w’x’h’, filled with zeros
- Arguments:
w : int
h : int
- Texture2Duint4(w: int; h: int): Texture2Duint4
Create Texture2Duint4 with size ‘w’x’h’, filled with zeros
- Arguments:
w : int
h : int
- Texture2Duint2(w: int; h: int): Texture2Duint2
Create Texture2Duint2 with size ‘w’x’h’, filled with zeros
- Arguments:
w : int
h : int
- Texture2Duint(w: int; h: int): Texture2Duint
Create Texture2Duint with size ‘w’x’h’, filled with zeros
- Arguments:
w : int
h : int
- create_render_target(w: int; h: int; declaration: TextureDeclaration): TextureId
Create render target texture ‘w’x’h’ with ‘pixels’ and ‘declaration’ This texture can be used as ‘render target’ in camera component
- Arguments:
w : int
h : int
declaration : TextureDeclaration
- create_texture(w: int; h: int; pixels: array<uint>; declaration: TextureDeclaration; rgba8_format: bool = true): TextureId
Create texture ‘w’x’h’ with ‘pixels’ and ‘declaration’
- Arguments:
w : int
h : int
pixels : array<uint>
declaration : TextureDeclaration
rgba8_format : bool
- create_texture(color: uint; declaration: TextureDeclaration = TextureDeclaration()): TextureId
Create 1x1 texture filled with ‘color’
- Arguments:
color : uint
declaration : TextureDeclaration
- create_texture(color: float4; declaration: TextureDeclaration = TextureDeclaration()): TextureId
Create 1x1 texture filled with ‘color’
- Arguments:
color : float4
declaration : TextureDeclaration
- create_texture(tex: Bitmap|Texture2Dfloat4|Texture2Dfloat2|Texture2Dfloat|Texture2Duint4|Texture2Duint2|Texture2Duint; request: TextureDeclaration): TextureId
Create texture resource with given ‘tex’ content and properties in ‘request’
- Arguments:
tex : option< Bitmap | Texture2Dfloat4 | Texture2Dfloat2 | Texture2Dfloat | Texture2Duint4 | Texture2Duint2 | Texture2Duint >
request : TextureDeclaration
- create_texture(w: int; h: int; pixels: array<auto(TT)>; declaration: TextureDeclaration): TextureId
Create texture ‘w’x’h’ with ‘pixels’ and ‘declaration’
- Arguments:
w : int
h : int
pixels : array<auto(TT)>
declaration : TextureDeclaration
- get_image_content(path: string; cb: block<(var bitmap:Bitmap):void>): bool
Retrieves the content of an image from disk and invokes the provided callback with the pixel data and size.
- Arguments:
path : string - path to the image file
cb : block<(bitmap: Bitmap ):void> - the callback function to invoke with the bitmap
- Returns:
bool - true if the image was successfully loaded, false otherwise
Usage example:
get_image_content(image_path) $(var bitmap : Bitmap) {
// Do something with bitmap
image1 = bitmap // move data to another variable
}
- get_texture_size(textureId: TextureId; blk: block<(size:int2):void>): bool
Retrieves the size of a texture and returns it via the provided block.
- Arguments:
textureId : TextureId - the ID of the texture resource
blk : block<(size:int2):void> - block to handle the size of the texture
- Returns:
bool - true if the image resource exists, false otherwise
Usage example:
get_texture_size(textureId) $(size : int2) {
print("Texture size: {size.x} x {size.y}")
}
- update_texture(tex: Bitmap|Texture2Dfloat4|Texture2Dfloat2|Texture2Dfloat|Texture2Duint4|Texture2Duint2|Texture2Duint; resId: TextureId; mip: int = 0; offset: int2 = int2(0, 0); size: int2 = int2(0, 0))
Update texture with new data
- Arguments:
tex : option< Bitmap | Texture2Dfloat4 | Texture2Dfloat2 | Texture2Dfloat | Texture2Duint4 | Texture2Duint2 | Texture2Duint >
resId : TextureId
mip : int
offset : int2
size : int2