@galacean/engine-rhi-webgl 0.9.21 → 0.9.22
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/dist/main.js +84 -34
- package/dist/main.js.map +1 -1
- package/dist/miniprogram.js +84 -34
- package/dist/module.js +57 -4
- package/dist/module.js.map +1 -1
- package/package.json +4 -4
- package/types/GLBuffer.d.ts +1 -0
- package/types/WebGLGraphicDevice.d.ts +1 -2
package/dist/main.js
CHANGED
|
@@ -2,20 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var _create_class = require('@swc/helpers/src/_create_class.mjs');
|
|
6
|
-
var _instanceof = require('@swc/helpers/src/_instanceof.mjs');
|
|
7
5
|
var engineMath = require('@galacean/engine-math');
|
|
8
|
-
var _inherits = require('@swc/helpers/src/_inherits.mjs');
|
|
9
6
|
var engineCore = require('@galacean/engine-core');
|
|
10
|
-
var _extends = require('@swc/helpers/src/_extends.mjs');
|
|
11
|
-
|
|
12
|
-
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
13
|
-
|
|
14
|
-
var _create_class__default = /*#__PURE__*/_interopDefaultLegacy(_create_class);
|
|
15
|
-
var _instanceof__default = /*#__PURE__*/_interopDefaultLegacy(_instanceof);
|
|
16
|
-
var _inherits__default = /*#__PURE__*/_interopDefaultLegacy(_inherits);
|
|
17
|
-
var _extends__default = /*#__PURE__*/_interopDefaultLegacy(_extends);
|
|
18
7
|
|
|
8
|
+
/**
|
|
9
|
+
* Smoothing plug-in.
|
|
10
|
+
* */ exports.GLCompressedTextureInternalFormat = void 0;
|
|
19
11
|
(function(GLCompressedTextureInternalFormat) {
|
|
20
12
|
GLCompressedTextureInternalFormat[GLCompressedTextureInternalFormat[// astc
|
|
21
13
|
"RGBA_ASTC_4X4_KHR"] = 0x93b0] = "RGBA_ASTC_4X4_KHR";
|
|
@@ -71,6 +63,30 @@ var _extends__default = /*#__PURE__*/_interopDefaultLegacy(_extends);
|
|
|
71
63
|
GLCompressedTextureInternalFormat[GLCompressedTextureInternalFormat["RGBA_S3TC_DXT5_EXT"] = 0x83f3] = "RGBA_S3TC_DXT5_EXT";
|
|
72
64
|
})(exports.GLCompressedTextureInternalFormat || (exports.GLCompressedTextureInternalFormat = {}));
|
|
73
65
|
|
|
66
|
+
function _defineProperties(target, props) {
|
|
67
|
+
for (var i = 0; i < props.length; i++) {
|
|
68
|
+
var descriptor = props[i];
|
|
69
|
+
descriptor.enumerable = descriptor.enumerable || false;
|
|
70
|
+
descriptor.configurable = true;
|
|
71
|
+
|
|
72
|
+
if ("value" in descriptor) descriptor.writable = true;
|
|
73
|
+
|
|
74
|
+
Object.defineProperty(target, descriptor.key, descriptor);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
function _create_class(Constructor, protoProps, staticProps) {
|
|
78
|
+
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
|
|
79
|
+
if (staticProps) _defineProperties(Constructor, staticProps);
|
|
80
|
+
|
|
81
|
+
return Constructor;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function _instanceof(left, right) {
|
|
85
|
+
if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
|
|
86
|
+
return !!right[Symbol.hasInstance](left);
|
|
87
|
+
} else return left instanceof right;
|
|
88
|
+
}
|
|
89
|
+
|
|
74
90
|
/**
|
|
75
91
|
* The canvas used on the web, which can support HTMLCanvasElement and OffscreenCanvas.
|
|
76
92
|
*/ var WebCanvas = /*#__PURE__*/ function() {
|
|
@@ -89,7 +105,7 @@ var _extends__default = /*#__PURE__*/_interopDefaultLegacy(_extends);
|
|
|
89
105
|
*/ _proto.resizeByClientSize = function resizeByClientSize(pixelRatio) {
|
|
90
106
|
if (pixelRatio === void 0) pixelRatio = window.devicePixelRatio;
|
|
91
107
|
var webCanvas = this._webCanvas;
|
|
92
|
-
if (typeof OffscreenCanvas === "undefined" || !
|
|
108
|
+
if (typeof OffscreenCanvas === "undefined" || !_instanceof(webCanvas, OffscreenCanvas)) {
|
|
93
109
|
this.width = webCanvas.clientWidth * pixelRatio;
|
|
94
110
|
this.height = webCanvas.clientHeight * pixelRatio;
|
|
95
111
|
}
|
|
@@ -102,7 +118,7 @@ var _extends__default = /*#__PURE__*/_interopDefaultLegacy(_extends);
|
|
|
102
118
|
this._scale.set(x, y);
|
|
103
119
|
this.scale = this._scale;
|
|
104
120
|
};
|
|
105
|
-
|
|
121
|
+
_create_class(WebCanvas, [
|
|
106
122
|
{
|
|
107
123
|
key: "width",
|
|
108
124
|
get: /**
|
|
@@ -138,14 +154,14 @@ var _extends__default = /*#__PURE__*/_interopDefaultLegacy(_extends);
|
|
|
138
154
|
* @remarks Need to re-assign after modification to ensure that the modification takes effect.
|
|
139
155
|
*/ function get() {
|
|
140
156
|
var webCanvas = this._webCanvas;
|
|
141
|
-
if (typeof OffscreenCanvas === "undefined" || !
|
|
157
|
+
if (typeof OffscreenCanvas === "undefined" || !_instanceof(webCanvas, OffscreenCanvas)) {
|
|
142
158
|
this._scale.set(webCanvas.clientWidth * devicePixelRatio / webCanvas.width, webCanvas.clientHeight * devicePixelRatio / webCanvas.height);
|
|
143
159
|
}
|
|
144
160
|
return this._scale;
|
|
145
161
|
},
|
|
146
162
|
set: function set(value) {
|
|
147
163
|
var webCanvas = this._webCanvas;
|
|
148
|
-
if (typeof OffscreenCanvas === "undefined" || !
|
|
164
|
+
if (typeof OffscreenCanvas === "undefined" || !_instanceof(webCanvas, OffscreenCanvas)) {
|
|
149
165
|
webCanvas.style.transformOrigin = "left top";
|
|
150
166
|
webCanvas.style.transform = "scale(" + value.x + ", " + value.y + ")";
|
|
151
167
|
}
|
|
@@ -155,6 +171,39 @@ var _extends__default = /*#__PURE__*/_interopDefaultLegacy(_extends);
|
|
|
155
171
|
return WebCanvas;
|
|
156
172
|
}();
|
|
157
173
|
|
|
174
|
+
function _set_prototype_of(o, p) {
|
|
175
|
+
_set_prototype_of = Object.setPrototypeOf || function setPrototypeOf(o, p) {
|
|
176
|
+
o.__proto__ = p;
|
|
177
|
+
|
|
178
|
+
return o;
|
|
179
|
+
};
|
|
180
|
+
|
|
181
|
+
return _set_prototype_of(o, p);
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
function _inherits(subClass, superClass) {
|
|
185
|
+
if (typeof superClass !== "function" && superClass !== null) {
|
|
186
|
+
throw new TypeError("Super expression must either be null or a function");
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } });
|
|
190
|
+
|
|
191
|
+
if (superClass) _set_prototype_of(subClass, superClass);
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
function _extends() {
|
|
195
|
+
_extends = Object.assign || function assign(target) {
|
|
196
|
+
for (var i = 1; i < arguments.length; i++) {
|
|
197
|
+
var source = arguments[i];
|
|
198
|
+
for (var key in source) if (Object.prototype.hasOwnProperty.call(source, key)) target[key] = source[key];
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
return target;
|
|
202
|
+
};
|
|
203
|
+
|
|
204
|
+
return _extends.apply(this, arguments);
|
|
205
|
+
}
|
|
206
|
+
|
|
158
207
|
/**
|
|
159
208
|
* GL capability.
|
|
160
209
|
*/ var GLCapability = /*#__PURE__*/ function() {
|
|
@@ -273,7 +322,7 @@ var _extends__default = /*#__PURE__*/_interopDefaultLegacy(_extends);
|
|
|
273
322
|
i != 0 && (items["COLOR_ATTACHMENT" + i] = "COLOR_ATTACHMENT" + i + "_WEBGL");
|
|
274
323
|
items["DRAW_BUFFER" + i] = "DRAW_BUFFER" + i + "_WEBGL";
|
|
275
324
|
}
|
|
276
|
-
this._compatibleInterface(drawBuffers,
|
|
325
|
+
this._compatibleInterface(drawBuffers, _extends({
|
|
277
326
|
drawBuffers: "drawBuffersWEBGL"
|
|
278
327
|
}, items));
|
|
279
328
|
}
|
|
@@ -291,7 +340,7 @@ var _extends__default = /*#__PURE__*/_interopDefaultLegacy(_extends);
|
|
|
291
340
|
TEXTURE_MAX_ANISOTROPY_EXT: "TEXTURE_MAX_ANISOTROPY_EXT"
|
|
292
341
|
});
|
|
293
342
|
};
|
|
294
|
-
|
|
343
|
+
_create_class(GLCapability, [
|
|
295
344
|
{
|
|
296
345
|
key: "maxTextureSize",
|
|
297
346
|
get: function get() {
|
|
@@ -1045,7 +1094,7 @@ var _extends__default = /*#__PURE__*/_interopDefaultLegacy(_extends);
|
|
|
1045
1094
|
}
|
|
1046
1095
|
return true;
|
|
1047
1096
|
};
|
|
1048
|
-
|
|
1097
|
+
_create_class(GLTexture, [
|
|
1049
1098
|
{
|
|
1050
1099
|
key: "wrapModeU",
|
|
1051
1100
|
set: /**
|
|
@@ -1146,7 +1195,7 @@ var _extends__default = /*#__PURE__*/_interopDefaultLegacy(_extends);
|
|
|
1146
1195
|
this._isWebGL2 = rhi.isWebGL2;
|
|
1147
1196
|
this._target = target;
|
|
1148
1197
|
/** @ts-ignore */ var _colorTextures = target._colorTextures, _depth = target._depth, width = target.width, height = target.height;
|
|
1149
|
-
var isDepthTexture =
|
|
1198
|
+
var isDepthTexture = _instanceof(_depth, engineCore.Texture);
|
|
1150
1199
|
/** todo
|
|
1151
1200
|
* MRT + Cube + [,MSAA]
|
|
1152
1201
|
* MRT + MSAA
|
|
@@ -1172,7 +1221,7 @@ var _extends__default = /*#__PURE__*/_interopDefaultLegacy(_extends);
|
|
|
1172
1221
|
}
|
|
1173
1222
|
// todo: necessary to support MRT + Cube + [,MSAA] ?
|
|
1174
1223
|
if (_colorTextures.length > 1 && _colorTextures.some(function(v) {
|
|
1175
|
-
return
|
|
1224
|
+
return _instanceof(v, engineCore.TextureCube);
|
|
1176
1225
|
})) {
|
|
1177
1226
|
throw new Error("MRT+Cube+[,MSAA] is not supported");
|
|
1178
1227
|
}
|
|
@@ -1202,14 +1251,14 @@ var _extends__default = /*#__PURE__*/_interopDefaultLegacy(_extends);
|
|
|
1202
1251
|
var mipChanged = mipLevel !== this._curMipLevel;
|
|
1203
1252
|
gl.bindFramebuffer(gl.FRAMEBUFFER, this._frameBuffer);
|
|
1204
1253
|
if (colorTexture) {
|
|
1205
|
-
var isCube =
|
|
1254
|
+
var isCube = _instanceof(colorTexture, engineCore.TextureCube);
|
|
1206
1255
|
if (mipChanged || isCube) {
|
|
1207
1256
|
gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, isCube ? gl.TEXTURE_CUBE_MAP_POSITIVE_X + faceIndex : gl.TEXTURE_2D, // @ts-ignore
|
|
1208
1257
|
colorTexture._platformTexture._glTexture, mipLevel);
|
|
1209
1258
|
}
|
|
1210
1259
|
}
|
|
1211
1260
|
if (depthTexture) {
|
|
1212
|
-
var isCube1 =
|
|
1261
|
+
var isCube1 = _instanceof(depthTexture, engineCore.TextureCube);
|
|
1213
1262
|
if (mipChanged || isCube1) {
|
|
1214
1263
|
// @ts-ignore
|
|
1215
1264
|
var platformTexture = depthTexture._platformTexture;
|
|
@@ -1287,7 +1336,7 @@ var _extends__default = /*#__PURE__*/_interopDefaultLegacy(_extends);
|
|
|
1287
1336
|
var colorTexture = this._target.getColorTexture(i);
|
|
1288
1337
|
var attachment = gl.COLOR_ATTACHMENT0 + i;
|
|
1289
1338
|
drawBuffers[i] = attachment;
|
|
1290
|
-
if (!
|
|
1339
|
+
if (!_instanceof(colorTexture, engineCore.TextureCube)) {
|
|
1291
1340
|
gl.framebufferTexture2D(gl.FRAMEBUFFER, attachment, gl.TEXTURE_2D, /** @ts-ignore */ colorTexture._platformTexture._glTexture, 0);
|
|
1292
1341
|
}
|
|
1293
1342
|
}
|
|
@@ -1296,7 +1345,7 @@ var _extends__default = /*#__PURE__*/_interopDefaultLegacy(_extends);
|
|
|
1296
1345
|
}
|
|
1297
1346
|
this._oriDrawBuffers = drawBuffers;
|
|
1298
1347
|
/** depth render buffer */ if (_depth !== null) {
|
|
1299
|
-
if (
|
|
1348
|
+
if (_instanceof(_depth, engineCore.Texture) && !_instanceof(_depth, engineCore.TextureCube)) {
|
|
1300
1349
|
// @ts-ignore
|
|
1301
1350
|
var platformTexture = _depth._platformTexture;
|
|
1302
1351
|
gl.framebufferTexture2D(gl.FRAMEBUFFER, platformTexture._formatDetail.attachment, gl.TEXTURE_2D, platformTexture._glTexture, 0);
|
|
@@ -1332,7 +1381,7 @@ var _extends__default = /*#__PURE__*/_interopDefaultLegacy(_extends);
|
|
|
1332
1381
|
gl.drawBuffers(this._oriDrawBuffers);
|
|
1333
1382
|
// prepare MSAA depth RBO
|
|
1334
1383
|
if (_depth !== null) {
|
|
1335
|
-
var _ref =
|
|
1384
|
+
var _ref = _instanceof(_depth, engineCore.Texture) ? /** @ts-ignore */ _depth._platformTexture._formatDetail : GLTexture._getRenderBufferDepthFormatDetail(_depth, gl, isWebGL2), internalFormat = _ref.internalFormat, attachment = _ref.attachment;
|
|
1336
1385
|
gl.bindRenderbuffer(gl.RENDERBUFFER, MSAADepthRenderBuffer);
|
|
1337
1386
|
gl.renderbufferStorageMultisample(gl.RENDERBUFFER, antiAliasing, internalFormat, width, height);
|
|
1338
1387
|
gl.framebufferRenderbuffer(gl.FRAMEBUFFER, attachment, gl.RENDERBUFFER, MSAADepthRenderBuffer);
|
|
@@ -1365,7 +1414,7 @@ var _extends__default = /*#__PURE__*/_interopDefaultLegacy(_extends);
|
|
|
1365
1414
|
/**
|
|
1366
1415
|
* Texture 2d in WebGL platform.
|
|
1367
1416
|
*/ var GLTexture2D = /*#__PURE__*/ function(GLTexture1) {
|
|
1368
|
-
|
|
1417
|
+
_inherits(GLTexture2D, GLTexture1);
|
|
1369
1418
|
function GLTexture2D(rhi, texture2D) {
|
|
1370
1419
|
var _this;
|
|
1371
1420
|
_this = GLTexture1.call(this, rhi, texture2D, rhi.gl.TEXTURE_2D) || this;
|
|
@@ -1435,7 +1484,7 @@ var _extends__default = /*#__PURE__*/_interopDefaultLegacy(_extends);
|
|
|
1435
1484
|
/**
|
|
1436
1485
|
* Texture 2D array in WebGL platform.
|
|
1437
1486
|
*/ var GLTexture2DArray = /*#__PURE__*/ function(GLTexture1) {
|
|
1438
|
-
|
|
1487
|
+
_inherits(GLTexture2DArray, GLTexture1);
|
|
1439
1488
|
function GLTexture2DArray(rhi, texture2DArray) {
|
|
1440
1489
|
var _this;
|
|
1441
1490
|
_this = GLTexture1.call(this, rhi, texture2DArray, rhi.gl.TEXTURE_2D_ARRAY) || this;
|
|
@@ -1497,7 +1546,7 @@ var _extends__default = /*#__PURE__*/_interopDefaultLegacy(_extends);
|
|
|
1497
1546
|
/**
|
|
1498
1547
|
* Cube texture in WebGL platform.
|
|
1499
1548
|
*/ var GLTextureCube = /*#__PURE__*/ function(GLTexture1) {
|
|
1500
|
-
|
|
1549
|
+
_inherits(GLTextureCube, GLTexture1);
|
|
1501
1550
|
function GLTextureCube(rhi, textureCube) {
|
|
1502
1551
|
var _this;
|
|
1503
1552
|
_this = GLTexture1.call(this, rhi, textureCube, rhi.gl.TEXTURE_CUBE_MAP) || this;
|
|
@@ -1569,6 +1618,7 @@ var _extends__default = /*#__PURE__*/_interopDefaultLegacy(_extends);
|
|
|
1569
1618
|
return GLTextureCube;
|
|
1570
1619
|
}(GLTexture);
|
|
1571
1620
|
|
|
1621
|
+
exports.WebGLMode = void 0;
|
|
1572
1622
|
(function(WebGLMode) {
|
|
1573
1623
|
WebGLMode[WebGLMode[/** Auto, use WebGL2.0 if support, or will fallback to WebGL1.0. */ "Auto"] = 0] = "Auto";
|
|
1574
1624
|
WebGLMode[WebGLMode[/** WebGL2.0. */ "WebGL2"] = 1] = "WebGL2";
|
|
@@ -1586,7 +1636,7 @@ var _extends__default = /*#__PURE__*/_interopDefaultLegacy(_extends);
|
|
|
1586
1636
|
this._lastScissor = new engineMath.Vector4(null, null, null, null);
|
|
1587
1637
|
this._lastClearColor = new engineMath.Color(null, null, null, null);
|
|
1588
1638
|
this._scissorEnable = false;
|
|
1589
|
-
var options =
|
|
1639
|
+
var options = _extends({
|
|
1590
1640
|
webGLMode: 0,
|
|
1591
1641
|
alpha: false,
|
|
1592
1642
|
stencil: true,
|
|
@@ -1613,7 +1663,7 @@ var _extends__default = /*#__PURE__*/_interopDefaultLegacy(_extends);
|
|
|
1613
1663
|
var gl;
|
|
1614
1664
|
if (webGLMode == 0 || webGLMode == 1) {
|
|
1615
1665
|
gl = webCanvas.getContext("webgl2", options);
|
|
1616
|
-
if (!gl && (typeof OffscreenCanvas === "undefined" || !
|
|
1666
|
+
if (!gl && (typeof OffscreenCanvas === "undefined" || !_instanceof(webCanvas, OffscreenCanvas))) {
|
|
1617
1667
|
gl = webCanvas.getContext("experimental-webgl2", options);
|
|
1618
1668
|
}
|
|
1619
1669
|
this._isWebGL2 = true;
|
|
@@ -1625,7 +1675,7 @@ var _extends__default = /*#__PURE__*/_interopDefaultLegacy(_extends);
|
|
|
1625
1675
|
if (!gl) {
|
|
1626
1676
|
if (webGLMode == 0 || webGLMode == 2) {
|
|
1627
1677
|
gl = webCanvas.getContext("webgl", options);
|
|
1628
|
-
if (!gl && (typeof OffscreenCanvas === "undefined" || !
|
|
1678
|
+
if (!gl && (typeof OffscreenCanvas === "undefined" || !_instanceof(webCanvas, OffscreenCanvas))) {
|
|
1629
1679
|
gl = webCanvas.getContext("experimental-webgl", options);
|
|
1630
1680
|
}
|
|
1631
1681
|
this._isWebGL2 = false;
|
|
@@ -1789,7 +1839,7 @@ var _extends__default = /*#__PURE__*/_interopDefaultLegacy(_extends);
|
|
|
1789
1839
|
this._gl.flush();
|
|
1790
1840
|
};
|
|
1791
1841
|
_proto.destroy = function destroy() {};
|
|
1792
|
-
|
|
1842
|
+
_create_class(WebGLRenderer, [
|
|
1793
1843
|
{
|
|
1794
1844
|
key: "isWebGL2",
|
|
1795
1845
|
get: function get() {
|
|
@@ -1836,13 +1886,13 @@ var _extends__default = /*#__PURE__*/_interopDefaultLegacy(_extends);
|
|
|
1836
1886
|
/**
|
|
1837
1887
|
* WebGL platform engine,support includes WebGL1.0 and WebGL2.0.
|
|
1838
1888
|
*/ var WebGLEngine = /*#__PURE__*/ function(Engine) {
|
|
1839
|
-
|
|
1889
|
+
_inherits(WebGLEngine, Engine);
|
|
1840
1890
|
function WebGLEngine(canvas, webGLRendererOptions) {
|
|
1841
1891
|
var webCanvas = new WebCanvas(typeof canvas === "string" ? document.getElementById(canvas) : canvas);
|
|
1842
1892
|
var hardwareRenderer = new WebGLRenderer(webGLRendererOptions);
|
|
1843
1893
|
return Engine.call(this, webCanvas, hardwareRenderer);
|
|
1844
1894
|
}
|
|
1845
|
-
|
|
1895
|
+
_create_class(WebGLEngine, [
|
|
1846
1896
|
{
|
|
1847
1897
|
key: "canvas",
|
|
1848
1898
|
get: /**
|