Class: VideoBaseTexture

SINT.VideoBaseTexture

A texture of a [playing] Video.

Video base textures mimic SINTJS BaseTexture.from.... method in their creation process.

This can be used in several ways, such as:

let texture = SINT.VideoBaseTexture.fromUrl('http://mydomain.com/video.mp4');

let texture = SINT.VideoBaseTexture.fromUrl({ src: 'http://mydomain.com/video.mp4', mime: 'video/mp4' });

let texture = SINT.VideoBaseTexture.fromUrls(['/video.webm', '/video.mp4']);

let texture = SINT.VideoBaseTexture.fromUrls([
    { src: '/video.webm', mime: 'video/webm' },
    { src: '/video.mp4', mime: 'video/mp4' }
]);

See the "deus" demo.

new SINT.VideoBaseTexture (source, scaleMode, autoPlay)

Name Type Default Description
source HTMLVideoElement

Video source

scaleMode number SINT.settings.SCALE_MODE optional

See SINT.SCALE_MODES for possible values

autoPlay boolean true optional

Start playing video as soon as it is loaded

Extends

Members

autoPlay boolean

When set to true will automatically play videos used by this texture once they are loaded. If false, it will not modify the playing state.

Default Value:
  • true

autoUpdate boolean

Should the base texture automatically update itself, set to true by default

hasLoaded boolean readonly inherited overrides

Set to true once the base texture has successfully loaded.

This is never true if the underlying source fails to load or has no texture data.

height number readonly inherited overrides

The height of the base texture set when the image has loaded

imageType string readonly inherited overrides

Type of image defined in source, eg. png or svg

imageUrl string inherited overrides

The image url of the texture

isLoading boolean readonly inherited overrides

Set to true if the source is currently loading.

If an Image source is loading the 'loaded' or 'error' event will be dispatched when the operation ends. An underyling source that is immediately-available bypasses loading entirely.

mipmap boolean inherited overrides

Set this to true if a mipmap of this texture needs to be generated. This value needs to be set before the texture is used Also the texture must be a power of two size to work

See:
  • SINT.MIPMAP_TEXTURES

origSource Image readonly inherited overrides

The image source that is used to create the texture. This is used to store the original Svg source when it is replaced with a canvas element.

TODO: Currently not in use but could be used when re-scaling svg.

premultipliedAlpha boolean inherited overrides

Controls if RGB channels should be pre-multiplied by Alpha (WebGL only) All blend modes, and shaders written for default value. Change it on your own risk.

Default Value:
  • true

realHeight number readonly inherited overrides

Used to store the actual height of the source of this texture

realWidth number readonly inherited overrides

Used to store the actual width of the source of this texture

resolution number inherited overrides

The resolution / device pixel ratio of the texture

Default Value:
  • 1

scaleMode number inherited overrides

The scale mode to apply when scaling this texture

Default Value:
  • SINT.settings.SCALE_MODE
See:

source HTMLImageElement | HTMLCanvasElement readonly inherited overrides

The image source that is used to create the texture.

TODO: Make this a setter that calls loadSource();

sourceScale number readonly inherited overrides

Scale for source image. Used with Svg images to scale them before rasterization.

textureCacheIds Array.<string> inherited overrides

The ids under which this BaseTexture has been added to the base texture cache. This is automatically set as long as BaseTexture.addToCache is used, but may not be set if a BaseTexture is added directly to the BaseTextureCache array.

width number readonly inherited overrides

The width of the base texture set when the image has loaded

wrapMode number inherited overrides

WebGL Texture wrap mode

See:

Methods

SINT.VideoBaseTexture.fromUrl (videoSrc, scaleMode, crossorigin, autoPlay)SINT.VideoBaseTexture static

Helper function that creates a new BaseTexture based on the given video element. This BaseTexture can then be used to create a texture

Name Type Default Description
videoSrc string | object | Array.<string> | Array.<object>

The URL(s) for the video.

Name Type Description
src string optional

One of the source urls for the video

mime string optional

The mimetype of the video (e.g. 'video/mp4'). If not specified the url's extension will be used as the second part of the mime type.

scaleMode number

See SINT.SCALE_MODES for possible values

crossorigin boolean (auto) optional

Should use anonymous CORS? Defaults to true if the URL is not a data-URI.

autoPlay boolean true optional

Start playing video as soon as it is loaded

Returns:
Type Description
SINT.VideoBaseTexture Newly created VideoBaseTexture

SINT.VideoBaseTexture.fromVideo (video, scaleMode, autoPlay)SINT.VideoBaseTexture static

Mimic SINTJS BaseTexture.from.... method.

Name Type Default Description
video HTMLVideoElement

Video to create texture from

scaleMode number SINT.settings.SCALE_MODE optional

See SINT.SCALE_MODES for possible values

autoPlay boolean true optional

Start playing video as soon as it is loaded

Returns:
Type Description
SINT.VideoBaseTexture Newly created VideoBaseTexture

_loadSvgSource () inherited overrides

Checks if source is an SVG image and whether it's loaded via a URL or a data URI. Then calls _loadSvgSourceUsingDataUri or _loadSvgSourceUsingXhr.

_loadSvgSourceUsingDataUri (dataUri) inherited overrides

Reads an SVG string from data URI and then calls _loadSvgSourceUsingString.

Name Type Description
dataUri string

The data uri to load from.

_loadSvgSourceUsingString (svgString) inherited overrides

Loads texture using an SVG string. The original SVG Image is stored as origSource and the created canvas is the new source. The SVG is scaled using sourceScale. Called by _loadSvgSourceUsingXhr or _loadSvgSourceUsingDataUri.

Name Type Description
svgString string

SVG source as string

Fires:
  • SINT.BaseTexture#event:loaded

_loadSvgSourceUsingXhr () inherited overrides

Loads an SVG string from imageUrl using XHR and then calls _loadSvgSourceUsingString.

_updateDimensions () inherited overrides

Update dimensions from real values

_updateImageType () inherited overrides

Updates type of the source image.

destroy () overrides

Destroys this texture

dispose () inherited overrides

Frees the texture from WebGL memory without destroying this texture object. This means you can still use the texture later which will upload it to GPU memory again.

Fires:
  • SINT.BaseTexture#event:dispose

loadSource (source) protected inherited overrides

Load a source.

If the source is not-immediately-available, such as an image that needs to be downloaded, then the 'loaded' or 'error' event will be dispatched in the future and hasLoaded will remain false after this call.

The logic state after calling loadSource directly or indirectly (eg. fromImage, new BaseTexture) is:

if (texture.hasLoaded) {
   // texture ready for use
} else if (texture.isLoading) {
   // listen to 'loaded' and/or 'error' events on texture
} else {
   // not loading, not going to load UNLESS the source is reloaded
   // (it may still make sense to listen to the events)
}
Name Type Description
source HTMLImageElement | HTMLCanvasElement

the source object of the texture.

update () inherited overrides

Updates the texture on all the webgl renderers, this also assumes the src has changed.

Fires:
  • SINT.BaseTexture#event:update

updateSourceImage (newSrc) inherited overrides

Changes the source image of the texture. The original source must be an Image element.

Name Type Description
newSrc string

the path of the image