melonjs 12.0.0 → 13.1.1
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 +4 -6
- package/dist/melonjs.js +22648 -22478
- package/dist/melonjs.min.js +5 -6
- package/dist/melonjs.module.d.ts +289 -264
- package/dist/melonjs.module.js +21979 -21804
- package/package.json +15 -16
- package/src/application/application.js +231 -0
- package/src/audio/audio.js +8 -2
- package/src/camera/camera2d.js +6 -6
- package/src/game.js +9 -232
- package/src/index.js +3 -3
- package/src/input/keyboard.js +2 -2
- package/src/input/pointer.js +4 -5
- package/src/input/pointerevent.js +10 -10
- package/src/lang/deprecated.js +27 -30
- package/src/level/level.js +2 -2
- package/src/level/tiled/TMXGroup.js +10 -0
- package/src/level/tiled/TMXLayer.js +11 -2
- package/src/level/tiled/TMXObject.js +13 -2
- package/src/level/tiled/TMXTileMap.js +15 -3
- package/src/level/tiled/TMXTileset.js +8 -0
- package/src/loader/loader.js +64 -28
- package/src/loader/loadingscreen.js +27 -28
- package/src/math/color.js +62 -42
- package/src/math/observable_vector2.js +26 -2
- package/src/math/observable_vector3.js +32 -4
- package/src/math/vector2.js +23 -0
- package/src/math/vector3.js +26 -0
- package/src/physics/body.js +27 -51
- package/src/physics/detector.js +3 -3
- package/src/physics/quadtree.js +58 -29
- package/src/physics/world.js +32 -3
- package/src/renderable/container.js +2 -2
- package/src/renderable/imagelayer.js +8 -8
- package/src/renderable/nineslicesprite.js +27 -1
- package/src/renderable/trigger.js +4 -4
- package/src/state/stage.js +1 -1
- package/src/state/state.js +50 -3
- package/src/system/device.js +814 -981
- package/src/system/event.js +2 -1
- package/src/system/platform.js +32 -0
- package/src/system/save.js +23 -14
- package/src/system/timer.js +12 -35
- package/src/text/text.js +9 -12
- package/src/tweens/tween.js +6 -6
- package/src/utils/string.js +13 -0
- package/src/video/canvas/canvas_renderer.js +30 -65
- package/src/video/renderer.js +23 -30
- package/src/video/texture/canvas_texture.js +39 -3
- package/src/video/video.js +27 -25
- package/src/video/webgl/glshader.js +1 -1
- package/src/video/webgl/webgl_compositor.js +2 -2
- package/src/video/webgl/webgl_renderer.js +8 -20
package/src/video/renderer.js
CHANGED
|
@@ -2,7 +2,7 @@ import Color from "./../math/color.js";
|
|
|
2
2
|
import Matrix3d from "./../math/matrix3.js";
|
|
3
3
|
import { createCanvas, renderer } from "./video.js";
|
|
4
4
|
import * as event from "./../system/event.js";
|
|
5
|
-
import device from "./../system/device.js";
|
|
5
|
+
import * as device from "./../system/device.js";
|
|
6
6
|
import { setPrefixed } from "./../utils/agent.js";
|
|
7
7
|
import Rect from "./../geometries/rectangle.js";
|
|
8
8
|
import RoundRect from "./../geometries/roundrect.js";
|
|
@@ -22,7 +22,6 @@ class Renderer {
|
|
|
22
22
|
* @param {number} options.width The width of the canvas without scaling
|
|
23
23
|
* @param {number} options.height The height of the canvas without scaling
|
|
24
24
|
* @param {HTMLCanvasElement} [options.canvas] The html canvas to draw to on screen
|
|
25
|
-
* @param {boolean} [options.doubleBuffering=false] Whether to enable double buffering
|
|
26
25
|
* @param {boolean} [options.antiAlias=false] Whether to enable anti-aliasing, use false (default) for a pixelated effect.
|
|
27
26
|
* @param {boolean} [options.failIfMajorPerformanceCaveat=true] If true, the renderer will switch to CANVAS mode if the performances of a WebGL context would be dramatically lower than that of a native application making equivalent OpenGL calls.
|
|
28
27
|
* @param {boolean} [options.transparent=false] Whether to enable transparency on the canvas (performance hit when enabled)
|
|
@@ -84,13 +83,9 @@ class Renderer {
|
|
|
84
83
|
} else if (typeof this.settings.canvas !== "undefined") {
|
|
85
84
|
this.canvas = this.settings.canvas;
|
|
86
85
|
} else {
|
|
87
|
-
this.canvas = createCanvas(this.settings.
|
|
86
|
+
this.canvas = createCanvas(this.settings.width, this.settings.height);
|
|
88
87
|
}
|
|
89
88
|
|
|
90
|
-
// canvas object and context
|
|
91
|
-
this.backBufferCanvas = this.canvas;
|
|
92
|
-
this.context = null;
|
|
93
|
-
|
|
94
89
|
// global color
|
|
95
90
|
this.currentColor = new Color(0, 0, 0, 1.0);
|
|
96
91
|
|
|
@@ -116,6 +111,13 @@ class Renderer {
|
|
|
116
111
|
*/
|
|
117
112
|
clear() {}
|
|
118
113
|
|
|
114
|
+
/**
|
|
115
|
+
* render the main framebuffer on screen
|
|
116
|
+
* @name flush
|
|
117
|
+
* @memberof Renderer
|
|
118
|
+
*/
|
|
119
|
+
flush() {}
|
|
120
|
+
|
|
119
121
|
/**
|
|
120
122
|
* Reset context state
|
|
121
123
|
* @name reset
|
|
@@ -129,39 +131,29 @@ class Renderer {
|
|
|
129
131
|
this.cache.clear();
|
|
130
132
|
this.currentScissor[0] = 0;
|
|
131
133
|
this.currentScissor[1] = 0;
|
|
132
|
-
this.currentScissor[2] = this.
|
|
133
|
-
this.currentScissor[3] = this.
|
|
134
|
+
this.currentScissor[2] = this.getCanvas().width;
|
|
135
|
+
this.currentScissor[3] = this.getCanvas().height;
|
|
134
136
|
this.clearMask();
|
|
135
137
|
}
|
|
136
138
|
|
|
137
139
|
/**
|
|
138
|
-
* return a reference to the
|
|
140
|
+
* return a reference to the canvas which this renderer draws to
|
|
139
141
|
* @name getCanvas
|
|
140
142
|
* @memberof Renderer
|
|
141
143
|
* @returns {HTMLCanvasElement}
|
|
142
144
|
*/
|
|
143
145
|
getCanvas() {
|
|
144
|
-
return this.backBufferCanvas;
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
/**
|
|
148
|
-
* return a reference to the screen canvas
|
|
149
|
-
* @name getScreenCanvas
|
|
150
|
-
* @memberof Renderer
|
|
151
|
-
* @returns {HTMLCanvasElement}
|
|
152
|
-
*/
|
|
153
|
-
getScreenCanvas() {
|
|
154
146
|
return this.canvas;
|
|
155
147
|
}
|
|
156
148
|
|
|
149
|
+
|
|
157
150
|
/**
|
|
158
|
-
* return a reference to
|
|
159
|
-
*
|
|
160
|
-
* @name getScreenContext
|
|
151
|
+
* return a reference to this renderer canvas corresponding Context
|
|
152
|
+
* @name getContext
|
|
161
153
|
* @memberof Renderer
|
|
162
|
-
* @returns {CanvasRenderingContext2D}
|
|
154
|
+
* @returns {CanvasRenderingContext2D|WebGLRenderingContext}
|
|
163
155
|
*/
|
|
164
|
-
|
|
156
|
+
getContext() {
|
|
165
157
|
return this.context;
|
|
166
158
|
}
|
|
167
159
|
|
|
@@ -220,7 +212,7 @@ class Renderer {
|
|
|
220
212
|
* @returns {number}
|
|
221
213
|
*/
|
|
222
214
|
getWidth() {
|
|
223
|
-
return this.
|
|
215
|
+
return this.getCanvas().width;
|
|
224
216
|
}
|
|
225
217
|
|
|
226
218
|
/**
|
|
@@ -230,7 +222,7 @@ class Renderer {
|
|
|
230
222
|
* @returns {number} height of the system Canvas
|
|
231
223
|
*/
|
|
232
224
|
getHeight() {
|
|
233
|
-
return this.
|
|
225
|
+
return this.getCanvas().height;
|
|
234
226
|
}
|
|
235
227
|
|
|
236
228
|
/**
|
|
@@ -276,9 +268,10 @@ class Renderer {
|
|
|
276
268
|
* @param {number} height new height of the canvas
|
|
277
269
|
*/
|
|
278
270
|
resize(width, height) {
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
271
|
+
var canvas = this.getCanvas();
|
|
272
|
+
if (width !== canvas.width || height !== canvas.height) {
|
|
273
|
+
canvas.width = width;
|
|
274
|
+
canvas.height = height;
|
|
282
275
|
this.currentScissor[0] = 0;
|
|
283
276
|
this.currentScissor[1] = 0;
|
|
284
277
|
this.currentScissor[2] = width;
|
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import { createCanvas } from "./../video.js";
|
|
2
|
+
import { setPrefixed } from "./../../utils/agent.js";
|
|
2
3
|
|
|
3
|
-
// default
|
|
4
|
+
// default canvas settings
|
|
4
5
|
var defaultAttributes = {
|
|
5
6
|
offscreenCanvas : false,
|
|
6
|
-
willReadFrequently : false
|
|
7
|
+
willReadFrequently : false,
|
|
8
|
+
antiAlias : false,
|
|
9
|
+
context: "2d"
|
|
7
10
|
};
|
|
8
11
|
|
|
9
12
|
/**
|
|
@@ -13,9 +16,11 @@ class CanvasTexture {
|
|
|
13
16
|
/**
|
|
14
17
|
* @param {number} width the desired width of the canvas
|
|
15
18
|
* @param {number} height the desired height of the canvas
|
|
16
|
-
* @param {object} attributes The attributes to create both the canvas and
|
|
19
|
+
* @param {object} attributes The attributes to create both the canvas and context
|
|
20
|
+
* @param {boolean} [attributes.context="2d"] the context type to be created ("2d", "webgl", "webgl2")
|
|
17
21
|
* @param {boolean} [attributes.offscreenCanvas=false] will create an offscreenCanvas if true instead of a standard canvas
|
|
18
22
|
* @param {boolean} [attributes.willReadFrequently=false] Indicates whether or not a lot of read-back operations are planned
|
|
23
|
+
* @param {boolean} [attributes.antiAlias=false] Whether to enable anti-aliasing, use false (default) for a pixelated effect.
|
|
19
24
|
*/
|
|
20
25
|
constructor(width, height, attributes = defaultAttributes) {
|
|
21
26
|
|
|
@@ -33,6 +38,9 @@ class CanvasTexture {
|
|
|
33
38
|
* @type {CanvasRenderingContext2D}
|
|
34
39
|
*/
|
|
35
40
|
this.context = this.canvas.getContext("2d", { willReadFrequently: attributes.willReadFrequently });
|
|
41
|
+
|
|
42
|
+
// enable or disable antiAlias if specified
|
|
43
|
+
this.setAntiAlias(attributes.antiAlias);
|
|
36
44
|
}
|
|
37
45
|
|
|
38
46
|
/**
|
|
@@ -51,6 +59,34 @@ class CanvasTexture {
|
|
|
51
59
|
this.context.clearRect(0, 0, this.canvas.width, this.canvas.height);
|
|
52
60
|
}
|
|
53
61
|
|
|
62
|
+
/**
|
|
63
|
+
* enable/disable image smoothing (scaling interpolation)
|
|
64
|
+
* @param {boolean} [enable=false]
|
|
65
|
+
*/
|
|
66
|
+
setAntiAlias(enable = false) {
|
|
67
|
+
var canvas = this.canvas;
|
|
68
|
+
|
|
69
|
+
// enable/disable antialias on the given Context2d object
|
|
70
|
+
setPrefixed("imageSmoothingEnabled", enable, this.context);
|
|
71
|
+
|
|
72
|
+
// set antialias CSS property on the main canvas
|
|
73
|
+
if (typeof canvas.style !== "undefined") {
|
|
74
|
+
if (enable !== true) {
|
|
75
|
+
// https://developer.mozilla.org/en-US/docs/Web/CSS/image-rendering
|
|
76
|
+
canvas.style["image-rendering"] = "optimizeSpeed"; // legal fallback
|
|
77
|
+
canvas.style["image-rendering"] = "-moz-crisp-edges"; // Firefox
|
|
78
|
+
canvas.style["image-rendering"] = "-o-crisp-edges"; // Opera
|
|
79
|
+
canvas.style["image-rendering"] = "-webkit-optimize-contrast"; // Safari
|
|
80
|
+
canvas.style["image-rendering"] = "optimize-contrast"; // CSS 3
|
|
81
|
+
canvas.style["image-rendering"] = "crisp-edges"; // CSS 4
|
|
82
|
+
canvas.style["image-rendering"] = "pixelated"; // CSS 4
|
|
83
|
+
canvas.style.msInterpolationMode = "nearest-neighbor"; // IE8+
|
|
84
|
+
} else {
|
|
85
|
+
canvas.style["image-rendering"] = "auto";
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
54
90
|
/**
|
|
55
91
|
* Resizes the canvas texture to the given width and height.
|
|
56
92
|
* @param {number} width the desired width
|
package/src/video/video.js
CHANGED
|
@@ -3,8 +3,8 @@ import WebGLRenderer from "./webgl/webgl_renderer.js";
|
|
|
3
3
|
import CanvasRenderer from "./canvas/canvas_renderer.js";
|
|
4
4
|
import utils from "./../utils/utils.js";
|
|
5
5
|
import * as event from "./../system/event.js";
|
|
6
|
-
import
|
|
7
|
-
import device from "./../system/device.js";
|
|
6
|
+
import game from "./../game.js";
|
|
7
|
+
import * as device from "./../system/device.js";
|
|
8
8
|
import { initialized, version } from "./../index.js";
|
|
9
9
|
|
|
10
10
|
/**
|
|
@@ -20,10 +20,9 @@ var designHeight = 0;
|
|
|
20
20
|
var settings = {
|
|
21
21
|
parent : undefined,
|
|
22
22
|
renderer : 2, // AUTO
|
|
23
|
-
doubleBuffering : false,
|
|
24
23
|
autoScale : false,
|
|
25
24
|
scale : 1.0,
|
|
26
|
-
scaleMethod : "
|
|
25
|
+
scaleMethod : "manual",
|
|
27
26
|
transparent : false,
|
|
28
27
|
blendMode : "normal",
|
|
29
28
|
antiAlias : false,
|
|
@@ -65,7 +64,7 @@ function onresize() {
|
|
|
65
64
|
var canvasMaxHeight = Infinity;
|
|
66
65
|
|
|
67
66
|
if (globalThis.getComputedStyle) {
|
|
68
|
-
var style = globalThis.getComputedStyle(renderer.
|
|
67
|
+
var style = globalThis.getComputedStyle(renderer.getCanvas(), null);
|
|
69
68
|
canvasMaxWidth = parseInt(style.maxWidth, 10) || Infinity;
|
|
70
69
|
canvasMaxHeight = parseInt(style.maxHeight, 10) || Infinity;
|
|
71
70
|
}
|
|
@@ -119,6 +118,9 @@ function onresize() {
|
|
|
119
118
|
|
|
120
119
|
// adjust scaling ratio based on the new scaling ratio
|
|
121
120
|
scale(scaleX, scaleY);
|
|
121
|
+
} else {
|
|
122
|
+
// adjust scaling ratio based on the given settings
|
|
123
|
+
scale(settings.scale, settings.scale);
|
|
122
124
|
}
|
|
123
125
|
};
|
|
124
126
|
|
|
@@ -196,7 +198,6 @@ export let renderer = null;
|
|
|
196
198
|
* @param {object} [options] The optional video/renderer parameters.<br> (see Renderer(s) documentation for further specific options)
|
|
197
199
|
* @param {string|HTMLElement} [options.parent=document.body] the DOM parent element to hold the canvas in the HTML file
|
|
198
200
|
* @param {number} [options.renderer=video.AUTO] renderer to use (me.video.CANVAS, me.video.WEBGL, me.video.AUTO)
|
|
199
|
-
* @param {boolean} [options.doubleBuffering=false] enable/disable double buffering
|
|
200
201
|
* @param {number|string} [options.scale=1.0] enable scaling of the canvas ('auto' for automatic scaling)
|
|
201
202
|
* @param {string} [options.scaleMethod="fit"] screen scaling modes ('fit','fill-min','fill-max','flex','flex-width','flex-height','stretch')
|
|
202
203
|
* @param {boolean} [options.preferWebGL1=false] if true the renderer will only use WebGL 1
|
|
@@ -211,8 +212,7 @@ export let renderer = null;
|
|
|
211
212
|
* parent : "screen",
|
|
212
213
|
* renderer : me.video.AUTO,
|
|
213
214
|
* scale : "auto",
|
|
214
|
-
* scaleMethod : "fit"
|
|
215
|
-
* doubleBuffering : true
|
|
215
|
+
* scaleMethod : "fit"
|
|
216
216
|
* });
|
|
217
217
|
*/
|
|
218
218
|
export function init(width, height, options) {
|
|
@@ -228,7 +228,6 @@ export function init(width, height, options) {
|
|
|
228
228
|
// sanitize potential given parameters
|
|
229
229
|
settings.width = width;
|
|
230
230
|
settings.height = height;
|
|
231
|
-
settings.doubleBuffering = !!(settings.doubleBuffering);
|
|
232
231
|
settings.transparent = !!(settings.transparent);
|
|
233
232
|
settings.antiAlias = !!(settings.antiAlias);
|
|
234
233
|
settings.failIfMajorPerformanceCaveat = !!(settings.failIfMajorPerformanceCaveat);
|
|
@@ -248,24 +247,21 @@ export function init(width, height, options) {
|
|
|
248
247
|
console.log("melonJS 2 (v" + version + ") | http://melonjs.org" );
|
|
249
248
|
}
|
|
250
249
|
|
|
251
|
-
// override renderer settings if &webgl is defined in the URL
|
|
250
|
+
// override renderer settings if &webgl or &canvas is defined in the URL
|
|
252
251
|
var uriFragment = utils.getUriFragment();
|
|
253
252
|
if (uriFragment.webgl === true || uriFragment.webgl1 === true || uriFragment.webgl2 === true) {
|
|
254
253
|
settings.renderer = WEBGL;
|
|
255
254
|
if (uriFragment.webgl1 === true) {
|
|
256
255
|
settings.preferWebGL1 = true;
|
|
257
256
|
}
|
|
257
|
+
} else if (uriFragment.canvas === true) {
|
|
258
|
+
settings.renderer = CANVAS;
|
|
258
259
|
}
|
|
259
260
|
|
|
260
261
|
// normalize scale
|
|
261
262
|
settings.scale = (settings.autoScale) ? 1.0 : (+settings.scale || 1.0);
|
|
262
263
|
scaleRatio.set(settings.scale, settings.scale);
|
|
263
264
|
|
|
264
|
-
// force double buffering if scaling is required
|
|
265
|
-
if (settings.autoScale || (settings.scale !== 1.0)) {
|
|
266
|
-
settings.doubleBuffering = true;
|
|
267
|
-
}
|
|
268
|
-
|
|
269
265
|
// hold the requested video size ratio
|
|
270
266
|
designRatio = width / height;
|
|
271
267
|
designWidth = width;
|
|
@@ -302,7 +298,7 @@ export function init(width, height, options) {
|
|
|
302
298
|
false
|
|
303
299
|
);
|
|
304
300
|
|
|
305
|
-
if (device.
|
|
301
|
+
if (device.screenOrientation === true) {
|
|
306
302
|
globalThis.screen.orientation.onchange = function (e) {
|
|
307
303
|
event.emit(event.WINDOW_ONORIENTATION_CHANGE, e);
|
|
308
304
|
};
|
|
@@ -337,7 +333,13 @@ export function init(width, height, options) {
|
|
|
337
333
|
|
|
338
334
|
// add our canvas (default to document.body if settings.parent is undefined)
|
|
339
335
|
parent = device.getElement(typeof settings.parent !== "undefined" ? settings.parent : document.body);
|
|
340
|
-
parent.appendChild(renderer.
|
|
336
|
+
parent.appendChild(renderer.getCanvas());
|
|
337
|
+
|
|
338
|
+
// Mobile browser hacks
|
|
339
|
+
if (device.platform.isMobile) {
|
|
340
|
+
// Prevent the webview from moving on a swipe
|
|
341
|
+
device.enableSwipe(false);
|
|
342
|
+
}
|
|
341
343
|
|
|
342
344
|
// trigger an initial resize();
|
|
343
345
|
onresize();
|
|
@@ -362,7 +364,7 @@ export function init(width, height, options) {
|
|
|
362
364
|
renderType + " renderer" + gpu_renderer + " | " +
|
|
363
365
|
audioType + " | " +
|
|
364
366
|
"pixel ratio " + device.devicePixelRatio + " | " +
|
|
365
|
-
(device.nodeJS ? "node.js" : device.isMobile ? "mobile" : "desktop") + " | " +
|
|
367
|
+
(device.platform.nodeJS ? "node.js" : device.platform.isMobile ? "mobile" : "desktop") + " | " +
|
|
366
368
|
device.getScreenOrientation() + " | " +
|
|
367
369
|
device.language
|
|
368
370
|
);
|
|
@@ -382,18 +384,18 @@ export function init(width, height, options) {
|
|
|
382
384
|
* @function video.createCanvas
|
|
383
385
|
* @param {number} width width
|
|
384
386
|
* @param {number} height height
|
|
385
|
-
* @param {boolean} [
|
|
387
|
+
* @param {boolean} [returnOffscreenCanvas=false] will return an OffscreenCanvas if supported
|
|
386
388
|
* @returns {HTMLCanvasElement|OffscreenCanvas}
|
|
387
389
|
*/
|
|
388
|
-
export function createCanvas(width, height,
|
|
390
|
+
export function createCanvas(width, height, returnOffscreenCanvas = false) {
|
|
389
391
|
var _canvas;
|
|
390
392
|
|
|
391
393
|
if (width === 0 || height === 0) {
|
|
392
394
|
throw new Error("width or height was zero, Canvas could not be initialized !");
|
|
393
395
|
}
|
|
394
396
|
|
|
395
|
-
if (device.
|
|
396
|
-
_canvas = new OffscreenCanvas(0, 0);
|
|
397
|
+
if (device.offscreenCanvas === true && returnOffscreenCanvas === true) {
|
|
398
|
+
_canvas = new globalThis.OffscreenCanvas(0, 0);
|
|
397
399
|
// stubbing style for compatibility,
|
|
398
400
|
// as OffscreenCanvas is detached from the DOM
|
|
399
401
|
if (typeof _canvas.style === "undefined") {
|
|
@@ -428,8 +430,8 @@ export function getParent() {
|
|
|
428
430
|
* @param {number} y y scaling multiplier
|
|
429
431
|
*/
|
|
430
432
|
export function scale(x, y) {
|
|
431
|
-
var canvas = renderer.
|
|
432
|
-
var context = renderer.
|
|
433
|
+
var canvas = renderer.getCanvas();
|
|
434
|
+
var context = renderer.getContext();
|
|
433
435
|
var settings = renderer.settings;
|
|
434
436
|
var pixelRatio = device.devicePixelRatio;
|
|
435
437
|
|
|
@@ -448,5 +450,5 @@ export function scale(x, y) {
|
|
|
448
450
|
renderer.setBlendMode(settings.blendMode, context);
|
|
449
451
|
|
|
450
452
|
// force repaint
|
|
451
|
-
repaint();
|
|
453
|
+
game.repaint();
|
|
452
454
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as event from "./../../system/event.js";
|
|
2
|
-
import device from "./../../system/device.js";
|
|
2
|
+
import * as device from "./../../system/device.js";
|
|
3
3
|
import { extractUniforms } from "./utils/uniforms.js";
|
|
4
4
|
import { extractAttributes } from "./utils/attributes.js";
|
|
5
5
|
import { compileProgram } from "./utils/program.js";
|
|
@@ -132,8 +132,8 @@ class WebGLCompositor {
|
|
|
132
132
|
// initial viewport size
|
|
133
133
|
this.setViewport(
|
|
134
134
|
0, 0,
|
|
135
|
-
this.renderer.
|
|
136
|
-
this.renderer.
|
|
135
|
+
this.renderer.getCanvas().width,
|
|
136
|
+
this.renderer.getCanvas().height
|
|
137
137
|
);
|
|
138
138
|
|
|
139
139
|
// Initialize clear color
|
|
@@ -20,7 +20,6 @@ class WebGLRenderer extends Renderer {
|
|
|
20
20
|
* @param {number} options.width The width of the canvas without scaling
|
|
21
21
|
* @param {number} options.height The height of the canvas without scaling
|
|
22
22
|
* @param {HTMLCanvasElement} [options.canvas] The html canvas to draw to on screen
|
|
23
|
-
* @param {boolean} [options.doubleBuffering=false] Whether to enable double buffering
|
|
24
23
|
* @param {boolean} [options.antiAlias=false] Whether to enable anti-aliasing
|
|
25
24
|
* @param {boolean} [options.failIfMajorPerformanceCaveat=true] If true, the renderer will switch to CANVAS mode if the performances of a WebGL context would be dramatically lower than that of a native application making equivalent OpenGL calls.
|
|
26
25
|
* @param {boolean} [options.transparent=false] Whether to enable transparency on the canvas (performance hit when enabled)
|
|
@@ -72,7 +71,7 @@ class WebGLRenderer extends Renderer {
|
|
|
72
71
|
* @memberof WebGLRenderer
|
|
73
72
|
* @type {WebGLRenderingContext}
|
|
74
73
|
*/
|
|
75
|
-
this.context = this.gl = this.getContextGL(this.
|
|
74
|
+
this.context = this.gl = this.getContextGL(this.getCanvas(), options.transparent);
|
|
76
75
|
|
|
77
76
|
/**
|
|
78
77
|
* Maximum number of texture unit supported under the current context
|
|
@@ -154,13 +153,13 @@ class WebGLRenderer extends Renderer {
|
|
|
154
153
|
// to simulate context lost and restore in WebGL:
|
|
155
154
|
// var ctx = me.video.renderer.context.getExtension('WEBGL_lose_context');
|
|
156
155
|
// ctx.loseContext()
|
|
157
|
-
this.
|
|
156
|
+
this.getCanvas().addEventListener("webglcontextlost", (e) => {
|
|
158
157
|
e.preventDefault();
|
|
159
158
|
this.isContextValid = false;
|
|
160
159
|
event.emit(event.ONCONTEXT_LOST, this);
|
|
161
160
|
}, false );
|
|
162
161
|
// ctx.restoreContext()
|
|
163
|
-
this.
|
|
162
|
+
this.getCanvas().addEventListener("webglcontextrestored", () => {
|
|
164
163
|
this.reset();
|
|
165
164
|
this.isContextValid = true;
|
|
166
165
|
event.emit(event.ONCONTEXT_RESTORED, this);
|
|
@@ -231,7 +230,7 @@ class WebGLRenderer extends Renderer {
|
|
|
231
230
|
*/
|
|
232
231
|
createFontTexture(cache) {
|
|
233
232
|
if (typeof this.fontTexture === "undefined") {
|
|
234
|
-
var canvas = this.
|
|
233
|
+
var canvas = this.getCanvas();
|
|
235
234
|
var width = canvas.width;
|
|
236
235
|
var height = canvas.height;
|
|
237
236
|
|
|
@@ -459,17 +458,6 @@ class WebGLRenderer extends Renderer {
|
|
|
459
458
|
this.currentCompositor.addQuad(pattern, x, y, width, height, uvs[0], uvs[1], uvs[2], uvs[3], this.currentTint.toUint32());
|
|
460
459
|
}
|
|
461
460
|
|
|
462
|
-
|
|
463
|
-
/**
|
|
464
|
-
* return a reference to the screen canvas corresponding WebGL Context
|
|
465
|
-
* @name getScreenContext
|
|
466
|
-
* @memberof WebGLRenderer
|
|
467
|
-
* @returns {WebGLRenderingContext}
|
|
468
|
-
*/
|
|
469
|
-
getScreenContext() {
|
|
470
|
-
return this.gl;
|
|
471
|
-
}
|
|
472
|
-
|
|
473
461
|
/**
|
|
474
462
|
* Returns the WebGL Context object of the given Canvas
|
|
475
463
|
* @name getContextGL
|
|
@@ -627,8 +615,8 @@ class WebGLRenderer extends Renderer {
|
|
|
627
615
|
this.gl.disable(this.gl.SCISSOR_TEST);
|
|
628
616
|
this.currentScissor[0] = 0;
|
|
629
617
|
this.currentScissor[1] = 0;
|
|
630
|
-
this.currentScissor[2] = this.
|
|
631
|
-
this.currentScissor[3] = this.
|
|
618
|
+
this.currentScissor[2] = this.getCanvas().width;
|
|
619
|
+
this.currentScissor[3] = this.getCanvas().height;
|
|
632
620
|
}
|
|
633
621
|
}
|
|
634
622
|
|
|
@@ -719,7 +707,7 @@ class WebGLRenderer extends Renderer {
|
|
|
719
707
|
* @param {number} width Line width
|
|
720
708
|
*/
|
|
721
709
|
setLineWidth(width) {
|
|
722
|
-
this.
|
|
710
|
+
this.getContext().lineWidth(width);
|
|
723
711
|
}
|
|
724
712
|
|
|
725
713
|
/**
|
|
@@ -1015,7 +1003,7 @@ class WebGLRenderer extends Renderer {
|
|
|
1015
1003
|
* @param {number} height
|
|
1016
1004
|
*/
|
|
1017
1005
|
clipRect(x, y, width, height) {
|
|
1018
|
-
var canvas = this.
|
|
1006
|
+
var canvas = this.getCanvas();
|
|
1019
1007
|
var gl = this.gl;
|
|
1020
1008
|
// if requested box is different from the current canvas size
|
|
1021
1009
|
if (x !== 0 || y !== 0 || width !== canvas.width || height !== canvas.height) {
|