@galacean/engine-rhi-webgl 2.0.0-alpha.6 → 2.0.0-alpha.61
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 +605 -521
- package/dist/main.js.map +1 -1
- package/dist/module.js +608 -523
- 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 +31 -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 +1 -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
|
-
|
|
149
|
-
|
|
150
|
-
|
|
148
|
+
* @internal
|
|
149
|
+
*/ _proto._isOffscreenCanvas = function _isOffscreenCanvas() {
|
|
150
|
+
return typeof OffscreenCanvas !== "undefined" && _instanceof(this._webCanvas, OffscreenCanvas);
|
|
151
|
+
};
|
|
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
|
+
}
|
|
151
175
|
};
|
|
152
|
-
_proto.
|
|
153
|
-
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));
|
|
154
181
|
};
|
|
155
|
-
|
|
156
|
-
|
|
182
|
+
/**
|
|
183
|
+
* @internal
|
|
184
|
+
*/ _proto._destroy = function _destroy() {
|
|
185
|
+
this._exitAutoResolution();
|
|
157
186
|
};
|
|
158
|
-
|
|
159
|
-
{
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
* The scale of canvas, the value is visible width/height divide the render width/height.
|
|
163
|
-
* @remarks Need to re-assign after modification to ensure that the modification takes effect.
|
|
164
|
-
*/ function get() {
|
|
165
|
-
var webCanvas = this._webCanvas;
|
|
166
|
-
if (typeof OffscreenCanvas === "undefined" || !_instanceof(webCanvas, OffscreenCanvas)) {
|
|
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
|
-
}
|
|
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,98 @@ 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.R16_UNorm:
|
|
406
|
+
return this.canIUse(GLCapabilityType.textureNorm16);
|
|
407
|
+
case TextureFormat.BC1:
|
|
408
|
+
case TextureFormat.BC3:
|
|
409
|
+
return this.canIUse(GLCapabilityType.s3tc);
|
|
410
|
+
case TextureFormat.BC7:
|
|
411
|
+
case TextureFormat.BC6H:
|
|
412
|
+
return this.canIUse(GLCapabilityType.bptc);
|
|
413
|
+
case TextureFormat.ETC1_RGB:
|
|
414
|
+
return this.canIUse(GLCapabilityType.etc1);
|
|
415
|
+
case TextureFormat.ETC2_RGB:
|
|
416
|
+
case TextureFormat.ETC2_RGBA5:
|
|
417
|
+
case TextureFormat.ETC2_RGBA8:
|
|
418
|
+
return this.canIUse(GLCapabilityType.etc);
|
|
419
|
+
case TextureFormat.PVRTC_RGB2:
|
|
420
|
+
case TextureFormat.PVRTC_RGBA2:
|
|
421
|
+
case TextureFormat.PVRTC_RGB4:
|
|
422
|
+
case TextureFormat.PVRTC_RGBA4:
|
|
423
|
+
return this.canIUse(GLCapabilityType.pvrtc);
|
|
424
|
+
case TextureFormat.ASTC_4x4:
|
|
425
|
+
case TextureFormat.ASTC_5x5:
|
|
426
|
+
case TextureFormat.ASTC_6x6:
|
|
427
|
+
case TextureFormat.ASTC_8x8:
|
|
428
|
+
case TextureFormat.ASTC_10x10:
|
|
429
|
+
case TextureFormat.ASTC_12x12:
|
|
430
|
+
return this.canIUse(GLCapabilityType.astc);
|
|
431
|
+
case TextureFormat.R8G8B8_UNorm:
|
|
432
|
+
case TextureFormat.R8G8B8A8_UNorm:
|
|
433
|
+
case TextureFormat.R4G4B4A4_UNorm:
|
|
434
|
+
case TextureFormat.R5G5B5A1_UNorm:
|
|
435
|
+
case TextureFormat.R5G6B5_UNorm:
|
|
436
|
+
case TextureFormat.R16G16B16A16_SFloat:
|
|
437
|
+
case TextureFormat.R32G32B32A32_SFloat:
|
|
438
|
+
case TextureFormat.R32G32B32A32_UInt:
|
|
439
|
+
case TextureFormat.R11G11B10_UFloat:
|
|
440
|
+
case TextureFormat.R16_SFloat:
|
|
441
|
+
case TextureFormat.R16G16_SFloat:
|
|
442
|
+
case TextureFormat.R32_SFloat:
|
|
443
|
+
case TextureFormat.R32G32_SFloat:
|
|
444
|
+
case TextureFormat.R8_UNorm:
|
|
445
|
+
case TextureFormat.R8G8_UNorm:
|
|
446
|
+
case TextureFormat.Depth:
|
|
447
|
+
case TextureFormat.DepthStencil:
|
|
448
|
+
case TextureFormat.Depth16:
|
|
449
|
+
case TextureFormat.Depth24:
|
|
450
|
+
case TextureFormat.Depth32:
|
|
451
|
+
case TextureFormat.Depth24Stencil8:
|
|
452
|
+
case TextureFormat.Depth32Stencil8:
|
|
453
|
+
return true;
|
|
454
|
+
default:
|
|
455
|
+
return false;
|
|
456
|
+
}
|
|
457
|
+
};
|
|
458
|
+
/**
|
|
459
|
+
* Check whether the given texture format can be rendered to as a color attachment.
|
|
460
|
+
*/ _proto.supportsRenderTargetColorFormat = function supportsRenderTargetColorFormat(format) {
|
|
461
|
+
switch(format){
|
|
462
|
+
case TextureFormat.R16G16B16A16_SFloat:
|
|
463
|
+
return this.canIUse(GLCapabilityType.colorBufferHalfFloat);
|
|
464
|
+
case TextureFormat.R16_SFloat:
|
|
465
|
+
case TextureFormat.R16G16_SFloat:
|
|
466
|
+
case TextureFormat.R32_SFloat:
|
|
467
|
+
case TextureFormat.R32G32_SFloat:
|
|
468
|
+
case TextureFormat.R32G32B32A32_SFloat:
|
|
469
|
+
case TextureFormat.R11G11B10_UFloat:
|
|
470
|
+
return this.canIUse(GLCapabilityType.colorBufferFloat);
|
|
471
|
+
default:
|
|
472
|
+
return this.supportsTextureFormat(format);
|
|
473
|
+
}
|
|
474
|
+
};
|
|
475
|
+
/**
|
|
348
476
|
* Init capabilities.
|
|
349
477
|
*/ _proto._init = function _init() {
|
|
350
478
|
var cap = this.capabilityList;
|
|
351
|
-
var isWebGL2 = this.rhi.isWebGL2;
|
|
352
479
|
var requireExtension = this.rhi.requireExtension.bind(this.rhi);
|
|
353
|
-
var
|
|
354
|
-
cap.set(
|
|
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));
|
|
480
|
+
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, textureNorm16 = GLCapabilityType.textureNorm16, textureFloatLinear = GLCapabilityType.textureFloatLinear, colorBufferFloat = GLCapabilityType.colorBufferFloat, colorBufferHalfFloat = GLCapabilityType.colorBufferHalfFloat, textureFilterAnisotropic = GLCapabilityType.textureFilterAnisotropic;
|
|
481
|
+
cap.set(textureNorm16, !!requireExtension(textureNorm16));
|
|
366
482
|
cap.set(textureFloatLinear, !!requireExtension(textureFloatLinear));
|
|
367
|
-
cap.set(
|
|
368
|
-
cap.set(
|
|
369
|
-
cap.set(colorBufferHalfFloat, isWebGL2 && !!requireExtension(colorBufferFloat) || !!requireExtension(colorBufferHalfFloat));
|
|
483
|
+
cap.set(colorBufferFloat, !!requireExtension(colorBufferFloat));
|
|
484
|
+
cap.set(colorBufferHalfFloat, !!requireExtension(colorBufferFloat) || !!requireExtension(colorBufferHalfFloat));
|
|
370
485
|
cap.set(textureFilterAnisotropic, !!requireExtension(textureFilterAnisotropic));
|
|
371
|
-
cap.set(fragDepth, isWebGL2 || !!requireExtension(fragDepth));
|
|
372
486
|
cap.set(etc, !!(requireExtension(etc) || requireExtension(etc_webkit)));
|
|
373
487
|
cap.set(etc1, !!(requireExtension(etc1) || requireExtension(etc1_webkit)));
|
|
374
488
|
cap.set(pvrtc, !!(requireExtension(pvrtc) || requireExtension(pvrtc_webkit)));
|
|
@@ -377,86 +491,7 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
377
491
|
cap.set(bptc, !!requireExtension(bptc));
|
|
378
492
|
var astcExtension = requireExtension(astc) || requireExtension(astc_webkit);
|
|
379
493
|
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
|
-
});
|
|
494
|
+
cap.set(astc_hdr, typeof (astcExtension == null ? void 0 : astcExtension.getSupportedProfiles) === "function" && astcExtension.getSupportedProfiles().includes("hdr"));
|
|
460
495
|
};
|
|
461
496
|
_create_class(GLCapability, [
|
|
462
497
|
{
|
|
@@ -466,28 +501,16 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
466
501
|
}
|
|
467
502
|
},
|
|
468
503
|
{
|
|
469
|
-
key: "
|
|
504
|
+
key: "maxVertexUniformVectors",
|
|
470
505
|
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;
|
|
506
|
+
return this.rhi.renderStates.getParameter(this.rhi.gl.MAX_VERTEX_UNIFORM_VECTORS);
|
|
480
507
|
}
|
|
481
508
|
},
|
|
482
509
|
{
|
|
483
510
|
key: "maxDrawBuffers",
|
|
484
511
|
get: function get() {
|
|
485
512
|
if (!this._maxDrawBuffers) {
|
|
486
|
-
|
|
487
|
-
this._maxDrawBuffers = this._rhi.gl.getParameter(this._rhi.gl.MAX_DRAW_BUFFERS);
|
|
488
|
-
} else {
|
|
489
|
-
this._maxDrawBuffers = 1;
|
|
490
|
-
}
|
|
513
|
+
this._maxDrawBuffers = this._rhi.gl.getParameter(this._rhi.gl.MAX_DRAW_BUFFERS);
|
|
491
514
|
}
|
|
492
515
|
return this._maxDrawBuffers;
|
|
493
516
|
}
|
|
@@ -511,19 +534,11 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
511
534
|
*/ function get() {
|
|
512
535
|
if (!this._maxAntiAliasing) {
|
|
513
536
|
var gl = this._rhi.gl;
|
|
514
|
-
|
|
515
|
-
this._maxAntiAliasing = canMSAA ? gl.getParameter(gl.MAX_SAMPLES) : 1;
|
|
537
|
+
this._maxAntiAliasing = gl.getParameter(gl.MAX_SAMPLES);
|
|
516
538
|
}
|
|
517
539
|
return this._maxAntiAliasing;
|
|
518
540
|
}
|
|
519
541
|
},
|
|
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
542
|
{
|
|
528
543
|
key: "rhi",
|
|
529
544
|
get: function get() {
|
|
@@ -555,9 +570,6 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
555
570
|
}();
|
|
556
571
|
|
|
557
572
|
/**
|
|
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
573
|
* @internal
|
|
562
574
|
* GL platform primitive.
|
|
563
575
|
*/ var GLPrimitive = /*#__PURE__*/ function() {
|
|
@@ -565,8 +577,6 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
565
577
|
this._attribLocArray = [];
|
|
566
578
|
this._vaoMap = new Map();
|
|
567
579
|
this._primitive = primitive;
|
|
568
|
-
this._canUseInstancedArrays = rhi.canIUse(GLCapabilityType.instancedArrays);
|
|
569
|
-
this._isSupportVAO = rhi.canIUse(GLCapabilityType.vertexArrayObject);
|
|
570
580
|
this._gl = rhi.gl;
|
|
571
581
|
}
|
|
572
582
|
var _proto = GLPrimitive.prototype;
|
|
@@ -575,7 +585,7 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
575
585
|
*/ _proto.draw = function draw(shaderProgram, subMesh) {
|
|
576
586
|
var gl = this._gl;
|
|
577
587
|
var primitive = this._primitive;
|
|
578
|
-
var useVao =
|
|
588
|
+
var useVao = primitive.enableVAO;
|
|
579
589
|
if (useVao) {
|
|
580
590
|
if (primitive._bufferStructChanged) {
|
|
581
591
|
this._clearVAO();
|
|
@@ -604,21 +614,17 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
604
614
|
gl.drawArrays(topology, start, count);
|
|
605
615
|
}
|
|
606
616
|
} 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
|
-
}
|
|
617
|
+
if (indexBufferBinding) {
|
|
618
|
+
if (useVao) {
|
|
619
|
+
gl.drawElementsInstanced(topology, count, _glIndexType, start * _glIndexByteCount, instanceCount);
|
|
617
620
|
} else {
|
|
618
|
-
|
|
621
|
+
var _glBuffer1 = indexBufferBinding.buffer._platformBuffer._glBuffer;
|
|
622
|
+
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, _glBuffer1);
|
|
623
|
+
gl.drawElementsInstanced(topology, count, _glIndexType, start * _glIndexByteCount, instanceCount);
|
|
624
|
+
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, null);
|
|
619
625
|
}
|
|
620
626
|
} else {
|
|
621
|
-
|
|
627
|
+
gl.drawArraysInstanced(topology, start, count, instanceCount);
|
|
622
628
|
}
|
|
623
629
|
}
|
|
624
630
|
// Unbind
|
|
@@ -629,7 +635,7 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
629
635
|
}
|
|
630
636
|
};
|
|
631
637
|
_proto.destroy = function destroy() {
|
|
632
|
-
this.
|
|
638
|
+
this._clearVAO();
|
|
633
639
|
};
|
|
634
640
|
/**
|
|
635
641
|
* Bind buffer and attribute.
|
|
@@ -657,9 +663,7 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
657
663
|
gl.enableVertexAttribArray(loc);
|
|
658
664
|
var elementInfo = element._formatMetaInfo;
|
|
659
665
|
gl.vertexAttribPointer(loc, elementInfo.size, elementInfo.type, elementInfo.normalized, stride, element.offset);
|
|
660
|
-
|
|
661
|
-
gl.vertexAttribDivisor(loc, element.instanceStepRate);
|
|
662
|
-
}
|
|
666
|
+
gl.vertexAttribDivisor(loc, element.instanceStepRate);
|
|
663
667
|
this._attribLocArray.push(loc);
|
|
664
668
|
} else {
|
|
665
669
|
Logger.warn("vertex attribute not found: " + name);
|
|
@@ -707,7 +711,6 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
707
711
|
/** cache */ this._parameters[gl.MAX_COMBINED_TEXTURE_IMAGE_UNITS] = gl.getParameter(gl.MAX_COMBINED_TEXTURE_IMAGE_UNITS);
|
|
708
712
|
this._parameters[gl.MAX_VERTEX_UNIFORM_VECTORS] = gl.getParameter(gl.MAX_VERTEX_UNIFORM_VECTORS);
|
|
709
713
|
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
714
|
this._parameters[gl.MAX_TEXTURE_SIZE] = gl.getParameter(gl.MAX_TEXTURE_SIZE);
|
|
712
715
|
// init blend state same as BlendState default value.
|
|
713
716
|
gl.blendFuncSeparate(gl.ONE, gl.ZERO, gl.ONE, gl.ZERO);
|
|
@@ -748,7 +751,6 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
748
751
|
this._texture = texture;
|
|
749
752
|
this._rhi = rhi;
|
|
750
753
|
this._gl = rhi.gl;
|
|
751
|
-
this._isWebGL2 = rhi.isWebGL2;
|
|
752
754
|
this._target = target;
|
|
753
755
|
this._glTexture = this._gl.createTexture();
|
|
754
756
|
}
|
|
@@ -771,10 +773,14 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
771
773
|
* Generate multi-level textures based on the 0th level data.
|
|
772
774
|
*/ _proto.generateMipmaps = function generateMipmaps() {
|
|
773
775
|
var texture = this._texture;
|
|
774
|
-
//@ts-ignore
|
|
775
776
|
var mipmap = texture._mipmap;
|
|
776
|
-
if (!TextureUtils.supportGenerateMipmaps(texture.format, mipmap, texture.isSRGBColorSpace
|
|
777
|
-
Logger.warn("Auto-generating mipmaps for sRGB textures is only supported in [WebGL2 +
|
|
777
|
+
if (!TextureUtils.supportGenerateMipmaps(texture.format, mipmap, texture.isSRGBColorSpace)) {
|
|
778
|
+
Logger.warn("Auto-generating mipmaps for sRGB textures is only supported in [WebGL2 + R8G8B8A8_UNorm], you must generate mipmaps manually.");
|
|
779
|
+
return;
|
|
780
|
+
}
|
|
781
|
+
// WebGL2 generateMipmap requires the format to be both color-renderable and texture-filterable
|
|
782
|
+
if (!this._rhi.supportsRenderTargetColorFormat(texture.format) || this._isFloat32Format(texture.format) && !this._rhi.canIUse(GLCapabilityType.textureFloatLinear)) {
|
|
783
|
+
Logger.warn("Auto-generating mipmaps is not supported for TextureFormat." + TextureFormat[texture.format] + " on this device.");
|
|
778
784
|
return;
|
|
779
785
|
}
|
|
780
786
|
// @todo (1x1).generateMipmap() will flash back in uc.
|
|
@@ -790,12 +796,10 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
790
796
|
* Pre-development mipmapping GPU memory.
|
|
791
797
|
*/ _proto._init = function _init(isCube) {
|
|
792
798
|
var gl = this._gl;
|
|
793
|
-
var isWebGL2 = this._isWebGL2;
|
|
794
799
|
var _this__formatDetail = this._formatDetail, internalFormat = _this__formatDetail.internalFormat, baseFormat = _this__formatDetail.baseFormat, dataType = _this__formatDetail.dataType;
|
|
795
|
-
// @ts-ignore
|
|
796
800
|
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
801
|
this._bind();
|
|
798
|
-
if (
|
|
802
|
+
if (usage !== TextureUsage.Dynamic) {
|
|
799
803
|
gl.texStorage2D(this._target, mipmapCount, internalFormat, width, height);
|
|
800
804
|
} else {
|
|
801
805
|
if (!isCube) {
|
|
@@ -829,22 +833,26 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
829
833
|
* @param mipLevel - Set mip level the data want to get from
|
|
830
834
|
*/ _proto._getPixelBuffer = function _getPixelBuffer(face, x, y, width, height, mipLevel, out) {
|
|
831
835
|
var gl = this._gl;
|
|
832
|
-
var _this__formatDetail = this._formatDetail,
|
|
836
|
+
var _this__formatDetail = this._formatDetail, dataType = _this__formatDetail.dataType, readType = _this__formatDetail.readType, alignment = _this__formatDetail.alignment;
|
|
837
|
+
var readFormat = this._getReadFormat();
|
|
833
838
|
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
839
|
if (face != null) {
|
|
839
840
|
gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_CUBE_MAP_POSITIVE_X + face, this._glTexture, mipLevel);
|
|
840
841
|
} else {
|
|
841
842
|
gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, this._glTexture, mipLevel);
|
|
842
843
|
}
|
|
843
844
|
gl.pixelStorei(gl.PACK_ALIGNMENT, alignment);
|
|
844
|
-
|
|
845
|
-
gl.readPixels(x, y, width, height, readFormat != null ? readFormat : baseFormat, dataType, out);
|
|
845
|
+
gl.readPixels(x, y, width, height, readFormat, readType != null ? readType : dataType, out);
|
|
846
846
|
gl.bindFramebuffer(gl.FRAMEBUFFER, null);
|
|
847
847
|
};
|
|
848
|
+
_proto._getReadFormat = function _getReadFormat() {
|
|
849
|
+
var format = this._texture.format;
|
|
850
|
+
if (!this._rhi.supportsRenderTargetColorFormat(format)) {
|
|
851
|
+
throw new Error("Reading pixels from TextureFormat." + TextureFormat[format] + " requires color-renderable support");
|
|
852
|
+
}
|
|
853
|
+
var _this__formatDetail = this._formatDetail, readFormat = _this__formatDetail.readFormat, baseFormat = _this__formatDetail.baseFormat;
|
|
854
|
+
return readFormat != null ? readFormat : baseFormat;
|
|
855
|
+
};
|
|
848
856
|
_proto._getReadFrameBuffer = function _getReadFrameBuffer() {
|
|
849
857
|
var frameBuffer = this._rhi._readFrameBuffer;
|
|
850
858
|
if (!frameBuffer) {
|
|
@@ -852,8 +860,8 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
852
860
|
}
|
|
853
861
|
return frameBuffer;
|
|
854
862
|
};
|
|
855
|
-
_proto._validate = function _validate(texture
|
|
856
|
-
var format = texture.format
|
|
863
|
+
_proto._validate = function _validate(texture) {
|
|
864
|
+
var format = texture.format;
|
|
857
865
|
// Validate sRGB format
|
|
858
866
|
// @ts-ignore
|
|
859
867
|
var isSRGBColorSpace = texture._isSRGBColorSpace;
|
|
@@ -862,25 +870,13 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
862
870
|
// @ts-ignore
|
|
863
871
|
texture._isSRGBColorSpace = false;
|
|
864
872
|
}
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
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
|
-
}
|
|
873
|
+
};
|
|
874
|
+
_proto._isFloat32Format = function _isFloat32Format(format) {
|
|
875
|
+
return format === TextureFormat.R32_SFloat || format === TextureFormat.R32G32_SFloat || format === TextureFormat.R32G32B32A32_SFloat;
|
|
874
876
|
};
|
|
875
877
|
_proto._setWrapMode = function _setWrapMode(value, pname) {
|
|
876
878
|
var gl = this._gl;
|
|
877
|
-
var isWebGL2 = this._isWebGL2;
|
|
878
879
|
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
880
|
switch(value){
|
|
885
881
|
case TextureWrapMode.Clamp:
|
|
886
882
|
gl.texParameteri(target, pname, gl.CLAMP_TO_EDGE);
|
|
@@ -896,92 +892,107 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
896
892
|
/**
|
|
897
893
|
* Get more texture info from TextureFormat.
|
|
898
894
|
* @internal
|
|
899
|
-
*/ GLTexture._getFormatDetail = function _getFormatDetail(format, isSRGBColorSpace, gl
|
|
895
|
+
*/ GLTexture._getFormatDetail = function _getFormatDetail(format, isSRGBColorSpace, gl) {
|
|
900
896
|
switch(format){
|
|
901
|
-
case TextureFormat.
|
|
897
|
+
case TextureFormat.R8G8B8_UNorm:
|
|
902
898
|
return {
|
|
903
|
-
internalFormat: isSRGBColorSpace ? gl.SRGB8 :
|
|
904
|
-
baseFormat:
|
|
905
|
-
readFormat: gl.
|
|
899
|
+
internalFormat: isSRGBColorSpace ? gl.SRGB8 : gl.RGB8,
|
|
900
|
+
baseFormat: gl.RGB,
|
|
901
|
+
readFormat: gl.RGBA,
|
|
906
902
|
dataType: gl.UNSIGNED_BYTE,
|
|
907
903
|
isCompressed: false,
|
|
908
904
|
alignment: 1
|
|
909
905
|
};
|
|
910
|
-
case TextureFormat.
|
|
906
|
+
case TextureFormat.R8G8B8A8_UNorm:
|
|
911
907
|
return {
|
|
912
|
-
internalFormat: isSRGBColorSpace ? gl.SRGB8_ALPHA8 :
|
|
913
|
-
baseFormat:
|
|
908
|
+
internalFormat: isSRGBColorSpace ? gl.SRGB8_ALPHA8 : gl.RGBA8,
|
|
909
|
+
baseFormat: gl.RGBA,
|
|
914
910
|
readFormat: gl.RGBA,
|
|
915
911
|
dataType: gl.UNSIGNED_BYTE,
|
|
916
912
|
isCompressed: false,
|
|
917
913
|
alignment: 4
|
|
918
914
|
};
|
|
919
|
-
case TextureFormat.
|
|
915
|
+
case TextureFormat.R4G4B4A4_UNorm:
|
|
920
916
|
return {
|
|
921
|
-
internalFormat:
|
|
917
|
+
internalFormat: gl.RGBA4,
|
|
922
918
|
baseFormat: gl.RGBA,
|
|
923
919
|
dataType: gl.UNSIGNED_SHORT_4_4_4_4,
|
|
924
920
|
isCompressed: false,
|
|
925
921
|
alignment: 2
|
|
926
922
|
};
|
|
927
|
-
case TextureFormat.
|
|
923
|
+
case TextureFormat.R5G5B5A1_UNorm:
|
|
928
924
|
return {
|
|
929
|
-
internalFormat:
|
|
925
|
+
internalFormat: gl.RGB5_A1,
|
|
930
926
|
baseFormat: gl.RGBA,
|
|
931
927
|
dataType: gl.UNSIGNED_SHORT_5_5_5_1,
|
|
932
928
|
isCompressed: false,
|
|
933
929
|
alignment: 2
|
|
934
930
|
};
|
|
935
|
-
case TextureFormat.
|
|
931
|
+
case TextureFormat.R5G6B5_UNorm:
|
|
936
932
|
return {
|
|
937
|
-
internalFormat:
|
|
933
|
+
internalFormat: gl.RGB565,
|
|
938
934
|
baseFormat: gl.RGB,
|
|
939
935
|
dataType: gl.UNSIGNED_SHORT_5_6_5,
|
|
940
936
|
isCompressed: false,
|
|
941
937
|
alignment: 2
|
|
942
938
|
};
|
|
943
|
-
case TextureFormat.
|
|
939
|
+
case TextureFormat.R16G16B16A16_SFloat:
|
|
944
940
|
return {
|
|
945
|
-
internalFormat: gl.
|
|
946
|
-
baseFormat: gl.
|
|
947
|
-
|
|
941
|
+
internalFormat: gl.RGBA16F,
|
|
942
|
+
baseFormat: gl.RGBA,
|
|
943
|
+
readFormat: gl.RGBA,
|
|
944
|
+
readType: gl.FLOAT,
|
|
945
|
+
dataType: gl.HALF_FLOAT,
|
|
948
946
|
isCompressed: false,
|
|
949
|
-
alignment:
|
|
947
|
+
alignment: 8
|
|
950
948
|
};
|
|
951
|
-
case TextureFormat.
|
|
949
|
+
case TextureFormat.R32G32B32A32_SFloat:
|
|
952
950
|
return {
|
|
953
|
-
internalFormat: gl.
|
|
954
|
-
baseFormat: gl.
|
|
955
|
-
dataType: gl.
|
|
951
|
+
internalFormat: gl.RGBA32F,
|
|
952
|
+
baseFormat: gl.RGBA,
|
|
953
|
+
dataType: gl.FLOAT,
|
|
954
|
+
isCompressed: false,
|
|
955
|
+
alignment: 8
|
|
956
|
+
};
|
|
957
|
+
case TextureFormat.R16_UNorm:
|
|
958
|
+
return {
|
|
959
|
+
internalFormat: 0x822a,
|
|
960
|
+
baseFormat: gl.RED,
|
|
961
|
+
readFormat: gl.RGBA,
|
|
962
|
+
dataType: gl.UNSIGNED_SHORT,
|
|
956
963
|
isCompressed: false,
|
|
957
964
|
alignment: 2
|
|
958
965
|
};
|
|
959
|
-
case TextureFormat.
|
|
966
|
+
case TextureFormat.R16_SFloat:
|
|
967
|
+
case TextureFormat.R16G16_SFloat:
|
|
960
968
|
return {
|
|
961
|
-
internalFormat:
|
|
962
|
-
baseFormat: gl.
|
|
969
|
+
internalFormat: format === TextureFormat.R16_SFloat ? gl.R16F : gl.RG16F,
|
|
970
|
+
baseFormat: format === TextureFormat.R16_SFloat ? gl.RED : gl.RG,
|
|
971
|
+
readFormat: gl.RGBA,
|
|
972
|
+
readType: gl.FLOAT,
|
|
963
973
|
dataType: gl.HALF_FLOAT,
|
|
964
974
|
isCompressed: false,
|
|
965
|
-
alignment:
|
|
975
|
+
alignment: 2
|
|
966
976
|
};
|
|
967
|
-
case TextureFormat.
|
|
977
|
+
case TextureFormat.R32_SFloat:
|
|
978
|
+
case TextureFormat.R32G32_SFloat:
|
|
968
979
|
return {
|
|
969
|
-
internalFormat:
|
|
970
|
-
baseFormat: gl.
|
|
980
|
+
internalFormat: format === TextureFormat.R32_SFloat ? gl.R32F : gl.RG32F,
|
|
981
|
+
baseFormat: format === TextureFormat.R32_SFloat ? gl.RED : gl.RG,
|
|
982
|
+
readFormat: gl.RGBA,
|
|
971
983
|
dataType: gl.FLOAT,
|
|
972
984
|
isCompressed: false,
|
|
973
|
-
alignment:
|
|
985
|
+
alignment: 4
|
|
974
986
|
};
|
|
975
|
-
// Only WebGL2 support
|
|
976
987
|
case TextureFormat.R11G11B10_UFloat:
|
|
977
988
|
return {
|
|
978
989
|
internalFormat: gl.R11F_G11F_B10F,
|
|
979
990
|
baseFormat: gl.RGB,
|
|
991
|
+
readFormat: gl.RGBA,
|
|
980
992
|
dataType: gl.FLOAT,
|
|
981
993
|
isCompressed: false,
|
|
982
994
|
alignment: 4
|
|
983
995
|
};
|
|
984
|
-
// Only WebGL2 support
|
|
985
996
|
case TextureFormat.R32G32B32A32_UInt:
|
|
986
997
|
return {
|
|
987
998
|
internalFormat: gl.RGBA32UI,
|
|
@@ -990,8 +1001,7 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
990
1001
|
isCompressed: false,
|
|
991
1002
|
alignment: 8
|
|
992
1003
|
};
|
|
993
|
-
|
|
994
|
-
case TextureFormat.R8:
|
|
1004
|
+
case TextureFormat.R8_UNorm:
|
|
995
1005
|
return {
|
|
996
1006
|
internalFormat: gl.R8,
|
|
997
1007
|
baseFormat: gl.RED,
|
|
@@ -999,8 +1009,7 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
999
1009
|
isCompressed: false,
|
|
1000
1010
|
alignment: 1
|
|
1001
1011
|
};
|
|
1002
|
-
|
|
1003
|
-
case TextureFormat.R8G8:
|
|
1012
|
+
case TextureFormat.R8G8_UNorm:
|
|
1004
1013
|
return {
|
|
1005
1014
|
internalFormat: gl.RG8,
|
|
1006
1015
|
baseFormat: gl.RG,
|
|
@@ -1040,7 +1049,7 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
1040
1049
|
};
|
|
1041
1050
|
case TextureFormat.ETC2_RGBA5:
|
|
1042
1051
|
return {
|
|
1043
|
-
internalFormat: GLCompressedTextureInternalFormat.RGB8_PUNCHTHROUGH_ALPHA1_ETC2,
|
|
1052
|
+
internalFormat: isSRGBColorSpace ? GLCompressedTextureInternalFormat.SRGB8_PUNCHTHROUGH_ALPHA1_ETC2 : GLCompressedTextureInternalFormat.RGB8_PUNCHTHROUGH_ALPHA1_ETC2,
|
|
1044
1053
|
isCompressed: true
|
|
1045
1054
|
};
|
|
1046
1055
|
case TextureFormat.ETC2_RGBA8:
|
|
@@ -1075,48 +1084,48 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
1075
1084
|
};
|
|
1076
1085
|
case TextureFormat.ASTC_5x5:
|
|
1077
1086
|
return {
|
|
1078
|
-
internalFormat: GLCompressedTextureInternalFormat.RGBA_ASTC_5X5_KHR,
|
|
1087
|
+
internalFormat: isSRGBColorSpace ? GLCompressedTextureInternalFormat.SRGB8_ALPHA8_ASTC_5X5_KHR : GLCompressedTextureInternalFormat.RGBA_ASTC_5X5_KHR,
|
|
1079
1088
|
isCompressed: true
|
|
1080
1089
|
};
|
|
1081
1090
|
case TextureFormat.ASTC_6x6:
|
|
1082
1091
|
return {
|
|
1083
|
-
internalFormat: GLCompressedTextureInternalFormat.RGBA_ASTC_6X6_KHR,
|
|
1092
|
+
internalFormat: isSRGBColorSpace ? GLCompressedTextureInternalFormat.SRGB8_ALPHA8_ASTC_6X6_KHR : GLCompressedTextureInternalFormat.RGBA_ASTC_6X6_KHR,
|
|
1084
1093
|
isCompressed: true
|
|
1085
1094
|
};
|
|
1086
1095
|
case TextureFormat.ASTC_8x8:
|
|
1087
1096
|
return {
|
|
1088
|
-
internalFormat: GLCompressedTextureInternalFormat.RGBA_ASTC_8X8_KHR,
|
|
1097
|
+
internalFormat: isSRGBColorSpace ? GLCompressedTextureInternalFormat.SRGB8_ALPHA8_ASTC_8X8_KHR : GLCompressedTextureInternalFormat.RGBA_ASTC_8X8_KHR,
|
|
1089
1098
|
isCompressed: true
|
|
1090
1099
|
};
|
|
1091
1100
|
case TextureFormat.ASTC_10x10:
|
|
1092
1101
|
return {
|
|
1093
|
-
internalFormat: GLCompressedTextureInternalFormat.RGBA_ASTC_10X10_KHR,
|
|
1102
|
+
internalFormat: isSRGBColorSpace ? GLCompressedTextureInternalFormat.SRGB8_ALPHA8_ASTC_10X10_KHR : GLCompressedTextureInternalFormat.RGBA_ASTC_10X10_KHR,
|
|
1094
1103
|
isCompressed: true
|
|
1095
1104
|
};
|
|
1096
1105
|
case TextureFormat.ASTC_12x12:
|
|
1097
1106
|
return {
|
|
1098
|
-
internalFormat: GLCompressedTextureInternalFormat.RGBA_ASTC_12X12_KHR,
|
|
1107
|
+
internalFormat: isSRGBColorSpace ? GLCompressedTextureInternalFormat.SRGB8_ALPHA8_ASTC_12X12_KHR : GLCompressedTextureInternalFormat.RGBA_ASTC_12X12_KHR,
|
|
1099
1108
|
isCompressed: true
|
|
1100
1109
|
};
|
|
1101
1110
|
case TextureFormat.Depth:
|
|
1102
1111
|
return {
|
|
1103
|
-
internalFormat:
|
|
1112
|
+
internalFormat: gl.DEPTH_COMPONENT32F,
|
|
1104
1113
|
baseFormat: gl.DEPTH_COMPONENT,
|
|
1105
|
-
dataType:
|
|
1114
|
+
dataType: gl.FLOAT,
|
|
1106
1115
|
isCompressed: false,
|
|
1107
1116
|
attachment: gl.DEPTH_ATTACHMENT
|
|
1108
1117
|
};
|
|
1109
1118
|
case TextureFormat.DepthStencil:
|
|
1110
1119
|
return {
|
|
1111
|
-
internalFormat:
|
|
1120
|
+
internalFormat: gl.DEPTH32F_STENCIL8,
|
|
1112
1121
|
baseFormat: gl.DEPTH_STENCIL,
|
|
1113
|
-
dataType:
|
|
1122
|
+
dataType: gl.FLOAT_32_UNSIGNED_INT_24_8_REV,
|
|
1114
1123
|
isCompressed: false,
|
|
1115
1124
|
attachment: gl.DEPTH_STENCIL_ATTACHMENT
|
|
1116
1125
|
};
|
|
1117
1126
|
case TextureFormat.Depth16:
|
|
1118
1127
|
return {
|
|
1119
|
-
internalFormat:
|
|
1128
|
+
internalFormat: gl.DEPTH_COMPONENT16,
|
|
1120
1129
|
baseFormat: gl.DEPTH_COMPONENT,
|
|
1121
1130
|
dataType: gl.UNSIGNED_SHORT,
|
|
1122
1131
|
isCompressed: false,
|
|
@@ -1124,13 +1133,12 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
1124
1133
|
};
|
|
1125
1134
|
case TextureFormat.Depth24Stencil8:
|
|
1126
1135
|
return {
|
|
1127
|
-
internalFormat:
|
|
1136
|
+
internalFormat: gl.DEPTH24_STENCIL8,
|
|
1128
1137
|
baseFormat: gl.DEPTH_STENCIL,
|
|
1129
1138
|
dataType: gl.UNSIGNED_INT_24_8,
|
|
1130
1139
|
isCompressed: false,
|
|
1131
1140
|
attachment: gl.DEPTH_STENCIL_ATTACHMENT
|
|
1132
1141
|
};
|
|
1133
|
-
// Only WebGL2 support
|
|
1134
1142
|
case TextureFormat.Depth24:
|
|
1135
1143
|
return {
|
|
1136
1144
|
internalFormat: gl.DEPTH_COMPONENT24,
|
|
@@ -1139,7 +1147,6 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
1139
1147
|
isCompressed: false,
|
|
1140
1148
|
attachment: gl.DEPTH_ATTACHMENT
|
|
1141
1149
|
};
|
|
1142
|
-
// Only WebGL2 support
|
|
1143
1150
|
case TextureFormat.Depth32:
|
|
1144
1151
|
return {
|
|
1145
1152
|
internalFormat: gl.DEPTH_COMPONENT32F,
|
|
@@ -1148,7 +1155,6 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
1148
1155
|
isCompressed: false,
|
|
1149
1156
|
attachment: gl.DEPTH_ATTACHMENT
|
|
1150
1157
|
};
|
|
1151
|
-
// Only WebGL2 support
|
|
1152
1158
|
case TextureFormat.Depth32Stencil8:
|
|
1153
1159
|
return {
|
|
1154
1160
|
internalFormat: gl.DEPTH32F_STENCIL8,
|
|
@@ -1162,23 +1168,22 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
1162
1168
|
}
|
|
1163
1169
|
};
|
|
1164
1170
|
/**
|
|
1165
|
-
* In WebGL 1, internalformat must be the same as baseFormat when call texImage2D.
|
|
1166
1171
|
* @internal
|
|
1167
|
-
*/ GLTexture._getRenderBufferDepthFormatDetail = function _getRenderBufferDepthFormatDetail(format, gl
|
|
1172
|
+
*/ GLTexture._getRenderBufferDepthFormatDetail = function _getRenderBufferDepthFormatDetail(format, gl) {
|
|
1168
1173
|
switch(format){
|
|
1169
1174
|
case TextureFormat.Depth:
|
|
1170
1175
|
return {
|
|
1171
|
-
internalFormat:
|
|
1176
|
+
internalFormat: gl.DEPTH_COMPONENT32F,
|
|
1172
1177
|
baseFormat: gl.DEPTH_COMPONENT,
|
|
1173
|
-
dataType:
|
|
1178
|
+
dataType: gl.FLOAT,
|
|
1174
1179
|
isCompressed: false,
|
|
1175
1180
|
attachment: gl.DEPTH_ATTACHMENT
|
|
1176
1181
|
};
|
|
1177
1182
|
case TextureFormat.DepthStencil:
|
|
1178
1183
|
return {
|
|
1179
|
-
internalFormat:
|
|
1184
|
+
internalFormat: gl.DEPTH32F_STENCIL8,
|
|
1180
1185
|
baseFormat: gl.DEPTH_STENCIL,
|
|
1181
|
-
dataType:
|
|
1186
|
+
dataType: gl.FLOAT_32_UNSIGNED_INT_24_8_REV,
|
|
1182
1187
|
isCompressed: false,
|
|
1183
1188
|
attachment: gl.DEPTH_STENCIL_ATTACHMENT
|
|
1184
1189
|
};
|
|
@@ -1200,7 +1205,7 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
1200
1205
|
};
|
|
1201
1206
|
case TextureFormat.Depth24Stencil8:
|
|
1202
1207
|
return {
|
|
1203
|
-
internalFormat:
|
|
1208
|
+
internalFormat: gl.DEPTH24_STENCIL8,
|
|
1204
1209
|
baseFormat: gl.DEPTH_STENCIL,
|
|
1205
1210
|
dataType: gl.UNSIGNED_INT_24_8,
|
|
1206
1211
|
isCompressed: false,
|
|
@@ -1234,46 +1239,6 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
1234
1239
|
throw new Error("this TextureFormat is not supported in Galacean Engine: " + format);
|
|
1235
1240
|
}
|
|
1236
1241
|
};
|
|
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
1242
|
_create_class(GLTexture, [
|
|
1278
1243
|
{
|
|
1279
1244
|
key: "wrapModeU",
|
|
@@ -1300,7 +1265,10 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
1300
1265
|
*/ function set(value) {
|
|
1301
1266
|
var gl = this._gl;
|
|
1302
1267
|
var target = this._target;
|
|
1303
|
-
|
|
1268
|
+
var _this__texture = this._texture, _mipmap = _this__texture._mipmap, format = _this__texture.format;
|
|
1269
|
+
if (value !== TextureFilterMode.Point && this._isFloat32Format(format) && !this._rhi.canIUse(GLCapabilityType.textureFloatLinear)) {
|
|
1270
|
+
value = TextureFilterMode.Point;
|
|
1271
|
+
}
|
|
1304
1272
|
this._bind();
|
|
1305
1273
|
switch(value){
|
|
1306
1274
|
case TextureFilterMode.Point:
|
|
@@ -1323,14 +1291,16 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
1323
1291
|
set: /**
|
|
1324
1292
|
* Anisotropic level for texture.
|
|
1325
1293
|
*/ function set(value) {
|
|
1326
|
-
var
|
|
1294
|
+
var extension = this._rhi.requireExtension(GLCapabilityType.textureFilterAnisotropic);
|
|
1295
|
+
if (!extension) return;
|
|
1327
1296
|
this._bind();
|
|
1328
|
-
|
|
1297
|
+
this._gl.texParameterf(this._target, extension.TEXTURE_MAX_ANISOTROPY_EXT, Math.min(value, this._rhi.capability.maxAnisoLevel));
|
|
1329
1298
|
}
|
|
1330
1299
|
},
|
|
1331
1300
|
{
|
|
1332
1301
|
key: "depthCompareFunction",
|
|
1333
1302
|
set: function set(value) {
|
|
1303
|
+
if (value === undefined) return;
|
|
1334
1304
|
this._bind();
|
|
1335
1305
|
var gl = this._gl;
|
|
1336
1306
|
switch(value){
|
|
@@ -1373,34 +1343,27 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
1373
1343
|
this._curMipLevel = 0;
|
|
1374
1344
|
this._curFaceIndex = undefined;
|
|
1375
1345
|
this._gl = rhi.gl;
|
|
1376
|
-
this._isWebGL2 = rhi.isWebGL2;
|
|
1377
1346
|
this._target = target;
|
|
1347
|
+
this._antiAliasing = Math.min(target.antiAliasing, rhi.capability.maxAntiAliasing);
|
|
1378
1348
|
/** @ts-ignore */ var _colorTextures = target._colorTextures, _depth = target._depth, width = target.width, height = target.height;
|
|
1379
|
-
var isDepthTexture = _instanceof(_depth, Texture);
|
|
1380
1349
|
/** todo
|
|
1381
1350
|
* MRT + Cube + [,MSAA]
|
|
1382
1351
|
* MRT + MSAA
|
|
1383
1352
|
*/ for(var i = 0, n = _colorTextures.length; i < n; i++){
|
|
1384
1353
|
var _colorTextures_i = _colorTextures[i], format = _colorTextures_i.format, isSRGBColorSpace = _colorTextures_i.isSRGBColorSpace;
|
|
1385
|
-
if (!
|
|
1354
|
+
if (!rhi.supportsRenderTargetColorFormat(format)) {
|
|
1386
1355
|
throw new Error("TextureFormat is not supported:" + TextureFormat[format] + " in RenderTarget");
|
|
1387
1356
|
}
|
|
1388
|
-
if (isSRGBColorSpace && format === TextureFormat.
|
|
1389
|
-
throw new Error("If you want to use sRGB color space, only
|
|
1357
|
+
if (isSRGBColorSpace && format === TextureFormat.R8G8B8_UNorm) {
|
|
1358
|
+
throw new Error("If you want to use sRGB color space, only R8G8B8A8_UNorm format is supported in RenderTarget");
|
|
1390
1359
|
}
|
|
1391
1360
|
}
|
|
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
1361
|
if (_colorTextures.some(function(v) {
|
|
1399
1362
|
return v.width !== width || v.height !== height;
|
|
1400
1363
|
})) {
|
|
1401
1364
|
throw new Error("ColorTexture's size must as same as RenderTarget");
|
|
1402
1365
|
}
|
|
1403
|
-
if (
|
|
1366
|
+
if (_instanceof(_depth, Texture) && (_depth.width !== width || _depth.height !== height)) {
|
|
1404
1367
|
throw new Error("DepthTexture's size must as same as RenderTarget");
|
|
1405
1368
|
}
|
|
1406
1369
|
// todo: necessary to support MRT + Cube + [,MSAA] ?
|
|
@@ -1413,7 +1376,7 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
1413
1376
|
// bind main FBO
|
|
1414
1377
|
this._bindMainFBO();
|
|
1415
1378
|
// bind MSAA FBO
|
|
1416
|
-
if (
|
|
1379
|
+
if (this._antiAliasing > 1) {
|
|
1417
1380
|
this._MSAAFrameBuffer = this._gl.createFramebuffer();
|
|
1418
1381
|
this._bindMSAAFBO();
|
|
1419
1382
|
}
|
|
@@ -1433,22 +1396,20 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
1433
1396
|
if (colorTexture) {
|
|
1434
1397
|
var isCube = _instanceof(colorTexture, TextureCube);
|
|
1435
1398
|
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);
|
|
1399
|
+
gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, isCube ? gl.TEXTURE_CUBE_MAP_POSITIVE_X + faceIndex : gl.TEXTURE_2D, colorTexture._platformTexture._glTexture, mipLevel);
|
|
1438
1400
|
}
|
|
1439
1401
|
}
|
|
1440
1402
|
var depthTexture = target.depthTexture;
|
|
1441
1403
|
if (depthTexture) {
|
|
1442
1404
|
var isCube1 = _instanceof(depthTexture, TextureCube);
|
|
1443
1405
|
if (mipChanged || isCube1) {
|
|
1444
|
-
// @ts-ignore
|
|
1445
1406
|
var platformTexture = depthTexture._platformTexture;
|
|
1446
1407
|
gl.framebufferTexture2D(gl.FRAMEBUFFER, platformTexture._formatDetail.attachment, isCube1 ? gl.TEXTURE_CUBE_MAP_POSITIVE_X + faceIndex : gl.TEXTURE_2D, platformTexture._glTexture, mipLevel);
|
|
1447
1408
|
}
|
|
1448
1409
|
} else {
|
|
1449
1410
|
if (mipChanged) {
|
|
1450
1411
|
// @ts-ignore
|
|
1451
|
-
var internalFormat = GLTexture._getRenderBufferDepthFormatDetail(target._depth, gl
|
|
1412
|
+
var internalFormat = GLTexture._getRenderBufferDepthFormatDetail(target._depth, gl).internalFormat;
|
|
1452
1413
|
gl.bindRenderbuffer(gl.RENDERBUFFER, this._depthRenderBuffer);
|
|
1453
1414
|
gl.renderbufferStorage(gl.RENDERBUFFER, internalFormat, target.width >> mipLevel, target.height >> mipLevel);
|
|
1454
1415
|
}
|
|
@@ -1497,8 +1458,7 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
1497
1458
|
};
|
|
1498
1459
|
_proto._bindMainFBO = function _bindMainFBO() {
|
|
1499
1460
|
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;
|
|
1461
|
+
var _this__target = this._target, _depth = _this__target._depth, colorTextureCount = _this__target.colorTextureCount; _this__target.width; _this__target.height;
|
|
1502
1462
|
var drawBuffers = new Array(colorTextureCount);
|
|
1503
1463
|
gl.bindFramebuffer(gl.FRAMEBUFFER, this._frameBuffer);
|
|
1504
1464
|
/** color render buffer */ for(var i = 0; i < colorTextureCount; i++){
|
|
@@ -1506,7 +1466,7 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
1506
1466
|
var attachment = gl.COLOR_ATTACHMENT0 + i;
|
|
1507
1467
|
drawBuffers[i] = attachment;
|
|
1508
1468
|
if (!_instanceof(colorTexture, TextureCube)) {
|
|
1509
|
-
gl.framebufferTexture2D(gl.FRAMEBUFFER, attachment, gl.TEXTURE_2D,
|
|
1469
|
+
gl.framebufferTexture2D(gl.FRAMEBUFFER, attachment, gl.TEXTURE_2D, colorTexture._platformTexture._glTexture, 0);
|
|
1510
1470
|
}
|
|
1511
1471
|
}
|
|
1512
1472
|
if (colorTextureCount > 1) {
|
|
@@ -1514,17 +1474,14 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
1514
1474
|
}
|
|
1515
1475
|
this._oriDrawBuffers = drawBuffers;
|
|
1516
1476
|
/** 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);
|
|
1477
|
+
if (_instanceof(_depth, Texture)) {
|
|
1478
|
+
if (!_instanceof(_depth, TextureCube)) {
|
|
1479
|
+
var platformTexture = _depth._platformTexture;
|
|
1480
|
+
gl.framebufferTexture2D(gl.FRAMEBUFFER, platformTexture._formatDetail.attachment, gl.TEXTURE_2D, platformTexture._glTexture, 0);
|
|
1481
|
+
}
|
|
1482
|
+
} else if (this._antiAliasing <= 1) {
|
|
1483
|
+
var _GLTexture__getRenderBufferDepthFormatDetail = GLTexture._getRenderBufferDepthFormatDetail(_depth, gl), internalFormat = _GLTexture__getRenderBufferDepthFormatDetail.internalFormat, attachment1 = _GLTexture__getRenderBufferDepthFormatDetail.attachment;
|
|
1484
|
+
this._depthRenderBuffer = this._createRenderBuffer(internalFormat, attachment1);
|
|
1528
1485
|
}
|
|
1529
1486
|
}
|
|
1530
1487
|
gl.bindFramebuffer(gl.FRAMEBUFFER, null);
|
|
@@ -1532,33 +1489,39 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
1532
1489
|
};
|
|
1533
1490
|
_proto._bindMSAAFBO = function _bindMSAAFBO() {
|
|
1534
1491
|
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;
|
|
1492
|
+
var _this__target = this._target, _depth = _this__target._depth, colorTextureCount = _this__target.colorTextureCount;
|
|
1538
1493
|
this._blitDrawBuffers = new Array(colorTextureCount);
|
|
1539
|
-
this._MSAADepthRenderBuffer = MSAADepthRenderBuffer;
|
|
1540
1494
|
gl.bindFramebuffer(gl.FRAMEBUFFER, this._MSAAFrameBuffer);
|
|
1541
1495
|
// prepare MRT+MSAA color RBOs
|
|
1542
1496
|
for(var i = 0; i < colorTextureCount; i++){
|
|
1543
|
-
var MSAAColorRenderBuffer = gl.createRenderbuffer();
|
|
1544
|
-
this._MSAAColorRenderBuffers[i] = MSAAColorRenderBuffer;
|
|
1545
1497
|
this._blitDrawBuffers[i] = gl.NONE;
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
gl.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0 + i, gl.RENDERBUFFER, MSAAColorRenderBuffer);
|
|
1498
|
+
var internalFormat = this._target.getColorTexture(i)._platformTexture._formatDetail.internalFormat;
|
|
1499
|
+
this._MSAAColorRenderBuffers[i] = this._createRenderBuffer(internalFormat, gl.COLOR_ATTACHMENT0 + i);
|
|
1549
1500
|
}
|
|
1550
1501
|
gl.drawBuffers(this._oriDrawBuffers);
|
|
1551
1502
|
// prepare MSAA depth RBO
|
|
1552
1503
|
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);
|
|
1504
|
+
var _ref = _instanceof(_depth, Texture) ? _depth._platformTexture._formatDetail : GLTexture._getRenderBufferDepthFormatDetail(_depth, gl), internalFormat1 = _ref.internalFormat, attachment = _ref.attachment;
|
|
1505
|
+
this._MSAADepthRenderBuffer = this._createRenderBuffer(internalFormat1, attachment);
|
|
1557
1506
|
}
|
|
1558
1507
|
this._checkFrameBuffer();
|
|
1559
1508
|
gl.bindFramebuffer(gl.FRAMEBUFFER, null);
|
|
1560
1509
|
gl.bindRenderbuffer(gl.RENDERBUFFER, null);
|
|
1561
1510
|
};
|
|
1511
|
+
_proto._createRenderBuffer = function _createRenderBuffer(internalFormat, attachment) {
|
|
1512
|
+
var gl = this._gl;
|
|
1513
|
+
var _this__target = this._target, width = _this__target.width, height = _this__target.height;
|
|
1514
|
+
var antiAliasing = this._antiAliasing;
|
|
1515
|
+
var renderBuffer = gl.createRenderbuffer();
|
|
1516
|
+
gl.bindRenderbuffer(gl.RENDERBUFFER, renderBuffer);
|
|
1517
|
+
if (antiAliasing > 1) {
|
|
1518
|
+
gl.renderbufferStorageMultisample(gl.RENDERBUFFER, antiAliasing, internalFormat, width, height);
|
|
1519
|
+
} else {
|
|
1520
|
+
gl.renderbufferStorage(gl.RENDERBUFFER, internalFormat, width, height);
|
|
1521
|
+
}
|
|
1522
|
+
gl.framebufferRenderbuffer(gl.FRAMEBUFFER, attachment, gl.RENDERBUFFER, renderBuffer);
|
|
1523
|
+
return renderBuffer;
|
|
1524
|
+
};
|
|
1562
1525
|
_proto._checkFrameBuffer = function _checkFrameBuffer() {
|
|
1563
1526
|
var gl = this._gl;
|
|
1564
1527
|
var e = gl.checkFramebufferStatus(gl.FRAMEBUFFER);
|
|
@@ -1588,12 +1551,11 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
1588
1551
|
_inherits(GLTexture2D, GLTexture1);
|
|
1589
1552
|
function GLTexture2D(rhi, texture2D) {
|
|
1590
1553
|
var _this;
|
|
1591
|
-
_this = GLTexture1.call(this, rhi, texture2D, rhi.gl.TEXTURE_2D) || this
|
|
1592
|
-
_this._validate(texture2D
|
|
1554
|
+
_this = GLTexture1.call(this, rhi, texture2D, rhi.gl.TEXTURE_2D) || this;
|
|
1555
|
+
_this._validate(texture2D);
|
|
1593
1556
|
var format = texture2D.format, isSRGBColorSpace = texture2D.isSRGBColorSpace;
|
|
1594
|
-
|
|
1595
|
-
_this.
|
|
1596
|
-
_this._formatDetail.isCompressed && !isWebGL2 || _this._init(false);
|
|
1557
|
+
_this._formatDetail = GLTexture._getFormatDetail(format, isSRGBColorSpace, _this._gl);
|
|
1558
|
+
_this._init(false);
|
|
1597
1559
|
return _this;
|
|
1598
1560
|
}
|
|
1599
1561
|
var _proto = GLTexture2D.prototype;
|
|
@@ -1609,15 +1571,7 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
1609
1571
|
height = height || mipHeight - y;
|
|
1610
1572
|
this._bind();
|
|
1611
1573
|
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
|
-
}
|
|
1574
|
+
gl.compressedTexSubImage2D(this._target, mipLevel, x, y, width, height, formatDetail.internalFormat, colorBuffer);
|
|
1621
1575
|
} else {
|
|
1622
1576
|
var baseFormat = formatDetail.baseFormat, dataType = formatDetail.dataType;
|
|
1623
1577
|
gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, 0);
|
|
@@ -1658,10 +1612,10 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
1658
1612
|
function GLTexture2DArray(rhi, texture2DArray) {
|
|
1659
1613
|
var _this;
|
|
1660
1614
|
_this = GLTexture1.call(this, rhi, texture2DArray, rhi.gl.TEXTURE_2D_ARRAY) || this;
|
|
1661
|
-
_this._validate(texture2DArray
|
|
1615
|
+
_this._validate(texture2DArray);
|
|
1662
1616
|
var format = texture2DArray.format, width = texture2DArray.width, height = texture2DArray.height, length = texture2DArray.length, mipmapCount = texture2DArray.mipmapCount, isSRGBColorSpace = texture2DArray.isSRGBColorSpace;
|
|
1663
1617
|
_this._bind();
|
|
1664
|
-
_this._formatDetail = GLTexture._getFormatDetail(format, isSRGBColorSpace, _this._gl
|
|
1618
|
+
_this._formatDetail = GLTexture._getFormatDetail(format, isSRGBColorSpace, _this._gl);
|
|
1665
1619
|
_this._gl.texStorage3D(_this._target, mipmapCount, _this._formatDetail.internalFormat, width, height, length);
|
|
1666
1620
|
return _this;
|
|
1667
1621
|
}
|
|
@@ -1676,12 +1630,12 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
1676
1630
|
height = height || Math.max(1, this._texture.height >> mipLevel) - y;
|
|
1677
1631
|
length = length || this._texture.length;
|
|
1678
1632
|
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
1633
|
if (isCompressed) {
|
|
1683
1634
|
gl.compressedTexSubImage3D(target, mipLevel, x, y, offsetIndex, width, height, length, internalFormat, colorBuffer);
|
|
1684
1635
|
} else {
|
|
1636
|
+
gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, 0);
|
|
1637
|
+
gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, 0);
|
|
1638
|
+
gl.pixelStorei(gl.UNPACK_ALIGNMENT, formatDetail.alignment);
|
|
1685
1639
|
gl.texSubImage3D(target, mipLevel, x, y, offsetIndex, width, height, length, baseFormat, dataType, colorBuffer);
|
|
1686
1640
|
}
|
|
1687
1641
|
};
|
|
@@ -1703,13 +1657,15 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
1703
1657
|
if (formatDetail.isCompressed) {
|
|
1704
1658
|
throw new Error("Unable to read compressed texture");
|
|
1705
1659
|
}
|
|
1660
|
+
var readFormat = this._getReadFormat();
|
|
1706
1661
|
gl.pixelStorei(gl.PACK_ALIGNMENT, formatDetail.alignment);
|
|
1707
1662
|
gl.bindFramebuffer(gl.FRAMEBUFFER, this._getReadFrameBuffer());
|
|
1708
1663
|
gl.framebufferTextureLayer(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, this._glTexture, mipLevel, elementIndex);
|
|
1709
|
-
|
|
1664
|
+
var _formatDetail_readType;
|
|
1665
|
+
gl.readPixels(x, y, width, height, readFormat, (_formatDetail_readType = formatDetail.readType) != null ? _formatDetail_readType : formatDetail.dataType, out);
|
|
1710
1666
|
gl.bindFramebuffer(gl.FRAMEBUFFER, null);
|
|
1711
1667
|
};
|
|
1712
|
-
_proto._validate = function _validate(texture
|
|
1668
|
+
_proto._validate = function _validate(texture) {
|
|
1713
1669
|
var format = texture.format;
|
|
1714
1670
|
// Validate sRGB format
|
|
1715
1671
|
// @ts-ignore
|
|
@@ -1729,19 +1685,11 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
1729
1685
|
_inherits(GLTextureCube, GLTexture1);
|
|
1730
1686
|
function GLTextureCube(rhi, textureCube) {
|
|
1731
1687
|
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);
|
|
1688
|
+
_this = GLTexture1.call(this, rhi, textureCube, rhi.gl.TEXTURE_CUBE_MAP) || this;
|
|
1689
|
+
_this._validate(textureCube);
|
|
1741
1690
|
var format = textureCube.format, isSRGBColorSpace = textureCube.isSRGBColorSpace;
|
|
1742
|
-
|
|
1743
|
-
_this.
|
|
1744
|
-
_this._formatDetail.isCompressed && !isWebGL2 || _this._init(true);
|
|
1691
|
+
_this._formatDetail = GLTexture._getFormatDetail(format, isSRGBColorSpace, _this._gl);
|
|
1692
|
+
_this._init(true);
|
|
1745
1693
|
return _this;
|
|
1746
1694
|
}
|
|
1747
1695
|
var _proto = GLTextureCube.prototype;
|
|
@@ -1749,25 +1697,18 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
1749
1697
|
* {@inheritDoc IPlatformTextureCube.setPixelBuffer}
|
|
1750
1698
|
*/ _proto.setPixelBuffer = function setPixelBuffer(face, colorBuffer, mipLevel, x, y, width, height) {
|
|
1751
1699
|
var gl = this._gl;
|
|
1752
|
-
var isWebGL2 = this._isWebGL2;
|
|
1753
1700
|
var formatDetail = this._formatDetail;
|
|
1754
|
-
var
|
|
1701
|
+
var baseFormat = formatDetail.baseFormat, dataType = formatDetail.dataType, isCompressed = formatDetail.isCompressed;
|
|
1755
1702
|
var mipSize = Math.max(1, this._texture.width >> mipLevel);
|
|
1756
1703
|
width = width || mipSize - x;
|
|
1757
1704
|
height = height || mipSize - y;
|
|
1758
1705
|
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
1706
|
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
|
-
}
|
|
1707
|
+
gl.compressedTexSubImage2D(gl.TEXTURE_CUBE_MAP_POSITIVE_X + face, mipLevel, x, y, width, height, formatDetail.internalFormat, colorBuffer);
|
|
1770
1708
|
} else {
|
|
1709
|
+
gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, 0);
|
|
1710
|
+
gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, 0);
|
|
1711
|
+
gl.pixelStorei(gl.UNPACK_ALIGNMENT, formatDetail.alignment);
|
|
1771
1712
|
gl.texSubImage2D(gl.TEXTURE_CUBE_MAP_POSITIVE_X + face, mipLevel, x, y, width, height, baseFormat, dataType, colorBuffer);
|
|
1772
1713
|
}
|
|
1773
1714
|
};
|
|
@@ -1793,18 +1734,150 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
1793
1734
|
}(GLTexture);
|
|
1794
1735
|
|
|
1795
1736
|
/**
|
|
1796
|
-
*
|
|
1797
|
-
|
|
1798
|
-
|
|
1799
|
-
|
|
1800
|
-
|
|
1801
|
-
|
|
1802
|
-
|
|
1737
|
+
* @internal
|
|
1738
|
+
* WebGL2 implementation of Transform Feedback.
|
|
1739
|
+
*/ var GLTransformFeedback = /*#__PURE__*/ function() {
|
|
1740
|
+
function GLTransformFeedback(rhi) {
|
|
1741
|
+
var gl = rhi.gl;
|
|
1742
|
+
this._gl = gl;
|
|
1743
|
+
this._glTransformFeedback = gl.createTransformFeedback();
|
|
1744
|
+
}
|
|
1745
|
+
var _proto = GLTransformFeedback.prototype;
|
|
1746
|
+
_proto.bindBufferRange = function bindBufferRange(index, buffer, byteOffset, byteSize) {
|
|
1747
|
+
var gl = this._gl;
|
|
1748
|
+
gl.bindBufferRange(gl.TRANSFORM_FEEDBACK_BUFFER, index, buffer._glBuffer, byteOffset, byteSize);
|
|
1749
|
+
};
|
|
1750
|
+
_proto.unbindBuffer = function unbindBuffer(index) {
|
|
1751
|
+
var gl = this._gl;
|
|
1752
|
+
gl.bindBufferBase(gl.TRANSFORM_FEEDBACK_BUFFER, index, null);
|
|
1753
|
+
};
|
|
1754
|
+
_proto.begin = function begin(primitiveMode) {
|
|
1755
|
+
this._gl.beginTransformFeedback(primitiveMode);
|
|
1756
|
+
};
|
|
1757
|
+
_proto.end = function end() {
|
|
1758
|
+
this._gl.endTransformFeedback();
|
|
1759
|
+
};
|
|
1760
|
+
_proto.bind = function bind() {
|
|
1761
|
+
var gl = this._gl;
|
|
1762
|
+
gl.bindTransformFeedback(gl.TRANSFORM_FEEDBACK, this._glTransformFeedback);
|
|
1763
|
+
};
|
|
1764
|
+
_proto.unbind = function unbind() {
|
|
1765
|
+
var gl = this._gl;
|
|
1766
|
+
gl.bindTransformFeedback(gl.TRANSFORM_FEEDBACK, null);
|
|
1767
|
+
};
|
|
1768
|
+
_proto.destroy = function destroy() {
|
|
1769
|
+
if (this._glTransformFeedback) {
|
|
1770
|
+
this._gl.deleteTransformFeedback(this._glTransformFeedback);
|
|
1771
|
+
this._glTransformFeedback = null;
|
|
1772
|
+
}
|
|
1773
|
+
};
|
|
1774
|
+
return GLTransformFeedback;
|
|
1775
|
+
}();
|
|
1776
|
+
|
|
1803
1777
|
/**
|
|
1804
|
-
*
|
|
1778
|
+
* @internal
|
|
1779
|
+
* WebGL2 implementation of Transform Feedback primitive.
|
|
1780
|
+
* Maintains two VAOs (one per read direction), rebuilding when the program or input bindings change.
|
|
1781
|
+
*/ var GLTransformFeedbackPrimitive = /*#__PURE__*/ function() {
|
|
1782
|
+
function GLTransformFeedbackPrimitive(gl) {
|
|
1783
|
+
this._lastProgramId = -1;
|
|
1784
|
+
this._lastInputBindings = [];
|
|
1785
|
+
this._gl = gl;
|
|
1786
|
+
}
|
|
1787
|
+
var _proto = GLTransformFeedbackPrimitive.prototype;
|
|
1788
|
+
_proto.bind = function bind(program, bindingA, bindingB, feedbackElements, inputBindings, inputElements, readIsA) {
|
|
1789
|
+
var layoutChanged = program.id !== this._lastProgramId;
|
|
1790
|
+
var lastInputBindings = this._lastInputBindings;
|
|
1791
|
+
if (!layoutChanged) {
|
|
1792
|
+
if (inputBindings.length !== lastInputBindings.length) {
|
|
1793
|
+
layoutChanged = true;
|
|
1794
|
+
} else {
|
|
1795
|
+
for(var i = 0, n = inputBindings.length; i < n; i++){
|
|
1796
|
+
if (inputBindings[i] !== lastInputBindings[i]) {
|
|
1797
|
+
layoutChanged = true;
|
|
1798
|
+
break;
|
|
1799
|
+
}
|
|
1800
|
+
}
|
|
1801
|
+
}
|
|
1802
|
+
}
|
|
1803
|
+
if (layoutChanged) {
|
|
1804
|
+
this._deleteVAOs();
|
|
1805
|
+
var attribs = program.attributeLocation;
|
|
1806
|
+
this._vaoA = this._createVAO(attribs, bindingA, feedbackElements, inputBindings, inputElements);
|
|
1807
|
+
this._vaoB = this._createVAO(attribs, bindingB, feedbackElements, inputBindings, inputElements);
|
|
1808
|
+
this._lastProgramId = program.id;
|
|
1809
|
+
lastInputBindings.length = inputBindings.length;
|
|
1810
|
+
for(var i1 = 0, n1 = inputBindings.length; i1 < n1; i1++){
|
|
1811
|
+
lastInputBindings[i1] = inputBindings[i1];
|
|
1812
|
+
}
|
|
1813
|
+
this._gl.bindVertexArray(null);
|
|
1814
|
+
}
|
|
1815
|
+
this._gl.bindVertexArray(readIsA ? this._vaoA : this._vaoB);
|
|
1816
|
+
};
|
|
1817
|
+
_proto.unbind = function unbind() {
|
|
1818
|
+
this._gl.bindVertexArray(null);
|
|
1819
|
+
};
|
|
1820
|
+
_proto.draw = function draw(mode, first, count) {
|
|
1821
|
+
this._gl.drawArrays(mode, first, count);
|
|
1822
|
+
};
|
|
1823
|
+
_proto.invalidate = function invalidate() {
|
|
1824
|
+
this._deleteVAOs();
|
|
1825
|
+
};
|
|
1826
|
+
_proto.destroy = function destroy() {
|
|
1827
|
+
this._deleteVAOs();
|
|
1828
|
+
};
|
|
1829
|
+
_proto._deleteVAOs = function _deleteVAOs() {
|
|
1830
|
+
var gl = this._gl;
|
|
1831
|
+
if (this._vaoA) {
|
|
1832
|
+
gl.deleteVertexArray(this._vaoA);
|
|
1833
|
+
this._vaoA = null;
|
|
1834
|
+
}
|
|
1835
|
+
if (this._vaoB) {
|
|
1836
|
+
gl.deleteVertexArray(this._vaoB);
|
|
1837
|
+
this._vaoB = null;
|
|
1838
|
+
}
|
|
1839
|
+
this._lastProgramId = -1;
|
|
1840
|
+
this._lastInputBindings.length = 0;
|
|
1841
|
+
};
|
|
1842
|
+
_proto._createVAO = function _createVAO(attribs, feedbackBinding, feedbackElements, inputBindings, inputElements) {
|
|
1843
|
+
var gl = this._gl;
|
|
1844
|
+
var vao = gl.createVertexArray();
|
|
1845
|
+
gl.bindVertexArray(vao);
|
|
1846
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, feedbackBinding.buffer._platformBuffer._glBuffer);
|
|
1847
|
+
for(var i = 0, n = feedbackElements.length; i < n; i++){
|
|
1848
|
+
this._bindElement(attribs, feedbackElements[i], feedbackBinding.stride);
|
|
1849
|
+
}
|
|
1850
|
+
var lastInputBinding;
|
|
1851
|
+
for(var i1 = 0, n1 = inputElements.length; i1 < n1; i1++){
|
|
1852
|
+
var element = inputElements[i1];
|
|
1853
|
+
var inputBinding = inputBindings[element.bindingIndex];
|
|
1854
|
+
if (inputBinding !== lastInputBinding) {
|
|
1855
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, inputBinding.buffer._platformBuffer._glBuffer);
|
|
1856
|
+
lastInputBinding = inputBinding;
|
|
1857
|
+
}
|
|
1858
|
+
this._bindElement(attribs, element, inputBinding.stride);
|
|
1859
|
+
}
|
|
1860
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, null);
|
|
1861
|
+
return vao;
|
|
1862
|
+
};
|
|
1863
|
+
_proto._bindElement = function _bindElement(attribs, element, stride) {
|
|
1864
|
+
var gl = this._gl;
|
|
1865
|
+
var loc = attribs[element.attribute];
|
|
1866
|
+
if (loc !== undefined && loc !== -1) {
|
|
1867
|
+
var info = element._formatMetaInfo;
|
|
1868
|
+
gl.enableVertexAttribArray(loc);
|
|
1869
|
+
gl.vertexAttribPointer(loc, info.size, info.type, info.normalized, stride, element.offset);
|
|
1870
|
+
}
|
|
1871
|
+
};
|
|
1872
|
+
return GLTransformFeedbackPrimitive;
|
|
1873
|
+
}();
|
|
1874
|
+
|
|
1875
|
+
/**
|
|
1876
|
+
* WebGL graphic device, using WebGL2.0.
|
|
1805
1877
|
*/ var WebGLGraphicDevice = /*#__PURE__*/ function() {
|
|
1806
1878
|
function WebGLGraphicDevice(initializeOptions) {
|
|
1807
1879
|
if (initializeOptions === void 0) initializeOptions = {};
|
|
1880
|
+
this.supportsRendering = true;
|
|
1808
1881
|
/** @internal */ this._readFrameBuffer = null;
|
|
1809
1882
|
/** @internal */ this._mainFrameBuffer = null;
|
|
1810
1883
|
/** @internal */ this._mainFrameWidth = 0;
|
|
@@ -1816,7 +1889,6 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
1816
1889
|
this._lastClearColor = new Color(null, null, null, null);
|
|
1817
1890
|
this._scissorEnable = false;
|
|
1818
1891
|
var options = _extends({
|
|
1819
|
-
webGLMode: 0,
|
|
1820
1892
|
_forceFlush: false,
|
|
1821
1893
|
_maxAllowSkinUniformVectorCount: 256,
|
|
1822
1894
|
alpha: true,
|
|
@@ -1859,40 +1931,26 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
1859
1931
|
var _proto = WebGLGraphicDevice.prototype;
|
|
1860
1932
|
_proto.init = function init(canvas, onDeviceLost, onDeviceRestored) {
|
|
1861
1933
|
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
1934
|
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))) {
|
|
1935
|
+
try {
|
|
1936
|
+
var webGLOptions = this._webGLOptions;
|
|
1937
|
+
var gl = webCanvas.getContext("webgl2", webGLOptions);
|
|
1938
|
+
if (!gl && !canvas._isOffscreenCanvas()) {
|
|
1874
1939
|
gl = webCanvas.getContext("experimental-webgl2", webGLOptions);
|
|
1875
1940
|
}
|
|
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;
|
|
1941
|
+
if (!gl || !gl.deleteQuery) {
|
|
1942
|
+
throw new Error("WebGL2 is not supported.");
|
|
1889
1943
|
}
|
|
1944
|
+
this._gl = gl;
|
|
1945
|
+
this._initGLState(gl);
|
|
1946
|
+
} finally{
|
|
1947
|
+
webCanvas.removeEventListener("webglcontextcreationerror", this._onContextCreationError, false);
|
|
1890
1948
|
}
|
|
1891
|
-
|
|
1892
|
-
|
|
1893
|
-
|
|
1894
|
-
this.
|
|
1895
|
-
this.
|
|
1949
|
+
this._webCanvas = webCanvas;
|
|
1950
|
+
this._onDeviceLost = onDeviceLost;
|
|
1951
|
+
this._onDeviceRestored = onDeviceRestored;
|
|
1952
|
+
webCanvas.addEventListener("webglcontextlost", this._onWebGLContextLost, false);
|
|
1953
|
+
webCanvas.addEventListener("webglcontextrestored", this._onWebGLContextRestored, false);
|
|
1896
1954
|
};
|
|
1897
1955
|
_proto.createPlatformPrimitive = function createPlatformPrimitive(primitive) {
|
|
1898
1956
|
return new GLPrimitive(this, primitive);
|
|
@@ -1913,6 +1971,45 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
1913
1971
|
if (bufferUsage === void 0) bufferUsage = BufferUsage.Static;
|
|
1914
1972
|
return new GLBuffer(this, type, byteLength, bufferUsage, data);
|
|
1915
1973
|
};
|
|
1974
|
+
_proto.createPlatformTransformFeedback = function createPlatformTransformFeedback() {
|
|
1975
|
+
return new GLTransformFeedback(this);
|
|
1976
|
+
};
|
|
1977
|
+
_proto.createPlatformTransformFeedbackPrimitive = function createPlatformTransformFeedbackPrimitive() {
|
|
1978
|
+
return new GLTransformFeedbackPrimitive(this._gl);
|
|
1979
|
+
};
|
|
1980
|
+
_proto.bindUniformBufferBase = function bindUniformBufferBase(bindingPoint, buffer) {
|
|
1981
|
+
var gl = this._gl;
|
|
1982
|
+
gl.bindBufferBase(gl.UNIFORM_BUFFER, bindingPoint, buffer._glBuffer);
|
|
1983
|
+
};
|
|
1984
|
+
_proto.bindUniformBlock = function bindUniformBlock(program, blockName, bindingPoint) {
|
|
1985
|
+
var gl = this._gl;
|
|
1986
|
+
var blockIndex = gl.getUniformBlockIndex(program, blockName);
|
|
1987
|
+
if (blockIndex !== gl.INVALID_INDEX) {
|
|
1988
|
+
gl.uniformBlockBinding(program, blockIndex, bindingPoint);
|
|
1989
|
+
}
|
|
1990
|
+
return blockIndex;
|
|
1991
|
+
};
|
|
1992
|
+
/**
|
|
1993
|
+
* Enable GL_RASTERIZER_DISCARD (WebGL2 only).
|
|
1994
|
+
*/ _proto.enableRasterizerDiscard = function enableRasterizerDiscard() {
|
|
1995
|
+
var gl = this._gl;
|
|
1996
|
+
gl.enable(gl.RASTERIZER_DISCARD);
|
|
1997
|
+
};
|
|
1998
|
+
/**
|
|
1999
|
+
* Disable GL_RASTERIZER_DISCARD (WebGL2 only).
|
|
2000
|
+
*/ _proto.disableRasterizerDiscard = function disableRasterizerDiscard() {
|
|
2001
|
+
var gl = this._gl;
|
|
2002
|
+
gl.disable(gl.RASTERIZER_DISCARD);
|
|
2003
|
+
};
|
|
2004
|
+
/**
|
|
2005
|
+
* Invalidate the cached shader program state.
|
|
2006
|
+
* Call this after using a custom program (e.g., Transform Feedback) outside the engine's pipeline.
|
|
2007
|
+
*/ _proto.invalidateShaderProgramState = function invalidateShaderProgramState() {
|
|
2008
|
+
if (this._currentBindShaderProgram) {
|
|
2009
|
+
this._gl.useProgram(null);
|
|
2010
|
+
this._currentBindShaderProgram = null;
|
|
2011
|
+
}
|
|
2012
|
+
};
|
|
1916
2013
|
_proto.requireExtension = function requireExtension(ext) {
|
|
1917
2014
|
return this._extensions.requireExtension(ext);
|
|
1918
2015
|
};
|
|
@@ -1922,6 +2019,12 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
1922
2019
|
_proto.canIUseCompressedTextureInternalFormat = function canIUseCompressedTextureInternalFormat(type) {
|
|
1923
2020
|
return this.capability.canIUseCompressedTextureInternalFormat(type);
|
|
1924
2021
|
};
|
|
2022
|
+
_proto.supportsTextureFormat = function supportsTextureFormat(format) {
|
|
2023
|
+
return this.capability.supportsTextureFormat(format);
|
|
2024
|
+
};
|
|
2025
|
+
_proto.supportsRenderTargetColorFormat = function supportsRenderTargetColorFormat(format) {
|
|
2026
|
+
return this.capability.supportsRenderTargetColorFormat(format);
|
|
2027
|
+
};
|
|
1925
2028
|
_proto.viewport = function viewport(x, y, width, height) {
|
|
1926
2029
|
var _this = this, gl = _this._gl, lastViewport = _this._lastViewport;
|
|
1927
2030
|
if (x !== lastViewport.x || y !== lastViewport.y || width !== lastViewport.z || height !== lastViewport.w) {
|
|
@@ -1986,7 +2089,7 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
1986
2089
|
};
|
|
1987
2090
|
_proto.drawPrimitive = function drawPrimitive(primitive, subPrimitive, shaderProgram) {
|
|
1988
2091
|
// todo: VAO not support morph animation
|
|
1989
|
-
if (primitive) {
|
|
2092
|
+
if (primitive && subPrimitive) {
|
|
1990
2093
|
primitive.draw(shaderProgram, subPrimitive);
|
|
1991
2094
|
} else {
|
|
1992
2095
|
Logger.error("draw primitive failed.");
|
|
@@ -2001,8 +2104,8 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
2001
2104
|
_proto.activeRenderTarget = function activeRenderTarget(renderTarget, viewport, isFlipProjection, mipLevel, faceIndex) {
|
|
2002
2105
|
var bufferWidth, bufferHeight;
|
|
2003
2106
|
if (renderTarget) {
|
|
2004
|
-
|
|
2005
|
-
|
|
2107
|
+
renderTarget._isContentLost = false;
|
|
2108
|
+
var platformRenderTarget = renderTarget._platformRenderTarget;
|
|
2006
2109
|
platformRenderTarget.activeRenderTarget(mipLevel, faceIndex);
|
|
2007
2110
|
bufferWidth = renderTarget.width >> mipLevel;
|
|
2008
2111
|
bufferHeight = renderTarget.height >> mipLevel;
|
|
@@ -2020,10 +2123,6 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
2020
2123
|
this.scissor(x, y, width, height);
|
|
2021
2124
|
};
|
|
2022
2125
|
_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
2126
|
var gl = this._gl;
|
|
2028
2127
|
// @ts-ignore
|
|
2029
2128
|
var srcFrameBuffer = srcRT ? srcRT._platformRenderTarget._frameBuffer : null;
|
|
@@ -2043,7 +2142,6 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
2043
2142
|
gl.bindFramebuffer(gl.DRAW_FRAMEBUFFER, destFrameBuffer);
|
|
2044
2143
|
var blitMask = needBlitColor ? gl.COLOR_BUFFER_BIT : 0;
|
|
2045
2144
|
if (needBlitDepth || needBlitStencil) {
|
|
2046
|
-
// @ts-ignore
|
|
2047
2145
|
var depthFormat = destRT._depthFormat;
|
|
2048
2146
|
if (needBlitDepth) {
|
|
2049
2147
|
if (depthFormat === TextureFormat.Depth || depthFormat >= TextureFormat.DepthStencil && depthFormat <= TextureFormat.Depth32Stencil8) {
|
|
@@ -2080,11 +2178,9 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
2080
2178
|
var _srcRT__platformRenderTarget__frameBuffer;
|
|
2081
2179
|
// @ts-ignore
|
|
2082
2180
|
var frameBuffer = (_srcRT__platformRenderTarget__frameBuffer = srcRT == null ? void 0 : srcRT._platformRenderTarget._frameBuffer) != null ? _srcRT__platformRenderTarget__frameBuffer : this._mainFrameBuffer;
|
|
2083
|
-
// @ts-ignore
|
|
2084
2181
|
gl.bindFramebuffer(gl.FRAMEBUFFER, frameBuffer);
|
|
2085
|
-
// @ts-ignore
|
|
2086
2182
|
var glTexture = grabTexture._platformTexture;
|
|
2087
|
-
|
|
2183
|
+
this.bindTexture(glTexture);
|
|
2088
2184
|
gl.copyTexSubImage2D(glTexture._target, 0, 0, 0, xStart, yStart, copyWidth, copyHeight);
|
|
2089
2185
|
};
|
|
2090
2186
|
_proto.activeTexture = function activeTexture(textureID) {
|
|
@@ -2093,7 +2189,8 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
2093
2189
|
this._activeTextureID = textureID;
|
|
2094
2190
|
}
|
|
2095
2191
|
};
|
|
2096
|
-
_proto.bindTexture = function bindTexture(
|
|
2192
|
+
_proto.bindTexture = function bindTexture(platformTexture) {
|
|
2193
|
+
var texture = platformTexture;
|
|
2097
2194
|
var index = this._activeTextureID - this._gl.TEXTURE0;
|
|
2098
2195
|
if (this._activeTextures[index] !== texture) {
|
|
2099
2196
|
this._gl.bindTexture(texture._target, texture._glTexture);
|
|
@@ -2153,10 +2250,10 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
2153
2250
|
if (debugRenderInfo != null) {
|
|
2154
2251
|
this._renderer = gl.getParameter(debugRenderInfo.UNMASKED_RENDERER_WEBGL);
|
|
2155
2252
|
}
|
|
2253
|
+
this.maxUniformBlockSize = gl.getParameter(gl.MAX_UNIFORM_BLOCK_SIZE);
|
|
2156
2254
|
};
|
|
2157
2255
|
_proto.destroy = function destroy() {
|
|
2158
2256
|
var webCanvas = this._webCanvas;
|
|
2159
|
-
webCanvas.removeEventListener("webglcontextcreationerror", this._onContextCreationError, false);
|
|
2160
2257
|
webCanvas.removeEventListener("webglcontextlost", this._onWebGLContextLost, false);
|
|
2161
2258
|
webCanvas.removeEventListener("webglcontextrestored", this._onWebGLContextRestored, false);
|
|
2162
2259
|
};
|
|
@@ -2171,12 +2268,6 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
2171
2268
|
this._onDeviceRestored();
|
|
2172
2269
|
};
|
|
2173
2270
|
_create_class(WebGLGraphicDevice, [
|
|
2174
|
-
{
|
|
2175
|
-
key: "isWebGL2",
|
|
2176
|
-
get: function get() {
|
|
2177
|
-
return this._isWebGL2;
|
|
2178
|
-
}
|
|
2179
|
-
},
|
|
2180
2271
|
{
|
|
2181
2272
|
key: "renderer",
|
|
2182
2273
|
get: function get() {
|
|
@@ -2187,7 +2278,7 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
2187
2278
|
key: "gl",
|
|
2188
2279
|
get: /**
|
|
2189
2280
|
* GL Context
|
|
2190
|
-
* @member {
|
|
2281
|
+
* @member {WebGL2RenderingContext}
|
|
2191
2282
|
*/ function get() {
|
|
2192
2283
|
return this._gl;
|
|
2193
2284
|
}
|
|
@@ -2203,16 +2294,10 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
2203
2294
|
get: function get() {
|
|
2204
2295
|
return this._capability;
|
|
2205
2296
|
}
|
|
2206
|
-
},
|
|
2207
|
-
{
|
|
2208
|
-
key: "canIUseMoreJoints",
|
|
2209
|
-
get: function get() {
|
|
2210
|
-
return this.capability.canIUseMoreJoints;
|
|
2211
|
-
}
|
|
2212
2297
|
}
|
|
2213
2298
|
]);
|
|
2214
2299
|
return WebGLGraphicDevice;
|
|
2215
2300
|
}();
|
|
2216
2301
|
|
|
2217
|
-
export { GLCompressedTextureInternalFormat, WebCanvas, WebGLEngine, WebGLGraphicDevice
|
|
2302
|
+
export { GLCompressedTextureInternalFormat, WebCanvas, WebGLEngine, WebGLGraphicDevice };
|
|
2218
2303
|
//# sourceMappingURL=module.js.map
|