melonjs 14.5.0 → 15.1.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 +6 -6
- 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 +7 -3
- 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 +27 -17
- package/dist/melonjs.mjs/application/header.js +6 -5
- package/dist/melonjs.mjs/application/resize.js +20 -20
- package/dist/melonjs.mjs/application/settings.js +1 -1
- package/dist/melonjs.mjs/audio/audio.js +18 -20
- package/dist/melonjs.mjs/camera/camera2d.js +10 -10
- package/dist/melonjs.mjs/const.js +1 -1
- package/dist/melonjs.mjs/entity/entity.js +4 -4
- package/dist/melonjs.mjs/geometries/ellipse.js +6 -6
- package/dist/melonjs.mjs/geometries/line.js +9 -9
- package/dist/melonjs.mjs/geometries/path2d.js +56 -56
- package/dist/melonjs.mjs/geometries/point.js +2 -2
- package/dist/melonjs.mjs/geometries/poly.js +29 -29
- package/dist/melonjs.mjs/geometries/rectangle.js +8 -8
- package/dist/melonjs.mjs/geometries/roundrect.js +6 -6
- package/dist/melonjs.mjs/index.js +8 -6
- package/dist/melonjs.mjs/input/gamepad.js +30 -30
- package/dist/melonjs.mjs/input/input.js +2 -2
- package/dist/melonjs.mjs/input/keyboard.js +15 -15
- package/dist/melonjs.mjs/input/pointer.js +2 -2
- package/dist/melonjs.mjs/input/pointerevent.js +59 -59
- package/dist/melonjs.mjs/lang/console.js +3 -3
- package/dist/melonjs.mjs/lang/deprecated.js +2 -2
- package/dist/melonjs.mjs/level/level.js +9 -9
- package/dist/melonjs.mjs/level/tiled/TMXGroup.js +3 -3
- package/dist/melonjs.mjs/level/tiled/TMXLayer.js +31 -31
- package/dist/melonjs.mjs/level/tiled/TMXObject.js +8 -8
- package/dist/melonjs.mjs/level/tiled/TMXTile.js +8 -8
- package/dist/melonjs.mjs/level/tiled/TMXTileMap.js +19 -19
- package/dist/melonjs.mjs/level/tiled/TMXTileset.js +15 -15
- package/dist/melonjs.mjs/level/tiled/TMXTilesetGroup.js +3 -3
- package/dist/melonjs.mjs/level/tiled/TMXUtils.js +46 -41
- package/dist/melonjs.mjs/level/tiled/constants.js +1 -1
- package/dist/melonjs.mjs/level/tiled/renderer/TMXHexagonalRenderer.js +30 -30
- package/dist/melonjs.mjs/level/tiled/renderer/TMXIsometricRenderer.js +21 -21
- package/dist/melonjs.mjs/level/tiled/renderer/TMXOrthogonalRenderer.js +10 -10
- package/dist/melonjs.mjs/level/tiled/renderer/TMXRenderer.js +2 -2
- package/dist/melonjs.mjs/level/tiled/renderer/TMXStaggeredRenderer.js +6 -6
- package/dist/melonjs.mjs/level/tiled/renderer/autodetect.js +1 -1
- package/dist/melonjs.mjs/loader/cache.js +1 -1
- package/dist/melonjs.mjs/loader/loader.js +7 -7
- package/dist/melonjs.mjs/loader/loadingscreen.js +2 -2
- package/dist/melonjs.mjs/loader/melonjs_logo.png.js +1 -1
- package/dist/melonjs.mjs/loader/parser.js +13 -13
- package/dist/melonjs.mjs/loader/settings.js +3 -3
- package/dist/melonjs.mjs/math/color.js +25 -24
- package/dist/melonjs.mjs/math/math.js +2 -2
- package/dist/melonjs.mjs/math/matrix2.js +22 -22
- package/dist/melonjs.mjs/math/matrix3.js +52 -52
- package/dist/melonjs.mjs/math/observable_vector2.js +12 -12
- package/dist/melonjs.mjs/math/observable_vector3.js +22 -22
- package/dist/melonjs.mjs/math/vector2.js +11 -11
- package/dist/melonjs.mjs/math/vector3.js +21 -21
- package/dist/melonjs.mjs/node_modules/@teppeis/multimaps/dist/esm/arraymultimap.js +45 -0
- package/dist/melonjs.mjs/node_modules/@teppeis/multimaps/dist/esm/multimap.js +130 -0
- 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 +2 -2
- 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 +5 -5
- package/dist/melonjs.mjs/particles/particle.js +8 -8
- package/dist/melonjs.mjs/particles/settings.js +3 -3
- package/dist/melonjs.mjs/physics/body.js +17 -17
- package/dist/melonjs.mjs/physics/bounds.js +12 -12
- package/dist/melonjs.mjs/physics/collision.js +3 -3
- package/dist/melonjs.mjs/physics/detector.js +14 -14
- package/dist/melonjs.mjs/physics/quadtree.js +19 -19
- package/dist/melonjs.mjs/physics/response.js +1 -1
- package/dist/melonjs.mjs/physics/sat.js +60 -60
- package/dist/melonjs.mjs/physics/world.js +4 -4
- package/dist/melonjs.mjs/plugin/plugin.js +11 -11
- package/dist/melonjs.mjs/renderable/collectable.js +2 -2
- package/dist/melonjs.mjs/renderable/colorlayer.js +1 -1
- package/dist/melonjs.mjs/renderable/container.js +77 -59
- package/dist/melonjs.mjs/renderable/dragndrop.js +5 -5
- package/dist/melonjs.mjs/renderable/imagelayer.js +7 -6
- package/dist/melonjs.mjs/renderable/light2d.js +6 -6
- package/dist/melonjs.mjs/renderable/nineslicesprite.js +12 -12
- package/dist/melonjs.mjs/renderable/renderable.js +35 -13
- package/dist/melonjs.mjs/renderable/sprite.js +25 -25
- package/dist/melonjs.mjs/renderable/trigger.js +11 -9
- package/dist/melonjs.mjs/renderable/ui/uibaseelement.js +97 -27
- package/dist/melonjs.mjs/renderable/ui/uispriteelement.js +25 -25
- package/dist/melonjs.mjs/renderable/ui/uitextbutton.js +83 -65
- package/dist/melonjs.mjs/state/stage.js +7 -7
- package/dist/melonjs.mjs/state/state.js +15 -15
- package/dist/melonjs.mjs/system/device.js +3 -3
- package/dist/melonjs.mjs/system/dom.js +1 -1
- package/dist/melonjs.mjs/system/event.js +2 -2
- package/dist/melonjs.mjs/system/platform.js +1 -1
- package/dist/melonjs.mjs/system/pooling.js +9 -9
- package/dist/melonjs.mjs/system/save.js +6 -6
- package/dist/melonjs.mjs/system/timer.js +16 -12
- package/dist/melonjs.mjs/text/bitmaptext.js +20 -20
- package/dist/melonjs.mjs/text/bitmaptextdata.js +22 -22
- package/dist/melonjs.mjs/text/glyph.js +3 -3
- package/dist/melonjs.mjs/text/text.js +63 -92
- package/dist/melonjs.mjs/text/textmetrics.js +15 -15
- package/dist/melonjs.mjs/text/textstyle.js +4 -6
- package/dist/melonjs.mjs/tweens/easing.js +4 -4
- package/dist/melonjs.mjs/tweens/interpolation.js +8 -8
- package/dist/melonjs.mjs/tweens/tween.js +11 -11
- package/dist/melonjs.mjs/utils/agent.js +6 -6
- package/dist/melonjs.mjs/utils/array.js +4 -4
- package/dist/melonjs.mjs/utils/file.js +1 -1
- package/dist/melonjs.mjs/utils/function.js +5 -5
- package/dist/melonjs.mjs/utils/string.js +3 -3
- package/dist/melonjs.mjs/utils/utils.js +16 -16
- package/dist/melonjs.mjs/video/canvas/canvas_renderer.js +41 -119
- package/dist/melonjs.mjs/video/renderer.js +70 -14
- package/dist/melonjs.mjs/video/texture/atlas.js +39 -45
- package/dist/melonjs.mjs/video/texture/cache.js +9 -10
- package/dist/melonjs.mjs/video/texture/canvas_texture.js +63 -3
- 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 +23 -19
- package/dist/melonjs.mjs/video/webgl/compositors/compositor.js +80 -80
- package/dist/melonjs.mjs/video/webgl/compositors/primitive_compositor.js +77 -0
- package/dist/melonjs.mjs/video/webgl/compositors/quad_compositor.js +252 -0
- package/dist/melonjs.mjs/video/webgl/compositors/webgl_compositor.js +1 -1
- package/dist/melonjs.mjs/video/webgl/glshader.js +7 -7
- 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 +2 -2
- package/dist/melonjs.mjs/video/webgl/utils/precision.js +1 -1
- package/dist/melonjs.mjs/video/webgl/utils/program.js +7 -7
- package/dist/melonjs.mjs/video/webgl/utils/string.js +1 -1
- package/dist/melonjs.mjs/video/webgl/utils/uniforms.js +4 -4
- package/dist/melonjs.mjs/video/webgl/webgl_renderer.js +188 -181
- package/dist/melonjs.module.js +25040 -25193
- package/dist/types/application/application.d.ts +11 -8
- package/dist/types/audio/audio.d.ts +3 -3
- package/dist/types/entity/entity.d.ts +1 -1
- package/dist/types/index.d.ts +7 -4
- package/dist/types/input/input.d.ts +1 -1
- package/dist/types/input/keyboard.d.ts +1 -1
- package/dist/types/input/pointerevent.d.ts +6 -6
- package/dist/types/level/level.d.ts +2 -2
- package/dist/types/level/tiled/TMXLayer.d.ts +4 -4
- package/dist/types/level/tiled/TMXTileMap.d.ts +2 -2
- package/dist/types/level/tiled/TMXUtils.d.ts +5 -4
- package/dist/types/loader/loader.d.ts +2 -2
- package/dist/types/loader/settings.d.ts +2 -2
- package/dist/types/particles/emitter.d.ts +1 -1
- package/dist/types/physics/collision.d.ts +1 -1
- package/dist/types/physics/detector.d.ts +1 -1
- package/dist/types/plugin/plugin.d.ts +2 -2
- package/dist/types/renderable/container.d.ts +21 -17
- package/dist/types/renderable/renderable.d.ts +6 -0
- package/dist/types/renderable/sprite.d.ts +11 -11
- package/dist/types/renderable/trigger.d.ts +1 -1
- package/dist/types/renderable/ui/uibaseelement.d.ts +28 -6
- package/dist/types/renderable/ui/uispriteelement.d.ts +12 -14
- package/dist/types/renderable/ui/uitextbutton.d.ts +52 -12
- package/dist/types/state/stage.d.ts +1 -1
- package/dist/types/system/device.d.ts +1 -1
- package/dist/types/system/pooling.d.ts +3 -3
- package/dist/types/system/timer.d.ts +5 -5
- package/dist/types/text/bitmaptext.d.ts +1 -1
- package/dist/types/text/text.d.ts +7 -21
- package/dist/types/text/textstyle.d.ts +1 -1
- package/dist/types/utils/array.d.ts +2 -2
- package/dist/types/video/canvas/canvas_renderer.d.ts +8 -81
- package/dist/types/video/renderer.d.ts +48 -4
- package/dist/types/video/texture/atlas.d.ts +3 -3
- package/dist/types/video/texture/canvas_texture.d.ts +40 -0
- package/dist/types/video/webgl/buffer/vertex.d.ts +3 -3
- package/dist/types/video/webgl/compositors/compositor.d.ts +38 -32
- 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/glshader.d.ts +1 -1
- package/dist/types/video/webgl/webgl_renderer.d.ts +47 -37
- package/package.json +16 -17
- package/src/application/application.js +26 -16
- package/src/application/header.js +5 -4
- package/src/application/resize.js +19 -19
- package/src/audio/audio.js +17 -19
- package/src/camera/camera2d.js +9 -9
- package/src/entity/entity.js +3 -3
- package/src/geometries/ellipse.js +5 -5
- package/src/geometries/line.js +8 -8
- package/src/geometries/path2d.js +55 -55
- package/src/geometries/point.js +1 -1
- package/src/geometries/poly.js +28 -28
- package/src/geometries/rectangle.js +7 -7
- package/src/geometries/roundrect.js +5 -5
- package/src/index.js +9 -4
- package/src/input/gamepad.js +29 -29
- package/src/input/input.js +1 -1
- package/src/input/keyboard.js +14 -14
- package/src/input/pointer.js +1 -1
- package/src/input/pointerevent.js +52 -52
- package/src/lang/console.js +2 -2
- package/src/lang/deprecated.js +1 -1
- package/src/level/level.js +8 -8
- package/src/level/tiled/TMXGroup.js +2 -2
- package/src/level/tiled/TMXLayer.js +30 -30
- package/src/level/tiled/TMXObject.js +7 -7
- package/src/level/tiled/TMXTile.js +7 -7
- package/src/level/tiled/TMXTileMap.js +18 -18
- package/src/level/tiled/TMXTileset.js +14 -14
- package/src/level/tiled/TMXTilesetGroup.js +2 -2
- package/src/level/tiled/TMXUtils.js +45 -40
- package/src/level/tiled/renderer/TMXHexagonalRenderer.js +29 -29
- package/src/level/tiled/renderer/TMXIsometricRenderer.js +20 -20
- package/src/level/tiled/renderer/TMXOrthogonalRenderer.js +9 -9
- package/src/level/tiled/renderer/TMXRenderer.js +1 -1
- package/src/level/tiled/renderer/TMXStaggeredRenderer.js +5 -5
- package/src/loader/loader.js +6 -6
- package/src/loader/loadingscreen.js +1 -1
- package/src/loader/parser.js +12 -12
- package/src/loader/settings.js +2 -2
- package/src/math/color.js +24 -23
- package/src/math/math.js +1 -1
- package/src/math/matrix2.js +21 -21
- package/src/math/matrix3.js +51 -51
- package/src/math/observable_vector2.js +11 -11
- package/src/math/observable_vector3.js +21 -21
- package/src/math/vector2.js +10 -10
- package/src/math/vector3.js +20 -20
- package/src/particles/emitter.js +4 -4
- package/src/particles/particle.js +7 -7
- package/src/particles/settings.js +2 -2
- package/src/physics/body.js +16 -16
- package/src/physics/bounds.js +11 -11
- package/src/physics/collision.js +2 -2
- package/src/physics/detector.js +13 -13
- package/src/physics/quadtree.js +18 -18
- package/src/physics/sat.js +59 -59
- package/src/physics/world.js +3 -3
- package/src/plugin/plugin.js +8 -8
- package/src/polyfill/index.js +0 -2
- package/src/renderable/collectable.js +1 -1
- package/src/renderable/container.js +76 -58
- package/src/renderable/dragndrop.js +4 -4
- package/src/renderable/imagelayer.js +6 -5
- package/src/renderable/light2d.js +5 -5
- package/src/renderable/nineslicesprite.js +11 -11
- package/src/renderable/renderable.js +34 -12
- package/src/renderable/sprite.js +24 -24
- package/src/renderable/trigger.js +10 -8
- package/src/renderable/ui/uibaseelement.js +96 -26
- package/src/renderable/ui/uispriteelement.js +24 -24
- package/src/renderable/ui/uitextbutton.js +85 -67
- package/src/state/stage.js +6 -6
- package/src/state/state.js +14 -14
- package/src/system/device.js +2 -2
- package/src/system/event.js +1 -1
- package/src/system/pooling.js +8 -8
- package/src/system/save.js +5 -5
- package/src/system/timer.js +15 -11
- package/src/text/bitmaptext.js +19 -19
- package/src/text/bitmaptextdata.js +21 -21
- package/src/text/glyph.js +2 -2
- package/src/text/text.js +62 -91
- package/src/text/textmetrics.js +14 -14
- package/src/text/textstyle.js +3 -5
- package/src/tweens/easing.js +3 -3
- package/src/tweens/interpolation.js +7 -7
- package/src/tweens/tween.js +10 -10
- package/src/utils/agent.js +5 -5
- package/src/utils/array.js +3 -3
- package/src/utils/function.js +4 -4
- package/src/utils/string.js +2 -2
- package/src/utils/utils.js +15 -15
- package/src/video/canvas/canvas_renderer.js +39 -117
- package/src/video/renderer.js +68 -12
- package/src/video/texture/atlas.js +38 -44
- package/src/video/texture/cache.js +6 -6
- package/src/video/texture/canvas_texture.js +62 -2
- package/src/video/video.js +1 -1
- package/src/video/webgl/buffer/vertex.js +22 -18
- package/src/video/webgl/compositors/compositor.js +79 -80
- package/src/video/webgl/compositors/primitive_compositor.js +68 -0
- package/src/video/webgl/compositors/{webgl_compositor.js → quad_compositor.js} +52 -109
- package/src/video/webgl/glshader.js +6 -6
- package/src/video/webgl/shaders/primitive.vert +2 -5
- package/src/video/webgl/shaders/quad.vert +3 -1
- package/src/video/webgl/utils/attributes.js +1 -1
- package/src/video/webgl/utils/program.js +6 -6
- package/src/video/webgl/utils/uniforms.js +3 -3
- package/src/video/webgl/webgl_renderer.js +186 -179
- 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/dist/melonjs.mjs/video/webgl/webgl_compositor.js +0 -494
- package/src/polyfill/performance.js +0 -20
- package/src/polyfill/requestAnimationFrame.js +0 -39
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
import Vector2d from "./../../math/vector2.js";
|
|
2
|
-
import WebGLRenderer from "./../webgl/webgl_renderer.js";
|
|
3
|
-
import TextureCache from "./../texture/cache.js";
|
|
4
2
|
import Sprite from "./../../renderable/sprite.js";
|
|
5
3
|
import { renderer } from "./../video.js";
|
|
6
4
|
import pool from "./../../system/pooling.js";
|
|
@@ -88,8 +86,8 @@ export class TextureAtlas {
|
|
|
88
86
|
if (typeof (atlases) !== "undefined") {
|
|
89
87
|
// normalize to array to keep the following code generic
|
|
90
88
|
atlases = Array.isArray(atlases) ? atlases : [atlases];
|
|
91
|
-
for (
|
|
92
|
-
|
|
89
|
+
for (let i in atlases) {
|
|
90
|
+
let atlas = atlases[i];
|
|
93
91
|
|
|
94
92
|
if (typeof(atlas.meta) !== "undefined") {
|
|
95
93
|
// Texture Packer or Free Texture Packer
|
|
@@ -98,7 +96,7 @@ export class TextureAtlas {
|
|
|
98
96
|
// set the texture
|
|
99
97
|
if (typeof(src) === "undefined") {
|
|
100
98
|
// get the texture name from the atlas meta data
|
|
101
|
-
|
|
99
|
+
let image = getImage(atlas.meta.image);
|
|
102
100
|
if (!image) {
|
|
103
101
|
throw new Error(
|
|
104
102
|
"Atlas texture '" + image + "' not found"
|
|
@@ -159,11 +157,7 @@ export class TextureAtlas {
|
|
|
159
157
|
// Add self to TextureCache if cache !== false
|
|
160
158
|
if (cache !== false) {
|
|
161
159
|
this.sources.forEach((source) => {
|
|
162
|
-
|
|
163
|
-
cache.set(source, this);
|
|
164
|
-
} else {
|
|
165
|
-
renderer.cache.set(source, this);
|
|
166
|
-
}
|
|
160
|
+
renderer.cache.set(source, this);
|
|
167
161
|
});
|
|
168
162
|
}
|
|
169
163
|
}
|
|
@@ -173,17 +167,17 @@ export class TextureAtlas {
|
|
|
173
167
|
* @ignore
|
|
174
168
|
*/
|
|
175
169
|
parse(data) {
|
|
176
|
-
|
|
170
|
+
let atlas = {};
|
|
177
171
|
|
|
178
172
|
data.frames.forEach((frame) => {
|
|
179
173
|
// fix wrongly formatted JSON (e.g. last dummy object in ShoeBox)
|
|
180
174
|
if (frame.hasOwnProperty("filename")) {
|
|
181
175
|
// Source coordinates
|
|
182
|
-
|
|
176
|
+
let s = frame.frame;
|
|
183
177
|
|
|
184
|
-
|
|
178
|
+
let originX, originY;
|
|
185
179
|
// Pixel-based offset origin from the top-left of the source frame
|
|
186
|
-
|
|
180
|
+
let hasTextureAnchorPoint = (frame.spriteSourceSize && frame.sourceSize && frame.pivot);
|
|
187
181
|
if (hasTextureAnchorPoint) {
|
|
188
182
|
originX = (frame.sourceSize.w * frame.pivot.x) - ((frame.trimmed) ? frame.spriteSourceSize.x : 0);
|
|
189
183
|
originY = (frame.sourceSize.h * frame.pivot.y) - ((frame.trimmed) ? frame.spriteSourceSize.y : 0);
|
|
@@ -210,16 +204,16 @@ export class TextureAtlas {
|
|
|
210
204
|
* @ignore
|
|
211
205
|
*/
|
|
212
206
|
parseFromSpriteSheet(data) {
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
207
|
+
let atlas = {};
|
|
208
|
+
let image = data.image;
|
|
209
|
+
let spacing = data.spacing || 0;
|
|
210
|
+
let margin = data.margin || 0;
|
|
217
211
|
|
|
218
|
-
|
|
219
|
-
|
|
212
|
+
let width = image.width;
|
|
213
|
+
let height = image.height;
|
|
220
214
|
|
|
221
215
|
// calculate the sprite count (line, col)
|
|
222
|
-
|
|
216
|
+
let spritecount = pool.pull("Vector2d",
|
|
223
217
|
~~((width - margin + spacing) / (data.framewidth + spacing)),
|
|
224
218
|
~~((height - margin + spacing) / (data.frameheight + spacing))
|
|
225
219
|
);
|
|
@@ -227,8 +221,8 @@ export class TextureAtlas {
|
|
|
227
221
|
// verifying the texture size
|
|
228
222
|
if ((width % (data.framewidth + spacing)) !== 0 ||
|
|
229
223
|
(height % (data.frameheight + spacing)) !== 0) {
|
|
230
|
-
|
|
231
|
-
|
|
224
|
+
let computed_width = spritecount.x * (data.framewidth + spacing);
|
|
225
|
+
let computed_height = spritecount.y * (data.frameheight + spacing);
|
|
232
226
|
if (computed_width - width !== spacing && computed_height - height !== spacing) {
|
|
233
227
|
// "truncate size" if delta is different from the spacing size
|
|
234
228
|
width = computed_width;
|
|
@@ -244,8 +238,8 @@ export class TextureAtlas {
|
|
|
244
238
|
}
|
|
245
239
|
|
|
246
240
|
// build the local atlas
|
|
247
|
-
for (
|
|
248
|
-
|
|
241
|
+
for (let frame = 0, count = spritecount.x * spritecount.y; frame < count; frame++) {
|
|
242
|
+
let name = "" + frame;
|
|
249
243
|
atlas[name] = {
|
|
250
244
|
name : name,
|
|
251
245
|
texture : "default", // the source texture
|
|
@@ -316,10 +310,10 @@ export class TextureAtlas {
|
|
|
316
310
|
console.warn("Adding texture region", name, "for texture", this);
|
|
317
311
|
}
|
|
318
312
|
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
313
|
+
let source = this.getTexture();
|
|
314
|
+
let atlas = this.getAtlas();
|
|
315
|
+
let dw = source.width;
|
|
316
|
+
let dh = source.height;
|
|
323
317
|
|
|
324
318
|
atlas[name] = {
|
|
325
319
|
name : name,
|
|
@@ -341,7 +335,7 @@ export class TextureAtlas {
|
|
|
341
335
|
* @returns {object}
|
|
342
336
|
*/
|
|
343
337
|
getRegion(name, atlas) {
|
|
344
|
-
|
|
338
|
+
let region;
|
|
345
339
|
if (typeof atlas === "string") {
|
|
346
340
|
region = this.getAtlas(atlas)[name];
|
|
347
341
|
} else {
|
|
@@ -364,11 +358,11 @@ export class TextureAtlas {
|
|
|
364
358
|
*/
|
|
365
359
|
getUVs(name) {
|
|
366
360
|
// Get the source texture region
|
|
367
|
-
|
|
361
|
+
let region = this.getRegion(name);
|
|
368
362
|
|
|
369
363
|
if (typeof(region) === "undefined") {
|
|
370
364
|
// TODO: Require proper atlas regions instead of caching arbitrary region keys
|
|
371
|
-
|
|
365
|
+
let keys = name.split(","),
|
|
372
366
|
sx = +keys[0],
|
|
373
367
|
sy = +keys[1],
|
|
374
368
|
sw = +keys[2],
|
|
@@ -388,11 +382,11 @@ export class TextureAtlas {
|
|
|
388
382
|
*/
|
|
389
383
|
addUVs(atlas, name, w, h) {
|
|
390
384
|
// ignore if using the Canvas Renderer
|
|
391
|
-
if (renderer
|
|
385
|
+
if (typeof renderer.gl !== "undefined") {
|
|
392
386
|
// Source coordinates
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
387
|
+
let s = atlas[name].offset;
|
|
388
|
+
let sw = atlas[name].width;
|
|
389
|
+
let sh = atlas[name].height;
|
|
396
390
|
|
|
397
391
|
atlas[name].uvs = new Float32Array([
|
|
398
392
|
s.x / w, // u0 (left)
|
|
@@ -402,7 +396,7 @@ export class TextureAtlas {
|
|
|
402
396
|
]);
|
|
403
397
|
// Cache source coordinates
|
|
404
398
|
// TODO: Remove this when the Batcher only accepts a region name
|
|
405
|
-
|
|
399
|
+
let key = s.x + "," + s.y + "," + w + "," + h;
|
|
406
400
|
atlas[key] = atlas[name];
|
|
407
401
|
}
|
|
408
402
|
return atlas[name].uvs;
|
|
@@ -423,13 +417,13 @@ export class TextureAtlas {
|
|
|
423
417
|
* ...
|
|
424
418
|
* ...
|
|
425
419
|
* // create a new "coin" sprite
|
|
426
|
-
*
|
|
420
|
+
* let sprite = game.texture.createSpriteFromName("coin.png");
|
|
427
421
|
* // set the renderable position to bottom center
|
|
428
422
|
* sprite.anchorPoint.set(0.5, 1.0);
|
|
429
423
|
* ...
|
|
430
424
|
* ...
|
|
431
425
|
* // create a 9-slice sprite
|
|
432
|
-
*
|
|
426
|
+
* let dialogPanel = game.texture.createSpriteFromName(
|
|
433
427
|
* "rpg_dialo.png",
|
|
434
428
|
* // width & height are mandatory for 9-slice sprites
|
|
435
429
|
* { width: this.width, height: this.height },
|
|
@@ -462,7 +456,7 @@ export class TextureAtlas {
|
|
|
462
456
|
* );
|
|
463
457
|
*
|
|
464
458
|
* // create a new Animated Sprite
|
|
465
|
-
*
|
|
459
|
+
* let sprite = game.texture.createAnimationFromName([
|
|
466
460
|
* "walk0001.png", "walk0002.png", "walk0003.png",
|
|
467
461
|
* "walk0004.png", "walk0005.png", "walk0006.png",
|
|
468
462
|
* "walk0007.png", "walk0008.png", "walk0009.png",
|
|
@@ -479,12 +473,12 @@ export class TextureAtlas {
|
|
|
479
473
|
* sprite.anchorPoint.set(0.5, 1.0);
|
|
480
474
|
*/
|
|
481
475
|
createAnimationFromName(names, settings) {
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
476
|
+
let tpAtlas = [], indices = {};
|
|
477
|
+
let width = 0, height = 0;
|
|
478
|
+
let region;
|
|
485
479
|
// iterate through the given names
|
|
486
480
|
// and create a "normalized" atlas
|
|
487
|
-
for (
|
|
481
|
+
for (let i = 0; i < names.length; ++i) {
|
|
488
482
|
region = this.getRegion(names[i]);
|
|
489
483
|
if (region == null) {
|
|
490
484
|
// throw an error
|
|
@@ -49,14 +49,14 @@ class TextureCache {
|
|
|
49
49
|
* @ignore
|
|
50
50
|
*/
|
|
51
51
|
get(image, atlas) {
|
|
52
|
-
|
|
52
|
+
let entry;
|
|
53
53
|
|
|
54
54
|
if (typeof atlas === "undefined") {
|
|
55
55
|
entry = this.cache.get(image)[0];
|
|
56
56
|
} else {
|
|
57
57
|
// manage cases where a specific atlas is specified
|
|
58
58
|
this.cache.forEach((value, key) => {
|
|
59
|
-
|
|
59
|
+
let _atlas = value.getAtlas()[0];
|
|
60
60
|
if (key === image && _atlas.width === atlas.framewidth && _atlas.height === atlas.frameheight) {
|
|
61
61
|
entry = value;
|
|
62
62
|
}
|
|
@@ -88,7 +88,7 @@ class TextureCache {
|
|
|
88
88
|
*/
|
|
89
89
|
tint(src, color) {
|
|
90
90
|
// make sure the src is in the cache
|
|
91
|
-
|
|
91
|
+
let image_cache = this.tinted.get(src);
|
|
92
92
|
|
|
93
93
|
if (image_cache === undefined) {
|
|
94
94
|
image_cache = this.tinted.set(src, new Map());
|
|
@@ -105,12 +105,12 @@ class TextureCache {
|
|
|
105
105
|
* @ignore
|
|
106
106
|
*/
|
|
107
107
|
set(image, texture) {
|
|
108
|
-
|
|
109
|
-
|
|
108
|
+
let width = image.width;
|
|
109
|
+
let height = image.height;
|
|
110
110
|
|
|
111
111
|
// warn if a non POT texture is added to the cache when using WebGL1
|
|
112
112
|
if (renderer.WebGLVersion === 1 && (!isPowerOfTwo(width) || !isPowerOfTwo(height))) {
|
|
113
|
-
|
|
113
|
+
let src = typeof image.src !== "undefined" ? image.src : image;
|
|
114
114
|
console.warn(
|
|
115
115
|
"[Texture] " + src + " is not a POT texture " +
|
|
116
116
|
"(" + width + "x" + height + ")"
|
|
@@ -3,7 +3,7 @@ import { setPrefixed } from "./../../utils/agent.js";
|
|
|
3
3
|
import { clamp } from "../../math/math.js";
|
|
4
4
|
|
|
5
5
|
// default canvas settings
|
|
6
|
-
|
|
6
|
+
let defaultAttributes = {
|
|
7
7
|
offscreenCanvas : false,
|
|
8
8
|
willReadFrequently : false,
|
|
9
9
|
antiAlias : false,
|
|
@@ -65,7 +65,7 @@ class CanvasTexture {
|
|
|
65
65
|
* @param {boolean} [enable=false]
|
|
66
66
|
*/
|
|
67
67
|
setAntiAlias(enable = false) {
|
|
68
|
-
|
|
68
|
+
let canvas = this.canvas;
|
|
69
69
|
|
|
70
70
|
// enable/disable antialias on the given Context2d object
|
|
71
71
|
setPrefixed("imageSmoothingEnabled", enable, this.context);
|
|
@@ -117,6 +117,66 @@ class CanvasTexture {
|
|
|
117
117
|
return this.context.getImageData(x, y, width, height);
|
|
118
118
|
}
|
|
119
119
|
|
|
120
|
+
/**
|
|
121
|
+
* creates a Blob object representing the image contained in this canvas texture
|
|
122
|
+
* @param {Object} [options] - An object with the following properties:
|
|
123
|
+
* @param {String} [options.type="image/png"] - A string indicating the image format
|
|
124
|
+
* @param {Number} [options.quality] - A Number between 0 and 1 indicating the image quality to be used when creating images using file formats that support lossy compression (such as image/jpeg or image/webp). A user agent will use its default quality value if this option is not specified, or if the number is outside the allowed range.
|
|
125
|
+
* @return {Promise} A Promise returning a Blob object representing the image contained in this canvas texture
|
|
126
|
+
* @example
|
|
127
|
+
* canvasTexture.convertToBlob().then((blob) => console.log(blob));
|
|
128
|
+
*/
|
|
129
|
+
toBlob(options) {
|
|
130
|
+
if (typeof this.canvas.convertToBlob === "function") {
|
|
131
|
+
return this.canvas.convertToBlob(options);
|
|
132
|
+
} else {
|
|
133
|
+
return new Promise(function(resolve) {
|
|
134
|
+
this.canvas.toBlob((blob) => {
|
|
135
|
+
resolve(blob);
|
|
136
|
+
}, options ? options.type : undefined, options ? options.quality : undefined);
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* creates an ImageBitmap object from the most recently rendered image of this canvas texture
|
|
143
|
+
* @param {Object} [options] - An object with the following properties:
|
|
144
|
+
* @param {String} [options.type="image/png"] - A string indicating the image format
|
|
145
|
+
* @param {Number} [options.quality] - A Number between 0 and 1 indicating the image quality to be used when creating images using file formats that support lossy compression (such as image/jpeg or image/webp). A user agent will use its default quality value if this option is not specified, or if the number is outside the allowed range.
|
|
146
|
+
* @return {Promise} A Promise returning an ImageBitmap.
|
|
147
|
+
* @example
|
|
148
|
+
* canvasTexture.transferToImageBitmap().then((bitmap) => console.log(bitmap));
|
|
149
|
+
*/
|
|
150
|
+
toImageBitmap(options) {
|
|
151
|
+
return new Promise((resolve) => {
|
|
152
|
+
if (typeof this.canvas.transferToImageBitmap === "function") {
|
|
153
|
+
resolve(this.canvas.transferToImageBitmap());
|
|
154
|
+
} else {
|
|
155
|
+
let image = new Image();
|
|
156
|
+
image.src = this.canvas.toDataURL(options);
|
|
157
|
+
image.onload = () => {
|
|
158
|
+
createImageBitmap(image).then((bitmap) => resolve(bitmap));
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* returns a data URL containing a representation of the most recently rendered image of this canvas texture
|
|
166
|
+
* (not supported by OffscreenCanvas)
|
|
167
|
+
* @param {Object} [options] - An object with the following properties:
|
|
168
|
+
* @param {String} [options.type="image/png"] - A string indicating the image format
|
|
169
|
+
* @param {Number} [options.quality] - A Number between 0 and 1 indicating the image quality to be used when creating images using file formats that support lossy compression (such as image/jpeg or image/webp). A user agent will use its default quality value if this option is not specified, or if the number is outside the allowed range.
|
|
170
|
+
* @return {Promise} A Promise returning a string containing the requested data URL.
|
|
171
|
+
* @example
|
|
172
|
+
* renderer.toDataURL().then((dataURL) => console.log(dataURL));
|
|
173
|
+
*/
|
|
174
|
+
toDataURL(options) {
|
|
175
|
+
return new Promise((resolve) => {
|
|
176
|
+
resolve(this.canvas.toDataURL(options));
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
|
|
120
180
|
/**
|
|
121
181
|
* @ignore
|
|
122
182
|
*/
|
package/src/video/video.js
CHANGED
|
@@ -149,7 +149,7 @@ export function init(width, height, options) {
|
|
|
149
149
|
* @returns {HTMLCanvasElement|OffscreenCanvas}
|
|
150
150
|
*/
|
|
151
151
|
export function createCanvas(width, height, returnOffscreenCanvas = false) {
|
|
152
|
-
|
|
152
|
+
let _canvas;
|
|
153
153
|
|
|
154
154
|
if (width === 0 || height === 0) {
|
|
155
155
|
throw new Error("width or height was zero, Canvas could not be initialized !");
|
|
@@ -7,18 +7,18 @@
|
|
|
7
7
|
|
|
8
8
|
export default class VertexArrayBuffer {
|
|
9
9
|
|
|
10
|
-
constructor(vertex_size,
|
|
10
|
+
constructor(vertex_size, vertex_per_obj) {
|
|
11
11
|
// the size of one vertex in float
|
|
12
12
|
this.vertexSize = vertex_size;
|
|
13
|
-
// size of
|
|
14
|
-
this.
|
|
13
|
+
// size of an object in vertex
|
|
14
|
+
this.objSize = vertex_per_obj;
|
|
15
15
|
// the maximum number of vertices the vertex array buffer can hold
|
|
16
|
-
this.maxVertex = 256;
|
|
16
|
+
this.maxVertex = 256; // (note: this seems to be the sweet spot performance-wise when using batching)
|
|
17
17
|
// the current number of vertices added to the vertex array buffer
|
|
18
18
|
this.vertexCount = 0;
|
|
19
19
|
|
|
20
20
|
// the actual vertex data buffer
|
|
21
|
-
this.buffer = new ArrayBuffer(this.maxVertex * this.vertexSize * this.
|
|
21
|
+
this.buffer = new ArrayBuffer(this.maxVertex * this.vertexSize * this.objSize);
|
|
22
22
|
// Float32 and Uint32 view of the vertex data array buffer
|
|
23
23
|
this.bufferF32 = new Float32Array(this.buffer);
|
|
24
24
|
this.bufferU32 = new Uint32Array(this.buffer);
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
* return true if full
|
|
38
38
|
* @ignore
|
|
39
39
|
*/
|
|
40
|
-
isFull(vertex = this.
|
|
40
|
+
isFull(vertex = this.objSize) {
|
|
41
41
|
return (this.vertexCount + vertex >= this.maxVertex);
|
|
42
42
|
}
|
|
43
43
|
|
|
@@ -45,14 +45,18 @@
|
|
|
45
45
|
* resize the vertex buffer, retaining its original contents
|
|
46
46
|
* @ignore
|
|
47
47
|
*/
|
|
48
|
-
resize() {
|
|
49
|
-
|
|
50
|
-
this.maxVertex
|
|
48
|
+
resize(vertexCount) {
|
|
49
|
+
|
|
50
|
+
while (vertexCount > this.maxVertex) {
|
|
51
|
+
// double the vertex size
|
|
52
|
+
this.maxVertex <<= 1;
|
|
53
|
+
}
|
|
54
|
+
|
|
51
55
|
// save a reference to the previous data
|
|
52
|
-
|
|
56
|
+
let data = this.bufferF32;
|
|
53
57
|
|
|
54
58
|
// recreate ArrayBuffer and views
|
|
55
|
-
this.buffer = new ArrayBuffer(this.maxVertex * this.vertexSize * this.
|
|
59
|
+
this.buffer = new ArrayBuffer(this.maxVertex * this.vertexSize * this.objSize);
|
|
56
60
|
this.bufferF32 = new Float32Array(this.buffer);
|
|
57
61
|
this.bufferU32 = new Uint32Array(this.buffer);
|
|
58
62
|
|
|
@@ -67,22 +71,22 @@
|
|
|
67
71
|
* @ignore
|
|
68
72
|
*/
|
|
69
73
|
push(x, y, u, v, tint) {
|
|
70
|
-
|
|
74
|
+
let offset = this.vertexCount * this.vertexSize;
|
|
71
75
|
|
|
72
76
|
if (this.vertexCount >= this.maxVertex) {
|
|
73
|
-
this.resize();
|
|
77
|
+
this.resize(this.vertexCount);
|
|
74
78
|
}
|
|
75
79
|
|
|
76
|
-
this.bufferF32[offset
|
|
77
|
-
this.bufferF32[offset
|
|
80
|
+
this.bufferF32[offset] = x;
|
|
81
|
+
this.bufferF32[++offset] = y;
|
|
78
82
|
|
|
79
83
|
if (typeof u !== "undefined") {
|
|
80
|
-
this.bufferF32[offset
|
|
81
|
-
this.bufferF32[offset
|
|
84
|
+
this.bufferF32[++offset] = u;
|
|
85
|
+
this.bufferF32[++offset] = v;
|
|
82
86
|
}
|
|
83
87
|
|
|
84
88
|
if (typeof tint !== "undefined") {
|
|
85
|
-
this.bufferU32[offset
|
|
89
|
+
this.bufferU32[++offset] = tint;
|
|
86
90
|
}
|
|
87
91
|
|
|
88
92
|
this.vertexCount++;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
1
|
+
import VertexArrayBuffer from "../buffer/vertex.js";
|
|
2
|
+
import GLShader from "../glshader.js";
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* @classdesc
|
|
@@ -8,19 +8,26 @@ import * as event from "../../../system/event.js";
|
|
|
8
8
|
export default class Compositor {
|
|
9
9
|
/**
|
|
10
10
|
* @param {WebGLRenderer} renderer - the current WebGL renderer session
|
|
11
|
+
* @param {Object} settings - additional settings to initialize this compositors
|
|
12
|
+
* @param {object[]} attribute - an array of attributes definition
|
|
13
|
+
* @param {string} attribute.name - name of the attribute in the vertex shader
|
|
14
|
+
* @param {number} attribute.size - number of components per vertex attribute. Must be 1, 2, 3, or 4.
|
|
15
|
+
* @param {GLenum} attribute.type - data type of each component in the array
|
|
16
|
+
* @param {boolean} attribute.normalized - whether integer data values should be normalized into a certain range when being cast to a float
|
|
17
|
+
* @param {number} attribute.offset - offset in bytes of the first component in the vertex attribute array
|
|
18
|
+
* @param {object} shader - an array of attributes definition
|
|
19
|
+
* @param {string} shader.vertex - a string containing the GLSL source code to set
|
|
20
|
+
* @param {string} shader.fragment - a string containing the GLSL source code to set
|
|
11
21
|
*/
|
|
12
|
-
constructor (renderer) {
|
|
13
|
-
this.init(renderer);
|
|
22
|
+
constructor (renderer, settings) {
|
|
23
|
+
this.init(renderer, settings);
|
|
14
24
|
}
|
|
15
25
|
|
|
16
26
|
/**
|
|
17
27
|
* Initialize the compositor
|
|
18
28
|
* @ignore
|
|
19
29
|
*/
|
|
20
|
-
init (renderer) {
|
|
21
|
-
// local reference
|
|
22
|
-
var gl = renderer.gl;
|
|
23
|
-
|
|
30
|
+
init (renderer, settings) {
|
|
24
31
|
// the associated renderer
|
|
25
32
|
this.renderer = renderer;
|
|
26
33
|
|
|
@@ -34,17 +41,23 @@ import * as event from "../../../system/event.js";
|
|
|
34
41
|
this.viewMatrix = renderer.currentTransform;
|
|
35
42
|
|
|
36
43
|
/**
|
|
37
|
-
*
|
|
44
|
+
* the default shader created by this compositor
|
|
38
45
|
* @type {GLShader}
|
|
39
46
|
*/
|
|
40
|
-
this.
|
|
47
|
+
this.defaultShader = undefined;
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* the shader currently used by this compositor
|
|
51
|
+
* @type {GLShader}
|
|
52
|
+
*/
|
|
53
|
+
this.currentShader = undefined;
|
|
41
54
|
|
|
42
55
|
/**
|
|
43
56
|
* primitive type to render (gl.POINTS, gl.LINE_STRIP, gl.LINE_LOOP, gl.LINES, gl.TRIANGLE_STRIP, gl.TRIANGLE_FAN, gl.TRIANGLES)
|
|
44
57
|
* @type {number}
|
|
45
58
|
* @default gl.TRIANGLES
|
|
46
59
|
*/
|
|
47
|
-
this.mode = gl.TRIANGLES;
|
|
60
|
+
this.mode = this.gl.TRIANGLES;
|
|
48
61
|
|
|
49
62
|
/**
|
|
50
63
|
* an array of vertex attribute properties
|
|
@@ -69,11 +82,28 @@ import * as event from "../../../system/event.js";
|
|
|
69
82
|
*/
|
|
70
83
|
this.vertexSize = 0;
|
|
71
84
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
85
|
+
/**
|
|
86
|
+
* the vertex data buffer used by this compositor
|
|
87
|
+
* @type {VertexArrayBuffer}
|
|
88
|
+
*/
|
|
89
|
+
this.vertexData = null;
|
|
90
|
+
|
|
91
|
+
// parse given attibrutes
|
|
92
|
+
if (typeof settings !== "undefined" && Array.isArray(settings.attributes)) {
|
|
93
|
+
settings.attributes.forEach((attr) => {
|
|
94
|
+
this.addAttribute(attr.name, attr.size, attr.type, attr.normalized, attr.offset);
|
|
95
|
+
this.vertexData = new VertexArrayBuffer(this.vertexSize, 6);
|
|
96
|
+
});
|
|
97
|
+
} else {
|
|
98
|
+
throw new Error("attributes definition missing");
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// parse and instantiate the default shader
|
|
102
|
+
if (typeof settings !== "undefined" && typeof settings.shader !== "undefined") {
|
|
103
|
+
this.defaultShader = new GLShader(this.gl, settings.shader.vertex, settings.shader.fragment);
|
|
104
|
+
} else {
|
|
105
|
+
throw new Error("shader definition missing");
|
|
106
|
+
}
|
|
77
107
|
}
|
|
78
108
|
|
|
79
109
|
/**
|
|
@@ -84,17 +114,35 @@ import * as event from "../../../system/event.js";
|
|
|
84
114
|
// WebGL context
|
|
85
115
|
this.gl = this.renderer.gl;
|
|
86
116
|
|
|
87
|
-
|
|
117
|
+
// clear the vertex data buffer
|
|
118
|
+
this.vertexData.clear();
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* @ignore
|
|
123
|
+
* called by the WebGL renderer when a compositor become the current one
|
|
124
|
+
*/
|
|
125
|
+
bind() {
|
|
126
|
+
if (this.renderer.currentProgram !== this.defaultShader.program) {
|
|
127
|
+
this.useShader(this.defaultShader);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
88
130
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
131
|
+
/**
|
|
132
|
+
* Select the shader to use for compositing
|
|
133
|
+
* @see GLShader
|
|
134
|
+
* @param {GLShader} shader - a reference to a GLShader instance
|
|
135
|
+
*/
|
|
136
|
+
useShader(shader) {
|
|
137
|
+
if (this.renderer.currentProgram !== shader.program) {
|
|
138
|
+
this.flush();
|
|
139
|
+
shader.bind();
|
|
140
|
+
shader.setUniform("uProjectionMatrix", this.renderer.projectionMatrix);
|
|
141
|
+
shader.setVertexAttributes(this.gl, this.attributes, this.vertexByteSize);
|
|
95
142
|
|
|
96
|
-
|
|
97
|
-
|
|
143
|
+
this.currentShader = shader;
|
|
144
|
+
this.renderer.currentProgram = this.currentShader.program;
|
|
145
|
+
}
|
|
98
146
|
}
|
|
99
147
|
|
|
100
148
|
/**
|
|
@@ -142,51 +190,25 @@ import * as event from "../../../system/event.js";
|
|
|
142
190
|
this.vertexSize = this.vertexByteSize / Float32Array.BYTES_PER_ELEMENT;
|
|
143
191
|
}
|
|
144
192
|
|
|
145
|
-
/**
|
|
146
|
-
* Sets the viewport
|
|
147
|
-
* @param {number} x - x position of viewport
|
|
148
|
-
* @param {number} y - y position of viewport
|
|
149
|
-
* @param {number} w - width of viewport
|
|
150
|
-
* @param {number} h - height of viewport
|
|
151
|
-
*/
|
|
152
|
-
setViewport(x, y, w, h) {
|
|
153
|
-
this.gl.viewport(x, y, w, h);
|
|
154
|
-
}
|
|
155
|
-
|
|
156
193
|
/**
|
|
157
194
|
* set/change the current projection matrix
|
|
158
195
|
* @param {Matrix3d} matrix
|
|
159
196
|
*/
|
|
160
197
|
setProjection(matrix) {
|
|
161
|
-
this.
|
|
198
|
+
this.currentShader.setUniform("uProjectionMatrix", matrix);
|
|
162
199
|
}
|
|
163
200
|
|
|
164
201
|
/**
|
|
165
|
-
*
|
|
166
|
-
* @see GLShader
|
|
167
|
-
* @param {GLShader} shader - a reference to a GLShader instance
|
|
168
|
-
*/
|
|
169
|
-
useShader(shader) {
|
|
170
|
-
if (this.activeShader !== shader) {
|
|
171
|
-
this.flush();
|
|
172
|
-
this.activeShader = shader;
|
|
173
|
-
this.activeShader.bind();
|
|
174
|
-
this.activeShader.setUniform("uProjectionMatrix", this.renderer.projectionMatrix);
|
|
175
|
-
this.activeShader.setVertexAttributes(this.gl, this.attributes, this.vertexByteSize);
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
/**
|
|
180
|
-
* Flush batched texture operations to the GPU
|
|
202
|
+
* Flush batched vertex data to the GPU
|
|
181
203
|
* @param {number} [mode=gl.TRIANGLES] - the GL drawing mode
|
|
182
204
|
*/
|
|
183
205
|
flush(mode = this.mode) {
|
|
184
|
-
|
|
185
|
-
|
|
206
|
+
let vertex = this.vertexData;
|
|
207
|
+
let vertexCount = vertex.vertexCount;
|
|
186
208
|
|
|
187
209
|
if (vertexCount > 0) {
|
|
188
|
-
|
|
189
|
-
|
|
210
|
+
let gl = this.gl;
|
|
211
|
+
let vertexSize = vertex.vertexSize;
|
|
190
212
|
|
|
191
213
|
// Copy data into stream buffer
|
|
192
214
|
if (this.renderer.WebGLVersion > 1) {
|
|
@@ -201,27 +223,4 @@ import * as event from "../../../system/event.js";
|
|
|
201
223
|
vertex.clear();
|
|
202
224
|
}
|
|
203
225
|
}
|
|
204
|
-
|
|
205
|
-
/**
|
|
206
|
-
* Clear the frame buffer
|
|
207
|
-
* @param {number} [alpha = 0.0] - the alpha value used when clearing the framebuffer
|
|
208
|
-
*/
|
|
209
|
-
clear(alpha = 0) {
|
|
210
|
-
var gl = this.gl;
|
|
211
|
-
gl.clearColor(0, 0, 0, alpha);
|
|
212
|
-
gl.clear(gl.COLOR_BUFFER_BIT | gl.STENCIL_BUFFER_BIT);
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
/**
|
|
216
|
-
* Specify the color values used when clearing color buffers. The values are clamped between 0 and 1.
|
|
217
|
-
* @param {number} [r = 0] - the red color value used when the color buffers are cleared
|
|
218
|
-
* @param {number} [g = 0] - the green color value used when the color buffers are cleared
|
|
219
|
-
* @param {number} [b = 0] - the blue color value used when the color buffers are cleared
|
|
220
|
-
* @param {number} [a = 0] - the alpha color value used when the color buffers are cleared
|
|
221
|
-
*/
|
|
222
|
-
clearColor(r = 0, g = 0, b = 0, a = 0) {
|
|
223
|
-
var gl = this.gl;
|
|
224
|
-
gl.clearColor(r, g, b, a);
|
|
225
|
-
gl.clear(gl.COLOR_BUFFER_BIT);
|
|
226
|
-
}
|
|
227
226
|
}
|