Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
/**
* The target type
*
* @member {PIXI.TARGETS}
* @default PIXI.TARGETS.TEXTURE_2D
*/
this.target = target || TARGETS.TEXTURE_2D;
/**
* How to treat premultiplied alpha, see {@link PIXI.ALPHA_MODES}.
*
* @member {PIXI.ALPHA_MODES}
* @default PIXI.ALPHA_MODES.UNPACK
*/
this.alphaMode = alphaMode !== undefined ? alphaMode : ALPHA_MODES.UNPACK;
if (options.premultiplyAlpha !== undefined)
{
// triggers deprecation
this.premultiplyAlpha = options.premultiplyAlpha;
}
/**
* Global unique identifier for this BaseTexture
*
* @member {string}
* @protected
*/
this.uid = uid();
/**
upload(renderer, baseTexture, glTexture)
{
const gl = renderer.gl;
gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, baseTexture.alphaMode === ALPHA_MODES.UNPACK);
if (glTexture.width === baseTexture.width && glTexture.height === baseTexture.height)
{
gl.texSubImage2D(
baseTexture.target,
0,
0,
0,
baseTexture.width,
baseTexture.height,
baseTexture.format,
baseTexture.type,
this.data
);
}
else
upload(renderer, baseTexture, glTexture, source)
{
const gl = renderer.gl;
const width = baseTexture.realWidth;
const height = baseTexture.realHeight;
source = source || this.source;
gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, baseTexture.alphaMode === ALPHA_MODES.UNPACK);
if (!this.noSubImage
&& baseTexture.target === gl.TEXTURE_2D
&& glTexture.width === width
&& glTexture.height === height)
{
gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, 0, baseTexture.format, baseTexture.type, source);
}
else
{
glTexture.width = width;
glTexture.height = height;
gl.texImage2D(baseTexture.target, 0, baseTexture.format, baseTexture.format, baseTexture.type, source);
}
process()
{
if (this._process !== null)
{
return this._process;
}
if (this.bitmap !== null || !window.createImageBitmap)
{
return Promise.resolve(this);
}
this._process = window.createImageBitmap(this.source,
0, 0, this.source.width, this.source.height,
{
premultiplyAlpha: this.premultiplyAlpha === ALPHA_MODES.UNPACK ? 'premultiply' : 'none',
})
.then((bitmap) =>
{
if (this.destroyed)
{
return Promise.reject();
}
this.bitmap = bitmap;
this.update();
this._process = null;
return Promise.resolve(this);
});
return this._process;
}
upload(renderer, baseTexture, glTexture)
{
const gl = renderer.gl;
gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, baseTexture.alphaMode === ALPHA_MODES.UNPACK);
if (glTexture.width === baseTexture.width && glTexture.height === baseTexture.height)
{
gl.texSubImage2D(
baseTexture.target,
0,
0,
0,
baseTexture.width,
baseTexture.height,
baseTexture.format,
baseTexture.type,
this.data
);
}
else