@vpmedia/phaser 1.0.1 → 1.0.3
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/README.md +20 -3
- package/dist/phaser.cjs +1 -1
- package/dist/phaser.cjs.LICENSE.txt +1 -1
- package/dist/phaser.cjs.map +1 -1
- package/dist/phaser.js +1 -1
- package/dist/phaser.js.LICENSE.txt +1 -1
- package/dist/phaser.js.map +1 -1
- package/package.json +23 -17
- package/src/index.js +142 -0
- package/src/phaser/core/animation.js +355 -0
- package/src/phaser/core/animation_manager.js +238 -0
- package/src/phaser/core/animation_parser.js +133 -0
- package/src/phaser/core/array_set.js +107 -0
- package/src/phaser/core/cache.js +558 -0
- package/src/phaser/core/const.js +106 -0
- package/src/phaser/core/device.js +67 -0
- package/src/phaser/core/device_util.js +388 -0
- package/src/phaser/core/dom.js +207 -0
- package/src/phaser/core/event_manager.js +243 -0
- package/src/phaser/core/factory.js +74 -0
- package/src/phaser/core/frame.js +75 -0
- package/src/phaser/core/frame_data.js +84 -0
- package/src/phaser/core/frame_util.js +33 -0
- package/src/phaser/core/game.js +412 -0
- package/src/phaser/core/input.js +401 -0
- package/src/phaser/core/input_button.js +102 -0
- package/src/phaser/core/input_handler.js +687 -0
- package/src/phaser/core/input_mouse.js +289 -0
- package/src/phaser/core/input_mspointer.js +197 -0
- package/src/phaser/core/input_pointer.js +427 -0
- package/src/phaser/core/input_touch.js +157 -0
- package/src/phaser/core/loader.js +1057 -0
- package/src/phaser/core/loader_parser.js +109 -0
- package/src/phaser/core/raf.js +46 -0
- package/src/phaser/core/raf_fb.js +75 -0
- package/src/phaser/core/raf_to.js +34 -0
- package/src/phaser/core/scale_manager.js +806 -0
- package/src/phaser/core/scene.js +65 -0
- package/src/phaser/core/scene_manager.js +309 -0
- package/src/phaser/core/signal.js +175 -0
- package/src/phaser/core/signal_binding.js +69 -0
- package/src/phaser/core/sound.js +538 -0
- package/src/phaser/core/sound_manager.js +364 -0
- package/src/phaser/core/stage.js +108 -0
- package/src/phaser/core/time.js +203 -0
- package/src/phaser/core/timer.js +276 -0
- package/src/phaser/core/timer_event.js +21 -0
- package/src/phaser/core/tween.js +329 -0
- package/src/phaser/core/tween_data.js +258 -0
- package/src/phaser/core/tween_easing.js +341 -0
- package/src/phaser/core/tween_manager.js +185 -0
- package/src/phaser/core/world.js +18 -0
- package/src/phaser/display/bitmap_text.js +322 -0
- package/src/phaser/display/button.js +194 -0
- package/src/phaser/display/canvas/buffer.js +36 -0
- package/src/phaser/display/canvas/graphics.js +227 -0
- package/src/phaser/display/canvas/masker.js +39 -0
- package/src/phaser/display/canvas/pool.js +126 -0
- package/src/phaser/display/canvas/renderer.js +123 -0
- package/src/phaser/display/canvas/tinter.js +144 -0
- package/src/phaser/display/canvas/util.js +159 -0
- package/src/phaser/display/display_object.js +597 -0
- package/src/phaser/display/graphics.js +723 -0
- package/src/phaser/display/graphics_data.js +27 -0
- package/src/phaser/display/graphics_data_util.js +15 -0
- package/src/phaser/display/group.js +227 -0
- package/src/phaser/display/image.js +288 -0
- package/src/phaser/display/sprite_batch.js +15 -0
- package/src/phaser/display/sprite_util.js +250 -0
- package/src/phaser/display/text.js +1089 -0
- package/src/phaser/display/webgl/abstract_filter.js +25 -0
- package/src/phaser/display/webgl/base_texture.js +68 -0
- package/src/phaser/display/webgl/blend_manager.js +35 -0
- package/src/phaser/display/webgl/earcut.js +662 -0
- package/src/phaser/display/webgl/earcut_node.js +28 -0
- package/src/phaser/display/webgl/fast_sprite_batch.js +242 -0
- package/src/phaser/display/webgl/filter_manager.js +46 -0
- package/src/phaser/display/webgl/filter_texture.js +61 -0
- package/src/phaser/display/webgl/graphics.js +624 -0
- package/src/phaser/display/webgl/graphics_data.js +42 -0
- package/src/phaser/display/webgl/mask_manager.js +36 -0
- package/src/phaser/display/webgl/render_texture.js +81 -0
- package/src/phaser/display/webgl/renderer.js +234 -0
- package/src/phaser/display/webgl/shader/complex.js +74 -0
- package/src/phaser/display/webgl/shader/fast.js +97 -0
- package/src/phaser/display/webgl/shader/normal.js +225 -0
- package/src/phaser/display/webgl/shader/primitive.js +72 -0
- package/src/phaser/display/webgl/shader/strip.js +77 -0
- package/src/phaser/display/webgl/shader_manager.js +89 -0
- package/src/phaser/display/webgl/sprite_batch.js +320 -0
- package/src/phaser/display/webgl/stencil_manager.js +170 -0
- package/src/phaser/display/webgl/texture.js +117 -0
- package/src/phaser/display/webgl/texture_util.js +34 -0
- package/src/phaser/display/webgl/util.js +78 -0
- package/src/phaser/geom/circle.js +186 -0
- package/src/phaser/geom/ellipse.js +65 -0
- package/src/phaser/geom/line.js +190 -0
- package/src/phaser/geom/matrix.js +147 -0
- package/src/phaser/geom/point.js +164 -0
- package/src/phaser/geom/polygon.js +140 -0
- package/src/phaser/geom/rectangle.js +306 -0
- package/src/phaser/geom/rounded_rectangle.js +36 -0
- package/src/phaser/geom/util/circle.js +122 -0
- package/src/phaser/geom/util/ellipse.js +34 -0
- package/src/phaser/geom/util/line.js +135 -0
- package/src/phaser/geom/util/matrix.js +53 -0
- package/src/phaser/geom/util/point.js +296 -0
- package/src/phaser/geom/util/polygon.js +28 -0
- package/src/phaser/geom/util/rectangle.js +229 -0
- package/src/phaser/geom/util/rounded_rectangle.js +32 -0
- package/src/phaser/util/math.js +297 -0
- package/src/phaser/util/string.js +32 -0
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @author Andras Csizmadia <andras@vpmedia.hu>
|
|
3
|
+
* @author Richard Davey <rich@photonstorm.com>
|
|
4
|
+
* @author Mat Groves http://matgroves.com/ @Doormat23
|
|
5
|
+
* @copyright Copyright (c) 2018-present Richard Davey, Photon Storm Ltd., Andras Csizmadia <andras@vpmedia.hu> (www.vpmedia.hu)
|
|
6
|
+
*/
|
|
7
|
+
import Rectangle from '../../geom/rectangle';
|
|
8
|
+
import Point from '../../geom/point';
|
|
9
|
+
import Texture from './texture';
|
|
10
|
+
import BaseTexture from './base_texture';
|
|
11
|
+
import FilterTexture from './filter_texture';
|
|
12
|
+
import CanvasBuffer from '../canvas/buffer';
|
|
13
|
+
import { RENDER_WEBGL } from '../../core/const';
|
|
14
|
+
|
|
15
|
+
export default class extends Texture {
|
|
16
|
+
|
|
17
|
+
constructor(width, height, renderer, scaleMode, resolution = 1) {
|
|
18
|
+
const w = width || 100;
|
|
19
|
+
const h = height || 100;
|
|
20
|
+
const res = resolution || 1;
|
|
21
|
+
const baseTexture = new BaseTexture(null, scaleMode || window.PhaserRegistry.TEXTURE_SCALE_MODE);
|
|
22
|
+
baseTexture.width = width * res;
|
|
23
|
+
baseTexture.height = height * res;
|
|
24
|
+
baseTexture._glTextures = [];
|
|
25
|
+
baseTexture.resolution = res;
|
|
26
|
+
baseTexture.scaleMode = scaleMode || window.PhaserRegistry.TEXTURE_SCALE_MODE;
|
|
27
|
+
baseTexture.hasLoaded = true;
|
|
28
|
+
super(baseTexture, new Rectangle(0, 0, w * res, h * res));
|
|
29
|
+
this.width = w;
|
|
30
|
+
this.height = h;
|
|
31
|
+
this.resolution = res;
|
|
32
|
+
this.frame = new Rectangle(0, 0, this.width * this.resolution, this.height * this.resolution);
|
|
33
|
+
this.crop = new Rectangle(0, 0, this.width * this.resolution, this.height * this.resolution);
|
|
34
|
+
this.renderer = renderer || window.PhaserRegistry.DEFAULT_RENDERER;
|
|
35
|
+
if (this.renderer.type === RENDER_WEBGL) {
|
|
36
|
+
const gl = this.renderer.gl;
|
|
37
|
+
this.baseTexture._dirty[gl.id] = false;
|
|
38
|
+
this.textureBuffer = new FilterTexture(gl, this.width, this.height, this.baseTexture.scaleMode);
|
|
39
|
+
this.baseTexture._glTextures[gl.id] = this.textureBuffer.texture;
|
|
40
|
+
this.render = this.renderWebGL;
|
|
41
|
+
this.projection = new Point(this.width * 0.5, -this.height * 0.5);
|
|
42
|
+
} else {
|
|
43
|
+
this.render = this.renderCanvas;
|
|
44
|
+
this.textureBuffer = new CanvasBuffer(this.width * this.resolution, this.height * this.resolution);
|
|
45
|
+
this.baseTexture.source = this.textureBuffer.canvas;
|
|
46
|
+
}
|
|
47
|
+
this.valid = true;
|
|
48
|
+
this._updateUvs();
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
resize() {
|
|
52
|
+
// TODO
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
clear() {
|
|
56
|
+
// TODO
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
renderWebGL() {
|
|
60
|
+
// TODO
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
renderCanvas() {
|
|
64
|
+
// TODO
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
getImage() {
|
|
68
|
+
const image = new Image();
|
|
69
|
+
image.src = this.getBase64();
|
|
70
|
+
return image;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
getBase64() {
|
|
74
|
+
return this.getCanvas().toDataURL();
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
getCanvas() {
|
|
78
|
+
// TODO
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
}
|
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @author Andras Csizmadia <andras@vpmedia.hu>
|
|
3
|
+
* @author Richard Davey <rich@photonstorm.com>
|
|
4
|
+
* @author Mat Groves http://matgroves.com/ @Doormat23
|
|
5
|
+
* @copyright Copyright (c) 2018-present Richard Davey, Photon Storm Ltd., Andras Csizmadia <andras@vpmedia.hu> (www.vpmedia.hu)
|
|
6
|
+
*/
|
|
7
|
+
import { RENDER_WEBGL, SCALE_LINEAR, BLEND_NORMAL, BLEND_ADD, BLEND_MULTIPLY, BLEND_SCREEN, BLEND_OVERLAY, BLEND_DARKEN, BLEND_LIGHTEN, BLEND_COLOR_DODGE, BLEND_COLOR_BURN, BLEND_HARD_LIGHT, BLEND_SOFT_LIGHT, BLEND_DIFFERENCE, BLEND_EXCLUSION, BLEND_HUE, BLEND_SATURATION, BLEND_COLOR, BLEND_LUMINOSITY } from '../../core/const';
|
|
8
|
+
import { remove } from '../canvas/pool';
|
|
9
|
+
import { isPowerOfTwo } from '../../util/math';
|
|
10
|
+
import Point from '../../geom/point';
|
|
11
|
+
import WebGLShaderManager from './shader_manager';
|
|
12
|
+
import WebGLSpriteBatch from './sprite_batch';
|
|
13
|
+
import * as WebGLMaskManager from './mask_manager';
|
|
14
|
+
import WebGLFilterManager from './filter_manager';
|
|
15
|
+
import WebGLStencilManager from './stencil_manager';
|
|
16
|
+
import WebGLBlendModeManager from './blend_manager';
|
|
17
|
+
|
|
18
|
+
export default class {
|
|
19
|
+
|
|
20
|
+
constructor(game) {
|
|
21
|
+
this.type = RENDER_WEBGL;
|
|
22
|
+
this.resolution = game.config.resolution;
|
|
23
|
+
this.autoResize = false;
|
|
24
|
+
this.clearBeforeRender = game.config.clearBeforeRender;
|
|
25
|
+
this.width = game.width;
|
|
26
|
+
this.height = game.height;
|
|
27
|
+
this.view = game.canvas;
|
|
28
|
+
this._contextOptions = {
|
|
29
|
+
alpha: game.config.transparent,
|
|
30
|
+
depth: false,
|
|
31
|
+
antialias: game.config.antialias,
|
|
32
|
+
premultipliedAlpha: game.config.transparent && game.config.transparent !== 'notMultiplied',
|
|
33
|
+
stencil: true,
|
|
34
|
+
failIfMajorPerformanceCaveat: false,
|
|
35
|
+
preserveDrawingBuffer: game.config.preserveDrawingBuffer,
|
|
36
|
+
};
|
|
37
|
+
this.projection = new Point();
|
|
38
|
+
this.offset = new Point();
|
|
39
|
+
this.shaderManager = new WebGLShaderManager();
|
|
40
|
+
this.spriteBatch = new WebGLSpriteBatch();
|
|
41
|
+
this.filterManager = new WebGLFilterManager();
|
|
42
|
+
this.stencilManager = new WebGLStencilManager();
|
|
43
|
+
this.blendModeManager = new WebGLBlendModeManager();
|
|
44
|
+
this.renderSession = {};
|
|
45
|
+
this.renderSession.gl = this.gl;
|
|
46
|
+
this.renderSession.drawCount = 0;
|
|
47
|
+
this.renderSession.shaderManager = this.shaderManager;
|
|
48
|
+
this.renderSession.maskManager = WebGLMaskManager;
|
|
49
|
+
this.renderSession.filterManager = this.filterManager;
|
|
50
|
+
this.renderSession.blendModeManager = this.blendModeManager;
|
|
51
|
+
this.renderSession.spriteBatch = this.spriteBatch;
|
|
52
|
+
this.renderSession.stencilManager = this.stencilManager;
|
|
53
|
+
this.renderSession.renderer = this;
|
|
54
|
+
this.renderSession.resolution = this.resolution;
|
|
55
|
+
this.initContext();
|
|
56
|
+
this.mapBlendModes();
|
|
57
|
+
window.PhaserRegistry.DEFAULT_RENDERER = this;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
destroy() {
|
|
61
|
+
window.PhaserRegistry.GL_CONTEXTS[this.glContextId] = null;
|
|
62
|
+
this.projection = null;
|
|
63
|
+
this.offset = null;
|
|
64
|
+
this.shaderManager.destroy();
|
|
65
|
+
this.spriteBatch.destroy();
|
|
66
|
+
this.filterManager.destroy();
|
|
67
|
+
this.shaderManager = null;
|
|
68
|
+
this.spriteBatch = null;
|
|
69
|
+
this.filterManager = null;
|
|
70
|
+
if (this.gl) {
|
|
71
|
+
this.gl.canvas.width = 1;
|
|
72
|
+
this.gl.canvas.height = 1;
|
|
73
|
+
const loseContextExt = this.gl.getExtension('WEBGL_lose_context');
|
|
74
|
+
if (loseContextExt) {
|
|
75
|
+
loseContextExt.loseContext();
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
this.gl = null;
|
|
79
|
+
this.renderSession = null;
|
|
80
|
+
remove(this);
|
|
81
|
+
window.PhaserRegistry.INSTANCES[this.glContextId] = null;
|
|
82
|
+
window.PhaserRegistry.DEFAULT_RENDERER = null;
|
|
83
|
+
window.PhaserRegistry.GL_CONTEXT_ID -= 1;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
initRegistry() {
|
|
87
|
+
if (!window.PhaserRegistry.GL_CONTEXT_ID) {
|
|
88
|
+
window.PhaserRegistry.GL_CONTEXT_ID = 0;
|
|
89
|
+
}
|
|
90
|
+
if (!window.PhaserRegistry.GL_CONTEXTS) {
|
|
91
|
+
window.PhaserRegistry.GL_CONTEXTS = [];
|
|
92
|
+
}
|
|
93
|
+
if (!window.PhaserRegistry.INSTANCES) {
|
|
94
|
+
window.PhaserRegistry.INSTANCES = [];
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
initContext() {
|
|
99
|
+
const gl = this.view.getContext('webgl', this._contextOptions) || this.view.getContext('experimental-webgl', this._contextOptions);
|
|
100
|
+
this.gl = gl;
|
|
101
|
+
if (!gl) {
|
|
102
|
+
// fail, not able to get a context
|
|
103
|
+
throw new Error('This browser does not support WebGL. Try using the Canvas 2D.');
|
|
104
|
+
}
|
|
105
|
+
this.initRegistry();
|
|
106
|
+
this.glContextId = window.PhaserRegistry.GL_CONTEXT_ID;
|
|
107
|
+
gl.id = window.PhaserRegistry.GL_CONTEXT_ID;
|
|
108
|
+
window.PhaserRegistry.GL_CONTEXTS[this.glContextId] = gl;
|
|
109
|
+
window.PhaserRegistry.INSTANCES[this.glContextId] = this;
|
|
110
|
+
window.PhaserRegistry.GL_CONTEXT_ID += 1;
|
|
111
|
+
// set up the default pixi settings..
|
|
112
|
+
gl.disable(gl.DEPTH_TEST);
|
|
113
|
+
gl.disable(gl.CULL_FACE);
|
|
114
|
+
gl.enable(gl.BLEND);
|
|
115
|
+
// need to set the context for all the managers...
|
|
116
|
+
this.shaderManager.setContext(gl);
|
|
117
|
+
this.spriteBatch.setContext(gl);
|
|
118
|
+
this.stencilManager.setContext(gl);
|
|
119
|
+
this.filterManager.setContext(gl);
|
|
120
|
+
this.blendModeManager.setContext(gl);
|
|
121
|
+
this.renderSession.gl = this.gl;
|
|
122
|
+
// now resize and we are good to go!
|
|
123
|
+
this.resize(this.width, this.height);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
render(stage) {
|
|
127
|
+
if (this.contextLost) {
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
const gl = this.gl;
|
|
131
|
+
// -- Does this need to be set every frame? -- //
|
|
132
|
+
gl.viewport(0, 0, this.width, this.height);
|
|
133
|
+
// make sure we are bound to the main frame buffer
|
|
134
|
+
gl.bindFramebuffer(gl.FRAMEBUFFER, null);
|
|
135
|
+
if (this.clearBeforeRender) {
|
|
136
|
+
gl.clearColor(stage._bgColor.r, stage._bgColor.g, stage._bgColor.b, stage._bgColor.a);
|
|
137
|
+
gl.clear(gl.COLOR_BUFFER_BIT);
|
|
138
|
+
}
|
|
139
|
+
this.offset.x = 0;
|
|
140
|
+
this.offset.y = 0;
|
|
141
|
+
this.renderDisplayObject(stage, this.projection);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
renderDisplayObject(displayObject, projection, buffer, matrix) {
|
|
145
|
+
this.renderSession.blendModeManager.setBlendMode(BLEND_NORMAL);
|
|
146
|
+
// reset the render session data..
|
|
147
|
+
this.renderSession.drawCount = 0;
|
|
148
|
+
// make sure to flip the Y if using a render texture..
|
|
149
|
+
this.renderSession.flipY = buffer ? -1 : 1;
|
|
150
|
+
// set the default projection
|
|
151
|
+
this.renderSession.projection = projection;
|
|
152
|
+
// set the default offset
|
|
153
|
+
this.renderSession.offset = this.offset;
|
|
154
|
+
// start the sprite batch
|
|
155
|
+
this.spriteBatch.begin(this.renderSession);
|
|
156
|
+
// start the filter manager
|
|
157
|
+
this.filterManager.begin(this.renderSession, buffer);
|
|
158
|
+
// render the scene!
|
|
159
|
+
displayObject.renderWebGL(this.renderSession, matrix);
|
|
160
|
+
// finish the sprite batch
|
|
161
|
+
this.spriteBatch.end();
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
resize(width, height) {
|
|
165
|
+
this.width = width * this.resolution;
|
|
166
|
+
this.height = height * this.resolution;
|
|
167
|
+
this.view.width = this.width;
|
|
168
|
+
this.view.height = this.height;
|
|
169
|
+
if (this.autoResize) {
|
|
170
|
+
this.view.style.width = this.width / this.resolution + 'px';
|
|
171
|
+
this.view.style.height = this.height / this.resolution + 'px';
|
|
172
|
+
}
|
|
173
|
+
this.gl.viewport(0, 0, this.width, this.height);
|
|
174
|
+
this.projection.x = this.width / 2 / this.resolution;
|
|
175
|
+
this.projection.y = -this.height / 2 / this.resolution;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
updateTexture(texture) {
|
|
179
|
+
if (!texture.hasLoaded) {
|
|
180
|
+
return false;
|
|
181
|
+
}
|
|
182
|
+
const gl = this.gl;
|
|
183
|
+
if (!texture._glTextures[gl.id]) {
|
|
184
|
+
texture._glTextures[gl.id] = gl.createTexture();
|
|
185
|
+
}
|
|
186
|
+
gl.bindTexture(gl.TEXTURE_2D, texture._glTextures[gl.id]);
|
|
187
|
+
gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, texture.premultipliedAlpha);
|
|
188
|
+
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, texture.source);
|
|
189
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, texture.scaleMode === SCALE_LINEAR ? gl.LINEAR : gl.NEAREST);
|
|
190
|
+
if (texture.mipmap && isPowerOfTwo(texture.width, texture.height)) {
|
|
191
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, texture.scaleMode === SCALE_LINEAR ? gl.LINEAR_MIPMAP_LINEAR : gl.NEAREST_MIPMAP_NEAREST);
|
|
192
|
+
gl.generateMipmap(gl.TEXTURE_2D);
|
|
193
|
+
} else {
|
|
194
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, texture.scaleMode === SCALE_LINEAR ? gl.LINEAR : gl.NEAREST);
|
|
195
|
+
}
|
|
196
|
+
if (!texture._powerOf2) {
|
|
197
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
|
|
198
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
|
|
199
|
+
} else {
|
|
200
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.REPEAT);
|
|
201
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.REPEAT);
|
|
202
|
+
}
|
|
203
|
+
texture._dirty[gl.id] = false;
|
|
204
|
+
// return texture._glTextures[gl.id];
|
|
205
|
+
return true;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
mapBlendModes() {
|
|
209
|
+
if (window.PhaserRegistry.blendModesWebGL) {
|
|
210
|
+
return;
|
|
211
|
+
}
|
|
212
|
+
const gl = this.gl;
|
|
213
|
+
const b = [];
|
|
214
|
+
b[BLEND_NORMAL] = [gl.ONE, gl.ONE_MINUS_SRC_ALPHA];
|
|
215
|
+
b[BLEND_ADD] = [gl.SRC_ALPHA, gl.DST_ALPHA];
|
|
216
|
+
b[BLEND_MULTIPLY] = [gl.DST_COLOR, gl.ONE_MINUS_SRC_ALPHA];
|
|
217
|
+
b[BLEND_SCREEN] = [gl.SRC_ALPHA, gl.ONE];
|
|
218
|
+
b[BLEND_OVERLAY] = [gl.ONE, gl.ONE_MINUS_SRC_ALPHA];
|
|
219
|
+
b[BLEND_DARKEN] = [gl.ONE, gl.ONE_MINUS_SRC_ALPHA];
|
|
220
|
+
b[BLEND_LIGHTEN] = [gl.ONE, gl.ONE_MINUS_SRC_ALPHA];
|
|
221
|
+
b[BLEND_COLOR_DODGE] = [gl.ONE, gl.ONE_MINUS_SRC_ALPHA];
|
|
222
|
+
b[BLEND_COLOR_BURN] = [gl.ONE, gl.ONE_MINUS_SRC_ALPHA];
|
|
223
|
+
b[BLEND_HARD_LIGHT] = [gl.ONE, gl.ONE_MINUS_SRC_ALPHA];
|
|
224
|
+
b[BLEND_SOFT_LIGHT] = [gl.ONE, gl.ONE_MINUS_SRC_ALPHA];
|
|
225
|
+
b[BLEND_DIFFERENCE] = [gl.ONE, gl.ONE_MINUS_SRC_ALPHA];
|
|
226
|
+
b[BLEND_EXCLUSION] = [gl.ONE, gl.ONE_MINUS_SRC_ALPHA];
|
|
227
|
+
b[BLEND_HUE] = [gl.ONE, gl.ONE_MINUS_SRC_ALPHA];
|
|
228
|
+
b[BLEND_SATURATION] = [gl.ONE, gl.ONE_MINUS_SRC_ALPHA];
|
|
229
|
+
b[BLEND_COLOR] = [gl.ONE, gl.ONE_MINUS_SRC_ALPHA];
|
|
230
|
+
b[BLEND_LUMINOSITY] = [gl.ONE, gl.ONE_MINUS_SRC_ALPHA];
|
|
231
|
+
window.PhaserRegistry.blendModesWebGL = b;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @author Andras Csizmadia <andras@vpmedia.hu>
|
|
3
|
+
* @author Richard Davey <rich@photonstorm.com>
|
|
4
|
+
* @author Mat Groves http://matgroves.com/ @Doormat23
|
|
5
|
+
* @copyright Copyright (c) 2018-present Richard Davey, Photon Storm Ltd., Andras Csizmadia <andras@vpmedia.hu> (www.vpmedia.hu)
|
|
6
|
+
*/
|
|
7
|
+
import { generateShaderID } from '../../../util/string';
|
|
8
|
+
import { compileProgram } from '../util';
|
|
9
|
+
|
|
10
|
+
// the next one is used for rendering triangle strips
|
|
11
|
+
|
|
12
|
+
export default class {
|
|
13
|
+
|
|
14
|
+
constructor(gl) {
|
|
15
|
+
this.gl = gl;
|
|
16
|
+
this._UID = generateShaderID();
|
|
17
|
+
this.program = null;
|
|
18
|
+
this.fragmentSrc = [
|
|
19
|
+
'precision mediump float;',
|
|
20
|
+
'varying vec4 vColor;',
|
|
21
|
+
'void main(void) {',
|
|
22
|
+
' gl_FragColor = vColor;',
|
|
23
|
+
'}',
|
|
24
|
+
];
|
|
25
|
+
this.vertexSrc = [
|
|
26
|
+
'attribute vec2 aVertexPosition;',
|
|
27
|
+
// 'attribute vec4 aColor;',
|
|
28
|
+
'uniform mat3 translationMatrix;',
|
|
29
|
+
'uniform vec2 projectionVector;',
|
|
30
|
+
'uniform vec2 offsetVector;',
|
|
31
|
+
|
|
32
|
+
'uniform vec3 tint;',
|
|
33
|
+
'uniform float alpha;',
|
|
34
|
+
'uniform vec3 color;',
|
|
35
|
+
'uniform float flipY;',
|
|
36
|
+
'varying vec4 vColor;',
|
|
37
|
+
|
|
38
|
+
'void main(void) {',
|
|
39
|
+
' vec3 v = translationMatrix * vec3(aVertexPosition , 1.0);',
|
|
40
|
+
' v -= offsetVector.xyx;',
|
|
41
|
+
' gl_Position = vec4( v.x / projectionVector.x -1.0, (v.y / projectionVector.y * -flipY) + flipY , 0.0, 1.0);',
|
|
42
|
+
' vColor = vec4(color * alpha * tint, alpha);', // " * vec4(tint * alpha, alpha);',
|
|
43
|
+
'}',
|
|
44
|
+
];
|
|
45
|
+
this.init();
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
init() {
|
|
49
|
+
const gl = this.gl;
|
|
50
|
+
const program = compileProgram(gl, this.vertexSrc, this.fragmentSrc);
|
|
51
|
+
gl.useProgram(program);
|
|
52
|
+
// get and store the uniforms for the shader
|
|
53
|
+
this.projectionVector = gl.getUniformLocation(program, 'projectionVector');
|
|
54
|
+
this.offsetVector = gl.getUniformLocation(program, 'offsetVector');
|
|
55
|
+
this.tintColor = gl.getUniformLocation(program, 'tint');
|
|
56
|
+
this.color = gl.getUniformLocation(program, 'color');
|
|
57
|
+
this.flipY = gl.getUniformLocation(program, 'flipY');
|
|
58
|
+
// get and store the attributes
|
|
59
|
+
this.aVertexPosition = gl.getAttribLocation(program, 'aVertexPosition');
|
|
60
|
+
// this.colorAttribute = gl.getAttribLocation(program, 'aColor');
|
|
61
|
+
this.attributes = [this.aVertexPosition, this.colorAttribute];
|
|
62
|
+
this.translationMatrix = gl.getUniformLocation(program, 'translationMatrix');
|
|
63
|
+
this.alpha = gl.getUniformLocation(program, 'alpha');
|
|
64
|
+
this.program = program;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
destroy() {
|
|
68
|
+
this.gl.deleteProgram(this.program);
|
|
69
|
+
this.uniforms = null;
|
|
70
|
+
this.gl = null;
|
|
71
|
+
this.attribute = null;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @author Andras Csizmadia <andras@vpmedia.hu>
|
|
3
|
+
* @author Richard Davey <rich@photonstorm.com>
|
|
4
|
+
* @author Mat Groves http://matgroves.com/ @Doormat23
|
|
5
|
+
* @copyright Copyright (c) 2018-present Richard Davey, Photon Storm Ltd., Andras Csizmadia <andras@vpmedia.hu> (www.vpmedia.hu)
|
|
6
|
+
*/
|
|
7
|
+
import { generateShaderID } from '../../../util/string';
|
|
8
|
+
import { compileProgram } from '../util';
|
|
9
|
+
|
|
10
|
+
// this shader is used for the fast sprite rendering
|
|
11
|
+
|
|
12
|
+
export default class {
|
|
13
|
+
|
|
14
|
+
constructor(gl) {
|
|
15
|
+
this.gl = gl;
|
|
16
|
+
this._UID = generateShaderID();
|
|
17
|
+
this.program = null;
|
|
18
|
+
this.textureCount = 0;
|
|
19
|
+
this.fragmentSrc = [
|
|
20
|
+
'precision lowp float;',
|
|
21
|
+
'varying vec2 vTextureCoord;',
|
|
22
|
+
'varying float vColor;',
|
|
23
|
+
'uniform sampler2D uSampler;',
|
|
24
|
+
'void main(void) {',
|
|
25
|
+
' gl_FragColor = texture2D(uSampler, vTextureCoord) * vColor ;',
|
|
26
|
+
'}',
|
|
27
|
+
];
|
|
28
|
+
this.vertexSrc = [
|
|
29
|
+
'attribute vec2 aVertexPosition;',
|
|
30
|
+
'attribute vec2 aPositionCoord;',
|
|
31
|
+
'attribute vec2 aScale;',
|
|
32
|
+
'attribute float aRotation;',
|
|
33
|
+
'attribute vec2 aTextureCoord;',
|
|
34
|
+
'attribute float aColor;',
|
|
35
|
+
|
|
36
|
+
'uniform vec2 projectionVector;',
|
|
37
|
+
'uniform vec2 offsetVector;',
|
|
38
|
+
'uniform mat3 uMatrix;',
|
|
39
|
+
|
|
40
|
+
'varying vec2 vTextureCoord;',
|
|
41
|
+
'varying float vColor;',
|
|
42
|
+
|
|
43
|
+
'const vec2 center = vec2(-1.0, 1.0);',
|
|
44
|
+
|
|
45
|
+
'void main(void) {',
|
|
46
|
+
' vec2 v;',
|
|
47
|
+
' vec2 sv = aVertexPosition * aScale;',
|
|
48
|
+
' v.x = (sv.x) * cos(aRotation) - (sv.y) * sin(aRotation);',
|
|
49
|
+
' v.y = (sv.x) * sin(aRotation) + (sv.y) * cos(aRotation);',
|
|
50
|
+
' v = ( uMatrix * vec3(v + aPositionCoord , 1.0) ).xy ;',
|
|
51
|
+
' gl_Position = vec4( ( v / projectionVector) + center , 0.0, 1.0);',
|
|
52
|
+
' vTextureCoord = aTextureCoord;',
|
|
53
|
+
// ' vec3 color = mod(vec3(aColor.y/65536.0, aColor.y/256.0, aColor.y), 256.0) / 256.0;',
|
|
54
|
+
' vColor = aColor;',
|
|
55
|
+
'}',
|
|
56
|
+
];
|
|
57
|
+
this.init();
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
init() {
|
|
61
|
+
const gl = this.gl;
|
|
62
|
+
const program = compileProgram(gl, this.vertexSrc, this.fragmentSrc);
|
|
63
|
+
gl.useProgram(program);
|
|
64
|
+
// get and store the uniforms for the shader
|
|
65
|
+
this.uSampler = gl.getUniformLocation(program, 'uSampler');
|
|
66
|
+
this.projectionVector = gl.getUniformLocation(program, 'projectionVector');
|
|
67
|
+
this.offsetVector = gl.getUniformLocation(program, 'offsetVector');
|
|
68
|
+
this.dimensions = gl.getUniformLocation(program, 'dimensions');
|
|
69
|
+
this.uMatrix = gl.getUniformLocation(program, 'uMatrix');
|
|
70
|
+
// get and store the attributes
|
|
71
|
+
this.aVertexPosition = gl.getAttribLocation(program, 'aVertexPosition');
|
|
72
|
+
this.aPositionCoord = gl.getAttribLocation(program, 'aPositionCoord');
|
|
73
|
+
this.aScale = gl.getAttribLocation(program, 'aScale');
|
|
74
|
+
this.aRotation = gl.getAttribLocation(program, 'aRotation');
|
|
75
|
+
this.aTextureCoord = gl.getAttribLocation(program, 'aTextureCoord');
|
|
76
|
+
this.colorAttribute = gl.getAttribLocation(program, 'aColor');
|
|
77
|
+
// Begin worst hack eva //
|
|
78
|
+
// WHY??? ONLY on my chrome pixel the line above returns -1 when using filters?
|
|
79
|
+
// maybe its somthing to do with the current state of the gl context.
|
|
80
|
+
// Im convinced this is a bug in the chrome browser as there is NO reason why this should be returning -1 especially as it only manifests on my chrome pixel
|
|
81
|
+
// If theres any webGL people that know why could happen please help :)
|
|
82
|
+
if (this.colorAttribute === -1) {
|
|
83
|
+
this.colorAttribute = 2;
|
|
84
|
+
}
|
|
85
|
+
this.attributes = [this.aVertexPosition, this.aPositionCoord, this.aScale, this.aRotation, this.aTextureCoord, this.colorAttribute];
|
|
86
|
+
// End worst hack eva //
|
|
87
|
+
this.program = program;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
destroy() {
|
|
91
|
+
this.gl.deleteProgram(this.program);
|
|
92
|
+
this.uniforms = null;
|
|
93
|
+
this.gl = null;
|
|
94
|
+
this.attributes = null;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
}
|