@openglobus/og 0.12.3 → 0.13.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/README.md +0 -2
- package/dist/@openglobus/og.esm.js +2 -2
- package/dist/@openglobus/og.esm.js.map +1 -1
- package/dist/@openglobus/og.umd.js +2 -2
- package/dist/@openglobus/og.umd.js.map +1 -1
- package/package.json +7 -7
- package/src/og/Extent.js +3 -3
- package/src/og/Globe.js +277 -275
- package/src/og/ImageCanvas.js +3 -3
- package/src/og/LonLat.js +9 -9
- package/src/og/QueueArray.js +2 -2
- package/src/og/Rectangle.js +5 -5
- package/src/og/bv/Box.js +1 -1
- package/src/og/bv/Sphere.js +2 -2
- package/src/og/camera/Camera.js +1 -1
- package/src/og/camera/PlanetCamera.js +649 -646
- package/src/og/control/LayerSwitcher.js +1 -1
- package/src/og/control/MouseNavigation.js +22 -13
- package/src/og/control/MouseWheelZoomControl.js +2 -2
- package/src/og/control/ScaleControl.js +1 -1
- package/src/og/control/TouchNavigation.js +319 -319
- package/src/og/control/ZoomControl.js +132 -132
- package/src/og/control/visibleExtent/Segment.js +12 -12
- package/src/og/ellipsoid/Ellipsoid.js +577 -567
- package/src/og/entity/BillboardHandler.js +878 -1051
- package/src/og/entity/Entity.js +1 -1
- package/src/og/entity/EntityCollection.js +847 -857
- package/src/og/entity/GeoObjectHandler.js +2 -2
- package/src/og/entity/LabelHandler.js +888 -1040
- package/src/og/entity/LabelWorker.js +0 -6
- package/src/og/entity/PointCloud.js +495 -495
- package/src/og/entity/Polyline.js +2218 -2222
- package/src/og/entity/RayHandler.js +1 -1
- package/src/og/layer/CanvasTiles.js +6 -3
- package/src/og/layer/GeoImage.js +1 -1
- package/src/og/layer/KML.js +5 -5
- package/src/og/layer/Layer.js +804 -752
- package/src/og/layer/Vector.js +997 -1010
- package/src/og/layer/XYZ.js +359 -357
- package/src/og/math/Line2.js +4 -4
- package/src/og/math/Quat.js +2 -2
- package/src/og/math/Ray.js +2 -2
- package/src/og/math/Vec2.js +524 -524
- package/src/og/math/Vec3.js +900 -900
- package/src/og/math/Vec4.js +261 -261
- package/src/og/math.js +397 -398
- package/src/og/quadTree/EntityCollectionNode.js +389 -387
- package/src/og/renderer/Renderer.js +14 -20
- package/src/og/renderer/RendererEvents.js +1034 -1045
- package/src/og/scene/Planet.js +12 -9
- package/src/og/scene/RenderNode.js +347 -354
- package/src/og/segment/Segment.js +3 -1
- package/src/og/segment/SegmentLonLat.js +1 -4
- package/src/og/shaders/billboard.js +220 -204
- package/src/og/shaders/drawnode.js +603 -603
- package/src/og/shaders/label.js +595 -456
- package/src/og/shaders/polyline.js +365 -361
- package/src/og/terrain/MapboxTerrain.js +1 -1
- package/src/og/utils/FontAtlas.js +209 -200
- package/src/og/utils/GeoImageCreator.js +4 -5
- package/src/og/utils/TextureAtlas.js +4 -4
- package/src/og/utils/VectorTileCreator.js +414 -414
- package/src/og/utils/shared.js +1 -1
- package/src/og/webgl/Handler.js +28 -60
- package/src/og/webgl/Multisample.js +260 -260
- package/src/og/webgl/Program.js +411 -396
- package/types/bv/Box.d.ts +1 -1
- package/types/bv/Sphere.d.ts +1 -1
- package/types/camera/PlanetCamera.d.ts +3 -3
- package/types/control/LayerSwitcher.d.ts +1 -1
- package/types/ellipsoid/Ellipsoid.d.ts +9 -2
- package/types/entity/BillboardHandler.d.ts +0 -4
- package/types/entity/EntityCollection.d.ts +0 -8
- package/types/entity/LabelHandler.d.ts +0 -2
- package/types/entity/Polyline.d.ts +1 -1
- package/types/layer/KML.d.ts +11 -11
- package/types/layer/Layer.d.ts +5 -0
- package/types/layer/Vector.d.ts +1 -8
- package/types/math/Line2.d.ts +4 -4
- package/types/math/Ray.d.ts +2 -2
- package/types/math/Vec2.d.ts +1 -1
- package/types/math/Vec3.d.ts +1 -1
- package/types/math/Vec4.d.ts +2 -2
- package/types/math.d.ts +1 -1
- package/types/renderer/Renderer.d.ts +1 -1
- package/types/renderer/RendererEvents.d.ts +1 -1
- package/types/shaders/label.d.ts +1 -1
- package/types/utils/FontAtlas.d.ts +3 -2
- package/types/utils/TextureAtlas.d.ts +3 -3
- package/types/utils/VectorTileCreator.d.ts +4 -4
- package/types/utils/shared.d.ts +1 -1
- package/types/webgl/Handler.d.ts +6 -31
- package/types/webgl/Program.d.ts +2 -0
package/src/og/webgl/Program.js
CHANGED
|
@@ -1,396 +1,411 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @module og/webgl/Program
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
"use strict";
|
|
6
|
-
|
|
7
|
-
import { callbacks } from "./callbacks.js";
|
|
8
|
-
import { cons } from "../cons.js";
|
|
9
|
-
import { typeStr, types } from "./types.js";
|
|
10
|
-
|
|
11
|
-
const itemTypes = ["BYTE", "SHORT", "UNSIGNED_BYTE", "UNSIGNED_SHORT", "FLOAT", "HALF_FLOAT"];
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Represents more comfortable using WebGL shader program.
|
|
15
|
-
* @class
|
|
16
|
-
* @param {string} name - Shader program name identificator.
|
|
17
|
-
* @param {object} material - Object stores uniforms, attributes and program codes:
|
|
18
|
-
* @param {object} material.uniforms - Uniforms definition section.
|
|
19
|
-
* @param {object} material.attributes - Attributes definition section.
|
|
20
|
-
* @param {string} material.vertexShader - Vertex glsl code.
|
|
21
|
-
* @param {string} material.fragmentShader - Fragment glsl code.
|
|
22
|
-
*/
|
|
23
|
-
class Program {
|
|
24
|
-
constructor(name, material) {
|
|
25
|
-
/**
|
|
26
|
-
* Shader progarm name.
|
|
27
|
-
* @public
|
|
28
|
-
* @type {string}
|
|
29
|
-
*/
|
|
30
|
-
this.name = name;
|
|
31
|
-
|
|
32
|
-
this.attributes = {};
|
|
33
|
-
this.uniforms = {};
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* Attributes.
|
|
37
|
-
* @public
|
|
38
|
-
* @type {Object}
|
|
39
|
-
*/
|
|
40
|
-
this._attributes = {};
|
|
41
|
-
for (let t in material.attributes) {
|
|
42
|
-
if (
|
|
43
|
-
typeof material.attributes[t] === "string" ||
|
|
44
|
-
typeof material.attributes[t] === "number"
|
|
45
|
-
) {
|
|
46
|
-
this._attributes[t] = { type: material.attributes[t] };
|
|
47
|
-
} else {
|
|
48
|
-
this._attributes[t] = material.attributes[t];
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
* Uniforms.
|
|
54
|
-
* @public
|
|
55
|
-
* @type {Object}
|
|
56
|
-
*/
|
|
57
|
-
this._uniforms = {};
|
|
58
|
-
for (let t in material.uniforms) {
|
|
59
|
-
if (
|
|
60
|
-
typeof material.uniforms[t] === "string" ||
|
|
61
|
-
typeof material.uniforms[t] === "number"
|
|
62
|
-
) {
|
|
63
|
-
this._uniforms[t] = { type: material.uniforms[t] };
|
|
64
|
-
} else {
|
|
65
|
-
this._uniforms[t] = material.uniforms[t];
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
/**
|
|
70
|
-
* Vertex shader.
|
|
71
|
-
* @public
|
|
72
|
-
* @type {string}
|
|
73
|
-
*/
|
|
74
|
-
this.vertexShader = material.vertexShader;
|
|
75
|
-
|
|
76
|
-
/**
|
|
77
|
-
* Fragment shader.
|
|
78
|
-
* @public
|
|
79
|
-
* @type {string}
|
|
80
|
-
*/
|
|
81
|
-
this.fragmentShader = material.fragmentShader;
|
|
82
|
-
|
|
83
|
-
/**
|
|
84
|
-
* Webgl context.
|
|
85
|
-
* @public
|
|
86
|
-
* @type {Object}
|
|
87
|
-
*/
|
|
88
|
-
this.gl = null;
|
|
89
|
-
|
|
90
|
-
/**
|
|
91
|
-
* All program variables.
|
|
92
|
-
* @private
|
|
93
|
-
* @type {Object}
|
|
94
|
-
*/
|
|
95
|
-
this._variables = {};
|
|
96
|
-
|
|
97
|
-
/**
|
|
98
|
-
* Program pointer.
|
|
99
|
-
* @private
|
|
100
|
-
* @type {Object}
|
|
101
|
-
*/
|
|
102
|
-
this._p = null;
|
|
103
|
-
|
|
104
|
-
/**
|
|
105
|
-
* Texture counter.
|
|
106
|
-
* @prvate
|
|
107
|
-
* @type {number}
|
|
108
|
-
*/
|
|
109
|
-
this._textureID = 0;
|
|
110
|
-
|
|
111
|
-
/**
|
|
112
|
-
* Program attributes array.
|
|
113
|
-
* @private
|
|
114
|
-
* @type {Array.<Object>}
|
|
115
|
-
*/
|
|
116
|
-
this._attribArrays = [];
|
|
117
|
-
|
|
118
|
-
/**
|
|
119
|
-
* Program attributes divisor.
|
|
120
|
-
* @private
|
|
121
|
-
* @type {Array.<Object>}
|
|
122
|
-
*/
|
|
123
|
-
this._attribDivisor = [];
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
*
|
|
129
|
-
* @
|
|
130
|
-
* @param {
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
gl.
|
|
135
|
-
gl.
|
|
136
|
-
|
|
137
|
-
variable.
|
|
138
|
-
variable.
|
|
139
|
-
variable.
|
|
140
|
-
|
|
141
|
-
0
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
*
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
*
|
|
156
|
-
* @
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
this._variables[i].
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
*
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
*
|
|
181
|
-
* @
|
|
182
|
-
* @param {
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
this.gl.
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
*
|
|
192
|
-
* @
|
|
193
|
-
* @param {number}
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
*
|
|
202
|
-
* @
|
|
203
|
-
* @param {
|
|
204
|
-
* @
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
this.gl.
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
*
|
|
221
|
-
* @
|
|
222
|
-
* @
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
*
|
|
235
|
-
* @
|
|
236
|
-
* @
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
*
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
var
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
gl.
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
*
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
var
|
|
266
|
-
var
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
gl.
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
gl.
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
);
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
this._attributes[a].
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
}
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
}
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
this.
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
1
|
+
/**
|
|
2
|
+
* @module og/webgl/Program
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
"use strict";
|
|
6
|
+
|
|
7
|
+
import { callbacks } from "./callbacks.js";
|
|
8
|
+
import { cons } from "../cons.js";
|
|
9
|
+
import { typeStr, types } from "./types.js";
|
|
10
|
+
|
|
11
|
+
const itemTypes = ["BYTE", "SHORT", "UNSIGNED_BYTE", "UNSIGNED_SHORT", "FLOAT", "HALF_FLOAT"];
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Represents more comfortable using WebGL shader program.
|
|
15
|
+
* @class
|
|
16
|
+
* @param {string} name - Shader program name identificator.
|
|
17
|
+
* @param {object} material - Object stores uniforms, attributes and program codes:
|
|
18
|
+
* @param {object} material.uniforms - Uniforms definition section.
|
|
19
|
+
* @param {object} material.attributes - Attributes definition section.
|
|
20
|
+
* @param {string} material.vertexShader - Vertex glsl code.
|
|
21
|
+
* @param {string} material.fragmentShader - Fragment glsl code.
|
|
22
|
+
*/
|
|
23
|
+
class Program {
|
|
24
|
+
constructor(name, material) {
|
|
25
|
+
/**
|
|
26
|
+
* Shader progarm name.
|
|
27
|
+
* @public
|
|
28
|
+
* @type {string}
|
|
29
|
+
*/
|
|
30
|
+
this.name = name;
|
|
31
|
+
|
|
32
|
+
this.attributes = {};
|
|
33
|
+
this.uniforms = {};
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Attributes.
|
|
37
|
+
* @public
|
|
38
|
+
* @type {Object}
|
|
39
|
+
*/
|
|
40
|
+
this._attributes = {};
|
|
41
|
+
for (let t in material.attributes) {
|
|
42
|
+
if (
|
|
43
|
+
typeof material.attributes[t] === "string" ||
|
|
44
|
+
typeof material.attributes[t] === "number"
|
|
45
|
+
) {
|
|
46
|
+
this._attributes[t] = { type: material.attributes[t] };
|
|
47
|
+
} else {
|
|
48
|
+
this._attributes[t] = material.attributes[t];
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Uniforms.
|
|
54
|
+
* @public
|
|
55
|
+
* @type {Object}
|
|
56
|
+
*/
|
|
57
|
+
this._uniforms = {};
|
|
58
|
+
for (let t in material.uniforms) {
|
|
59
|
+
if (
|
|
60
|
+
typeof material.uniforms[t] === "string" ||
|
|
61
|
+
typeof material.uniforms[t] === "number"
|
|
62
|
+
) {
|
|
63
|
+
this._uniforms[t] = { type: material.uniforms[t] };
|
|
64
|
+
} else {
|
|
65
|
+
this._uniforms[t] = material.uniforms[t];
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Vertex shader.
|
|
71
|
+
* @public
|
|
72
|
+
* @type {string}
|
|
73
|
+
*/
|
|
74
|
+
this.vertexShader = material.vertexShader;
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Fragment shader.
|
|
78
|
+
* @public
|
|
79
|
+
* @type {string}
|
|
80
|
+
*/
|
|
81
|
+
this.fragmentShader = material.fragmentShader;
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Webgl context.
|
|
85
|
+
* @public
|
|
86
|
+
* @type {Object}
|
|
87
|
+
*/
|
|
88
|
+
this.gl = null;
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* All program variables.
|
|
92
|
+
* @private
|
|
93
|
+
* @type {Object}
|
|
94
|
+
*/
|
|
95
|
+
this._variables = {};
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Program pointer.
|
|
99
|
+
* @private
|
|
100
|
+
* @type {Object}
|
|
101
|
+
*/
|
|
102
|
+
this._p = null;
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Texture counter.
|
|
106
|
+
* @prvate
|
|
107
|
+
* @type {number}
|
|
108
|
+
*/
|
|
109
|
+
this._textureID = 0;
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Program attributes array.
|
|
113
|
+
* @private
|
|
114
|
+
* @type {Array.<Object>}
|
|
115
|
+
*/
|
|
116
|
+
this._attribArrays = [];
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Program attributes divisor.
|
|
120
|
+
* @private
|
|
121
|
+
* @type {Array.<Object>}
|
|
122
|
+
*/
|
|
123
|
+
this._attribDivisor = [];
|
|
124
|
+
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Bind program buffer.
|
|
129
|
+
* @function
|
|
130
|
+
* @param {Program} program - Used program.
|
|
131
|
+
* @param {Object} variable - Variable represents buffer data.
|
|
132
|
+
*/
|
|
133
|
+
static bindBuffer(program, variable) {
|
|
134
|
+
var gl = program.gl;
|
|
135
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, variable.value);
|
|
136
|
+
gl.vertexAttribPointer(
|
|
137
|
+
variable._pName,
|
|
138
|
+
variable.value.itemSize,
|
|
139
|
+
variable.itemType,
|
|
140
|
+
variable.normalized,
|
|
141
|
+
0,
|
|
142
|
+
0
|
|
143
|
+
);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* Sets the current program frame.
|
|
148
|
+
* @public
|
|
149
|
+
*/
|
|
150
|
+
use() {
|
|
151
|
+
this.gl.useProgram(this._p);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* Sets program variables.
|
|
156
|
+
* @public
|
|
157
|
+
* @param {Object} material - Variables and values object.
|
|
158
|
+
*/
|
|
159
|
+
set(material) {
|
|
160
|
+
this._textureID = 0;
|
|
161
|
+
for (var i in material) {
|
|
162
|
+
this._variables[i].value = material[i];
|
|
163
|
+
this._variables[i]._callback(this, this._variables[i]);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* Apply current variables.
|
|
169
|
+
* @public
|
|
170
|
+
*/
|
|
171
|
+
apply() {
|
|
172
|
+
this._textureID = 0;
|
|
173
|
+
var v = this._variables;
|
|
174
|
+
for (var i in v) {
|
|
175
|
+
v[i]._callback(this, v[i]);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* Calls drawElements index buffer function.
|
|
181
|
+
* @public
|
|
182
|
+
* @param {number} mode - Draw mode(GL_TRIANGLES, GL_LINESTRING etc.).
|
|
183
|
+
* @param {Object} buffer - Index buffer.
|
|
184
|
+
*/
|
|
185
|
+
drawIndexBuffer(mode, buffer) {
|
|
186
|
+
this.gl.bindBuffer(this.gl.ELEMENT_ARRAY_BUFFER, buffer);
|
|
187
|
+
this.gl.drawElements(mode, buffer.numItems, this.gl.UNSIGNED_SHORT, 0);
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* Calls drawArrays function.
|
|
192
|
+
* @public
|
|
193
|
+
* @param {number} mode - Draw mode(GL_TRIANGLES, GL_LINESTRING etc.).
|
|
194
|
+
* @param {number} numItems - Curent binded buffer drawing items count.
|
|
195
|
+
*/
|
|
196
|
+
drawArrays(mode, numItems) {
|
|
197
|
+
this.gl.drawArrays(mode, 0, numItems);
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
/**
|
|
201
|
+
* Check and log for an shader compile errors and warnings. Returns True - if no errors otherwise returns False.
|
|
202
|
+
* @private
|
|
203
|
+
* @param {Object} shader - WebGl shader program.
|
|
204
|
+
* @param {string} src - Shader program source.
|
|
205
|
+
* @returns {boolean} -
|
|
206
|
+
*/
|
|
207
|
+
_getShaderCompileStatus(shader, src) {
|
|
208
|
+
this.gl.shaderSource(shader, src);
|
|
209
|
+
this.gl.compileShader(shader);
|
|
210
|
+
if (!this.gl.getShaderParameter(shader, this.gl.COMPILE_STATUS)) {
|
|
211
|
+
cons.logErr(
|
|
212
|
+
"og/Program/Program:" + this.name + " - " + this.gl.getShaderInfoLog(shader) + "."
|
|
213
|
+
);
|
|
214
|
+
return false;
|
|
215
|
+
}
|
|
216
|
+
return true;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
/**
|
|
220
|
+
* Returns compiled vertex shader program pointer.
|
|
221
|
+
* @private
|
|
222
|
+
* @param {string} src - Vertex shader source code.
|
|
223
|
+
* @returns {Object} -
|
|
224
|
+
*/
|
|
225
|
+
_createVertexShader(src) {
|
|
226
|
+
var shader = this.gl.createShader(this.gl.VERTEX_SHADER);
|
|
227
|
+
if (!this._getShaderCompileStatus(shader, src)) {
|
|
228
|
+
return null;
|
|
229
|
+
}
|
|
230
|
+
return shader;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
/**
|
|
234
|
+
* Returns compiled fragment shader program pointer.
|
|
235
|
+
* @private
|
|
236
|
+
* @param {string} src - Vertex shader source code.
|
|
237
|
+
* @returns {Object} -
|
|
238
|
+
*/
|
|
239
|
+
_createFragmentShader(src) {
|
|
240
|
+
var shader = this.gl.createShader(this.gl.FRAGMENT_SHADER);
|
|
241
|
+
if (!this._getShaderCompileStatus(shader, src)) {
|
|
242
|
+
return null;
|
|
243
|
+
}
|
|
244
|
+
return shader;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
/**
|
|
248
|
+
* Disable current program vertexAttribArrays.
|
|
249
|
+
* @public
|
|
250
|
+
*/
|
|
251
|
+
disableAttribArrays() {
|
|
252
|
+
var gl = this.gl;
|
|
253
|
+
var a = this._attribArrays;
|
|
254
|
+
for (let i = 0, len = a.length; i < len; i++) {
|
|
255
|
+
gl.disableVertexAttribArray(a[i]);
|
|
256
|
+
this.vertexAttribDivisor(a[i], 0);
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
/**
|
|
261
|
+
* Enable current program vertexAttribArrays.
|
|
262
|
+
* @public
|
|
263
|
+
*/
|
|
264
|
+
enableAttribArrays() {
|
|
265
|
+
var gl = this.gl;
|
|
266
|
+
var a = this._attribArrays;
|
|
267
|
+
var d = this._attribDivisor;
|
|
268
|
+
for (let i = 0, len = a.length; i < len; i++) {
|
|
269
|
+
gl.enableVertexAttribArray(a[i]);
|
|
270
|
+
this.vertexAttribDivisor(a[i], d[i]);
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
vertexAttribDivisor(index, divisor) {
|
|
275
|
+
const gl = this.gl;
|
|
276
|
+
gl.vertexAttribDivisor ? gl.vertexAttribDivisor(index, divisor) : gl.getExtension('ANGLE_instanced_arrays').vertexAttribDivisorANGLE(index, divisor);
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
/**
|
|
280
|
+
* Delete program.
|
|
281
|
+
* @public
|
|
282
|
+
*/
|
|
283
|
+
delete() {
|
|
284
|
+
this.gl.deleteProgram(this._p);
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
/**
|
|
288
|
+
* Creates program.
|
|
289
|
+
* @public
|
|
290
|
+
* @param {Object} gl - WebGl context.
|
|
291
|
+
*/
|
|
292
|
+
createProgram(gl) {
|
|
293
|
+
this.gl = gl;
|
|
294
|
+
this._p = this.gl.createProgram();
|
|
295
|
+
|
|
296
|
+
var fs = this._createFragmentShader(this.fragmentShader);
|
|
297
|
+
var vs = this._createVertexShader(this.vertexShader);
|
|
298
|
+
gl.attachShader(this._p, fs);
|
|
299
|
+
gl.attachShader(this._p, vs);
|
|
300
|
+
gl.linkProgram(this._p);
|
|
301
|
+
|
|
302
|
+
if (!this.drawElementsInstanced) {
|
|
303
|
+
this.drawElementsInstanced = gl.drawElementsInstanced ? gl.drawElementsInstanced.bind(gl) : gl.getExtension('ANGLE_instanced_arrays').drawElementsInstancedANGLE.bind(gl.getExtension('ANGLE_instanced_arrays'));
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
if (!this.vertexAttribDivisor) {
|
|
307
|
+
this.vertexAttribDivisor = gl.vertexAttribDivisor ? gl.vertexAttribDivisor.bind(gl) : gl.getExtension('ANGLE_instanced_arrays').vertexAttribDivisorANGLE.bind(gl.getExtension('ANGLE_instanced_arrays'));
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
|
|
311
|
+
if (!gl.getProgramParameter(this._p, gl.LINK_STATUS)) {
|
|
312
|
+
cons.logErr(
|
|
313
|
+
"og/Program/Program:" +
|
|
314
|
+
this.name +
|
|
315
|
+
" - couldn't initialise shaders. " +
|
|
316
|
+
gl.getProgramInfoLog(this._p) +
|
|
317
|
+
"."
|
|
318
|
+
);
|
|
319
|
+
gl.deleteProgram(this._p);
|
|
320
|
+
return;
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
this.use();
|
|
324
|
+
|
|
325
|
+
for (var a in this._attributes) {
|
|
326
|
+
//this.attributes[a]._name = a;
|
|
327
|
+
this._variables[a] = this._attributes[a];
|
|
328
|
+
|
|
329
|
+
this._attributes[a]._callback = Program.bindBuffer;
|
|
330
|
+
|
|
331
|
+
let itemTypeStr = this._attributes[a].itemType
|
|
332
|
+
? this._attributes[a].itemType.trim().toUpperCase()
|
|
333
|
+
: "FLOAT";
|
|
334
|
+
|
|
335
|
+
if (itemTypes.indexOf(itemTypeStr) == -1) {
|
|
336
|
+
cons.logErr(
|
|
337
|
+
`og/Program/Program: ${this.name}- attribute '${a}', item type ${this._attributes[a].itemType} not exists.`
|
|
338
|
+
);
|
|
339
|
+
this._attributes[a].itemType = gl.FLOAT;
|
|
340
|
+
} else {
|
|
341
|
+
this._attributes[a].itemType = gl[itemTypeStr];
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
this._attributes[a].normalized = this._attributes[a].normalized || false;
|
|
345
|
+
this._attributes[a].divisor = this._attributes[a].divisor || 0;
|
|
346
|
+
|
|
347
|
+
this._p[a] = gl.getAttribLocation(this._p, a);
|
|
348
|
+
|
|
349
|
+
if (this._p[a] == undefined) {
|
|
350
|
+
cons.logErr(
|
|
351
|
+
"og/Program/Program:" + this.name + " - attribute '" + a + "' is not exists."
|
|
352
|
+
);
|
|
353
|
+
gl.deleteProgram(this._p);
|
|
354
|
+
return;
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
let type = this._attributes[a].type;
|
|
358
|
+
if (typeof type === "string") {
|
|
359
|
+
type = typeStr[type.trim().toLowerCase()];
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
let d = this._attributes[a].divisor;
|
|
363
|
+
if (type === types.MAT4) {
|
|
364
|
+
let loc = this._p[a];
|
|
365
|
+
this._attribArrays.push(loc, loc + 1, loc + 2, loc + 3);
|
|
366
|
+
this._attribDivisor.push(d, d, d, d);
|
|
367
|
+
} else {
|
|
368
|
+
this._attribArrays.push(this._p[a]);
|
|
369
|
+
this._attribDivisor.push(d);
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
gl.enableVertexAttribArray(this._p[a]);
|
|
373
|
+
|
|
374
|
+
this._attributes[a]._pName = this._p[a];
|
|
375
|
+
this.attributes[a] = this._p[a];
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
for (var u in this._uniforms) {
|
|
379
|
+
//this.uniforms[u]._name = u;
|
|
380
|
+
|
|
381
|
+
if (typeof this._uniforms[u].type === "string") {
|
|
382
|
+
this._uniforms[u]._callback =
|
|
383
|
+
callbacks.u[typeStr[this._uniforms[u].type.trim().toLowerCase()]];
|
|
384
|
+
} else {
|
|
385
|
+
this._uniforms[u]._callback = callbacks.u[this._uniforms[u].type];
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
this._variables[u] = this._uniforms[u];
|
|
389
|
+
this._p[u] = gl.getUniformLocation(this._p, u);
|
|
390
|
+
|
|
391
|
+
if (this._p[u] == undefined) {
|
|
392
|
+
cons.logErr(
|
|
393
|
+
"og/Program/Program:" + this.name + " - uniform '" + u + "' is not exists."
|
|
394
|
+
);
|
|
395
|
+
gl.deleteProgram(this._p);
|
|
396
|
+
return;
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
this._uniforms[u]._pName = this._p[u];
|
|
400
|
+
this.uniforms[u] = this._p[u];
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
gl.detachShader(this._p, fs);
|
|
404
|
+
gl.detachShader(this._p, vs);
|
|
405
|
+
|
|
406
|
+
gl.deleteShader(fs);
|
|
407
|
+
gl.deleteShader(vs);
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
export { Program };
|