/  ChuGL Textures

Texture

TextureSampler

TextureDesc

TextureWriteDesc

TextureLoadDesc

Textures can be loaded from file, created dynamically from data; they are passed into materials and mapped onto 2D and 3D surfaces.

Texture

inherits : SG_Component : Object

Texture class. Immutable, meaning properties (e.g. format, dimension, size, mip levels) cannot be changed after creation. You can, however, write data to the texture.

examples

constructors

Texture()

Default constructor for Texture.

Texture(TextureDesc texture_desc)

No description available

member functions

float[] data()

Get the most recently read texture data. This function should be called after waiting on the Event object returned by `Texture.read()`.

int depth()

Get the texture depth (immutable). For a 2D texture, depth corresponds to the number of array layers (e.g. depth=6 for a cubemap)

int dimension()

Get the texture dimension (immutable). Returns a value from the Texture.Dimension_XXXXX enum, e.g. Texture.Dimension_2D.

int format()

Get the texture format (immutable). Returns a value from the Texture.Format_XXXXX enum, e.g. Texture.Format_RGBA8Unorm.

int height()

Get the texture height (immutable)

int mips()

Get the number of mip levels (immutable). Returns the number of mip levels in the texture.

Event read()

Initializes an async readback of texture data at mip level 0 from GPU to CPU. This function returns an Event object which can be waited on until the data is ready. Access the newly acquired data via `Texture.data()`. Note that it can take several frames for the data to read back to chuck.

int usage()

Get the texture usage flags (immutable). Returns a bitmask of usage flgas from the Texture.Usage_XXXXX enum e.g. Texture.Usage_TextureBinding | Texture.Usage_RenderAttachment. By default, textures are created with ALL usages enabled.

int width()

Get the texture width (immutable)

void write(float[] pixel_data)

Convenience function for writing into a texture. Assumes pixel_data is being written into the texture origin (0,0,0) with a region equal to the full texture dimensions (width, height, depth) at mip level 0.

void write(float[] pixel_data, TextureWriteDesc write_desc)

Write pixel data to an arbitrary texture region. The input float data is automatically converted based on the texture format.

static member functions

void copy(Texture dst_texture, Texture src_texture)

Copy the entire src texture to the dst texture at mip level 0.

void copy(Texture dst_texture, TextureLocation dst_location, Texture src_texture, TextureLocation src_location, int size_x, int size_y, int size_z)

Copy a region of the src texture to a location in the dst texture. The size parameter is floored to integers and specifies the 3D dimensions of the region to copy.

Texture load(string filepath)

Load a 2D texture from a file.

Texture load(string filepath, TextureLoadDesc load_desc)

Load a 2D texture from a file with additional parameters.

Texture load(string right, string left, string top, string bottom, string back, string front)

Load a cubemap texture from 6 filepaths, one for each face.

static member variables

int Dimension_2D

No description available

int Format_R32Float

No description available

int Format_RGBA16Float

No description available

int Format_RGBA32Float

No description available

int Format_RGBA8Unorm

No description available

int Usage_All

Texture usage flag: all usages enabled.

int Usage_CopyDst

Texture usage flag: can be used destination for copy/write operations.

int Usage_CopySrc

Texture usage flag: can be used as a source for copy/write operations.

int Usage_RenderAttachment

Texture usage flag: texture can be used as a render attachment, i.e. written to by a render pass.

int Usage_StorageBinding

Texture usage flag: texture can be bound as a storage texture to a shader.

int Usage_TextureBinding

Texture usage flag: texture can be bound to a shader.


TextureSampler

inherits : Object

Texture Sampler -- options for sampling a texture.

constructors

TextureSampler()

Default constructor for TextureSampler.

member variables

int filterMag

Magnification filter. Valid values are TextureSampler.Filter_Nearest, TextureSampler.Filter_Linear.

int filterMin

Minification filter. Valid values are TextureSampler.Filter_Nearest, TextureSampler.Filter_Linear.

int filterMip

Mip level filter. Valid values are TextureSampler.Filter_Nearest, TextureSampler.Filter_Linear.

int wrapU

U-axis (horizontal) wrap mode. Valid values are TextureSampler.Wrap_Repeat, TextureSampler.Wrap_Mirror, TextureSampler.Wrap_Clamp.

int wrapV

V-axis (vertical) wrap mode. Valid values are TextureSampler.Wrap_Repeat, TextureSampler.Wrap_Mirror, TextureSampler.Wrap_Clamp.

int wrapW

W-axis wrap mode. Valid values are TextureSampler.Wrap_Repeat, TextureSampler.Wrap_Mirror, TextureSampler.Wrap_Clamp.

static member variables

int Filter_Linear

No description available

int Filter_Nearest

No description available

int Wrap_Clamp

No description available

int Wrap_Mirror

No description available

int Wrap_Repeat

No description available


TextureDesc

inherits : Object

Texture Descriptor -- options for creating a texture.

constructors

TextureDesc()

Default constructor for TextureDesc.

member variables

int depth

Depth in texels. Default is 1.

int dimension

Texture dimension. Valid options are defined in the Texture.Dimension_* enum. Default is Texture.Dimension_2D.

int format

Texture format. Valid options are defined in the Texture.Format_* enum. Default is Texture.Format_RGBA8Unorm.

int height

Height in texels. Default is 1.

int mips

Number of mip levels. Default is 1.

int usage

Bit mask of texture usage flags. Valid flags are defined in the Texture.Usage_* enum. Default is Texture.Usage_All, which enables all usages.

int width

Width in texels. Default is 1.


TextureWriteDesc

inherits : Object

Options for writing to a texture.

constructors

TextureWriteDesc()

Default constructor for TextureWriteDesc.

member variables

int depth

Depth of write region. Default 0.

int height

Height of write region. Default 0.

int mip

Which mip level to write to. Default is 0 (base level)

int width

Width of write region. Default 0.

int x

X offset of write region. Default 0.

int y

Y offset of write region. Default 0.

int z

Z offset of write region. Default 0.


TextureLoadDesc

inherits : Object

Options for loading a texture from a file.

constructors

TextureLoadDesc()

Default constructor for TextureLoadDesc.

member variables

int flip_y

Flip the image vertically before loading. Default false.

int gen_mips

Generate mipmaps for the texture. Default true.