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