p5 2.0.0 → 2.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/{src → dist}/accessibility/color_namer.js +48 -3
- package/{src → dist}/accessibility/describe.js +2 -2
- package/{src → dist}/accessibility/gridOutput.js +2 -2
- package/dist/accessibility/index.js +60 -0
- package/{src → dist}/accessibility/outputs.js +2 -2
- package/{src → dist}/accessibility/textOutput.js +2 -2
- package/dist/app.js +120 -0
- package/{src → dist}/color/color_conversion.js +48 -10
- package/{src → dist}/color/color_spaces/hsb.js +3 -1
- package/dist/color/creating_reading.js +3 -0
- package/dist/color/index.js +13 -0
- package/dist/color/p5.Color.culori.js +1 -0
- package/dist/color/p5.Color.js +3 -0
- package/{src → dist}/color/setting.js +9 -6
- package/{src/core/constants.js → dist/constants-C-g_eAdC.js} +266 -130
- package/{src → dist}/core/States.js +3 -1
- package/dist/core/constants.js +1 -0
- package/{src → dist}/core/environment.js +7 -6
- package/{src → dist}/core/friendly_errors/browser_errors.js +1 -1
- package/{src → dist}/core/friendly_errors/fes_core.js +14 -44
- package/{src → dist}/core/friendly_errors/file_errors.js +6 -3
- package/dist/core/friendly_errors/index.js +23 -0
- package/dist/core/friendly_errors/param_validator.js +5455 -0
- package/{src → dist}/core/friendly_errors/sketch_reader.js +50 -4
- package/{src → dist}/core/friendly_errors/sketch_verifier.js +6 -6
- package/{src → dist}/core/friendly_errors/stacktrace.js +3 -5
- package/{src → dist}/core/friendly_errors/validate_params.js +50 -41
- package/{src → dist}/core/helpers.js +9 -6
- package/dist/core/init.js +105 -0
- package/dist/core/internationalization.js +302 -0
- package/dist/core/legacy.js +73 -0
- package/dist/core/main.js +44 -0
- package/dist/core/noop.js +3 -0
- package/dist/core/p5.Graphics.js +40 -0
- package/dist/core/p5.Renderer.js +11 -0
- package/dist/core/p5.Renderer2D.js +44 -0
- package/dist/core/reference.js +1 -0
- package/dist/core/rendering.js +40 -0
- package/{src → dist}/core/structure.js +3 -3
- package/{src → dist}/core/transform.js +2 -2
- package/{src/color/creating_reading.js → dist/creating_reading-D4AAKRbx.js} +841 -13
- package/{src → dist}/data/index.js +3 -1
- package/{src → dist}/data/local_storage.js +2 -8
- package/{src → dist}/dom/dom.js +11 -5
- package/dist/dom/index.js +18 -0
- package/{src → dist}/dom/p5.Element.js +14 -12
- package/{src → dist}/dom/p5.File.js +4 -4
- package/{src → dist}/dom/p5.MediaElement.js +10 -4
- package/{src → dist}/events/acceleration.js +2 -2
- package/{src → dist}/events/index.js +3 -1
- package/{src → dist}/events/keyboard.js +14 -11
- package/{src → dist}/events/pointer.js +16 -17
- package/dist/image/const.js +9 -0
- package/{src → dist}/image/filterRenderer2D.js +57 -37
- package/{src → dist}/image/filters.js +1 -3
- package/dist/image/image.js +40 -0
- package/dist/image/index.js +51 -0
- package/dist/image/loading_displaying.js +40 -0
- package/dist/image/p5.Image.js +11 -0
- package/{src → dist}/image/pixels.js +4 -3
- package/{src → dist}/io/csv.js +72 -70
- package/dist/io/files.js +40 -0
- package/dist/io/index.js +51 -0
- package/{src → dist}/io/p5.Table.js +6 -6
- package/{src → dist}/io/p5.TableRow.js +3 -4
- package/{src → dist}/io/p5.XML.js +2 -5
- package/{src → dist}/io/utilities.js +1 -1
- package/{src/core/p5.Renderer2D.js → dist/main-s72KWcUy.js} +735 -57
- package/{src → dist}/math/Matrices/Matrix.js +10 -8
- package/{src → dist}/math/Matrices/MatrixInterface.js +5 -3
- package/{src → dist}/math/Matrices/MatrixNumjs.js +12 -26
- package/{src → dist}/math/calculation.js +2 -2
- package/{src → dist}/math/index.js +6 -3
- package/{src → dist}/math/math.js +2 -2
- package/{src → dist}/math/noise.js +2 -2
- package/{src → dist}/math/p5.Matrix.js +7 -4
- package/{src → dist}/math/p5.Vector.js +6 -6
- package/{src → dist}/math/random.js +2 -2
- package/{src → dist}/math/trigonometry.js +16 -15
- package/{src/image/p5.Image.js → dist/p5.Renderer-CwAYZOC2.js} +390 -19
- package/dist/rendering--aAe5aq3.js +24925 -0
- package/{src → dist}/shape/2d_primitives.js +18 -17
- package/{src → dist}/shape/attributes.js +18 -17
- package/{src → dist}/shape/curves.js +2 -2
- package/{src → dist}/shape/custom_shapes.js +44 -64
- package/{src → dist}/shape/index.js +10 -2
- package/{src → dist}/shape/vertex.js +2 -3
- package/dist/type/index.js +25 -0
- package/{src → dist}/type/lib/Typr.js +76 -94
- package/{src → dist}/type/p5.Font.js +37 -61
- package/{src → dist}/type/textCore.js +34 -57
- package/{src → dist}/type/unicodeRanges.js +3 -1
- package/{src → dist}/utilities/conversion.js +2 -2
- package/{src → dist}/utilities/index.js +3 -1
- package/{src → dist}/utilities/time_date.js +6 -7
- package/{src → dist}/utilities/utility_functions.js +2 -2
- package/dist/webgl/3d_primitives.js +40 -0
- package/{src → dist}/webgl/GeometryBufferCache.js +3 -1
- package/{src → dist}/webgl/GeometryBuilder.js +12 -8
- package/{src → dist}/webgl/ShaderGenerator.js +79 -82
- package/{src → dist}/webgl/ShapeBuilder.js +26 -23
- package/dist/webgl/index.js +76 -0
- package/{src → dist}/webgl/interaction.js +7 -6
- package/dist/webgl/light.js +40 -0
- package/{src → dist}/webgl/loading.js +45 -12
- package/dist/webgl/material.js +40 -0
- package/dist/webgl/p5.Camera.js +40 -0
- package/{src → dist}/webgl/p5.DataArray.js +3 -5
- package/dist/webgl/p5.Framebuffer.js +40 -0
- package/{src → dist}/webgl/p5.Geometry.js +12 -15
- package/{src → dist}/webgl/p5.Quat.js +5 -4
- package/{src → dist}/webgl/p5.RenderBuffer.js +2 -3
- package/dist/webgl/p5.RendererGL.js +40 -0
- package/dist/webgl/p5.Shader.js +40 -0
- package/dist/webgl/p5.Texture.js +40 -0
- package/{src → dist}/webgl/text.js +51 -9
- package/lib/p5.esm.js +102 -48
- package/lib/p5.js +102 -48
- package/lib/p5.min.js +1 -1
- package/package.json +17 -16
- package/translations/dev.js +6 -6
- package/translations/index.js +1 -1
- package/src/README.md +0 -27
- package/src/accessibility/index.js +0 -13
- package/src/app.js +0 -61
- package/src/color/index.js +0 -9
- package/src/color/p5.Color.culori.js +0 -66
- package/src/color/p5.Color.js +0 -851
- package/src/core/README.md +0 -91
- package/src/core/friendly_errors/index.js +0 -13
- package/src/core/friendly_errors/param_validator.js +0 -561
- package/src/core/init.js +0 -58
- package/src/core/internationalization.js +0 -195
- package/src/core/legacy.js +0 -29
- package/src/core/main.js +0 -689
- package/src/core/noop.js +0 -1
- package/src/core/p5.Graphics.js +0 -696
- package/src/core/p5.Renderer.js +0 -408
- package/src/core/reference.js +0 -2060
- package/src/core/rendering.js +0 -697
- package/src/dom/index.js +0 -11
- package/src/image/const.js +0 -6
- package/src/image/image.js +0 -731
- package/src/image/index.js +0 -15
- package/src/image/loading_displaying.js +0 -1431
- package/src/io/files.js +0 -2210
- package/src/io/index.js +0 -11
- package/src/math/README.md +0 -40
- package/src/type/index.js +0 -9
- package/src/webgl/3d_primitives.js +0 -2741
- package/src/webgl/index.js +0 -37
- package/src/webgl/light.js +0 -1851
- package/src/webgl/material.js +0 -3854
- package/src/webgl/p5.Camera.js +0 -4010
- package/src/webgl/p5.Framebuffer.js +0 -1865
- package/src/webgl/p5.RendererGL.js +0 -2867
- package/src/webgl/p5.Shader.js +0 -1505
- package/src/webgl/p5.Texture.js +0 -541
- package/src/webgl/shaders/basic.frag +0 -6
- package/src/webgl/shaders/filters/base.frag +0 -22
- package/src/webgl/shaders/filters/base.vert +0 -19
- package/src/webgl/shaders/filters/blur.frag +0 -60
- package/src/webgl/shaders/filters/default.vert +0 -18
- package/src/webgl/shaders/filters/dilate.frag +0 -39
- package/src/webgl/shaders/filters/erode.frag +0 -39
- package/src/webgl/shaders/filters/gray.frag +0 -16
- package/src/webgl/shaders/filters/invert.frag +0 -15
- package/src/webgl/shaders/filters/opaque.frag +0 -12
- package/src/webgl/shaders/filters/posterize.frag +0 -29
- package/src/webgl/shaders/filters/threshold.frag +0 -23
- package/src/webgl/shaders/font.frag +0 -216
- package/src/webgl/shaders/font.vert +0 -44
- package/src/webgl/shaders/imageLight.vert +0 -33
- package/src/webgl/shaders/imageLightDiffused.frag +0 -82
- package/src/webgl/shaders/imageLightSpecular.frag +0 -134
- package/src/webgl/shaders/light.vert +0 -37
- package/src/webgl/shaders/light_texture.frag +0 -26
- package/src/webgl/shaders/lighting.glsl +0 -227
- package/src/webgl/shaders/line.frag +0 -74
- package/src/webgl/shaders/line.vert +0 -294
- package/src/webgl/shaders/normal.frag +0 -6
- package/src/webgl/shaders/normal.vert +0 -72
- package/src/webgl/shaders/phong.frag +0 -84
- package/src/webgl/shaders/phong.vert +0 -87
- package/src/webgl/shaders/point.frag +0 -29
- package/src/webgl/shaders/point.vert +0 -19
- package/src/webgl/shaders/sphereMapping.frag +0 -26
- package/src/webgl/shaders/webgl2Compatibility.glsl +0 -34
package/src/webgl/p5.Texture.js
DELETED
|
@@ -1,541 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* This module defines the p5.Texture class
|
|
3
|
-
* @module 3D
|
|
4
|
-
* @submodule Material
|
|
5
|
-
* @for p5
|
|
6
|
-
* @requires core
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
import * as constants from '../core/constants';
|
|
10
|
-
import { Element } from '../dom/p5.Element';
|
|
11
|
-
import { Renderer } from '../core/p5.Renderer';
|
|
12
|
-
import { MediaElement } from '../dom/p5.MediaElement';
|
|
13
|
-
import { Image } from '../image/p5.Image';
|
|
14
|
-
import { Graphics } from '../core/p5.Graphics';
|
|
15
|
-
import { FramebufferTexture } from './p5.Framebuffer';
|
|
16
|
-
|
|
17
|
-
class Texture {
|
|
18
|
-
constructor (renderer, obj, settings) {
|
|
19
|
-
this._renderer = renderer;
|
|
20
|
-
|
|
21
|
-
const gl = this._renderer.GL;
|
|
22
|
-
|
|
23
|
-
settings = settings || {};
|
|
24
|
-
|
|
25
|
-
this.src = obj;
|
|
26
|
-
this.glTex = undefined;
|
|
27
|
-
this.glTarget = gl.TEXTURE_2D;
|
|
28
|
-
this.glFormat = settings.format || gl.RGBA;
|
|
29
|
-
this.mipmaps = false;
|
|
30
|
-
this.glMinFilter = settings.minFilter || gl.LINEAR;
|
|
31
|
-
this.glMagFilter = settings.magFilter || gl.LINEAR;
|
|
32
|
-
this.glWrapS = settings.wrapS || gl.CLAMP_TO_EDGE;
|
|
33
|
-
this.glWrapT = settings.wrapT || gl.CLAMP_TO_EDGE;
|
|
34
|
-
this.glDataType = settings.dataType || gl.UNSIGNED_BYTE;
|
|
35
|
-
|
|
36
|
-
const support = checkWebGLCapabilities(renderer);
|
|
37
|
-
if (this.glFormat === gl.HALF_FLOAT && !support.halfFloat) {
|
|
38
|
-
console.log('This device does not support dataType HALF_FLOAT. Falling back to FLOAT.');
|
|
39
|
-
this.glDataType = gl.FLOAT;
|
|
40
|
-
}
|
|
41
|
-
if (
|
|
42
|
-
this.glFormat === gl.HALF_FLOAT &&
|
|
43
|
-
(this.glMinFilter === gl.LINEAR || this.glMagFilter === gl.LINEAR) &&
|
|
44
|
-
!support.halfFloatLinear
|
|
45
|
-
) {
|
|
46
|
-
console.log('This device does not support linear filtering for dataType FLOAT. Falling back to NEAREST.');
|
|
47
|
-
if (this.glMinFilter === gl.LINEAR) this.glMinFilter = gl.NEAREST;
|
|
48
|
-
if (this.glMagFilter === gl.LINEAR) this.glMagFilter = gl.NEAREST;
|
|
49
|
-
}
|
|
50
|
-
if (this.glFormat === gl.FLOAT && !support.float) {
|
|
51
|
-
console.log('This device does not support dataType FLOAT. Falling back to UNSIGNED_BYTE.');
|
|
52
|
-
this.glDataType = gl.UNSIGNED_BYTE;
|
|
53
|
-
}
|
|
54
|
-
if (
|
|
55
|
-
this.glFormat === gl.FLOAT &&
|
|
56
|
-
(this.glMinFilter === gl.LINEAR || this.glMagFilter === gl.LINEAR) &&
|
|
57
|
-
!support.floatLinear
|
|
58
|
-
) {
|
|
59
|
-
console.log('This device does not support linear filtering for dataType FLOAT. Falling back to NEAREST.');
|
|
60
|
-
if (this.glMinFilter === gl.LINEAR) this.glMinFilter = gl.NEAREST;
|
|
61
|
-
if (this.glMagFilter === gl.LINEAR) this.glMagFilter = gl.NEAREST;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
// used to determine if this texture might need constant updating
|
|
65
|
-
// because it is a video or gif.
|
|
66
|
-
this.isSrcMediaElement = false;
|
|
67
|
-
typeof MediaElement !== 'undefined' && obj instanceof MediaElement;
|
|
68
|
-
this._videoPrevUpdateTime = 0;
|
|
69
|
-
this.isSrcHTMLElement =
|
|
70
|
-
typeof Element !== 'undefined' &&
|
|
71
|
-
obj instanceof Element &&
|
|
72
|
-
!(obj instanceof Graphics) &&
|
|
73
|
-
!(obj instanceof Renderer);
|
|
74
|
-
this.isSrcP5Image = obj instanceof Image;
|
|
75
|
-
this.isSrcP5Graphics = obj instanceof Graphics;
|
|
76
|
-
this.isSrcP5Renderer = obj instanceof Renderer;
|
|
77
|
-
this.isImageData =
|
|
78
|
-
typeof ImageData !== 'undefined' && obj instanceof ImageData;
|
|
79
|
-
this.isFramebufferTexture = obj instanceof FramebufferTexture;
|
|
80
|
-
|
|
81
|
-
const textureData = this._getTextureDataFromSource();
|
|
82
|
-
this.width = textureData.width;
|
|
83
|
-
this.height = textureData.height;
|
|
84
|
-
|
|
85
|
-
this.init(textureData);
|
|
86
|
-
return this;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
remove() {
|
|
90
|
-
if (this.glTex) {
|
|
91
|
-
const gl = this._renderer.GL;
|
|
92
|
-
gl.deleteTexture(this.glTex);
|
|
93
|
-
this.glTex = undefined;
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
_getTextureDataFromSource () {
|
|
98
|
-
let textureData;
|
|
99
|
-
if (this.isFramebufferTexture) {
|
|
100
|
-
textureData = this.src.rawTexture();
|
|
101
|
-
} else if (this.isSrcP5Image) {
|
|
102
|
-
// param is a p5.Image
|
|
103
|
-
textureData = this.src.canvas;
|
|
104
|
-
} else if (
|
|
105
|
-
this.isSrcMediaElement ||
|
|
106
|
-
this.isSrcHTMLElement
|
|
107
|
-
) {
|
|
108
|
-
// if param is a video HTML element
|
|
109
|
-
if (this.src._ensureCanvas) {
|
|
110
|
-
this.src._ensureCanvas();
|
|
111
|
-
}
|
|
112
|
-
textureData = this.src.elt;
|
|
113
|
-
} else if (this.isSrcP5Graphics || this.isSrcP5Renderer) {
|
|
114
|
-
textureData = this.src.canvas;
|
|
115
|
-
} else if (this.isImageData) {
|
|
116
|
-
textureData = this.src;
|
|
117
|
-
}
|
|
118
|
-
return textureData;
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
/**
|
|
122
|
-
* Initializes common texture parameters, creates a gl texture,
|
|
123
|
-
* tries to upload the texture for the first time if data is
|
|
124
|
-
* already available.
|
|
125
|
-
*/
|
|
126
|
-
init (data) {
|
|
127
|
-
const gl = this._renderer.GL;
|
|
128
|
-
if (!this.isFramebufferTexture) {
|
|
129
|
-
this.glTex = gl.createTexture();
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
this.glWrapS = this._renderer.states.textureWrapX;
|
|
133
|
-
this.glWrapT = this._renderer.states.textureWrapY;
|
|
134
|
-
|
|
135
|
-
this.setWrapMode(this.glWrapS, this.glWrapT);
|
|
136
|
-
this.bindTexture();
|
|
137
|
-
|
|
138
|
-
//gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, true);
|
|
139
|
-
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, this.glMagFilter);
|
|
140
|
-
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, this.glMinFilter);
|
|
141
|
-
|
|
142
|
-
if (this.isFramebufferTexture) {
|
|
143
|
-
// Do nothing, the framebuffer manages its own content
|
|
144
|
-
} else if (
|
|
145
|
-
this.width === 0 ||
|
|
146
|
-
this.height === 0 ||
|
|
147
|
-
(this.isSrcMediaElement && !this.src.loadedmetadata)
|
|
148
|
-
) {
|
|
149
|
-
// assign a 1×1 empty texture initially, because data is not yet ready,
|
|
150
|
-
// so that no errors occur in gl console!
|
|
151
|
-
const tmpdata = new Uint8Array([1, 1, 1, 1]);
|
|
152
|
-
gl.texImage2D(
|
|
153
|
-
this.glTarget,
|
|
154
|
-
0,
|
|
155
|
-
gl.RGBA,
|
|
156
|
-
1,
|
|
157
|
-
1,
|
|
158
|
-
0,
|
|
159
|
-
this.glFormat,
|
|
160
|
-
this.glDataType,
|
|
161
|
-
tmpdata
|
|
162
|
-
);
|
|
163
|
-
} else {
|
|
164
|
-
// data is ready: just push the texture!
|
|
165
|
-
gl.texImage2D(
|
|
166
|
-
this.glTarget,
|
|
167
|
-
0,
|
|
168
|
-
this.glFormat,
|
|
169
|
-
this.glFormat,
|
|
170
|
-
this.glDataType,
|
|
171
|
-
data
|
|
172
|
-
);
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
/**
|
|
177
|
-
* Checks if the source data for this texture has changed (if it's
|
|
178
|
-
* easy to do so) and reuploads the texture if necessary. If it's not
|
|
179
|
-
* possible or to expensive to do a calculation to determine wheter or
|
|
180
|
-
* not the data has occurred, this method simply re-uploads the texture.
|
|
181
|
-
*/
|
|
182
|
-
update () {
|
|
183
|
-
const data = this.src;
|
|
184
|
-
if (data.width === 0 || data.height === 0) {
|
|
185
|
-
return false; // nothing to do!
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
// FramebufferTexture instances wrap raw WebGL textures already, which
|
|
189
|
-
// don't need any extra updating, as they already live on the GPU
|
|
190
|
-
if (this.isFramebufferTexture) {
|
|
191
|
-
return false;
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
const textureData = this._getTextureDataFromSource();
|
|
195
|
-
let updated = false;
|
|
196
|
-
|
|
197
|
-
const gl = this._renderer.GL;
|
|
198
|
-
// pull texture from data, make sure width & height are appropriate
|
|
199
|
-
if (
|
|
200
|
-
textureData.width !== this.width ||
|
|
201
|
-
textureData.height !== this.height
|
|
202
|
-
) {
|
|
203
|
-
updated = true;
|
|
204
|
-
|
|
205
|
-
// make sure that if the width and height of this.src have changed
|
|
206
|
-
// for some reason, we update our metadata and upload the texture again
|
|
207
|
-
this.width = textureData.width || data.width;
|
|
208
|
-
this.height = textureData.height || data.height;
|
|
209
|
-
|
|
210
|
-
if (this.isSrcP5Image) {
|
|
211
|
-
data.setModified(false);
|
|
212
|
-
} else if (this.isSrcMediaElement || this.isSrcHTMLElement) {
|
|
213
|
-
// on the first frame the metadata comes in, the size will be changed
|
|
214
|
-
// from 0 to actual size, but pixels may not be available.
|
|
215
|
-
// flag for update in a future frame.
|
|
216
|
-
// if we don't do this, a paused video, for example, may not
|
|
217
|
-
// send the first frame to texture memory.
|
|
218
|
-
data.setModified && data.setModified(true);
|
|
219
|
-
}
|
|
220
|
-
} else if (this.isSrcP5Image) {
|
|
221
|
-
// for an image, we only update if the modified field has been set,
|
|
222
|
-
// for example, by a call to p5.Image.set
|
|
223
|
-
if (data.isModified()) {
|
|
224
|
-
updated = true;
|
|
225
|
-
data.setModified(false);
|
|
226
|
-
}
|
|
227
|
-
} else if (this.isSrcMediaElement) {
|
|
228
|
-
// for a media element (video), we'll check if the current time in
|
|
229
|
-
// the video frame matches the last time. if it doesn't match, the
|
|
230
|
-
// video has advanced or otherwise been taken to a new frame,
|
|
231
|
-
// and we need to upload it.
|
|
232
|
-
if (data.isModified()) {
|
|
233
|
-
// p5.MediaElement may have also had set/updatePixels, etc. called
|
|
234
|
-
// on it and should be updated, or may have been set for the first
|
|
235
|
-
// time!
|
|
236
|
-
updated = true;
|
|
237
|
-
data.setModified(false);
|
|
238
|
-
} else if (data.loadedmetadata) {
|
|
239
|
-
// if the meta data has been loaded, we can ask the video
|
|
240
|
-
// what it's current position (in time) is.
|
|
241
|
-
if (this._videoPrevUpdateTime !== data.time()) {
|
|
242
|
-
// update the texture in gpu mem only if the current
|
|
243
|
-
// video timestamp does not match the timestamp of the last
|
|
244
|
-
// time we uploaded this texture (and update the time we
|
|
245
|
-
// last uploaded, too)
|
|
246
|
-
this._videoPrevUpdateTime = data.time();
|
|
247
|
-
updated = true;
|
|
248
|
-
}
|
|
249
|
-
}
|
|
250
|
-
} else if (this.isImageData) {
|
|
251
|
-
if (data._dirty) {
|
|
252
|
-
data._dirty = false;
|
|
253
|
-
updated = true;
|
|
254
|
-
}
|
|
255
|
-
} else {
|
|
256
|
-
/* data instanceof p5.Graphics, probably */
|
|
257
|
-
// there is not enough information to tell if the texture can be
|
|
258
|
-
// conditionally updated; so to be safe, we just go ahead and upload it.
|
|
259
|
-
updated = true;
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
if (updated) {
|
|
263
|
-
this.bindTexture();
|
|
264
|
-
gl.texImage2D(
|
|
265
|
-
this.glTarget,
|
|
266
|
-
0,
|
|
267
|
-
this.glFormat,
|
|
268
|
-
this.glFormat,
|
|
269
|
-
this.glDataType,
|
|
270
|
-
textureData
|
|
271
|
-
);
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
return updated;
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
/**
|
|
278
|
-
* Binds the texture to the appropriate GL target.
|
|
279
|
-
*/
|
|
280
|
-
bindTexture () {
|
|
281
|
-
// bind texture using gl context + glTarget and
|
|
282
|
-
// generated gl texture object
|
|
283
|
-
const gl = this._renderer.GL;
|
|
284
|
-
gl.bindTexture(this.glTarget, this.getTexture());
|
|
285
|
-
|
|
286
|
-
return this;
|
|
287
|
-
}
|
|
288
|
-
|
|
289
|
-
/**
|
|
290
|
-
* Unbinds the texture from the appropriate GL target.
|
|
291
|
-
*/
|
|
292
|
-
unbindTexture () {
|
|
293
|
-
// unbind per above, disable texturing on glTarget
|
|
294
|
-
const gl = this._renderer.GL;
|
|
295
|
-
gl.bindTexture(this.glTarget, null);
|
|
296
|
-
}
|
|
297
|
-
|
|
298
|
-
getTexture() {
|
|
299
|
-
if (this.isFramebufferTexture) {
|
|
300
|
-
return this.src.rawTexture();
|
|
301
|
-
} else {
|
|
302
|
-
return this.glTex;
|
|
303
|
-
}
|
|
304
|
-
}
|
|
305
|
-
|
|
306
|
-
/**
|
|
307
|
-
* Sets how a texture is be interpolated when upscaled or downscaled.
|
|
308
|
-
* Nearest filtering uses nearest neighbor scaling when interpolating
|
|
309
|
-
* Linear filtering uses WebGL's linear scaling when interpolating
|
|
310
|
-
* @param {String} downScale Specifies the texture filtering when
|
|
311
|
-
* textures are shrunk. Options are LINEAR or NEAREST
|
|
312
|
-
* @param {String} upScale Specifies the texture filtering when
|
|
313
|
-
* textures are magnified. Options are LINEAR or NEAREST
|
|
314
|
-
* @todo implement mipmapping filters
|
|
315
|
-
*/
|
|
316
|
-
setInterpolation (downScale, upScale) {
|
|
317
|
-
const gl = this._renderer.GL;
|
|
318
|
-
|
|
319
|
-
this.glMinFilter = this.glFilter(downScale);
|
|
320
|
-
this.glMagFilter = this.glFilter(upScale);
|
|
321
|
-
|
|
322
|
-
this.bindTexture();
|
|
323
|
-
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, this.glMinFilter);
|
|
324
|
-
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, this.glMagFilter);
|
|
325
|
-
this.unbindTexture();
|
|
326
|
-
}
|
|
327
|
-
|
|
328
|
-
glFilter(filter) {
|
|
329
|
-
const gl = this._renderer.GL;
|
|
330
|
-
if (filter === constants.NEAREST) {
|
|
331
|
-
return gl.NEAREST;
|
|
332
|
-
} else {
|
|
333
|
-
return gl.LINEAR;
|
|
334
|
-
}
|
|
335
|
-
}
|
|
336
|
-
|
|
337
|
-
/**
|
|
338
|
-
* Sets the texture wrapping mode. This controls how textures behave
|
|
339
|
-
* when their uv's go outside of the 0 - 1 range. There are three options:
|
|
340
|
-
* CLAMP, REPEAT, and MIRROR. REPEAT & MIRROR are only available if the texture
|
|
341
|
-
* is a power of two size (128, 256, 512, 1024, etc.).
|
|
342
|
-
* @param {String} wrapX Controls the horizontal texture wrapping behavior
|
|
343
|
-
* @param {String} wrapY Controls the vertical texture wrapping behavior
|
|
344
|
-
*/
|
|
345
|
-
setWrapMode (wrapX, wrapY) {
|
|
346
|
-
const gl = this._renderer.GL;
|
|
347
|
-
|
|
348
|
-
// for webgl 1 we need to check if the texture is power of two
|
|
349
|
-
// if it isn't we will set the wrap mode to CLAMP
|
|
350
|
-
// webgl2 will support npot REPEAT and MIRROR but we don't check for it yet
|
|
351
|
-
const isPowerOfTwo = x => (x & (x - 1)) === 0;
|
|
352
|
-
const textureData = this._getTextureDataFromSource();
|
|
353
|
-
|
|
354
|
-
let wrapWidth;
|
|
355
|
-
let wrapHeight;
|
|
356
|
-
|
|
357
|
-
if (textureData.naturalWidth && textureData.naturalHeight) {
|
|
358
|
-
wrapWidth = textureData.naturalWidth;
|
|
359
|
-
wrapHeight = textureData.naturalHeight;
|
|
360
|
-
} else {
|
|
361
|
-
wrapWidth = this.width;
|
|
362
|
-
wrapHeight = this.height;
|
|
363
|
-
}
|
|
364
|
-
|
|
365
|
-
const widthPowerOfTwo = isPowerOfTwo(wrapWidth);
|
|
366
|
-
const heightPowerOfTwo = isPowerOfTwo(wrapHeight);
|
|
367
|
-
|
|
368
|
-
if (wrapX === constants.REPEAT) {
|
|
369
|
-
if (
|
|
370
|
-
this._renderer.webglVersion === constants.WEBGL2 ||
|
|
371
|
-
(widthPowerOfTwo && heightPowerOfTwo)
|
|
372
|
-
) {
|
|
373
|
-
this.glWrapS = gl.REPEAT;
|
|
374
|
-
} else {
|
|
375
|
-
console.warn(
|
|
376
|
-
'You tried to set the wrap mode to REPEAT but the texture size is not a power of two. Setting to CLAMP instead'
|
|
377
|
-
);
|
|
378
|
-
this.glWrapS = gl.CLAMP_TO_EDGE;
|
|
379
|
-
}
|
|
380
|
-
} else if (wrapX === constants.MIRROR) {
|
|
381
|
-
if (
|
|
382
|
-
this._renderer.webglVersion === constants.WEBGL2 ||
|
|
383
|
-
(widthPowerOfTwo && heightPowerOfTwo)
|
|
384
|
-
) {
|
|
385
|
-
this.glWrapS = gl.MIRRORED_REPEAT;
|
|
386
|
-
} else {
|
|
387
|
-
console.warn(
|
|
388
|
-
'You tried to set the wrap mode to MIRROR but the texture size is not a power of two. Setting to CLAMP instead'
|
|
389
|
-
);
|
|
390
|
-
this.glWrapS = gl.CLAMP_TO_EDGE;
|
|
391
|
-
}
|
|
392
|
-
} else {
|
|
393
|
-
// falling back to default if didn't get a proper mode
|
|
394
|
-
this.glWrapS = gl.CLAMP_TO_EDGE;
|
|
395
|
-
}
|
|
396
|
-
|
|
397
|
-
if (wrapY === constants.REPEAT) {
|
|
398
|
-
if (
|
|
399
|
-
this._renderer.webglVersion === constants.WEBGL2 ||
|
|
400
|
-
(widthPowerOfTwo && heightPowerOfTwo)
|
|
401
|
-
) {
|
|
402
|
-
this.glWrapT = gl.REPEAT;
|
|
403
|
-
} else {
|
|
404
|
-
console.warn(
|
|
405
|
-
'You tried to set the wrap mode to REPEAT but the texture size is not a power of two. Setting to CLAMP instead'
|
|
406
|
-
);
|
|
407
|
-
this.glWrapT = gl.CLAMP_TO_EDGE;
|
|
408
|
-
}
|
|
409
|
-
} else if (wrapY === constants.MIRROR) {
|
|
410
|
-
if (
|
|
411
|
-
this._renderer.webglVersion === constants.WEBGL2 ||
|
|
412
|
-
(widthPowerOfTwo && heightPowerOfTwo)
|
|
413
|
-
) {
|
|
414
|
-
this.glWrapT = gl.MIRRORED_REPEAT;
|
|
415
|
-
} else {
|
|
416
|
-
console.warn(
|
|
417
|
-
'You tried to set the wrap mode to MIRROR but the texture size is not a power of two. Setting to CLAMP instead'
|
|
418
|
-
);
|
|
419
|
-
this.glWrapT = gl.CLAMP_TO_EDGE;
|
|
420
|
-
}
|
|
421
|
-
} else {
|
|
422
|
-
// falling back to default if didn't get a proper mode
|
|
423
|
-
this.glWrapT = gl.CLAMP_TO_EDGE;
|
|
424
|
-
}
|
|
425
|
-
|
|
426
|
-
this.bindTexture();
|
|
427
|
-
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, this.glWrapS);
|
|
428
|
-
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, this.glWrapT);
|
|
429
|
-
this.unbindTexture();
|
|
430
|
-
}
|
|
431
|
-
}
|
|
432
|
-
|
|
433
|
-
class MipmapTexture extends Texture {
|
|
434
|
-
constructor(renderer, levels, settings) {
|
|
435
|
-
super(renderer, levels, settings);
|
|
436
|
-
const gl = this._renderer.GL;
|
|
437
|
-
if (this.glMinFilter === gl.LINEAR) {
|
|
438
|
-
this.glMinFilter = gl.LINEAR_MIPMAP_LINEAR;
|
|
439
|
-
}
|
|
440
|
-
}
|
|
441
|
-
|
|
442
|
-
glFilter(_filter) {
|
|
443
|
-
const gl = this._renderer.GL;
|
|
444
|
-
// TODO: support others
|
|
445
|
-
return gl.LINEAR_MIPMAP_LINEAR;
|
|
446
|
-
}
|
|
447
|
-
|
|
448
|
-
_getTextureDataFromSource() {
|
|
449
|
-
return this.src;
|
|
450
|
-
}
|
|
451
|
-
|
|
452
|
-
init(levels) {
|
|
453
|
-
const gl = this._renderer.GL;
|
|
454
|
-
this.glTex = gl.createTexture();
|
|
455
|
-
|
|
456
|
-
this.bindTexture();
|
|
457
|
-
for (let level = 0; level < levels.length; level++) {
|
|
458
|
-
gl.texImage2D(
|
|
459
|
-
this.glTarget,
|
|
460
|
-
level,
|
|
461
|
-
this.glFormat,
|
|
462
|
-
this.glFormat,
|
|
463
|
-
this.glDataType,
|
|
464
|
-
levels[level]
|
|
465
|
-
);
|
|
466
|
-
}
|
|
467
|
-
|
|
468
|
-
this.glMinFilter = gl.LINEAR_MIPMAP_LINEAR;
|
|
469
|
-
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, this.glMagFilter);
|
|
470
|
-
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, this.glMinFilter);
|
|
471
|
-
|
|
472
|
-
this.unbindTexture();
|
|
473
|
-
}
|
|
474
|
-
|
|
475
|
-
update() {}
|
|
476
|
-
}
|
|
477
|
-
|
|
478
|
-
function texture(p5, fn){
|
|
479
|
-
/**
|
|
480
|
-
* Texture class for WEBGL Mode
|
|
481
|
-
* @private
|
|
482
|
-
* @class p5.Texture
|
|
483
|
-
* @param {p5.RendererGL} renderer an instance of p5.RendererGL that
|
|
484
|
-
* will provide the GL context for this new p5.Texture
|
|
485
|
-
* @param {p5.Image|p5.Graphics|p5.Element|p5.MediaElement|ImageData|p5.Framebuffer|p5.FramebufferTexture|ImageData} [obj] the
|
|
486
|
-
* object containing the image data to store in the texture.
|
|
487
|
-
* @param {Object} [settings] optional A javascript object containing texture
|
|
488
|
-
* settings.
|
|
489
|
-
* @param {Number} [settings.format] optional The internal color component
|
|
490
|
-
* format for the texture. Possible values for format include gl.RGBA,
|
|
491
|
-
* gl.RGB, gl.ALPHA, gl.LUMINANCE, gl.LUMINANCE_ALPHA. Defaults to gl.RBGA
|
|
492
|
-
* @param {Number} [settings.minFilter] optional The texture minification
|
|
493
|
-
* filter setting. Possible values are gl.NEAREST or gl.LINEAR. Defaults
|
|
494
|
-
* to gl.LINEAR. Note, Mipmaps are not implemented in p5.
|
|
495
|
-
* @param {Number} [settings.magFilter] optional The texture magnification
|
|
496
|
-
* filter setting. Possible values are gl.NEAREST or gl.LINEAR. Defaults
|
|
497
|
-
* to gl.LINEAR. Note, Mipmaps are not implemented in p5.
|
|
498
|
-
* @param {Number} [settings.wrapS] optional The texture wrap settings for
|
|
499
|
-
* the s coordinate, or x axis. Possible values are gl.CLAMP_TO_EDGE,
|
|
500
|
-
* gl.REPEAT, and gl.MIRRORED_REPEAT. The mirror settings are only available
|
|
501
|
-
* when using a power of two sized texture. Defaults to gl.CLAMP_TO_EDGE
|
|
502
|
-
* @param {Number} [settings.wrapT] optional The texture wrap settings for
|
|
503
|
-
* the t coordinate, or y axis. Possible values are gl.CLAMP_TO_EDGE,
|
|
504
|
-
* gl.REPEAT, and gl.MIRRORED_REPEAT. The mirror settings are only available
|
|
505
|
-
* when using a power of two sized texture. Defaults to gl.CLAMP_TO_EDGE
|
|
506
|
-
* @param {Number} [settings.dataType] optional The data type of the texel
|
|
507
|
-
* data. Possible values are gl.UNSIGNED_BYTE or gl.FLOAT. There are more
|
|
508
|
-
* formats that are not implemented in p5. Defaults to gl.UNSIGNED_BYTE.
|
|
509
|
-
*/
|
|
510
|
-
p5.Texture = Texture;
|
|
511
|
-
|
|
512
|
-
p5.MipmapTexture = MipmapTexture;
|
|
513
|
-
}
|
|
514
|
-
|
|
515
|
-
export function checkWebGLCapabilities({ GL, webglVersion }) {
|
|
516
|
-
const gl = GL;
|
|
517
|
-
const supportsFloat = webglVersion === constants.WEBGL2
|
|
518
|
-
? (gl.getExtension('EXT_color_buffer_float') &&
|
|
519
|
-
gl.getExtension('EXT_float_blend'))
|
|
520
|
-
: gl.getExtension('OES_texture_float');
|
|
521
|
-
const supportsFloatLinear = supportsFloat &&
|
|
522
|
-
gl.getExtension('OES_texture_float_linear');
|
|
523
|
-
const supportsHalfFloat = webglVersion === constants.WEBGL2
|
|
524
|
-
? gl.getExtension('EXT_color_buffer_float')
|
|
525
|
-
: gl.getExtension('OES_texture_half_float');
|
|
526
|
-
const supportsHalfFloatLinear = supportsHalfFloat &&
|
|
527
|
-
gl.getExtension('OES_texture_half_float_linear');
|
|
528
|
-
return {
|
|
529
|
-
float: supportsFloat,
|
|
530
|
-
floatLinear: supportsFloatLinear,
|
|
531
|
-
halfFloat: supportsHalfFloat,
|
|
532
|
-
halfFloatLinear: supportsHalfFloatLinear
|
|
533
|
-
};
|
|
534
|
-
}
|
|
535
|
-
|
|
536
|
-
export default texture;
|
|
537
|
-
export { Texture, MipmapTexture };
|
|
538
|
-
|
|
539
|
-
if(typeof p5 !== 'undefined'){
|
|
540
|
-
texture(p5, p5.prototype);
|
|
541
|
-
}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
precision highp float;
|
|
2
|
-
|
|
3
|
-
uniform sampler2D tex0;
|
|
4
|
-
uniform vec2 canvasSize;
|
|
5
|
-
uniform vec2 texelSize;
|
|
6
|
-
|
|
7
|
-
IN vec2 vTexCoord;
|
|
8
|
-
|
|
9
|
-
struct FilterInputs {
|
|
10
|
-
vec2 texCoord;
|
|
11
|
-
vec2 canvasSize;
|
|
12
|
-
vec2 texelSize;
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
void main(void) {
|
|
16
|
-
FilterInputs inputs;
|
|
17
|
-
inputs.texCoord = vTexCoord;
|
|
18
|
-
inputs.canvasSize = canvasSize;
|
|
19
|
-
inputs.texelSize = texelSize;
|
|
20
|
-
OUT_COLOR = HOOK_getColor(inputs, tex0);
|
|
21
|
-
OUT_COLOR.rgb *= outColor.a;
|
|
22
|
-
}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
precision highp int;
|
|
2
|
-
|
|
3
|
-
uniform mat4 uModelViewMatrix;
|
|
4
|
-
uniform mat4 uProjectionMatrix;
|
|
5
|
-
|
|
6
|
-
IN vec3 aPosition;
|
|
7
|
-
IN vec2 aTexCoord;
|
|
8
|
-
OUT vec2 vTexCoord;
|
|
9
|
-
|
|
10
|
-
void main() {
|
|
11
|
-
// transferring texcoords for the frag shader
|
|
12
|
-
vTexCoord = aTexCoord;
|
|
13
|
-
|
|
14
|
-
// copy position with a fourth coordinate for projection (1.0 is normal)
|
|
15
|
-
vec4 positionVec4 = vec4(aPosition, 1.0);
|
|
16
|
-
|
|
17
|
-
// project to 3D space
|
|
18
|
-
gl_Position = uProjectionMatrix * uModelViewMatrix * positionVec4;
|
|
19
|
-
}
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
precision highp float;
|
|
2
|
-
|
|
3
|
-
// Two-pass blur filter, unweighted kernel.
|
|
4
|
-
// See also a similar blur at Adam Ferriss' repo of shader examples:
|
|
5
|
-
// https://github.com/aferriss/p5jsShaderExamples/blob/gh-pages/4_image-effects/4-9_single-pass-blur/effect.frag
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
uniform sampler2D tex0;
|
|
9
|
-
varying vec2 vTexCoord;
|
|
10
|
-
uniform vec2 direction;
|
|
11
|
-
uniform vec2 canvasSize;
|
|
12
|
-
uniform float radius;
|
|
13
|
-
|
|
14
|
-
float random(vec2 p) {
|
|
15
|
-
vec3 p3 = fract(vec3(p.xyx) * .1031);
|
|
16
|
-
p3 += dot(p3, p3.yzx + 33.33);
|
|
17
|
-
return fract((p3.x + p3.y) * p3.z);
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
// This isn't a real Gaussian weight, it's a quadratic weight. It's what the
|
|
21
|
-
// CPU mode's blur uses though, so we also use it here to match.
|
|
22
|
-
float quadWeight(float x, float e) {
|
|
23
|
-
return pow(e-abs(x), 2.);
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
void main(){
|
|
27
|
-
vec2 uv = vTexCoord;
|
|
28
|
-
|
|
29
|
-
// A reasonable maximum number of samples
|
|
30
|
-
const float maxSamples = 64.0;
|
|
31
|
-
|
|
32
|
-
float numSamples = floor(7. * radius);
|
|
33
|
-
if (fract(numSamples / 2.) == 0.) {
|
|
34
|
-
numSamples++;
|
|
35
|
-
}
|
|
36
|
-
vec4 avg = vec4(0.0);
|
|
37
|
-
float total = 0.0;
|
|
38
|
-
|
|
39
|
-
// Calculate the spacing to avoid skewing if numSamples > maxSamples
|
|
40
|
-
float spacing = 1.0;
|
|
41
|
-
if (numSamples > maxSamples) {
|
|
42
|
-
spacing = numSamples / maxSamples;
|
|
43
|
-
numSamples = maxSamples;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
float randomOffset = (spacing - 1.0) * mix(-0.5, 0.5, random(gl_FragCoord.xy));
|
|
47
|
-
for (float i = 0.0; i < maxSamples; i++) {
|
|
48
|
-
if (i >= numSamples) break;
|
|
49
|
-
|
|
50
|
-
float sample = i * spacing - (numSamples - 1.0) * 0.5 * spacing + randomOffset;
|
|
51
|
-
vec2 sampleCoord = uv + vec2(sample, sample) / canvasSize * direction;
|
|
52
|
-
float weight = quadWeight(sample, (numSamples - 1.0) * 0.5 * spacing);
|
|
53
|
-
|
|
54
|
-
avg += weight * texture2D(tex0, sampleCoord);
|
|
55
|
-
total += weight;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
avg /= total;
|
|
59
|
-
gl_FragColor = avg;
|
|
60
|
-
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
uniform mat4 uModelViewMatrix;
|
|
2
|
-
uniform mat4 uProjectionMatrix;
|
|
3
|
-
|
|
4
|
-
attribute vec3 aPosition;
|
|
5
|
-
// texcoords only come from p5 to vertex shader
|
|
6
|
-
// so pass texcoords on to the fragment shader in a varying variable
|
|
7
|
-
attribute vec2 aTexCoord;
|
|
8
|
-
varying vec2 vTexCoord;
|
|
9
|
-
|
|
10
|
-
void main() {
|
|
11
|
-
// transferring texcoords for the frag shader
|
|
12
|
-
vTexCoord = aTexCoord;
|
|
13
|
-
|
|
14
|
-
// copy position with a fourth coordinate for projection (1.0 is normal)
|
|
15
|
-
vec4 positionVec4 = vec4(aPosition, 1.0);
|
|
16
|
-
|
|
17
|
-
gl_Position = uProjectionMatrix * uModelViewMatrix * positionVec4;
|
|
18
|
-
}
|