melonjs 10.9.0 → 10.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +1 -1
- package/README.md +32 -25
- package/dist/melonjs.js +1635 -2383
- package/dist/melonjs.min.js +4 -4
- package/dist/melonjs.module.d.ts +929 -1504
- package/dist/melonjs.module.js +1581 -2344
- package/package.json +18 -18
- package/src/audio/audio.js +0 -1
- package/src/camera/camera2d.js +1 -16
- package/src/entity/entity.js +6 -11
- package/src/game.js +2 -2
- package/src/geometries/ellipse.js +19 -28
- package/src/geometries/line.js +5 -8
- package/src/geometries/path2d.js +14 -24
- package/src/geometries/poly.js +29 -47
- package/src/geometries/rectangle.js +25 -37
- package/src/geometries/roundrect.js +8 -12
- package/src/index.js +7 -2
- package/src/input/gamepad.js +3 -14
- package/src/input/keyboard.js +1 -9
- package/src/input/pointer.js +0 -1
- package/src/input/pointerevent.js +14 -23
- package/src/lang/deprecated.js +9 -6
- package/src/level/level.js +0 -9
- package/src/level/tiled/TMXGroup.js +0 -4
- package/src/level/tiled/TMXLayer.js +0 -8
- package/src/level/tiled/TMXObject.js +0 -3
- package/src/level/tiled/TMXTile.js +4 -5
- package/src/level/tiled/TMXTileMap.js +1 -7
- package/src/level/tiled/TMXTileset.js +0 -5
- package/src/level/tiled/TMXTilesetGroup.js +1 -4
- package/src/level/tiled/TMXUtils.js +1 -4
- package/src/level/tiled/renderer/TMXHexagonalRenderer.js +2 -3
- package/src/level/tiled/renderer/TMXIsometricRenderer.js +0 -1
- package/src/level/tiled/renderer/TMXRenderer.js +1 -7
- package/src/loader/loader.js +0 -11
- package/src/loader/loadingscreen.js +16 -5
- package/src/math/color.js +10 -30
- package/src/math/math.js +0 -10
- package/src/math/matrix2.js +12 -27
- package/src/math/matrix3.js +1 -22
- package/src/math/observable_vector2.js +0 -29
- package/src/math/observable_vector3.js +0 -29
- package/src/math/vector2.js +3 -40
- package/src/math/vector3.js +4 -41
- package/src/particles/emitter.js +11 -12
- package/src/physics/body.js +4 -5
- package/src/physics/bounds.js +5 -19
- package/src/physics/collision.js +1 -13
- package/src/physics/detector.js +6 -56
- package/src/physics/quadtree.js +0 -7
- package/src/physics/response.js +48 -0
- package/src/physics/sat.js +4 -4
- package/src/physics/world.js +0 -4
- package/src/plugin/plugin.js +0 -2
- package/src/polyfill/roundrect.js +4 -2
- package/src/renderable/GUI.js +11 -14
- package/src/renderable/collectable.js +1 -0
- package/src/renderable/colorlayer.js +9 -7
- package/src/renderable/container.js +38 -64
- package/src/renderable/dragndrop.js +1 -10
- package/src/renderable/imagelayer.js +8 -12
- package/src/renderable/light2d.js +118 -0
- package/src/renderable/renderable.js +27 -48
- package/src/renderable/sprite.js +17 -29
- package/src/renderable/trigger.js +10 -3
- package/src/state/stage.js +72 -6
- package/src/state/state.js +22 -23
- package/src/system/device.js +14 -53
- package/src/system/event.js +11 -0
- package/src/system/pooling.js +20 -9
- package/src/system/save.js +9 -11
- package/src/system/timer.js +239 -218
- package/src/text/bitmaptextdata.js +1 -4
- package/src/text/glyph.js +2 -2
- package/src/text/text.js +25 -24
- package/src/text/textmetrics.js +0 -2
- package/src/tweens/easing.js +1 -1
- package/src/tweens/interpolation.js +2 -2
- package/src/tweens/tween.js +1 -13
- package/src/utils/agent.js +1 -3
- package/src/utils/array.js +0 -3
- package/src/utils/file.js +0 -2
- package/src/utils/function.js +0 -2
- package/src/utils/string.js +0 -6
- package/src/utils/utils.js +0 -3
- package/src/video/canvas/canvas_renderer.js +73 -90
- package/src/video/renderer.js +34 -49
- package/src/video/{texture.js → texture/atlas.js} +10 -8
- package/src/video/{texture_cache.js → texture/cache.js} +4 -5
- package/src/video/texture/canvas_texture.js +99 -0
- package/src/video/video.js +3 -3
- package/src/video/webgl/glshader.js +0 -5
- package/src/video/webgl/utils/uniforms.js +3 -6
- package/src/video/webgl/webgl_compositor.js +0 -14
- package/src/video/webgl/webgl_renderer.js +73 -97
package/src/video/renderer.js
CHANGED
|
@@ -38,7 +38,7 @@ class Renderer {
|
|
|
38
38
|
* @public
|
|
39
39
|
* @name settings
|
|
40
40
|
* @memberof Renderer#
|
|
41
|
-
* @
|
|
41
|
+
* @type {object}
|
|
42
42
|
*/
|
|
43
43
|
this.settings = options;
|
|
44
44
|
|
|
@@ -64,6 +64,11 @@ class Renderer {
|
|
|
64
64
|
*/
|
|
65
65
|
this.currentScissor = new Int32Array([ 0, 0, this.settings.width, this.settings.height ]);
|
|
66
66
|
|
|
67
|
+
/**
|
|
68
|
+
* @ignore
|
|
69
|
+
*/
|
|
70
|
+
this.maskLevel = 0;
|
|
71
|
+
|
|
67
72
|
/**
|
|
68
73
|
* @ignore
|
|
69
74
|
*/
|
|
@@ -107,16 +112,14 @@ class Renderer {
|
|
|
107
112
|
/**
|
|
108
113
|
* prepare the framebuffer for drawing a new frame
|
|
109
114
|
* @name clear
|
|
110
|
-
* @memberof Renderer
|
|
111
|
-
* @function
|
|
115
|
+
* @memberof Renderer
|
|
112
116
|
*/
|
|
113
117
|
clear() {}
|
|
114
118
|
|
|
115
119
|
/**
|
|
116
120
|
* Reset context state
|
|
117
121
|
* @name reset
|
|
118
|
-
* @memberof Renderer
|
|
119
|
-
* @function
|
|
122
|
+
* @memberof Renderer
|
|
120
123
|
*/
|
|
121
124
|
reset() {
|
|
122
125
|
this.resetTransform();
|
|
@@ -128,13 +131,13 @@ class Renderer {
|
|
|
128
131
|
this.currentScissor[1] = 0;
|
|
129
132
|
this.currentScissor[2] = this.backBufferCanvas.width;
|
|
130
133
|
this.currentScissor[3] = this.backBufferCanvas.height;
|
|
134
|
+
this.clearMask();
|
|
131
135
|
}
|
|
132
136
|
|
|
133
137
|
/**
|
|
134
138
|
* return a reference to the system canvas
|
|
135
139
|
* @name getCanvas
|
|
136
|
-
* @memberof Renderer
|
|
137
|
-
* @function
|
|
140
|
+
* @memberof Renderer
|
|
138
141
|
* @returns {HTMLCanvasElement}
|
|
139
142
|
*/
|
|
140
143
|
getCanvas() {
|
|
@@ -144,8 +147,7 @@ class Renderer {
|
|
|
144
147
|
/**
|
|
145
148
|
* return a reference to the screen canvas
|
|
146
149
|
* @name getScreenCanvas
|
|
147
|
-
* @memberof Renderer
|
|
148
|
-
* @function
|
|
150
|
+
* @memberof Renderer
|
|
149
151
|
* @returns {HTMLCanvasElement}
|
|
150
152
|
*/
|
|
151
153
|
getScreenCanvas() {
|
|
@@ -156,8 +158,7 @@ class Renderer {
|
|
|
156
158
|
* return a reference to the screen canvas corresponding 2d Context<br>
|
|
157
159
|
* (will return buffered context if double buffering is enabled, or a reference to the Screen Context)
|
|
158
160
|
* @name getScreenContext
|
|
159
|
-
* @memberof Renderer
|
|
160
|
-
* @function
|
|
161
|
+
* @memberof Renderer
|
|
161
162
|
* @returns {CanvasRenderingContext2D}
|
|
162
163
|
*/
|
|
163
164
|
getScreenContext() {
|
|
@@ -167,8 +168,7 @@ class Renderer {
|
|
|
167
168
|
/**
|
|
168
169
|
* returns the current blend mode for this renderer
|
|
169
170
|
* @name getBlendMode
|
|
170
|
-
* @memberof Renderer
|
|
171
|
-
* @function
|
|
171
|
+
* @memberof Renderer
|
|
172
172
|
* @returns {string} blend mode
|
|
173
173
|
*/
|
|
174
174
|
getBlendMode() {
|
|
@@ -179,8 +179,7 @@ class Renderer {
|
|
|
179
179
|
* Returns the 2D Context object of the given Canvas<br>
|
|
180
180
|
* Also configures anti-aliasing and blend modes based on constructor options.
|
|
181
181
|
* @name getContext2d
|
|
182
|
-
* @memberof Renderer
|
|
183
|
-
* @function
|
|
182
|
+
* @memberof Renderer
|
|
184
183
|
* @param {HTMLCanvasElement} canvas
|
|
185
184
|
* @param {boolean} [transparent=true] use false to disable transparency
|
|
186
185
|
* @returns {CanvasRenderingContext2D}
|
|
@@ -217,8 +216,7 @@ class Renderer {
|
|
|
217
216
|
/**
|
|
218
217
|
* return the width of the system Canvas
|
|
219
218
|
* @name getWidth
|
|
220
|
-
* @memberof Renderer
|
|
221
|
-
* @function
|
|
219
|
+
* @memberof Renderer
|
|
222
220
|
* @returns {number}
|
|
223
221
|
*/
|
|
224
222
|
getWidth() {
|
|
@@ -228,8 +226,7 @@ class Renderer {
|
|
|
228
226
|
/**
|
|
229
227
|
* return the height of the system Canvas
|
|
230
228
|
* @name getHeight
|
|
231
|
-
* @memberof Renderer
|
|
232
|
-
* @function
|
|
229
|
+
* @memberof Renderer
|
|
233
230
|
* @returns {number} height of the system Canvas
|
|
234
231
|
*/
|
|
235
232
|
getHeight() {
|
|
@@ -239,8 +236,7 @@ class Renderer {
|
|
|
239
236
|
/**
|
|
240
237
|
* get the current fill & stroke style color.
|
|
241
238
|
* @name getColor
|
|
242
|
-
* @memberof Renderer
|
|
243
|
-
* @function
|
|
239
|
+
* @memberof Renderer
|
|
244
240
|
* @returns {Color} current global color
|
|
245
241
|
*/
|
|
246
242
|
getColor() {
|
|
@@ -250,8 +246,7 @@ class Renderer {
|
|
|
250
246
|
/**
|
|
251
247
|
* return the current global alpha
|
|
252
248
|
* @name globalAlpha
|
|
253
|
-
* @memberof Renderer
|
|
254
|
-
* @function
|
|
249
|
+
* @memberof Renderer
|
|
255
250
|
* @returns {number}
|
|
256
251
|
*/
|
|
257
252
|
globalAlpha() {
|
|
@@ -261,8 +256,7 @@ class Renderer {
|
|
|
261
256
|
/**
|
|
262
257
|
* check if the given rect or bounds overlaps with the renderer screen coordinates
|
|
263
258
|
* @name overlaps
|
|
264
|
-
* @memberof Renderer
|
|
265
|
-
* @function
|
|
259
|
+
* @memberof Renderer
|
|
266
260
|
* @param {Rect|Bounds} bounds
|
|
267
261
|
* @returns {boolean} true if overlaps
|
|
268
262
|
*/
|
|
@@ -277,8 +271,7 @@ class Renderer {
|
|
|
277
271
|
/**
|
|
278
272
|
* resizes the system canvas
|
|
279
273
|
* @name resize
|
|
280
|
-
* @memberof Renderer
|
|
281
|
-
* @function
|
|
274
|
+
* @memberof Renderer
|
|
282
275
|
* @param {number} width new width of the canvas
|
|
283
276
|
* @param {number} height new height of the canvas
|
|
284
277
|
*/
|
|
@@ -298,8 +291,7 @@ class Renderer {
|
|
|
298
291
|
/**
|
|
299
292
|
* enable/disable image smoothing (scaling interpolation) for the given context
|
|
300
293
|
* @name setAntiAlias
|
|
301
|
-
* @memberof Renderer
|
|
302
|
-
* @function
|
|
294
|
+
* @memberof Renderer
|
|
303
295
|
* @param {CanvasRenderingContext2D} context
|
|
304
296
|
* @param {boolean} [enable=false]
|
|
305
297
|
*/
|
|
@@ -328,8 +320,7 @@ class Renderer {
|
|
|
328
320
|
/**
|
|
329
321
|
* set/change the current projection matrix (WebGL only)
|
|
330
322
|
* @name setProjection
|
|
331
|
-
* @memberof Renderer
|
|
332
|
-
* @function
|
|
323
|
+
* @memberof Renderer
|
|
333
324
|
* @param {Matrix3d} matrix
|
|
334
325
|
*/
|
|
335
326
|
setProjection(matrix) {
|
|
@@ -339,12 +330,15 @@ class Renderer {
|
|
|
339
330
|
/**
|
|
340
331
|
* stroke the given shape
|
|
341
332
|
* @name stroke
|
|
342
|
-
* @memberof Renderer
|
|
343
|
-
* @function
|
|
333
|
+
* @memberof Renderer
|
|
344
334
|
* @param {Rect|RoundRect|Polygon|Line|Ellipse} shape a shape object to stroke
|
|
345
335
|
* @param {boolean} [fill=false] fill the shape with the current color if true
|
|
346
336
|
*/
|
|
347
337
|
stroke(shape, fill) {
|
|
338
|
+
if (shape instanceof RoundRect) {
|
|
339
|
+
this.strokeRoundRect(shape.left, shape.top, shape.width, shape.height, shape.radius, fill);
|
|
340
|
+
return;
|
|
341
|
+
}
|
|
348
342
|
if (shape instanceof Rect || shape instanceof Bounds) {
|
|
349
343
|
this.strokeRect(shape.left, shape.top, shape.width, shape.height, fill);
|
|
350
344
|
return;
|
|
@@ -353,10 +347,6 @@ class Renderer {
|
|
|
353
347
|
this.strokePolygon(shape, fill);
|
|
354
348
|
return;
|
|
355
349
|
}
|
|
356
|
-
if (shape instanceof RoundRect) {
|
|
357
|
-
this.strokeRoundRect(shape.left, shape.top, shape.width, shape.height, shape.radius, fill);
|
|
358
|
-
return;
|
|
359
|
-
}
|
|
360
350
|
if (shape instanceof Ellipse) {
|
|
361
351
|
this.strokeEllipse(
|
|
362
352
|
shape.pos.x,
|
|
@@ -373,8 +363,7 @@ class Renderer {
|
|
|
373
363
|
/**
|
|
374
364
|
* fill the given shape
|
|
375
365
|
* @name fill
|
|
376
|
-
* @memberof Renderer
|
|
377
|
-
* @function
|
|
366
|
+
* @memberof Renderer
|
|
378
367
|
* @param {Rect|RoundRect|Polygon|Line|Ellipse} shape a shape object to fill
|
|
379
368
|
*/
|
|
380
369
|
fill(shape) {
|
|
@@ -384,8 +373,7 @@ class Renderer {
|
|
|
384
373
|
/**
|
|
385
374
|
* tint the given image or canvas using the given color
|
|
386
375
|
* @name tint
|
|
387
|
-
* @memberof Renderer
|
|
388
|
-
* @function
|
|
376
|
+
* @memberof Renderer
|
|
389
377
|
* @param {HTMLImageElement|HTMLCanvasElement|OffscreenCanvas} src the source image to be tinted
|
|
390
378
|
* @param {Color|string} color the color that will be used to tint the image
|
|
391
379
|
* @param {string} [mode="multiply"] the composition mode used to tint the image
|
|
@@ -415,9 +403,9 @@ class Renderer {
|
|
|
415
403
|
* So, if the renderable is larger than the mask, only the intersecting part of the renderable will be visible.
|
|
416
404
|
* Mask are not preserved through renderer context save and restore.
|
|
417
405
|
* @name setMask
|
|
418
|
-
* @memberof Renderer
|
|
419
|
-
* @function
|
|
406
|
+
* @memberof Renderer
|
|
420
407
|
* @param {Rect|RoundRect|Polygon|Line|Ellipse} [mask] the shape defining the mask to be applied
|
|
408
|
+
* @param {boolean} [invert=false] either the given shape should define what is visible (default) or the opposite
|
|
421
409
|
*/
|
|
422
410
|
// eslint-disable-next-line no-unused-vars
|
|
423
411
|
setMask(mask) {}
|
|
@@ -426,16 +414,14 @@ class Renderer {
|
|
|
426
414
|
* disable (remove) the rendering mask set through setMask.
|
|
427
415
|
* @name clearMask
|
|
428
416
|
* @see Renderer#setMask
|
|
429
|
-
* @memberof Renderer
|
|
430
|
-
* @function
|
|
417
|
+
* @memberof Renderer
|
|
431
418
|
*/
|
|
432
419
|
clearMask() {}
|
|
433
420
|
|
|
434
421
|
/**
|
|
435
422
|
* set a coloring tint for sprite based renderables
|
|
436
423
|
* @name setTint
|
|
437
|
-
* @memberof Renderer
|
|
438
|
-
* @function
|
|
424
|
+
* @memberof Renderer
|
|
439
425
|
* @param {Color} tint the tint color
|
|
440
426
|
* @param {number} [alpha] an alpha value to be applied to the tint
|
|
441
427
|
*/
|
|
@@ -449,8 +435,7 @@ class Renderer {
|
|
|
449
435
|
* clear the rendering tint set through setTint.
|
|
450
436
|
* @name clearTint
|
|
451
437
|
* @see Renderer#setTint
|
|
452
|
-
* @memberof Renderer
|
|
453
|
-
* @function
|
|
438
|
+
* @memberof Renderer
|
|
454
439
|
*/
|
|
455
440
|
clearTint() {
|
|
456
441
|
// reset to default
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import Vector2d from "
|
|
2
|
-
import WebGLRenderer from "
|
|
3
|
-
import TextureCache from "
|
|
4
|
-
import Sprite from "
|
|
5
|
-
import { renderer } from "
|
|
6
|
-
import pool from "
|
|
7
|
-
import loader from "
|
|
8
|
-
import { ETA } from "
|
|
1
|
+
import Vector2d from "./../../math/vector2.js";
|
|
2
|
+
import WebGLRenderer from "./../webgl/webgl_renderer.js";
|
|
3
|
+
import TextureCache from "./../texture/cache.js";
|
|
4
|
+
import Sprite from "./../../renderable/sprite.js";
|
|
5
|
+
import { renderer } from "./../video.js";
|
|
6
|
+
import pool from "./../../system/pooling.js";
|
|
7
|
+
import loader from "./../../loader/loader.js";
|
|
8
|
+
import { ETA } from "./../../math/math.js";
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
11
|
* create a simple 1 frame texture atlas based on the given parameters
|
|
@@ -381,6 +381,8 @@ export class TextureAtlas {
|
|
|
381
381
|
* add uvs mapping for the given region
|
|
382
382
|
* @param {object} atlas the atlas dictionnary where the region is define
|
|
383
383
|
* @param {object} name region (or frame) name
|
|
384
|
+
* @param {number} w the width of the region
|
|
385
|
+
* @param {number} h the height of the region
|
|
384
386
|
* @returns {Float32Array} the created region UVs
|
|
385
387
|
*/
|
|
386
388
|
addUVs(atlas, name, w, h) {
|
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import { renderer } from "
|
|
2
|
-
import * as fileUtil from "
|
|
3
|
-
import { TextureAtlas, createAtlas } from "./
|
|
4
|
-
import { isPowerOfTwo} from "
|
|
1
|
+
import { renderer } from "./../video.js";
|
|
2
|
+
import * as fileUtil from "./../../utils/file.js";
|
|
3
|
+
import { TextureAtlas, createAtlas } from "./atlas.js";
|
|
4
|
+
import { isPowerOfTwo} from "./../../math/math.js";
|
|
5
5
|
import {ArrayMultimap} from "@teppeis/multimaps";
|
|
6
6
|
|
|
7
|
-
|
|
8
7
|
/**
|
|
9
8
|
* a basic texture cache object
|
|
10
9
|
* @ignore
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { createCanvas } from "./../video.js";
|
|
2
|
+
|
|
3
|
+
// default video settings
|
|
4
|
+
var defaultAttributes = {
|
|
5
|
+
offscreenCanvas : false,
|
|
6
|
+
willReadFrequently : false
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Creates a Canvas Texture of the given size
|
|
11
|
+
*/
|
|
12
|
+
class CanvasTexture {
|
|
13
|
+
/**
|
|
14
|
+
* @param {number} width the desired width of the canvas
|
|
15
|
+
* @param {number} height the desired height of the canvas
|
|
16
|
+
* @param {object} attributes The attributes to create both the canvas and 2d context
|
|
17
|
+
* @param {boolean} [attributes.offscreenCanvas=false] will create an offscreenCanvas if true instead of a standard canvas
|
|
18
|
+
* @param {boolean} [attributes.willReadFrequently=false] Indicates whether or not a lot of read-back operations are planned
|
|
19
|
+
*/
|
|
20
|
+
constructor(width, height, attributes = defaultAttributes) {
|
|
21
|
+
|
|
22
|
+
// clean up the given attributes
|
|
23
|
+
attributes = Object.assign(defaultAttributes, attributes || {});
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* the canvas created for this CanvasTexture
|
|
27
|
+
* @type {HTMLCanvasElement|OffscreenCanvas}
|
|
28
|
+
*/
|
|
29
|
+
this.canvas = createCanvas(width, height, attributes.offscreenCanvas);
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* the rendering context of this CanvasTexture
|
|
33
|
+
* @type {CanvasRenderingContext2D}
|
|
34
|
+
*/
|
|
35
|
+
this.context = this.canvas.getContext("2d", { willReadFrequently: attributes.willReadFrequently });
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* @ignore
|
|
40
|
+
*/
|
|
41
|
+
onResetEvent(width, height) {
|
|
42
|
+
this.clear();
|
|
43
|
+
this.resize(width, height);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Clears the content of the canvas texture
|
|
48
|
+
*/
|
|
49
|
+
clear() {
|
|
50
|
+
this.context.setTransform(1, 0, 0, 1, 0, 0);
|
|
51
|
+
this.context.clearRect(0, 0, this.canvas.width, this.canvas.height);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Resizes the canvas texture to the given width and height.
|
|
56
|
+
* @param {number} width the desired width
|
|
57
|
+
* @param {number} height the desired height
|
|
58
|
+
*/
|
|
59
|
+
resize(width, height) {
|
|
60
|
+
this.canvas.width = Math.round(width);
|
|
61
|
+
this.canvas.height = Math.round(height);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* @ignore
|
|
66
|
+
*/
|
|
67
|
+
destroy() {
|
|
68
|
+
this.context = undefined;
|
|
69
|
+
this.canvas = undefined;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* The width of this canvas texture in pixels
|
|
74
|
+
* @public
|
|
75
|
+
* @type {number}
|
|
76
|
+
*/
|
|
77
|
+
get width() {
|
|
78
|
+
return this.canvas.width;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
set width(val) {
|
|
82
|
+
this.canvas.width = Math.round(val);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* The height of this canvas texture in pixels
|
|
87
|
+
* @public
|
|
88
|
+
* @type {number}
|
|
89
|
+
*/
|
|
90
|
+
get height() {
|
|
91
|
+
return this.canvas.height;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
set height(val) {
|
|
95
|
+
this.canvas.height = Math.round(val);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export default CanvasTexture;
|
package/src/video/video.js
CHANGED
|
@@ -382,17 +382,17 @@ export function init(width, height, options) {
|
|
|
382
382
|
* @function video.createCanvas
|
|
383
383
|
* @param {number} width width
|
|
384
384
|
* @param {number} height height
|
|
385
|
-
* @param {boolean} [
|
|
385
|
+
* @param {boolean} [offscreenCanvas=false] will return an OffscreenCanvas if supported
|
|
386
386
|
* @returns {HTMLCanvasElement|OffscreenCanvas}
|
|
387
387
|
*/
|
|
388
|
-
export function createCanvas(width, height,
|
|
388
|
+
export function createCanvas(width, height, offscreenCanvas = false) {
|
|
389
389
|
var _canvas;
|
|
390
390
|
|
|
391
391
|
if (width === 0 || height === 0) {
|
|
392
392
|
throw new Error("width or height was zero, Canvas could not be initialized !");
|
|
393
393
|
}
|
|
394
394
|
|
|
395
|
-
if (device.OffscreenCanvas === true &&
|
|
395
|
+
if (device.OffscreenCanvas === true && offscreenCanvas === true) {
|
|
396
396
|
_canvas = new OffscreenCanvas(0, 0);
|
|
397
397
|
// stubbing style for compatibility,
|
|
398
398
|
// as OffscreenCanvas is detached from the DOM
|
|
@@ -103,7 +103,6 @@ class GLShader {
|
|
|
103
103
|
* Installs this shader program as part of current rendering state
|
|
104
104
|
* @name bind
|
|
105
105
|
* @memberof GLShader
|
|
106
|
-
* @function
|
|
107
106
|
*/
|
|
108
107
|
bind() {
|
|
109
108
|
this.gl.useProgram(this.program);
|
|
@@ -113,7 +112,6 @@ class GLShader {
|
|
|
113
112
|
* returns the location of an attribute variable in this shader program
|
|
114
113
|
* @name getAttribLocation
|
|
115
114
|
* @memberof GLShader
|
|
116
|
-
* @function
|
|
117
115
|
* @param {string} name the name of the attribute variable whose location to get.
|
|
118
116
|
* @returns {GLint} number indicating the location of the variable name if found. Returns -1 otherwise
|
|
119
117
|
*/
|
|
@@ -130,7 +128,6 @@ class GLShader {
|
|
|
130
128
|
* Set the uniform to the given value
|
|
131
129
|
* @name setUniform
|
|
132
130
|
* @memberof GLShader
|
|
133
|
-
* @function
|
|
134
131
|
* @param {string} name the uniform name
|
|
135
132
|
* @param {object|Float32Array} value the value to assign to that uniform
|
|
136
133
|
* @example
|
|
@@ -153,7 +150,6 @@ class GLShader {
|
|
|
153
150
|
* activate the given vertex attribute for this shader
|
|
154
151
|
* @name setVertexAttributes
|
|
155
152
|
* @memberof GLShader
|
|
156
|
-
* @function
|
|
157
153
|
* @param {WebGLRenderingContext} gl the current WebGL rendering context
|
|
158
154
|
* @param {object[]} attributes an array of vertex attributes
|
|
159
155
|
* @param {number} vertexByteSize the size of a single vertex in bytes
|
|
@@ -177,7 +173,6 @@ class GLShader {
|
|
|
177
173
|
* destroy this shader objects resources (program, attributes, uniforms)
|
|
178
174
|
* @name destroy
|
|
179
175
|
* @memberof GLShader
|
|
180
|
-
* @function
|
|
181
176
|
*/
|
|
182
177
|
destroy() {
|
|
183
178
|
this.uniforms = null;
|
|
@@ -47,9 +47,8 @@ export function extractUniforms(gl, shader) {
|
|
|
47
47
|
|
|
48
48
|
descriptor[name] = {
|
|
49
49
|
"get" : (function (name) {
|
|
50
|
-
|
|
50
|
+
/*
|
|
51
51
|
* A getter for the uniform location
|
|
52
|
-
* @ignore
|
|
53
52
|
*/
|
|
54
53
|
return function () {
|
|
55
54
|
return locations[name];
|
|
@@ -57,18 +56,16 @@ export function extractUniforms(gl, shader) {
|
|
|
57
56
|
})(name),
|
|
58
57
|
"set" : (function (name, type, fn) {
|
|
59
58
|
if (type.indexOf("mat") === 0) {
|
|
60
|
-
|
|
59
|
+
/*
|
|
61
60
|
* A generic setter for uniform matrices
|
|
62
|
-
* @ignore
|
|
63
61
|
*/
|
|
64
62
|
return function (val) {
|
|
65
63
|
gl[fn](locations[name], false, val);
|
|
66
64
|
};
|
|
67
65
|
}
|
|
68
66
|
else {
|
|
69
|
-
|
|
67
|
+
/*
|
|
70
68
|
* A generic setter for uniform vectors
|
|
71
|
-
* @ignore
|
|
72
69
|
*/
|
|
73
70
|
return function (val) {
|
|
74
71
|
var fnv = fn;
|
|
@@ -156,7 +156,6 @@ class WebGLCompositor {
|
|
|
156
156
|
* add vertex attribute property definition to the compositor
|
|
157
157
|
* @name addAttribute
|
|
158
158
|
* @memberof WebGLCompositor
|
|
159
|
-
* @function
|
|
160
159
|
* @param {string} name name of the attribute in the vertex shader
|
|
161
160
|
* @param {number} size number of components per vertex attribute. Must be 1, 2, 3, or 4.
|
|
162
161
|
* @param {GLenum} type data type of each component in the array
|
|
@@ -204,7 +203,6 @@ class WebGLCompositor {
|
|
|
204
203
|
* Sets the viewport
|
|
205
204
|
* @name setViewport
|
|
206
205
|
* @memberof WebGLCompositor
|
|
207
|
-
* @function
|
|
208
206
|
* @param {number} x x position of viewport
|
|
209
207
|
* @param {number} y y position of viewport
|
|
210
208
|
* @param {number} w width of viewport
|
|
@@ -218,7 +216,6 @@ class WebGLCompositor {
|
|
|
218
216
|
* Create a WebGL texture from an image
|
|
219
217
|
* @name createTexture2D
|
|
220
218
|
* @memberof WebGLCompositor
|
|
221
|
-
* @function
|
|
222
219
|
* @param {number} unit Destination texture unit
|
|
223
220
|
* @param {Image|HTMLCanvasElement|ImageData|Uint8Array[]|Float32Array[]} image Source image
|
|
224
221
|
* @param {number} filter gl.LINEAR or gl.NEAREST
|
|
@@ -263,7 +260,6 @@ class WebGLCompositor {
|
|
|
263
260
|
* delete the given WebGL texture
|
|
264
261
|
* @name bindTexture2D
|
|
265
262
|
* @memberof WebGLCompositor
|
|
266
|
-
* @function
|
|
267
263
|
* @param {WebGLTexture} [texture] a WebGL texture to delete
|
|
268
264
|
* @param {number} [unit] Texture unit to delete
|
|
269
265
|
*/
|
|
@@ -276,7 +272,6 @@ class WebGLCompositor {
|
|
|
276
272
|
* returns the WebGL texture associated to the given texture unit
|
|
277
273
|
* @name bindTexture2D
|
|
278
274
|
* @memberof WebGLCompositor
|
|
279
|
-
* @function
|
|
280
275
|
* @param {number} unit Texture unit to which a texture is bound
|
|
281
276
|
* @returns {WebGLTexture} texture a WebGL texture
|
|
282
277
|
*/
|
|
@@ -288,7 +283,6 @@ class WebGLCompositor {
|
|
|
288
283
|
* assign the given WebGL texture to the current batch
|
|
289
284
|
* @name bindTexture2D
|
|
290
285
|
* @memberof WebGLCompositor
|
|
291
|
-
* @function
|
|
292
286
|
* @param {WebGLTexture} texture a WebGL texture
|
|
293
287
|
* @param {number} unit Texture unit to which the given texture is bound
|
|
294
288
|
*/
|
|
@@ -316,7 +310,6 @@ class WebGLCompositor {
|
|
|
316
310
|
* unbind the given WebGL texture, forcing it to be reuploaded
|
|
317
311
|
* @name unbindTexture2D
|
|
318
312
|
* @memberof WebGLCompositor
|
|
319
|
-
* @function
|
|
320
313
|
* @param {WebGLTexture} [texture] a WebGL texture
|
|
321
314
|
* @param {number} [unit] a WebGL texture
|
|
322
315
|
* @returns {number} unit the unit number that was associated with the given texture
|
|
@@ -363,7 +356,6 @@ class WebGLCompositor {
|
|
|
363
356
|
* set/change the current projection matrix
|
|
364
357
|
* @name setProjection
|
|
365
358
|
* @memberof WebGLCompositor
|
|
366
|
-
* @function
|
|
367
359
|
* @param {Matrix3d} matrix
|
|
368
360
|
*/
|
|
369
361
|
setProjection(matrix) {
|
|
@@ -375,7 +367,6 @@ class WebGLCompositor {
|
|
|
375
367
|
* @name useShader
|
|
376
368
|
* @see GLShader
|
|
377
369
|
* @memberof WebGLCompositor
|
|
378
|
-
* @function
|
|
379
370
|
* @param {GLShader} shader a reference to a GLShader instance
|
|
380
371
|
*/
|
|
381
372
|
useShader(shader) {
|
|
@@ -392,7 +383,6 @@ class WebGLCompositor {
|
|
|
392
383
|
* Add a textured quad
|
|
393
384
|
* @name addQuad
|
|
394
385
|
* @memberof WebGLCompositor
|
|
395
|
-
* @function
|
|
396
386
|
* @param {TextureAtlas} texture Source texture atlas
|
|
397
387
|
* @param {number} x Destination x-coordinate
|
|
398
388
|
* @param {number} y Destination y-coordinate
|
|
@@ -449,7 +439,6 @@ class WebGLCompositor {
|
|
|
449
439
|
* Flush batched texture operations to the GPU
|
|
450
440
|
* @param {number} [mode=gl.TRIANGLES] the GL drawing mode
|
|
451
441
|
* @memberof WebGLCompositor
|
|
452
|
-
* @function
|
|
453
442
|
*/
|
|
454
443
|
flush(mode = this.mode) {
|
|
455
444
|
var vertex = this.vertexBuffer;
|
|
@@ -477,7 +466,6 @@ class WebGLCompositor {
|
|
|
477
466
|
* Draw an array of vertices
|
|
478
467
|
* @name drawVertices
|
|
479
468
|
* @memberof WebGLCompositor
|
|
480
|
-
* @function
|
|
481
469
|
* @param {GLenum} mode primitive type to render (gl.POINTS, gl.LINE_STRIP, gl.LINE_LOOP, gl.LINES, gl.TRIANGLE_STRIP, gl.TRIANGLE_FAN, gl.TRIANGLES)
|
|
482
470
|
* @param {Vector2d[]} verts vertices
|
|
483
471
|
* @param {number} [vertexCount=verts.length] amount of points defined in the points array
|
|
@@ -507,7 +495,6 @@ class WebGLCompositor {
|
|
|
507
495
|
* Specify the color values used when clearing color buffers. The values are clamped between 0 and 1.
|
|
508
496
|
* @name clearColor
|
|
509
497
|
* @memberof WebGLCompositor
|
|
510
|
-
* @function
|
|
511
498
|
* @param {number} [r=0] - the red color value used when the color buffers are cleared
|
|
512
499
|
* @param {number} [g=0] - the green color value used when the color buffers are cleared
|
|
513
500
|
* @param {number} [b=0] - the blue color value used when the color buffers are cleared
|
|
@@ -521,7 +508,6 @@ class WebGLCompositor {
|
|
|
521
508
|
* Clear the frame buffer
|
|
522
509
|
* @name clear
|
|
523
510
|
* @memberof WebGLCompositor
|
|
524
|
-
* @function
|
|
525
511
|
*/
|
|
526
512
|
clear() {
|
|
527
513
|
this.gl.clear(this.gl.COLOR_BUFFER_BIT);
|