- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
import { ALPHA_MODES } from '@pixi/constants';
import { BufferResource } from './BufferResource';
import type { BaseTexture } from '../BaseTexture';
import type { Renderer } from '../../Renderer';
import type { GLTexture } from '../GLTexture';
/**
* Resource type for DepthTexture.
* @memberof PIXI
*/
export class DepthResource extends BufferResource
{
/**
* Upload the texture to the GPU.
* @param renderer - Upload to the renderer
* @param baseTexture - Reference to parent texture
* @param glTexture - glTexture
* @returns - true is success
*/
upload(renderer: Renderer, baseTexture: BaseTexture, glTexture: GLTexture): boolean
{
const gl = renderer.gl;
gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, baseTexture.alphaMode === ALPHA_MODES.UNPACK);
const width = baseTexture.realWidth;
const height = baseTexture.realHeight;
if (glTexture.width === width && glTexture.height === height)
{
gl.texSubImage2D(
baseTexture.target,
0,
0,
0,
width,
height,
baseTexture.format,
glTexture.type,
this.data,
);
}
else
{
glTexture.width = width;
glTexture.height = height;
gl.texImage2D(
baseTexture.target,
0,
glTexture.internalFormat,
width,
height,
0,
baseTexture.format,
glTexture.type,
this.data,
);
}
return true;
}
}