@galacean/engine-rhi-webgl 2.0.0-alpha.6 → 2.0.0-alpha.60
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 +529 -509
- package/dist/main.js.map +1 -1
- package/dist/module.js +532 -511
- package/dist/module.js.map +1 -1
- package/package.json +3 -6
- package/types/GLBuffer.d.ts +4 -3
- package/types/GLCapability.d.ts +11 -18
- package/types/GLPrimitive.d.ts +25 -1
- package/types/GLRenderStates.d.ts +2 -2
- package/types/GLRenderTarget.d.ts +2 -1
- package/types/GLTexture.d.ts +29 -3
- package/types/GLTexture2D.d.ts +1 -3
- package/types/GLTexture2DArray.d.ts +1 -1
- package/types/GLTextureCube.d.ts +0 -2
- package/types/GLTransformFeedback.d.ts +18 -0
- package/types/GLTransformFeedbackPrimitive.d.ts +22 -0
- package/types/WebCanvas.d.ts +26 -17
- package/types/WebGLEngine.d.ts +3 -3
- package/types/WebGLGraphicDevice.d.ts +58 -32
- package/types/index.d.ts +1 -1
- package/types/type.d.ts +0 -24
package/dist/module.js
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
import { Canvas,
|
|
2
|
-
import {
|
|
1
|
+
import { Canvas, Engine, BufferUsage, BufferBindFlag, SetDataOptions, GLCapabilityType, TextureFormat, Logger, TextureUtils, TextureUsage, TextureWrapMode, TextureFilterMode, TextureDepthCompareFunction, Texture, TextureCube, CameraClearFlags, ColorWriteMask, SystemInfo, Platform } from '@galacean/engine-core';
|
|
2
|
+
import { Vector4, Color } from '@galacean/engine-math';
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
* Smoothing plug-in.
|
|
6
|
-
* */ var GLCompressedTextureInternalFormat = /*#__PURE__*/ function(GLCompressedTextureInternalFormat) {
|
|
4
|
+
var GLCompressedTextureInternalFormat = /*#__PURE__*/ function(GLCompressedTextureInternalFormat) {
|
|
7
5
|
// astc
|
|
8
6
|
GLCompressedTextureInternalFormat[GLCompressedTextureInternalFormat["RGBA_ASTC_4X4_KHR"] = 37808] = "RGBA_ASTC_4X4_KHR";
|
|
9
7
|
GLCompressedTextureInternalFormat[GLCompressedTextureInternalFormat["RGBA_ASTC_5X4_KHR"] = 37809] = "RGBA_ASTC_5X4_KHR";
|
|
@@ -69,24 +67,6 @@ import { Vector2, MathUtil, Vector4, Color } from '@galacean/engine-math';
|
|
|
69
67
|
return GLCompressedTextureInternalFormat;
|
|
70
68
|
}({});
|
|
71
69
|
|
|
72
|
-
function _defineProperties(target, props) {
|
|
73
|
-
for (var i = 0; i < props.length; i++) {
|
|
74
|
-
var descriptor = props[i];
|
|
75
|
-
descriptor.enumerable = descriptor.enumerable || false;
|
|
76
|
-
descriptor.configurable = true;
|
|
77
|
-
|
|
78
|
-
if ("value" in descriptor) descriptor.writable = true;
|
|
79
|
-
|
|
80
|
-
Object.defineProperty(target, descriptor.key, descriptor);
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
function _create_class(Constructor, protoProps, staticProps) {
|
|
84
|
-
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
|
|
85
|
-
if (staticProps) _defineProperties(Constructor, staticProps);
|
|
86
|
-
|
|
87
|
-
return Constructor;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
70
|
function _set_prototype_of(o, p) {
|
|
91
71
|
_set_prototype_of = Object.setPrototypeOf || function setPrototypeOf(o, p) {
|
|
92
72
|
o.__proto__ = p;
|
|
@@ -119,69 +99,134 @@ function _instanceof(left, right) {
|
|
|
119
99
|
_inherits(WebCanvas, Canvas);
|
|
120
100
|
function WebCanvas(webCanvas) {
|
|
121
101
|
var _this;
|
|
122
|
-
_this = Canvas.call(this) || this, _this.
|
|
123
|
-
var width = webCanvas.width;
|
|
124
|
-
var height = webCanvas.height;
|
|
102
|
+
_this = Canvas.call(this) || this, _this._autoResolutionScale = 1, _this._resolutionDirty = false, _this._pendingDevicePixelWidth = 0, _this._pendingDevicePixelHeight = 0;
|
|
125
103
|
_this._webCanvas = webCanvas;
|
|
126
|
-
_this.width
|
|
127
|
-
_this.height = height;
|
|
104
|
+
_this._setResolution(webCanvas.width, webCanvas.height);
|
|
128
105
|
return _this;
|
|
129
106
|
}
|
|
130
107
|
var _proto = WebCanvas.prototype;
|
|
131
108
|
/**
|
|
132
|
-
*
|
|
133
|
-
*
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
109
|
+
* @inheritdoc
|
|
110
|
+
*
|
|
111
|
+
* @remarks
|
|
112
|
+
* The canvas must have a CSS-constrained display size; otherwise auto-resolution disables itself.
|
|
113
|
+
*/ _proto.setAutoResolution = function setAutoResolution(scale) {
|
|
114
|
+
var _this = this;
|
|
115
|
+
if (scale === void 0) scale = 1;
|
|
116
|
+
if (!Number.isFinite(scale) || scale <= 0) {
|
|
117
|
+
throw new Error("WebCanvas.setAutoResolution: invalid scale " + scale);
|
|
118
|
+
}
|
|
119
|
+
// OffscreenCanvas has no display size to follow
|
|
120
|
+
if (this._isOffscreenCanvas()) return;
|
|
121
|
+
this._autoResolutionScale = scale;
|
|
122
|
+
if (this._resizeObserver) {
|
|
123
|
+
this._resolutionDirty = true;
|
|
124
|
+
} else if (typeof ResizeObserver !== "undefined") {
|
|
125
|
+
// observe() fires an initial entry, which sets the pending device pixel size
|
|
126
|
+
this._resizeObserver = new ResizeObserver(function(entries) {
|
|
127
|
+
var _entries__devicePixelContentBoxSize;
|
|
128
|
+
var box = (_entries__devicePixelContentBoxSize = entries[entries.length - 1].devicePixelContentBoxSize) == null ? void 0 : _entries__devicePixelContentBoxSize[0];
|
|
129
|
+
_this._pendingDevicePixelWidth = box ? box.inlineSize : 0;
|
|
130
|
+
_this._pendingDevicePixelHeight = box ? box.blockSize : 0;
|
|
131
|
+
_this._resolutionDirty = true;
|
|
132
|
+
});
|
|
133
|
+
// Observe exact device pixels where supported, otherwise the content-box and size from the client size
|
|
134
|
+
if (WebCanvas._supportsDevicePixelContentBox()) {
|
|
135
|
+
this._resizeObserver.observe(this._webCanvas, {
|
|
136
|
+
box: "device-pixel-content-box"
|
|
137
|
+
});
|
|
138
|
+
} else {
|
|
139
|
+
this._resizeObserver.observe(this._webCanvas);
|
|
140
|
+
}
|
|
141
|
+
} else {
|
|
142
|
+
// ResizeObserver is unavailable (e.g. mini-programs, iOS Safari < 13.4): size once from the client size
|
|
143
|
+
console.warn("ResizeObserver is not supported in this environment. Falling back to one-time clientWidth × devicePixelRatio × scale sizing");
|
|
144
|
+
this._setResolutionByClientSizeFallback(scale);
|
|
142
145
|
}
|
|
143
146
|
};
|
|
144
147
|
/**
|
|
145
|
-
*
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
*/ _proto.setScale = function setScale(x, y) {
|
|
149
|
-
this._scale.set(x, y);
|
|
150
|
-
this.scale = this._scale;
|
|
148
|
+
* @internal
|
|
149
|
+
*/ _proto._isOffscreenCanvas = function _isOffscreenCanvas() {
|
|
150
|
+
return typeof OffscreenCanvas !== "undefined" && _instanceof(this._webCanvas, OffscreenCanvas);
|
|
151
151
|
};
|
|
152
|
-
|
|
153
|
-
|
|
152
|
+
/**
|
|
153
|
+
* @internal
|
|
154
|
+
*/ _proto._pumpPendingResolution = function _pumpPendingResolution() {
|
|
155
|
+
if (!this._resolutionDirty) return;
|
|
156
|
+
var webCanvas = this._webCanvas;
|
|
157
|
+
if (webCanvas.clientWidth === 0 || webCanvas.clientHeight === 0) return;
|
|
158
|
+
this._resolutionDirty = false;
|
|
159
|
+
var scale = this._autoResolutionScale;
|
|
160
|
+
// Snapshot the display size to detect a layout feedback loop after applying the buffer size below
|
|
161
|
+
var prevClientWidth = webCanvas.clientWidth;
|
|
162
|
+
var prevClientHeight = webCanvas.clientHeight;
|
|
163
|
+
if (this._pendingDevicePixelWidth > 0 && this._pendingDevicePixelHeight > 0) {
|
|
164
|
+
// Device pixels already fold in the device pixel ratio, so only the scale is applied
|
|
165
|
+
this._setResolution(Math.round(this._pendingDevicePixelWidth * scale), Math.round(this._pendingDevicePixelHeight * scale));
|
|
166
|
+
} else {
|
|
167
|
+
this._setResolutionByClientSizeFallback(scale);
|
|
168
|
+
}
|
|
169
|
+
// If setting the buffer moved the display size, the canvas has no CSS size constraint and would grow
|
|
170
|
+
// unboundedly; exit auto-resolution instead
|
|
171
|
+
if (webCanvas.clientWidth !== prevClientWidth || webCanvas.clientHeight !== prevClientHeight) {
|
|
172
|
+
console.warn("Auto-resolution disabled: the canvas has no CSS width/height, so sizing the buffer grows its display size. " + "Set a CSS width/height on the canvas, then call setResolution() or setAutoResolution().");
|
|
173
|
+
this._exitAutoResolution();
|
|
174
|
+
}
|
|
154
175
|
};
|
|
155
|
-
_proto.
|
|
156
|
-
this._webCanvas
|
|
176
|
+
_proto._setResolutionByClientSizeFallback = function _setResolutionByClientSizeFallback(scale) {
|
|
177
|
+
var webCanvas = this._webCanvas;
|
|
178
|
+
if (webCanvas.clientWidth <= 0 || webCanvas.clientHeight <= 0) return;
|
|
179
|
+
var pixelRatio = window.devicePixelRatio * scale;
|
|
180
|
+
this._setResolution(Math.round(webCanvas.clientWidth * pixelRatio), Math.round(webCanvas.clientHeight * pixelRatio));
|
|
157
181
|
};
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
this._scale.set(webCanvas.clientWidth * devicePixelRatio / webCanvas.width, webCanvas.clientHeight * devicePixelRatio / webCanvas.height);
|
|
168
|
-
}
|
|
169
|
-
return this._scale;
|
|
170
|
-
},
|
|
171
|
-
set: function set(value) {
|
|
172
|
-
var webCanvas = this._webCanvas;
|
|
173
|
-
if (typeof OffscreenCanvas === "undefined" || !_instanceof(webCanvas, OffscreenCanvas)) {
|
|
174
|
-
webCanvas.style.transformOrigin = "left top";
|
|
175
|
-
webCanvas.style.transform = "scale(" + value.x + ", " + value.y + ")";
|
|
176
|
-
}
|
|
177
|
-
}
|
|
182
|
+
/**
|
|
183
|
+
* @internal
|
|
184
|
+
*/ _proto._destroy = function _destroy() {
|
|
185
|
+
this._exitAutoResolution();
|
|
186
|
+
};
|
|
187
|
+
_proto._exitAutoResolution = function _exitAutoResolution() {
|
|
188
|
+
if (this._resizeObserver) {
|
|
189
|
+
this._resizeObserver.disconnect();
|
|
190
|
+
this._resizeObserver = undefined;
|
|
178
191
|
}
|
|
179
|
-
|
|
192
|
+
this._resolutionDirty = false;
|
|
193
|
+
this._pendingDevicePixelWidth = 0;
|
|
194
|
+
this._pendingDevicePixelHeight = 0;
|
|
195
|
+
};
|
|
196
|
+
_proto._onResolutionChanged = function _onResolutionChanged(width, height) {
|
|
197
|
+
var webCanvas = this._webCanvas;
|
|
198
|
+
webCanvas.width = width;
|
|
199
|
+
webCanvas.height = height;
|
|
200
|
+
};
|
|
201
|
+
WebCanvas._supportsDevicePixelContentBox = function _supportsDevicePixelContentBox() {
|
|
202
|
+
var _this__devicePixelContentBoxSupported;
|
|
203
|
+
// Passing { box: "device-pixel-content-box" } to observe() throws on browsers whose
|
|
204
|
+
// ResizeObserverBoxOptions enum lacks that value (Safari, Firefox < 93), so callers must gate on this
|
|
205
|
+
return (_this__devicePixelContentBoxSupported = this._devicePixelContentBoxSupported) != null ? _this__devicePixelContentBoxSupported : this._devicePixelContentBoxSupported = typeof ResizeObserverEntry !== "undefined" && "devicePixelContentBoxSize" in ResizeObserverEntry.prototype;
|
|
206
|
+
};
|
|
180
207
|
return WebCanvas;
|
|
181
208
|
}(Canvas);
|
|
182
209
|
|
|
210
|
+
function _defineProperties(target, props) {
|
|
211
|
+
for (var i = 0; i < props.length; i++) {
|
|
212
|
+
var descriptor = props[i];
|
|
213
|
+
descriptor.enumerable = descriptor.enumerable || false;
|
|
214
|
+
descriptor.configurable = true;
|
|
215
|
+
|
|
216
|
+
if ("value" in descriptor) descriptor.writable = true;
|
|
217
|
+
|
|
218
|
+
Object.defineProperty(target, descriptor.key, descriptor);
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
function _create_class(Constructor, protoProps, staticProps) {
|
|
222
|
+
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
|
|
223
|
+
if (staticProps) _defineProperties(Constructor, staticProps);
|
|
224
|
+
|
|
225
|
+
return Constructor;
|
|
226
|
+
}
|
|
227
|
+
|
|
183
228
|
/**
|
|
184
|
-
* WebGL platform engine,
|
|
229
|
+
* WebGL platform engine, supports WebGL 2.0.
|
|
185
230
|
*/ var WebGLEngine = /*#__PURE__*/ function(Engine) {
|
|
186
231
|
_inherits(WebGLEngine, Engine);
|
|
187
232
|
function WebGLEngine() {
|
|
@@ -196,20 +241,15 @@ function _instanceof(left, right) {
|
|
|
196
241
|
var webCanvas = new WebCanvas(typeof canvas === "string" ? document.getElementById(canvas) : canvas);
|
|
197
242
|
var webGLGraphicDevice = new WebGLGraphicDevice(configuration.graphicDeviceOptions);
|
|
198
243
|
var engine = new WebGLEngine(webCanvas, webGLGraphicDevice, configuration);
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
return promise.then(function() {
|
|
202
|
-
engine.sceneManager.addScene(new Scene(engine, "DefaultScene"));
|
|
203
|
-
return engine;
|
|
204
|
-
});
|
|
244
|
+
webCanvas.setAutoResolution();
|
|
245
|
+
return engine._initialize(configuration);
|
|
205
246
|
};
|
|
206
247
|
_create_class(WebGLEngine, [
|
|
207
248
|
{
|
|
208
249
|
key: "canvas",
|
|
209
250
|
get: /**
|
|
210
|
-
*
|
|
251
|
+
* The web canvas the engine renders to.
|
|
211
252
|
*/ function get() {
|
|
212
|
-
// @ts-ignore
|
|
213
253
|
return this._canvas;
|
|
214
254
|
}
|
|
215
255
|
}
|
|
@@ -236,12 +276,22 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
236
276
|
var gl = rhi.gl;
|
|
237
277
|
var glBuffer = gl.createBuffer();
|
|
238
278
|
var glBufferUsage = this._getGLBufferUsage(gl, bufferUsage);
|
|
239
|
-
var glBindTarget
|
|
279
|
+
var glBindTarget;
|
|
280
|
+
switch(type){
|
|
281
|
+
case BufferBindFlag.VertexBuffer:
|
|
282
|
+
glBindTarget = gl.ARRAY_BUFFER;
|
|
283
|
+
break;
|
|
284
|
+
case BufferBindFlag.IndexBuffer:
|
|
285
|
+
glBindTarget = gl.ELEMENT_ARRAY_BUFFER;
|
|
286
|
+
break;
|
|
287
|
+
case BufferBindFlag.ConstantBuffer:
|
|
288
|
+
glBindTarget = gl.UNIFORM_BUFFER;
|
|
289
|
+
break;
|
|
290
|
+
}
|
|
240
291
|
this._gl = gl;
|
|
241
292
|
this._glBuffer = glBuffer;
|
|
242
293
|
this._glBufferUsage = glBufferUsage;
|
|
243
294
|
this._glBindTarget = glBindTarget;
|
|
244
|
-
this._isWebGL2 = rhi.isWebGL2;
|
|
245
295
|
this.bind();
|
|
246
296
|
if (data) {
|
|
247
297
|
gl.bufferData(glBindTarget, data, glBufferUsage);
|
|
@@ -266,7 +316,7 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
266
316
|
var dataByteLength = dataLength ? byteSize * dataLength : data.byteLength;
|
|
267
317
|
if (dataOffset !== 0 || dataByteLength < data.byteLength) {
|
|
268
318
|
var isArrayBufferView = data.byteOffset !== undefined;
|
|
269
|
-
if (
|
|
319
|
+
if (isArrayBufferView) {
|
|
270
320
|
gl.bufferSubData(glBindTarget, bufferByteOffset, data, dataOffset, dataByteLength / byteSize);
|
|
271
321
|
} else {
|
|
272
322
|
var subData = new Uint8Array(isArrayBufferView ? data.buffer : data, dataOffset * byteSize, dataByteLength);
|
|
@@ -278,13 +328,16 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
278
328
|
gl.bindBuffer(glBindTarget, null);
|
|
279
329
|
};
|
|
280
330
|
_proto.getData = function getData(data, bufferByteOffset, dataOffset, dataLength) {
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
331
|
+
this.bind();
|
|
332
|
+
this._gl.getBufferSubData(this._glBindTarget, bufferByteOffset, data, dataOffset, dataLength);
|
|
333
|
+
};
|
|
334
|
+
_proto.copyFromBuffer = function copyFromBuffer(srcBuffer, srcByteOffset, dstByteOffset, byteLength) {
|
|
335
|
+
var gl = this._gl;
|
|
336
|
+
gl.bindBuffer(gl.COPY_READ_BUFFER, srcBuffer._glBuffer);
|
|
337
|
+
gl.bindBuffer(gl.COPY_WRITE_BUFFER, this._glBuffer);
|
|
338
|
+
gl.copyBufferSubData(gl.COPY_READ_BUFFER, gl.COPY_WRITE_BUFFER, srcByteOffset, dstByteOffset, byteLength);
|
|
339
|
+
gl.bindBuffer(gl.COPY_READ_BUFFER, null);
|
|
340
|
+
gl.bindBuffer(gl.COPY_WRITE_BUFFER, null);
|
|
288
341
|
};
|
|
289
342
|
_proto.destroy = function destroy() {
|
|
290
343
|
this._gl.deleteBuffer(this._glBuffer);
|
|
@@ -311,7 +364,6 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
311
364
|
this._rhi = rhi;
|
|
312
365
|
this.capabilityList = new Map();
|
|
313
366
|
this._init();
|
|
314
|
-
this._compatibleAllInterface();
|
|
315
367
|
}
|
|
316
368
|
var _proto = GLCapability.prototype;
|
|
317
369
|
/**
|
|
@@ -327,9 +379,9 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
327
379
|
RGB_ETC1_WEBGL = GLCompressedTextureInternalFormat.RGB_ETC1_WEBGL, // etc
|
|
328
380
|
R11_EAC = GLCompressedTextureInternalFormat.R11_EAC, SRGB8_ALPHA8_ETC2_EAC = GLCompressedTextureInternalFormat.SRGB8_ALPHA8_ETC2_EAC, // pvrtc
|
|
329
381
|
RGB_PVRTC_4BPPV1_IMG = GLCompressedTextureInternalFormat.RGB_PVRTC_4BPPV1_IMG, RGBA_PVRTC_2BPPV1_IMG = GLCompressedTextureInternalFormat.RGBA_PVRTC_2BPPV1_IMG, // s3tc
|
|
330
|
-
RGB_S3TC_DXT1_EXT = GLCompressedTextureInternalFormat.RGB_S3TC_DXT1_EXT, RGBA_S3TC_DXT5_EXT = GLCompressedTextureInternalFormat.RGBA_S3TC_DXT5_EXT, // bptc
|
|
382
|
+
RGB_S3TC_DXT1_EXT = GLCompressedTextureInternalFormat.RGB_S3TC_DXT1_EXT, RGBA_S3TC_DXT5_EXT = GLCompressedTextureInternalFormat.RGBA_S3TC_DXT5_EXT, SRGB_S3TC_DXT1_EXT = GLCompressedTextureInternalFormat.SRGB_S3TC_DXT1_EXT, SRGB_ALPHA_S3TC_DXT5_EXT = GLCompressedTextureInternalFormat.SRGB_ALPHA_S3TC_DXT5_EXT, // bptc
|
|
331
383
|
RGBA_BPTC_UNORM_EXT = GLCompressedTextureInternalFormat.RGBA_BPTC_UNORM_EXT, RGB_BPTC_UNSIGNED_FLOAT_EXT = GLCompressedTextureInternalFormat.RGB_BPTC_UNSIGNED_FLOAT_EXT;
|
|
332
|
-
if (internalType >= RGBA_ASTC_4X4_KHR &&
|
|
384
|
+
if (internalType >= RGBA_ASTC_4X4_KHR && internalType <= RGBA_ASTC_12X12_KHR || internalType >= SRGB8_ALPHA8_ASTC_4X4_KHR && internalType <= SRGB8_ALPHA8_ASTC_12X12_KHR) {
|
|
333
385
|
return this.canIUse(GLCapabilityType.astc);
|
|
334
386
|
} else if (internalType === RGB_ETC1_WEBGL) {
|
|
335
387
|
return this.canIUse(GLCapabilityType.etc1);
|
|
@@ -339,36 +391,88 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
339
391
|
return this.canIUse(GLCapabilityType.pvrtc);
|
|
340
392
|
} else if (internalType >= RGB_S3TC_DXT1_EXT && internalType <= RGBA_S3TC_DXT5_EXT) {
|
|
341
393
|
return this.canIUse(GLCapabilityType.s3tc);
|
|
394
|
+
} else if (internalType >= SRGB_S3TC_DXT1_EXT && internalType <= SRGB_ALPHA_S3TC_DXT5_EXT) {
|
|
395
|
+
return this.canIUse(GLCapabilityType.s3tc_srgb);
|
|
342
396
|
} else if (internalType >= RGBA_BPTC_UNORM_EXT && internalType <= RGB_BPTC_UNSIGNED_FLOAT_EXT) {
|
|
343
397
|
return this.canIUse(GLCapabilityType.bptc);
|
|
344
398
|
}
|
|
345
399
|
return false;
|
|
346
400
|
};
|
|
347
401
|
/**
|
|
402
|
+
* Check whether the given texture format is supported.
|
|
403
|
+
*/ _proto.supportsTextureFormat = function supportsTextureFormat(format) {
|
|
404
|
+
switch(format){
|
|
405
|
+
case TextureFormat.BC1:
|
|
406
|
+
case TextureFormat.BC3:
|
|
407
|
+
return this.canIUse(GLCapabilityType.s3tc);
|
|
408
|
+
case TextureFormat.BC7:
|
|
409
|
+
case TextureFormat.BC6H:
|
|
410
|
+
return this.canIUse(GLCapabilityType.bptc);
|
|
411
|
+
case TextureFormat.ETC1_RGB:
|
|
412
|
+
return this.canIUse(GLCapabilityType.etc1);
|
|
413
|
+
case TextureFormat.ETC2_RGB:
|
|
414
|
+
case TextureFormat.ETC2_RGBA5:
|
|
415
|
+
case TextureFormat.ETC2_RGBA8:
|
|
416
|
+
return this.canIUse(GLCapabilityType.etc);
|
|
417
|
+
case TextureFormat.PVRTC_RGB2:
|
|
418
|
+
case TextureFormat.PVRTC_RGBA2:
|
|
419
|
+
case TextureFormat.PVRTC_RGB4:
|
|
420
|
+
case TextureFormat.PVRTC_RGBA4:
|
|
421
|
+
return this.canIUse(GLCapabilityType.pvrtc);
|
|
422
|
+
case TextureFormat.ASTC_4x4:
|
|
423
|
+
case TextureFormat.ASTC_5x5:
|
|
424
|
+
case TextureFormat.ASTC_6x6:
|
|
425
|
+
case TextureFormat.ASTC_8x8:
|
|
426
|
+
case TextureFormat.ASTC_10x10:
|
|
427
|
+
case TextureFormat.ASTC_12x12:
|
|
428
|
+
return this.canIUse(GLCapabilityType.astc);
|
|
429
|
+
case TextureFormat.R8G8B8:
|
|
430
|
+
case TextureFormat.R8G8B8A8:
|
|
431
|
+
case TextureFormat.R4G4B4A4:
|
|
432
|
+
case TextureFormat.R5G5B5A1:
|
|
433
|
+
case TextureFormat.R5G6B5:
|
|
434
|
+
case TextureFormat.R16G16B16A16:
|
|
435
|
+
case TextureFormat.R32G32B32A32:
|
|
436
|
+
case TextureFormat.R32G32B32A32_UInt:
|
|
437
|
+
case TextureFormat.R11G11B10_UFloat:
|
|
438
|
+
case TextureFormat.R8:
|
|
439
|
+
case TextureFormat.R8G8:
|
|
440
|
+
case TextureFormat.Depth:
|
|
441
|
+
case TextureFormat.DepthStencil:
|
|
442
|
+
case TextureFormat.Depth16:
|
|
443
|
+
case TextureFormat.Depth24:
|
|
444
|
+
case TextureFormat.Depth32:
|
|
445
|
+
case TextureFormat.Depth24Stencil8:
|
|
446
|
+
case TextureFormat.Depth32Stencil8:
|
|
447
|
+
return true;
|
|
448
|
+
default:
|
|
449
|
+
return false;
|
|
450
|
+
}
|
|
451
|
+
};
|
|
452
|
+
/**
|
|
453
|
+
* Check whether the given texture format can be rendered to as a color attachment.
|
|
454
|
+
*/ _proto.supportsRenderTargetColorFormat = function supportsRenderTargetColorFormat(format) {
|
|
455
|
+
switch(format){
|
|
456
|
+
case TextureFormat.R16G16B16A16:
|
|
457
|
+
return this.canIUse(GLCapabilityType.colorBufferHalfFloat);
|
|
458
|
+
case TextureFormat.R32G32B32A32:
|
|
459
|
+
return this.canIUse(GLCapabilityType.colorBufferFloat);
|
|
460
|
+
case TextureFormat.R11G11B10_UFloat:
|
|
461
|
+
return this.canIUse(GLCapabilityType.colorBufferFloat);
|
|
462
|
+
default:
|
|
463
|
+
return this.supportsTextureFormat(format);
|
|
464
|
+
}
|
|
465
|
+
};
|
|
466
|
+
/**
|
|
348
467
|
* Init capabilities.
|
|
349
468
|
*/ _proto._init = function _init() {
|
|
350
469
|
var cap = this.capabilityList;
|
|
351
|
-
var isWebGL2 = this.rhi.isWebGL2;
|
|
352
470
|
var requireExtension = this.rhi.requireExtension.bind(this.rhi);
|
|
353
|
-
var
|
|
354
|
-
cap.set(shaderVertexID, isWebGL2);
|
|
355
|
-
cap.set(standardDerivatives, isWebGL2 || !!requireExtension(standardDerivatives));
|
|
356
|
-
cap.set(shaderTextureLod, isWebGL2 || !!requireExtension(shaderTextureLod));
|
|
357
|
-
cap.set(elementIndexUint, isWebGL2 || !!requireExtension(elementIndexUint));
|
|
358
|
-
cap.set(depthTexture, isWebGL2 || !!requireExtension(depthTexture));
|
|
359
|
-
cap.set(vertexArrayObject, isWebGL2 || !!requireExtension(vertexArrayObject));
|
|
360
|
-
cap.set(instancedArrays, isWebGL2 || !!requireExtension(instancedArrays));
|
|
361
|
-
cap.set(multipleSample, isWebGL2);
|
|
362
|
-
cap.set(drawBuffers, isWebGL2 || !!requireExtension(drawBuffers));
|
|
363
|
-
cap.set(blendMinMax, isWebGL2 || !!requireExtension(blendMinMax));
|
|
364
|
-
cap.set(textureFloat, isWebGL2 || !!requireExtension(textureFloat));
|
|
365
|
-
cap.set(textureHalfFloat, isWebGL2 || !!requireExtension(textureHalfFloat));
|
|
471
|
+
var astc = GLCapabilityType.astc, astc_webkit = GLCapabilityType.astc_webkit, astc_hdr = GLCapabilityType.astc_hdr, etc = GLCapabilityType.etc, etc_webkit = GLCapabilityType.etc_webkit, etc1 = GLCapabilityType.etc1, etc1_webkit = GLCapabilityType.etc1_webkit, pvrtc = GLCapabilityType.pvrtc, pvrtc_webkit = GLCapabilityType.pvrtc_webkit, s3tc = GLCapabilityType.s3tc, s3tc_webkit = GLCapabilityType.s3tc_webkit, bptc = GLCapabilityType.bptc, s3tc_srgb = GLCapabilityType.s3tc_srgb, textureFloatLinear = GLCapabilityType.textureFloatLinear, colorBufferFloat = GLCapabilityType.colorBufferFloat, colorBufferHalfFloat = GLCapabilityType.colorBufferHalfFloat, textureFilterAnisotropic = GLCapabilityType.textureFilterAnisotropic;
|
|
366
472
|
cap.set(textureFloatLinear, !!requireExtension(textureFloatLinear));
|
|
367
|
-
cap.set(
|
|
368
|
-
cap.set(
|
|
369
|
-
cap.set(colorBufferHalfFloat, isWebGL2 && !!requireExtension(colorBufferFloat) || !!requireExtension(colorBufferHalfFloat));
|
|
473
|
+
cap.set(colorBufferFloat, !!requireExtension(colorBufferFloat));
|
|
474
|
+
cap.set(colorBufferHalfFloat, !!requireExtension(colorBufferFloat) || !!requireExtension(colorBufferHalfFloat));
|
|
370
475
|
cap.set(textureFilterAnisotropic, !!requireExtension(textureFilterAnisotropic));
|
|
371
|
-
cap.set(fragDepth, isWebGL2 || !!requireExtension(fragDepth));
|
|
372
476
|
cap.set(etc, !!(requireExtension(etc) || requireExtension(etc_webkit)));
|
|
373
477
|
cap.set(etc1, !!(requireExtension(etc1) || requireExtension(etc1_webkit)));
|
|
374
478
|
cap.set(pvrtc, !!(requireExtension(pvrtc) || requireExtension(pvrtc_webkit)));
|
|
@@ -377,86 +481,7 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
377
481
|
cap.set(bptc, !!requireExtension(bptc));
|
|
378
482
|
var astcExtension = requireExtension(astc) || requireExtension(astc_webkit);
|
|
379
483
|
cap.set(astc, !!astcExtension);
|
|
380
|
-
cap.set(astc_hdr,
|
|
381
|
-
cap.set(sRGB, isWebGL2 || !!requireExtension(sRGB));
|
|
382
|
-
};
|
|
383
|
-
/**
|
|
384
|
-
* If there are extensions that can supplement this ability, smooth out the difference.
|
|
385
|
-
* @example
|
|
386
|
-
* compatible(GLCapabilityType.depthTexture,{
|
|
387
|
-
* UNSIGNED_INT_24_8: "UNSIGNED_INT_24_8_WEBGL"
|
|
388
|
-
* })
|
|
389
|
-
* gl.UNSIGNED_INT_24_8 = ext.UNSIGNED_INT_24_8_WEBGL
|
|
390
|
-
*/ _proto._compatibleInterface = function _compatibleInterface(capabilityType, flatItem) {
|
|
391
|
-
var rhi = this.rhi;
|
|
392
|
-
var gl = rhi.gl;
|
|
393
|
-
var ext = null;
|
|
394
|
-
if (ext = rhi.requireExtension(capabilityType)) {
|
|
395
|
-
for(var glKey in flatItem){
|
|
396
|
-
var extensionKey = flatItem[glKey];
|
|
397
|
-
var extensionVal = ext[extensionKey];
|
|
398
|
-
// Mini game hack the native function,use “.bind” to smooth out if is “Funcion”.
|
|
399
|
-
if (extensionVal == null ? void 0 : extensionVal.bind) {
|
|
400
|
-
gl[glKey] = extensionVal.bind(ext);
|
|
401
|
-
} else {
|
|
402
|
-
gl[glKey] = extensionVal;
|
|
403
|
-
}
|
|
404
|
-
}
|
|
405
|
-
}
|
|
406
|
-
};
|
|
407
|
-
_proto._compatibleAllInterface = function _compatibleAllInterface() {
|
|
408
|
-
var depthTexture = GLCapabilityType.depthTexture, vertexArrayObject = GLCapabilityType.vertexArrayObject, instancedArrays = GLCapabilityType.instancedArrays, drawBuffers = GLCapabilityType.drawBuffers, textureFilterAnisotropic = GLCapabilityType.textureFilterAnisotropic, textureHalfFloat = GLCapabilityType.textureHalfFloat, colorBufferHalfFloat = GLCapabilityType.colorBufferHalfFloat, WEBGL_colorBufferFloat = GLCapabilityType.WEBGL_colorBufferFloat, blendMinMax = GLCapabilityType.blendMinMax, sRGB = GLCapabilityType.sRGB;
|
|
409
|
-
var isWebGL2 = this.rhi.isWebGL2;
|
|
410
|
-
if (!isWebGL2) {
|
|
411
|
-
this._compatibleInterface(blendMinMax, {
|
|
412
|
-
MIN: "MIN_EXT",
|
|
413
|
-
MAX: "MAX_EXT"
|
|
414
|
-
});
|
|
415
|
-
this._compatibleInterface(depthTexture, {
|
|
416
|
-
UNSIGNED_INT_24_8: "UNSIGNED_INT_24_8_WEBGL"
|
|
417
|
-
});
|
|
418
|
-
this._compatibleInterface(vertexArrayObject, {
|
|
419
|
-
createVertexArray: "createVertexArrayOES",
|
|
420
|
-
deleteVertexArray: "deleteVertexArrayOES",
|
|
421
|
-
isVertexArray: "isVertexArrayOES",
|
|
422
|
-
bindVertexArray: "bindVertexArrayOES"
|
|
423
|
-
});
|
|
424
|
-
this._compatibleInterface(instancedArrays, {
|
|
425
|
-
drawArraysInstanced: "drawArraysInstancedANGLE",
|
|
426
|
-
drawElementsInstanced: "drawElementsInstancedANGLE",
|
|
427
|
-
vertexAttribDivisor: "vertexAttribDivisorANGLE"
|
|
428
|
-
});
|
|
429
|
-
this._compatibleInterface(drawBuffers, {
|
|
430
|
-
MAX_DRAW_BUFFERS: "MAX_DRAW_BUFFERS_WEBGL"
|
|
431
|
-
});
|
|
432
|
-
var items = {};
|
|
433
|
-
if (this.canIUse(GLCapabilityType.drawBuffers)) {
|
|
434
|
-
var maxDrawBuffers = this.maxDrawBuffers;
|
|
435
|
-
for(var i = 0; i < maxDrawBuffers; i++){
|
|
436
|
-
i != 0 && (items["COLOR_ATTACHMENT" + i] = "COLOR_ATTACHMENT" + i + "_WEBGL");
|
|
437
|
-
items["DRAW_BUFFER" + i] = "DRAW_BUFFER" + i + "_WEBGL";
|
|
438
|
-
}
|
|
439
|
-
this._compatibleInterface(drawBuffers, _extends({
|
|
440
|
-
drawBuffers: "drawBuffersWEBGL"
|
|
441
|
-
}, items));
|
|
442
|
-
}
|
|
443
|
-
this._compatibleInterface(textureHalfFloat, {
|
|
444
|
-
HALF_FLOAT: "HALF_FLOAT_OES"
|
|
445
|
-
});
|
|
446
|
-
this._compatibleInterface(colorBufferHalfFloat, {
|
|
447
|
-
RGBA16F: "RBGA16F_EXT"
|
|
448
|
-
});
|
|
449
|
-
this._compatibleInterface(WEBGL_colorBufferFloat, {
|
|
450
|
-
RGBA32F: "RBGA32F_EXT"
|
|
451
|
-
});
|
|
452
|
-
this._compatibleInterface(sRGB, {
|
|
453
|
-
SRGB8: "SRGB_EXT",
|
|
454
|
-
SRGB8_ALPHA8: "SRGB_ALPHA_EXT"
|
|
455
|
-
});
|
|
456
|
-
}
|
|
457
|
-
this._compatibleInterface(textureFilterAnisotropic, {
|
|
458
|
-
TEXTURE_MAX_ANISOTROPY_EXT: "TEXTURE_MAX_ANISOTROPY_EXT"
|
|
459
|
-
});
|
|
484
|
+
cap.set(astc_hdr, typeof (astcExtension == null ? void 0 : astcExtension.getSupportedProfiles) === "function" && astcExtension.getSupportedProfiles().includes("hdr"));
|
|
460
485
|
};
|
|
461
486
|
_create_class(GLCapability, [
|
|
462
487
|
{
|
|
@@ -466,28 +491,16 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
466
491
|
}
|
|
467
492
|
},
|
|
468
493
|
{
|
|
469
|
-
key: "
|
|
494
|
+
key: "maxVertexUniformVectors",
|
|
470
495
|
get: function get() {
|
|
471
|
-
return this.
|
|
472
|
-
}
|
|
473
|
-
},
|
|
474
|
-
{
|
|
475
|
-
key: "canIUseMoreJoints",
|
|
476
|
-
get: /**
|
|
477
|
-
* Whether can use more joints.
|
|
478
|
-
*/ function get() {
|
|
479
|
-
return this.canIUse(GLCapabilityType.textureFloat) && this.rhi.renderStates.getParameter(this.rhi.gl.MAX_VERTEX_TEXTURE_IMAGE_UNITS) > 0;
|
|
496
|
+
return this.rhi.renderStates.getParameter(this.rhi.gl.MAX_VERTEX_UNIFORM_VECTORS);
|
|
480
497
|
}
|
|
481
498
|
},
|
|
482
499
|
{
|
|
483
500
|
key: "maxDrawBuffers",
|
|
484
501
|
get: function get() {
|
|
485
502
|
if (!this._maxDrawBuffers) {
|
|
486
|
-
|
|
487
|
-
this._maxDrawBuffers = this._rhi.gl.getParameter(this._rhi.gl.MAX_DRAW_BUFFERS);
|
|
488
|
-
} else {
|
|
489
|
-
this._maxDrawBuffers = 1;
|
|
490
|
-
}
|
|
503
|
+
this._maxDrawBuffers = this._rhi.gl.getParameter(this._rhi.gl.MAX_DRAW_BUFFERS);
|
|
491
504
|
}
|
|
492
505
|
return this._maxDrawBuffers;
|
|
493
506
|
}
|
|
@@ -511,19 +524,11 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
511
524
|
*/ function get() {
|
|
512
525
|
if (!this._maxAntiAliasing) {
|
|
513
526
|
var gl = this._rhi.gl;
|
|
514
|
-
|
|
515
|
-
this._maxAntiAliasing = canMSAA ? gl.getParameter(gl.MAX_SAMPLES) : 1;
|
|
527
|
+
this._maxAntiAliasing = gl.getParameter(gl.MAX_SAMPLES);
|
|
516
528
|
}
|
|
517
529
|
return this._maxAntiAliasing;
|
|
518
530
|
}
|
|
519
531
|
},
|
|
520
|
-
{
|
|
521
|
-
key: "isFragmentHighPrecision",
|
|
522
|
-
get: function get() {
|
|
523
|
-
var gl = this._rhi.gl;
|
|
524
|
-
return gl.getShaderPrecisionFormat(gl.FRAGMENT_SHADER, gl.HIGH_FLOAT).precision !== 0;
|
|
525
|
-
}
|
|
526
|
-
},
|
|
527
532
|
{
|
|
528
533
|
key: "rhi",
|
|
529
534
|
get: function get() {
|
|
@@ -555,9 +560,6 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
555
560
|
}();
|
|
556
561
|
|
|
557
562
|
/**
|
|
558
|
-
* Improvement of VAO:
|
|
559
|
-
* 1) WebGL2.0 must support VAO, almost all devices support vao extensions in webgl1.0, we can use PollyFill,only keep VAO mode.
|
|
560
|
-
*/ /**
|
|
561
563
|
* @internal
|
|
562
564
|
* GL platform primitive.
|
|
563
565
|
*/ var GLPrimitive = /*#__PURE__*/ function() {
|
|
@@ -565,8 +567,6 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
565
567
|
this._attribLocArray = [];
|
|
566
568
|
this._vaoMap = new Map();
|
|
567
569
|
this._primitive = primitive;
|
|
568
|
-
this._canUseInstancedArrays = rhi.canIUse(GLCapabilityType.instancedArrays);
|
|
569
|
-
this._isSupportVAO = rhi.canIUse(GLCapabilityType.vertexArrayObject);
|
|
570
570
|
this._gl = rhi.gl;
|
|
571
571
|
}
|
|
572
572
|
var _proto = GLPrimitive.prototype;
|
|
@@ -575,7 +575,7 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
575
575
|
*/ _proto.draw = function draw(shaderProgram, subMesh) {
|
|
576
576
|
var gl = this._gl;
|
|
577
577
|
var primitive = this._primitive;
|
|
578
|
-
var useVao =
|
|
578
|
+
var useVao = primitive.enableVAO;
|
|
579
579
|
if (useVao) {
|
|
580
580
|
if (primitive._bufferStructChanged) {
|
|
581
581
|
this._clearVAO();
|
|
@@ -604,21 +604,17 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
604
604
|
gl.drawArrays(topology, start, count);
|
|
605
605
|
}
|
|
606
606
|
} else {
|
|
607
|
-
if (
|
|
608
|
-
if (
|
|
609
|
-
|
|
610
|
-
gl.drawElementsInstanced(topology, count, _glIndexType, start * _glIndexByteCount, instanceCount);
|
|
611
|
-
} else {
|
|
612
|
-
var _glBuffer1 = indexBufferBinding.buffer._platformBuffer._glBuffer;
|
|
613
|
-
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, _glBuffer1);
|
|
614
|
-
gl.drawElementsInstanced(topology, count, _glIndexType, start * _glIndexByteCount, instanceCount);
|
|
615
|
-
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, null);
|
|
616
|
-
}
|
|
607
|
+
if (indexBufferBinding) {
|
|
608
|
+
if (useVao) {
|
|
609
|
+
gl.drawElementsInstanced(topology, count, _glIndexType, start * _glIndexByteCount, instanceCount);
|
|
617
610
|
} else {
|
|
618
|
-
|
|
611
|
+
var _glBuffer1 = indexBufferBinding.buffer._platformBuffer._glBuffer;
|
|
612
|
+
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, _glBuffer1);
|
|
613
|
+
gl.drawElementsInstanced(topology, count, _glIndexType, start * _glIndexByteCount, instanceCount);
|
|
614
|
+
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, null);
|
|
619
615
|
}
|
|
620
616
|
} else {
|
|
621
|
-
|
|
617
|
+
gl.drawArraysInstanced(topology, start, count, instanceCount);
|
|
622
618
|
}
|
|
623
619
|
}
|
|
624
620
|
// Unbind
|
|
@@ -629,7 +625,7 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
629
625
|
}
|
|
630
626
|
};
|
|
631
627
|
_proto.destroy = function destroy() {
|
|
632
|
-
this.
|
|
628
|
+
this._clearVAO();
|
|
633
629
|
};
|
|
634
630
|
/**
|
|
635
631
|
* Bind buffer and attribute.
|
|
@@ -657,9 +653,7 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
657
653
|
gl.enableVertexAttribArray(loc);
|
|
658
654
|
var elementInfo = element._formatMetaInfo;
|
|
659
655
|
gl.vertexAttribPointer(loc, elementInfo.size, elementInfo.type, elementInfo.normalized, stride, element.offset);
|
|
660
|
-
|
|
661
|
-
gl.vertexAttribDivisor(loc, element.instanceStepRate);
|
|
662
|
-
}
|
|
656
|
+
gl.vertexAttribDivisor(loc, element.instanceStepRate);
|
|
663
657
|
this._attribLocArray.push(loc);
|
|
664
658
|
} else {
|
|
665
659
|
Logger.warn("vertex attribute not found: " + name);
|
|
@@ -707,7 +701,6 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
707
701
|
/** cache */ this._parameters[gl.MAX_COMBINED_TEXTURE_IMAGE_UNITS] = gl.getParameter(gl.MAX_COMBINED_TEXTURE_IMAGE_UNITS);
|
|
708
702
|
this._parameters[gl.MAX_VERTEX_UNIFORM_VECTORS] = gl.getParameter(gl.MAX_VERTEX_UNIFORM_VECTORS);
|
|
709
703
|
this._parameters[gl.MAX_VERTEX_ATTRIBS] = gl.getParameter(gl.MAX_VERTEX_ATTRIBS);
|
|
710
|
-
this._parameters[gl.MAX_VERTEX_TEXTURE_IMAGE_UNITS] = gl.getParameter(gl.MAX_VERTEX_TEXTURE_IMAGE_UNITS);
|
|
711
704
|
this._parameters[gl.MAX_TEXTURE_SIZE] = gl.getParameter(gl.MAX_TEXTURE_SIZE);
|
|
712
705
|
// init blend state same as BlendState default value.
|
|
713
706
|
gl.blendFuncSeparate(gl.ONE, gl.ZERO, gl.ONE, gl.ZERO);
|
|
@@ -748,7 +741,6 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
748
741
|
this._texture = texture;
|
|
749
742
|
this._rhi = rhi;
|
|
750
743
|
this._gl = rhi.gl;
|
|
751
|
-
this._isWebGL2 = rhi.isWebGL2;
|
|
752
744
|
this._target = target;
|
|
753
745
|
this._glTexture = this._gl.createTexture();
|
|
754
746
|
}
|
|
@@ -771,9 +763,8 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
771
763
|
* Generate multi-level textures based on the 0th level data.
|
|
772
764
|
*/ _proto.generateMipmaps = function generateMipmaps() {
|
|
773
765
|
var texture = this._texture;
|
|
774
|
-
//@ts-ignore
|
|
775
766
|
var mipmap = texture._mipmap;
|
|
776
|
-
if (!TextureUtils.supportGenerateMipmaps(texture.format, mipmap, texture.isSRGBColorSpace
|
|
767
|
+
if (!TextureUtils.supportGenerateMipmaps(texture.format, mipmap, texture.isSRGBColorSpace)) {
|
|
777
768
|
Logger.warn("Auto-generating mipmaps for sRGB textures is only supported in [WebGL2 + R8G8B8A8], you must generate mipmaps manually.");
|
|
778
769
|
return;
|
|
779
770
|
}
|
|
@@ -790,12 +781,10 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
790
781
|
* Pre-development mipmapping GPU memory.
|
|
791
782
|
*/ _proto._init = function _init(isCube) {
|
|
792
783
|
var gl = this._gl;
|
|
793
|
-
var isWebGL2 = this._isWebGL2;
|
|
794
784
|
var _this__formatDetail = this._formatDetail, internalFormat = _this__formatDetail.internalFormat, baseFormat = _this__formatDetail.baseFormat, dataType = _this__formatDetail.dataType;
|
|
795
|
-
// @ts-ignore
|
|
796
785
|
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;
|
|
797
786
|
this._bind();
|
|
798
|
-
if (
|
|
787
|
+
if (usage !== TextureUsage.Dynamic) {
|
|
799
788
|
gl.texStorage2D(this._target, mipmapCount, internalFormat, width, height);
|
|
800
789
|
} else {
|
|
801
790
|
if (!isCube) {
|
|
@@ -831,17 +820,12 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
831
820
|
var gl = this._gl;
|
|
832
821
|
var _this__formatDetail = this._formatDetail, baseFormat = _this__formatDetail.baseFormat, dataType = _this__formatDetail.dataType, readFormat = _this__formatDetail.readFormat, alignment = _this__formatDetail.alignment;
|
|
833
822
|
gl.bindFramebuffer(gl.FRAMEBUFFER, this._getReadFrameBuffer());
|
|
834
|
-
if (mipLevel > 0 && !this._isWebGL2) {
|
|
835
|
-
mipLevel = 0;
|
|
836
|
-
Logger.error("mipLevel only take effect in WebGL2.0");
|
|
837
|
-
}
|
|
838
823
|
if (face != null) {
|
|
839
824
|
gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_CUBE_MAP_POSITIVE_X + face, this._glTexture, mipLevel);
|
|
840
825
|
} else {
|
|
841
826
|
gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, this._glTexture, mipLevel);
|
|
842
827
|
}
|
|
843
828
|
gl.pixelStorei(gl.PACK_ALIGNMENT, alignment);
|
|
844
|
-
// Base format is different from read format in webgl1.0 with sRGB
|
|
845
829
|
gl.readPixels(x, y, width, height, readFormat != null ? readFormat : baseFormat, dataType, out);
|
|
846
830
|
gl.bindFramebuffer(gl.FRAMEBUFFER, null);
|
|
847
831
|
};
|
|
@@ -852,8 +836,8 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
852
836
|
}
|
|
853
837
|
return frameBuffer;
|
|
854
838
|
};
|
|
855
|
-
_proto._validate = function _validate(texture
|
|
856
|
-
var format = texture.format
|
|
839
|
+
_proto._validate = function _validate(texture) {
|
|
840
|
+
var format = texture.format;
|
|
857
841
|
// Validate sRGB format
|
|
858
842
|
// @ts-ignore
|
|
859
843
|
var isSRGBColorSpace = texture._isSRGBColorSpace;
|
|
@@ -862,25 +846,10 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
862
846
|
// @ts-ignore
|
|
863
847
|
texture._isSRGBColorSpace = false;
|
|
864
848
|
}
|
|
865
|
-
var isWebGL2 = rhi.isWebGL2;
|
|
866
|
-
// Validate mipmap
|
|
867
|
-
// @ts-ignore
|
|
868
|
-
var mipmap = texture._mipmap;
|
|
869
|
-
if (mipmap && !TextureUtils.supportMipmaps(width, height, isWebGL2)) {
|
|
870
|
-
Logger.warn("Non-power-2 texture is not supported for mipmap in WebGL1, and has automatically downgraded to non-mipmap");
|
|
871
|
-
/** @ts-ignore */ texture._mipmap = false;
|
|
872
|
-
/** @ts-ignore */ texture._mipmapCount = texture._getMipmapCount();
|
|
873
|
-
}
|
|
874
849
|
};
|
|
875
850
|
_proto._setWrapMode = function _setWrapMode(value, pname) {
|
|
876
851
|
var gl = this._gl;
|
|
877
|
-
var isWebGL2 = this._isWebGL2;
|
|
878
852
|
var target = this._target;
|
|
879
|
-
var _this__texture = this._texture, width = _this__texture.width, height = _this__texture.height;
|
|
880
|
-
if (!isWebGL2 && value !== TextureWrapMode.Clamp && (!MathUtil.isPowerOf2(width) || !MathUtil.isPowerOf2(height))) {
|
|
881
|
-
Logger.warn("non-power-2 texture is not supported for REPEAT or MIRRORED_REPEAT in WebGL1,and has automatically downgraded to CLAMP_TO_EDGE");
|
|
882
|
-
value = TextureWrapMode.Clamp;
|
|
883
|
-
}
|
|
884
853
|
switch(value){
|
|
885
854
|
case TextureWrapMode.Clamp:
|
|
886
855
|
gl.texParameteri(target, pname, gl.CLAMP_TO_EDGE);
|
|
@@ -896,21 +865,21 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
896
865
|
/**
|
|
897
866
|
* Get more texture info from TextureFormat.
|
|
898
867
|
* @internal
|
|
899
|
-
*/ GLTexture._getFormatDetail = function _getFormatDetail(format, isSRGBColorSpace, gl
|
|
868
|
+
*/ GLTexture._getFormatDetail = function _getFormatDetail(format, isSRGBColorSpace, gl) {
|
|
900
869
|
switch(format){
|
|
901
870
|
case TextureFormat.R8G8B8:
|
|
902
871
|
return {
|
|
903
|
-
internalFormat: isSRGBColorSpace ? gl.SRGB8 :
|
|
904
|
-
baseFormat:
|
|
905
|
-
readFormat: gl.
|
|
872
|
+
internalFormat: isSRGBColorSpace ? gl.SRGB8 : gl.RGB8,
|
|
873
|
+
baseFormat: gl.RGB,
|
|
874
|
+
readFormat: gl.RGBA,
|
|
906
875
|
dataType: gl.UNSIGNED_BYTE,
|
|
907
876
|
isCompressed: false,
|
|
908
877
|
alignment: 1
|
|
909
878
|
};
|
|
910
879
|
case TextureFormat.R8G8B8A8:
|
|
911
880
|
return {
|
|
912
|
-
internalFormat: isSRGBColorSpace ? gl.SRGB8_ALPHA8 :
|
|
913
|
-
baseFormat:
|
|
881
|
+
internalFormat: isSRGBColorSpace ? gl.SRGB8_ALPHA8 : gl.RGBA8,
|
|
882
|
+
baseFormat: gl.RGBA,
|
|
914
883
|
readFormat: gl.RGBA,
|
|
915
884
|
dataType: gl.UNSIGNED_BYTE,
|
|
916
885
|
isCompressed: false,
|
|
@@ -918,7 +887,7 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
918
887
|
};
|
|
919
888
|
case TextureFormat.R4G4B4A4:
|
|
920
889
|
return {
|
|
921
|
-
internalFormat:
|
|
890
|
+
internalFormat: gl.RGBA4,
|
|
922
891
|
baseFormat: gl.RGBA,
|
|
923
892
|
dataType: gl.UNSIGNED_SHORT_4_4_4_4,
|
|
924
893
|
isCompressed: false,
|
|
@@ -926,7 +895,7 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
926
895
|
};
|
|
927
896
|
case TextureFormat.R5G5B5A1:
|
|
928
897
|
return {
|
|
929
|
-
internalFormat:
|
|
898
|
+
internalFormat: gl.RGB5_A1,
|
|
930
899
|
baseFormat: gl.RGBA,
|
|
931
900
|
dataType: gl.UNSIGNED_SHORT_5_5_5_1,
|
|
932
901
|
isCompressed: false,
|
|
@@ -934,31 +903,15 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
934
903
|
};
|
|
935
904
|
case TextureFormat.R5G6B5:
|
|
936
905
|
return {
|
|
937
|
-
internalFormat:
|
|
906
|
+
internalFormat: gl.RGB565,
|
|
938
907
|
baseFormat: gl.RGB,
|
|
939
908
|
dataType: gl.UNSIGNED_SHORT_5_6_5,
|
|
940
909
|
isCompressed: false,
|
|
941
910
|
alignment: 2
|
|
942
911
|
};
|
|
943
|
-
case TextureFormat.Alpha8:
|
|
944
|
-
return {
|
|
945
|
-
internalFormat: gl.ALPHA,
|
|
946
|
-
baseFormat: gl.ALPHA,
|
|
947
|
-
dataType: gl.UNSIGNED_BYTE,
|
|
948
|
-
isCompressed: false,
|
|
949
|
-
alignment: 1
|
|
950
|
-
};
|
|
951
|
-
case TextureFormat.LuminanceAlpha:
|
|
952
|
-
return {
|
|
953
|
-
internalFormat: gl.LUMINANCE_ALPHA,
|
|
954
|
-
baseFormat: gl.LUMINANCE_ALPHA,
|
|
955
|
-
dataType: gl.UNSIGNED_BYTE,
|
|
956
|
-
isCompressed: false,
|
|
957
|
-
alignment: 2
|
|
958
|
-
};
|
|
959
912
|
case TextureFormat.R16G16B16A16:
|
|
960
913
|
return {
|
|
961
|
-
internalFormat:
|
|
914
|
+
internalFormat: gl.RGBA16F,
|
|
962
915
|
baseFormat: gl.RGBA,
|
|
963
916
|
dataType: gl.HALF_FLOAT,
|
|
964
917
|
isCompressed: false,
|
|
@@ -966,22 +919,21 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
966
919
|
};
|
|
967
920
|
case TextureFormat.R32G32B32A32:
|
|
968
921
|
return {
|
|
969
|
-
internalFormat:
|
|
922
|
+
internalFormat: gl.RGBA32F,
|
|
970
923
|
baseFormat: gl.RGBA,
|
|
971
924
|
dataType: gl.FLOAT,
|
|
972
925
|
isCompressed: false,
|
|
973
926
|
alignment: 8
|
|
974
927
|
};
|
|
975
|
-
// Only WebGL2 support
|
|
976
928
|
case TextureFormat.R11G11B10_UFloat:
|
|
977
929
|
return {
|
|
978
930
|
internalFormat: gl.R11F_G11F_B10F,
|
|
979
931
|
baseFormat: gl.RGB,
|
|
932
|
+
readFormat: gl.RGBA,
|
|
980
933
|
dataType: gl.FLOAT,
|
|
981
934
|
isCompressed: false,
|
|
982
935
|
alignment: 4
|
|
983
936
|
};
|
|
984
|
-
// Only WebGL2 support
|
|
985
937
|
case TextureFormat.R32G32B32A32_UInt:
|
|
986
938
|
return {
|
|
987
939
|
internalFormat: gl.RGBA32UI,
|
|
@@ -990,7 +942,6 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
990
942
|
isCompressed: false,
|
|
991
943
|
alignment: 8
|
|
992
944
|
};
|
|
993
|
-
// Only WebGL2 support
|
|
994
945
|
case TextureFormat.R8:
|
|
995
946
|
return {
|
|
996
947
|
internalFormat: gl.R8,
|
|
@@ -999,7 +950,6 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
999
950
|
isCompressed: false,
|
|
1000
951
|
alignment: 1
|
|
1001
952
|
};
|
|
1002
|
-
// Only WebGL2 support
|
|
1003
953
|
case TextureFormat.R8G8:
|
|
1004
954
|
return {
|
|
1005
955
|
internalFormat: gl.RG8,
|
|
@@ -1040,7 +990,7 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
1040
990
|
};
|
|
1041
991
|
case TextureFormat.ETC2_RGBA5:
|
|
1042
992
|
return {
|
|
1043
|
-
internalFormat: GLCompressedTextureInternalFormat.RGB8_PUNCHTHROUGH_ALPHA1_ETC2,
|
|
993
|
+
internalFormat: isSRGBColorSpace ? GLCompressedTextureInternalFormat.SRGB8_PUNCHTHROUGH_ALPHA1_ETC2 : GLCompressedTextureInternalFormat.RGB8_PUNCHTHROUGH_ALPHA1_ETC2,
|
|
1044
994
|
isCompressed: true
|
|
1045
995
|
};
|
|
1046
996
|
case TextureFormat.ETC2_RGBA8:
|
|
@@ -1075,48 +1025,48 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
1075
1025
|
};
|
|
1076
1026
|
case TextureFormat.ASTC_5x5:
|
|
1077
1027
|
return {
|
|
1078
|
-
internalFormat: GLCompressedTextureInternalFormat.RGBA_ASTC_5X5_KHR,
|
|
1028
|
+
internalFormat: isSRGBColorSpace ? GLCompressedTextureInternalFormat.SRGB8_ALPHA8_ASTC_5X5_KHR : GLCompressedTextureInternalFormat.RGBA_ASTC_5X5_KHR,
|
|
1079
1029
|
isCompressed: true
|
|
1080
1030
|
};
|
|
1081
1031
|
case TextureFormat.ASTC_6x6:
|
|
1082
1032
|
return {
|
|
1083
|
-
internalFormat: GLCompressedTextureInternalFormat.RGBA_ASTC_6X6_KHR,
|
|
1033
|
+
internalFormat: isSRGBColorSpace ? GLCompressedTextureInternalFormat.SRGB8_ALPHA8_ASTC_6X6_KHR : GLCompressedTextureInternalFormat.RGBA_ASTC_6X6_KHR,
|
|
1084
1034
|
isCompressed: true
|
|
1085
1035
|
};
|
|
1086
1036
|
case TextureFormat.ASTC_8x8:
|
|
1087
1037
|
return {
|
|
1088
|
-
internalFormat: GLCompressedTextureInternalFormat.RGBA_ASTC_8X8_KHR,
|
|
1038
|
+
internalFormat: isSRGBColorSpace ? GLCompressedTextureInternalFormat.SRGB8_ALPHA8_ASTC_8X8_KHR : GLCompressedTextureInternalFormat.RGBA_ASTC_8X8_KHR,
|
|
1089
1039
|
isCompressed: true
|
|
1090
1040
|
};
|
|
1091
1041
|
case TextureFormat.ASTC_10x10:
|
|
1092
1042
|
return {
|
|
1093
|
-
internalFormat: GLCompressedTextureInternalFormat.RGBA_ASTC_10X10_KHR,
|
|
1043
|
+
internalFormat: isSRGBColorSpace ? GLCompressedTextureInternalFormat.SRGB8_ALPHA8_ASTC_10X10_KHR : GLCompressedTextureInternalFormat.RGBA_ASTC_10X10_KHR,
|
|
1094
1044
|
isCompressed: true
|
|
1095
1045
|
};
|
|
1096
1046
|
case TextureFormat.ASTC_12x12:
|
|
1097
1047
|
return {
|
|
1098
|
-
internalFormat: GLCompressedTextureInternalFormat.RGBA_ASTC_12X12_KHR,
|
|
1048
|
+
internalFormat: isSRGBColorSpace ? GLCompressedTextureInternalFormat.SRGB8_ALPHA8_ASTC_12X12_KHR : GLCompressedTextureInternalFormat.RGBA_ASTC_12X12_KHR,
|
|
1099
1049
|
isCompressed: true
|
|
1100
1050
|
};
|
|
1101
1051
|
case TextureFormat.Depth:
|
|
1102
1052
|
return {
|
|
1103
|
-
internalFormat:
|
|
1053
|
+
internalFormat: gl.DEPTH_COMPONENT32F,
|
|
1104
1054
|
baseFormat: gl.DEPTH_COMPONENT,
|
|
1105
|
-
dataType:
|
|
1055
|
+
dataType: gl.FLOAT,
|
|
1106
1056
|
isCompressed: false,
|
|
1107
1057
|
attachment: gl.DEPTH_ATTACHMENT
|
|
1108
1058
|
};
|
|
1109
1059
|
case TextureFormat.DepthStencil:
|
|
1110
1060
|
return {
|
|
1111
|
-
internalFormat:
|
|
1061
|
+
internalFormat: gl.DEPTH32F_STENCIL8,
|
|
1112
1062
|
baseFormat: gl.DEPTH_STENCIL,
|
|
1113
|
-
dataType:
|
|
1063
|
+
dataType: gl.FLOAT_32_UNSIGNED_INT_24_8_REV,
|
|
1114
1064
|
isCompressed: false,
|
|
1115
1065
|
attachment: gl.DEPTH_STENCIL_ATTACHMENT
|
|
1116
1066
|
};
|
|
1117
1067
|
case TextureFormat.Depth16:
|
|
1118
1068
|
return {
|
|
1119
|
-
internalFormat:
|
|
1069
|
+
internalFormat: gl.DEPTH_COMPONENT16,
|
|
1120
1070
|
baseFormat: gl.DEPTH_COMPONENT,
|
|
1121
1071
|
dataType: gl.UNSIGNED_SHORT,
|
|
1122
1072
|
isCompressed: false,
|
|
@@ -1124,13 +1074,12 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
1124
1074
|
};
|
|
1125
1075
|
case TextureFormat.Depth24Stencil8:
|
|
1126
1076
|
return {
|
|
1127
|
-
internalFormat:
|
|
1077
|
+
internalFormat: gl.DEPTH24_STENCIL8,
|
|
1128
1078
|
baseFormat: gl.DEPTH_STENCIL,
|
|
1129
1079
|
dataType: gl.UNSIGNED_INT_24_8,
|
|
1130
1080
|
isCompressed: false,
|
|
1131
1081
|
attachment: gl.DEPTH_STENCIL_ATTACHMENT
|
|
1132
1082
|
};
|
|
1133
|
-
// Only WebGL2 support
|
|
1134
1083
|
case TextureFormat.Depth24:
|
|
1135
1084
|
return {
|
|
1136
1085
|
internalFormat: gl.DEPTH_COMPONENT24,
|
|
@@ -1139,7 +1088,6 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
1139
1088
|
isCompressed: false,
|
|
1140
1089
|
attachment: gl.DEPTH_ATTACHMENT
|
|
1141
1090
|
};
|
|
1142
|
-
// Only WebGL2 support
|
|
1143
1091
|
case TextureFormat.Depth32:
|
|
1144
1092
|
return {
|
|
1145
1093
|
internalFormat: gl.DEPTH_COMPONENT32F,
|
|
@@ -1148,7 +1096,6 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
1148
1096
|
isCompressed: false,
|
|
1149
1097
|
attachment: gl.DEPTH_ATTACHMENT
|
|
1150
1098
|
};
|
|
1151
|
-
// Only WebGL2 support
|
|
1152
1099
|
case TextureFormat.Depth32Stencil8:
|
|
1153
1100
|
return {
|
|
1154
1101
|
internalFormat: gl.DEPTH32F_STENCIL8,
|
|
@@ -1162,23 +1109,22 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
1162
1109
|
}
|
|
1163
1110
|
};
|
|
1164
1111
|
/**
|
|
1165
|
-
* In WebGL 1, internalformat must be the same as baseFormat when call texImage2D.
|
|
1166
1112
|
* @internal
|
|
1167
|
-
*/ GLTexture._getRenderBufferDepthFormatDetail = function _getRenderBufferDepthFormatDetail(format, gl
|
|
1113
|
+
*/ GLTexture._getRenderBufferDepthFormatDetail = function _getRenderBufferDepthFormatDetail(format, gl) {
|
|
1168
1114
|
switch(format){
|
|
1169
1115
|
case TextureFormat.Depth:
|
|
1170
1116
|
return {
|
|
1171
|
-
internalFormat:
|
|
1117
|
+
internalFormat: gl.DEPTH_COMPONENT32F,
|
|
1172
1118
|
baseFormat: gl.DEPTH_COMPONENT,
|
|
1173
|
-
dataType:
|
|
1119
|
+
dataType: gl.FLOAT,
|
|
1174
1120
|
isCompressed: false,
|
|
1175
1121
|
attachment: gl.DEPTH_ATTACHMENT
|
|
1176
1122
|
};
|
|
1177
1123
|
case TextureFormat.DepthStencil:
|
|
1178
1124
|
return {
|
|
1179
|
-
internalFormat:
|
|
1125
|
+
internalFormat: gl.DEPTH32F_STENCIL8,
|
|
1180
1126
|
baseFormat: gl.DEPTH_STENCIL,
|
|
1181
|
-
dataType:
|
|
1127
|
+
dataType: gl.FLOAT_32_UNSIGNED_INT_24_8_REV,
|
|
1182
1128
|
isCompressed: false,
|
|
1183
1129
|
attachment: gl.DEPTH_STENCIL_ATTACHMENT
|
|
1184
1130
|
};
|
|
@@ -1200,7 +1146,7 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
1200
1146
|
};
|
|
1201
1147
|
case TextureFormat.Depth24Stencil8:
|
|
1202
1148
|
return {
|
|
1203
|
-
internalFormat:
|
|
1149
|
+
internalFormat: gl.DEPTH24_STENCIL8,
|
|
1204
1150
|
baseFormat: gl.DEPTH_STENCIL,
|
|
1205
1151
|
dataType: gl.UNSIGNED_INT_24_8,
|
|
1206
1152
|
isCompressed: false,
|
|
@@ -1234,46 +1180,6 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
1234
1180
|
throw new Error("this TextureFormat is not supported in Galacean Engine: " + format);
|
|
1235
1181
|
}
|
|
1236
1182
|
};
|
|
1237
|
-
/**
|
|
1238
|
-
* @internal
|
|
1239
|
-
*/ GLTexture._supportRenderBufferColorFormat = function _supportRenderBufferColorFormat(format, rhi) {
|
|
1240
|
-
var isSupported = true;
|
|
1241
|
-
switch(format){
|
|
1242
|
-
case TextureFormat.R16G16B16A16:
|
|
1243
|
-
{
|
|
1244
|
-
if (!rhi.canIUse(GLCapabilityType.colorBufferHalfFloat) || !rhi.canIUse(GLCapabilityType.textureHalfFloat)) {
|
|
1245
|
-
isSupported = false;
|
|
1246
|
-
}
|
|
1247
|
-
}
|
|
1248
|
-
break;
|
|
1249
|
-
case TextureFormat.R32G32B32A32:
|
|
1250
|
-
{
|
|
1251
|
-
if (!rhi.canIUse(GLCapabilityType.colorBufferFloat) || !rhi.canIUse(GLCapabilityType.textureFloat)) {
|
|
1252
|
-
isSupported = false;
|
|
1253
|
-
}
|
|
1254
|
-
}
|
|
1255
|
-
break;
|
|
1256
|
-
case TextureFormat.R11G11B10_UFloat:
|
|
1257
|
-
{
|
|
1258
|
-
isSupported = rhi.isWebGL2;
|
|
1259
|
-
}
|
|
1260
|
-
break;
|
|
1261
|
-
}
|
|
1262
|
-
return isSupported;
|
|
1263
|
-
};
|
|
1264
|
-
/**
|
|
1265
|
-
* @internal
|
|
1266
|
-
*/ GLTexture._supportRenderBufferDepthFormat = function _supportRenderBufferDepthFormat(format, rhi) {
|
|
1267
|
-
if (!rhi.isWebGL2) {
|
|
1268
|
-
switch(format){
|
|
1269
|
-
case TextureFormat.Depth24:
|
|
1270
|
-
case TextureFormat.Depth32:
|
|
1271
|
-
case TextureFormat.Depth32Stencil8:
|
|
1272
|
-
return false;
|
|
1273
|
-
}
|
|
1274
|
-
}
|
|
1275
|
-
return true;
|
|
1276
|
-
};
|
|
1277
1183
|
_create_class(GLTexture, [
|
|
1278
1184
|
{
|
|
1279
1185
|
key: "wrapModeU",
|
|
@@ -1300,7 +1206,7 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
1300
1206
|
*/ function set(value) {
|
|
1301
1207
|
var gl = this._gl;
|
|
1302
1208
|
var target = this._target;
|
|
1303
|
-
|
|
1209
|
+
var _mipmap = this._texture._mipmap;
|
|
1304
1210
|
this._bind();
|
|
1305
1211
|
switch(value){
|
|
1306
1212
|
case TextureFilterMode.Point:
|
|
@@ -1323,14 +1229,16 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
1323
1229
|
set: /**
|
|
1324
1230
|
* Anisotropic level for texture.
|
|
1325
1231
|
*/ function set(value) {
|
|
1326
|
-
var
|
|
1232
|
+
var extension = this._rhi.requireExtension(GLCapabilityType.textureFilterAnisotropic);
|
|
1233
|
+
if (!extension) return;
|
|
1327
1234
|
this._bind();
|
|
1328
|
-
|
|
1235
|
+
this._gl.texParameterf(this._target, extension.TEXTURE_MAX_ANISOTROPY_EXT, Math.min(value, this._rhi.capability.maxAnisoLevel));
|
|
1329
1236
|
}
|
|
1330
1237
|
},
|
|
1331
1238
|
{
|
|
1332
1239
|
key: "depthCompareFunction",
|
|
1333
1240
|
set: function set(value) {
|
|
1241
|
+
if (value === undefined) return;
|
|
1334
1242
|
this._bind();
|
|
1335
1243
|
var gl = this._gl;
|
|
1336
1244
|
switch(value){
|
|
@@ -1373,34 +1281,27 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
1373
1281
|
this._curMipLevel = 0;
|
|
1374
1282
|
this._curFaceIndex = undefined;
|
|
1375
1283
|
this._gl = rhi.gl;
|
|
1376
|
-
this._isWebGL2 = rhi.isWebGL2;
|
|
1377
1284
|
this._target = target;
|
|
1285
|
+
this._antiAliasing = Math.min(target.antiAliasing, rhi.capability.maxAntiAliasing);
|
|
1378
1286
|
/** @ts-ignore */ var _colorTextures = target._colorTextures, _depth = target._depth, width = target.width, height = target.height;
|
|
1379
|
-
var isDepthTexture = _instanceof(_depth, Texture);
|
|
1380
1287
|
/** todo
|
|
1381
1288
|
* MRT + Cube + [,MSAA]
|
|
1382
1289
|
* MRT + MSAA
|
|
1383
1290
|
*/ for(var i = 0, n = _colorTextures.length; i < n; i++){
|
|
1384
1291
|
var _colorTextures_i = _colorTextures[i], format = _colorTextures_i.format, isSRGBColorSpace = _colorTextures_i.isSRGBColorSpace;
|
|
1385
|
-
if (!
|
|
1292
|
+
if (!rhi.supportsRenderTargetColorFormat(format)) {
|
|
1386
1293
|
throw new Error("TextureFormat is not supported:" + TextureFormat[format] + " in RenderTarget");
|
|
1387
1294
|
}
|
|
1388
1295
|
if (isSRGBColorSpace && format === TextureFormat.R8G8B8) {
|
|
1389
1296
|
throw new Error("If you want to use sRGB color space, only R8G8B8A8 format is supported in RenderTarget");
|
|
1390
1297
|
}
|
|
1391
1298
|
}
|
|
1392
|
-
if (!isDepthTexture && !GLTexture._supportRenderBufferDepthFormat(_depth, rhi)) {
|
|
1393
|
-
throw new Error("TextureFormat is not supported:" + TextureFormat[_depth] + " in RenderTarget");
|
|
1394
|
-
}
|
|
1395
|
-
if (_colorTextures.length > 1 && !rhi.canIUse(GLCapabilityType.drawBuffers)) {
|
|
1396
|
-
throw new Error("MRT is not supported");
|
|
1397
|
-
}
|
|
1398
1299
|
if (_colorTextures.some(function(v) {
|
|
1399
1300
|
return v.width !== width || v.height !== height;
|
|
1400
1301
|
})) {
|
|
1401
1302
|
throw new Error("ColorTexture's size must as same as RenderTarget");
|
|
1402
1303
|
}
|
|
1403
|
-
if (
|
|
1304
|
+
if (_instanceof(_depth, Texture) && (_depth.width !== width || _depth.height !== height)) {
|
|
1404
1305
|
throw new Error("DepthTexture's size must as same as RenderTarget");
|
|
1405
1306
|
}
|
|
1406
1307
|
// todo: necessary to support MRT + Cube + [,MSAA] ?
|
|
@@ -1413,7 +1314,7 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
1413
1314
|
// bind main FBO
|
|
1414
1315
|
this._bindMainFBO();
|
|
1415
1316
|
// bind MSAA FBO
|
|
1416
|
-
if (
|
|
1317
|
+
if (this._antiAliasing > 1) {
|
|
1417
1318
|
this._MSAAFrameBuffer = this._gl.createFramebuffer();
|
|
1418
1319
|
this._bindMSAAFBO();
|
|
1419
1320
|
}
|
|
@@ -1433,22 +1334,20 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
1433
1334
|
if (colorTexture) {
|
|
1434
1335
|
var isCube = _instanceof(colorTexture, TextureCube);
|
|
1435
1336
|
if (mipChanged || isCube && faceChanged) {
|
|
1436
|
-
gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, isCube ? gl.TEXTURE_CUBE_MAP_POSITIVE_X + faceIndex : gl.TEXTURE_2D,
|
|
1437
|
-
colorTexture._platformTexture._glTexture, mipLevel);
|
|
1337
|
+
gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, isCube ? gl.TEXTURE_CUBE_MAP_POSITIVE_X + faceIndex : gl.TEXTURE_2D, colorTexture._platformTexture._glTexture, mipLevel);
|
|
1438
1338
|
}
|
|
1439
1339
|
}
|
|
1440
1340
|
var depthTexture = target.depthTexture;
|
|
1441
1341
|
if (depthTexture) {
|
|
1442
1342
|
var isCube1 = _instanceof(depthTexture, TextureCube);
|
|
1443
1343
|
if (mipChanged || isCube1) {
|
|
1444
|
-
// @ts-ignore
|
|
1445
1344
|
var platformTexture = depthTexture._platformTexture;
|
|
1446
1345
|
gl.framebufferTexture2D(gl.FRAMEBUFFER, platformTexture._formatDetail.attachment, isCube1 ? gl.TEXTURE_CUBE_MAP_POSITIVE_X + faceIndex : gl.TEXTURE_2D, platformTexture._glTexture, mipLevel);
|
|
1447
1346
|
}
|
|
1448
1347
|
} else {
|
|
1449
1348
|
if (mipChanged) {
|
|
1450
1349
|
// @ts-ignore
|
|
1451
|
-
var internalFormat = GLTexture._getRenderBufferDepthFormatDetail(target._depth, gl
|
|
1350
|
+
var internalFormat = GLTexture._getRenderBufferDepthFormatDetail(target._depth, gl).internalFormat;
|
|
1452
1351
|
gl.bindRenderbuffer(gl.RENDERBUFFER, this._depthRenderBuffer);
|
|
1453
1352
|
gl.renderbufferStorage(gl.RENDERBUFFER, internalFormat, target.width >> mipLevel, target.height >> mipLevel);
|
|
1454
1353
|
}
|
|
@@ -1497,8 +1396,7 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
1497
1396
|
};
|
|
1498
1397
|
_proto._bindMainFBO = function _bindMainFBO() {
|
|
1499
1398
|
var gl = this._gl;
|
|
1500
|
-
var
|
|
1501
|
-
/** @ts-ignore */ var _this__target = this._target, _depth = _this__target._depth, colorTextureCount = _this__target.colorTextureCount, width = _this__target.width, height = _this__target.height;
|
|
1399
|
+
var _this__target = this._target, _depth = _this__target._depth, colorTextureCount = _this__target.colorTextureCount; _this__target.width; _this__target.height;
|
|
1502
1400
|
var drawBuffers = new Array(colorTextureCount);
|
|
1503
1401
|
gl.bindFramebuffer(gl.FRAMEBUFFER, this._frameBuffer);
|
|
1504
1402
|
/** color render buffer */ for(var i = 0; i < colorTextureCount; i++){
|
|
@@ -1506,7 +1404,7 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
1506
1404
|
var attachment = gl.COLOR_ATTACHMENT0 + i;
|
|
1507
1405
|
drawBuffers[i] = attachment;
|
|
1508
1406
|
if (!_instanceof(colorTexture, TextureCube)) {
|
|
1509
|
-
gl.framebufferTexture2D(gl.FRAMEBUFFER, attachment, gl.TEXTURE_2D,
|
|
1407
|
+
gl.framebufferTexture2D(gl.FRAMEBUFFER, attachment, gl.TEXTURE_2D, colorTexture._platformTexture._glTexture, 0);
|
|
1510
1408
|
}
|
|
1511
1409
|
}
|
|
1512
1410
|
if (colorTextureCount > 1) {
|
|
@@ -1514,17 +1412,14 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
1514
1412
|
}
|
|
1515
1413
|
this._oriDrawBuffers = drawBuffers;
|
|
1516
1414
|
/** depth render buffer */ if (_depth !== null) {
|
|
1517
|
-
if (_instanceof(_depth, Texture)
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
var
|
|
1524
|
-
this._depthRenderBuffer =
|
|
1525
|
-
gl.bindRenderbuffer(gl.RENDERBUFFER, depthRenderBuffer);
|
|
1526
|
-
gl.renderbufferStorage(gl.RENDERBUFFER, internalFormat, width, height);
|
|
1527
|
-
gl.framebufferRenderbuffer(gl.FRAMEBUFFER, attachment1, gl.RENDERBUFFER, depthRenderBuffer);
|
|
1415
|
+
if (_instanceof(_depth, Texture)) {
|
|
1416
|
+
if (!_instanceof(_depth, TextureCube)) {
|
|
1417
|
+
var platformTexture = _depth._platformTexture;
|
|
1418
|
+
gl.framebufferTexture2D(gl.FRAMEBUFFER, platformTexture._formatDetail.attachment, gl.TEXTURE_2D, platformTexture._glTexture, 0);
|
|
1419
|
+
}
|
|
1420
|
+
} else if (this._antiAliasing <= 1) {
|
|
1421
|
+
var _GLTexture__getRenderBufferDepthFormatDetail = GLTexture._getRenderBufferDepthFormatDetail(_depth, gl), internalFormat = _GLTexture__getRenderBufferDepthFormatDetail.internalFormat, attachment1 = _GLTexture__getRenderBufferDepthFormatDetail.attachment;
|
|
1422
|
+
this._depthRenderBuffer = this._createRenderBuffer(internalFormat, attachment1);
|
|
1528
1423
|
}
|
|
1529
1424
|
}
|
|
1530
1425
|
gl.bindFramebuffer(gl.FRAMEBUFFER, null);
|
|
@@ -1532,33 +1427,39 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
1532
1427
|
};
|
|
1533
1428
|
_proto._bindMSAAFBO = function _bindMSAAFBO() {
|
|
1534
1429
|
var gl = this._gl;
|
|
1535
|
-
var
|
|
1536
|
-
var MSAADepthRenderBuffer = gl.createRenderbuffer();
|
|
1537
|
-
/** @ts-ignore */ var _this__target = this._target, _depth = _this__target._depth, colorTextureCount = _this__target.colorTextureCount, antiAliasing = _this__target.antiAliasing, width = _this__target.width, height = _this__target.height;
|
|
1430
|
+
var _this__target = this._target, _depth = _this__target._depth, colorTextureCount = _this__target.colorTextureCount;
|
|
1538
1431
|
this._blitDrawBuffers = new Array(colorTextureCount);
|
|
1539
|
-
this._MSAADepthRenderBuffer = MSAADepthRenderBuffer;
|
|
1540
1432
|
gl.bindFramebuffer(gl.FRAMEBUFFER, this._MSAAFrameBuffer);
|
|
1541
1433
|
// prepare MRT+MSAA color RBOs
|
|
1542
1434
|
for(var i = 0; i < colorTextureCount; i++){
|
|
1543
|
-
var MSAAColorRenderBuffer = gl.createRenderbuffer();
|
|
1544
|
-
this._MSAAColorRenderBuffers[i] = MSAAColorRenderBuffer;
|
|
1545
1435
|
this._blitDrawBuffers[i] = gl.NONE;
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
gl.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0 + i, gl.RENDERBUFFER, MSAAColorRenderBuffer);
|
|
1436
|
+
var internalFormat = this._target.getColorTexture(i)._platformTexture._formatDetail.internalFormat;
|
|
1437
|
+
this._MSAAColorRenderBuffers[i] = this._createRenderBuffer(internalFormat, gl.COLOR_ATTACHMENT0 + i);
|
|
1549
1438
|
}
|
|
1550
1439
|
gl.drawBuffers(this._oriDrawBuffers);
|
|
1551
1440
|
// prepare MSAA depth RBO
|
|
1552
1441
|
if (_depth !== null) {
|
|
1553
|
-
var _ref = _instanceof(_depth, Texture) ?
|
|
1554
|
-
|
|
1555
|
-
gl.renderbufferStorageMultisample(gl.RENDERBUFFER, antiAliasing, internalFormat, width, height);
|
|
1556
|
-
gl.framebufferRenderbuffer(gl.FRAMEBUFFER, attachment, gl.RENDERBUFFER, MSAADepthRenderBuffer);
|
|
1442
|
+
var _ref = _instanceof(_depth, Texture) ? _depth._platformTexture._formatDetail : GLTexture._getRenderBufferDepthFormatDetail(_depth, gl), internalFormat1 = _ref.internalFormat, attachment = _ref.attachment;
|
|
1443
|
+
this._MSAADepthRenderBuffer = this._createRenderBuffer(internalFormat1, attachment);
|
|
1557
1444
|
}
|
|
1558
1445
|
this._checkFrameBuffer();
|
|
1559
1446
|
gl.bindFramebuffer(gl.FRAMEBUFFER, null);
|
|
1560
1447
|
gl.bindRenderbuffer(gl.RENDERBUFFER, null);
|
|
1561
1448
|
};
|
|
1449
|
+
_proto._createRenderBuffer = function _createRenderBuffer(internalFormat, attachment) {
|
|
1450
|
+
var gl = this._gl;
|
|
1451
|
+
var _this__target = this._target, width = _this__target.width, height = _this__target.height;
|
|
1452
|
+
var antiAliasing = this._antiAliasing;
|
|
1453
|
+
var renderBuffer = gl.createRenderbuffer();
|
|
1454
|
+
gl.bindRenderbuffer(gl.RENDERBUFFER, renderBuffer);
|
|
1455
|
+
if (antiAliasing > 1) {
|
|
1456
|
+
gl.renderbufferStorageMultisample(gl.RENDERBUFFER, antiAliasing, internalFormat, width, height);
|
|
1457
|
+
} else {
|
|
1458
|
+
gl.renderbufferStorage(gl.RENDERBUFFER, internalFormat, width, height);
|
|
1459
|
+
}
|
|
1460
|
+
gl.framebufferRenderbuffer(gl.FRAMEBUFFER, attachment, gl.RENDERBUFFER, renderBuffer);
|
|
1461
|
+
return renderBuffer;
|
|
1462
|
+
};
|
|
1562
1463
|
_proto._checkFrameBuffer = function _checkFrameBuffer() {
|
|
1563
1464
|
var gl = this._gl;
|
|
1564
1465
|
var e = gl.checkFramebufferStatus(gl.FRAMEBUFFER);
|
|
@@ -1588,12 +1489,11 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
1588
1489
|
_inherits(GLTexture2D, GLTexture1);
|
|
1589
1490
|
function GLTexture2D(rhi, texture2D) {
|
|
1590
1491
|
var _this;
|
|
1591
|
-
_this = GLTexture1.call(this, rhi, texture2D, rhi.gl.TEXTURE_2D) || this
|
|
1592
|
-
_this._validate(texture2D
|
|
1492
|
+
_this = GLTexture1.call(this, rhi, texture2D, rhi.gl.TEXTURE_2D) || this;
|
|
1493
|
+
_this._validate(texture2D);
|
|
1593
1494
|
var format = texture2D.format, isSRGBColorSpace = texture2D.isSRGBColorSpace;
|
|
1594
|
-
|
|
1595
|
-
_this.
|
|
1596
|
-
_this._formatDetail.isCompressed && !isWebGL2 || _this._init(false);
|
|
1495
|
+
_this._formatDetail = GLTexture._getFormatDetail(format, isSRGBColorSpace, _this._gl);
|
|
1496
|
+
_this._init(false);
|
|
1597
1497
|
return _this;
|
|
1598
1498
|
}
|
|
1599
1499
|
var _proto = GLTexture2D.prototype;
|
|
@@ -1609,15 +1509,7 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
1609
1509
|
height = height || mipHeight - y;
|
|
1610
1510
|
this._bind();
|
|
1611
1511
|
if (formatDetail.isCompressed) {
|
|
1612
|
-
|
|
1613
|
-
var internalFormat = formatDetail.internalFormat;
|
|
1614
|
-
var mipBit = 1 << mipLevel;
|
|
1615
|
-
if (isWebGL2 || this._compressedMipFilled & mipBit) {
|
|
1616
|
-
gl.compressedTexSubImage2D(this._target, mipLevel, x, y, width, height, internalFormat, colorBuffer);
|
|
1617
|
-
} else {
|
|
1618
|
-
gl.compressedTexImage2D(this._target, mipLevel, internalFormat, width, height, 0, colorBuffer);
|
|
1619
|
-
this._compressedMipFilled |= mipBit;
|
|
1620
|
-
}
|
|
1512
|
+
gl.compressedTexSubImage2D(this._target, mipLevel, x, y, width, height, formatDetail.internalFormat, colorBuffer);
|
|
1621
1513
|
} else {
|
|
1622
1514
|
var baseFormat = formatDetail.baseFormat, dataType = formatDetail.dataType;
|
|
1623
1515
|
gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, 0);
|
|
@@ -1658,10 +1550,10 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
1658
1550
|
function GLTexture2DArray(rhi, texture2DArray) {
|
|
1659
1551
|
var _this;
|
|
1660
1552
|
_this = GLTexture1.call(this, rhi, texture2DArray, rhi.gl.TEXTURE_2D_ARRAY) || this;
|
|
1661
|
-
_this._validate(texture2DArray
|
|
1553
|
+
_this._validate(texture2DArray);
|
|
1662
1554
|
var format = texture2DArray.format, width = texture2DArray.width, height = texture2DArray.height, length = texture2DArray.length, mipmapCount = texture2DArray.mipmapCount, isSRGBColorSpace = texture2DArray.isSRGBColorSpace;
|
|
1663
1555
|
_this._bind();
|
|
1664
|
-
_this._formatDetail = GLTexture._getFormatDetail(format, isSRGBColorSpace, _this._gl
|
|
1556
|
+
_this._formatDetail = GLTexture._getFormatDetail(format, isSRGBColorSpace, _this._gl);
|
|
1665
1557
|
_this._gl.texStorage3D(_this._target, mipmapCount, _this._formatDetail.internalFormat, width, height, length);
|
|
1666
1558
|
return _this;
|
|
1667
1559
|
}
|
|
@@ -1676,12 +1568,12 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
1676
1568
|
height = height || Math.max(1, this._texture.height >> mipLevel) - y;
|
|
1677
1569
|
length = length || this._texture.length;
|
|
1678
1570
|
this._bind();
|
|
1679
|
-
gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, 0);
|
|
1680
|
-
gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, 0);
|
|
1681
|
-
gl.pixelStorei(gl.UNPACK_ALIGNMENT, formatDetail.alignment);
|
|
1682
1571
|
if (isCompressed) {
|
|
1683
1572
|
gl.compressedTexSubImage3D(target, mipLevel, x, y, offsetIndex, width, height, length, internalFormat, colorBuffer);
|
|
1684
1573
|
} else {
|
|
1574
|
+
gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, 0);
|
|
1575
|
+
gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, 0);
|
|
1576
|
+
gl.pixelStorei(gl.UNPACK_ALIGNMENT, formatDetail.alignment);
|
|
1685
1577
|
gl.texSubImage3D(target, mipLevel, x, y, offsetIndex, width, height, length, baseFormat, dataType, colorBuffer);
|
|
1686
1578
|
}
|
|
1687
1579
|
};
|
|
@@ -1709,7 +1601,7 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
1709
1601
|
gl.readPixels(x, y, width, height, formatDetail.baseFormat, formatDetail.dataType, out);
|
|
1710
1602
|
gl.bindFramebuffer(gl.FRAMEBUFFER, null);
|
|
1711
1603
|
};
|
|
1712
|
-
_proto._validate = function _validate(texture
|
|
1604
|
+
_proto._validate = function _validate(texture) {
|
|
1713
1605
|
var format = texture.format;
|
|
1714
1606
|
// Validate sRGB format
|
|
1715
1607
|
// @ts-ignore
|
|
@@ -1729,19 +1621,11 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
1729
1621
|
_inherits(GLTextureCube, GLTexture1);
|
|
1730
1622
|
function GLTextureCube(rhi, textureCube) {
|
|
1731
1623
|
var _this;
|
|
1732
|
-
_this = GLTexture1.call(this, rhi, textureCube, rhi.gl.TEXTURE_CUBE_MAP) || this
|
|
1733
|
-
|
|
1734
|
-
0,
|
|
1735
|
-
0,
|
|
1736
|
-
0,
|
|
1737
|
-
0,
|
|
1738
|
-
0
|
|
1739
|
-
];
|
|
1740
|
-
_this._validate(textureCube, rhi);
|
|
1624
|
+
_this = GLTexture1.call(this, rhi, textureCube, rhi.gl.TEXTURE_CUBE_MAP) || this;
|
|
1625
|
+
_this._validate(textureCube);
|
|
1741
1626
|
var format = textureCube.format, isSRGBColorSpace = textureCube.isSRGBColorSpace;
|
|
1742
|
-
|
|
1743
|
-
_this.
|
|
1744
|
-
_this._formatDetail.isCompressed && !isWebGL2 || _this._init(true);
|
|
1627
|
+
_this._formatDetail = GLTexture._getFormatDetail(format, isSRGBColorSpace, _this._gl);
|
|
1628
|
+
_this._init(true);
|
|
1745
1629
|
return _this;
|
|
1746
1630
|
}
|
|
1747
1631
|
var _proto = GLTextureCube.prototype;
|
|
@@ -1749,25 +1633,18 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
1749
1633
|
* {@inheritDoc IPlatformTextureCube.setPixelBuffer}
|
|
1750
1634
|
*/ _proto.setPixelBuffer = function setPixelBuffer(face, colorBuffer, mipLevel, x, y, width, height) {
|
|
1751
1635
|
var gl = this._gl;
|
|
1752
|
-
var isWebGL2 = this._isWebGL2;
|
|
1753
1636
|
var formatDetail = this._formatDetail;
|
|
1754
|
-
var
|
|
1637
|
+
var baseFormat = formatDetail.baseFormat, dataType = formatDetail.dataType, isCompressed = formatDetail.isCompressed;
|
|
1755
1638
|
var mipSize = Math.max(1, this._texture.width >> mipLevel);
|
|
1756
1639
|
width = width || mipSize - x;
|
|
1757
1640
|
height = height || mipSize - y;
|
|
1758
1641
|
this._bind();
|
|
1759
|
-
gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, 0);
|
|
1760
|
-
gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, 0);
|
|
1761
|
-
gl.pixelStorei(gl.UNPACK_ALIGNMENT, formatDetail.alignment);
|
|
1762
1642
|
if (isCompressed) {
|
|
1763
|
-
|
|
1764
|
-
if (isWebGL2 || this._compressedFaceFilled[face] & mipBit) {
|
|
1765
|
-
gl.compressedTexSubImage2D(gl.TEXTURE_CUBE_MAP_POSITIVE_X + face, mipLevel, x, y, width, height, internalFormat, colorBuffer);
|
|
1766
|
-
} else {
|
|
1767
|
-
gl.compressedTexImage2D(gl.TEXTURE_CUBE_MAP_POSITIVE_X + face, mipLevel, internalFormat, width, height, 0, colorBuffer);
|
|
1768
|
-
this._compressedFaceFilled[face] |= mipBit;
|
|
1769
|
-
}
|
|
1643
|
+
gl.compressedTexSubImage2D(gl.TEXTURE_CUBE_MAP_POSITIVE_X + face, mipLevel, x, y, width, height, formatDetail.internalFormat, colorBuffer);
|
|
1770
1644
|
} else {
|
|
1645
|
+
gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, 0);
|
|
1646
|
+
gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, 0);
|
|
1647
|
+
gl.pixelStorei(gl.UNPACK_ALIGNMENT, formatDetail.alignment);
|
|
1771
1648
|
gl.texSubImage2D(gl.TEXTURE_CUBE_MAP_POSITIVE_X + face, mipLevel, x, y, width, height, baseFormat, dataType, colorBuffer);
|
|
1772
1649
|
}
|
|
1773
1650
|
};
|
|
@@ -1793,18 +1670,150 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
1793
1670
|
}(GLTexture);
|
|
1794
1671
|
|
|
1795
1672
|
/**
|
|
1796
|
-
*
|
|
1797
|
-
|
|
1798
|
-
|
|
1799
|
-
|
|
1800
|
-
|
|
1801
|
-
|
|
1802
|
-
|
|
1673
|
+
* @internal
|
|
1674
|
+
* WebGL2 implementation of Transform Feedback.
|
|
1675
|
+
*/ var GLTransformFeedback = /*#__PURE__*/ function() {
|
|
1676
|
+
function GLTransformFeedback(rhi) {
|
|
1677
|
+
var gl = rhi.gl;
|
|
1678
|
+
this._gl = gl;
|
|
1679
|
+
this._glTransformFeedback = gl.createTransformFeedback();
|
|
1680
|
+
}
|
|
1681
|
+
var _proto = GLTransformFeedback.prototype;
|
|
1682
|
+
_proto.bindBufferRange = function bindBufferRange(index, buffer, byteOffset, byteSize) {
|
|
1683
|
+
var gl = this._gl;
|
|
1684
|
+
gl.bindBufferRange(gl.TRANSFORM_FEEDBACK_BUFFER, index, buffer._glBuffer, byteOffset, byteSize);
|
|
1685
|
+
};
|
|
1686
|
+
_proto.unbindBuffer = function unbindBuffer(index) {
|
|
1687
|
+
var gl = this._gl;
|
|
1688
|
+
gl.bindBufferBase(gl.TRANSFORM_FEEDBACK_BUFFER, index, null);
|
|
1689
|
+
};
|
|
1690
|
+
_proto.begin = function begin(primitiveMode) {
|
|
1691
|
+
this._gl.beginTransformFeedback(primitiveMode);
|
|
1692
|
+
};
|
|
1693
|
+
_proto.end = function end() {
|
|
1694
|
+
this._gl.endTransformFeedback();
|
|
1695
|
+
};
|
|
1696
|
+
_proto.bind = function bind() {
|
|
1697
|
+
var gl = this._gl;
|
|
1698
|
+
gl.bindTransformFeedback(gl.TRANSFORM_FEEDBACK, this._glTransformFeedback);
|
|
1699
|
+
};
|
|
1700
|
+
_proto.unbind = function unbind() {
|
|
1701
|
+
var gl = this._gl;
|
|
1702
|
+
gl.bindTransformFeedback(gl.TRANSFORM_FEEDBACK, null);
|
|
1703
|
+
};
|
|
1704
|
+
_proto.destroy = function destroy() {
|
|
1705
|
+
if (this._glTransformFeedback) {
|
|
1706
|
+
this._gl.deleteTransformFeedback(this._glTransformFeedback);
|
|
1707
|
+
this._glTransformFeedback = null;
|
|
1708
|
+
}
|
|
1709
|
+
};
|
|
1710
|
+
return GLTransformFeedback;
|
|
1711
|
+
}();
|
|
1712
|
+
|
|
1713
|
+
/**
|
|
1714
|
+
* @internal
|
|
1715
|
+
* WebGL2 implementation of Transform Feedback primitive.
|
|
1716
|
+
* Maintains two VAOs (one per read direction), rebuilding when the program or input bindings change.
|
|
1717
|
+
*/ var GLTransformFeedbackPrimitive = /*#__PURE__*/ function() {
|
|
1718
|
+
function GLTransformFeedbackPrimitive(gl) {
|
|
1719
|
+
this._lastProgramId = -1;
|
|
1720
|
+
this._lastInputBindings = [];
|
|
1721
|
+
this._gl = gl;
|
|
1722
|
+
}
|
|
1723
|
+
var _proto = GLTransformFeedbackPrimitive.prototype;
|
|
1724
|
+
_proto.bind = function bind(program, bindingA, bindingB, feedbackElements, inputBindings, inputElements, readIsA) {
|
|
1725
|
+
var layoutChanged = program.id !== this._lastProgramId;
|
|
1726
|
+
var lastInputBindings = this._lastInputBindings;
|
|
1727
|
+
if (!layoutChanged) {
|
|
1728
|
+
if (inputBindings.length !== lastInputBindings.length) {
|
|
1729
|
+
layoutChanged = true;
|
|
1730
|
+
} else {
|
|
1731
|
+
for(var i = 0, n = inputBindings.length; i < n; i++){
|
|
1732
|
+
if (inputBindings[i] !== lastInputBindings[i]) {
|
|
1733
|
+
layoutChanged = true;
|
|
1734
|
+
break;
|
|
1735
|
+
}
|
|
1736
|
+
}
|
|
1737
|
+
}
|
|
1738
|
+
}
|
|
1739
|
+
if (layoutChanged) {
|
|
1740
|
+
this._deleteVAOs();
|
|
1741
|
+
var attribs = program.attributeLocation;
|
|
1742
|
+
this._vaoA = this._createVAO(attribs, bindingA, feedbackElements, inputBindings, inputElements);
|
|
1743
|
+
this._vaoB = this._createVAO(attribs, bindingB, feedbackElements, inputBindings, inputElements);
|
|
1744
|
+
this._lastProgramId = program.id;
|
|
1745
|
+
lastInputBindings.length = inputBindings.length;
|
|
1746
|
+
for(var i1 = 0, n1 = inputBindings.length; i1 < n1; i1++){
|
|
1747
|
+
lastInputBindings[i1] = inputBindings[i1];
|
|
1748
|
+
}
|
|
1749
|
+
this._gl.bindVertexArray(null);
|
|
1750
|
+
}
|
|
1751
|
+
this._gl.bindVertexArray(readIsA ? this._vaoA : this._vaoB);
|
|
1752
|
+
};
|
|
1753
|
+
_proto.unbind = function unbind() {
|
|
1754
|
+
this._gl.bindVertexArray(null);
|
|
1755
|
+
};
|
|
1756
|
+
_proto.draw = function draw(mode, first, count) {
|
|
1757
|
+
this._gl.drawArrays(mode, first, count);
|
|
1758
|
+
};
|
|
1759
|
+
_proto.invalidate = function invalidate() {
|
|
1760
|
+
this._deleteVAOs();
|
|
1761
|
+
};
|
|
1762
|
+
_proto.destroy = function destroy() {
|
|
1763
|
+
this._deleteVAOs();
|
|
1764
|
+
};
|
|
1765
|
+
_proto._deleteVAOs = function _deleteVAOs() {
|
|
1766
|
+
var gl = this._gl;
|
|
1767
|
+
if (this._vaoA) {
|
|
1768
|
+
gl.deleteVertexArray(this._vaoA);
|
|
1769
|
+
this._vaoA = null;
|
|
1770
|
+
}
|
|
1771
|
+
if (this._vaoB) {
|
|
1772
|
+
gl.deleteVertexArray(this._vaoB);
|
|
1773
|
+
this._vaoB = null;
|
|
1774
|
+
}
|
|
1775
|
+
this._lastProgramId = -1;
|
|
1776
|
+
this._lastInputBindings.length = 0;
|
|
1777
|
+
};
|
|
1778
|
+
_proto._createVAO = function _createVAO(attribs, feedbackBinding, feedbackElements, inputBindings, inputElements) {
|
|
1779
|
+
var gl = this._gl;
|
|
1780
|
+
var vao = gl.createVertexArray();
|
|
1781
|
+
gl.bindVertexArray(vao);
|
|
1782
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, feedbackBinding.buffer._platformBuffer._glBuffer);
|
|
1783
|
+
for(var i = 0, n = feedbackElements.length; i < n; i++){
|
|
1784
|
+
this._bindElement(attribs, feedbackElements[i], feedbackBinding.stride);
|
|
1785
|
+
}
|
|
1786
|
+
var lastInputBinding;
|
|
1787
|
+
for(var i1 = 0, n1 = inputElements.length; i1 < n1; i1++){
|
|
1788
|
+
var element = inputElements[i1];
|
|
1789
|
+
var inputBinding = inputBindings[element.bindingIndex];
|
|
1790
|
+
if (inputBinding !== lastInputBinding) {
|
|
1791
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, inputBinding.buffer._platformBuffer._glBuffer);
|
|
1792
|
+
lastInputBinding = inputBinding;
|
|
1793
|
+
}
|
|
1794
|
+
this._bindElement(attribs, element, inputBinding.stride);
|
|
1795
|
+
}
|
|
1796
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, null);
|
|
1797
|
+
return vao;
|
|
1798
|
+
};
|
|
1799
|
+
_proto._bindElement = function _bindElement(attribs, element, stride) {
|
|
1800
|
+
var gl = this._gl;
|
|
1801
|
+
var loc = attribs[element.attribute];
|
|
1802
|
+
if (loc !== undefined && loc !== -1) {
|
|
1803
|
+
var info = element._formatMetaInfo;
|
|
1804
|
+
gl.enableVertexAttribArray(loc);
|
|
1805
|
+
gl.vertexAttribPointer(loc, info.size, info.type, info.normalized, stride, element.offset);
|
|
1806
|
+
}
|
|
1807
|
+
};
|
|
1808
|
+
return GLTransformFeedbackPrimitive;
|
|
1809
|
+
}();
|
|
1810
|
+
|
|
1803
1811
|
/**
|
|
1804
|
-
* WebGL graphic device,
|
|
1812
|
+
* WebGL graphic device, using WebGL2.0.
|
|
1805
1813
|
*/ var WebGLGraphicDevice = /*#__PURE__*/ function() {
|
|
1806
1814
|
function WebGLGraphicDevice(initializeOptions) {
|
|
1807
1815
|
if (initializeOptions === void 0) initializeOptions = {};
|
|
1816
|
+
this.supportsRendering = true;
|
|
1808
1817
|
/** @internal */ this._readFrameBuffer = null;
|
|
1809
1818
|
/** @internal */ this._mainFrameBuffer = null;
|
|
1810
1819
|
/** @internal */ this._mainFrameWidth = 0;
|
|
@@ -1816,7 +1825,6 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
1816
1825
|
this._lastClearColor = new Color(null, null, null, null);
|
|
1817
1826
|
this._scissorEnable = false;
|
|
1818
1827
|
var options = _extends({
|
|
1819
|
-
webGLMode: 0,
|
|
1820
1828
|
_forceFlush: false,
|
|
1821
1829
|
_maxAllowSkinUniformVectorCount: 256,
|
|
1822
1830
|
alpha: true,
|
|
@@ -1859,40 +1867,26 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
1859
1867
|
var _proto = WebGLGraphicDevice.prototype;
|
|
1860
1868
|
_proto.init = function init(canvas, onDeviceLost, onDeviceRestored) {
|
|
1861
1869
|
var webCanvas = canvas._webCanvas;
|
|
1862
|
-
var webGLMode = this._options.webGLMode;
|
|
1863
|
-
this._onDeviceLost = onDeviceLost;
|
|
1864
|
-
this._onDeviceRestored = onDeviceRestored;
|
|
1865
|
-
webCanvas.addEventListener("webglcontextlost", this._onWebGLContextLost, false);
|
|
1866
|
-
webCanvas.addEventListener("webglcontextrestored", this._onWebGLContextRestored, false);
|
|
1867
1870
|
webCanvas.addEventListener("webglcontextcreationerror", this._onContextCreationError, false);
|
|
1868
|
-
|
|
1869
|
-
|
|
1870
|
-
|
|
1871
|
-
|
|
1872
|
-
gl = webCanvas.getContext("webgl2", webGLOptions);
|
|
1873
|
-
if (!gl && (typeof OffscreenCanvas === "undefined" || !_instanceof(webCanvas, OffscreenCanvas))) {
|
|
1871
|
+
try {
|
|
1872
|
+
var webGLOptions = this._webGLOptions;
|
|
1873
|
+
var gl = webCanvas.getContext("webgl2", webGLOptions);
|
|
1874
|
+
if (!gl && !canvas._isOffscreenCanvas()) {
|
|
1874
1875
|
gl = webCanvas.getContext("experimental-webgl2", webGLOptions);
|
|
1875
1876
|
}
|
|
1876
|
-
|
|
1877
|
-
|
|
1878
|
-
if (gl && !gl.deleteQuery) {
|
|
1879
|
-
this._isWebGL2 = false;
|
|
1880
|
-
}
|
|
1881
|
-
}
|
|
1882
|
-
if (!gl) {
|
|
1883
|
-
if (webGLMode == 0 || webGLMode == 2) {
|
|
1884
|
-
gl = webCanvas.getContext("webgl", webGLOptions);
|
|
1885
|
-
if (!gl && (typeof OffscreenCanvas === "undefined" || !_instanceof(webCanvas, OffscreenCanvas))) {
|
|
1886
|
-
gl = webCanvas.getContext("experimental-webgl", webGLOptions);
|
|
1887
|
-
}
|
|
1888
|
-
this._isWebGL2 = false;
|
|
1877
|
+
if (!gl || !gl.deleteQuery) {
|
|
1878
|
+
throw new Error("WebGL2 is not supported.");
|
|
1889
1879
|
}
|
|
1880
|
+
this._gl = gl;
|
|
1881
|
+
this._initGLState(gl);
|
|
1882
|
+
} finally{
|
|
1883
|
+
webCanvas.removeEventListener("webglcontextcreationerror", this._onContextCreationError, false);
|
|
1890
1884
|
}
|
|
1891
|
-
|
|
1892
|
-
|
|
1893
|
-
|
|
1894
|
-
this.
|
|
1895
|
-
this.
|
|
1885
|
+
this._webCanvas = webCanvas;
|
|
1886
|
+
this._onDeviceLost = onDeviceLost;
|
|
1887
|
+
this._onDeviceRestored = onDeviceRestored;
|
|
1888
|
+
webCanvas.addEventListener("webglcontextlost", this._onWebGLContextLost, false);
|
|
1889
|
+
webCanvas.addEventListener("webglcontextrestored", this._onWebGLContextRestored, false);
|
|
1896
1890
|
};
|
|
1897
1891
|
_proto.createPlatformPrimitive = function createPlatformPrimitive(primitive) {
|
|
1898
1892
|
return new GLPrimitive(this, primitive);
|
|
@@ -1913,6 +1907,45 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
1913
1907
|
if (bufferUsage === void 0) bufferUsage = BufferUsage.Static;
|
|
1914
1908
|
return new GLBuffer(this, type, byteLength, bufferUsage, data);
|
|
1915
1909
|
};
|
|
1910
|
+
_proto.createPlatformTransformFeedback = function createPlatformTransformFeedback() {
|
|
1911
|
+
return new GLTransformFeedback(this);
|
|
1912
|
+
};
|
|
1913
|
+
_proto.createPlatformTransformFeedbackPrimitive = function createPlatformTransformFeedbackPrimitive() {
|
|
1914
|
+
return new GLTransformFeedbackPrimitive(this._gl);
|
|
1915
|
+
};
|
|
1916
|
+
_proto.bindUniformBufferBase = function bindUniformBufferBase(bindingPoint, buffer) {
|
|
1917
|
+
var gl = this._gl;
|
|
1918
|
+
gl.bindBufferBase(gl.UNIFORM_BUFFER, bindingPoint, buffer._glBuffer);
|
|
1919
|
+
};
|
|
1920
|
+
_proto.bindUniformBlock = function bindUniformBlock(program, blockName, bindingPoint) {
|
|
1921
|
+
var gl = this._gl;
|
|
1922
|
+
var blockIndex = gl.getUniformBlockIndex(program, blockName);
|
|
1923
|
+
if (blockIndex !== gl.INVALID_INDEX) {
|
|
1924
|
+
gl.uniformBlockBinding(program, blockIndex, bindingPoint);
|
|
1925
|
+
}
|
|
1926
|
+
return blockIndex;
|
|
1927
|
+
};
|
|
1928
|
+
/**
|
|
1929
|
+
* Enable GL_RASTERIZER_DISCARD (WebGL2 only).
|
|
1930
|
+
*/ _proto.enableRasterizerDiscard = function enableRasterizerDiscard() {
|
|
1931
|
+
var gl = this._gl;
|
|
1932
|
+
gl.enable(gl.RASTERIZER_DISCARD);
|
|
1933
|
+
};
|
|
1934
|
+
/**
|
|
1935
|
+
* Disable GL_RASTERIZER_DISCARD (WebGL2 only).
|
|
1936
|
+
*/ _proto.disableRasterizerDiscard = function disableRasterizerDiscard() {
|
|
1937
|
+
var gl = this._gl;
|
|
1938
|
+
gl.disable(gl.RASTERIZER_DISCARD);
|
|
1939
|
+
};
|
|
1940
|
+
/**
|
|
1941
|
+
* Invalidate the cached shader program state.
|
|
1942
|
+
* Call this after using a custom program (e.g., Transform Feedback) outside the engine's pipeline.
|
|
1943
|
+
*/ _proto.invalidateShaderProgramState = function invalidateShaderProgramState() {
|
|
1944
|
+
if (this._currentBindShaderProgram) {
|
|
1945
|
+
this._gl.useProgram(null);
|
|
1946
|
+
this._currentBindShaderProgram = null;
|
|
1947
|
+
}
|
|
1948
|
+
};
|
|
1916
1949
|
_proto.requireExtension = function requireExtension(ext) {
|
|
1917
1950
|
return this._extensions.requireExtension(ext);
|
|
1918
1951
|
};
|
|
@@ -1922,6 +1955,12 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
1922
1955
|
_proto.canIUseCompressedTextureInternalFormat = function canIUseCompressedTextureInternalFormat(type) {
|
|
1923
1956
|
return this.capability.canIUseCompressedTextureInternalFormat(type);
|
|
1924
1957
|
};
|
|
1958
|
+
_proto.supportsTextureFormat = function supportsTextureFormat(format) {
|
|
1959
|
+
return this.capability.supportsTextureFormat(format);
|
|
1960
|
+
};
|
|
1961
|
+
_proto.supportsRenderTargetColorFormat = function supportsRenderTargetColorFormat(format) {
|
|
1962
|
+
return this.capability.supportsRenderTargetColorFormat(format);
|
|
1963
|
+
};
|
|
1925
1964
|
_proto.viewport = function viewport(x, y, width, height) {
|
|
1926
1965
|
var _this = this, gl = _this._gl, lastViewport = _this._lastViewport;
|
|
1927
1966
|
if (x !== lastViewport.x || y !== lastViewport.y || width !== lastViewport.z || height !== lastViewport.w) {
|
|
@@ -1986,7 +2025,7 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
1986
2025
|
};
|
|
1987
2026
|
_proto.drawPrimitive = function drawPrimitive(primitive, subPrimitive, shaderProgram) {
|
|
1988
2027
|
// todo: VAO not support morph animation
|
|
1989
|
-
if (primitive) {
|
|
2028
|
+
if (primitive && subPrimitive) {
|
|
1990
2029
|
primitive.draw(shaderProgram, subPrimitive);
|
|
1991
2030
|
} else {
|
|
1992
2031
|
Logger.error("draw primitive failed.");
|
|
@@ -2001,8 +2040,8 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
2001
2040
|
_proto.activeRenderTarget = function activeRenderTarget(renderTarget, viewport, isFlipProjection, mipLevel, faceIndex) {
|
|
2002
2041
|
var bufferWidth, bufferHeight;
|
|
2003
2042
|
if (renderTarget) {
|
|
2004
|
-
|
|
2005
|
-
|
|
2043
|
+
renderTarget._isContentLost = false;
|
|
2044
|
+
var platformRenderTarget = renderTarget._platformRenderTarget;
|
|
2006
2045
|
platformRenderTarget.activeRenderTarget(mipLevel, faceIndex);
|
|
2007
2046
|
bufferWidth = renderTarget.width >> mipLevel;
|
|
2008
2047
|
bufferHeight = renderTarget.height >> mipLevel;
|
|
@@ -2020,10 +2059,6 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
2020
2059
|
this.scissor(x, y, width, height);
|
|
2021
2060
|
};
|
|
2022
2061
|
_proto.blitInternalRTByBlitFrameBuffer = function blitInternalRTByBlitFrameBuffer(srcRT, destRT, clearFlags, viewport) {
|
|
2023
|
-
if (!this._isWebGL2) {
|
|
2024
|
-
Logger.warn("WebGL1.0 not support blit frame buffer.");
|
|
2025
|
-
return;
|
|
2026
|
-
}
|
|
2027
2062
|
var gl = this._gl;
|
|
2028
2063
|
// @ts-ignore
|
|
2029
2064
|
var srcFrameBuffer = srcRT ? srcRT._platformRenderTarget._frameBuffer : null;
|
|
@@ -2043,7 +2078,6 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
2043
2078
|
gl.bindFramebuffer(gl.DRAW_FRAMEBUFFER, destFrameBuffer);
|
|
2044
2079
|
var blitMask = needBlitColor ? gl.COLOR_BUFFER_BIT : 0;
|
|
2045
2080
|
if (needBlitDepth || needBlitStencil) {
|
|
2046
|
-
// @ts-ignore
|
|
2047
2081
|
var depthFormat = destRT._depthFormat;
|
|
2048
2082
|
if (needBlitDepth) {
|
|
2049
2083
|
if (depthFormat === TextureFormat.Depth || depthFormat >= TextureFormat.DepthStencil && depthFormat <= TextureFormat.Depth32Stencil8) {
|
|
@@ -2080,11 +2114,9 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
2080
2114
|
var _srcRT__platformRenderTarget__frameBuffer;
|
|
2081
2115
|
// @ts-ignore
|
|
2082
2116
|
var frameBuffer = (_srcRT__platformRenderTarget__frameBuffer = srcRT == null ? void 0 : srcRT._platformRenderTarget._frameBuffer) != null ? _srcRT__platformRenderTarget__frameBuffer : this._mainFrameBuffer;
|
|
2083
|
-
// @ts-ignore
|
|
2084
2117
|
gl.bindFramebuffer(gl.FRAMEBUFFER, frameBuffer);
|
|
2085
|
-
// @ts-ignore
|
|
2086
2118
|
var glTexture = grabTexture._platformTexture;
|
|
2087
|
-
|
|
2119
|
+
this.bindTexture(glTexture);
|
|
2088
2120
|
gl.copyTexSubImage2D(glTexture._target, 0, 0, 0, xStart, yStart, copyWidth, copyHeight);
|
|
2089
2121
|
};
|
|
2090
2122
|
_proto.activeTexture = function activeTexture(textureID) {
|
|
@@ -2093,7 +2125,8 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
2093
2125
|
this._activeTextureID = textureID;
|
|
2094
2126
|
}
|
|
2095
2127
|
};
|
|
2096
|
-
_proto.bindTexture = function bindTexture(
|
|
2128
|
+
_proto.bindTexture = function bindTexture(platformTexture) {
|
|
2129
|
+
var texture = platformTexture;
|
|
2097
2130
|
var index = this._activeTextureID - this._gl.TEXTURE0;
|
|
2098
2131
|
if (this._activeTextures[index] !== texture) {
|
|
2099
2132
|
this._gl.bindTexture(texture._target, texture._glTexture);
|
|
@@ -2153,10 +2186,10 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
2153
2186
|
if (debugRenderInfo != null) {
|
|
2154
2187
|
this._renderer = gl.getParameter(debugRenderInfo.UNMASKED_RENDERER_WEBGL);
|
|
2155
2188
|
}
|
|
2189
|
+
this.maxUniformBlockSize = gl.getParameter(gl.MAX_UNIFORM_BLOCK_SIZE);
|
|
2156
2190
|
};
|
|
2157
2191
|
_proto.destroy = function destroy() {
|
|
2158
2192
|
var webCanvas = this._webCanvas;
|
|
2159
|
-
webCanvas.removeEventListener("webglcontextcreationerror", this._onContextCreationError, false);
|
|
2160
2193
|
webCanvas.removeEventListener("webglcontextlost", this._onWebGLContextLost, false);
|
|
2161
2194
|
webCanvas.removeEventListener("webglcontextrestored", this._onWebGLContextRestored, false);
|
|
2162
2195
|
};
|
|
@@ -2171,12 +2204,6 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
2171
2204
|
this._onDeviceRestored();
|
|
2172
2205
|
};
|
|
2173
2206
|
_create_class(WebGLGraphicDevice, [
|
|
2174
|
-
{
|
|
2175
|
-
key: "isWebGL2",
|
|
2176
|
-
get: function get() {
|
|
2177
|
-
return this._isWebGL2;
|
|
2178
|
-
}
|
|
2179
|
-
},
|
|
2180
2207
|
{
|
|
2181
2208
|
key: "renderer",
|
|
2182
2209
|
get: function get() {
|
|
@@ -2187,7 +2214,7 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
2187
2214
|
key: "gl",
|
|
2188
2215
|
get: /**
|
|
2189
2216
|
* GL Context
|
|
2190
|
-
* @member {
|
|
2217
|
+
* @member {WebGL2RenderingContext}
|
|
2191
2218
|
*/ function get() {
|
|
2192
2219
|
return this._gl;
|
|
2193
2220
|
}
|
|
@@ -2203,16 +2230,10 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
2203
2230
|
get: function get() {
|
|
2204
2231
|
return this._capability;
|
|
2205
2232
|
}
|
|
2206
|
-
},
|
|
2207
|
-
{
|
|
2208
|
-
key: "canIUseMoreJoints",
|
|
2209
|
-
get: function get() {
|
|
2210
|
-
return this.capability.canIUseMoreJoints;
|
|
2211
|
-
}
|
|
2212
2233
|
}
|
|
2213
2234
|
]);
|
|
2214
2235
|
return WebGLGraphicDevice;
|
|
2215
2236
|
}();
|
|
2216
2237
|
|
|
2217
|
-
export { GLCompressedTextureInternalFormat, WebCanvas, WebGLEngine, WebGLGraphicDevice
|
|
2238
|
+
export { GLCompressedTextureInternalFormat, WebCanvas, WebGLEngine, WebGLGraphicDevice };
|
|
2218
2239
|
//# sourceMappingURL=module.js.map
|