Hatch Game Engine Documentation v1.4.0
The documentation for the Hatch Game Engine
Loading...
Searching...
No Matches
Texture Class Reference

Representation of a GPU texture. More...

Public Member Functions

Texture Create (integer width, integer height)
 Creates a texture with the given dimensions.
void Copy (Texture destTexture, Drawable srcDrawable)
 Copies pixels from srcDrawable into destTexture.
void Convert (Drawable srcDrawable, array destPixels, TEXTUREFORMAT targetFormat, array palette)
 Converts the format of the pixels in srcPixels from srcFormat into targetFormat. If srcFormat and targetFormat are the same, this just copies the pixels from srcDrawable into destPixels.
void Convert (array srcPixels, TEXTUREFORMAT srcFormat, array destPixels, TEXTUREFORMAT targetFormat, array palette)
 Converts the format of the pixels in srcPixels from srcFormat into targetFormat. If srcFormat and targetFormat are the same, this just copies the pixels from srcPixels into destPixels.
integer Convert (integer color, TEXTUREFORMAT srcFormat, TEXTUREFORMAT targetFormat, array palette)
 Converts color from srcFormat into targetFormat. If srcFormat and targetFormat are the same, this just returns color.
boolean CanConvertBetweenFormats (TEXTUREFORMAT srcFormat, TEXTUREFORMAT targetFormat)
 Returns whether srcFormat can be converted into targetFormat.
boolean FormatHasAlphaChannel (TEXTUREFORMAT format)
 Returns whether format has an alpha channel.
void SetSize (integer width, integer height)
 Changes the dimensions of the texture, without scaling the pixels.
void Scale (integer width, integer height)
 Scales the texture to the given dimensions, using nearest neighbor interpolation.
integer GetPixel (integer x, integer y)
 Gets the pixel at the specified coordinates.
array GetPixelData (integer x=0, integer y=0, integer width, integer height)
 Gets an array of pixels of the given dimensions at the specified coordinates.
void SetPixel (integer x, integer y, integer color)
 Sets the pixel at the specified coordinates.
void CopyPixels (Drawable srcDrawable, array srcPalette)
 Copies pixels from a Drawable into the specified coordinates. The formats must be compatible.
void CopyPixels (Drawable srcDrawable, integer destX, integer destY, array srcPalette)
 Copies pixels from a Drawable into the specified coordinates. The formats must be compatible.
void CopyPixels (Drawable srcDrawable, integer srcX, integer srcY, integer destX, integer destY, integer destWidth, integer destHeight, array srcPalette)
 Copies a region of pixels from a Drawable into the specified coordinates. The formats must be compatible.
void CopyPixels (array srcPixels, array srcPalette)
 Copies pixels from an array into the specified coordinates.
void CopyPixels (array srcPixels, TEXTUREFORMAT srcFormat, array srcPalette)
 Copies pixels from an array into the specified coordinates.
void CopyPixels (array srcPixels, TEXTUREFORMAT srcFormat, integer srcWidth, integer srcHeight, array srcPalette)
 Copies pixels from an array into the specified coordinates.
void CopyPixels (array srcPixels, TEXTUREFORMAT srcFormat, integer srcWidth, integer srcHeight, integer destX, integer destY, array srcPalette)
 Copies a region of pixels from an array into the specified coordinates.
void CopyPixels (array srcPixels, TEXTUREFORMAT srcFormat, integer srcX, integer srcY, integer srcWidth, integer srcHeight, integer destX, integer destY, integer destWidth, integer destHeight, array srcPalette)
 Copies a region of pixels from an array into the specified coordinates.
void Apply ()
 Uploads all changes made to the texture to the GPU. This is an expensive operation, so change the most amount of pixels as possible before calling this.
void Delete ()
 Deletes the texture. It can no longer be used after this function is called.
 Texture (integer width, integer height, TEXTUREACCESS access, TEXTUREFORMAT format, array pixels, array palette)
 Creates a texture with the given dimensions, access mode, and format.
 Texture (integer width, integer height, TEXTUREACCESS access, TEXTUREFORMAT format, Drawable source, array palette)
 Creates a texture with the given dimensions, access mode, and format.

Public Attributes

integer Width
 The width of the texture.
integer Height
 The height of the texture.
TEXTUREFORMAT Format
 The format of the texture.
TEXTUREACCESS Access
 The access mode of the texture.

Detailed Description

Representation of a GPU texture.

Constructor & Destructor Documentation

◆ Texture() [1/2]

Texture.Texture ( integer width,
integer height,
TEXTUREACCESS access,
TEXTUREFORMAT format,
array pixels,
array palette )

Creates a texture with the given dimensions, access mode, and format.

Parameters
widthThe width of the texture.
heightThe height of the texture.
accessThe access mode of the texture. (default: TEXTUREACCESS_STATIC)
formatThe format of the texture. The default is TEXTUREFORMAT_RGB888, or TEXTUREFORMAT_NATIVE for render target textures.
pixelsAn array of pixels to initialize the texture with. The length of the array must match the dimensions of the texture (e.g., for a 64x64 texture, you must pass an array of exactly 4096 values.)
paletteThe palette of the texture, format 0xRRGGBB.

◆ Texture() [2/2]

Texture.Texture ( integer width,
integer height,
TEXTUREACCESS access,
TEXTUREFORMAT format,
Drawable source,
array palette )

Creates a texture with the given dimensions, access mode, and format.

Parameters
widthThe width of the texture.
heightThe height of the texture.
accessThe access mode of the texture. (default: TEXTUREACCESS_STATIC)
formatThe format of the texture. The default is TEXTUREFORMAT_RGB888, or TEXTUREFORMAT_NATIVE for render target textures.
sourceThe Drawable to initialize the texture with.
paletteThe palette of the Drawable, format 0xRRGGBB.

Member Function Documentation

◆ CanConvertBetweenFormats()

boolean Texture.CanConvertBetweenFormats ( TEXTUREFORMAT srcFormat,
TEXTUREFORMAT targetFormat )

Returns whether srcFormat can be converted into targetFormat.

Parameters
srcFormatThe source format.
targetFormatThe target format.
Returns
Returns a boolean value.

◆ Convert() [1/3]

void Texture.Convert ( array srcPixels,
TEXTUREFORMAT srcFormat,
array destPixels,
TEXTUREFORMAT targetFormat,
array palette )

Converts the format of the pixels in srcPixels from srcFormat into targetFormat. If srcFormat and targetFormat are the same, this just copies the pixels from srcPixels into destPixels.

Parameters
srcPixelsAn array of pixels.
srcFormatThe source format.
destPixelsThe destination array.
targetFormatThe target format.
paletteThe palette of the source if srcFormat is TEXTUREFORMAT_INDEXED, or the palette of the target if targetFormat is TEXTUREFORMAT_INDEXED. Format 0xRRGGBB. Required if srcFormat is TEXTUREFORMAT_INDEXED.

◆ Convert() [2/3]

void Texture.Convert ( Drawable srcDrawable,
array destPixels,
TEXTUREFORMAT targetFormat,
array palette )

Converts the format of the pixels in srcPixels from srcFormat into targetFormat. If srcFormat and targetFormat are the same, this just copies the pixels from srcDrawable into destPixels.

Parameters
srcDrawableThe Drawable to convert.
destPixelsThe destination array.
targetFormatThe target format.
paletteThe palette of the source if srcFormat is TEXTUREFORMAT_INDEXED, or the palette of the target if targetFormat is TEXTUREFORMAT_INDEXED. Format 0xRRGGBB.

◆ Convert() [3/3]

integer Texture.Convert ( integer color,
TEXTUREFORMAT srcFormat,
TEXTUREFORMAT targetFormat,
array palette )

Converts color from srcFormat into targetFormat. If srcFormat and targetFormat are the same, this just returns color.

Parameters
colorThe color to convert.
srcFormatThe source format.
targetFormatThe target format.
paletteThe palette of the source if srcFormat is TEXTUREFORMAT_INDEXED, or the palette of the target if targetFormat is TEXTUREFORMAT_INDEXED. Format 0xRRGGBB. Required if srcFormat is TEXTUREFORMAT_INDEXED.
Returns
Returns color converted to targetFormat.

◆ Copy()

void Texture.Copy ( Texture destTexture,
Drawable srcDrawable )

Copies pixels from srcDrawable into destTexture.

Parameters
destTextureThe texture to copy pixels into.
srcDrawableThe drawable to copy pixels from.
Deprecated
Use Texture.CopyPixels instead.

◆ CopyPixels() [1/8]

void Texture.CopyPixels ( array srcPixels,
array srcPalette )

Copies pixels from an array into the specified coordinates.

Parameters
srcPixelsAn array of pixels in the pixel format of the texture.
srcPaletteThe palette of the source, format 0xRRGGBB.

◆ CopyPixels() [2/8]

void Texture.CopyPixels ( array srcPixels,
TEXTUREFORMAT srcFormat,
array srcPalette )

Copies pixels from an array into the specified coordinates.

Parameters
srcPixelsAn array of pixels in the pixel format of the texture.
srcFormatThe format of the pixels in the array.
srcPaletteThe palette of the source, format 0xRRGGBB. Required if srcFormat is TEXTUREFORMAT_INDEXED, and the format of the destination texture is not TEXTUREFORMAT_INDEXED.

◆ CopyPixels() [3/8]

void Texture.CopyPixels ( array srcPixels,
TEXTUREFORMAT srcFormat,
integer srcWidth,
integer srcHeight,
array srcPalette )

Copies pixels from an array into the specified coordinates.

Parameters
srcPixelsAn array of pixels in the pixel format of the texture.
srcFormatThe format of the pixels in the array.
srcWidthThe width of the source.
srcHeightThe height of the source.
srcPaletteThe palette of the source, format 0xRRGGBB. Required if srcFormat is TEXTUREFORMAT_INDEXED, and the format of the destination texture is not TEXTUREFORMAT_INDEXED.

◆ CopyPixels() [4/8]

void Texture.CopyPixels ( array srcPixels,
TEXTUREFORMAT srcFormat,
integer srcWidth,
integer srcHeight,
integer destX,
integer destY,
array srcPalette )

Copies a region of pixels from an array into the specified coordinates.

Parameters
srcPixelsAn array of pixels in the pixel format of the texture.
srcFormatThe format of the pixels in the array.
srcWidthThe width of the source.
srcHeightThe height of the source.
destXThe X coordinate in the destination to copy the pixels to.
destYThe Y coordinate in the destination to copy the pixels to.
srcPaletteThe palette of the source, format 0xRRGGBB. Required if srcFormat is TEXTUREFORMAT_INDEXED, and the format of the destination texture is not TEXTUREFORMAT_INDEXED.

◆ CopyPixels() [5/8]

void Texture.CopyPixels ( array srcPixels,
TEXTUREFORMAT srcFormat,
integer srcX,
integer srcY,
integer srcWidth,
integer srcHeight,
integer destX,
integer destY,
integer destWidth,
integer destHeight,
array srcPalette )

Copies a region of pixels from an array into the specified coordinates.

Parameters
srcPixelsAn array of pixels in the pixel format of the texture.
srcFormatThe format of the pixels in the array.
srcXThe X coordinate in the source to start copying the pixels from.
srcYThe Y coordinate in the source to start copying the pixels from.
srcWidthThe width of the source.
srcHeightThe height of the source.
destXThe X coordinate in the destination to copy the pixels to.
destYThe Y coordinate in the destination to copy the pixels to.
destWidthThe width of the region to copy.
destHeightThe height of the region to copy.
srcPaletteThe palette of the source, format 0xRRGGBB. Required if srcFormat is TEXTUREFORMAT_INDEXED, and the format of the destination texture is not TEXTUREFORMAT_INDEXED.

◆ CopyPixels() [6/8]

void Texture.CopyPixels ( Drawable srcDrawable,
array srcPalette )

Copies pixels from a Drawable into the specified coordinates. The formats must be compatible.

Parameters
srcDrawableThe Drawable to copy pixels from.
srcPaletteThe palette of the source, format 0xRRGGBB.

◆ CopyPixels() [7/8]

void Texture.CopyPixels ( Drawable srcDrawable,
integer destX,
integer destY,
array srcPalette )

Copies pixels from a Drawable into the specified coordinates. The formats must be compatible.

Parameters
srcDrawableThe Drawable to copy pixels from.
destXThe X coordinate in the destination to copy the pixels to.
destYThe Y coordinate in the destination to copy the pixels to.
srcPaletteThe palette of the source, format 0xRRGGBB.

◆ CopyPixels() [8/8]

void Texture.CopyPixels ( Drawable srcDrawable,
integer srcX,
integer srcY,
integer destX,
integer destY,
integer destWidth,
integer destHeight,
array srcPalette )

Copies a region of pixels from a Drawable into the specified coordinates. The formats must be compatible.

Parameters
srcDrawableThe Drawable to copy pixels from.
srcXThe X coordinate in the source to start copying the pixels from.
srcYThe Y coordinate in the source to start copying the pixels from.
destXThe X coordinate in the destination to copy the pixels to.
destYThe Y coordinate in the destination to copy the pixels to.
destWidthThe width of the region to copy.
destHeightThe height of the region to copy.
srcPaletteThe palette of the source, format 0xRRGGBB.

◆ Create()

Texture Texture.Create ( integer width,
integer height )

Creates a texture with the given dimensions.

Parameters
widthThe width of the texture.
heightThe height of the texture.
Returns
Returns a texture.
Deprecated
Use the <Texture> constructor instead.

◆ FormatHasAlphaChannel()

boolean Texture.FormatHasAlphaChannel ( TEXTUREFORMAT format)

Returns whether format has an alpha channel.

Parameters
formatThe texture format to check.
Returns
Returns a boolean value.

◆ GetPixel()

integer Texture.GetPixel ( integer x,
integer y )

Gets the pixel at the specified coordinates.

Parameters
xThe X coordinate of the pixel to get.
yThe Y coordinate of the pixel to get.
Returns
Returns a color in the pixel format of the texture.

◆ GetPixelData()

array Texture.GetPixelData ( integer x = 0,
integer y = 0,
integer width,
integer height )

Gets an array of pixels of the given dimensions at the specified coordinates.

Parameters
xThe X coordinate of the region.
yThe Y coordinate of the region.
widthThe width of the region. (default: width of texture)
heightThe height of the region. (default: height of texture)
Returns
Returns an array of pixels in the pixel format of the texture.

◆ Scale()

void Texture.Scale ( integer width,
integer height )

Scales the texture to the given dimensions, using nearest neighbor interpolation.

Parameters
widthThe new width of the texture.
heightThe new height of the texture.

◆ SetPixel()

void Texture.SetPixel ( integer x,
integer y,
integer color )

Sets the pixel at the specified coordinates.

Parameters
xThe X coordinate of the pixel to set.
yThe Y coordinate of the pixel to set.
colorThe color in the pixel format of the texture.

◆ SetSize()

void Texture.SetSize ( integer width,
integer height )

Changes the dimensions of the texture, without scaling the pixels.

Parameters
widthThe new width of the texture.
heightThe new height of the texture.