@openglobus/og 0.11.4 → 0.11.8
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/css/og.css +3 -2
- package/package.json +12 -14
- package/src/og/Clock.js +6 -10
- package/src/og/Events.js +5 -7
- package/src/og/Extent.js +73 -32
- package/src/og/Globe.js +8 -5
- package/src/og/ImageCanvas.js +18 -15
- package/src/og/LonLat.js +13 -10
- package/src/og/Popup.js +19 -17
- package/src/og/QueueArray.js +3 -4
- package/src/og/Rectangle.js +4 -6
- package/src/og/Stack.js +2 -4
- package/src/og/ajax.js +20 -14
- package/src/og/astro/earth.js +21 -15
- package/src/og/bv/Box.js +2 -3
- package/src/og/bv/Sphere.js +10 -7
- package/src/og/camera/Frustum.js +19 -12
- package/src/og/camera/PlanetCamera.js +9 -5
- package/src/og/control/CompassButton.js +1 -2
- package/src/og/control/Control.js +7 -9
- package/src/og/control/DebugInfo.js +0 -1
- package/src/og/control/KeyboardNavigation.js +9 -9
- package/src/og/control/LayerSwitcher.js +21 -20
- package/src/og/control/Lighting.js +74 -64
- package/src/og/control/MouseNavigation.js +21 -18
- package/src/og/control/MouseWheelZoomControl.js +257 -0
- package/src/og/control/SegmentBoundVisualization.js +5 -6
- package/src/og/control/ShowFps.js +12 -7
- package/src/og/control/SimpleNavigation.js +5 -7
- package/src/og/control/Sun.js +22 -12
- package/src/og/control/ToggleWireframe.js +3 -3
- package/src/og/control/TouchNavigation.js +43 -32
- package/src/og/control/ZoomControl.js +40 -24
- package/src/og/control/index.js +2 -0
- package/src/og/control/visibleExtent/Segment.js +1862 -0
- package/src/og/control/visibleExtent/VisibleExtent.js +80 -0
- package/src/og/control/visibleExtent/drawnode.js +751 -0
- package/src/og/ellipsoid/Ellipsoid.js +149 -57
- package/src/og/ellipsoid/wgs84.js +3 -3
- package/src/og/entity/BaseBillboard.js +72 -30
- package/src/og/entity/Billboard.js +9 -5
- package/src/og/entity/BillboardHandler.js +315 -62
- package/src/og/entity/Entity.js +39 -1
- package/src/og/entity/EntityCollection.js +47 -24
- package/src/og/entity/GeoObject.js +228 -0
- package/src/og/entity/GeoObjectHandler.js +910 -0
- package/src/og/entity/GeometryHandler.js +595 -123
- package/src/og/entity/Label.js +62 -30
- package/src/og/entity/LabelHandler.js +40 -242
- package/src/og/entity/LabelWorker.js +218 -0
- package/src/og/entity/Object3d.js +504 -0
- package/src/og/entity/PointCloud.js +76 -28
- package/src/og/entity/PointCloudHandler.js +5 -5
- package/src/og/entity/Ray.js +49 -16
- package/src/og/entity/Strip.js +72 -43
- package/src/og/entity/StripHandler.js +23 -23
- package/src/og/layer/BaseGeoImage.js +50 -19
- package/src/og/layer/CanvasTiles.js +16 -17
- package/src/og/layer/GeoImage.js +8 -16
- package/src/og/layer/GeoTexture2d.js +2 -10
- package/src/og/layer/GeoVideo.js +2 -10
- package/src/og/layer/KML.js +55 -33
- package/src/og/layer/Layer.js +24 -32
- package/src/og/layer/Material.js +1 -1
- package/src/og/layer/Vector.js +94 -48
- package/src/og/layer/WMS.js +33 -18
- package/src/og/layer/XYZ.js +4 -5
- package/src/og/light/LightSource.js +19 -12
- package/src/og/math/Mat3.js +24 -12
- package/src/og/math/Mat4.js +603 -603
- package/src/og/math/Plane.js +19 -18
- package/src/og/math/Ray.js +17 -12
- package/src/og/math/Vec2.js +24 -14
- package/src/og/math/Vec3.js +60 -30
- package/src/og/math/coder.js +7 -7
- package/src/og/proj/EPSG3857.js +3 -3
- package/src/og/proj/EPSG4326.js +3 -3
- package/src/og/proj/Proj.js +2 -4
- package/src/og/quadTree/Node.js +3 -3
- package/src/og/renderer/Renderer.js +106 -124
- package/src/og/renderer/RendererEvents.js +45 -23
- package/src/og/scene/BaseNode.js +2 -3
- package/src/og/scene/Planet.js +51 -90
- package/src/og/scene/RenderNode.js +15 -8
- package/src/og/segment/Segment.js +60 -156
- package/src/og/segment/Slice.js +45 -0
- package/src/og/shaders/drawnode.js +245 -342
- package/src/og/shaders/geoObject.js +211 -0
- package/src/og/shaders/pointCloud.js +41 -41
- package/src/og/shaders/shape.js +12 -18
- package/src/og/shaders/skybox.js +36 -36
- package/src/og/shaders/toneMapping.js +1 -0
- package/src/og/shapes/BaseShape.js +108 -36
- package/src/og/shapes/Icosphere.js +25 -10
- package/src/og/shapes/Sphere.js +8 -11
- package/src/og/utils/FontAtlas.js +6 -2
- package/src/og/utils/GeoImageCreator.js +5 -1
- package/src/og/utils/TextureAtlas.js +18 -20
- package/src/og/utils/VectorTileCreator.js +1 -3
- package/src/og/utils/shared.js +2 -2
- package/src/og/webgl/Handler.js +215 -162
- package/src/og/webgl/Multisample.js +44 -16
- package/src/og/webgl/Program.js +78 -33
- package/src/og/webgl/callbacks.js +3 -3
- package/types/Clock.d.ts +0 -94
- package/types/Deferred.d.ts +0 -6
- package/types/Events.d.ts +0 -77
- package/types/Extent.d.ts +0 -166
- package/types/Globe.d.ts +0 -82
- package/types/ImageCanvas.d.ts +0 -123
- package/types/Lock.d.ts +0 -12
- package/types/LonLat.d.ts +0 -108
- package/types/Popup.d.ts +0 -42
- package/types/QueueArray.d.ts +0 -19
- package/types/Rectangle.d.ts +0 -80
- package/types/Stack.d.ts +0 -19
- package/types/ajax.d.ts +0 -24
- package/types/arial.d.ts +0 -48
- package/types/astro/astro.d.ts +0 -38
- package/types/astro/earth.d.ts +0 -7
- package/types/astro/jd.d.ts +0 -254
- package/types/bv/Box.d.ts +0 -30
- package/types/bv/Sphere.d.ts +0 -38
- package/types/bv/index.d.ts +0 -3
- package/types/camera/Camera.d.ts +0 -312
- package/types/camera/Frustum.d.ts +0 -133
- package/types/camera/PlanetCamera.d.ts +0 -218
- package/types/camera/index.d.ts +0 -3
- package/types/cons.d.ts +0 -40
- package/types/control/CompassButton.d.ts +0 -17
- package/types/control/Control.d.ts +0 -104
- package/types/control/DebugInfo.d.ts +0 -15
- package/types/control/EarthCoordinates.d.ts +0 -47
- package/types/control/EarthNavigation.d.ts +0 -42
- package/types/control/GeoImageDragControl.d.ts +0 -6
- package/types/control/KeyboardNavigation.d.ts +0 -21
- package/types/control/LayerSwitcher.d.ts +0 -21
- package/types/control/Lighting.d.ts +0 -16
- package/types/control/MouseNavigation.d.ts +0 -47
- package/types/control/ScaleControl.d.ts +0 -22
- package/types/control/ShowFps.d.ts +0 -11
- package/types/control/SimpleNavigation.d.ts +0 -25
- package/types/control/Sun.d.ts +0 -50
- package/types/control/ToggleWireframe.d.ts +0 -12
- package/types/control/TouchNavigation.d.ts +0 -48
- package/types/control/ZoomControl.d.ts +0 -27
- package/types/control/index.d.ts +0 -17
- package/types/ellipsoid/Ellipsoid.d.ts +0 -146
- package/types/ellipsoid/index.d.ts +0 -3
- package/types/ellipsoid/wgs84.d.ts +0 -6
- package/types/entity/BaseBillboard.d.ts +0 -208
- package/types/entity/Billboard.d.ts +0 -94
- package/types/entity/BillboardHandler.d.ts +0 -78
- package/types/entity/Entity.d.ts +0 -333
- package/types/entity/EntityCollection.d.ts +0 -311
- package/types/entity/Geometry.d.ts +0 -74
- package/types/entity/GeometryHandler.d.ts +0 -76
- package/types/entity/Label.d.ts +0 -189
- package/types/entity/LabelHandler.d.ts +0 -29
- package/types/entity/PointCloud.d.ts +0 -174
- package/types/entity/PointCloudHandler.d.ts +0 -38
- package/types/entity/Polyline.d.ts +0 -306
- package/types/entity/PolylineHandler.d.ts +0 -18
- package/types/entity/Ray.d.ts +0 -124
- package/types/entity/RayHandler.d.ts +0 -67
- package/types/entity/ShapeHandler.d.ts +0 -22
- package/types/entity/Strip.d.ts +0 -119
- package/types/entity/StripHandler.d.ts +0 -38
- package/types/entity/index.d.ts +0 -8
- package/types/index.core.d.ts +0 -65
- package/types/index.d.ts +0 -45
- package/types/index.webgl.d.ts +0 -7
- package/types/input/KeyboardHandler.d.ts +0 -10
- package/types/input/MouseHandler.d.ts +0 -5
- package/types/input/TouchHandler.d.ts +0 -5
- package/types/input/input.d.ts +0 -34
- package/types/layer/BaseGeoImage.d.ts +0 -94
- package/types/layer/CanvasTiles.d.ts +0 -68
- package/types/layer/GeoImage.d.ts +0 -52
- package/types/layer/GeoTexture2d.d.ts +0 -8
- package/types/layer/GeoVideo.d.ts +0 -55
- package/types/layer/KML.d.ts +0 -63
- package/types/layer/Layer.d.ts +0 -325
- package/types/layer/Material.d.ts +0 -45
- package/types/layer/Vector.d.ts +0 -208
- package/types/layer/WMS.d.ts +0 -63
- package/types/layer/XYZ.d.ts +0 -120
- package/types/layer/index.d.ts +0 -10
- package/types/light/LightSource.d.ts +0 -178
- package/types/math/Line2.d.ts +0 -11
- package/types/math/Line3.d.ts +0 -10
- package/types/math/Mat3.d.ts +0 -65
- package/types/math/Mat4.d.ts +0 -176
- package/types/math/Plane.d.ts +0 -18
- package/types/math/Quat.d.ts +0 -379
- package/types/math/Ray.d.ts +0 -82
- package/types/math/Vec2.d.ts +0 -309
- package/types/math/Vec3.d.ts +0 -460
- package/types/math/Vec4.d.ts +0 -162
- package/types/math/coder.d.ts +0 -43
- package/types/math/index.d.ts +0 -11
- package/types/math.d.ts +0 -261
- package/types/mercator.d.ts +0 -92
- package/types/proj/EPSG3857.d.ts +0 -6
- package/types/proj/EPSG4326.d.ts +0 -6
- package/types/proj/Proj.d.ts +0 -42
- package/types/quadTree/EntityCollectionNode.d.ts +0 -34
- package/types/quadTree/Node.d.ts +0 -61
- package/types/quadTree/quadTree.d.ts +0 -40
- package/types/renderer/Renderer.d.ts +0 -298
- package/types/renderer/RendererEvents.d.ts +0 -233
- package/types/res/images.d.ts +0 -3
- package/types/scene/Axes.d.ts +0 -11
- package/types/scene/BaseNode.d.ts +0 -60
- package/types/scene/Planet.d.ts +0 -577
- package/types/scene/RenderNode.d.ts +0 -142
- package/types/scene/SkyBox.d.ts +0 -10
- package/types/scene/index.d.ts +0 -4
- package/types/segment/Segment.d.ts +0 -279
- package/types/segment/SegmentLonLat.d.ts +0 -16
- package/types/segment/segmentHelper.d.ts +0 -13
- package/types/shaders/billboard.d.ts +0 -3
- package/types/shaders/depth.d.ts +0 -2
- package/types/shaders/drawnode.d.ts +0 -7
- package/types/shaders/label.d.ts +0 -4
- package/types/shaders/pointCloud.d.ts +0 -2
- package/types/shaders/polyline.d.ts +0 -3
- package/types/shaders/ray.d.ts +0 -2
- package/types/shaders/screenFrame.d.ts +0 -2
- package/types/shaders/shape.d.ts +0 -4
- package/types/shaders/skybox.d.ts +0 -2
- package/types/shaders/toneMapping.d.ts +0 -2
- package/types/shapes/BaseShape.d.ts +0 -250
- package/types/shapes/Sphere.d.ts +0 -41
- package/types/terrain/BilTerrain.d.ts +0 -7
- package/types/terrain/EmptyTerrain.d.ts +0 -72
- package/types/terrain/Geoid.d.ts +0 -26
- package/types/terrain/GlobusTerrain.d.ts +0 -116
- package/types/terrain/MapboxTerrain.d.ts +0 -7
- package/types/terrain/index.d.ts +0 -5
- package/types/utils/FontAtlas.d.ts +0 -14
- package/types/utils/GeoImageCreator.d.ts +0 -30
- package/types/utils/ImagesCacheManager.d.ts +0 -10
- package/types/utils/Loader.d.ts +0 -25
- package/types/utils/NormalMapCreator.d.ts +0 -39
- package/types/utils/PlainSegmentWorker.d.ts +0 -10
- package/types/utils/TerrainWorker.d.ts +0 -9
- package/types/utils/TextureAtlas.d.ts +0 -111
- package/types/utils/VectorTileCreator.d.ts +0 -16
- package/types/utils/colorTable.d.ts +0 -143
- package/types/utils/earcut.d.ts +0 -6
- package/types/utils/shared.d.ts +0 -231
- package/types/webgl/Framebuffer.d.ts +0 -135
- package/types/webgl/Handler.d.ts +0 -388
- package/types/webgl/Multisample.d.ts +0 -89
- package/types/webgl/Program.d.ts +0 -155
- package/types/webgl/ProgramController.d.ts +0 -89
- package/types/webgl/callbacks.d.ts +0 -1
- package/types/webgl/index.d.ts +0 -6
- package/types/webgl/types.d.ts +0 -2
package/src/og/webgl/Handler.js
CHANGED
|
@@ -12,25 +12,20 @@ import { ProgramController } from "./ProgramController.js";
|
|
|
12
12
|
import { Stack } from "../Stack.js";
|
|
13
13
|
import { Vec2 } from "../math/Vec2.js";
|
|
14
14
|
|
|
15
|
-
/**
|
|
16
|
-
* Maximum texture image size.
|
|
17
|
-
* @const
|
|
18
|
-
* @type {number}
|
|
19
|
-
*/
|
|
20
|
-
const MAX_SIZE = 4096;
|
|
21
|
-
|
|
22
15
|
const vendorPrefixes = ["", "WEBKIT_", "MOZ_"];
|
|
23
16
|
|
|
17
|
+
// Maximal mipmap levels
|
|
18
|
+
const MAX_LEVELS = 2;
|
|
19
|
+
|
|
24
20
|
/**
|
|
25
21
|
* A WebGL handler for accessing low-level WebGL capabilities.
|
|
26
22
|
* @class
|
|
27
23
|
* @param {string} id - Canvas element id that WebGL handler assing with. If it's null
|
|
28
24
|
* or undefined creates hidden canvas and handler bacomes hidden.
|
|
29
25
|
* @param {Object} [params] - Handler options:
|
|
30
|
-
* @param {number} [params.anisotropy] -
|
|
26
|
+
* @param {number} [params.anisotropy] - Anisotropy filter degree. 8 is default.
|
|
31
27
|
* @param {number} [params.width] - Hidden handler width. 256 is default.
|
|
32
28
|
* @param {number} [params.height] - Hidden handler height. 256 is default.
|
|
33
|
-
* @param {Object} [param.scontext] - Native WebGL context attributes. See https://www.khronos.org/registry/webgl/specs/latest/1.0/#WEBGLCONTEXTATTRIBUTES
|
|
34
29
|
* @param {Array.<string>} [params.extensions] - Additional WebGL extension list. Available by default: EXT_texture_filter_anisotropic.
|
|
35
30
|
*/
|
|
36
31
|
class Handler {
|
|
@@ -93,21 +88,13 @@ class Handler {
|
|
|
93
88
|
* @type {Object}
|
|
94
89
|
*/
|
|
95
90
|
this._params = params || {};
|
|
96
|
-
this._params.anisotropy = this._params.anisotropy ||
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
}
|
|
101
|
-
this._params.width = w || 256;
|
|
102
|
-
|
|
103
|
-
var h = this._params.height;
|
|
104
|
-
if (h > MAX_SIZE) {
|
|
105
|
-
h = MAX_SIZE;
|
|
106
|
-
}
|
|
107
|
-
this._params.height = h || 256;
|
|
91
|
+
this._params.anisotropy = this._params.anisotropy || 4;
|
|
92
|
+
this._params.width = this._params.width || 256;
|
|
93
|
+
this._params.height = this._params.height || 256;
|
|
94
|
+
this._params.pixelRatio = this._params.pixelRatio || 1.0;
|
|
108
95
|
this._params.context = this._params.context || {};
|
|
109
96
|
this._params.extensions = this._params.extensions || [];
|
|
110
|
-
this._oneByHeight = 1 / this._params.height;
|
|
97
|
+
this._oneByHeight = 1.0 / (this._params.height * this._params.pixelRatio);
|
|
111
98
|
|
|
112
99
|
/**
|
|
113
100
|
* Current WebGL extensions. Becomes here after context initialization.
|
|
@@ -132,12 +119,21 @@ class Handler {
|
|
|
132
119
|
* @private
|
|
133
120
|
* @type {frameCallback}
|
|
134
121
|
*/
|
|
135
|
-
this._frameCallback = function () {};
|
|
122
|
+
this._frameCallback = function () { };
|
|
136
123
|
|
|
137
124
|
this.transparentTexture = null;
|
|
138
125
|
|
|
139
126
|
this.framebufferStack = new Stack();
|
|
140
127
|
|
|
128
|
+
this.createTexture = {
|
|
129
|
+
"NEAREST": null,
|
|
130
|
+
"LINEAR": null,
|
|
131
|
+
"MIPMAP": null,
|
|
132
|
+
"ANISOTROPIC": null
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
this.createTextureDefault = null;
|
|
136
|
+
|
|
141
137
|
if (params.autoActivate || isEmpty(params.autoActivate)) {
|
|
142
138
|
this.initialize();
|
|
143
139
|
}
|
|
@@ -150,7 +146,7 @@ class Handler {
|
|
|
150
146
|
* @returns {Object} -
|
|
151
147
|
*/
|
|
152
148
|
static getExtension(gl, name) {
|
|
153
|
-
|
|
149
|
+
let i, ext;
|
|
154
150
|
for (i in vendorPrefixes) {
|
|
155
151
|
ext = gl.getExtension(vendorPrefixes[i] + name);
|
|
156
152
|
if (ext) {
|
|
@@ -168,12 +164,13 @@ class Handler {
|
|
|
168
164
|
*/
|
|
169
165
|
static getContext(canvas, contextAttributes) {
|
|
170
166
|
const CONTEXT_TYPE = ["webgl2", "webgl"];
|
|
171
|
-
|
|
167
|
+
let ctx = null;
|
|
172
168
|
|
|
173
169
|
try {
|
|
174
170
|
for (let i = 0; i < CONTEXT_TYPE.length; i++) {
|
|
175
171
|
ctx = canvas.getContext(CONTEXT_TYPE[i], contextAttributes);
|
|
176
172
|
if (ctx) {
|
|
173
|
+
console.log(CONTEXT_TYPE[i]);
|
|
177
174
|
ctx.type = CONTEXT_TYPE[i];
|
|
178
175
|
break;
|
|
179
176
|
}
|
|
@@ -219,8 +216,8 @@ class Handler {
|
|
|
219
216
|
type = "UNSIGNED_BYTE",
|
|
220
217
|
level = 0
|
|
221
218
|
) {
|
|
222
|
-
|
|
223
|
-
|
|
219
|
+
let gl = this.gl;
|
|
220
|
+
let texture = gl.createTexture();
|
|
224
221
|
gl.bindTexture(gl.TEXTURE_2D, texture);
|
|
225
222
|
gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, false);
|
|
226
223
|
|
|
@@ -245,48 +242,6 @@ class Handler {
|
|
|
245
242
|
return texture;
|
|
246
243
|
}
|
|
247
244
|
|
|
248
|
-
///**
|
|
249
|
-
// * Creates Empty half float texture.
|
|
250
|
-
// * @public
|
|
251
|
-
// * @param {number} width - Empty texture width.
|
|
252
|
-
// * @param {number} height - Empty texture height.
|
|
253
|
-
// * @returns {Object} - WebGL half float texture object.
|
|
254
|
-
// */
|
|
255
|
-
//createEmptyTexture_hf(width, height) {
|
|
256
|
-
// var gl = this.gl;
|
|
257
|
-
// var texture = gl.createTexture();
|
|
258
|
-
// gl.bindTexture(gl.TEXTURE_2D, texture);
|
|
259
|
-
// gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, false);
|
|
260
|
-
// gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, width, height, 0, gl.RGBA, gl.HALF_FLOAT_OES, null);
|
|
261
|
-
// //gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
|
|
262
|
-
// //gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
|
|
263
|
-
// //gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
|
|
264
|
-
// //gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
|
|
265
|
-
// gl.bindTexture(gl.TEXTURE_2D, null);
|
|
266
|
-
// return texture;
|
|
267
|
-
//}
|
|
268
|
-
|
|
269
|
-
///**
|
|
270
|
-
// * Creates Empty float texture.
|
|
271
|
-
// * @public
|
|
272
|
-
// * @param {number} width - Empty texture width.
|
|
273
|
-
// * @param {number} height - Empty texture height.
|
|
274
|
-
// * @returns {Object} - WebGL float texture object.
|
|
275
|
-
// */
|
|
276
|
-
//createEmptyTexture_f(width, height) {
|
|
277
|
-
// var gl = this.gl;
|
|
278
|
-
// var texture = gl.createTexture();
|
|
279
|
-
// gl.bindTexture(gl.TEXTURE_2D, texture);
|
|
280
|
-
// gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, false);
|
|
281
|
-
// gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, width, height, 0, gl.RGBA, gl.FLOAT, null);
|
|
282
|
-
// //gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
|
|
283
|
-
// //gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
|
|
284
|
-
// //gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
|
|
285
|
-
// //gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
|
|
286
|
-
// gl.bindTexture(gl.TEXTURE_2D, null);
|
|
287
|
-
// return texture;
|
|
288
|
-
//}
|
|
289
|
-
|
|
290
245
|
/**
|
|
291
246
|
* Creates Empty NEAREST filtered texture.
|
|
292
247
|
* @public
|
|
@@ -294,12 +249,12 @@ class Handler {
|
|
|
294
249
|
* @param {number} height - Empty texture height.
|
|
295
250
|
* @returns {Object} - WebGL texture object.
|
|
296
251
|
*/
|
|
297
|
-
createEmptyTexture_n(width, height) {
|
|
298
|
-
|
|
299
|
-
|
|
252
|
+
createEmptyTexture_n(width, height, internalFormat) {
|
|
253
|
+
let gl = this.gl;
|
|
254
|
+
let texture = gl.createTexture();
|
|
300
255
|
gl.bindTexture(gl.TEXTURE_2D, texture);
|
|
301
256
|
gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, false);
|
|
302
|
-
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, width, height, 0, gl.RGBA, gl.UNSIGNED_BYTE, null);
|
|
257
|
+
gl.texImage2D(gl.TEXTURE_2D, 0, internalFormat || gl.RGBA, width, height, 0, gl.RGBA, gl.UNSIGNED_BYTE, null);
|
|
303
258
|
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
|
|
304
259
|
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
|
|
305
260
|
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
|
|
@@ -315,12 +270,12 @@ class Handler {
|
|
|
315
270
|
* @param {number} height - Empty texture height.
|
|
316
271
|
* @returns {Object} - WebGL texture object.
|
|
317
272
|
*/
|
|
318
|
-
createEmptyTexture_l(width, height) {
|
|
319
|
-
|
|
320
|
-
|
|
273
|
+
createEmptyTexture_l(width, height, internalFormat) {
|
|
274
|
+
let gl = this.gl;
|
|
275
|
+
let texture = gl.createTexture();
|
|
321
276
|
gl.bindTexture(gl.TEXTURE_2D, texture);
|
|
322
277
|
gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, false);
|
|
323
|
-
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, width, height, 0, gl.RGBA, gl.UNSIGNED_BYTE, null);
|
|
278
|
+
gl.texImage2D(gl.TEXTURE_2D, 0, internalFormat || gl.RGBA, width, height, 0, gl.RGBA, gl.UNSIGNED_BYTE, null);
|
|
324
279
|
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
|
|
325
280
|
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
|
|
326
281
|
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
|
|
@@ -335,12 +290,12 @@ class Handler {
|
|
|
335
290
|
* @param {Object} image - Image or Canvas object.
|
|
336
291
|
* @returns {Object} - WebGL texture object.
|
|
337
292
|
*/
|
|
338
|
-
|
|
339
|
-
var gl =
|
|
293
|
+
createTexture_n_webgl1(image, internalFormat) {
|
|
294
|
+
var gl = this.gl;
|
|
340
295
|
var texture = gl.createTexture();
|
|
341
296
|
gl.bindTexture(gl.TEXTURE_2D, texture);
|
|
342
297
|
gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, false);
|
|
343
|
-
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, image);
|
|
298
|
+
gl.texImage2D(gl.TEXTURE_2D, 0, internalFormat || gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, image);
|
|
344
299
|
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
|
|
345
300
|
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
|
|
346
301
|
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
|
|
@@ -355,11 +310,13 @@ class Handler {
|
|
|
355
310
|
* @param {Object} image - Image or Canvas object.
|
|
356
311
|
* @returns {Object} - WebGL texture object.
|
|
357
312
|
*/
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
313
|
+
createTexture_l_webgl1(image, internalFormat) {
|
|
314
|
+
let gl = this.gl;
|
|
315
|
+
let texture = gl.createTexture();
|
|
361
316
|
gl.bindTexture(gl.TEXTURE_2D, texture);
|
|
362
|
-
|
|
317
|
+
|
|
318
|
+
gl.texImage2D(gl.TEXTURE_2D, 0, internalFormat || gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, image);
|
|
319
|
+
|
|
363
320
|
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
|
|
364
321
|
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
|
|
365
322
|
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
|
|
@@ -374,12 +331,14 @@ class Handler {
|
|
|
374
331
|
* @param {Object} image - Image or Canvas object.
|
|
375
332
|
* @returns {Object} - WebGL texture object.
|
|
376
333
|
*/
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
334
|
+
createTexture_mm_webgl1(image, internalFormat) {
|
|
335
|
+
let gl = this.gl;
|
|
336
|
+
let texture = gl.createTexture();
|
|
380
337
|
gl.bindTexture(gl.TEXTURE_2D, texture);
|
|
381
338
|
gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, false);
|
|
382
|
-
|
|
339
|
+
|
|
340
|
+
gl.texImage2D(gl.TEXTURE_2D, 0, internalFormat || gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, image);
|
|
341
|
+
|
|
383
342
|
gl.generateMipmap(gl.TEXTURE_2D);
|
|
384
343
|
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR_MIPMAP_LINEAR);
|
|
385
344
|
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
|
|
@@ -394,19 +353,17 @@ class Handler {
|
|
|
394
353
|
* @param {Object} image - Image or Canvas object.
|
|
395
354
|
* @returns {Object} - WebGL texture object.
|
|
396
355
|
*/
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
356
|
+
createTexture_a_webgl1(image, internalFormat) {
|
|
357
|
+
let gl = this.gl;
|
|
358
|
+
let texture = gl.createTexture();
|
|
400
359
|
gl.bindTexture(gl.TEXTURE_2D, texture);
|
|
401
360
|
gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, false);
|
|
402
|
-
|
|
361
|
+
|
|
362
|
+
gl.texImage2D(gl.TEXTURE_2D, 0, internalFormat || gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, image);
|
|
363
|
+
|
|
403
364
|
gl.generateMipmap(gl.TEXTURE_2D);
|
|
404
365
|
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR_MIPMAP_LINEAR);
|
|
405
|
-
gl.texParameterf(
|
|
406
|
-
gl.TEXTURE_2D,
|
|
407
|
-
handler.extensions.EXT_texture_filter_anisotropic.TEXTURE_MAX_ANISOTROPY_EXT,
|
|
408
|
-
handler._params.anisotropy
|
|
409
|
-
);
|
|
366
|
+
gl.texParameterf(gl.TEXTURE_2D, this.extensions.EXT_texture_filter_anisotropic.TEXTURE_MAX_ANISOTROPY_EXT, this._params.anisotropy);
|
|
410
367
|
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
|
|
411
368
|
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
|
|
412
369
|
gl.bindTexture(gl.TEXTURE_2D, null);
|
|
@@ -414,29 +371,95 @@ class Handler {
|
|
|
414
371
|
}
|
|
415
372
|
|
|
416
373
|
/**
|
|
417
|
-
* Creates
|
|
374
|
+
* Creates NEAREST filter texture.
|
|
418
375
|
* @public
|
|
419
376
|
* @param {Object} image - Image or Canvas object.
|
|
420
377
|
* @returns {Object} - WebGL texture object.
|
|
421
378
|
*/
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
379
|
+
createTexture_n_webgl2(image, internalFormat) {
|
|
380
|
+
var gl = this.gl;
|
|
381
|
+
var texture = gl.createTexture();
|
|
382
|
+
gl.bindTexture(gl.TEXTURE_2D, texture);
|
|
383
|
+
gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, false);
|
|
425
384
|
|
|
426
|
-
|
|
427
|
-
|
|
385
|
+
gl.texStorage2D(gl.TEXTURE_2D, 1, internalFormat || gl.RGBA8, image.width, image.height);
|
|
386
|
+
gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, 0, image.width, image.height, gl.RGBA, gl.UNSIGNED_BYTE, image);
|
|
387
|
+
|
|
388
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
|
|
389
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
|
|
390
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
|
|
391
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
|
|
392
|
+
gl.bindTexture(gl.TEXTURE_2D, null);
|
|
393
|
+
return texture;
|
|
428
394
|
}
|
|
429
395
|
|
|
430
|
-
|
|
431
|
-
|
|
396
|
+
/**
|
|
397
|
+
* Creates LINEAR filter texture.
|
|
398
|
+
* @public
|
|
399
|
+
* @param {Object} image - Image or Canvas object.
|
|
400
|
+
* @returns {Object} - WebGL texture object.
|
|
401
|
+
*/
|
|
402
|
+
createTexture_l_webgl2(image, internalFormat) {
|
|
403
|
+
let gl = this.gl;
|
|
404
|
+
let texture = gl.createTexture();
|
|
405
|
+
gl.bindTexture(gl.TEXTURE_2D, texture);
|
|
406
|
+
|
|
407
|
+
gl.texStorage2D(gl.TEXTURE_2D, 1, internalFormat || gl.RGBA8, image.width, image.height);
|
|
408
|
+
gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, 0, image.width, image.height, gl.RGBA, gl.UNSIGNED_BYTE, image);
|
|
409
|
+
|
|
410
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
|
|
411
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
|
|
412
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
|
|
413
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
|
|
414
|
+
gl.bindTexture(gl.TEXTURE_2D, null);
|
|
415
|
+
return texture;
|
|
432
416
|
}
|
|
433
417
|
|
|
434
|
-
|
|
435
|
-
|
|
418
|
+
/**
|
|
419
|
+
* Creates MIPMAP filter texture.
|
|
420
|
+
* @public
|
|
421
|
+
* @param {Object} image - Image or Canvas object.
|
|
422
|
+
* @returns {Object} - WebGL texture object.
|
|
423
|
+
*/
|
|
424
|
+
createTexture_mm_webgl2(image, internalFormat) {
|
|
425
|
+
let gl = this.gl;
|
|
426
|
+
let texture = gl.createTexture();
|
|
427
|
+
gl.bindTexture(gl.TEXTURE_2D, texture);
|
|
428
|
+
gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, false);
|
|
429
|
+
|
|
430
|
+
gl.texStorage2D(gl.TEXTURE_2D, MAX_LEVELS, internalFormat || gl.RGBA8, image.width, image.height);
|
|
431
|
+
gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, 0, image.width, image.height, gl.RGBA, gl.UNSIGNED_BYTE, image);
|
|
432
|
+
|
|
433
|
+
gl.generateMipmap(gl.TEXTURE_2D);
|
|
434
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR_MIPMAP_LINEAR);
|
|
435
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
|
|
436
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
|
|
437
|
+
gl.bindTexture(gl.TEXTURE_2D, null);
|
|
438
|
+
return texture;
|
|
436
439
|
}
|
|
437
440
|
|
|
438
|
-
|
|
439
|
-
|
|
441
|
+
/**
|
|
442
|
+
* Creates ANISOTROPY filter texture.
|
|
443
|
+
* @public
|
|
444
|
+
* @param {Object} image - Image or Canvas object.
|
|
445
|
+
* @returns {Object} - WebGL texture object.
|
|
446
|
+
*/
|
|
447
|
+
createTexture_a_webgl2(image, internalFormat) {
|
|
448
|
+
let gl = this.gl;
|
|
449
|
+
let texture = gl.createTexture();
|
|
450
|
+
gl.bindTexture(gl.TEXTURE_2D, texture);
|
|
451
|
+
gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, false);
|
|
452
|
+
|
|
453
|
+
gl.texStorage2D(gl.TEXTURE_2D, MAX_LEVELS, internalFormat || gl.RGBA8, image.width, image.height);
|
|
454
|
+
gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, 0, image.width, image.height, gl.RGBA, gl.UNSIGNED_BYTE, image);
|
|
455
|
+
|
|
456
|
+
gl.generateMipmap(gl.TEXTURE_2D);
|
|
457
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR_MIPMAP_LINEAR);
|
|
458
|
+
gl.texParameterf(gl.TEXTURE_2D, this.extensions.EXT_texture_filter_anisotropic.TEXTURE_MAX_ANISOTROPY_EXT, this._params.anisotropy);
|
|
459
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
|
|
460
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
|
|
461
|
+
gl.bindTexture(gl.TEXTURE_2D, null);
|
|
462
|
+
return texture;
|
|
440
463
|
}
|
|
441
464
|
|
|
442
465
|
/**
|
|
@@ -452,15 +475,15 @@ class Handler {
|
|
|
452
475
|
* @returns {Object} - WebGL texture object.
|
|
453
476
|
*/
|
|
454
477
|
loadCubeMapTexture(params) {
|
|
455
|
-
|
|
456
|
-
|
|
478
|
+
let gl = this.gl;
|
|
479
|
+
let texture = gl.createTexture();
|
|
457
480
|
gl.bindTexture(gl.TEXTURE_CUBE_MAP, texture);
|
|
458
481
|
gl.texParameteri(gl.TEXTURE_CUBE_MAP, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
|
|
459
482
|
gl.texParameteri(gl.TEXTURE_CUBE_MAP, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
|
|
460
483
|
gl.texParameteri(gl.TEXTURE_CUBE_MAP, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
|
|
461
484
|
gl.texParameteri(gl.TEXTURE_CUBE_MAP, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
|
|
462
485
|
|
|
463
|
-
|
|
486
|
+
let faces = [
|
|
464
487
|
[params.px, gl.TEXTURE_CUBE_MAP_POSITIVE_X],
|
|
465
488
|
[params.nx, gl.TEXTURE_CUBE_MAP_NEGATIVE_X],
|
|
466
489
|
[params.py, gl.TEXTURE_CUBE_MAP_POSITIVE_Y],
|
|
@@ -469,9 +492,9 @@ class Handler {
|
|
|
469
492
|
[params.nz, gl.TEXTURE_CUBE_MAP_NEGATIVE_Z]
|
|
470
493
|
];
|
|
471
494
|
|
|
472
|
-
|
|
495
|
+
let imageCanvas = new ImageCanvas();
|
|
473
496
|
imageCanvas.fillEmpty();
|
|
474
|
-
|
|
497
|
+
let emptyImage = imageCanvas.getImage();
|
|
475
498
|
|
|
476
499
|
for (let i = 0; i < faces.length; i++) {
|
|
477
500
|
let face = faces[i][1];
|
|
@@ -505,7 +528,7 @@ class Handler {
|
|
|
505
528
|
*/
|
|
506
529
|
addProgram(program, notActivate) {
|
|
507
530
|
if (!this.programs[program.name]) {
|
|
508
|
-
|
|
531
|
+
let sc = new ProgramController(this, program);
|
|
509
532
|
this.programs[program.name] = sc;
|
|
510
533
|
this._initProgramController(sc);
|
|
511
534
|
if (notActivate) {
|
|
@@ -534,7 +557,7 @@ class Handler {
|
|
|
534
557
|
* @param {Array.<Program>} programsArr - Shader program array.
|
|
535
558
|
*/
|
|
536
559
|
addPrograms(programsArr) {
|
|
537
|
-
for (
|
|
560
|
+
for (let i = 0; i < programsArr.length; i++) {
|
|
538
561
|
this.addProgram(programsArr[i]);
|
|
539
562
|
}
|
|
540
563
|
}
|
|
@@ -563,7 +586,7 @@ class Handler {
|
|
|
563
586
|
* @private
|
|
564
587
|
*/
|
|
565
588
|
_initPrograms() {
|
|
566
|
-
for (
|
|
589
|
+
for (let p in this.programs) {
|
|
567
590
|
this._initProgramController(this.programs[p]);
|
|
568
591
|
}
|
|
569
592
|
}
|
|
@@ -577,7 +600,7 @@ class Handler {
|
|
|
577
600
|
*/
|
|
578
601
|
initializeExtension(extensionStr, showLog) {
|
|
579
602
|
if (!(this.extensions && this.extensions[extensionStr])) {
|
|
580
|
-
|
|
603
|
+
let ext = Handler.getExtension(this.gl, extensionStr);
|
|
581
604
|
if (ext) {
|
|
582
605
|
this.extensions[extensionStr] = ext;
|
|
583
606
|
} else if (showLog) {
|
|
@@ -618,13 +641,28 @@ class Handler {
|
|
|
618
641
|
this._params.extensions.push("OES_texture_float_linear");
|
|
619
642
|
}
|
|
620
643
|
|
|
621
|
-
|
|
644
|
+
let i = this._params.extensions.length;
|
|
622
645
|
while (i--) {
|
|
623
646
|
this.initializeExtension(this._params.extensions[i], true);
|
|
624
647
|
}
|
|
625
648
|
|
|
649
|
+
//
|
|
650
|
+
//TODO: webgl1 case
|
|
651
|
+
//
|
|
652
|
+
this.createTexture_n = this.createTexture_n_webgl2.bind(this);
|
|
653
|
+
this.createTexture_l = this.createTexture_l_webgl2.bind(this);
|
|
654
|
+
this.createTexture_mm = this.createTexture_mm_webgl2.bind(this);
|
|
655
|
+
this.createTexture_a = this.createTexture_a_webgl2.bind(this);
|
|
656
|
+
|
|
657
|
+
this.createTexture["NEAREST"] = this.createTexture_n;
|
|
658
|
+
this.createTexture["LINEAR"] = this.createTexture_l;
|
|
659
|
+
this.createTexture["MIPMAP"] = this.createTexture_mm;
|
|
660
|
+
this.createTexture["ANISOTROPIC"] = this.createTexture_a;
|
|
661
|
+
|
|
626
662
|
if (!this.extensions.EXT_texture_filter_anisotropic) {
|
|
627
|
-
this.
|
|
663
|
+
this.createTextureDefault = this.createTexture_mm;
|
|
664
|
+
} else {
|
|
665
|
+
this.createTextureDefault = this.createTexture_a;
|
|
628
666
|
}
|
|
629
667
|
|
|
630
668
|
/** Initilalize shaders and rendering parameters*/
|
|
@@ -646,7 +684,7 @@ class Handler {
|
|
|
646
684
|
this.gl.cullFace(this.gl.BACK);
|
|
647
685
|
this.activateFaceCulling();
|
|
648
686
|
this.deactivateBlending();
|
|
649
|
-
|
|
687
|
+
let that = this;
|
|
650
688
|
this.createDefaultTexture({ color: "rgba(0,0,0,0.0)" }, function (t) {
|
|
651
689
|
that.transparentTexture = t;
|
|
652
690
|
});
|
|
@@ -710,7 +748,7 @@ class Handler {
|
|
|
710
748
|
* @return {Object} -
|
|
711
749
|
*/
|
|
712
750
|
createStreamArrayBuffer(itemSize, numItems, usage, bites = 4) {
|
|
713
|
-
|
|
751
|
+
let buffer = this.gl.createBuffer();
|
|
714
752
|
this.gl.bindBuffer(this.gl.ARRAY_BUFFER, buffer);
|
|
715
753
|
this.gl.bufferData(
|
|
716
754
|
this.gl.ARRAY_BUFFER,
|
|
@@ -750,7 +788,7 @@ class Handler {
|
|
|
750
788
|
* @return {Object} -
|
|
751
789
|
*/
|
|
752
790
|
createArrayBuffer(array, itemSize, numItems, usage) {
|
|
753
|
-
|
|
791
|
+
let buffer = this.gl.createBuffer();
|
|
754
792
|
this.gl.bindBuffer(this.gl.ARRAY_BUFFER, buffer);
|
|
755
793
|
this.gl.bufferData(this.gl.ARRAY_BUFFER, array, usage || this.gl.STATIC_DRAW);
|
|
756
794
|
this.gl.bindBuffer(this.gl.ARRAY_BUFFER, null);
|
|
@@ -759,6 +797,25 @@ class Handler {
|
|
|
759
797
|
return buffer;
|
|
760
798
|
}
|
|
761
799
|
|
|
800
|
+
/**
|
|
801
|
+
* Creates ARRAY buffer specific length.
|
|
802
|
+
* @public
|
|
803
|
+
* @param {Array.<number>} array - Input array.
|
|
804
|
+
* @param {number} itemSize - Array item size.
|
|
805
|
+
* @param {number} numItems - Items quantity.
|
|
806
|
+
* @param {number} [usage=STATIC_DRAW] - Parameter of the bufferData call can be one of STATIC_DRAW, DYNAMIC_DRAW, or STREAM_DRAW.
|
|
807
|
+
* @return {Object} -
|
|
808
|
+
*/
|
|
809
|
+
createArrayBufferLength(size, usage) {
|
|
810
|
+
let buffer = this.gl.createBuffer();
|
|
811
|
+
this.gl.bindBuffer(this.gl.ARRAY_BUFFER, buffer);
|
|
812
|
+
this.gl.bufferData(this.gl.ARRAY_BUFFER, size, usage || this.gl.STATIC_DRAW);
|
|
813
|
+
this.gl.bindBuffer(this.gl.ARRAY_BUFFER, null);
|
|
814
|
+
buffer.itemSize = 1;
|
|
815
|
+
buffer.numItems = size;
|
|
816
|
+
return buffer;
|
|
817
|
+
}
|
|
818
|
+
|
|
762
819
|
/**
|
|
763
820
|
* Creates ELEMENT ARRAY buffer.
|
|
764
821
|
* @public
|
|
@@ -769,7 +826,7 @@ class Handler {
|
|
|
769
826
|
* @return {Object} -
|
|
770
827
|
*/
|
|
771
828
|
createElementArrayBuffer(array, itemSize, numItems, usage) {
|
|
772
|
-
|
|
829
|
+
let buffer = this.gl.createBuffer();
|
|
773
830
|
this.gl.bindBuffer(this.gl.ELEMENT_ARRAY_BUFFER, buffer);
|
|
774
831
|
this.gl.bufferData(this.gl.ELEMENT_ARRAY_BUFFER, array, usage || this.gl.STATIC_DRAW);
|
|
775
832
|
this.gl.bindBuffer(this.gl.ELEMENT_ARRAY_BUFFER, null);
|
|
@@ -785,24 +842,26 @@ class Handler {
|
|
|
785
842
|
* @param {number} h - Canvas height.
|
|
786
843
|
*/
|
|
787
844
|
setSize(w, h) {
|
|
788
|
-
if (w > MAX_SIZE) {
|
|
789
|
-
w = MAX_SIZE;
|
|
790
|
-
}
|
|
791
|
-
|
|
792
|
-
if (h > MAX_SIZE) {
|
|
793
|
-
h = MAX_SIZE;
|
|
794
|
-
}
|
|
795
|
-
|
|
796
845
|
this._params.width = w;
|
|
797
846
|
this._params.height = h;
|
|
798
|
-
this.canvas.width = w;
|
|
799
|
-
this.canvas.height = h;
|
|
800
|
-
|
|
847
|
+
this.canvas.width = w * this._params.pixelRatio;
|
|
848
|
+
this.canvas.height = h * this._params.pixelRatio;
|
|
849
|
+
|
|
850
|
+
this._oneByHeight = 1.0 / this.canvas.height;
|
|
801
851
|
|
|
802
852
|
this.gl && this.gl.viewport(0, 0, w, h);
|
|
803
853
|
this.onCanvasResize && this.onCanvasResize(this.canvas);
|
|
804
854
|
}
|
|
805
855
|
|
|
856
|
+
get pixelRatio() {
|
|
857
|
+
return this._params.pixelRatio;
|
|
858
|
+
}
|
|
859
|
+
|
|
860
|
+
set pixelRatio(pr) {
|
|
861
|
+
this._params.pixelRatio = pr;
|
|
862
|
+
this.setSize(this._params.width, this._params.height);
|
|
863
|
+
}
|
|
864
|
+
|
|
806
865
|
/**
|
|
807
866
|
* Returns context screen width.
|
|
808
867
|
* @public
|
|
@@ -836,7 +895,7 @@ class Handler {
|
|
|
836
895
|
* @returns {number} -
|
|
837
896
|
*/
|
|
838
897
|
getCenter() {
|
|
839
|
-
|
|
898
|
+
let c = this.canvas;
|
|
840
899
|
return new Vec2(Math.round(c.width * 0.5), Math.round(c.height * 0.5));
|
|
841
900
|
}
|
|
842
901
|
|
|
@@ -847,19 +906,20 @@ class Handler {
|
|
|
847
906
|
*/
|
|
848
907
|
drawFrame() {
|
|
849
908
|
/** Calculating frame time */
|
|
850
|
-
|
|
909
|
+
let now = window.performance.now();
|
|
851
910
|
this.deltaTime = now - this._lastAnimationFrameTime;
|
|
852
911
|
this._lastAnimationFrameTime = now;
|
|
853
912
|
|
|
854
913
|
this.defaultClock._tick(this.deltaTime);
|
|
855
914
|
|
|
856
|
-
for (
|
|
915
|
+
for (let i = 0; i < this._clocks.length; i++) {
|
|
857
916
|
this._clocks[i]._tick(this.deltaTime);
|
|
858
917
|
}
|
|
859
918
|
|
|
860
919
|
/** Canvas resize checking */
|
|
861
|
-
|
|
862
|
-
|
|
920
|
+
let canvas = this.canvas;
|
|
921
|
+
|
|
922
|
+
if (Math.floor(canvas.clientWidth * this._params.pixelRatio) !== canvas.width || Math.floor(canvas.clientHeight * this._params.pixelRatio) !== canvas.height) {
|
|
863
923
|
this.setSize(canvas.clientWidth, canvas.clientHeight);
|
|
864
924
|
}
|
|
865
925
|
|
|
@@ -872,7 +932,7 @@ class Handler {
|
|
|
872
932
|
* @public
|
|
873
933
|
*/
|
|
874
934
|
clearFrame() {
|
|
875
|
-
|
|
935
|
+
let gl = this.gl;
|
|
876
936
|
this.gl.clearColor(0.0, 0.0, 0.0, 1.0);
|
|
877
937
|
gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
|
|
878
938
|
}
|
|
@@ -914,17 +974,17 @@ class Handler {
|
|
|
914
974
|
* @param {callback} [success] - Creation callback
|
|
915
975
|
*/
|
|
916
976
|
createDefaultTexture(params, success) {
|
|
917
|
-
|
|
918
|
-
|
|
977
|
+
let imgCnv;
|
|
978
|
+
let texture;
|
|
919
979
|
if (params && params.color) {
|
|
920
980
|
imgCnv = new ImageCanvas(2, 2);
|
|
921
981
|
imgCnv.fillColor(params.color);
|
|
922
|
-
texture =
|
|
982
|
+
texture = this.createTexture_n_webgl2(imgCnv._canvas, this.gl.RGBA8);
|
|
923
983
|
texture.default = true;
|
|
924
984
|
success(texture);
|
|
925
985
|
} else if (params && params.url) {
|
|
926
|
-
|
|
927
|
-
|
|
986
|
+
let img = new Image();
|
|
987
|
+
let that = this;
|
|
928
988
|
img.onload = function () {
|
|
929
989
|
texture = that.createTexture(this);
|
|
930
990
|
texture.default = true;
|
|
@@ -934,7 +994,7 @@ class Handler {
|
|
|
934
994
|
} else {
|
|
935
995
|
imgCnv = new ImageCanvas(2, 2);
|
|
936
996
|
imgCnv.fillColor("#C5C5C5");
|
|
937
|
-
texture =
|
|
997
|
+
texture = this.createTexture_n_webgl2(imgCnv._canvas, this.gl.RGBA8);
|
|
938
998
|
texture.default = true;
|
|
939
999
|
success(texture);
|
|
940
1000
|
}
|
|
@@ -944,11 +1004,11 @@ class Handler {
|
|
|
944
1004
|
* @public
|
|
945
1005
|
*/
|
|
946
1006
|
destroy() {
|
|
947
|
-
|
|
1007
|
+
let gl = this.gl;
|
|
948
1008
|
|
|
949
1009
|
this.stop();
|
|
950
1010
|
|
|
951
|
-
for (
|
|
1011
|
+
for (let p in this.programs) {
|
|
952
1012
|
this.removeProgram(p);
|
|
953
1013
|
}
|
|
954
1014
|
|
|
@@ -965,8 +1025,8 @@ class Handler {
|
|
|
965
1025
|
this.canvas.height = 1;
|
|
966
1026
|
this.canvas = null;
|
|
967
1027
|
|
|
968
|
-
|
|
969
|
-
|
|
1028
|
+
let numAttribs = gl.getParameter(gl.MAX_VERTEX_ATTRIBS);
|
|
1029
|
+
let tmp = gl.createBuffer();
|
|
970
1030
|
gl.bindBuffer(gl.ARRAY_BUFFER, tmp);
|
|
971
1031
|
for (let ii = 0; ii < numAttribs; ++ii) {
|
|
972
1032
|
gl.disableVertexAttribArray(ii);
|
|
@@ -975,7 +1035,7 @@ class Handler {
|
|
|
975
1035
|
}
|
|
976
1036
|
gl.deleteBuffer(tmp);
|
|
977
1037
|
|
|
978
|
-
|
|
1038
|
+
let numTextureUnits = gl.getParameter(gl.MAX_TEXTlURE_IMAGE_UNITS);
|
|
979
1039
|
for (let ii = 0; ii < numTextureUnits; ++ii) {
|
|
980
1040
|
gl.activeTexture(gl.TEXTURE0 + ii);
|
|
981
1041
|
gl.bindTexture(gl.TEXTURE_CUBE_MAP, null);
|
|
@@ -1013,15 +1073,15 @@ class Handler {
|
|
|
1013
1073
|
}
|
|
1014
1074
|
|
|
1015
1075
|
addClocks(clockArr) {
|
|
1016
|
-
for (
|
|
1076
|
+
for (let i = 0; i < clockArr.length; i++) {
|
|
1017
1077
|
this.addClock(clockArr[i]);
|
|
1018
1078
|
}
|
|
1019
1079
|
}
|
|
1020
1080
|
|
|
1021
1081
|
removeClock(clock) {
|
|
1022
1082
|
if (clock.__handler) {
|
|
1023
|
-
|
|
1024
|
-
|
|
1083
|
+
let c = this._clocks;
|
|
1084
|
+
let i = c.length;
|
|
1025
1085
|
while (i--) {
|
|
1026
1086
|
if (c[i].equal(clock)) {
|
|
1027
1087
|
clock.__handler = null;
|
|
@@ -1033,11 +1093,4 @@ class Handler {
|
|
|
1033
1093
|
}
|
|
1034
1094
|
}
|
|
1035
1095
|
|
|
1036
|
-
export const createTexture = {
|
|
1037
|
-
NEAREST: Handler.createTexture_n,
|
|
1038
|
-
LINEAR: Handler.createTexture_l,
|
|
1039
|
-
MIPMAP: Handler.createTexture_mm,
|
|
1040
|
-
ANISOTROPHIC: Handler.createTexture_a
|
|
1041
|
-
};
|
|
1042
|
-
|
|
1043
1096
|
export { Handler };
|