Texture
Wrapper around a native texture data.
For more information about how to create meshes, have a look at the TextureManager class.
Note: Textures are per-engine, they can thus be shared by multiple scenes.
- Texture
.constructor(engine, param) ⇒ Texture- .height
- .htmlElement
.id- .valid
- .width
- .destroy() ⇒ void
- .toString() ⇒ string
- .update() ⇒ void
- .updateSubImage(srcX, srcY, srcWidth, srcHeight, dstX, dstY, content) ⇒ boolean
.constructor(engine: WonderlandEngine, param: number | ImageLike) ⇒ Texture
Deprecated: Use create instead, accessible via textures:
Param | Type | Description |
---|---|---|
engine | WonderlandEngine | |
param | number | ImageLike |
.height: number
Height of the texture.
Note: If the texture has an htmlElement, this is the height used at creation. If the actual element’s height changed, it must be read from the element itself.
.htmlElement: null | ImageLike
Returns the html element associated to this texture.
Note: This accessor will return null
if the image is compressed.
.id: number
Index in this manager.
Deprecated: Use index instead.
.valid: boolean
Whether this texture is valid.
.width: number
Width of the texture.
Note: If the texture has an htmlElement, this is the width used at creation. If the actual element’s width changed, it must be read from the element itself.
.destroy() ⇒ void
0.9.0+Destroy and free the texture’s texture altas space and memory.
It is best practice to set the texture variable to null
after calling
destroy to prevent accidental use of the invalid texture:
.toString() ⇒ string
.update() ⇒ void
Update the texture to match the HTML element (e.g. reflect the current frame of a video).
.updateSubImage(srcX: number, srcY: number, srcWidth: number, srcHeight: number, dstX: number, dstY: number, content: ImageLike) ⇒ boolean
Upload content to the texture to the GPU.
Usage:
Note: The source is cropped if the destination offset and source dimensions are out-of-bounds regarding the texture size.
Note: Uploading a texture without a source offset is significantly faster.
ImageBitmap
If you need to upload a subregion, it’s recommended to use:
You could use this method with a src
offset, but the synchronous implementation
uses a temporary 2d canvas, negatively affecting performance for large content.
Returns: true
if the update went through, false
otherwise.
Param | Type | Description |
---|---|---|
srcX | number | Horizontal pixel offset, in the source image. |
srcY | number | Vertical pixel offset, in the source image. |
srcWidth | number | Width of the sub image, in the source image. |
srcHeight | number | Height of the sub image, in the source image |
dstX | number | Horizontal pixel offset, in the destination image. Defaults to srcX for backward compatibility with older API versions. |
dstY | number | Vertical pixel offset, in the destination image. Defaults to srcY for backward compatibility with older API versions. |
content | ImageLike | Image , HTMLCanvasElement , HTMLVideoElement , or ImageBitmap to upload. |