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