@galacean/engine-rhi-webgl 1.0.0 → 1.0.1
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 +211 -66
- package/dist/main.js.map +1 -1
- package/dist/miniprogram.js +211 -66
- package/dist/module.js +212 -67
- package/dist/module.js.map +1 -1
- package/package.json +4 -4
- package/types/GLBuffer.d.ts +16 -0
- 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 +15 -8
- package/types/WebGLGraphicDevice.d.ts +86 -0
- package/types/index.d.ts +3 -2
package/dist/module.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Vector2, Vector4, Color } from '@galacean/engine-math';
|
|
2
|
-
import { GLCapabilityType, Logger, TextureWrapMode, TextureFormat, RenderBufferDepthFormat, TextureFilterMode, TextureDepthCompareFunction, Texture, TextureCube, CameraClearFlags, ColorWriteMask, SystemInfo, Platform
|
|
2
|
+
import { Engine, BufferUsage, BufferBindFlag, SetDataOptions, GLCapabilityType, Logger, TextureUsage, TextureWrapMode, TextureFormat, RenderBufferDepthFormat, TextureFilterMode, TextureDepthCompareFunction, Texture, TextureCube, CameraClearFlags, ColorWriteMask, SystemInfo, Platform } from '@galacean/engine-core';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Smoothing plug-in.
|
|
@@ -187,6 +187,39 @@ 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 webGLGraphicDevice = new WebGLGraphicDevice(configuration.graphicDeviceOptions);
|
|
205
|
+
var engine = new WebGLEngine(webCanvas, webGLGraphicDevice, configuration);
|
|
206
|
+
// @ts-ignore
|
|
207
|
+
return engine._initialize(configuration);
|
|
208
|
+
};
|
|
209
|
+
_create_class(WebGLEngine, [
|
|
210
|
+
{
|
|
211
|
+
key: "canvas",
|
|
212
|
+
get: /**
|
|
213
|
+
* Web canvas.
|
|
214
|
+
*/ function get() {
|
|
215
|
+
// @ts-ignore
|
|
216
|
+
return this._canvas;
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
]);
|
|
220
|
+
return WebGLEngine;
|
|
221
|
+
}(Engine);
|
|
222
|
+
|
|
190
223
|
function _extends() {
|
|
191
224
|
_extends = Object.assign || function assign(target) {
|
|
192
225
|
for (var i = 1; i < arguments.length; i++) {
|
|
@@ -200,6 +233,84 @@ function _extends() {
|
|
|
200
233
|
return _extends.apply(this, arguments);
|
|
201
234
|
}
|
|
202
235
|
|
|
236
|
+
var GLBuffer = /*#__PURE__*/ function() {
|
|
237
|
+
function GLBuffer(rhi, type, byteLength, bufferUsage, data) {
|
|
238
|
+
if (bufferUsage === void 0) bufferUsage = BufferUsage.Static;
|
|
239
|
+
var gl = rhi.gl;
|
|
240
|
+
var glBuffer = gl.createBuffer();
|
|
241
|
+
var glBufferUsage = this._getGLBufferUsage(gl, bufferUsage);
|
|
242
|
+
var glBindTarget = type === BufferBindFlag.VertexBuffer ? gl.ARRAY_BUFFER : gl.ELEMENT_ARRAY_BUFFER;
|
|
243
|
+
this._gl = gl;
|
|
244
|
+
this._glBuffer = glBuffer;
|
|
245
|
+
this._glBufferUsage = glBufferUsage;
|
|
246
|
+
this._glBindTarget = glBindTarget;
|
|
247
|
+
this._isWebGL2 = rhi.isWebGL2;
|
|
248
|
+
this.bind();
|
|
249
|
+
if (data) {
|
|
250
|
+
gl.bufferData(glBindTarget, data, glBufferUsage);
|
|
251
|
+
} else {
|
|
252
|
+
gl.bufferData(glBindTarget, byteLength, glBufferUsage);
|
|
253
|
+
}
|
|
254
|
+
gl.bindBuffer(glBindTarget, null);
|
|
255
|
+
}
|
|
256
|
+
var _proto = GLBuffer.prototype;
|
|
257
|
+
_proto.bind = function bind() {
|
|
258
|
+
this._gl.bindBuffer(this._glBindTarget, this._glBuffer);
|
|
259
|
+
};
|
|
260
|
+
_proto.setData = function setData(byteLength, data, bufferByteOffset, dataOffset, dataLength, options) {
|
|
261
|
+
var gl = this._gl;
|
|
262
|
+
var glBindTarget = this._glBindTarget;
|
|
263
|
+
this.bind();
|
|
264
|
+
if (options === SetDataOptions.Discard) {
|
|
265
|
+
gl.bufferData(glBindTarget, byteLength, this._glBufferUsage);
|
|
266
|
+
}
|
|
267
|
+
// TypeArray is BYTES_PER_ELEMENT, unTypeArray is 1
|
|
268
|
+
var byteSize = data.BYTES_PER_ELEMENT || 1;
|
|
269
|
+
var dataByteLength = dataLength ? byteSize * dataLength : data.byteLength;
|
|
270
|
+
if (dataOffset !== 0 || dataByteLength < data.byteLength) {
|
|
271
|
+
var isArrayBufferView = data.byteOffset !== undefined;
|
|
272
|
+
if (this._isWebGL2 && isArrayBufferView) {
|
|
273
|
+
gl.bufferSubData(glBindTarget, bufferByteOffset, data, dataOffset, dataByteLength / byteSize);
|
|
274
|
+
} else {
|
|
275
|
+
var subData = new Uint8Array(isArrayBufferView ? data.buffer : data, dataOffset * byteSize, dataByteLength);
|
|
276
|
+
gl.bufferSubData(glBindTarget, bufferByteOffset, subData);
|
|
277
|
+
}
|
|
278
|
+
} else {
|
|
279
|
+
gl.bufferSubData(glBindTarget, bufferByteOffset, data);
|
|
280
|
+
}
|
|
281
|
+
gl.bindBuffer(glBindTarget, null);
|
|
282
|
+
};
|
|
283
|
+
_proto.getData = function getData(data, bufferByteOffset, dataOffset, dataLength) {
|
|
284
|
+
if (this._isWebGL2) {
|
|
285
|
+
var gl = this._gl;
|
|
286
|
+
this.bind();
|
|
287
|
+
gl.getBufferSubData(this._glBindTarget, bufferByteOffset, data, dataOffset, dataLength);
|
|
288
|
+
} else {
|
|
289
|
+
throw "Buffer is write-only on WebGL1.0 platforms.";
|
|
290
|
+
}
|
|
291
|
+
};
|
|
292
|
+
_proto.resize = function resize(byteLength) {
|
|
293
|
+
this.bind();
|
|
294
|
+
this._gl.bufferData(this._glBindTarget, byteLength, this._glBufferUsage);
|
|
295
|
+
};
|
|
296
|
+
_proto.destroy = function destroy() {
|
|
297
|
+
this._gl.deleteBuffer(this._glBuffer);
|
|
298
|
+
this._gl = null;
|
|
299
|
+
this._glBuffer = null;
|
|
300
|
+
};
|
|
301
|
+
_proto._getGLBufferUsage = function _getGLBufferUsage(gl, bufferUsage) {
|
|
302
|
+
switch(bufferUsage){
|
|
303
|
+
case BufferUsage.Static:
|
|
304
|
+
return gl.STATIC_DRAW;
|
|
305
|
+
case BufferUsage.Dynamic:
|
|
306
|
+
return gl.DYNAMIC_DRAW;
|
|
307
|
+
case BufferUsage.Stream:
|
|
308
|
+
return gl.STREAM_DRAW;
|
|
309
|
+
}
|
|
310
|
+
};
|
|
311
|
+
return GLBuffer;
|
|
312
|
+
}();
|
|
313
|
+
|
|
203
314
|
/**
|
|
204
315
|
* GL capability.
|
|
205
316
|
*/ var GLCapability = /*#__PURE__*/ function() {
|
|
@@ -469,8 +580,8 @@ function _extends() {
|
|
|
469
580
|
if (useVao) {
|
|
470
581
|
gl.drawElements(topology, count, _glIndexType, start * _glIndexByteCount);
|
|
471
582
|
} else {
|
|
472
|
-
var
|
|
473
|
-
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER,
|
|
583
|
+
var _glBuffer = _indexBufferBinding.buffer._platformBuffer._glBuffer;
|
|
584
|
+
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, _glBuffer);
|
|
474
585
|
gl.drawElements(topology, count, _glIndexType, start * _glIndexByteCount);
|
|
475
586
|
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, null);
|
|
476
587
|
}
|
|
@@ -483,8 +594,8 @@ function _extends() {
|
|
|
483
594
|
if (useVao) {
|
|
484
595
|
gl.drawElementsInstanced(topology, count, _glIndexType, start * _glIndexByteCount, _instanceCount);
|
|
485
596
|
} else {
|
|
486
|
-
var
|
|
487
|
-
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER,
|
|
597
|
+
var _glBuffer1 = _indexBufferBinding.buffer._platformBuffer._glBuffer;
|
|
598
|
+
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, _glBuffer1);
|
|
488
599
|
gl.drawElementsInstanced(topology, count, _glIndexType, start * _glIndexByteCount, _instanceCount);
|
|
489
600
|
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, null);
|
|
490
601
|
}
|
|
@@ -524,7 +635,7 @@ function _extends() {
|
|
|
524
635
|
var element = attributes[name];
|
|
525
636
|
if (element) {
|
|
526
637
|
var _vertexBufferBindings_element_bindingIndex = vertexBufferBindings[element.bindingIndex], buffer = _vertexBufferBindings_element_bindingIndex.buffer, stride = _vertexBufferBindings_element_bindingIndex.stride;
|
|
527
|
-
vbo = buffer.
|
|
638
|
+
vbo = buffer._platformBuffer._glBuffer;
|
|
528
639
|
// prevent binding the vbo which already bound at the last loop, e.g. a buffer with multiple attributes.
|
|
529
640
|
if (lastBoundVbo !== vbo) {
|
|
530
641
|
lastBoundVbo = vbo;
|
|
@@ -556,7 +667,7 @@ function _extends() {
|
|
|
556
667
|
// @ts-ignore
|
|
557
668
|
var _indexBufferBinding = this._primitive._indexBufferBinding;
|
|
558
669
|
if (_indexBufferBinding) {
|
|
559
|
-
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, _indexBufferBinding.buffer.
|
|
670
|
+
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, _indexBufferBinding.buffer._platformBuffer._glBuffer);
|
|
560
671
|
}
|
|
561
672
|
this._bindBufferAndAttrib(shaderProgram);
|
|
562
673
|
/** unbind */ gl.bindVertexArray(null);
|
|
@@ -663,9 +774,9 @@ function _extends() {
|
|
|
663
774
|
var isWebGL2 = this._isWebGL2;
|
|
664
775
|
var _this__formatDetail = this._formatDetail, internalFormat = _this__formatDetail.internalFormat, baseFormat = _this__formatDetail.baseFormat, dataType = _this__formatDetail.dataType;
|
|
665
776
|
// @ts-ignore
|
|
666
|
-
var _this__texture = this._texture, mipmapCount = _this__texture.mipmapCount, width = _this__texture.width, height = _this__texture.height, _isDepthTexture = _this__texture._isDepthTexture;
|
|
777
|
+
var _this__texture = this._texture, mipmapCount = _this__texture.mipmapCount, width = _this__texture.width, height = _this__texture.height, usage = _this__texture.usage, _isDepthTexture = _this__texture._isDepthTexture;
|
|
667
778
|
this._bind();
|
|
668
|
-
if (isWebGL2 && !(baseFormat === gl.LUMINANCE_ALPHA || baseFormat === gl.ALPHA)) {
|
|
779
|
+
if (isWebGL2 && !(baseFormat === gl.LUMINANCE_ALPHA || baseFormat === gl.ALPHA) && usage !== TextureUsage.Dynamic) {
|
|
669
780
|
gl.texStorage2D(this._target, mipmapCount, internalFormat, width, height);
|
|
670
781
|
} else {
|
|
671
782
|
if (!isCube) {
|
|
@@ -1460,11 +1571,15 @@ function _extends() {
|
|
|
1460
1571
|
* {@inheritDoc IPlatformTexture2D.setImageSource}
|
|
1461
1572
|
*/ _proto.setImageSource = function setImageSource(imageSource, mipLevel, flipY, premultiplyAlpha, x, y) {
|
|
1462
1573
|
var gl = this._gl;
|
|
1463
|
-
var _this__formatDetail = this._formatDetail, baseFormat = _this__formatDetail.baseFormat, dataType = _this__formatDetail.dataType;
|
|
1574
|
+
var _this__formatDetail = this._formatDetail, internalFormat = _this__formatDetail.internalFormat, baseFormat = _this__formatDetail.baseFormat, dataType = _this__formatDetail.dataType;
|
|
1464
1575
|
this._bind();
|
|
1465
1576
|
gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, +flipY);
|
|
1466
1577
|
gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, +premultiplyAlpha);
|
|
1467
|
-
|
|
1578
|
+
if (this._texture.usage === TextureUsage.Dynamic) {
|
|
1579
|
+
gl.texImage2D(this._target, mipLevel, internalFormat, baseFormat, dataType, imageSource);
|
|
1580
|
+
} else {
|
|
1581
|
+
gl.texSubImage2D(this._target, mipLevel, x || 0, y || 0, baseFormat, dataType, imageSource);
|
|
1582
|
+
}
|
|
1468
1583
|
};
|
|
1469
1584
|
/**
|
|
1470
1585
|
* {@inheritDoc IPlatformTexture2D.getPixelBuffer }
|
|
@@ -1621,22 +1736,22 @@ var WebGLMode;
|
|
|
1621
1736
|
WebGLMode[WebGLMode[/** WebGL1.0, */ "WebGL1"] = 2] = "WebGL1";
|
|
1622
1737
|
})(WebGLMode || (WebGLMode = {}));
|
|
1623
1738
|
/**
|
|
1624
|
-
* WebGL
|
|
1625
|
-
*/ var
|
|
1626
|
-
function
|
|
1739
|
+
* WebGL graphic device, including WebGL1.0 and WebGL2.0.
|
|
1740
|
+
*/ var WebGLGraphicDevice = /*#__PURE__*/ function() {
|
|
1741
|
+
function WebGLGraphicDevice(initializeOptions) {
|
|
1627
1742
|
if (initializeOptions === void 0) initializeOptions = {};
|
|
1743
|
+
/** @internal */ this._readFrameBuffer = null;
|
|
1628
1744
|
/** @internal */ this._enableGlobalDepthBias = false;
|
|
1629
1745
|
this._activeTextures = new Array(32);
|
|
1630
|
-
// cache value
|
|
1631
1746
|
this._lastViewport = new Vector4(null, null, null, null);
|
|
1632
1747
|
this._lastScissor = new Vector4(null, null, null, null);
|
|
1633
1748
|
this._lastClearColor = new Color(null, null, null, null);
|
|
1634
1749
|
this._scissorEnable = false;
|
|
1635
1750
|
var options = _extends({
|
|
1636
1751
|
webGLMode: 0,
|
|
1637
|
-
alpha: false,
|
|
1638
1752
|
stencil: true,
|
|
1639
|
-
_forceFlush: false
|
|
1753
|
+
_forceFlush: false,
|
|
1754
|
+
_maxAllowSkinUniformVectorCount: 256
|
|
1640
1755
|
}, initializeOptions);
|
|
1641
1756
|
if (SystemInfo.platform === Platform.IPhone || SystemInfo.platform === Platform.IPad) {
|
|
1642
1757
|
var version = SystemInfo.operatingSystem.match(/(\d+).?(\d+)?.?(\d+)?/);
|
|
@@ -1649,12 +1764,20 @@ var WebGLMode;
|
|
|
1649
1764
|
}
|
|
1650
1765
|
}
|
|
1651
1766
|
this._options = options;
|
|
1767
|
+
this._onWebGLContextLost = this._onWebGLContextLost.bind(this);
|
|
1768
|
+
this._onWebGLContextRestored = this._onWebGLContextRestored.bind(this);
|
|
1652
1769
|
}
|
|
1653
|
-
var _proto =
|
|
1654
|
-
_proto.init = function init(canvas) {
|
|
1770
|
+
var _proto = WebGLGraphicDevice.prototype;
|
|
1771
|
+
_proto.init = function init(canvas, onDeviceLost, onDeviceRestored) {
|
|
1655
1772
|
var options = this._options;
|
|
1656
|
-
var webCanvas =
|
|
1773
|
+
var webCanvas = canvas._webCanvas;
|
|
1657
1774
|
var webGLMode = options.webGLMode;
|
|
1775
|
+
this._onDeviceLost = onDeviceLost;
|
|
1776
|
+
this._onDeviceRestored = onDeviceRestored;
|
|
1777
|
+
webCanvas.addEventListener("webglcontextlost", this._onWebGLContextLost, false);
|
|
1778
|
+
webCanvas.addEventListener("webglcontextrestored", this._onWebGLContextRestored, false);
|
|
1779
|
+
webCanvas.addEventListener("webglcontextcreationerror", this._onContextCreationError, false);
|
|
1780
|
+
this._webCanvas = webCanvas;
|
|
1658
1781
|
var gl;
|
|
1659
1782
|
if (webGLMode == 0 || webGLMode == 1) {
|
|
1660
1783
|
gl = webCanvas.getContext("webgl2", options);
|
|
@@ -1680,16 +1803,7 @@ var WebGLMode;
|
|
|
1680
1803
|
throw new Error("Get GL Context FAILED.");
|
|
1681
1804
|
}
|
|
1682
1805
|
this._gl = gl;
|
|
1683
|
-
this.
|
|
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
|
-
}
|
|
1806
|
+
this._initGLState(gl);
|
|
1693
1807
|
};
|
|
1694
1808
|
_proto.createPlatformPrimitive = function createPlatformPrimitive(primitive) {
|
|
1695
1809
|
return new GLPrimitive(this, primitive);
|
|
@@ -1706,6 +1820,10 @@ var WebGLMode;
|
|
|
1706
1820
|
_proto.createPlatformRenderTarget = function createPlatformRenderTarget(target) {
|
|
1707
1821
|
return new GLRenderTarget(this, target);
|
|
1708
1822
|
};
|
|
1823
|
+
_proto.createPlatformBuffer = function createPlatformBuffer(type, byteLength, bufferUsage, data) {
|
|
1824
|
+
if (bufferUsage === void 0) bufferUsage = BufferUsage.Static;
|
|
1825
|
+
return new GLBuffer(this, type, byteLength, bufferUsage, data);
|
|
1826
|
+
};
|
|
1709
1827
|
_proto.requireExtension = function requireExtension(ext) {
|
|
1710
1828
|
return this._extensions.requireExtension(ext);
|
|
1711
1829
|
};
|
|
@@ -1788,23 +1906,23 @@ var WebGLMode;
|
|
|
1788
1906
|
};
|
|
1789
1907
|
_proto.activeRenderTarget = function activeRenderTarget(renderTarget, viewport, mipLevel) {
|
|
1790
1908
|
var gl = this._gl;
|
|
1909
|
+
var bufferWidth, bufferHeight;
|
|
1791
1910
|
if (renderTarget) {
|
|
1792
1911
|
var /** @ts-ignore */ _renderTarget__platformRenderTarget;
|
|
1793
1912
|
(_renderTarget__platformRenderTarget = renderTarget._platformRenderTarget) == null ? void 0 : _renderTarget__platformRenderTarget._activeRenderTarget();
|
|
1794
|
-
|
|
1795
|
-
|
|
1796
|
-
this.viewport(0, 0, width, height);
|
|
1797
|
-
this.scissor(0, 0, width, height);
|
|
1913
|
+
bufferWidth = renderTarget.width >> mipLevel;
|
|
1914
|
+
bufferHeight = renderTarget.height >> mipLevel;
|
|
1798
1915
|
} else {
|
|
1799
1916
|
gl.bindFramebuffer(gl.FRAMEBUFFER, null);
|
|
1800
|
-
|
|
1801
|
-
|
|
1802
|
-
var height1 = drawingBufferHeight * viewport.w;
|
|
1803
|
-
var x = viewport.x * drawingBufferWidth;
|
|
1804
|
-
var y = drawingBufferHeight - viewport.y * drawingBufferHeight - height1;
|
|
1805
|
-
this.viewport(x, y, width1, height1);
|
|
1806
|
-
this.scissor(x, y, width1, height1);
|
|
1917
|
+
bufferWidth = gl.drawingBufferWidth;
|
|
1918
|
+
bufferHeight = gl.drawingBufferHeight;
|
|
1807
1919
|
}
|
|
1920
|
+
var width = bufferWidth * viewport.z;
|
|
1921
|
+
var height = bufferHeight * viewport.w;
|
|
1922
|
+
var x = viewport.x * bufferWidth;
|
|
1923
|
+
var y = bufferHeight - viewport.y * bufferHeight - height;
|
|
1924
|
+
this.viewport(x, y, width, height);
|
|
1925
|
+
this.scissor(x, y, width, height);
|
|
1808
1926
|
};
|
|
1809
1927
|
_proto.activeTexture = function activeTexture(textureID) {
|
|
1810
1928
|
if (this._activeTextureID !== textureID) {
|
|
@@ -1833,8 +1951,57 @@ var WebGLMode;
|
|
|
1833
1951
|
_proto.flush = function flush() {
|
|
1834
1952
|
this._gl.flush();
|
|
1835
1953
|
};
|
|
1836
|
-
_proto.
|
|
1837
|
-
|
|
1954
|
+
_proto.forceLoseDevice = function forceLoseDevice() {
|
|
1955
|
+
var extension = this.requireExtension(GLCapabilityType.WEBGL_lose_context);
|
|
1956
|
+
extension.loseContext();
|
|
1957
|
+
};
|
|
1958
|
+
_proto.forceRestoreDevice = function forceRestoreDevice() {
|
|
1959
|
+
var extension = this.requireExtension(GLCapabilityType.WEBGL_lose_context);
|
|
1960
|
+
extension.restoreContext();
|
|
1961
|
+
};
|
|
1962
|
+
_proto.resetState = function resetState() {
|
|
1963
|
+
this._readFrameBuffer = null;
|
|
1964
|
+
this._enableGlobalDepthBias = false;
|
|
1965
|
+
this._currentBindShaderProgram = null;
|
|
1966
|
+
var activeTextures = this._activeTextures;
|
|
1967
|
+
for(var i = 0, n = activeTextures.length; i < n; i++){
|
|
1968
|
+
activeTextures[i] = null;
|
|
1969
|
+
}
|
|
1970
|
+
this._lastViewport.set(null, null, null, null);
|
|
1971
|
+
this._lastScissor.set(null, null, null, null);
|
|
1972
|
+
this._lastClearColor.set(null, null, null, null);
|
|
1973
|
+
this._scissorEnable = false;
|
|
1974
|
+
this._initGLState(this._gl);
|
|
1975
|
+
};
|
|
1976
|
+
_proto._initGLState = function _initGLState(gl) {
|
|
1977
|
+
this._activeTextureID = gl.TEXTURE0;
|
|
1978
|
+
this._renderStates = new GLRenderStates(gl);
|
|
1979
|
+
this._extensions = new GLExtensions(this);
|
|
1980
|
+
this._capability = new GLCapability(this);
|
|
1981
|
+
// Make sure the active texture in gl context is on default, because gl context may be used in other webgl renderer.
|
|
1982
|
+
gl.activeTexture(gl.TEXTURE0);
|
|
1983
|
+
var debugRenderInfo = gl.getExtension("WEBGL_debug_renderer_info");
|
|
1984
|
+
if (debugRenderInfo != null) {
|
|
1985
|
+
this._renderer = gl.getParameter(debugRenderInfo.UNMASKED_RENDERER_WEBGL);
|
|
1986
|
+
}
|
|
1987
|
+
};
|
|
1988
|
+
_proto.destroy = function destroy() {
|
|
1989
|
+
var webCanvas = this._webCanvas;
|
|
1990
|
+
webCanvas.removeEventListener("webglcontextcreationerror", this._onContextCreationError, false);
|
|
1991
|
+
webCanvas.removeEventListener("webglcontextlost", this._onWebGLContextLost, false);
|
|
1992
|
+
webCanvas.removeEventListener("webglcontextrestored", this._onWebGLContextRestored, false);
|
|
1993
|
+
};
|
|
1994
|
+
_proto._onContextCreationError = function _onContextCreationError(event) {
|
|
1995
|
+
console.error("WebGLRenderer: WebGL context could not be created. Reason: ", event.statusMessage);
|
|
1996
|
+
};
|
|
1997
|
+
_proto._onWebGLContextLost = function _onWebGLContextLost(event) {
|
|
1998
|
+
event.preventDefault();
|
|
1999
|
+
this._onDeviceLost();
|
|
2000
|
+
};
|
|
2001
|
+
_proto._onWebGLContextRestored = function _onWebGLContextRestored(event) {
|
|
2002
|
+
this._onDeviceRestored();
|
|
2003
|
+
};
|
|
2004
|
+
_create_class(WebGLGraphicDevice, [
|
|
1838
2005
|
{
|
|
1839
2006
|
key: "isWebGL2",
|
|
1840
2007
|
get: function get() {
|
|
@@ -1875,30 +2042,8 @@ var WebGLMode;
|
|
|
1875
2042
|
}
|
|
1876
2043
|
}
|
|
1877
2044
|
]);
|
|
1878
|
-
return
|
|
2045
|
+
return WebGLGraphicDevice;
|
|
1879
2046
|
}();
|
|
1880
2047
|
|
|
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 };
|
|
2048
|
+
export { GLCompressedTextureInternalFormat, WebCanvas, WebGLEngine, WebGLGraphicDevice, WebGLMode };
|
|
1904
2049
|
//# sourceMappingURL=module.js.map
|