@openglobus/og 0.12.4 → 0.13.2
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 +887 -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 +800 -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 +607 -603
- package/src/og/shaders/label.js +576 -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 +4 -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/utils/shared.js
CHANGED
package/src/og/webgl/Handler.js
CHANGED
|
@@ -14,6 +14,8 @@ import { Vec2 } from "../math/Vec2.js";
|
|
|
14
14
|
|
|
15
15
|
const vendorPrefixes = ["", "WEBKIT_", "MOZ_"];
|
|
16
16
|
|
|
17
|
+
const CONTEXT_TYPE = ["webgl2", "webgl"];
|
|
18
|
+
|
|
17
19
|
// Maximal mipmap levels
|
|
18
20
|
const MAX_LEVELS = 2;
|
|
19
21
|
|
|
@@ -119,7 +121,8 @@ class Handler {
|
|
|
119
121
|
* @private
|
|
120
122
|
* @type {frameCallback}
|
|
121
123
|
*/
|
|
122
|
-
this._frameCallback = function () {
|
|
124
|
+
this._frameCallback = function () {
|
|
125
|
+
};
|
|
123
126
|
|
|
124
127
|
this.transparentTexture = null;
|
|
125
128
|
|
|
@@ -137,6 +140,8 @@ class Handler {
|
|
|
137
140
|
if (params.autoActivate || isEmpty(params.autoActivate)) {
|
|
138
141
|
this.initialize();
|
|
139
142
|
}
|
|
143
|
+
|
|
144
|
+
this.createTexture_n = this.gl.type === "webgl2" ? this.createTexture_n_webgl2 : this.createTexture_n_webgl1;
|
|
140
145
|
}
|
|
141
146
|
|
|
142
147
|
/**
|
|
@@ -163,7 +168,6 @@ class Handler {
|
|
|
163
168
|
* @returns {Object} -
|
|
164
169
|
*/
|
|
165
170
|
static getContext(canvas, contextAttributes) {
|
|
166
|
-
const CONTEXT_TYPE = ["webgl2", "webgl"];
|
|
167
171
|
let ctx = null;
|
|
168
172
|
|
|
169
173
|
try {
|
|
@@ -635,6 +639,7 @@ class Handler {
|
|
|
635
639
|
this._params.extensions.push("OES_standard_derivatives");
|
|
636
640
|
this._params.extensions.push("OES_element_index_uint");
|
|
637
641
|
this._params.extensions.push("WEBGL_depth_texture");
|
|
642
|
+
this._params.extensions.push("ANGLE_instanced_arrays");
|
|
638
643
|
//this._params.extensions.push("EXT_frag_depth");
|
|
639
644
|
} else {
|
|
640
645
|
this._params.extensions.push("EXT_color_buffer_float");
|
|
@@ -679,69 +684,22 @@ class Handler {
|
|
|
679
684
|
* @private
|
|
680
685
|
*/
|
|
681
686
|
_setDefaults() {
|
|
682
|
-
this.
|
|
687
|
+
let gl = this.gl;
|
|
688
|
+
gl.depthFunc(gl.LESS);
|
|
689
|
+
gl.enable(gl.DEPTH_TEST);
|
|
683
690
|
this.setSize(
|
|
684
691
|
this.canvas.clientWidth || this._params.width,
|
|
685
692
|
this.canvas.clientHeight || this._params.height
|
|
686
693
|
);
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
that.transparentTexture = t;
|
|
694
|
+
gl.frontFace(gl.CCW);
|
|
695
|
+
gl.cullFace(gl.BACK);
|
|
696
|
+
gl.enable(gl.CULL_FACE);
|
|
697
|
+
gl.disable(gl.BLEND);
|
|
698
|
+
this.createDefaultTexture({ color: "rgba(0,0,0,0.0)" }, (t) => {
|
|
699
|
+
this.transparentTexture = t;
|
|
694
700
|
});
|
|
695
701
|
}
|
|
696
702
|
|
|
697
|
-
/**
|
|
698
|
-
* Activate depth test.
|
|
699
|
-
* @public
|
|
700
|
-
*/
|
|
701
|
-
activateDepthTest() {
|
|
702
|
-
this.gl.enable(this.gl.DEPTH_TEST);
|
|
703
|
-
}
|
|
704
|
-
|
|
705
|
-
/**
|
|
706
|
-
* Deactivate depth test.
|
|
707
|
-
* @public
|
|
708
|
-
*/
|
|
709
|
-
deactivateDepthTest() {
|
|
710
|
-
this.gl.disable(this.gl.DEPTH_TEST);
|
|
711
|
-
}
|
|
712
|
-
|
|
713
|
-
/**
|
|
714
|
-
* Activate face culling.
|
|
715
|
-
* @public
|
|
716
|
-
*/
|
|
717
|
-
activateFaceCulling() {
|
|
718
|
-
this.gl.enable(this.gl.CULL_FACE);
|
|
719
|
-
}
|
|
720
|
-
|
|
721
|
-
/**
|
|
722
|
-
* Deactivate face cullting.
|
|
723
|
-
* @public
|
|
724
|
-
*/
|
|
725
|
-
deactivateFaceCulling() {
|
|
726
|
-
this.gl.disable(this.gl.CULL_FACE);
|
|
727
|
-
}
|
|
728
|
-
|
|
729
|
-
/**
|
|
730
|
-
* Activate blending.
|
|
731
|
-
* @public
|
|
732
|
-
*/
|
|
733
|
-
activateBlending() {
|
|
734
|
-
this.gl.enable(this.gl.BLEND);
|
|
735
|
-
}
|
|
736
|
-
|
|
737
|
-
/**
|
|
738
|
-
* Deactivate blending.
|
|
739
|
-
* @public
|
|
740
|
-
*/
|
|
741
|
-
deactivateBlending() {
|
|
742
|
-
this.gl.disable(this.gl.BLEND);
|
|
743
|
-
}
|
|
744
|
-
|
|
745
703
|
/**
|
|
746
704
|
* Creates STREAM_DRAW ARRAY buffer.
|
|
747
705
|
* @public
|
|
@@ -960,6 +918,14 @@ class Handler {
|
|
|
960
918
|
}
|
|
961
919
|
}
|
|
962
920
|
|
|
921
|
+
/**
|
|
922
|
+
* Check is gl context type equals webgl2
|
|
923
|
+
* @public
|
|
924
|
+
*/
|
|
925
|
+
isWebGl2() {
|
|
926
|
+
return this.gl.type === "webgl2"
|
|
927
|
+
}
|
|
928
|
+
|
|
963
929
|
/**
|
|
964
930
|
* Make animation.
|
|
965
931
|
* @private
|
|
@@ -980,10 +946,12 @@ class Handler {
|
|
|
980
946
|
createDefaultTexture(params, success) {
|
|
981
947
|
let imgCnv;
|
|
982
948
|
let texture;
|
|
949
|
+
const is2 = this.isWebGl2();
|
|
950
|
+
|
|
983
951
|
if (params && params.color) {
|
|
984
952
|
imgCnv = new ImageCanvas(2, 2);
|
|
985
953
|
imgCnv.fillColor(params.color);
|
|
986
|
-
texture = this.
|
|
954
|
+
texture = this.createTexture_n(imgCnv._canvas);
|
|
987
955
|
texture.default = true;
|
|
988
956
|
success(texture);
|
|
989
957
|
} else if (params && params.url) {
|
|
@@ -998,7 +966,7 @@ class Handler {
|
|
|
998
966
|
} else {
|
|
999
967
|
imgCnv = new ImageCanvas(2, 2);
|
|
1000
968
|
imgCnv.fillColor("#C5C5C5");
|
|
1001
|
-
texture = this.
|
|
969
|
+
texture = this.createTexture_n(imgCnv._canvas);
|
|
1002
970
|
texture.default = true;
|
|
1003
971
|
success(texture);
|
|
1004
972
|
}
|
|
@@ -1,260 +1,260 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @module og/webgl/Multisample
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
"use strict";
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Class represents multisample framebuffer.
|
|
9
|
-
* @class
|
|
10
|
-
* @param {Handler} handler - WebGL handler.
|
|
11
|
-
* @param {Object} [options] - Framebuffer options:
|
|
12
|
-
* @param {number} [options.width] - Framebuffer width. Default is handler canvas width.
|
|
13
|
-
* @param {number} [options.height] - Framebuffer height. Default is handler canvas height.
|
|
14
|
-
* @param {Object} [options.texture] - Texture to render.
|
|
15
|
-
* @param {String} [options.depthComponent="DEPTH_COMPONENT16"] - Specifies depth buffer size.
|
|
16
|
-
* @param {Boolean} [options.useDepth] - Using depth buffer during the rendering.
|
|
17
|
-
*/
|
|
18
|
-
export class Multisample {
|
|
19
|
-
constructor(handler, options) {
|
|
20
|
-
options = options || {};
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* WebGL handler.
|
|
24
|
-
* @public
|
|
25
|
-
* @type {Handler}
|
|
26
|
-
*/
|
|
27
|
-
this.handler = handler;
|
|
28
|
-
|
|
29
|
-
this._internalFormat = options.internalFormat
|
|
30
|
-
? options.internalFormat.toUpperCase()
|
|
31
|
-
: "RGBA8";
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* Framebuffer object.
|
|
35
|
-
* @private
|
|
36
|
-
* @type {Object}
|
|
37
|
-
*/
|
|
38
|
-
this._fbo = null;
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* Renderbuffer object.
|
|
42
|
-
* @private
|
|
43
|
-
* @type {Object}
|
|
44
|
-
*/
|
|
45
|
-
this._depthRenderbuffer = null;
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* Framebuffer width.
|
|
49
|
-
* @private
|
|
50
|
-
* @type {number}
|
|
51
|
-
*/
|
|
52
|
-
this._width = options.width || handler.canvas.width;
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
* Framebuffer width.
|
|
56
|
-
* @private
|
|
57
|
-
* @type {number}
|
|
58
|
-
*/
|
|
59
|
-
this._height = options.height || handler.canvas.height;
|
|
60
|
-
|
|
61
|
-
this._msaa = options.msaa != undefined ? options.msaa : 4;
|
|
62
|
-
|
|
63
|
-
this._useDepth = options.useDepth != undefined ? options.useDepth : true;
|
|
64
|
-
|
|
65
|
-
this._depthComponent =
|
|
66
|
-
options.depthComponent != undefined ? options.depthComponent : "DEPTH_COMPONENT16";
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* Framebuffer activity.
|
|
70
|
-
* @private
|
|
71
|
-
* @type {boolean}
|
|
72
|
-
*/
|
|
73
|
-
this._active = false;
|
|
74
|
-
|
|
75
|
-
this._size = options.size || 1;
|
|
76
|
-
|
|
77
|
-
this._filter = options.filter || "NEAREST";
|
|
78
|
-
|
|
79
|
-
this._glFilter = null;
|
|
80
|
-
|
|
81
|
-
this.renderbuffers = new Array(this._size);
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
destroy() {
|
|
85
|
-
var gl = this.handler.gl;
|
|
86
|
-
|
|
87
|
-
for (var i = 0; i < this.renderbuffers.length; i++) {
|
|
88
|
-
gl.deleteRenderbuffer(this.renderbuffers[i]);
|
|
89
|
-
}
|
|
90
|
-
this.renderbuffers = new Array(this._size);
|
|
91
|
-
|
|
92
|
-
gl.deleteFramebuffer(this._fbo);
|
|
93
|
-
gl.deleteRenderbuffer(this._depthRenderbuffer);
|
|
94
|
-
|
|
95
|
-
this._depthRenderbuffer = null;
|
|
96
|
-
this._fbo = null;
|
|
97
|
-
|
|
98
|
-
this._active = false;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
/**
|
|
102
|
-
* Framebuffer initialization.
|
|
103
|
-
* @private
|
|
104
|
-
*/
|
|
105
|
-
init() {
|
|
106
|
-
var gl = this.handler.gl;
|
|
107
|
-
|
|
108
|
-
this._glFilter = gl[this._filter];
|
|
109
|
-
|
|
110
|
-
this._fbo = gl.createFramebuffer();
|
|
111
|
-
|
|
112
|
-
gl.bindFramebuffer(gl.FRAMEBUFFER, this._fbo);
|
|
113
|
-
|
|
114
|
-
let colorAttachments = [];
|
|
115
|
-
for (var i = 0; i < this.renderbuffers.length; i++) {
|
|
116
|
-
let rb = gl.createRenderbuffer();
|
|
117
|
-
gl.bindRenderbuffer(gl.RENDERBUFFER, rb);
|
|
118
|
-
gl.renderbufferStorageMultisample(
|
|
119
|
-
gl.RENDERBUFFER,
|
|
120
|
-
this._msaa,
|
|
121
|
-
gl[this._internalFormat],
|
|
122
|
-
this._width,
|
|
123
|
-
this._height
|
|
124
|
-
);
|
|
125
|
-
gl.framebufferRenderbuffer(
|
|
126
|
-
gl.FRAMEBUFFER,
|
|
127
|
-
gl.COLOR_ATTACHMENT0 + i,
|
|
128
|
-
gl.RENDERBUFFER,
|
|
129
|
-
rb
|
|
130
|
-
);
|
|
131
|
-
colorAttachments.push(gl.COLOR_ATTACHMENT0 + i);
|
|
132
|
-
this.renderbuffers[i] = rb;
|
|
133
|
-
gl.bindRenderbuffer(gl.RENDERBUFFER, null);
|
|
134
|
-
}
|
|
135
|
-
gl.drawBuffers(colorAttachments);
|
|
136
|
-
|
|
137
|
-
if (this._useDepth) {
|
|
138
|
-
this._depthRenderbuffer = gl.createRenderbuffer();
|
|
139
|
-
gl.bindRenderbuffer(gl.RENDERBUFFER, this._depthRenderbuffer);
|
|
140
|
-
gl.renderbufferStorageMultisample(
|
|
141
|
-
gl.RENDERBUFFER,
|
|
142
|
-
this._msaa,
|
|
143
|
-
gl[this._depthComponent],
|
|
144
|
-
this._width,
|
|
145
|
-
this._height
|
|
146
|
-
);
|
|
147
|
-
gl.framebufferRenderbuffer(
|
|
148
|
-
gl.FRAMEBUFFER,
|
|
149
|
-
gl.DEPTH_ATTACHMENT,
|
|
150
|
-
gl.RENDERBUFFER,
|
|
151
|
-
this._depthRenderbuffer
|
|
152
|
-
);
|
|
153
|
-
gl.bindRenderbuffer(gl.RENDERBUFFER, null);
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
gl.bindFramebuffer(gl.FRAMEBUFFER, null);
|
|
157
|
-
|
|
158
|
-
return this;
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
blitTo(framebuffer, attachmentIndex = 0) {
|
|
162
|
-
let gl = this.handler.gl;
|
|
163
|
-
|
|
164
|
-
gl.bindFramebuffer(gl.READ_FRAMEBUFFER, this._fbo);
|
|
165
|
-
gl.bindFramebuffer(gl.DRAW_FRAMEBUFFER, framebuffer._fbo);
|
|
166
|
-
gl.readBuffer(gl.COLOR_ATTACHMENT0 + attachmentIndex);
|
|
167
|
-
|
|
168
|
-
gl.clearBufferfv(gl.COLOR, 0, [0.0, 0.0, 0.0, 1.0]);
|
|
169
|
-
|
|
170
|
-
gl.blitFramebuffer(
|
|
171
|
-
0,
|
|
172
|
-
0,
|
|
173
|
-
this._width,
|
|
174
|
-
this._height,
|
|
175
|
-
0,
|
|
176
|
-
0,
|
|
177
|
-
framebuffer._width,
|
|
178
|
-
framebuffer._height,
|
|
179
|
-
gl.COLOR_BUFFER_BIT,
|
|
180
|
-
this._glFilter
|
|
181
|
-
);
|
|
182
|
-
|
|
183
|
-
gl.bindFramebuffer(gl.FRAMEBUFFER, null);
|
|
184
|
-
gl.bindFramebuffer(gl.READ_FRAMEBUFFER, null);
|
|
185
|
-
gl.bindFramebuffer(gl.DRAW_FRAMEBUFFER, null);
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
/**
|
|
189
|
-
* Sets framebuffer viewport size.
|
|
190
|
-
* @public
|
|
191
|
-
* @param {number} width - Framebuffer width.
|
|
192
|
-
* @param {number} height - Framebuffer height.
|
|
193
|
-
*/
|
|
194
|
-
setSize(width, height, forceDestroy) {
|
|
195
|
-
this._width = width;
|
|
196
|
-
this._height = height;
|
|
197
|
-
|
|
198
|
-
if (this._active) {
|
|
199
|
-
this.handler.gl.viewport(0, 0, this._width, this._height);
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
if (this._useDepth || forceDestroy) {
|
|
203
|
-
this.destroy();
|
|
204
|
-
this.init();
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
/**
|
|
209
|
-
* Returns framebuffer completed.
|
|
210
|
-
* @public
|
|
211
|
-
* @returns {boolean} -
|
|
212
|
-
*/
|
|
213
|
-
isComplete() {
|
|
214
|
-
var gl = this.handler.gl;
|
|
215
|
-
if (gl.checkFramebufferStatus(gl.FRAMEBUFFER) === gl.FRAMEBUFFER_COMPLETE) {
|
|
216
|
-
return true;
|
|
217
|
-
}
|
|
218
|
-
return false;
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
/**
|
|
222
|
-
* Activate framebuffer frame to draw.
|
|
223
|
-
* @public
|
|
224
|
-
* @returns {Framebuffer} Returns Current framebuffer.
|
|
225
|
-
*/
|
|
226
|
-
activate() {
|
|
227
|
-
var gl = this.handler.gl;
|
|
228
|
-
gl.bindFramebuffer(gl.FRAMEBUFFER, null);
|
|
229
|
-
gl.bindFramebuffer(gl.FRAMEBUFFER, this._fbo);
|
|
230
|
-
gl.viewport(0, 0, this._width, this._height);
|
|
231
|
-
this._active = true;
|
|
232
|
-
var c = this.handler.framebufferStack.current().data;
|
|
233
|
-
c && (c._active = false);
|
|
234
|
-
this.handler.framebufferStack.push(this);
|
|
235
|
-
return this;
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
/**
|
|
239
|
-
* Deactivate framebuffer frame.
|
|
240
|
-
* @public
|
|
241
|
-
*/
|
|
242
|
-
deactivate() {
|
|
243
|
-
var h = this.handler,
|
|
244
|
-
gl = h.gl;
|
|
245
|
-
|
|
246
|
-
//Q: check for this._useDepth ?
|
|
247
|
-
|
|
248
|
-
gl.bindFramebuffer(gl.FRAMEBUFFER, null);
|
|
249
|
-
this._active = false;
|
|
250
|
-
|
|
251
|
-
var f = this.handler.framebufferStack.popPrev();
|
|
252
|
-
|
|
253
|
-
if (f) {
|
|
254
|
-
gl.bindFramebuffer(gl.FRAMEBUFFER, f._fbo);
|
|
255
|
-
gl.viewport(0, 0, f._width, f._height);
|
|
256
|
-
} else {
|
|
257
|
-
gl.viewport(0, 0, h.canvas.width, h.canvas.height);
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* @module og/webgl/Multisample
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
"use strict";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Class represents multisample framebuffer.
|
|
9
|
+
* @class
|
|
10
|
+
* @param {Handler} handler - WebGL handler.
|
|
11
|
+
* @param {Object} [options] - Framebuffer options:
|
|
12
|
+
* @param {number} [options.width] - Framebuffer width. Default is handler canvas width.
|
|
13
|
+
* @param {number} [options.height] - Framebuffer height. Default is handler canvas height.
|
|
14
|
+
* @param {Object} [options.texture] - Texture to render.
|
|
15
|
+
* @param {String} [options.depthComponent="DEPTH_COMPONENT16"] - Specifies depth buffer size.
|
|
16
|
+
* @param {Boolean} [options.useDepth] - Using depth buffer during the rendering.
|
|
17
|
+
*/
|
|
18
|
+
export class Multisample {
|
|
19
|
+
constructor(handler, options) {
|
|
20
|
+
options = options || {};
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* WebGL handler.
|
|
24
|
+
* @public
|
|
25
|
+
* @type {Handler}
|
|
26
|
+
*/
|
|
27
|
+
this.handler = handler;
|
|
28
|
+
|
|
29
|
+
this._internalFormat = options.internalFormat
|
|
30
|
+
? options.internalFormat.toUpperCase()
|
|
31
|
+
: "RGBA8";
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Framebuffer object.
|
|
35
|
+
* @private
|
|
36
|
+
* @type {Object}
|
|
37
|
+
*/
|
|
38
|
+
this._fbo = null;
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Renderbuffer object.
|
|
42
|
+
* @private
|
|
43
|
+
* @type {Object}
|
|
44
|
+
*/
|
|
45
|
+
this._depthRenderbuffer = null;
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Framebuffer width.
|
|
49
|
+
* @private
|
|
50
|
+
* @type {number}
|
|
51
|
+
*/
|
|
52
|
+
this._width = options.width || handler.canvas.width;
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Framebuffer width.
|
|
56
|
+
* @private
|
|
57
|
+
* @type {number}
|
|
58
|
+
*/
|
|
59
|
+
this._height = options.height || handler.canvas.height;
|
|
60
|
+
|
|
61
|
+
this._msaa = options.msaa != undefined ? options.msaa : 4;
|
|
62
|
+
|
|
63
|
+
this._useDepth = options.useDepth != undefined ? options.useDepth : true;
|
|
64
|
+
|
|
65
|
+
this._depthComponent =
|
|
66
|
+
options.depthComponent != undefined ? options.depthComponent : "DEPTH_COMPONENT16";
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Framebuffer activity.
|
|
70
|
+
* @private
|
|
71
|
+
* @type {boolean}
|
|
72
|
+
*/
|
|
73
|
+
this._active = false;
|
|
74
|
+
|
|
75
|
+
this._size = options.size || 1;
|
|
76
|
+
|
|
77
|
+
this._filter = options.filter || "NEAREST";
|
|
78
|
+
|
|
79
|
+
this._glFilter = null;
|
|
80
|
+
|
|
81
|
+
this.renderbuffers = new Array(this._size);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
destroy() {
|
|
85
|
+
var gl = this.handler.gl;
|
|
86
|
+
|
|
87
|
+
for (var i = 0; i < this.renderbuffers.length; i++) {
|
|
88
|
+
gl.deleteRenderbuffer(this.renderbuffers[i]);
|
|
89
|
+
}
|
|
90
|
+
this.renderbuffers = new Array(this._size);
|
|
91
|
+
|
|
92
|
+
gl.deleteFramebuffer(this._fbo);
|
|
93
|
+
gl.deleteRenderbuffer(this._depthRenderbuffer);
|
|
94
|
+
|
|
95
|
+
this._depthRenderbuffer = null;
|
|
96
|
+
this._fbo = null;
|
|
97
|
+
|
|
98
|
+
this._active = false;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Framebuffer initialization.
|
|
103
|
+
* @private
|
|
104
|
+
*/
|
|
105
|
+
init() {
|
|
106
|
+
var gl = this.handler.gl;
|
|
107
|
+
|
|
108
|
+
this._glFilter = gl[this._filter];
|
|
109
|
+
|
|
110
|
+
this._fbo = gl.createFramebuffer();
|
|
111
|
+
|
|
112
|
+
gl.bindFramebuffer(gl.FRAMEBUFFER, this._fbo);
|
|
113
|
+
|
|
114
|
+
let colorAttachments = [];
|
|
115
|
+
for (var i = 0; i < this.renderbuffers.length; i++) {
|
|
116
|
+
let rb = gl.createRenderbuffer();
|
|
117
|
+
gl.bindRenderbuffer(gl.RENDERBUFFER, rb);
|
|
118
|
+
gl.renderbufferStorageMultisample(
|
|
119
|
+
gl.RENDERBUFFER,
|
|
120
|
+
this._msaa,
|
|
121
|
+
gl[this._internalFormat],
|
|
122
|
+
this._width,
|
|
123
|
+
this._height
|
|
124
|
+
);
|
|
125
|
+
gl.framebufferRenderbuffer(
|
|
126
|
+
gl.FRAMEBUFFER,
|
|
127
|
+
gl.COLOR_ATTACHMENT0 + i,
|
|
128
|
+
gl.RENDERBUFFER,
|
|
129
|
+
rb
|
|
130
|
+
);
|
|
131
|
+
colorAttachments.push(gl.COLOR_ATTACHMENT0 + i);
|
|
132
|
+
this.renderbuffers[i] = rb;
|
|
133
|
+
gl.bindRenderbuffer(gl.RENDERBUFFER, null);
|
|
134
|
+
}
|
|
135
|
+
gl.drawBuffers(colorAttachments);
|
|
136
|
+
|
|
137
|
+
if (this._useDepth) {
|
|
138
|
+
this._depthRenderbuffer = gl.createRenderbuffer();
|
|
139
|
+
gl.bindRenderbuffer(gl.RENDERBUFFER, this._depthRenderbuffer);
|
|
140
|
+
gl.renderbufferStorageMultisample(
|
|
141
|
+
gl.RENDERBUFFER,
|
|
142
|
+
this._msaa,
|
|
143
|
+
gl[this._depthComponent],
|
|
144
|
+
this._width,
|
|
145
|
+
this._height
|
|
146
|
+
);
|
|
147
|
+
gl.framebufferRenderbuffer(
|
|
148
|
+
gl.FRAMEBUFFER,
|
|
149
|
+
gl.DEPTH_ATTACHMENT,
|
|
150
|
+
gl.RENDERBUFFER,
|
|
151
|
+
this._depthRenderbuffer
|
|
152
|
+
);
|
|
153
|
+
gl.bindRenderbuffer(gl.RENDERBUFFER, null);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
gl.bindFramebuffer(gl.FRAMEBUFFER, null);
|
|
157
|
+
|
|
158
|
+
return this;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
blitTo(framebuffer, attachmentIndex = 0) {
|
|
162
|
+
let gl = this.handler.gl;
|
|
163
|
+
|
|
164
|
+
gl.bindFramebuffer(gl.READ_FRAMEBUFFER, this._fbo);
|
|
165
|
+
gl.bindFramebuffer(gl.DRAW_FRAMEBUFFER, framebuffer._fbo);
|
|
166
|
+
gl.readBuffer(gl.COLOR_ATTACHMENT0 + attachmentIndex);
|
|
167
|
+
|
|
168
|
+
gl.clearBufferfv(gl.COLOR, 0, [0.0, 0.0, 0.0, 1.0]);
|
|
169
|
+
|
|
170
|
+
gl.blitFramebuffer(
|
|
171
|
+
0,
|
|
172
|
+
0,
|
|
173
|
+
this._width,
|
|
174
|
+
this._height,
|
|
175
|
+
0,
|
|
176
|
+
0,
|
|
177
|
+
framebuffer._width,
|
|
178
|
+
framebuffer._height,
|
|
179
|
+
gl.COLOR_BUFFER_BIT,
|
|
180
|
+
this._glFilter
|
|
181
|
+
);
|
|
182
|
+
|
|
183
|
+
gl.bindFramebuffer(gl.FRAMEBUFFER, null);
|
|
184
|
+
gl.bindFramebuffer(gl.READ_FRAMEBUFFER, null);
|
|
185
|
+
gl.bindFramebuffer(gl.DRAW_FRAMEBUFFER, null);
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* Sets framebuffer viewport size.
|
|
190
|
+
* @public
|
|
191
|
+
* @param {number} width - Framebuffer width.
|
|
192
|
+
* @param {number} height - Framebuffer height.
|
|
193
|
+
*/
|
|
194
|
+
setSize(width, height, forceDestroy) {
|
|
195
|
+
this._width = width;
|
|
196
|
+
this._height = height;
|
|
197
|
+
|
|
198
|
+
if (this._active) {
|
|
199
|
+
this.handler.gl.viewport(0, 0, this._width, this._height);
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
if (this._useDepth || forceDestroy) {
|
|
203
|
+
this.destroy();
|
|
204
|
+
this.init();
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
/**
|
|
209
|
+
* Returns framebuffer completed.
|
|
210
|
+
* @public
|
|
211
|
+
* @returns {boolean} -
|
|
212
|
+
*/
|
|
213
|
+
isComplete() {
|
|
214
|
+
var gl = this.handler.gl;
|
|
215
|
+
if (gl.checkFramebufferStatus(gl.FRAMEBUFFER) === gl.FRAMEBUFFER_COMPLETE) {
|
|
216
|
+
return true;
|
|
217
|
+
}
|
|
218
|
+
return false;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
/**
|
|
222
|
+
* Activate framebuffer frame to draw.
|
|
223
|
+
* @public
|
|
224
|
+
* @returns {Framebuffer} Returns Current framebuffer.
|
|
225
|
+
*/
|
|
226
|
+
activate() {
|
|
227
|
+
var gl = this.handler.gl;
|
|
228
|
+
gl.bindFramebuffer(gl.FRAMEBUFFER, null);
|
|
229
|
+
gl.bindFramebuffer(gl.FRAMEBUFFER, this._fbo);
|
|
230
|
+
gl.viewport(0, 0, this._width, this._height);
|
|
231
|
+
this._active = true;
|
|
232
|
+
var c = this.handler.framebufferStack.current().data;
|
|
233
|
+
c && (c._active = false);
|
|
234
|
+
this.handler.framebufferStack.push(this);
|
|
235
|
+
return this;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
/**
|
|
239
|
+
* Deactivate framebuffer frame.
|
|
240
|
+
* @public
|
|
241
|
+
*/
|
|
242
|
+
deactivate() {
|
|
243
|
+
var h = this.handler,
|
|
244
|
+
gl = h.gl;
|
|
245
|
+
|
|
246
|
+
//Q: check for this._useDepth ?
|
|
247
|
+
|
|
248
|
+
gl.bindFramebuffer(gl.FRAMEBUFFER, null);
|
|
249
|
+
this._active = false;
|
|
250
|
+
|
|
251
|
+
var f = this.handler.framebufferStack.popPrev();
|
|
252
|
+
|
|
253
|
+
if (f) {
|
|
254
|
+
gl.bindFramebuffer(gl.FRAMEBUFFER, f._fbo);
|
|
255
|
+
gl.viewport(0, 0, f._width, f._height);
|
|
256
|
+
} else {
|
|
257
|
+
gl.viewport(0, 0, h.canvas.width, h.canvas.height);
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
}
|