.. _stdlib_texture_resource: ====================== Textures Scripting API ====================== Module:: engine.resources.texture_resource Handle Type:: TextureId ++++++++++++ Enumerations ++++++++++++ .. _enum-texture_resource-AnisotropyLevel: .. das:attribute:: 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 .. _enum-texture_resource-TextureAddress: .. das:attribute:: 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. .. _enum-texture_resource-TextureFilter: .. das:attribute:: TextureFilter Texture filter enumeration :Values: * **Point** = 0x1 - Point texture filter. * **Bilinear** = 0x2 - Bilinear texture filter. * **Anisotropic** = 0x3 - Anisotropic texture filter. .. _enum-texture_resource-TextureFormat: .. das:attribute:: 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 ++++++++++ .. _struct-texture_resource-TextureDeclaration: .. das:attribute:: TextureDeclaration Texture declaration. This structure is used to describe Texture2D properties for GPU. :Fields: * **filter** : :ref:`TextureFilter ` = texture_resource::TextureFilter.Bilinear - Texture filtration mode * **addressing** : :ref:`TextureAddress ` = texture_resource::TextureAddress.Wrap - Texture addressing mode * **anisotropicLevel** : :ref:`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** : :ref:`TextureFormat ` = texture_resource::TextureFormat.A8R8G8B8 - Texture format .. _struct-texture_resource-Bitmap: .. das:attribute:: Bitmap Bitmap for work with color32 texture :Fields: * **pixels** : array - pixels array * **w** : int - width * **h** : int - height .. _struct-texture_resource-Texture2Dfloat4: .. das:attribute:: Texture2Dfloat4 Texture for work with float4 texture :Fields: * **pixels** : array - pixels array * **w** : int - width * **h** : int - height .. _struct-texture_resource-Texture2Dfloat2: .. das:attribute:: Texture2Dfloat2 Texture for work with float2 texture :Fields: * **pixels** : array - pixels array * **w** : int - width * **h** : int - height .. _struct-texture_resource-Texture2Dfloat: .. das:attribute:: Texture2Dfloat Texture for work with float texture :Fields: * **pixels** : array - pixels array * **w** : int - width * **h** : int - height .. _struct-texture_resource-Texture2Duint4: .. das:attribute:: Texture2Duint4 Texture for work with uint4 texture :Fields: * **pixels** : array - pixels array * **w** : int - width * **h** : int - height .. _struct-texture_resource-Texture2Duint2: .. das:attribute:: Texture2Duint2 Texture for work with uint2 texture :Fields: * **pixels** : array - pixels array * **w** : int - width * **h** : int - height .. _struct-texture_resource-Texture2Duint: .. das:attribute:: Texture2Duint Texture for work with uint texture :Fields: * **pixels** : array - pixels array * **w** : int - width * **h** : int - height +++++++++ Functions +++++++++ * :ref:`request_texture (path_to_texture: string) : TextureId ` * :ref:`Bitmap (w: int; h: int) : Bitmap ` * :ref:`Texture2Dfloat4 (w: int; h: int) : Texture2Dfloat4 ` * :ref:`Texture2Dfloat2 (w: int; h: int) : Texture2Dfloat2 ` * :ref:`Texture2Dfloat (w: int; h: int) : Texture2Dfloat ` * :ref:`Texture2Duint4 (w: int; h: int) : Texture2Duint4 ` * :ref:`Texture2Duint2 (w: int; h: int) : Texture2Duint2 ` * :ref:`Texture2Duint (w: int; h: int) : Texture2Duint ` * :ref:`create_render_target (w: int; h: int; declaration: TextureDeclaration) : TextureId ` * :ref:`create_texture (w: int; h: int; pixels: array\; declaration: TextureDeclaration; rgba8_format: bool = true) : TextureId ` * :ref:`create_texture (color: uint; declaration: TextureDeclaration = TextureDeclaration()) : TextureId ` * :ref:`create_texture (color: float4; declaration: TextureDeclaration = TextureDeclaration()) : TextureId ` * :ref:`create_texture (tex: Bitmap|Texture2Dfloat4|Texture2Dfloat2|Texture2Dfloat|Texture2Duint4|Texture2Duint2|Texture2Duint; request: TextureDeclaration) : TextureId ` * :ref:`create_texture (w: int; h: int; pixels: array\; declaration: TextureDeclaration) : TextureId ` * :ref:`get_image_content (path: string; cb: block\<(var bitmap:Bitmap):void\>) : bool ` * :ref:`get_texture_size (textureId: TextureId; blk: block\<(size:int2):void\>) : bool ` * :ref:`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)) ` .. _function-texture_resource_request_texture_string: .. das:function:: 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 .. _function-texture_resource_Bitmap_int_int: .. das:function:: Bitmap(w: int; h: int) : Bitmap Create Bitmap with size 'w'x'h', filled with zeros :Arguments: * **w** : int * **h** : int .. _function-texture_resource_Texture2Dfloat4_int_int: .. das:function:: Texture2Dfloat4(w: int; h: int) : Texture2Dfloat4 Create Texture2Dfloat4 with size 'w'x'h', filled with zeros :Arguments: * **w** : int * **h** : int .. _function-texture_resource_Texture2Dfloat2_int_int: .. das:function:: Texture2Dfloat2(w: int; h: int) : Texture2Dfloat2 Create Texture2Dfloat2 with size 'w'x'h', filled with zeros :Arguments: * **w** : int * **h** : int .. _function-texture_resource_Texture2Dfloat_int_int: .. das:function:: Texture2Dfloat(w: int; h: int) : Texture2Dfloat Create Texture2Dfloat with size 'w'x'h', filled with zeros :Arguments: * **w** : int * **h** : int .. _function-texture_resource_Texture2Duint4_int_int: .. das:function:: Texture2Duint4(w: int; h: int) : Texture2Duint4 Create Texture2Duint4 with size 'w'x'h', filled with zeros :Arguments: * **w** : int * **h** : int .. _function-texture_resource_Texture2Duint2_int_int: .. das:function:: Texture2Duint2(w: int; h: int) : Texture2Duint2 Create Texture2Duint2 with size 'w'x'h', filled with zeros :Arguments: * **w** : int * **h** : int .. _function-texture_resource_Texture2Duint_int_int: .. das:function:: Texture2Duint(w: int; h: int) : Texture2Duint Create Texture2Duint with size 'w'x'h', filled with zeros :Arguments: * **w** : int * **h** : int .. _function-texture_resource_create_render_target_int_int_TextureDeclaration: .. das:function:: 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** : :ref:`TextureDeclaration ` .. _function-texture_resource_create_texture_int_int_array_ls_uint_gr__TextureDeclaration_bool: .. das:function:: create_texture(w: int; h: int; pixels: array; declaration: TextureDeclaration; rgba8_format: bool = true) : TextureId Create texture 'w'x'h' with 'pixels' and 'declaration' :Arguments: * **w** : int * **h** : int * **pixels** : array * **declaration** : :ref:`TextureDeclaration ` * **rgba8_format** : bool .. _function-texture_resource_create_texture_uint_TextureDeclaration: .. das:function:: create_texture(color: uint; declaration: TextureDeclaration = TextureDeclaration()) : TextureId Create 1x1 texture filled with 'color' :Arguments: * **color** : uint * **declaration** : :ref:`TextureDeclaration ` .. _function-texture_resource_create_texture_float4_TextureDeclaration: .. das:function:: create_texture(color: float4; declaration: TextureDeclaration = TextureDeclaration()) : TextureId Create 1x1 texture filled with 'color' :Arguments: * **color** : float4 * **declaration** : :ref:`TextureDeclaration ` .. _function-texture_resource_create_texture_BitmapTexture2Dfloat4Texture2Dfloat2Texture2DfloatTexture2Duint4Texture2Duint2Texture2Duint_TextureDeclaration: .. das:function:: 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< :ref:`Bitmap ` | :ref:`Texture2Dfloat4 ` | :ref:`Texture2Dfloat2 ` | :ref:`Texture2Dfloat ` | :ref:`Texture2Duint4 ` | :ref:`Texture2Duint2 ` | :ref:`Texture2Duint ` > * **request** : :ref:`TextureDeclaration ` .. _function-texture_resource_create_texture_int_int_array_ls_autoTT_gr__TextureDeclaration: .. das:function:: create_texture(w: int; h: int; pixels: array; declaration: TextureDeclaration) : TextureId Create texture 'w'x'h' with 'pixels' and 'declaration' :Arguments: * **w** : int * **h** : int * **pixels** : array * **declaration** : :ref:`TextureDeclaration ` .. _function-texture_resource_boost_get_image_content_string_block_ls_var_bitmap_c_Bitmap_c_void_gr_: .. das:function:: 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: :ref:`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 } .. _function-texture_resource_boost_get_texture_size_TextureId_block_ls_size_c_int2_c_void_gr_: .. das:function:: 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** : :ref:`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}") } .. _function-texture_resource_boost_update_texture_BitmapTexture2Dfloat4Texture2Dfloat2Texture2DfloatTexture2Duint4Texture2Duint2Texture2Duint_TextureId_int_int2_int2: .. das:function:: 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< :ref:`Bitmap ` | :ref:`Texture2Dfloat4 ` | :ref:`Texture2Dfloat2 ` | :ref:`Texture2Dfloat ` | :ref:`Texture2Duint4 ` | :ref:`Texture2Duint2 ` | :ref:`Texture2Duint ` > * **resId** : :ref:`TextureId ` * **mip** : int * **offset** : int2 * **size** : int2