melonjs 14.4.0 → 15.0.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 +13 -57
- package/dist/melonjs.mjs/_virtual/_commonjsHelpers.js +1 -1
- package/dist/melonjs.mjs/_virtual/arraymultimap.js +1 -1
- package/dist/melonjs.mjs/_virtual/earcut.js +1 -1
- package/dist/melonjs.mjs/_virtual/howler.js +1 -1
- package/dist/melonjs.mjs/_virtual/index.js +1 -1
- package/dist/melonjs.mjs/_virtual/index2.js +1 -1
- package/dist/melonjs.mjs/_virtual/multimap.js +1 -1
- package/dist/melonjs.mjs/_virtual/setmultimap.js +1 -1
- package/dist/melonjs.mjs/application/application.js +1 -1
- package/dist/melonjs.mjs/application/header.js +1 -1
- package/dist/melonjs.mjs/application/resize.js +1 -1
- package/dist/melonjs.mjs/application/settings.js +1 -1
- package/dist/melonjs.mjs/audio/audio.js +5 -7
- package/dist/melonjs.mjs/camera/camera2d.js +1 -1
- package/dist/melonjs.mjs/const.js +1 -1
- package/dist/melonjs.mjs/entity/entity.js +43 -9
- package/dist/melonjs.mjs/geometries/ellipse.js +2 -3
- package/dist/melonjs.mjs/geometries/line.js +1 -1
- package/dist/melonjs.mjs/geometries/path2d.js +20 -44
- package/dist/melonjs.mjs/geometries/point.js +1 -6
- package/dist/melonjs.mjs/geometries/poly.js +2 -5
- package/dist/melonjs.mjs/geometries/rectangle.js +13 -9
- package/dist/melonjs.mjs/geometries/roundrect.js +1 -1
- package/dist/melonjs.mjs/index.js +10 -6
- package/dist/melonjs.mjs/input/gamepad.js +10 -16
- package/dist/melonjs.mjs/input/input.js +1 -1
- package/dist/melonjs.mjs/input/keyboard.js +1 -1
- package/dist/melonjs.mjs/input/pointer.js +1 -1
- package/dist/melonjs.mjs/input/pointerevent.js +3 -17
- package/dist/melonjs.mjs/lang/console.js +1 -1
- package/dist/melonjs.mjs/lang/deprecated.js +1 -1
- package/dist/melonjs.mjs/level/level.js +3 -3
- package/dist/melonjs.mjs/level/tiled/TMXGroup.js +1 -1
- package/dist/melonjs.mjs/level/tiled/TMXLayer.js +1 -8
- package/dist/melonjs.mjs/level/tiled/TMXObject.js +1 -1
- package/dist/melonjs.mjs/level/tiled/TMXTile.js +1 -1
- package/dist/melonjs.mjs/level/tiled/TMXTileMap.js +8 -4
- package/dist/melonjs.mjs/level/tiled/TMXTileset.js +5 -5
- package/dist/melonjs.mjs/level/tiled/TMXTilesetGroup.js +1 -1
- package/dist/melonjs.mjs/level/tiled/TMXUtils.js +1 -1
- package/dist/melonjs.mjs/level/tiled/constants.js +1 -1
- package/dist/melonjs.mjs/level/tiled/renderer/TMXHexagonalRenderer.js +1 -1
- package/dist/melonjs.mjs/level/tiled/renderer/TMXIsometricRenderer.js +1 -1
- package/dist/melonjs.mjs/level/tiled/renderer/TMXOrthogonalRenderer.js +1 -1
- package/dist/melonjs.mjs/level/tiled/renderer/TMXRenderer.js +1 -1
- package/dist/melonjs.mjs/level/tiled/renderer/TMXStaggeredRenderer.js +1 -1
- package/dist/melonjs.mjs/level/tiled/renderer/autodetect.js +1 -1
- package/dist/melonjs.mjs/loader/cache.js +24 -0
- package/dist/melonjs.mjs/loader/loader.js +331 -716
- package/dist/melonjs.mjs/loader/loadingscreen.js +4 -4
- package/dist/melonjs.mjs/loader/melonjs_logo.png.js +1 -1
- package/dist/melonjs.mjs/loader/parser.js +281 -0
- package/dist/melonjs.mjs/loader/settings.js +91 -0
- package/dist/melonjs.mjs/math/color.js +9 -8
- package/dist/melonjs.mjs/math/math.js +1 -1
- package/dist/melonjs.mjs/math/matrix2.js +7 -9
- package/dist/melonjs.mjs/math/matrix3.js +18 -21
- package/dist/melonjs.mjs/math/observable_vector2.js +3 -3
- package/dist/melonjs.mjs/math/observable_vector3.js +3 -4
- package/dist/melonjs.mjs/math/vector2.js +3 -3
- package/dist/melonjs.mjs/math/vector3.js +3 -4
- package/dist/melonjs.mjs/node_modules/@teppeis/multimaps/dist/src/arraymultimap.js +1 -1
- package/dist/melonjs.mjs/node_modules/@teppeis/multimaps/dist/src/index.js +1 -1
- package/dist/melonjs.mjs/node_modules/@teppeis/multimaps/dist/src/multimap.js +1 -1
- package/dist/melonjs.mjs/node_modules/@teppeis/multimaps/dist/src/setmultimap.js +1 -1
- package/dist/melonjs.mjs/node_modules/earcut/src/earcut.js +1 -1
- package/dist/melonjs.mjs/node_modules/eventemitter3/index.js +1 -1
- package/dist/melonjs.mjs/node_modules/eventemitter3/index2.js +1 -1
- package/dist/melonjs.mjs/node_modules/howler/dist/howler.js +1 -1
- package/dist/melonjs.mjs/particles/emitter.js +3 -3
- package/dist/melonjs.mjs/particles/particle.js +1 -1
- package/dist/melonjs.mjs/particles/settings.js +1 -1
- package/dist/melonjs.mjs/physics/body.js +18 -14
- package/dist/melonjs.mjs/physics/bounds.js +18 -70
- package/dist/melonjs.mjs/physics/collision.js +1 -1
- package/dist/melonjs.mjs/physics/detector.js +1 -1
- package/dist/melonjs.mjs/physics/quadtree.js +1 -1
- package/dist/melonjs.mjs/physics/response.js +1 -1
- package/dist/melonjs.mjs/physics/sat.js +1 -1
- package/dist/melonjs.mjs/physics/world.js +1 -1
- package/dist/melonjs.mjs/plugin/plugin.js +3 -3
- package/dist/melonjs.mjs/renderable/collectable.js +1 -1
- package/dist/melonjs.mjs/renderable/colorlayer.js +1 -1
- package/dist/melonjs.mjs/renderable/container.js +25 -19
- package/dist/melonjs.mjs/renderable/dragndrop.js +1 -1
- package/dist/melonjs.mjs/renderable/imagelayer.js +7 -1
- package/dist/melonjs.mjs/renderable/light2d.js +1 -1
- package/dist/melonjs.mjs/renderable/nineslicesprite.js +1 -1
- package/dist/melonjs.mjs/renderable/renderable.js +148 -105
- package/dist/melonjs.mjs/renderable/sprite.js +33 -54
- package/dist/melonjs.mjs/renderable/trigger.js +1 -1
- package/dist/melonjs.mjs/renderable/ui/uibaseelement.js +1 -1
- package/dist/melonjs.mjs/renderable/ui/uispriteelement.js +1 -1
- package/dist/melonjs.mjs/renderable/ui/uitextbutton.js +1 -3
- package/dist/melonjs.mjs/state/stage.js +1 -1
- package/dist/melonjs.mjs/state/state.js +2 -2
- package/dist/melonjs.mjs/system/device.js +2 -2
- package/dist/melonjs.mjs/system/dom.js +1 -1
- package/dist/melonjs.mjs/system/event.js +1 -1
- package/dist/melonjs.mjs/system/platform.js +1 -1
- package/dist/melonjs.mjs/system/pooling.js +8 -18
- package/dist/melonjs.mjs/system/save.js +1 -1
- package/dist/melonjs.mjs/system/timer.js +1 -1
- package/dist/melonjs.mjs/text/bitmaptext.js +66 -8
- package/dist/melonjs.mjs/text/bitmaptextdata.js +1 -1
- package/dist/melonjs.mjs/text/glyph.js +1 -1
- package/dist/melonjs.mjs/text/text.js +56 -86
- package/dist/melonjs.mjs/text/textmetrics.js +1 -1
- package/dist/melonjs.mjs/text/textstyle.js +4 -6
- package/dist/melonjs.mjs/tweens/easing.js +1 -1
- package/dist/melonjs.mjs/tweens/interpolation.js +1 -1
- package/dist/melonjs.mjs/tweens/tween.js +1 -1
- package/dist/melonjs.mjs/utils/agent.js +1 -1
- package/dist/melonjs.mjs/utils/array.js +1 -1
- package/dist/melonjs.mjs/utils/file.js +1 -1
- package/dist/melonjs.mjs/utils/function.js +1 -1
- package/dist/melonjs.mjs/utils/string.js +2 -2
- package/dist/melonjs.mjs/utils/utils.js +2 -4
- package/dist/melonjs.mjs/video/canvas/canvas_renderer.js +7 -11
- package/dist/melonjs.mjs/video/renderer.js +2 -13
- package/dist/melonjs.mjs/video/texture/atlas.js +12 -17
- package/dist/melonjs.mjs/video/texture/cache.js +3 -3
- package/dist/melonjs.mjs/video/texture/canvas_texture.js +1 -1
- package/dist/melonjs.mjs/video/utils/autodetect.js +1 -1
- package/dist/melonjs.mjs/video/video.js +2 -2
- package/dist/melonjs.mjs/video/webgl/buffer/vertex.js +21 -17
- package/dist/melonjs.mjs/video/webgl/compositors/compositor.js +235 -0
- package/dist/melonjs.mjs/video/webgl/compositors/primitive_compositor.js +77 -0
- package/dist/melonjs.mjs/video/webgl/compositors/quad_compositor.js +249 -0
- package/dist/melonjs.mjs/video/webgl/{webgl_compositor.js → compositors/webgl_compositor.js} +20 -205
- package/dist/melonjs.mjs/video/webgl/glshader.js +1 -1
- package/dist/melonjs.mjs/video/webgl/shaders/primitive.frag.js +1 -1
- package/dist/melonjs.mjs/video/webgl/shaders/primitive.vert.js +2 -2
- package/dist/melonjs.mjs/video/webgl/shaders/quad.frag.js +1 -1
- package/dist/melonjs.mjs/video/webgl/shaders/quad.vert.js +2 -2
- package/dist/melonjs.mjs/video/webgl/utils/attributes.js +1 -1
- package/dist/melonjs.mjs/video/webgl/utils/precision.js +1 -1
- package/dist/melonjs.mjs/video/webgl/utils/program.js +1 -1
- package/dist/melonjs.mjs/video/webgl/utils/string.js +1 -1
- package/dist/melonjs.mjs/video/webgl/utils/uniforms.js +1 -1
- package/dist/melonjs.mjs/video/webgl/webgl_renderer.js +139 -149
- package/dist/melonjs.module.js +26320 -26376
- package/dist/types/entity/entity.d.ts +3 -3
- package/dist/types/geometries/path2d.d.ts +5 -31
- package/dist/types/geometries/point.d.ts +2 -7
- package/dist/types/geometries/poly.d.ts +0 -1
- package/dist/types/index.d.ts +5 -3
- package/dist/types/loader/cache.d.ts +7 -0
- package/dist/types/loader/loader.d.ts +166 -181
- package/dist/types/loader/parser.d.ts +41 -0
- package/dist/types/loader/settings.d.ts +57 -0
- package/dist/types/particles/emitter.d.ts +4 -4
- package/dist/types/physics/bounds.d.ts +29 -84
- package/dist/types/renderable/container.d.ts +0 -11
- package/dist/types/renderable/renderable.d.ts +43 -31
- package/dist/types/renderable/sprite.d.ts +3 -3
- package/dist/types/renderable/ui/uitextbutton.d.ts +0 -1
- package/dist/types/state/state.d.ts +1 -1
- package/dist/types/system/pooling.d.ts +2 -2
- package/dist/types/text/text.d.ts +6 -20
- package/dist/types/text/textstyle.d.ts +1 -1
- package/dist/types/video/canvas/canvas_renderer.d.ts +0 -5
- package/dist/types/video/renderer.d.ts +1 -5
- package/dist/types/video/webgl/buffer/vertex.d.ts +3 -3
- package/dist/types/video/webgl/compositors/compositor.d.ts +107 -0
- package/dist/types/video/webgl/compositors/primitive_compositor.d.ts +22 -0
- package/dist/types/video/webgl/compositors/quad_compositor.d.ts +72 -0
- package/dist/types/video/webgl/compositors/webgl_compositor.d.ts +86 -0
- package/dist/types/video/webgl/webgl_compositor.d.ts +2 -3
- package/dist/types/video/webgl/webgl_renderer.d.ts +34 -28
- package/package.json +18 -18
- package/src/audio/audio.js +4 -6
- package/src/entity/entity.js +42 -8
- package/src/geometries/ellipse.js +1 -2
- package/src/geometries/path2d.js +19 -43
- package/src/geometries/point.js +0 -5
- package/src/geometries/poly.js +1 -4
- package/src/geometries/rectangle.js +12 -8
- package/src/index.js +7 -3
- package/src/input/gamepad.js +9 -15
- package/src/input/pointerevent.js +1 -15
- package/src/level/level.js +2 -2
- package/src/level/tiled/TMXLayer.js +0 -7
- package/src/level/tiled/TMXTileMap.js +7 -3
- package/src/level/tiled/TMXTileset.js +4 -4
- package/src/loader/cache.js +16 -0
- package/src/loader/loader.js +339 -711
- package/src/loader/loadingscreen.js +3 -3
- package/src/loader/parser.js +279 -0
- package/src/loader/settings.js +85 -0
- package/src/math/color.js +8 -7
- package/src/math/matrix2.js +6 -8
- package/src/math/matrix3.js +17 -20
- package/src/math/observable_vector2.js +2 -2
- package/src/math/observable_vector3.js +2 -3
- package/src/math/vector2.js +2 -2
- package/src/math/vector3.js +2 -3
- package/src/particles/emitter.js +2 -2
- package/src/physics/body.js +17 -13
- package/src/physics/bounds.js +17 -69
- package/src/polyfill/index.js +0 -2
- package/src/renderable/container.js +24 -18
- package/src/renderable/imagelayer.js +6 -0
- package/src/renderable/renderable.js +147 -104
- package/src/renderable/sprite.js +32 -53
- package/src/renderable/ui/uitextbutton.js +0 -2
- package/src/state/state.js +1 -1
- package/src/system/device.js +1 -1
- package/src/system/pooling.js +7 -17
- package/src/text/bitmaptext.js +65 -7
- package/src/text/text.js +55 -85
- package/src/text/textstyle.js +3 -5
- package/src/utils/string.js +1 -1
- package/src/utils/utils.js +1 -3
- package/src/video/canvas/canvas_renderer.js +5 -9
- package/src/video/renderer.js +0 -11
- package/src/video/texture/atlas.js +11 -16
- package/src/video/texture/cache.js +2 -2
- package/src/video/video.js +1 -1
- package/src/video/webgl/buffer/vertex.js +20 -16
- package/src/video/webgl/compositors/compositor.js +226 -0
- package/src/video/webgl/compositors/primitive_compositor.js +68 -0
- package/src/video/webgl/compositors/quad_compositor.js +240 -0
- package/src/video/webgl/shaders/primitive.vert +2 -5
- package/src/video/webgl/shaders/quad.vert +3 -1
- package/src/video/webgl/webgl_renderer.js +137 -147
- package/dist/melonjs.mjs/_virtual/make-built-in.js +0 -10
- package/dist/melonjs.mjs/_virtual/object-define-property.js +0 -10
- package/dist/melonjs.mjs/_virtual/object-get-own-property-descriptor.js +0 -10
- package/dist/melonjs.mjs/_virtual/object-get-own-property-names.js +0 -10
- package/dist/melonjs.mjs/_virtual/object-get-own-property-symbols.js +0 -10
- package/dist/melonjs.mjs/_virtual/object-property-is-enumerable.js +0 -10
- package/dist/melonjs.mjs/_virtual/shared.js +0 -10
- package/dist/melonjs.mjs/game.js +0 -29
- package/dist/melonjs.mjs/polyfill/console.js +0 -18
- package/dist/melonjs.mjs/polyfill/performance.js +0 -27
- package/dist/melonjs.mjs/polyfill/requestAnimationFrame.js +0 -46
- package/dist/melonjs.mjs/polyfill/roundrect.js +0 -242
- package/dist/melonjs.mjs/renderable/re_container.js +0 -1016
- package/dist/melonjs.mjs/video/utils/resize.js +0 -116
- package/src/polyfill/performance.js +0 -20
- package/src/polyfill/requestAnimationFrame.js +0 -39
- package/src/video/webgl/webgl_compositor.js +0 -486
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* melonJS Game Engine - v15.0.0
|
|
3
|
+
* http://www.melonjs.org
|
|
4
|
+
* melonjs is licensed under the MIT License.
|
|
5
|
+
* http://www.opensource.org/licenses/mit-license
|
|
6
|
+
* @copyright (C) 2011 - 2023 Olivier Biot (AltByte Pte Ltd)
|
|
7
|
+
*/
|
|
8
|
+
import Vector2d from '../../../math/vector2.js';
|
|
9
|
+
import { isPowerOfTwo } from '../../../math/math.js';
|
|
10
|
+
import quadVertex from '../shaders/quad.vert.js';
|
|
11
|
+
import quadFragment from '../shaders/quad.frag.js';
|
|
12
|
+
import Compositor from './compositor.js';
|
|
13
|
+
|
|
14
|
+
// a pool of resuable vectors
|
|
15
|
+
var V_ARRAY = [
|
|
16
|
+
new Vector2d(),
|
|
17
|
+
new Vector2d(),
|
|
18
|
+
new Vector2d(),
|
|
19
|
+
new Vector2d()
|
|
20
|
+
];
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* @classdesc
|
|
24
|
+
* A WebGL Compositor object. This class handles all of the WebGL state<br>
|
|
25
|
+
* Pushes texture regions or shape geometry into WebGL buffers, automatically flushes to GPU
|
|
26
|
+
* @augments Compositor
|
|
27
|
+
*/
|
|
28
|
+
class QuadCompositor extends Compositor {
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Initialize the compositor
|
|
32
|
+
* @ignore
|
|
33
|
+
*/
|
|
34
|
+
init (renderer) {
|
|
35
|
+
super.init(renderer, {
|
|
36
|
+
attributes: [
|
|
37
|
+
{name: "aVertex", size: 2, type: renderer.gl.FLOAT, normalized: false, offset: 0 * Float32Array.BYTES_PER_ELEMENT},
|
|
38
|
+
{name: "aRegion", size: 2, type: renderer.gl.FLOAT, normalized: false, offset: 2 * Float32Array.BYTES_PER_ELEMENT},
|
|
39
|
+
{name: "aColor", size: 4, type: renderer.gl.UNSIGNED_BYTE, normalized: true, offset: 4 * Float32Array.BYTES_PER_ELEMENT}
|
|
40
|
+
],
|
|
41
|
+
shader: {
|
|
42
|
+
vertex: quadVertex, fragment: quadFragment
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
// list of active texture units
|
|
47
|
+
this.currentTextureUnit = -1;
|
|
48
|
+
this.boundTextures = [];
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Reset compositor internal state
|
|
53
|
+
* @ignore
|
|
54
|
+
*/
|
|
55
|
+
reset() {
|
|
56
|
+
super.reset();
|
|
57
|
+
|
|
58
|
+
// delete all related bound texture
|
|
59
|
+
for (var i = 0; i < this.renderer.maxTextures; i++) {
|
|
60
|
+
var texture2D = this.getTexture2D(i);
|
|
61
|
+
if (typeof texture2D !== "undefined") {
|
|
62
|
+
this.deleteTexture2D(texture2D);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
this.currentTextureUnit = -1;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Create a WebGL texture from an image
|
|
70
|
+
* @param {number} unit - Destination texture unit
|
|
71
|
+
* @param {Image|HTMLCanvasElement|ImageData|Uint8Array[]|Float32Array[]} [pixels=null] - Source image
|
|
72
|
+
* @param {number} filter - gl.LINEAR or gl.NEAREST
|
|
73
|
+
* @param {string} [repeat="no-repeat"] - Image repeat behavior (see {@link ImageLayer#repeat})
|
|
74
|
+
* @param {number} [w=pixels.width] - Source image width (Only use with UInt8Array[] or Float32Array[] source image)
|
|
75
|
+
* @param {number} [h=pixels.height] - Source image height (Only use with UInt8Array[] or Float32Array[] source image)
|
|
76
|
+
* @param {boolean} [premultipliedAlpha=true] - Multiplies the alpha channel into the other color channels
|
|
77
|
+
* @param {boolean} [mipmap=true] - Whether mipmap levels should be generated for this texture
|
|
78
|
+
* @returns {WebGLTexture} a WebGL texture
|
|
79
|
+
*/
|
|
80
|
+
createTexture2D(unit, pixels = null, filter, repeat = "no-repeat", w = pixels.width, h = pixels.height, premultipliedAlpha = true, mipmap = true) {
|
|
81
|
+
var gl = this.gl;
|
|
82
|
+
var isPOT = isPowerOfTwo(w) && isPowerOfTwo(h);
|
|
83
|
+
var rs = (repeat.search(/^repeat(-x)?$/) === 0) && (isPOT || this.renderer.WebGLVersion > 1) ? gl.REPEAT : gl.CLAMP_TO_EDGE;
|
|
84
|
+
var rt = (repeat.search(/^repeat(-y)?$/) === 0) && (isPOT || this.renderer.WebGLVersion > 1) ? gl.REPEAT : gl.CLAMP_TO_EDGE;
|
|
85
|
+
|
|
86
|
+
var texture = gl.createTexture();
|
|
87
|
+
|
|
88
|
+
this.bindTexture2D(texture, unit);
|
|
89
|
+
|
|
90
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, rs);
|
|
91
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, rt);
|
|
92
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, filter);
|
|
93
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, filter);
|
|
94
|
+
|
|
95
|
+
gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, premultipliedAlpha);
|
|
96
|
+
|
|
97
|
+
if (pixels === null || typeof pixels.byteLength !== "undefined") {
|
|
98
|
+
// if pixels is undefined, or if it's Uint8Array/Float32Array TypedArray
|
|
99
|
+
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, w, h, 0, gl.RGBA, gl.UNSIGNED_BYTE, pixels, 0);
|
|
100
|
+
} else {
|
|
101
|
+
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, pixels);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
// generate the sprite mimap (used when scaling) if a PowerOfTwo texture
|
|
105
|
+
if (isPOT && mipmap === true) {
|
|
106
|
+
gl.generateMipmap(gl.TEXTURE_2D);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
return texture;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* delete the given WebGL texture
|
|
114
|
+
* @param {WebGLTexture} [texture] - a WebGL texture to delete
|
|
115
|
+
* @param {number} [unit] - Texture unit to delete
|
|
116
|
+
*/
|
|
117
|
+
deleteTexture2D(texture) {
|
|
118
|
+
this.gl.deleteTexture(texture);
|
|
119
|
+
this.unbindTexture2D(texture);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* returns the WebGL texture associated to the given texture unit
|
|
124
|
+
* @param {number} unit - Texture unit to which a texture is bound
|
|
125
|
+
* @returns {WebGLTexture} texture a WebGL texture
|
|
126
|
+
*/
|
|
127
|
+
getTexture2D(unit) {
|
|
128
|
+
return this.boundTextures[unit];
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* assign the given WebGL texture to the current batch
|
|
133
|
+
* @param {WebGLTexture} texture - a WebGL texture
|
|
134
|
+
* @param {number} unit - Texture unit to which the given texture is bound
|
|
135
|
+
*/
|
|
136
|
+
bindTexture2D(texture, unit) {
|
|
137
|
+
var gl = this.gl;
|
|
138
|
+
|
|
139
|
+
if (texture !== this.boundTextures[unit]) {
|
|
140
|
+
this.flush();
|
|
141
|
+
if (this.currentTextureUnit !== unit) {
|
|
142
|
+
this.currentTextureUnit = unit;
|
|
143
|
+
gl.activeTexture(gl.TEXTURE0 + unit);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
gl.bindTexture(gl.TEXTURE_2D, texture);
|
|
147
|
+
this.boundTextures[unit] = texture;
|
|
148
|
+
|
|
149
|
+
} else if (this.currentTextureUnit !== unit) {
|
|
150
|
+
this.flush();
|
|
151
|
+
this.currentTextureUnit = unit;
|
|
152
|
+
gl.activeTexture(gl.TEXTURE0 + unit);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* unbind the given WebGL texture, forcing it to be reuploaded
|
|
158
|
+
* @param {WebGLTexture} [texture] - a WebGL texture
|
|
159
|
+
* @param {number} [unit] - a WebGL texture
|
|
160
|
+
* @returns {number} unit the unit number that was associated with the given texture
|
|
161
|
+
*/
|
|
162
|
+
unbindTexture2D(texture, unit) {
|
|
163
|
+
if (typeof unit === "undefined") {
|
|
164
|
+
unit = this.boundTextures.indexOf(texture);
|
|
165
|
+
}
|
|
166
|
+
if (unit !== -1) {
|
|
167
|
+
delete this.boundTextures[unit];
|
|
168
|
+
if (unit === this.currentTextureUnit) {
|
|
169
|
+
this.currentTextureUnit = -1;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
return unit;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* @ignore
|
|
177
|
+
*/
|
|
178
|
+
uploadTexture(texture, w, h, force = false) {
|
|
179
|
+
var unit = this.renderer.cache.getUnit(texture);
|
|
180
|
+
var texture2D = this.boundTextures[unit];
|
|
181
|
+
|
|
182
|
+
if (typeof texture2D === "undefined" || force) {
|
|
183
|
+
this.createTexture2D(
|
|
184
|
+
unit,
|
|
185
|
+
texture.getTexture(),
|
|
186
|
+
this.renderer.settings.antiAlias ? this.gl.LINEAR : this.gl.NEAREST,
|
|
187
|
+
texture.repeat,
|
|
188
|
+
w,
|
|
189
|
+
h,
|
|
190
|
+
texture.premultipliedAlpha
|
|
191
|
+
);
|
|
192
|
+
} else {
|
|
193
|
+
this.bindTexture2D(texture2D, unit);
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
return this.currentTextureUnit;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* Add a textured quad
|
|
201
|
+
* @param {TextureAtlas} texture - Source texture atlas
|
|
202
|
+
* @param {number} x - Destination x-coordinate
|
|
203
|
+
* @param {number} y - Destination y-coordinate
|
|
204
|
+
* @param {number} w - Destination width
|
|
205
|
+
* @param {number} h - Destination height
|
|
206
|
+
* @param {number} u0 - Texture UV (u0) value.
|
|
207
|
+
* @param {number} v0 - Texture UV (v0) value.
|
|
208
|
+
* @param {number} u1 - Texture UV (u1) value.
|
|
209
|
+
* @param {number} v1 - Texture UV (v1) value.
|
|
210
|
+
* @param {number} tint - tint color to be applied to the texture in UINT32 (argb) format
|
|
211
|
+
*/
|
|
212
|
+
addQuad(texture, x, y, w, h, u0, v0, u1, v1, tint) {
|
|
213
|
+
var vertexData = this.vertexData;
|
|
214
|
+
|
|
215
|
+
if (vertexData.isFull(6)) {
|
|
216
|
+
// is the vertex buffer full if we add 6 more vertices
|
|
217
|
+
this.flush();
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
// upload and activate the texture if necessary
|
|
221
|
+
var unit = this.uploadTexture(texture);
|
|
222
|
+
|
|
223
|
+
// set fragment sampler accordingly
|
|
224
|
+
this.currentShader.setUniform("uSampler", unit);
|
|
225
|
+
|
|
226
|
+
// Transform vertices
|
|
227
|
+
var m = this.viewMatrix,
|
|
228
|
+
vec0 = V_ARRAY[0].set(x, y),
|
|
229
|
+
vec1 = V_ARRAY[1].set(x + w, y),
|
|
230
|
+
vec2 = V_ARRAY[2].set(x, y + h),
|
|
231
|
+
vec3 = V_ARRAY[3].set(x + w, y + h);
|
|
232
|
+
|
|
233
|
+
if (!m.isIdentity()) {
|
|
234
|
+
m.apply(vec0);
|
|
235
|
+
m.apply(vec1);
|
|
236
|
+
m.apply(vec2);
|
|
237
|
+
m.apply(vec3);
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
vertexData.push(vec0.x, vec0.y, u0, v0, tint);
|
|
241
|
+
vertexData.push(vec1.x, vec1.y, u1, v0, tint);
|
|
242
|
+
vertexData.push(vec2.x, vec2.y, u0, v1, tint);
|
|
243
|
+
vertexData.push(vec2.x, vec2.y, u0, v1, tint);
|
|
244
|
+
vertexData.push(vec1.x, vec1.y, u1, v0, tint);
|
|
245
|
+
vertexData.push(vec3.x, vec3.y, u1, v1, tint);
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
export { QuadCompositor as default };
|
package/dist/melonjs.mjs/video/webgl/{webgl_compositor.js → compositors/webgl_compositor.js}
RENAMED
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* melonJS Game Engine -
|
|
2
|
+
* melonJS Game Engine - v15.0.0
|
|
3
3
|
* http://www.melonjs.org
|
|
4
4
|
* melonjs is licensed under the MIT License.
|
|
5
5
|
* http://www.opensource.org/licenses/mit-license
|
|
6
6
|
* @copyright (C) 2011 - 2023 Olivier Biot (AltByte Pte Ltd)
|
|
7
7
|
*/
|
|
8
|
-
import Vector2d from '
|
|
9
|
-
import GLShader from '
|
|
10
|
-
import VertexArrayBuffer from '
|
|
11
|
-
import {
|
|
12
|
-
import
|
|
13
|
-
import
|
|
14
|
-
import
|
|
15
|
-
import
|
|
16
|
-
import
|
|
8
|
+
import Vector2d from '../../../math/vector2.js';
|
|
9
|
+
import GLShader from '../glshader.js';
|
|
10
|
+
import VertexArrayBuffer from '../buffer/vertex.js';
|
|
11
|
+
import { isPowerOfTwo } from '../../../math/math.js';
|
|
12
|
+
import primitiveVertex from '../shaders/primitive.vert.js';
|
|
13
|
+
import primitiveFragment from '../shaders/primitive.frag.js';
|
|
14
|
+
import quadVertex from '../shaders/quad.vert.js';
|
|
15
|
+
import quadFragment from '../shaders/quad.frag.js';
|
|
16
|
+
import Compositor from './compositor.js';
|
|
17
17
|
|
|
18
18
|
// a pool of resuable vectors
|
|
19
19
|
var V_ARRAY = [
|
|
@@ -27,95 +27,35 @@ var V_ARRAY = [
|
|
|
27
27
|
* @classdesc
|
|
28
28
|
* A WebGL Compositor object. This class handles all of the WebGL state<br>
|
|
29
29
|
* Pushes texture regions or shape geometry into WebGL buffers, automatically flushes to GPU
|
|
30
|
+
* @augments Compositor
|
|
30
31
|
*/
|
|
31
|
-
class WebGLCompositor {
|
|
32
|
-
/**
|
|
33
|
-
* @param {WebGLRenderer} renderer - the current WebGL renderer session
|
|
34
|
-
*/
|
|
35
|
-
constructor (renderer) {
|
|
36
|
-
this.init(renderer);
|
|
37
|
-
}
|
|
32
|
+
class WebGLCompositor extends Compositor {
|
|
38
33
|
|
|
39
34
|
/**
|
|
40
35
|
* Initialize the compositor
|
|
41
36
|
* @ignore
|
|
42
37
|
*/
|
|
43
38
|
init (renderer) {
|
|
44
|
-
|
|
45
|
-
var gl = renderer.gl;
|
|
39
|
+
super.init(renderer);
|
|
46
40
|
|
|
47
41
|
// list of active texture units
|
|
48
42
|
this.currentTextureUnit = -1;
|
|
49
43
|
this.boundTextures = [];
|
|
50
44
|
|
|
51
|
-
// the associated renderer
|
|
52
|
-
this.renderer = renderer;
|
|
53
|
-
|
|
54
|
-
// WebGL context
|
|
55
|
-
this.gl = renderer.gl;
|
|
56
|
-
|
|
57
|
-
// Global fill color
|
|
58
|
-
this.color = renderer.currentColor;
|
|
59
|
-
|
|
60
|
-
// Global transformation matrix
|
|
61
|
-
this.viewMatrix = renderer.currentTransform;
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
* a reference to the active WebGL shader
|
|
65
|
-
* @type {GLShader}
|
|
66
|
-
*/
|
|
67
|
-
this.activeShader = null;
|
|
68
|
-
|
|
69
|
-
/**
|
|
70
|
-
* primitive type to render (gl.POINTS, gl.LINE_STRIP, gl.LINE_LOOP, gl.LINES, gl.TRIANGLE_STRIP, gl.TRIANGLE_FAN, gl.TRIANGLES)
|
|
71
|
-
* @type {number}
|
|
72
|
-
* @default gl.TRIANGLES
|
|
73
|
-
*/
|
|
74
|
-
this.mode = gl.TRIANGLES;
|
|
75
|
-
|
|
76
|
-
/**
|
|
77
|
-
* an array of vertex attribute properties
|
|
78
|
-
* @see WebGLCompositor.addAttribute
|
|
79
|
-
* @type {Array}
|
|
80
|
-
*/
|
|
81
|
-
this.attributes = [];
|
|
82
|
-
|
|
83
|
-
/**
|
|
84
|
-
* the size of a single vertex in bytes
|
|
85
|
-
* (will automatically be calculated as attributes definitions are added)
|
|
86
|
-
* @see WebGLCompositor.addAttribute
|
|
87
|
-
* @type {number}
|
|
88
|
-
*/
|
|
89
|
-
this.vertexByteSize = 0;
|
|
90
|
-
|
|
91
|
-
/**
|
|
92
|
-
* the size of a single vertex in floats
|
|
93
|
-
* (will automatically be calculated as attributes definitions are added)
|
|
94
|
-
* @see WebGLCompositor.addAttribute
|
|
95
|
-
* @type {number}
|
|
96
|
-
*/
|
|
97
|
-
this.vertexSize = 0;
|
|
98
|
-
|
|
99
45
|
// Load and create shader programs
|
|
100
46
|
this.primitiveShader = new GLShader(this.gl, primitiveVertex, primitiveFragment);
|
|
101
47
|
this.quadShader = new GLShader(this.gl, quadVertex, quadFragment);
|
|
102
48
|
|
|
103
49
|
/// define all vertex attributes
|
|
104
|
-
this.addAttribute("aVertex", 2, gl.FLOAT, false, 0 * Float32Array.BYTES_PER_ELEMENT); // 0
|
|
105
|
-
this.addAttribute("aRegion", 2, gl.FLOAT, false, 2 * Float32Array.BYTES_PER_ELEMENT); // 1
|
|
106
|
-
this.addAttribute("aColor", 4, gl.UNSIGNED_BYTE, true, 4 * Float32Array.BYTES_PER_ELEMENT); // 2
|
|
50
|
+
this.addAttribute("aVertex", 2, this.gl.FLOAT, false, 0 * Float32Array.BYTES_PER_ELEMENT); // 0
|
|
51
|
+
this.addAttribute("aRegion", 2, this.gl.FLOAT, false, 2 * Float32Array.BYTES_PER_ELEMENT); // 1
|
|
52
|
+
this.addAttribute("aColor", 4, this.gl.UNSIGNED_BYTE, true, 4 * Float32Array.BYTES_PER_ELEMENT); // 2
|
|
107
53
|
|
|
108
54
|
this.vertexBuffer = new VertexArrayBuffer(this.vertexSize, 6); // 6 vertices per quad
|
|
109
55
|
|
|
110
56
|
// vertex buffer
|
|
111
|
-
gl.bindBuffer(gl.ARRAY_BUFFER, gl.createBuffer());
|
|
112
|
-
gl.bufferData(gl.ARRAY_BUFFER, this.vertexBuffer.buffer, gl.STREAM_DRAW);
|
|
113
|
-
|
|
114
|
-
// register to the CANVAS resize channel
|
|
115
|
-
on(CANVAS_ONRESIZE, (width, height) => {
|
|
116
|
-
this.flush();
|
|
117
|
-
this.setViewport(0, 0, width, height);
|
|
118
|
-
});
|
|
57
|
+
this.gl.bindBuffer(this.gl.ARRAY_BUFFER, this.gl.createBuffer());
|
|
58
|
+
this.gl.bufferData(this.gl.ARRAY_BUFFER, this.vertexBuffer.buffer, this.gl.STREAM_DRAW);
|
|
119
59
|
}
|
|
120
60
|
|
|
121
61
|
/**
|
|
@@ -123,20 +63,7 @@ var V_ARRAY = [
|
|
|
123
63
|
* @ignore
|
|
124
64
|
*/
|
|
125
65
|
reset() {
|
|
126
|
-
|
|
127
|
-
this.gl = this.renderer.gl;
|
|
128
|
-
|
|
129
|
-
this.flush();
|
|
130
|
-
|
|
131
|
-
// initial viewport size
|
|
132
|
-
this.setViewport(
|
|
133
|
-
0, 0,
|
|
134
|
-
this.renderer.getCanvas().width,
|
|
135
|
-
this.renderer.getCanvas().height
|
|
136
|
-
);
|
|
137
|
-
|
|
138
|
-
// Initialize clear color
|
|
139
|
-
this.clearColor(0.0, 0.0, 0.0, 0.0);
|
|
66
|
+
super.reset();
|
|
140
67
|
|
|
141
68
|
// delete all related bound texture
|
|
142
69
|
for (var i = 0; i < this.renderer.maxTextures; i++) {
|
|
@@ -151,62 +78,6 @@ var V_ARRAY = [
|
|
|
151
78
|
this.useShader(this.quadShader);
|
|
152
79
|
}
|
|
153
80
|
|
|
154
|
-
/**
|
|
155
|
-
* add vertex attribute property definition to the compositor
|
|
156
|
-
* @param {string} name - name of the attribute in the vertex shader
|
|
157
|
-
* @param {number} size - number of components per vertex attribute. Must be 1, 2, 3, or 4.
|
|
158
|
-
* @param {GLenum} type - data type of each component in the array
|
|
159
|
-
* @param {boolean} normalized - whether integer data values should be normalized into a certain range when being cast to a float
|
|
160
|
-
* @param {number} offset - offset in bytes of the first component in the vertex attribute array
|
|
161
|
-
*/
|
|
162
|
-
addAttribute(name, size, type, normalized, offset) {
|
|
163
|
-
this.attributes.push({
|
|
164
|
-
name: name,
|
|
165
|
-
size: size,
|
|
166
|
-
type: type,
|
|
167
|
-
normalized: normalized,
|
|
168
|
-
offset: offset
|
|
169
|
-
});
|
|
170
|
-
|
|
171
|
-
switch (type) {
|
|
172
|
-
case this.gl.BYTE:
|
|
173
|
-
this.vertexByteSize += size * Int8Array.BYTES_PER_ELEMENT;
|
|
174
|
-
break;
|
|
175
|
-
case this.gl.UNSIGNED_BYTE:
|
|
176
|
-
this.vertexByteSize += size * Uint8Array.BYTES_PER_ELEMENT;
|
|
177
|
-
break;
|
|
178
|
-
case this.gl.SHORT:
|
|
179
|
-
this.vertexByteSize += size * Int16Array.BYTES_PER_ELEMENT;
|
|
180
|
-
break;
|
|
181
|
-
case this.gl.UNSIGNED_SHORT:
|
|
182
|
-
this.vertexByteSize += size * Uint16Array.BYTES_PER_ELEMENT;
|
|
183
|
-
break;
|
|
184
|
-
case this.gl.INT:
|
|
185
|
-
this.vertexByteSize += size * Int32Array.BYTES_PER_ELEMENT;
|
|
186
|
-
break;
|
|
187
|
-
case this.gl.UNSIGNED_INT:
|
|
188
|
-
this.vertexByteSize += size * Uint32Array.BYTES_PER_ELEMENT;
|
|
189
|
-
break;
|
|
190
|
-
case this.gl.FLOAT:
|
|
191
|
-
this.vertexByteSize += size * Float32Array.BYTES_PER_ELEMENT;
|
|
192
|
-
break;
|
|
193
|
-
default:
|
|
194
|
-
throw new Error("Invalid GL Attribute type");
|
|
195
|
-
}
|
|
196
|
-
this.vertexSize = this.vertexByteSize / Float32Array.BYTES_PER_ELEMENT;
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
/**
|
|
200
|
-
* Sets the viewport
|
|
201
|
-
* @param {number} x - x position of viewport
|
|
202
|
-
* @param {number} y - y position of viewport
|
|
203
|
-
* @param {number} w - width of viewport
|
|
204
|
-
* @param {number} h - height of viewport
|
|
205
|
-
*/
|
|
206
|
-
setViewport(x, y, w, h) {
|
|
207
|
-
this.gl.viewport(x, y, w, h);
|
|
208
|
-
}
|
|
209
|
-
|
|
210
81
|
/**
|
|
211
82
|
* Create a WebGL texture from an image
|
|
212
83
|
* @param {number} unit - Destination texture unit
|
|
@@ -337,13 +208,6 @@ var V_ARRAY = [
|
|
|
337
208
|
return this.currentTextureUnit;
|
|
338
209
|
}
|
|
339
210
|
|
|
340
|
-
/**
|
|
341
|
-
* set/change the current projection matrix
|
|
342
|
-
* @param {Matrix3d} matrix
|
|
343
|
-
*/
|
|
344
|
-
setProjection(matrix) {
|
|
345
|
-
this.activeShader.setUniform("uProjectionMatrix", matrix);
|
|
346
|
-
}
|
|
347
211
|
|
|
348
212
|
/**
|
|
349
213
|
* Select the shader to use for compositing
|
|
@@ -414,36 +278,10 @@ var V_ARRAY = [
|
|
|
414
278
|
this.vertexBuffer.push(vec3.x, vec3.y, u1, v1, tint);
|
|
415
279
|
}
|
|
416
280
|
|
|
417
|
-
/**
|
|
418
|
-
* Flush batched texture operations to the GPU
|
|
419
|
-
* @param {number} [mode=gl.TRIANGLES] - the GL drawing mode
|
|
420
|
-
*/
|
|
421
|
-
flush(mode = this.mode) {
|
|
422
|
-
var vertex = this.vertexBuffer;
|
|
423
|
-
var vertexCount = vertex.vertexCount;
|
|
424
|
-
|
|
425
|
-
if (vertexCount > 0) {
|
|
426
|
-
var gl = this.gl;
|
|
427
|
-
var vertexSize = vertex.vertexSize;
|
|
428
|
-
|
|
429
|
-
// Copy data into stream buffer
|
|
430
|
-
if (this.renderer.WebGLVersion > 1) {
|
|
431
|
-
gl.bufferData(gl.ARRAY_BUFFER, vertex.toFloat32(), gl.STREAM_DRAW, 0, vertexCount * vertexSize);
|
|
432
|
-
} else {
|
|
433
|
-
gl.bufferData(gl.ARRAY_BUFFER, vertex.toFloat32(0, vertexCount * vertexSize), gl.STREAM_DRAW);
|
|
434
|
-
}
|
|
435
|
-
|
|
436
|
-
gl.drawArrays(mode, 0, vertexCount);
|
|
437
|
-
|
|
438
|
-
// clear the vertex buffer
|
|
439
|
-
vertex.clear();
|
|
440
|
-
}
|
|
441
|
-
}
|
|
442
|
-
|
|
443
281
|
/**
|
|
444
282
|
* Draw an array of vertices
|
|
445
283
|
* @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)
|
|
446
|
-
* @param {
|
|
284
|
+
* @param {Point[]} verts - an array of vertices
|
|
447
285
|
* @param {number} [vertexCount=verts.length] - amount of points defined in the points array
|
|
448
286
|
*/
|
|
449
287
|
drawVertices(mode, verts, vertexCount = verts.length) {
|
|
@@ -466,29 +304,6 @@ var V_ARRAY = [
|
|
|
466
304
|
// flush
|
|
467
305
|
this.flush(mode);
|
|
468
306
|
}
|
|
469
|
-
|
|
470
|
-
/**
|
|
471
|
-
* Clear the frame buffer
|
|
472
|
-
* @param {number} [alpha = 0.0] - the alpha value used when clearing the framebuffer
|
|
473
|
-
*/
|
|
474
|
-
clear(alpha = 0) {
|
|
475
|
-
var gl = this.gl;
|
|
476
|
-
gl.clearColor(0, 0, 0, alpha);
|
|
477
|
-
gl.clear(gl.COLOR_BUFFER_BIT | gl.STENCIL_BUFFER_BIT);
|
|
478
|
-
}
|
|
479
|
-
|
|
480
|
-
/**
|
|
481
|
-
* Specify the color values used when clearing color buffers. The values are clamped between 0 and 1.
|
|
482
|
-
* @param {number} [r = 0] - the red color value used when the color buffers are cleared
|
|
483
|
-
* @param {number} [g = 0] - the green color value used when the color buffers are cleared
|
|
484
|
-
* @param {number} [b = 0] - the blue color value used when the color buffers are cleared
|
|
485
|
-
* @param {number} [a = 0] - the alpha color value used when the color buffers are cleared
|
|
486
|
-
*/
|
|
487
|
-
clearColor(r = 0, g = 0, b = 0, a = 0) {
|
|
488
|
-
var gl = this.gl;
|
|
489
|
-
gl.clearColor(r, g, b, a);
|
|
490
|
-
gl.clear(gl.COLOR_BUFFER_BIT);
|
|
491
|
-
}
|
|
492
307
|
}
|
|
493
308
|
|
|
494
309
|
export { WebGLCompositor as default };
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* melonJS Game Engine -
|
|
2
|
+
* melonJS Game Engine - v15.0.0
|
|
3
3
|
* http://www.melonjs.org
|
|
4
4
|
* melonjs is licensed under the MIT License.
|
|
5
5
|
* http://www.opensource.org/licenses/mit-license
|
|
6
6
|
* @copyright (C) 2011 - 2023 Olivier Biot (AltByte Pte Ltd)
|
|
7
7
|
*/
|
|
8
|
-
var primitiveVertex = "// Current vertex point\nattribute vec2 aVertex;\n\n// Projection matrix\nuniform mat4 uProjectionMatrix;\n\
|
|
8
|
+
var primitiveVertex = "// Current vertex point\nattribute vec2 aVertex;\nattribute vec4 aColor;\n\n// Projection matrix\nuniform mat4 uProjectionMatrix;\n\nvarying vec4 vColor;\n\nvoid main(void) {\n // Transform the vertex position by the projection matrix\n gl_Position = uProjectionMatrix * vec4(aVertex, 0.0, 1.0);\n // Pass the remaining attributes to the fragment shader\n vColor = vec4(aColor.bgr * aColor.a, aColor.a);\n}\n";
|
|
9
9
|
|
|
10
10
|
export { primitiveVertex as default };
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* melonJS Game Engine -
|
|
2
|
+
* melonJS Game Engine - v15.0.0
|
|
3
3
|
* http://www.melonjs.org
|
|
4
4
|
* melonjs is licensed under the MIT License.
|
|
5
5
|
* http://www.opensource.org/licenses/mit-license
|
|
6
6
|
* @copyright (C) 2011 - 2023 Olivier Biot (AltByte Pte Ltd)
|
|
7
7
|
*/
|
|
8
|
-
var quadVertex = "
|
|
8
|
+
var quadVertex = "// Current vertex point\nattribute vec2 aVertex;\nattribute vec2 aRegion;\nattribute vec4 aColor;\n\n// Projection matrix\nuniform mat4 uProjectionMatrix;\n\nvarying vec2 vRegion;\nvarying vec4 vColor;\n\nvoid main(void) {\n // Transform the vertex position by the projection matrix\n gl_Position = uProjectionMatrix * vec4(aVertex, 0.0, 1.0);\n // Pass the remaining attributes to the fragment shader\n vColor = vec4(aColor.bgr * aColor.a, aColor.a);\n vRegion = aRegion;\n}\n";
|
|
9
9
|
|
|
10
10
|
export { quadVertex as default };
|