melonjs 13.0.0 → 13.2.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/dist/melonjs.js +642 -583
- package/dist/melonjs.min.js +3 -3
- package/dist/melonjs.module.d.ts +286 -476
- package/dist/melonjs.module.js +629 -592
- package/package.json +7 -7
- package/src/geometries/point.js +80 -0
- package/src/index.js +4 -0
- package/src/input/pointerevent.js +2 -2
- package/src/lang/deprecated.js +27 -1
- package/src/level/tiled/TMXGroup.js +10 -0
- package/src/level/tiled/TMXLayer.js +9 -0
- package/src/level/tiled/TMXObject.js +33 -10
- package/src/level/tiled/TMXTileMap.js +12 -0
- package/src/level/tiled/TMXTileset.js +8 -0
- package/src/math/color.js +63 -43
- 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 +10 -3
- package/src/physics/bounds.js +10 -9
- package/src/polyfill/index.js +2 -2
- package/src/renderable/nineslicesprite.js +27 -1
- package/src/renderable/renderable.js +49 -135
- package/src/renderable/sprite.js +7 -1
- package/src/text/bitmaptext.js +8 -8
- package/src/text/text.js +1 -1
- package/src/text/textmetrics.js +1 -1
- package/src/video/canvas/canvas_renderer.js +51 -60
- package/src/video/renderer.js +27 -76
- package/src/video/texture/canvas_texture.js +4 -2
- package/src/video/video.js +13 -16
- package/src/video/webgl/glshader.js +0 -28
- package/src/video/webgl/webgl_compositor.js +21 -50
- package/src/video/webgl/webgl_renderer.js +44 -132
|
@@ -42,56 +42,38 @@ class GLShader {
|
|
|
42
42
|
|
|
43
43
|
/**
|
|
44
44
|
* the active gl rendering context
|
|
45
|
-
* @public
|
|
46
45
|
* @type {WebGLRenderingContext}
|
|
47
|
-
* @name gl
|
|
48
|
-
* @memberof GLShader
|
|
49
46
|
*/
|
|
50
47
|
this.gl = gl;
|
|
51
48
|
|
|
52
49
|
/**
|
|
53
50
|
* the vertex shader source code
|
|
54
|
-
* @public
|
|
55
51
|
* @type {string}
|
|
56
|
-
* @name vertex
|
|
57
|
-
* @memberof GLShader
|
|
58
52
|
*/
|
|
59
53
|
this.vertex = setPrecision(minify(vertex), precision || device.getMaxShaderPrecision(this.gl));
|
|
60
54
|
|
|
61
55
|
/**
|
|
62
56
|
* the fragment shader source code
|
|
63
|
-
* @public
|
|
64
57
|
* @type {string}
|
|
65
|
-
* @name vertex
|
|
66
|
-
* @memberof GLShader
|
|
67
58
|
*/
|
|
68
59
|
this.fragment = setPrecision(minify(fragment), precision || device.getMaxShaderPrecision(this.gl));
|
|
69
60
|
|
|
70
61
|
/**
|
|
71
62
|
* the location attributes of the shader
|
|
72
|
-
* @public
|
|
73
63
|
* @type {GLint[]}
|
|
74
|
-
* @name attributes
|
|
75
|
-
* @memberof GLShader
|
|
76
64
|
*/
|
|
77
65
|
this.attributes = extractAttributes(this.gl, this);
|
|
78
66
|
|
|
79
67
|
|
|
80
68
|
/**
|
|
81
69
|
* a reference to the shader program (once compiled)
|
|
82
|
-
* @public
|
|
83
70
|
* @type {WebGLProgram}
|
|
84
|
-
* @name program
|
|
85
|
-
* @memberof GLShader
|
|
86
71
|
*/
|
|
87
72
|
this.program = compileProgram(this.gl, this.vertex, this.fragment, this.attributes);
|
|
88
73
|
|
|
89
74
|
/**
|
|
90
75
|
* the uniforms of the shader
|
|
91
|
-
* @public
|
|
92
76
|
* @type {object}
|
|
93
|
-
* @name uniforms
|
|
94
|
-
* @memberof GLShader
|
|
95
77
|
*/
|
|
96
78
|
this.uniforms = extractUniforms(this.gl, this);
|
|
97
79
|
|
|
@@ -101,8 +83,6 @@ class GLShader {
|
|
|
101
83
|
|
|
102
84
|
/**
|
|
103
85
|
* Installs this shader program as part of current rendering state
|
|
104
|
-
* @name bind
|
|
105
|
-
* @memberof GLShader
|
|
106
86
|
*/
|
|
107
87
|
bind() {
|
|
108
88
|
this.gl.useProgram(this.program);
|
|
@@ -110,8 +90,6 @@ class GLShader {
|
|
|
110
90
|
|
|
111
91
|
/**
|
|
112
92
|
* returns the location of an attribute variable in this shader program
|
|
113
|
-
* @name getAttribLocation
|
|
114
|
-
* @memberof GLShader
|
|
115
93
|
* @param {string} name the name of the attribute variable whose location to get.
|
|
116
94
|
* @returns {GLint} number indicating the location of the variable name if found. Returns -1 otherwise
|
|
117
95
|
*/
|
|
@@ -126,8 +104,6 @@ class GLShader {
|
|
|
126
104
|
|
|
127
105
|
/**
|
|
128
106
|
* Set the uniform to the given value
|
|
129
|
-
* @name setUniform
|
|
130
|
-
* @memberof GLShader
|
|
131
107
|
* @param {string} name the uniform name
|
|
132
108
|
* @param {object|Float32Array} value the value to assign to that uniform
|
|
133
109
|
* @example
|
|
@@ -148,8 +124,6 @@ class GLShader {
|
|
|
148
124
|
|
|
149
125
|
/**
|
|
150
126
|
* activate the given vertex attribute for this shader
|
|
151
|
-
* @name setVertexAttributes
|
|
152
|
-
* @memberof GLShader
|
|
153
127
|
* @param {WebGLRenderingContext} gl the current WebGL rendering context
|
|
154
128
|
* @param {object[]} attributes an array of vertex attributes
|
|
155
129
|
* @param {number} vertexByteSize the size of a single vertex in bytes
|
|
@@ -171,8 +145,6 @@ class GLShader {
|
|
|
171
145
|
|
|
172
146
|
/**
|
|
173
147
|
* destroy this shader objects resources (program, attributes, uniforms)
|
|
174
|
-
* @name destroy
|
|
175
|
-
* @memberof GLShader
|
|
176
148
|
*/
|
|
177
149
|
destroy() {
|
|
178
150
|
this.uniforms = null;
|
|
@@ -56,44 +56,37 @@ class WebGLCompositor {
|
|
|
56
56
|
|
|
57
57
|
/**
|
|
58
58
|
* a reference to the active WebGL shader
|
|
59
|
-
* @name activeShader
|
|
60
|
-
* @memberof WebGLCompositor
|
|
61
59
|
* @type {GLShader}
|
|
62
60
|
*/
|
|
63
61
|
this.activeShader = null;
|
|
64
62
|
|
|
65
63
|
/**
|
|
66
64
|
* primitive type to render (gl.POINTS, gl.LINE_STRIP, gl.LINE_LOOP, gl.LINES, gl.TRIANGLE_STRIP, gl.TRIANGLE_FAN, gl.TRIANGLES)
|
|
67
|
-
* @
|
|
68
|
-
* @see WebGLCompositor
|
|
69
|
-
* @memberof WebGLCompositor
|
|
65
|
+
* @type {number}
|
|
70
66
|
* @default gl.TRIANGLES
|
|
71
67
|
*/
|
|
72
68
|
this.mode = gl.TRIANGLES;
|
|
73
69
|
|
|
74
70
|
/**
|
|
75
71
|
* an array of vertex attribute properties
|
|
76
|
-
* @name attributes
|
|
77
72
|
* @see WebGLCompositor.addAttribute
|
|
78
|
-
* @
|
|
73
|
+
* @type {Array}
|
|
79
74
|
*/
|
|
80
75
|
this.attributes = [];
|
|
81
76
|
|
|
82
77
|
/**
|
|
83
78
|
* the size of a single vertex in bytes
|
|
84
79
|
* (will automatically be calculated as attributes definitions are added)
|
|
85
|
-
* @name vertexByteSize
|
|
86
80
|
* @see WebGLCompositor.addAttribute
|
|
87
|
-
* @
|
|
81
|
+
* @type {number}
|
|
88
82
|
*/
|
|
89
83
|
this.vertexByteSize = 0;
|
|
90
84
|
|
|
91
85
|
/**
|
|
92
86
|
* the size of a single vertex in floats
|
|
93
87
|
* (will automatically be calculated as attributes definitions are added)
|
|
94
|
-
* @name vertexSize
|
|
95
88
|
* @see WebGLCompositor.addAttribute
|
|
96
|
-
* @
|
|
89
|
+
* @type {number}
|
|
97
90
|
*/
|
|
98
91
|
this.vertexSize = 0;
|
|
99
92
|
|
|
@@ -132,8 +125,8 @@ class WebGLCompositor {
|
|
|
132
125
|
// initial viewport size
|
|
133
126
|
this.setViewport(
|
|
134
127
|
0, 0,
|
|
135
|
-
this.renderer.
|
|
136
|
-
this.renderer.
|
|
128
|
+
this.renderer.getCanvas().width,
|
|
129
|
+
this.renderer.getCanvas().height
|
|
137
130
|
);
|
|
138
131
|
|
|
139
132
|
// Initialize clear color
|
|
@@ -154,8 +147,6 @@ class WebGLCompositor {
|
|
|
154
147
|
|
|
155
148
|
/**
|
|
156
149
|
* add vertex attribute property definition to the compositor
|
|
157
|
-
* @name addAttribute
|
|
158
|
-
* @memberof WebGLCompositor
|
|
159
150
|
* @param {string} name name of the attribute in the vertex shader
|
|
160
151
|
* @param {number} size number of components per vertex attribute. Must be 1, 2, 3, or 4.
|
|
161
152
|
* @param {GLenum} type data type of each component in the array
|
|
@@ -201,8 +192,6 @@ class WebGLCompositor {
|
|
|
201
192
|
|
|
202
193
|
/**
|
|
203
194
|
* Sets the viewport
|
|
204
|
-
* @name setViewport
|
|
205
|
-
* @memberof WebGLCompositor
|
|
206
195
|
* @param {number} x x position of viewport
|
|
207
196
|
* @param {number} y y position of viewport
|
|
208
197
|
* @param {number} w width of viewport
|
|
@@ -214,8 +203,6 @@ class WebGLCompositor {
|
|
|
214
203
|
|
|
215
204
|
/**
|
|
216
205
|
* Create a WebGL texture from an image
|
|
217
|
-
* @name createTexture2D
|
|
218
|
-
* @memberof WebGLCompositor
|
|
219
206
|
* @param {number} unit Destination texture unit
|
|
220
207
|
* @param {Image|HTMLCanvasElement|ImageData|Uint8Array[]|Float32Array[]} image Source image
|
|
221
208
|
* @param {number} filter gl.LINEAR or gl.NEAREST
|
|
@@ -258,8 +245,6 @@ class WebGLCompositor {
|
|
|
258
245
|
|
|
259
246
|
/**
|
|
260
247
|
* delete the given WebGL texture
|
|
261
|
-
* @name bindTexture2D
|
|
262
|
-
* @memberof WebGLCompositor
|
|
263
248
|
* @param {WebGLTexture} [texture] a WebGL texture to delete
|
|
264
249
|
* @param {number} [unit] Texture unit to delete
|
|
265
250
|
*/
|
|
@@ -270,8 +255,6 @@ class WebGLCompositor {
|
|
|
270
255
|
|
|
271
256
|
/**
|
|
272
257
|
* returns the WebGL texture associated to the given texture unit
|
|
273
|
-
* @name bindTexture2D
|
|
274
|
-
* @memberof WebGLCompositor
|
|
275
258
|
* @param {number} unit Texture unit to which a texture is bound
|
|
276
259
|
* @returns {WebGLTexture} texture a WebGL texture
|
|
277
260
|
*/
|
|
@@ -281,8 +264,6 @@ class WebGLCompositor {
|
|
|
281
264
|
|
|
282
265
|
/**
|
|
283
266
|
* assign the given WebGL texture to the current batch
|
|
284
|
-
* @name bindTexture2D
|
|
285
|
-
* @memberof WebGLCompositor
|
|
286
267
|
* @param {WebGLTexture} texture a WebGL texture
|
|
287
268
|
* @param {number} unit Texture unit to which the given texture is bound
|
|
288
269
|
*/
|
|
@@ -308,8 +289,6 @@ class WebGLCompositor {
|
|
|
308
289
|
|
|
309
290
|
/**
|
|
310
291
|
* unbind the given WebGL texture, forcing it to be reuploaded
|
|
311
|
-
* @name unbindTexture2D
|
|
312
|
-
* @memberof WebGLCompositor
|
|
313
292
|
* @param {WebGLTexture} [texture] a WebGL texture
|
|
314
293
|
* @param {number} [unit] a WebGL texture
|
|
315
294
|
* @returns {number} unit the unit number that was associated with the given texture
|
|
@@ -354,8 +333,6 @@ class WebGLCompositor {
|
|
|
354
333
|
|
|
355
334
|
/**
|
|
356
335
|
* set/change the current projection matrix
|
|
357
|
-
* @name setProjection
|
|
358
|
-
* @memberof WebGLCompositor
|
|
359
336
|
* @param {Matrix3d} matrix
|
|
360
337
|
*/
|
|
361
338
|
setProjection(matrix) {
|
|
@@ -364,9 +341,7 @@ class WebGLCompositor {
|
|
|
364
341
|
|
|
365
342
|
/**
|
|
366
343
|
* Select the shader to use for compositing
|
|
367
|
-
* @name useShader
|
|
368
344
|
* @see GLShader
|
|
369
|
-
* @memberof WebGLCompositor
|
|
370
345
|
* @param {GLShader} shader a reference to a GLShader instance
|
|
371
346
|
*/
|
|
372
347
|
useShader(shader) {
|
|
@@ -381,8 +356,6 @@ class WebGLCompositor {
|
|
|
381
356
|
|
|
382
357
|
/**
|
|
383
358
|
* Add a textured quad
|
|
384
|
-
* @name addQuad
|
|
385
|
-
* @memberof WebGLCompositor
|
|
386
359
|
* @param {TextureAtlas} texture Source texture atlas
|
|
387
360
|
* @param {number} x Destination x-coordinate
|
|
388
361
|
* @param {number} y Destination y-coordinate
|
|
@@ -438,7 +411,6 @@ class WebGLCompositor {
|
|
|
438
411
|
/**
|
|
439
412
|
* Flush batched texture operations to the GPU
|
|
440
413
|
* @param {number} [mode=gl.TRIANGLES] the GL drawing mode
|
|
441
|
-
* @memberof WebGLCompositor
|
|
442
414
|
*/
|
|
443
415
|
flush(mode = this.mode) {
|
|
444
416
|
var vertex = this.vertexBuffer;
|
|
@@ -464,8 +436,6 @@ class WebGLCompositor {
|
|
|
464
436
|
|
|
465
437
|
/**
|
|
466
438
|
* Draw an array of vertices
|
|
467
|
-
* @name drawVertices
|
|
468
|
-
* @memberof WebGLCompositor
|
|
469
439
|
* @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)
|
|
470
440
|
* @param {Vector2d[]} verts vertices
|
|
471
441
|
* @param {number} [vertexCount=verts.length] amount of points defined in the points array
|
|
@@ -492,25 +462,26 @@ class WebGLCompositor {
|
|
|
492
462
|
}
|
|
493
463
|
|
|
494
464
|
/**
|
|
495
|
-
*
|
|
496
|
-
* @
|
|
497
|
-
* @memberof WebGLCompositor
|
|
498
|
-
* @param {number} [r=0] - the red color value used when the color buffers are cleared
|
|
499
|
-
* @param {number} [g=0] - the green color value used when the color buffers are cleared
|
|
500
|
-
* @param {number} [b=0] - the blue color value used when the color buffers are cleared
|
|
501
|
-
* @param {number} [a=0] - the alpha color value used when the color buffers are cleared
|
|
465
|
+
* Clear the frame buffer
|
|
466
|
+
* @param {number} [alpha = 0.0] - the alpha value used when clearing the framebuffer
|
|
502
467
|
*/
|
|
503
|
-
|
|
504
|
-
this.gl
|
|
468
|
+
clear(alpha = 0) {
|
|
469
|
+
var gl = this.gl;
|
|
470
|
+
gl.clearColor(0, 0, 0, alpha);
|
|
471
|
+
gl.clear(gl.COLOR_BUFFER_BIT | gl.STENCIL_BUFFER_BIT);
|
|
505
472
|
}
|
|
506
473
|
|
|
507
474
|
/**
|
|
508
|
-
*
|
|
509
|
-
* @
|
|
510
|
-
* @
|
|
475
|
+
* Specify the color values used when clearing color buffers. The values are clamped between 0 and 1.
|
|
476
|
+
* @param {number} [r = 0] - the red color value used when the color buffers are cleared
|
|
477
|
+
* @param {number} [g = 0] - the green color value used when the color buffers are cleared
|
|
478
|
+
* @param {number} [b = 0] - the blue color value used when the color buffers are cleared
|
|
479
|
+
* @param {number} [a = 0] - the alpha color value used when the color buffers are cleared
|
|
511
480
|
*/
|
|
512
|
-
|
|
513
|
-
|
|
481
|
+
clearColor(r = 0, g = 0, b = 0, a = 0) {
|
|
482
|
+
var gl = this.gl;
|
|
483
|
+
gl.clearColor(r, g, b, a);
|
|
484
|
+
gl.clear(gl.COLOR_BUFFER_BIT);
|
|
514
485
|
}
|
|
515
486
|
};
|
|
516
487
|
|