1 | import { ALPHA_MODES, FORMATS, MIPMAP_MODES, SCALE_MODES, TARGETS, TYPES, WRAP_MODES } from '@pixi/constants';
|
2 | import { EventEmitter } from '@pixi/utils';
|
3 | import { BufferResource } from './resources/BufferResource';
|
4 | import { Resource } from './resources/Resource';
|
5 | import type { MSAA_QUALITY } from '@pixi/constants';
|
6 | import type { ICanvas } from '@pixi/settings';
|
7 | import type { GLTexture } from './GLTexture';
|
8 | import type { IAutoDetectOptions } from './resources/autoDetectResource';
|
9 | import type { BufferType, IBufferResourceOptions } from './resources/BufferResource';
|
10 | /**
|
11 | * Value types for the constructor of {@link PIXI.BaseTexture}, including:
|
12 | * - `HTMLImageElement`
|
13 | * - `HTMLVideoElement`
|
14 | * - `ImageBitmap`
|
15 | * - {@link PIXI.ICanvas}
|
16 | * - `VideoFrame`
|
17 | * @memberof PIXI
|
18 | */
|
19 | export type ImageSource = HTMLImageElement | HTMLVideoElement | ImageBitmap | ICanvas | VideoFrame;
|
20 | export interface IBaseTextureOptions<RO = any> {
|
21 | alphaMode?: ALPHA_MODES;
|
22 | mipmap?: MIPMAP_MODES;
|
23 | anisotropicLevel?: number;
|
24 | scaleMode?: SCALE_MODES;
|
25 | width?: number;
|
26 | height?: number;
|
27 | wrapMode?: WRAP_MODES;
|
28 | format?: FORMATS;
|
29 | type?: TYPES;
|
30 | target?: TARGETS;
|
31 | resolution?: number;
|
32 | multisample?: MSAA_QUALITY;
|
33 | resourceOptions?: RO;
|
34 | pixiIdPrefix?: string;
|
35 | }
|
36 | export interface BaseTexture extends GlobalMixins.BaseTexture, EventEmitter {
|
37 | }
|
38 | /**
|
39 | * A Texture stores the information that represents an image.
|
40 | * All textures have a base texture, which contains information about the source.
|
41 | * Therefore you can have many textures all using a single BaseTexture
|
42 | * @memberof PIXI
|
43 | * @typeParam R - The BaseTexture's Resource type.
|
44 | * @typeParam RO - The options for constructing resource.
|
45 | */
|
46 | export declare class BaseTexture<R extends Resource = Resource, RO = IAutoDetectOptions> extends EventEmitter {
|
47 | /**
|
48 | * The width of the base texture set when the image has loaded
|
49 | * @readonly
|
50 | */
|
51 | width: number;
|
52 | /**
|
53 | * The height of the base texture set when the image has loaded
|
54 | * @readonly
|
55 | */
|
56 | height: number;
|
57 | /**
|
58 | * The resolution / device pixel ratio of the texture
|
59 | * @readonly
|
60 | * @default PIXI.settings.RESOLUTION
|
61 | */
|
62 | resolution: number;
|
63 | /**
|
64 | * How to treat premultiplied alpha, see {@link PIXI.ALPHA_MODES}.
|
65 | * @member {PIXI.ALPHA_MODES}
|
66 | * @default PIXI.ALPHA_MODES.UNPACK
|
67 | */
|
68 | alphaMode: ALPHA_MODES;
|
69 | /**
|
70 | * Anisotropic filtering level of texture
|
71 | * @member {number}
|
72 | * @default 0
|
73 | */
|
74 | anisotropicLevel: number;
|
75 | /**
|
76 | * The pixel format of the texture
|
77 | * @default PIXI.FORMATS.RGBA
|
78 | */
|
79 | format: FORMATS;
|
80 | /**
|
81 | * The type of resource data
|
82 | * @default PIXI.TYPES.UNSIGNED_BYTE
|
83 | */
|
84 | type: TYPES;
|
85 | /**
|
86 | * The target type
|
87 | * @default PIXI.TARGETS.TEXTURE_2D
|
88 | */
|
89 | target: TARGETS;
|
90 | /**
|
91 | * Global unique identifier for this BaseTexture
|
92 | * @protected
|
93 | */
|
94 | readonly uid: number;
|
95 | /**
|
96 | * Used by automatic texture Garbage Collection, stores last GC tick when it was bound
|
97 | * @protected
|
98 | */
|
99 | touched: number;
|
100 | /**
|
101 | * Whether or not the texture is a power of two, try to use power of two textures as much
|
102 | * as you can
|
103 | * @readonly
|
104 | * @default false
|
105 | */
|
106 | isPowerOfTwo: boolean;
|
107 | /**
|
108 | * The map of render context textures where this is bound
|
109 | * @private
|
110 | */
|
111 | _glTextures: {
|
112 | [key: number]: GLTexture;
|
113 | };
|
114 | /**
|
115 | * Used by TextureSystem to only update texture to the GPU when needed.
|
116 | * Please call `update()` to increment it.
|
117 | * @readonly
|
118 | */
|
119 | dirtyId: number;
|
120 | /**
|
121 | * Used by TextureSystem to only update texture style when needed.
|
122 | * @protected
|
123 | */
|
124 | dirtyStyleId: number;
|
125 | /**
|
126 | * Currently default cache ID.
|
127 | * @member {string}
|
128 | */
|
129 | cacheId: string;
|
130 | /**
|
131 | * Generally speaking means when resource is loaded.
|
132 | * @readonly
|
133 | * @member {boolean}
|
134 | */
|
135 | valid: boolean;
|
136 | /**
|
137 | * The collection of alternative cache ids, since some BaseTextures
|
138 | * can have more than one ID, short name and longer full URL
|
139 | * @member {Array<string>}
|
140 | * @readonly
|
141 | */
|
142 | textureCacheIds: Array<string>;
|
143 | /**
|
144 | * Flag if BaseTexture has been destroyed.
|
145 | * @member {boolean}
|
146 | * @readonly
|
147 | */
|
148 | destroyed: boolean;
|
149 | /**
|
150 | * The resource used by this BaseTexture, there can only
|
151 | * be one resource per BaseTexture, but textures can share
|
152 | * resources.
|
153 | * @member {PIXI.Resource}
|
154 | * @readonly
|
155 | */
|
156 | resource: R;
|
157 | /**
|
158 | * Number of the texture batch, used by multi-texture renderers
|
159 | * @member {number}
|
160 | */
|
161 | _batchEnabled: number;
|
162 | /**
|
163 | * Location inside texture batch, used by multi-texture renderers
|
164 | * @member {number}
|
165 | */
|
166 | _batchLocation: number;
|
167 | /**
|
168 | * Whether its a part of another texture, handled by ArrayResource or CubeResource
|
169 | * @member {PIXI.BaseTexture}
|
170 | */
|
171 | parentTextureArray: BaseTexture;
|
172 | private _mipmap;
|
173 | private _scaleMode;
|
174 | private _wrapMode;
|
175 | /**
|
176 | * Default options used when creating BaseTexture objects.
|
177 | * @static
|
178 | * @memberof PIXI.BaseTexture
|
179 | * @type {PIXI.IBaseTextureOptions}
|
180 | */
|
181 | static defaultOptions: IBaseTextureOptions;
|
182 | /**
|
183 | * @param {PIXI.Resource|PIXI.ImageSource|string} [resource=null] -
|
184 | * The current resource to use, for things that aren't Resource objects, will be converted
|
185 | * into a Resource.
|
186 | * @param options - Collection of options, default options inherited from {@link PIXI.BaseTexture.defaultOptions}.
|
187 | * @param {PIXI.MIPMAP_MODES} [options.mipmap] - If mipmapping is enabled for texture
|
188 | * @param {number} [options.anisotropicLevel] - Anisotropic filtering level of texture
|
189 | * @param {PIXI.WRAP_MODES} [options.wrapMode] - Wrap mode for textures
|
190 | * @param {PIXI.SCALE_MODES} [options.scaleMode] - Default scale mode, linear, nearest
|
191 | * @param {PIXI.FORMATS} [options.format] - GL format type
|
192 | * @param {PIXI.TYPES} [options.type] - GL data type
|
193 | * @param {PIXI.TARGETS} [options.target] - GL texture target
|
194 | * @param {PIXI.ALPHA_MODES} [options.alphaMode] - Pre multiply the image alpha
|
195 | * @param {number} [options.width=0] - Width of the texture
|
196 | * @param {number} [options.height=0] - Height of the texture
|
197 | * @param {number} [options.resolution=PIXI.settings.RESOLUTION] - Resolution of the base texture
|
198 | * @param {object} [options.resourceOptions] - Optional resource options,
|
199 | * see {@link PIXI.autoDetectResource autoDetectResource}
|
200 | */
|
201 | constructor(resource?: R | ImageSource | string | any, options?: IBaseTextureOptions<RO>);
|
202 | /**
|
203 | * Pixel width of the source of this texture
|
204 | * @readonly
|
205 | */
|
206 | get realWidth(): number;
|
207 | /**
|
208 | * Pixel height of the source of this texture
|
209 | * @readonly
|
210 | */
|
211 | get realHeight(): number;
|
212 | /**
|
213 | * Mipmap mode of the texture, affects downscaled images
|
214 | * @default PIXI.MIPMAP_MODES.POW2
|
215 | */
|
216 | get mipmap(): MIPMAP_MODES;
|
217 | set mipmap(value: MIPMAP_MODES);
|
218 | /**
|
219 | * The scale mode to apply when scaling this texture
|
220 | * @default PIXI.SCALE_MODES.LINEAR
|
221 | */
|
222 | get scaleMode(): SCALE_MODES;
|
223 | set scaleMode(value: SCALE_MODES);
|
224 | /**
|
225 | * How the texture wraps
|
226 | * @default PIXI.WRAP_MODES.CLAMP
|
227 | */
|
228 | get wrapMode(): WRAP_MODES;
|
229 | set wrapMode(value: WRAP_MODES);
|
230 | /**
|
231 | * Changes style options of BaseTexture
|
232 | * @param scaleMode - Pixi scalemode
|
233 | * @param mipmap - enable mipmaps
|
234 | * @returns - this
|
235 | */
|
236 | setStyle(scaleMode?: SCALE_MODES, mipmap?: MIPMAP_MODES): this;
|
237 | /**
|
238 | * Changes w/h/resolution. Texture becomes valid if width and height are greater than zero.
|
239 | * @param desiredWidth - Desired visual width
|
240 | * @param desiredHeight - Desired visual height
|
241 | * @param resolution - Optionally set resolution
|
242 | * @returns - this
|
243 | */
|
244 | setSize(desiredWidth: number, desiredHeight: number, resolution?: number): this;
|
245 | /**
|
246 | * Sets real size of baseTexture, preserves current resolution.
|
247 | * @param realWidth - Full rendered width
|
248 | * @param realHeight - Full rendered height
|
249 | * @param resolution - Optionally set resolution
|
250 | * @returns - this
|
251 | */
|
252 | setRealSize(realWidth: number, realHeight: number, resolution?: number): this;
|
253 | /**
|
254 | * Refresh check for isPowerOfTwo texture based on size
|
255 | * @private
|
256 | */
|
257 | protected _refreshPOT(): void;
|
258 | /**
|
259 | * Changes resolution
|
260 | * @param resolution - res
|
261 | * @returns - this
|
262 | */
|
263 | setResolution(resolution: number): this;
|
264 | /**
|
265 | * Sets the resource if it wasn't set. Throws error if resource already present
|
266 | * @param resource - that is managing this BaseTexture
|
267 | * @returns - this
|
268 | */
|
269 | setResource(resource: R): this;
|
270 | /** Invalidates the object. Texture becomes valid if width and height are greater than zero. */
|
271 | update(): void;
|
272 | /**
|
273 | * Handle errors with resources.
|
274 | * @private
|
275 | * @param event - Error event emitted.
|
276 | */
|
277 | onError(event: ErrorEvent): void;
|
278 | /**
|
279 | * Destroys this base texture.
|
280 | * The method stops if resource doesn't want this texture to be destroyed.
|
281 | * Removes texture from all caches.
|
282 | * @fires PIXI.BaseTexture#destroyed
|
283 | */
|
284 | destroy(): void;
|
285 | /**
|
286 | * Frees the texture from WebGL memory without destroying this texture object.
|
287 | * This means you can still use the texture later which will upload it to GPU
|
288 | * memory again.
|
289 | * @fires PIXI.BaseTexture#dispose
|
290 | */
|
291 | dispose(): void;
|
292 | /** Utility function for BaseTexture|Texture cast. */
|
293 | castToBaseTexture(): BaseTexture;
|
294 | /**
|
295 | * Helper function that creates a base texture based on the source you provide.
|
296 | * The source can be - image url, image element, canvas element. If the
|
297 | * source is an image url or an image element and not in the base texture
|
298 | * cache, it will be created and loaded.
|
299 | * @static
|
300 | * @param {PIXI.ImageSource|string|string[]} source - The
|
301 | * source to create base texture from.
|
302 | * @param options - See {@link PIXI.BaseTexture}'s constructor for options.
|
303 | * string} [options.pixiIdPrefix=pixiid] - If a source has no id, this is the prefix of the generated id
{ |
304 | * boolean} [strict] - Enforce strict-mode, see { PIXI.settings.STRICT_TEXTURE_CACHE}.
{ |
305 | * new base texture.
{PIXI.BaseTexture} The |
306 | */
|
307 | static from<R extends Resource = Resource, RO = IAutoDetectOptions>(source: ImageSource | string | string[], options?: IBaseTextureOptions<RO>, strict?: boolean): BaseTexture<R>;
|
308 | /**
|
309 | * Create a new Texture with a BufferResource from a typed array.
|
310 | * @param buffer - The optional array to use. If no data is provided, a new Float32Array is created.
|
311 | * @param width - Width of the resource
|
312 | * @param height - Height of the resource
|
313 | * @param options - See {@link PIXI.BaseTexture}'s constructor for options.
|
314 | * Default properties are different from the constructor's defaults.
|
315 | * @param {PIXI.FORMATS} [options.format] - The format is not given, the type is inferred from the
|
316 | * type of the buffer: `RGBA` if Float32Array, Int8Array, Uint8Array, or Uint8ClampedArray,
|
317 | * otherwise `RGBA_INTEGER`.
|
318 | * @param {PIXI.TYPES} [options.type] - The type is not given, the type is inferred from the
|
319 | * type of the buffer. Maps Float32Array to `FLOAT`, Int32Array to `INT`, Uint32Array to
|
320 | * `UNSIGNED_INT`, Int16Array to `SHORT`, Uint16Array to `UNSIGNED_SHORT`, Int8Array to `BYTE`,
|
321 | * Uint8Array/Uint8ClampedArray to `UNSIGNED_BYTE`.
|
322 | * @param {PIXI.ALPHA_MODES} [options.alphaMode=PIXI.ALPHA_MODES.NPM]
|
323 | * @param {PIXI.SCALE_MODES} [options.scaleMode=PIXI.SCALE_MODES.NEAREST]
|
324 | * @returns - The resulting new BaseTexture
|
325 | */
|
326 | static fromBuffer(buffer: BufferType, width: number, height: number, options?: IBaseTextureOptions<IBufferResourceOptions>): BaseTexture<BufferResource>;
|
327 | /**
|
328 | * Adds a BaseTexture to the global BaseTextureCache. This cache is shared across the whole PIXI object.
|
329 | * @param {PIXI.BaseTexture} baseTexture - The BaseTexture to add to the cache.
|
330 | * @param {string} id - The id that the BaseTexture will be stored against.
|
331 | */
|
332 | static addToCache(baseTexture: BaseTexture, id: string): void;
|
333 | /**
|
334 | * Remove a BaseTexture from the global BaseTextureCache.
|
335 | * @param {string|PIXI.BaseTexture} baseTexture - id of a BaseTexture to be removed, or a BaseTexture instance itself.
|
336 | * @returns {PIXI.BaseTexture|null} The BaseTexture that was removed.
|
337 | */
|
338 | static removeFromCache(baseTexture: string | BaseTexture): BaseTexture | null;
|
339 | /** Global number of the texture batch, used by multi-texture renderers. */
|
340 | static _globalBatch: number;
|
341 | }
|