@galacean/engine-rhi-webgl 1.0.0-beta.0 → 1.0.0
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 +50 -188
- package/dist/main.js.map +1 -1
- package/dist/miniprogram.js +50 -188
- package/dist/module.js +51 -189
- package/dist/module.js.map +1 -1
- package/package.json +4 -4
- package/types/GLCapability.d.ts +4 -4
- package/types/GLExtensions.d.ts +2 -2
- package/types/GLRenderTarget.d.ts +2 -2
- package/types/GLTexture.d.ts +2 -2
- package/types/GLTexture2D.d.ts +2 -2
- package/types/GLTexture2DArray.d.ts +2 -2
- package/types/GLTextureCube.d.ts +2 -2
- package/types/WebGLEngine.d.ts +8 -15
- package/types/{WebGLGraphicDevice.d.ts → WebGLRenderer.d.ts} +9 -18
- package/types/index.d.ts +2 -3
- package/types/GLBuffer.d.ts +0 -16
package/dist/miniprogram.js
CHANGED
|
@@ -192,37 +192,6 @@ function _inherits(subClass, superClass) {
|
|
|
192
192
|
if (superClass) _set_prototype_of(subClass, superClass);
|
|
193
193
|
}
|
|
194
194
|
|
|
195
|
-
/**
|
|
196
|
-
* WebGL platform engine,support includes WebGL1.0 and WebGL2.0.
|
|
197
|
-
*/ var WebGLEngine = /*#__PURE__*/ function(Engine) {
|
|
198
|
-
_inherits(WebGLEngine, Engine);
|
|
199
|
-
function WebGLEngine() {
|
|
200
|
-
return Engine.apply(this, arguments);
|
|
201
|
-
}
|
|
202
|
-
/**
|
|
203
|
-
* Create a WebGL engine.
|
|
204
|
-
* @param configuration - WebGL engine configuration
|
|
205
|
-
* @returns A promise that will resolve when the engine is created
|
|
206
|
-
*/ WebGLEngine.create = function create(configuration) {
|
|
207
|
-
var canvas = configuration.canvas;
|
|
208
|
-
var webCanvas = new WebCanvas(typeof canvas === "string" ? engineMiniprogramAdapter.document.getElementById(canvas) : canvas);
|
|
209
|
-
var webGLRenderer = new WebGLGraphicDevice(configuration.graphicDeviceOptions);
|
|
210
|
-
var engine = new WebGLEngine(webCanvas, webGLRenderer, configuration);
|
|
211
|
-
return engine._initialize(configuration);
|
|
212
|
-
};
|
|
213
|
-
_create_class(WebGLEngine, [
|
|
214
|
-
{
|
|
215
|
-
key: "canvas",
|
|
216
|
-
get: /**
|
|
217
|
-
* Web canvas.
|
|
218
|
-
*/ function get() {
|
|
219
|
-
return this._canvas;
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
]);
|
|
223
|
-
return WebGLEngine;
|
|
224
|
-
}(miniprogram$1.Engine);
|
|
225
|
-
|
|
226
195
|
function _extends() {
|
|
227
196
|
_extends = Object.assign || function assign(target) {
|
|
228
197
|
for (var i = 1; i < arguments.length; i++) {
|
|
@@ -236,84 +205,6 @@ function _extends() {
|
|
|
236
205
|
return _extends.apply(this, arguments);
|
|
237
206
|
}
|
|
238
207
|
|
|
239
|
-
var GLBuffer = /*#__PURE__*/ function() {
|
|
240
|
-
function GLBuffer(rhi, type, byteLength, bufferUsage, data) {
|
|
241
|
-
if (bufferUsage === void 0) bufferUsage = miniprogram$1.BufferUsage.Static;
|
|
242
|
-
var gl = rhi.gl;
|
|
243
|
-
var glBuffer = gl.createBuffer();
|
|
244
|
-
var glBufferUsage = this._getGLBufferUsage(gl, bufferUsage);
|
|
245
|
-
var glBindTarget = type === miniprogram$1.BufferBindFlag.VertexBuffer ? gl.ARRAY_BUFFER : gl.ELEMENT_ARRAY_BUFFER;
|
|
246
|
-
this._gl = gl;
|
|
247
|
-
this._glBuffer = glBuffer;
|
|
248
|
-
this._glBufferUsage = glBufferUsage;
|
|
249
|
-
this._glBindTarget = glBindTarget;
|
|
250
|
-
this._isWebGL2 = rhi.isWebGL2;
|
|
251
|
-
this.bind();
|
|
252
|
-
if (data) {
|
|
253
|
-
gl.bufferData(glBindTarget, data, glBufferUsage);
|
|
254
|
-
} else {
|
|
255
|
-
gl.bufferData(glBindTarget, byteLength, glBufferUsage);
|
|
256
|
-
}
|
|
257
|
-
gl.bindBuffer(glBindTarget, null);
|
|
258
|
-
}
|
|
259
|
-
var _proto = GLBuffer.prototype;
|
|
260
|
-
_proto.bind = function bind() {
|
|
261
|
-
this._gl.bindBuffer(this._glBindTarget, this._glBuffer);
|
|
262
|
-
};
|
|
263
|
-
_proto.setData = function setData(byteLength, data, bufferByteOffset, dataOffset, dataLength, options) {
|
|
264
|
-
var gl = this._gl;
|
|
265
|
-
var glBindTarget = this._glBindTarget;
|
|
266
|
-
this.bind();
|
|
267
|
-
if (options === miniprogram$1.SetDataOptions.Discard) {
|
|
268
|
-
gl.bufferData(glBindTarget, byteLength, this._glBufferUsage);
|
|
269
|
-
}
|
|
270
|
-
// TypeArray is BYTES_PER_ELEMENT, unTypeArray is 1
|
|
271
|
-
var byteSize = data.BYTES_PER_ELEMENT || 1;
|
|
272
|
-
var dataByteLength = dataLength ? byteSize * dataLength : data.byteLength;
|
|
273
|
-
if (dataOffset !== 0 || dataByteLength < data.byteLength) {
|
|
274
|
-
var isArrayBufferView = data.byteOffset !== undefined;
|
|
275
|
-
if (this._isWebGL2 && isArrayBufferView) {
|
|
276
|
-
gl.bufferSubData(glBindTarget, bufferByteOffset, data, dataOffset, dataByteLength / byteSize);
|
|
277
|
-
} else {
|
|
278
|
-
var subData = new Uint8Array(isArrayBufferView ? data.buffer : data, dataOffset * byteSize, dataByteLength);
|
|
279
|
-
gl.bufferSubData(glBindTarget, bufferByteOffset, subData);
|
|
280
|
-
}
|
|
281
|
-
} else {
|
|
282
|
-
gl.bufferSubData(glBindTarget, bufferByteOffset, data);
|
|
283
|
-
}
|
|
284
|
-
gl.bindBuffer(glBindTarget, null);
|
|
285
|
-
};
|
|
286
|
-
_proto.getData = function getData(data, bufferByteOffset, dataOffset, dataLength) {
|
|
287
|
-
if (this._isWebGL2) {
|
|
288
|
-
var gl = this._gl;
|
|
289
|
-
this.bind();
|
|
290
|
-
gl.getBufferSubData(this._glBindTarget, bufferByteOffset, data, dataOffset, dataLength);
|
|
291
|
-
} else {
|
|
292
|
-
throw "Buffer is write-only on WebGL1.0 platforms.";
|
|
293
|
-
}
|
|
294
|
-
};
|
|
295
|
-
_proto.resize = function resize(byteLength) {
|
|
296
|
-
this.bind();
|
|
297
|
-
this._gl.bufferData(this._glBindTarget, byteLength, this._glBufferUsage);
|
|
298
|
-
};
|
|
299
|
-
_proto.destroy = function destroy() {
|
|
300
|
-
this._gl.deleteBuffer(this._glBuffer);
|
|
301
|
-
this._gl = null;
|
|
302
|
-
this._glBuffer = null;
|
|
303
|
-
};
|
|
304
|
-
_proto._getGLBufferUsage = function _getGLBufferUsage(gl, bufferUsage) {
|
|
305
|
-
switch(bufferUsage){
|
|
306
|
-
case miniprogram$1.BufferUsage.Static:
|
|
307
|
-
return gl.STATIC_DRAW;
|
|
308
|
-
case miniprogram$1.BufferUsage.Dynamic:
|
|
309
|
-
return gl.DYNAMIC_DRAW;
|
|
310
|
-
case miniprogram$1.BufferUsage.Stream:
|
|
311
|
-
return gl.STREAM_DRAW;
|
|
312
|
-
}
|
|
313
|
-
};
|
|
314
|
-
return GLBuffer;
|
|
315
|
-
}();
|
|
316
|
-
|
|
317
208
|
/**
|
|
318
209
|
* GL capability.
|
|
319
210
|
*/ var GLCapability = /*#__PURE__*/ function() {
|
|
@@ -583,8 +474,8 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
583
474
|
if (useVao) {
|
|
584
475
|
gl.drawElements(topology, count, _glIndexType, start * _glIndexByteCount);
|
|
585
476
|
} else {
|
|
586
|
-
var
|
|
587
|
-
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER,
|
|
477
|
+
var _nativeBuffer = _indexBufferBinding.buffer._nativeBuffer;
|
|
478
|
+
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, _nativeBuffer);
|
|
588
479
|
gl.drawElements(topology, count, _glIndexType, start * _glIndexByteCount);
|
|
589
480
|
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, null);
|
|
590
481
|
}
|
|
@@ -597,8 +488,8 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
597
488
|
if (useVao) {
|
|
598
489
|
gl.drawElementsInstanced(topology, count, _glIndexType, start * _glIndexByteCount, _instanceCount);
|
|
599
490
|
} else {
|
|
600
|
-
var
|
|
601
|
-
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER,
|
|
491
|
+
var _nativeBuffer1 = _indexBufferBinding.buffer._nativeBuffer;
|
|
492
|
+
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, _nativeBuffer1);
|
|
602
493
|
gl.drawElementsInstanced(topology, count, _glIndexType, start * _glIndexByteCount, _instanceCount);
|
|
603
494
|
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, null);
|
|
604
495
|
}
|
|
@@ -638,7 +529,7 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
638
529
|
var element = attributes[name];
|
|
639
530
|
if (element) {
|
|
640
531
|
var _vertexBufferBindings_element_bindingIndex = vertexBufferBindings[element.bindingIndex], buffer = _vertexBufferBindings_element_bindingIndex.buffer, stride = _vertexBufferBindings_element_bindingIndex.stride;
|
|
641
|
-
vbo = buffer.
|
|
532
|
+
vbo = buffer._nativeBuffer;
|
|
642
533
|
// prevent binding the vbo which already bound at the last loop, e.g. a buffer with multiple attributes.
|
|
643
534
|
if (lastBoundVbo !== vbo) {
|
|
644
535
|
lastBoundVbo = vbo;
|
|
@@ -670,7 +561,7 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
670
561
|
// @ts-ignore
|
|
671
562
|
var _indexBufferBinding = this._primitive._indexBufferBinding;
|
|
672
563
|
if (_indexBufferBinding) {
|
|
673
|
-
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, _indexBufferBinding.buffer.
|
|
564
|
+
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, _indexBufferBinding.buffer._nativeBuffer);
|
|
674
565
|
}
|
|
675
566
|
this._bindBufferAndAttrib(shaderProgram);
|
|
676
567
|
/** unbind */ gl.bindVertexArray(null);
|
|
@@ -1735,19 +1626,20 @@ exports.WebGLMode = void 0;
|
|
|
1735
1626
|
WebGLMode[WebGLMode[/** WebGL1.0, */ "WebGL1"] = 2] = "WebGL1";
|
|
1736
1627
|
})(exports.WebGLMode || (exports.WebGLMode = {}));
|
|
1737
1628
|
/**
|
|
1738
|
-
* WebGL
|
|
1739
|
-
*/ var
|
|
1740
|
-
function
|
|
1629
|
+
* WebGL renderer, including WebGL1.0 and WebGL2.0.
|
|
1630
|
+
*/ var WebGLRenderer = /*#__PURE__*/ function() {
|
|
1631
|
+
function WebGLRenderer(initializeOptions) {
|
|
1741
1632
|
if (initializeOptions === void 0) initializeOptions = {};
|
|
1742
|
-
/** @internal */ this._readFrameBuffer = null;
|
|
1743
1633
|
/** @internal */ this._enableGlobalDepthBias = false;
|
|
1744
1634
|
this._activeTextures = new Array(32);
|
|
1635
|
+
// cache value
|
|
1745
1636
|
this._lastViewport = new miniprogram.Vector4(null, null, null, null);
|
|
1746
1637
|
this._lastScissor = new miniprogram.Vector4(null, null, null, null);
|
|
1747
1638
|
this._lastClearColor = new miniprogram.Color(null, null, null, null);
|
|
1748
1639
|
this._scissorEnable = false;
|
|
1749
1640
|
var options = _extends({
|
|
1750
1641
|
webGLMode: 0,
|
|
1642
|
+
alpha: false,
|
|
1751
1643
|
stencil: true,
|
|
1752
1644
|
_forceFlush: false
|
|
1753
1645
|
}, initializeOptions);
|
|
@@ -1762,20 +1654,12 @@ exports.WebGLMode = void 0;
|
|
|
1762
1654
|
}
|
|
1763
1655
|
}
|
|
1764
1656
|
this._options = options;
|
|
1765
|
-
this._onWebGLContextLost = this._onWebGLContextLost.bind(this);
|
|
1766
|
-
this._onWebGLContextRestored = this._onWebGLContextRestored.bind(this);
|
|
1767
1657
|
}
|
|
1768
|
-
var _proto =
|
|
1769
|
-
_proto.init = function init(canvas
|
|
1658
|
+
var _proto = WebGLRenderer.prototype;
|
|
1659
|
+
_proto.init = function init(canvas) {
|
|
1770
1660
|
var options = this._options;
|
|
1771
|
-
var webCanvas = canvas._webCanvas;
|
|
1661
|
+
var webCanvas = this._webCanvas = canvas._webCanvas;
|
|
1772
1662
|
var webGLMode = options.webGLMode;
|
|
1773
|
-
this._onDeviceLost = onDeviceLost;
|
|
1774
|
-
this._onDeviceRestored = onDeviceRestored;
|
|
1775
|
-
webCanvas.addEventListener("webglcontextlost", this._onWebGLContextLost, false);
|
|
1776
|
-
webCanvas.addEventListener("webglcontextrestored", this._onWebGLContextRestored, false);
|
|
1777
|
-
webCanvas.addEventListener("webglcontextcreationerror", this._onContextCreationError, false);
|
|
1778
|
-
this._webCanvas = webCanvas;
|
|
1779
1663
|
var gl;
|
|
1780
1664
|
if (webGLMode == 0 || webGLMode == 1) {
|
|
1781
1665
|
gl = webCanvas.getContext("webgl2", options);
|
|
@@ -1801,7 +1685,16 @@ exports.WebGLMode = void 0;
|
|
|
1801
1685
|
throw new Error("Get GL Context FAILED.");
|
|
1802
1686
|
}
|
|
1803
1687
|
this._gl = gl;
|
|
1804
|
-
this.
|
|
1688
|
+
this._activeTextureID = gl.TEXTURE0;
|
|
1689
|
+
this._renderStates = new GLRenderStates(gl);
|
|
1690
|
+
this._extensions = new GLExtensions(this);
|
|
1691
|
+
this._capability = new GLCapability(this);
|
|
1692
|
+
// Make sure the active texture in gl context is on default, because gl context may be used in other webgl renderer.
|
|
1693
|
+
gl.activeTexture(gl.TEXTURE0);
|
|
1694
|
+
var debugRenderInfo = gl.getExtension("WEBGL_debug_renderer_info");
|
|
1695
|
+
if (debugRenderInfo != null) {
|
|
1696
|
+
this._renderer = gl.getParameter(debugRenderInfo.UNMASKED_RENDERER_WEBGL);
|
|
1697
|
+
}
|
|
1805
1698
|
};
|
|
1806
1699
|
_proto.createPlatformPrimitive = function createPlatformPrimitive(primitive) {
|
|
1807
1700
|
return new GLPrimitive(this, primitive);
|
|
@@ -1818,10 +1711,6 @@ exports.WebGLMode = void 0;
|
|
|
1818
1711
|
_proto.createPlatformRenderTarget = function createPlatformRenderTarget(target) {
|
|
1819
1712
|
return new GLRenderTarget(this, target);
|
|
1820
1713
|
};
|
|
1821
|
-
_proto.createPlatformBuffer = function createPlatformBuffer(type, byteLength, bufferUsage, data) {
|
|
1822
|
-
if (bufferUsage === void 0) bufferUsage = miniprogram$1.BufferUsage.Static;
|
|
1823
|
-
return new GLBuffer(this, type, byteLength, bufferUsage, data);
|
|
1824
|
-
};
|
|
1825
1714
|
_proto.requireExtension = function requireExtension(ext) {
|
|
1826
1715
|
return this._extensions.requireExtension(ext);
|
|
1827
1716
|
};
|
|
@@ -1949,57 +1838,8 @@ exports.WebGLMode = void 0;
|
|
|
1949
1838
|
_proto.flush = function flush() {
|
|
1950
1839
|
this._gl.flush();
|
|
1951
1840
|
};
|
|
1952
|
-
_proto.
|
|
1953
|
-
|
|
1954
|
-
extension.loseContext();
|
|
1955
|
-
};
|
|
1956
|
-
_proto.forceRestoreDevice = function forceRestoreDevice() {
|
|
1957
|
-
var extension = this.requireExtension(miniprogram$1.GLCapabilityType.WEBGL_lose_context);
|
|
1958
|
-
extension.restoreContext();
|
|
1959
|
-
};
|
|
1960
|
-
_proto.resetState = function resetState() {
|
|
1961
|
-
this._readFrameBuffer = null;
|
|
1962
|
-
this._enableGlobalDepthBias = false;
|
|
1963
|
-
this._currentBindShaderProgram = null;
|
|
1964
|
-
var activeTextures = this._activeTextures;
|
|
1965
|
-
for(var i = 0, n = activeTextures.length; i < n; i++){
|
|
1966
|
-
activeTextures[i] = null;
|
|
1967
|
-
}
|
|
1968
|
-
this._lastViewport.set(null, null, null, null);
|
|
1969
|
-
this._lastScissor.set(null, null, null, null);
|
|
1970
|
-
this._lastClearColor.set(null, null, null, null);
|
|
1971
|
-
this._scissorEnable = false;
|
|
1972
|
-
this._initGLState(this._gl);
|
|
1973
|
-
};
|
|
1974
|
-
_proto._initGLState = function _initGLState(gl) {
|
|
1975
|
-
this._activeTextureID = gl.TEXTURE0;
|
|
1976
|
-
this._renderStates = new GLRenderStates(gl);
|
|
1977
|
-
this._extensions = new GLExtensions(this);
|
|
1978
|
-
this._capability = new GLCapability(this);
|
|
1979
|
-
// Make sure the active texture in gl context is on default, because gl context may be used in other webgl renderer.
|
|
1980
|
-
gl.activeTexture(gl.TEXTURE0);
|
|
1981
|
-
var debugRenderInfo = gl.getExtension("WEBGL_debug_renderer_info");
|
|
1982
|
-
if (debugRenderInfo != null) {
|
|
1983
|
-
this._renderer = gl.getParameter(debugRenderInfo.UNMASKED_RENDERER_WEBGL);
|
|
1984
|
-
}
|
|
1985
|
-
};
|
|
1986
|
-
_proto.destroy = function destroy() {
|
|
1987
|
-
var webCanvas = this._webCanvas;
|
|
1988
|
-
webCanvas.removeEventListener("webglcontextcreationerror", this._onContextCreationError, false);
|
|
1989
|
-
webCanvas.removeEventListener("webglcontextlost", this._onWebGLContextLost, false);
|
|
1990
|
-
webCanvas.removeEventListener("webglcontextrestored", this._onWebGLContextRestored, false);
|
|
1991
|
-
};
|
|
1992
|
-
_proto._onContextCreationError = function _onContextCreationError(event) {
|
|
1993
|
-
console.error("WebGLRenderer: WebGL context could not be created. Reason: ", event.statusMessage);
|
|
1994
|
-
};
|
|
1995
|
-
_proto._onWebGLContextLost = function _onWebGLContextLost(event) {
|
|
1996
|
-
event.preventDefault();
|
|
1997
|
-
this._onDeviceLost();
|
|
1998
|
-
};
|
|
1999
|
-
_proto._onWebGLContextRestored = function _onWebGLContextRestored(event) {
|
|
2000
|
-
this._onDeviceRestored();
|
|
2001
|
-
};
|
|
2002
|
-
_create_class(WebGLGraphicDevice, [
|
|
1841
|
+
_proto.destroy = function destroy() {};
|
|
1842
|
+
_create_class(WebGLRenderer, [
|
|
2003
1843
|
{
|
|
2004
1844
|
key: "isWebGL2",
|
|
2005
1845
|
get: function get() {
|
|
@@ -2040,9 +1880,31 @@ exports.WebGLMode = void 0;
|
|
|
2040
1880
|
}
|
|
2041
1881
|
}
|
|
2042
1882
|
]);
|
|
2043
|
-
return
|
|
1883
|
+
return WebGLRenderer;
|
|
2044
1884
|
}();
|
|
2045
1885
|
|
|
1886
|
+
/**
|
|
1887
|
+
* WebGL platform engine,support includes WebGL1.0 and WebGL2.0.
|
|
1888
|
+
*/ var WebGLEngine = /*#__PURE__*/ function(Engine) {
|
|
1889
|
+
_inherits(WebGLEngine, Engine);
|
|
1890
|
+
function WebGLEngine(canvas, webGLRendererOptions) {
|
|
1891
|
+
var webCanvas = new WebCanvas(typeof canvas === "string" ? engineMiniprogramAdapter.document.getElementById(canvas) : canvas);
|
|
1892
|
+
var hardwareRenderer = new WebGLRenderer(webGLRendererOptions);
|
|
1893
|
+
return Engine.call(this, webCanvas, hardwareRenderer);
|
|
1894
|
+
}
|
|
1895
|
+
_create_class(WebGLEngine, [
|
|
1896
|
+
{
|
|
1897
|
+
key: "canvas",
|
|
1898
|
+
get: /**
|
|
1899
|
+
* Web canvas.
|
|
1900
|
+
*/ function get() {
|
|
1901
|
+
return this._canvas;
|
|
1902
|
+
}
|
|
1903
|
+
}
|
|
1904
|
+
]);
|
|
1905
|
+
return WebGLEngine;
|
|
1906
|
+
}(miniprogram$1.Engine);
|
|
1907
|
+
|
|
2046
1908
|
exports.WebCanvas = WebCanvas;
|
|
2047
1909
|
exports.WebGLEngine = WebGLEngine;
|
|
2048
|
-
exports.
|
|
1910
|
+
exports.WebGLRenderer = WebGLRenderer;
|
package/dist/module.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Vector2, Vector4, Color } from '@galacean/engine-math';
|
|
2
|
-
import {
|
|
2
|
+
import { GLCapabilityType, Logger, TextureWrapMode, TextureFormat, RenderBufferDepthFormat, TextureFilterMode, TextureDepthCompareFunction, Texture, TextureCube, CameraClearFlags, ColorWriteMask, SystemInfo, Platform, Engine } from '@galacean/engine-core';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Smoothing plug-in.
|
|
@@ -187,37 +187,6 @@ function _inherits(subClass, superClass) {
|
|
|
187
187
|
if (superClass) _set_prototype_of(subClass, superClass);
|
|
188
188
|
}
|
|
189
189
|
|
|
190
|
-
/**
|
|
191
|
-
* WebGL platform engine,support includes WebGL1.0 and WebGL2.0.
|
|
192
|
-
*/ var WebGLEngine = /*#__PURE__*/ function(Engine) {
|
|
193
|
-
_inherits(WebGLEngine, Engine);
|
|
194
|
-
function WebGLEngine() {
|
|
195
|
-
return Engine.apply(this, arguments);
|
|
196
|
-
}
|
|
197
|
-
/**
|
|
198
|
-
* Create a WebGL engine.
|
|
199
|
-
* @param configuration - WebGL engine configuration
|
|
200
|
-
* @returns A promise that will resolve when the engine is created
|
|
201
|
-
*/ WebGLEngine.create = function create(configuration) {
|
|
202
|
-
var canvas = configuration.canvas;
|
|
203
|
-
var webCanvas = new WebCanvas(typeof canvas === "string" ? document.getElementById(canvas) : canvas);
|
|
204
|
-
var webGLRenderer = new WebGLGraphicDevice(configuration.graphicDeviceOptions);
|
|
205
|
-
var engine = new WebGLEngine(webCanvas, webGLRenderer, configuration);
|
|
206
|
-
return engine._initialize(configuration);
|
|
207
|
-
};
|
|
208
|
-
_create_class(WebGLEngine, [
|
|
209
|
-
{
|
|
210
|
-
key: "canvas",
|
|
211
|
-
get: /**
|
|
212
|
-
* Web canvas.
|
|
213
|
-
*/ function get() {
|
|
214
|
-
return this._canvas;
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
]);
|
|
218
|
-
return WebGLEngine;
|
|
219
|
-
}(Engine);
|
|
220
|
-
|
|
221
190
|
function _extends() {
|
|
222
191
|
_extends = Object.assign || function assign(target) {
|
|
223
192
|
for (var i = 1; i < arguments.length; i++) {
|
|
@@ -231,84 +200,6 @@ function _extends() {
|
|
|
231
200
|
return _extends.apply(this, arguments);
|
|
232
201
|
}
|
|
233
202
|
|
|
234
|
-
var GLBuffer = /*#__PURE__*/ function() {
|
|
235
|
-
function GLBuffer(rhi, type, byteLength, bufferUsage, data) {
|
|
236
|
-
if (bufferUsage === void 0) bufferUsage = BufferUsage.Static;
|
|
237
|
-
var gl = rhi.gl;
|
|
238
|
-
var glBuffer = gl.createBuffer();
|
|
239
|
-
var glBufferUsage = this._getGLBufferUsage(gl, bufferUsage);
|
|
240
|
-
var glBindTarget = type === BufferBindFlag.VertexBuffer ? gl.ARRAY_BUFFER : gl.ELEMENT_ARRAY_BUFFER;
|
|
241
|
-
this._gl = gl;
|
|
242
|
-
this._glBuffer = glBuffer;
|
|
243
|
-
this._glBufferUsage = glBufferUsage;
|
|
244
|
-
this._glBindTarget = glBindTarget;
|
|
245
|
-
this._isWebGL2 = rhi.isWebGL2;
|
|
246
|
-
this.bind();
|
|
247
|
-
if (data) {
|
|
248
|
-
gl.bufferData(glBindTarget, data, glBufferUsage);
|
|
249
|
-
} else {
|
|
250
|
-
gl.bufferData(glBindTarget, byteLength, glBufferUsage);
|
|
251
|
-
}
|
|
252
|
-
gl.bindBuffer(glBindTarget, null);
|
|
253
|
-
}
|
|
254
|
-
var _proto = GLBuffer.prototype;
|
|
255
|
-
_proto.bind = function bind() {
|
|
256
|
-
this._gl.bindBuffer(this._glBindTarget, this._glBuffer);
|
|
257
|
-
};
|
|
258
|
-
_proto.setData = function setData(byteLength, data, bufferByteOffset, dataOffset, dataLength, options) {
|
|
259
|
-
var gl = this._gl;
|
|
260
|
-
var glBindTarget = this._glBindTarget;
|
|
261
|
-
this.bind();
|
|
262
|
-
if (options === SetDataOptions.Discard) {
|
|
263
|
-
gl.bufferData(glBindTarget, byteLength, this._glBufferUsage);
|
|
264
|
-
}
|
|
265
|
-
// TypeArray is BYTES_PER_ELEMENT, unTypeArray is 1
|
|
266
|
-
var byteSize = data.BYTES_PER_ELEMENT || 1;
|
|
267
|
-
var dataByteLength = dataLength ? byteSize * dataLength : data.byteLength;
|
|
268
|
-
if (dataOffset !== 0 || dataByteLength < data.byteLength) {
|
|
269
|
-
var isArrayBufferView = data.byteOffset !== undefined;
|
|
270
|
-
if (this._isWebGL2 && isArrayBufferView) {
|
|
271
|
-
gl.bufferSubData(glBindTarget, bufferByteOffset, data, dataOffset, dataByteLength / byteSize);
|
|
272
|
-
} else {
|
|
273
|
-
var subData = new Uint8Array(isArrayBufferView ? data.buffer : data, dataOffset * byteSize, dataByteLength);
|
|
274
|
-
gl.bufferSubData(glBindTarget, bufferByteOffset, subData);
|
|
275
|
-
}
|
|
276
|
-
} else {
|
|
277
|
-
gl.bufferSubData(glBindTarget, bufferByteOffset, data);
|
|
278
|
-
}
|
|
279
|
-
gl.bindBuffer(glBindTarget, null);
|
|
280
|
-
};
|
|
281
|
-
_proto.getData = function getData(data, bufferByteOffset, dataOffset, dataLength) {
|
|
282
|
-
if (this._isWebGL2) {
|
|
283
|
-
var gl = this._gl;
|
|
284
|
-
this.bind();
|
|
285
|
-
gl.getBufferSubData(this._glBindTarget, bufferByteOffset, data, dataOffset, dataLength);
|
|
286
|
-
} else {
|
|
287
|
-
throw "Buffer is write-only on WebGL1.0 platforms.";
|
|
288
|
-
}
|
|
289
|
-
};
|
|
290
|
-
_proto.resize = function resize(byteLength) {
|
|
291
|
-
this.bind();
|
|
292
|
-
this._gl.bufferData(this._glBindTarget, byteLength, this._glBufferUsage);
|
|
293
|
-
};
|
|
294
|
-
_proto.destroy = function destroy() {
|
|
295
|
-
this._gl.deleteBuffer(this._glBuffer);
|
|
296
|
-
this._gl = null;
|
|
297
|
-
this._glBuffer = null;
|
|
298
|
-
};
|
|
299
|
-
_proto._getGLBufferUsage = function _getGLBufferUsage(gl, bufferUsage) {
|
|
300
|
-
switch(bufferUsage){
|
|
301
|
-
case BufferUsage.Static:
|
|
302
|
-
return gl.STATIC_DRAW;
|
|
303
|
-
case BufferUsage.Dynamic:
|
|
304
|
-
return gl.DYNAMIC_DRAW;
|
|
305
|
-
case BufferUsage.Stream:
|
|
306
|
-
return gl.STREAM_DRAW;
|
|
307
|
-
}
|
|
308
|
-
};
|
|
309
|
-
return GLBuffer;
|
|
310
|
-
}();
|
|
311
|
-
|
|
312
203
|
/**
|
|
313
204
|
* GL capability.
|
|
314
205
|
*/ var GLCapability = /*#__PURE__*/ function() {
|
|
@@ -578,8 +469,8 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
578
469
|
if (useVao) {
|
|
579
470
|
gl.drawElements(topology, count, _glIndexType, start * _glIndexByteCount);
|
|
580
471
|
} else {
|
|
581
|
-
var
|
|
582
|
-
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER,
|
|
472
|
+
var _nativeBuffer = _indexBufferBinding.buffer._nativeBuffer;
|
|
473
|
+
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, _nativeBuffer);
|
|
583
474
|
gl.drawElements(topology, count, _glIndexType, start * _glIndexByteCount);
|
|
584
475
|
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, null);
|
|
585
476
|
}
|
|
@@ -592,8 +483,8 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
592
483
|
if (useVao) {
|
|
593
484
|
gl.drawElementsInstanced(topology, count, _glIndexType, start * _glIndexByteCount, _instanceCount);
|
|
594
485
|
} else {
|
|
595
|
-
var
|
|
596
|
-
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER,
|
|
486
|
+
var _nativeBuffer1 = _indexBufferBinding.buffer._nativeBuffer;
|
|
487
|
+
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, _nativeBuffer1);
|
|
597
488
|
gl.drawElementsInstanced(topology, count, _glIndexType, start * _glIndexByteCount, _instanceCount);
|
|
598
489
|
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, null);
|
|
599
490
|
}
|
|
@@ -633,7 +524,7 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
633
524
|
var element = attributes[name];
|
|
634
525
|
if (element) {
|
|
635
526
|
var _vertexBufferBindings_element_bindingIndex = vertexBufferBindings[element.bindingIndex], buffer = _vertexBufferBindings_element_bindingIndex.buffer, stride = _vertexBufferBindings_element_bindingIndex.stride;
|
|
636
|
-
vbo = buffer.
|
|
527
|
+
vbo = buffer._nativeBuffer;
|
|
637
528
|
// prevent binding the vbo which already bound at the last loop, e.g. a buffer with multiple attributes.
|
|
638
529
|
if (lastBoundVbo !== vbo) {
|
|
639
530
|
lastBoundVbo = vbo;
|
|
@@ -665,7 +556,7 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
665
556
|
// @ts-ignore
|
|
666
557
|
var _indexBufferBinding = this._primitive._indexBufferBinding;
|
|
667
558
|
if (_indexBufferBinding) {
|
|
668
|
-
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, _indexBufferBinding.buffer.
|
|
559
|
+
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, _indexBufferBinding.buffer._nativeBuffer);
|
|
669
560
|
}
|
|
670
561
|
this._bindBufferAndAttrib(shaderProgram);
|
|
671
562
|
/** unbind */ gl.bindVertexArray(null);
|
|
@@ -1730,19 +1621,20 @@ var WebGLMode;
|
|
|
1730
1621
|
WebGLMode[WebGLMode[/** WebGL1.0, */ "WebGL1"] = 2] = "WebGL1";
|
|
1731
1622
|
})(WebGLMode || (WebGLMode = {}));
|
|
1732
1623
|
/**
|
|
1733
|
-
* WebGL
|
|
1734
|
-
*/ var
|
|
1735
|
-
function
|
|
1624
|
+
* WebGL renderer, including WebGL1.0 and WebGL2.0.
|
|
1625
|
+
*/ var WebGLRenderer = /*#__PURE__*/ function() {
|
|
1626
|
+
function WebGLRenderer(initializeOptions) {
|
|
1736
1627
|
if (initializeOptions === void 0) initializeOptions = {};
|
|
1737
|
-
/** @internal */ this._readFrameBuffer = null;
|
|
1738
1628
|
/** @internal */ this._enableGlobalDepthBias = false;
|
|
1739
1629
|
this._activeTextures = new Array(32);
|
|
1630
|
+
// cache value
|
|
1740
1631
|
this._lastViewport = new Vector4(null, null, null, null);
|
|
1741
1632
|
this._lastScissor = new Vector4(null, null, null, null);
|
|
1742
1633
|
this._lastClearColor = new Color(null, null, null, null);
|
|
1743
1634
|
this._scissorEnable = false;
|
|
1744
1635
|
var options = _extends({
|
|
1745
1636
|
webGLMode: 0,
|
|
1637
|
+
alpha: false,
|
|
1746
1638
|
stencil: true,
|
|
1747
1639
|
_forceFlush: false
|
|
1748
1640
|
}, initializeOptions);
|
|
@@ -1757,20 +1649,12 @@ var WebGLMode;
|
|
|
1757
1649
|
}
|
|
1758
1650
|
}
|
|
1759
1651
|
this._options = options;
|
|
1760
|
-
this._onWebGLContextLost = this._onWebGLContextLost.bind(this);
|
|
1761
|
-
this._onWebGLContextRestored = this._onWebGLContextRestored.bind(this);
|
|
1762
1652
|
}
|
|
1763
|
-
var _proto =
|
|
1764
|
-
_proto.init = function init(canvas
|
|
1653
|
+
var _proto = WebGLRenderer.prototype;
|
|
1654
|
+
_proto.init = function init(canvas) {
|
|
1765
1655
|
var options = this._options;
|
|
1766
|
-
var webCanvas = canvas._webCanvas;
|
|
1656
|
+
var webCanvas = this._webCanvas = canvas._webCanvas;
|
|
1767
1657
|
var webGLMode = options.webGLMode;
|
|
1768
|
-
this._onDeviceLost = onDeviceLost;
|
|
1769
|
-
this._onDeviceRestored = onDeviceRestored;
|
|
1770
|
-
webCanvas.addEventListener("webglcontextlost", this._onWebGLContextLost, false);
|
|
1771
|
-
webCanvas.addEventListener("webglcontextrestored", this._onWebGLContextRestored, false);
|
|
1772
|
-
webCanvas.addEventListener("webglcontextcreationerror", this._onContextCreationError, false);
|
|
1773
|
-
this._webCanvas = webCanvas;
|
|
1774
1658
|
var gl;
|
|
1775
1659
|
if (webGLMode == 0 || webGLMode == 1) {
|
|
1776
1660
|
gl = webCanvas.getContext("webgl2", options);
|
|
@@ -1796,7 +1680,16 @@ var WebGLMode;
|
|
|
1796
1680
|
throw new Error("Get GL Context FAILED.");
|
|
1797
1681
|
}
|
|
1798
1682
|
this._gl = gl;
|
|
1799
|
-
this.
|
|
1683
|
+
this._activeTextureID = gl.TEXTURE0;
|
|
1684
|
+
this._renderStates = new GLRenderStates(gl);
|
|
1685
|
+
this._extensions = new GLExtensions(this);
|
|
1686
|
+
this._capability = new GLCapability(this);
|
|
1687
|
+
// Make sure the active texture in gl context is on default, because gl context may be used in other webgl renderer.
|
|
1688
|
+
gl.activeTexture(gl.TEXTURE0);
|
|
1689
|
+
var debugRenderInfo = gl.getExtension("WEBGL_debug_renderer_info");
|
|
1690
|
+
if (debugRenderInfo != null) {
|
|
1691
|
+
this._renderer = gl.getParameter(debugRenderInfo.UNMASKED_RENDERER_WEBGL);
|
|
1692
|
+
}
|
|
1800
1693
|
};
|
|
1801
1694
|
_proto.createPlatformPrimitive = function createPlatformPrimitive(primitive) {
|
|
1802
1695
|
return new GLPrimitive(this, primitive);
|
|
@@ -1813,10 +1706,6 @@ var WebGLMode;
|
|
|
1813
1706
|
_proto.createPlatformRenderTarget = function createPlatformRenderTarget(target) {
|
|
1814
1707
|
return new GLRenderTarget(this, target);
|
|
1815
1708
|
};
|
|
1816
|
-
_proto.createPlatformBuffer = function createPlatformBuffer(type, byteLength, bufferUsage, data) {
|
|
1817
|
-
if (bufferUsage === void 0) bufferUsage = BufferUsage.Static;
|
|
1818
|
-
return new GLBuffer(this, type, byteLength, bufferUsage, data);
|
|
1819
|
-
};
|
|
1820
1709
|
_proto.requireExtension = function requireExtension(ext) {
|
|
1821
1710
|
return this._extensions.requireExtension(ext);
|
|
1822
1711
|
};
|
|
@@ -1944,57 +1833,8 @@ var WebGLMode;
|
|
|
1944
1833
|
_proto.flush = function flush() {
|
|
1945
1834
|
this._gl.flush();
|
|
1946
1835
|
};
|
|
1947
|
-
_proto.
|
|
1948
|
-
|
|
1949
|
-
extension.loseContext();
|
|
1950
|
-
};
|
|
1951
|
-
_proto.forceRestoreDevice = function forceRestoreDevice() {
|
|
1952
|
-
var extension = this.requireExtension(GLCapabilityType.WEBGL_lose_context);
|
|
1953
|
-
extension.restoreContext();
|
|
1954
|
-
};
|
|
1955
|
-
_proto.resetState = function resetState() {
|
|
1956
|
-
this._readFrameBuffer = null;
|
|
1957
|
-
this._enableGlobalDepthBias = false;
|
|
1958
|
-
this._currentBindShaderProgram = null;
|
|
1959
|
-
var activeTextures = this._activeTextures;
|
|
1960
|
-
for(var i = 0, n = activeTextures.length; i < n; i++){
|
|
1961
|
-
activeTextures[i] = null;
|
|
1962
|
-
}
|
|
1963
|
-
this._lastViewport.set(null, null, null, null);
|
|
1964
|
-
this._lastScissor.set(null, null, null, null);
|
|
1965
|
-
this._lastClearColor.set(null, null, null, null);
|
|
1966
|
-
this._scissorEnable = false;
|
|
1967
|
-
this._initGLState(this._gl);
|
|
1968
|
-
};
|
|
1969
|
-
_proto._initGLState = function _initGLState(gl) {
|
|
1970
|
-
this._activeTextureID = gl.TEXTURE0;
|
|
1971
|
-
this._renderStates = new GLRenderStates(gl);
|
|
1972
|
-
this._extensions = new GLExtensions(this);
|
|
1973
|
-
this._capability = new GLCapability(this);
|
|
1974
|
-
// Make sure the active texture in gl context is on default, because gl context may be used in other webgl renderer.
|
|
1975
|
-
gl.activeTexture(gl.TEXTURE0);
|
|
1976
|
-
var debugRenderInfo = gl.getExtension("WEBGL_debug_renderer_info");
|
|
1977
|
-
if (debugRenderInfo != null) {
|
|
1978
|
-
this._renderer = gl.getParameter(debugRenderInfo.UNMASKED_RENDERER_WEBGL);
|
|
1979
|
-
}
|
|
1980
|
-
};
|
|
1981
|
-
_proto.destroy = function destroy() {
|
|
1982
|
-
var webCanvas = this._webCanvas;
|
|
1983
|
-
webCanvas.removeEventListener("webglcontextcreationerror", this._onContextCreationError, false);
|
|
1984
|
-
webCanvas.removeEventListener("webglcontextlost", this._onWebGLContextLost, false);
|
|
1985
|
-
webCanvas.removeEventListener("webglcontextrestored", this._onWebGLContextRestored, false);
|
|
1986
|
-
};
|
|
1987
|
-
_proto._onContextCreationError = function _onContextCreationError(event) {
|
|
1988
|
-
console.error("WebGLRenderer: WebGL context could not be created. Reason: ", event.statusMessage);
|
|
1989
|
-
};
|
|
1990
|
-
_proto._onWebGLContextLost = function _onWebGLContextLost(event) {
|
|
1991
|
-
event.preventDefault();
|
|
1992
|
-
this._onDeviceLost();
|
|
1993
|
-
};
|
|
1994
|
-
_proto._onWebGLContextRestored = function _onWebGLContextRestored(event) {
|
|
1995
|
-
this._onDeviceRestored();
|
|
1996
|
-
};
|
|
1997
|
-
_create_class(WebGLGraphicDevice, [
|
|
1836
|
+
_proto.destroy = function destroy() {};
|
|
1837
|
+
_create_class(WebGLRenderer, [
|
|
1998
1838
|
{
|
|
1999
1839
|
key: "isWebGL2",
|
|
2000
1840
|
get: function get() {
|
|
@@ -2035,8 +1875,30 @@ var WebGLMode;
|
|
|
2035
1875
|
}
|
|
2036
1876
|
}
|
|
2037
1877
|
]);
|
|
2038
|
-
return
|
|
1878
|
+
return WebGLRenderer;
|
|
2039
1879
|
}();
|
|
2040
1880
|
|
|
2041
|
-
|
|
1881
|
+
/**
|
|
1882
|
+
* WebGL platform engine,support includes WebGL1.0 and WebGL2.0.
|
|
1883
|
+
*/ var WebGLEngine = /*#__PURE__*/ function(Engine) {
|
|
1884
|
+
_inherits(WebGLEngine, Engine);
|
|
1885
|
+
function WebGLEngine(canvas, webGLRendererOptions) {
|
|
1886
|
+
var webCanvas = new WebCanvas(typeof canvas === "string" ? document.getElementById(canvas) : canvas);
|
|
1887
|
+
var hardwareRenderer = new WebGLRenderer(webGLRendererOptions);
|
|
1888
|
+
return Engine.call(this, webCanvas, hardwareRenderer);
|
|
1889
|
+
}
|
|
1890
|
+
_create_class(WebGLEngine, [
|
|
1891
|
+
{
|
|
1892
|
+
key: "canvas",
|
|
1893
|
+
get: /**
|
|
1894
|
+
* Web canvas.
|
|
1895
|
+
*/ function get() {
|
|
1896
|
+
return this._canvas;
|
|
1897
|
+
}
|
|
1898
|
+
}
|
|
1899
|
+
]);
|
|
1900
|
+
return WebGLEngine;
|
|
1901
|
+
}(Engine);
|
|
1902
|
+
|
|
1903
|
+
export { GLCompressedTextureInternalFormat, WebCanvas, WebGLEngine, WebGLMode, WebGLRenderer };
|
|
2042
1904
|
//# sourceMappingURL=module.js.map
|