UNPKG

3.82 kBTypeScriptView Raw
1import { Runner } from '@pixi/runner';
2import type { Renderer } from '../../Renderer';
3import type { BaseTexture } from '../BaseTexture';
4import type { GLTexture } from '../GLTexture';
5/**
6 * Base resource class for textures that manages validation and uploading, depending on its type.
7 *
8 * Uploading of a base texture to the GPU is required.
9 * @memberof PIXI
10 */
11export declare abstract class Resource {
12 /** The url of the resource */
13 src: string;
14 /**
15 * If resource has been destroyed.
16 * @readonly
17 * @default false
18 */
19 destroyed: boolean;
20 /**
21 * `true` if resource is created by BaseTexture
22 * useful for doing cleanup with BaseTexture destroy
23 * and not cleaning up resources that were created
24 * externally.
25 */
26 internal: boolean;
27 /** Internal width of the resource. */
28 protected _width: number;
29 /** Internal height of the resource. */
30 protected _height: number;
31 /**
32 * Mini-runner for handling resize events
33 * accepts 2 parameters: width, height
34 * @member {Runner}
35 * @private
36 */
37 protected onResize: Runner;
38 /**
39 * Mini-runner for handling update events
40 * @member {Runner}
41 * @private
42 */
43 protected onUpdate: Runner;
44 /**
45 * Handle internal errors, such as loading errors
46 * accepts 1 param: error
47 * @member {Runner}
48 * @private
49 */
50 protected onError: Runner;
51 /**
52 * @param width - Width of the resource
53 * @param height - Height of the resource
54 */
55 constructor(width?: number, height?: number);
56 /**
57 * Bind to a parent BaseTexture
58 * @param baseTexture - Parent texture
59 */
60 bind(baseTexture: BaseTexture): void;
61 /**
62 * Unbind to a parent BaseTexture
63 * @param baseTexture - Parent texture
64 */
65 unbind(baseTexture: BaseTexture): void;
66 /**
67 * Trigger a resize event
68 * @param width - X dimension
69 * @param height - Y dimension
70 */
71 resize(width: number, height: number): void;
72 /**
73 * Has been validated
74 * @readonly
75 */
76 get valid(): boolean;
77 /** Has been updated trigger event. */
78 update(): void;
79 /**
80 * This can be overridden to start preloading a resource
81 * or do any other prepare step.
82 * @protected
83 * @returns Handle the validate event
84 */
85 load(): Promise<Resource>;
86 /**
87 * The width of the resource.
88 * @readonly
89 */
90 get width(): number;
91 /**
92 * The height of the resource.
93 * @readonly
94 */
95 get height(): number;
96 /**
97 * Uploads the texture or returns false if it cant for some reason. Override this.
98 * @param renderer - yeah, renderer!
99 * @param baseTexture - the texture
100 * @param glTexture - texture instance for this webgl context
101 * @returns - true is success
102 */
103 abstract upload(renderer: Renderer, baseTexture: BaseTexture, glTexture: GLTexture): boolean;
104 /**
105 * Set the style, optional to override
106 * @param _renderer - yeah, renderer!
107 * @param _baseTexture - the texture
108 * @param _glTexture - texture instance for this webgl context
109 * @returns - `true` is success
110 */
111 style(_renderer: Renderer, _baseTexture: BaseTexture, _glTexture: GLTexture): boolean;
112 /** Clean up anything, this happens when destroying is ready. */
113 dispose(): void;
114 /**
115 * Call when destroying resource, unbind any BaseTexture object
116 * before calling this method, as reference counts are maintained
117 * internally.
118 */
119 destroy(): void;
120 /**
121 * Abstract, used to auto-detect resource type.
122 * @param {*} _source - The source object
123 * @param {string} _extension - The extension of source, if set
124 */
125 static test(_source: unknown, _extension?: string): boolean;
126}