holostaff-widget 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/BufferResource-Bh7Dg2tm.js +535 -0
- package/dist/BufferResource-Bh7Dg2tm.js.map +1 -0
- package/dist/CanvasRenderer-DVQieOII.js +976 -0
- package/dist/CanvasRenderer-DVQieOII.js.map +1 -0
- package/dist/RenderTargetSystem-B-GzTxxb.js +2500 -0
- package/dist/RenderTargetSystem-B-GzTxxb.js.map +1 -0
- package/dist/WebGLRenderer-D18tg5um.js +2938 -0
- package/dist/WebGLRenderer-D18tg5um.js.map +1 -0
- package/dist/WebGPURenderer-BuntxQ1w.js +1723 -0
- package/dist/WebGPURenderer-BuntxQ1w.js.map +1 -0
- package/dist/assets/idle-loop-green-8.mp4 +0 -0
- package/dist/assets/idle-loop-green.mp4 +0 -0
- package/dist/assets/idle-loop.mp4 +0 -0
- package/dist/assets/idle-loop.webm +0 -0
- package/dist/browserAll-DgNyjpqs.js +1872 -0
- package/dist/browserAll-DgNyjpqs.js.map +1 -0
- package/dist/hs-widget.es.js +5 -0
- package/dist/hs-widget.es.js.map +1 -0
- package/dist/hs-widget.umd.js +1003 -0
- package/dist/hs-widget.umd.js.map +1 -0
- package/dist/index-DjIeNhPr.js +23003 -0
- package/dist/index-DjIeNhPr.js.map +1 -0
- package/dist/webworkerAll-DndJ9Gy-.js +525 -0
- package/dist/webworkerAll-DndJ9Gy-.js.map +1 -0
- package/package.json +37 -0
|
@@ -0,0 +1,2938 @@
|
|
|
1
|
+
import { D as R, p as F, e as d, q as P, a as B, w as p, g as z, X as ye, O, T as S, aj as Ce, z as q, ak as Ne, S as g, aa as V, j as y, y as C, H as M, M as Z, al as Q, am as De, an as J, ao as Ie, ap as Ge, A as Ue, R as Fe, k as A } from "./index-DjIeNhPr.js";
|
|
2
|
+
import { e as Pe, G as Oe, c as Me, b as Le, U as we, B as ee, d as N, f as te, g as He } from "./BufferResource-Bh7Dg2tm.js";
|
|
3
|
+
import { R as Ve, S as Xe, d as ke } from "./RenderTargetSystem-B-GzTxxb.js";
|
|
4
|
+
function We() {
|
|
5
|
+
const { userAgent: t } = R.get().getNavigator();
|
|
6
|
+
return /^((?!chrome|android).)*safari/i.test(t);
|
|
7
|
+
}
|
|
8
|
+
class re {
|
|
9
|
+
constructor() {
|
|
10
|
+
this._tempState = F.for2d(), this._didUploadHash = {};
|
|
11
|
+
}
|
|
12
|
+
init(e) {
|
|
13
|
+
e.renderer.runners.contextChange.add(this);
|
|
14
|
+
}
|
|
15
|
+
contextChange() {
|
|
16
|
+
this._didUploadHash = {};
|
|
17
|
+
}
|
|
18
|
+
start(e, r, n) {
|
|
19
|
+
const s = e.renderer, i = this._didUploadHash[n.uid];
|
|
20
|
+
s.shader.bind(n, i), i || (this._didUploadHash[n.uid] = !0), s.shader.updateUniformGroup(s.globalUniforms.uniformGroup), s.geometry.bind(r, n.glProgram);
|
|
21
|
+
}
|
|
22
|
+
execute(e, r) {
|
|
23
|
+
const n = e.renderer;
|
|
24
|
+
this._tempState.blendMode = r.blendMode, n.state.set(this._tempState);
|
|
25
|
+
const s = r.textures.textures;
|
|
26
|
+
for (let i = 0; i < r.textures.count; i++)
|
|
27
|
+
n.texture.bind(s[i], i);
|
|
28
|
+
n.geometry.draw(r.topology, r.size, r.start);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
re.extension = {
|
|
32
|
+
type: [
|
|
33
|
+
d.WebGLPipesAdaptor
|
|
34
|
+
],
|
|
35
|
+
name: "batch"
|
|
36
|
+
};
|
|
37
|
+
var v = /* @__PURE__ */ ((t) => (t[t.ELEMENT_ARRAY_BUFFER = 34963] = "ELEMENT_ARRAY_BUFFER", t[t.ARRAY_BUFFER = 34962] = "ARRAY_BUFFER", t[t.UNIFORM_BUFFER = 35345] = "UNIFORM_BUFFER", t))(v || {});
|
|
38
|
+
class je {
|
|
39
|
+
constructor(e, r) {
|
|
40
|
+
this._lastBindBaseLocation = -1, this._lastBindCallId = -1, this.buffer = e || null, this.updateID = -1, this.byteLength = -1, this.type = r;
|
|
41
|
+
}
|
|
42
|
+
destroy() {
|
|
43
|
+
this.buffer = null, this.updateID = -1, this.byteLength = -1, this.type = -1, this._lastBindBaseLocation = -1, this._lastBindCallId = -1;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
class ne {
|
|
47
|
+
/**
|
|
48
|
+
* @param {Renderer} renderer - The renderer this System works for.
|
|
49
|
+
*/
|
|
50
|
+
constructor(e) {
|
|
51
|
+
this._boundBufferBases = /* @__PURE__ */ Object.create(null), this._minBaseLocation = 0, this._nextBindBaseIndex = this._minBaseLocation, this._bindCallId = 0, this._renderer = e, this._managedBuffers = new P({
|
|
52
|
+
renderer: e,
|
|
53
|
+
type: "resource",
|
|
54
|
+
onUnload: this.onBufferUnload.bind(this),
|
|
55
|
+
name: "glBuffer"
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
/** @ignore */
|
|
59
|
+
destroy() {
|
|
60
|
+
this._managedBuffers.destroy(), this._renderer = null, this._gl = null, this._boundBufferBases = {};
|
|
61
|
+
}
|
|
62
|
+
/** Sets up the renderer context and necessary buffers. */
|
|
63
|
+
contextChange() {
|
|
64
|
+
this._gl = this._renderer.gl, this.destroyAll(!0), this._maxBindings = this._renderer.limits.maxUniformBindings;
|
|
65
|
+
}
|
|
66
|
+
getGlBuffer(e) {
|
|
67
|
+
return e._gcLastUsed = this._renderer.gc.now, e._gpuData[this._renderer.uid] || this.createGLBuffer(e);
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* This binds specified buffer. On first run, it will create the webGL buffers for the context too
|
|
71
|
+
* @param buffer - the buffer to bind to the renderer
|
|
72
|
+
*/
|
|
73
|
+
bind(e) {
|
|
74
|
+
const { _gl: r } = this, n = this.getGlBuffer(e);
|
|
75
|
+
r.bindBuffer(n.type, n.buffer);
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Binds an uniform buffer to at the given index.
|
|
79
|
+
*
|
|
80
|
+
* A cache is used so a buffer will not be bound again if already bound.
|
|
81
|
+
* @param glBuffer - the buffer to bind
|
|
82
|
+
* @param index - the base index to bind it to.
|
|
83
|
+
*/
|
|
84
|
+
bindBufferBase(e, r) {
|
|
85
|
+
const { _gl: n } = this;
|
|
86
|
+
this._boundBufferBases[r] !== e && (this._boundBufferBases[r] = e, e._lastBindBaseLocation = r, n.bindBufferBase(n.UNIFORM_BUFFER, r, e.buffer));
|
|
87
|
+
}
|
|
88
|
+
nextBindBase(e) {
|
|
89
|
+
this._bindCallId++, this._minBaseLocation = 0, e && (this._boundBufferBases[0] = null, this._minBaseLocation = 1, this._nextBindBaseIndex < 1 && (this._nextBindBaseIndex = 1));
|
|
90
|
+
}
|
|
91
|
+
freeLocationForBufferBase(e) {
|
|
92
|
+
let r = this.getLastBindBaseLocation(e);
|
|
93
|
+
if (r >= this._minBaseLocation)
|
|
94
|
+
return e._lastBindCallId = this._bindCallId, r;
|
|
95
|
+
let n = 0, s = this._nextBindBaseIndex;
|
|
96
|
+
for (; n < 2; ) {
|
|
97
|
+
s >= this._maxBindings && (s = this._minBaseLocation, n++);
|
|
98
|
+
const i = this._boundBufferBases[s];
|
|
99
|
+
if (i && i._lastBindCallId === this._bindCallId) {
|
|
100
|
+
s++;
|
|
101
|
+
continue;
|
|
102
|
+
}
|
|
103
|
+
break;
|
|
104
|
+
}
|
|
105
|
+
return r = s, this._nextBindBaseIndex = s + 1, n >= 2 ? -1 : (e._lastBindCallId = this._bindCallId, this._boundBufferBases[r] = null, r);
|
|
106
|
+
}
|
|
107
|
+
getLastBindBaseLocation(e) {
|
|
108
|
+
const r = e._lastBindBaseLocation;
|
|
109
|
+
return this._boundBufferBases[r] === e ? r : -1;
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Binds a buffer whilst also binding its range.
|
|
113
|
+
* This will make the buffer start from the offset supplied rather than 0 when it is read.
|
|
114
|
+
* @param glBuffer - the buffer to bind
|
|
115
|
+
* @param index - the base index to bind at, defaults to 0
|
|
116
|
+
* @param offset - the offset to bind at (this is blocks of 256). 0 = 0, 1 = 256, 2 = 512 etc
|
|
117
|
+
* @param size - the size to bind at (this is blocks of 256).
|
|
118
|
+
*/
|
|
119
|
+
bindBufferRange(e, r, n, s) {
|
|
120
|
+
const { _gl: i } = this;
|
|
121
|
+
n || (n = 0), r || (r = 0), this._boundBufferBases[r] = null, i.bindBufferRange(i.UNIFORM_BUFFER, r || 0, e.buffer, n * 256, s || 256);
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Will ensure the data in the buffer is uploaded to the GPU.
|
|
125
|
+
* @param {Buffer} buffer - the buffer to update
|
|
126
|
+
*/
|
|
127
|
+
updateBuffer(e) {
|
|
128
|
+
const { _gl: r } = this, n = this.getGlBuffer(e);
|
|
129
|
+
if (e._updateID === n.updateID)
|
|
130
|
+
return n;
|
|
131
|
+
n.updateID = e._updateID, r.bindBuffer(n.type, n.buffer);
|
|
132
|
+
const s = e.data, i = e.descriptor.usage & B.STATIC ? r.STATIC_DRAW : r.DYNAMIC_DRAW;
|
|
133
|
+
return s ? n.byteLength >= s.byteLength ? r.bufferSubData(n.type, 0, s, 0, e._updateSize / s.BYTES_PER_ELEMENT) : (n.byteLength = s.byteLength, r.bufferData(n.type, s, i)) : (n.byteLength = e.descriptor.size, r.bufferData(n.type, n.byteLength, i)), n;
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* dispose all WebGL resources of all managed buffers
|
|
137
|
+
* @param contextLost
|
|
138
|
+
*/
|
|
139
|
+
destroyAll(e = !1) {
|
|
140
|
+
this._managedBuffers.removeAll(e);
|
|
141
|
+
}
|
|
142
|
+
onBufferUnload(e, r = !1) {
|
|
143
|
+
const n = e._gpuData[this._renderer.uid];
|
|
144
|
+
n && (r || this._gl.deleteBuffer(n.buffer));
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* creates and attaches a GLBuffer object tied to the current context.
|
|
148
|
+
* @param buffer
|
|
149
|
+
* @protected
|
|
150
|
+
*/
|
|
151
|
+
createGLBuffer(e) {
|
|
152
|
+
const { _gl: r } = this;
|
|
153
|
+
let n = v.ARRAY_BUFFER;
|
|
154
|
+
e.descriptor.usage & B.INDEX ? n = v.ELEMENT_ARRAY_BUFFER : e.descriptor.usage & B.UNIFORM && (n = v.UNIFORM_BUFFER);
|
|
155
|
+
const s = new je(r.createBuffer(), n);
|
|
156
|
+
return e._gpuData[this._renderer.uid] = s, this._managedBuffers.add(e), s;
|
|
157
|
+
}
|
|
158
|
+
resetState() {
|
|
159
|
+
this._boundBufferBases = /* @__PURE__ */ Object.create(null);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
ne.extension = {
|
|
163
|
+
type: [
|
|
164
|
+
d.WebGLSystem
|
|
165
|
+
],
|
|
166
|
+
name: "buffer"
|
|
167
|
+
};
|
|
168
|
+
const L = class se {
|
|
169
|
+
/** @param renderer - The renderer this System works for. */
|
|
170
|
+
constructor(e) {
|
|
171
|
+
this.supports = {
|
|
172
|
+
/** Support for 32-bit indices buffer. */
|
|
173
|
+
uint32Indices: !0,
|
|
174
|
+
/** Support for UniformBufferObjects */
|
|
175
|
+
uniformBufferObject: !0,
|
|
176
|
+
/** Support for VertexArrayObjects */
|
|
177
|
+
vertexArrayObject: !0,
|
|
178
|
+
/** Support for SRGB texture format */
|
|
179
|
+
srgbTextures: !0,
|
|
180
|
+
/** Support for wrapping modes if a texture is non-power of two */
|
|
181
|
+
nonPowOf2wrapping: !0,
|
|
182
|
+
/** Support for MSAA (antialiasing of dynamic textures) */
|
|
183
|
+
msaa: !0,
|
|
184
|
+
/** Support for mipmaps if a texture is non-power of two */
|
|
185
|
+
nonPowOf2mipmaps: !0
|
|
186
|
+
}, this._renderer = e, this.extensions = /* @__PURE__ */ Object.create(null), this.handleContextLost = this.handleContextLost.bind(this), this.handleContextRestored = this.handleContextRestored.bind(this);
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* `true` if the context is lost
|
|
190
|
+
* @readonly
|
|
191
|
+
*/
|
|
192
|
+
get isLost() {
|
|
193
|
+
return !this.gl || this.gl.isContextLost();
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* Handles the context change event.
|
|
197
|
+
* @param {WebGLRenderingContext} gl - New WebGL context.
|
|
198
|
+
*/
|
|
199
|
+
contextChange(e) {
|
|
200
|
+
this.gl = e, this._renderer.gl = e;
|
|
201
|
+
}
|
|
202
|
+
init(e) {
|
|
203
|
+
e = { ...se.defaultOptions, ...e };
|
|
204
|
+
let r = this.multiView = e.multiView;
|
|
205
|
+
if (e.context && r && (p("Renderer created with both a context and multiview enabled. Disabling multiView as both cannot work together."), r = !1), r ? this.canvas = R.get().createCanvas(this._renderer.canvas.width, this._renderer.canvas.height) : this.canvas = this._renderer.view.canvas, e.context)
|
|
206
|
+
this.initFromContext(e.context);
|
|
207
|
+
else {
|
|
208
|
+
const n = this._renderer.background.alpha < 1, s = e.premultipliedAlpha ?? !0, i = e.antialias && !this._renderer.backBuffer.useBackBuffer;
|
|
209
|
+
this.createContext(e.preferWebGLVersion, {
|
|
210
|
+
alpha: n,
|
|
211
|
+
premultipliedAlpha: s,
|
|
212
|
+
antialias: i,
|
|
213
|
+
stencil: !0,
|
|
214
|
+
preserveDrawingBuffer: e.preserveDrawingBuffer,
|
|
215
|
+
powerPreference: e.powerPreference ?? "default"
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
ensureCanvasSize(e) {
|
|
220
|
+
if (!this.multiView) {
|
|
221
|
+
e !== this.canvas && p("multiView is disabled, but targetCanvas is not the main canvas");
|
|
222
|
+
return;
|
|
223
|
+
}
|
|
224
|
+
const { canvas: r } = this;
|
|
225
|
+
(r.width < e.width || r.height < e.height) && (r.width = Math.max(e.width, e.width), r.height = Math.max(e.height, e.height));
|
|
226
|
+
}
|
|
227
|
+
/**
|
|
228
|
+
* Initializes the context.
|
|
229
|
+
* @protected
|
|
230
|
+
* @param {WebGLRenderingContext} gl - WebGL context
|
|
231
|
+
*/
|
|
232
|
+
initFromContext(e) {
|
|
233
|
+
this.gl = e, this.webGLVersion = e instanceof R.get().getWebGLRenderingContext() ? 1 : 2, this.getExtensions(), this.validateContext(e), this._renderer.runners.contextChange.emit(e);
|
|
234
|
+
const r = this._renderer.view.canvas;
|
|
235
|
+
r.addEventListener("webglcontextlost", this.handleContextLost, !1), r.addEventListener("webglcontextrestored", this.handleContextRestored, !1);
|
|
236
|
+
}
|
|
237
|
+
/**
|
|
238
|
+
* Initialize from context options
|
|
239
|
+
* @protected
|
|
240
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/getContext
|
|
241
|
+
* @param preferWebGLVersion
|
|
242
|
+
* @param {object} options - context attributes
|
|
243
|
+
*/
|
|
244
|
+
createContext(e, r) {
|
|
245
|
+
let n;
|
|
246
|
+
const s = this.canvas;
|
|
247
|
+
if (e === 2 && (n = s.getContext("webgl2", r)), !n && (n = s.getContext("webgl", r), !n))
|
|
248
|
+
throw new Error("This browser does not support WebGL. Try using the canvas renderer");
|
|
249
|
+
this.gl = n, this.initFromContext(this.gl);
|
|
250
|
+
}
|
|
251
|
+
/** Auto-populate the {@link GlContextSystem.extensions extensions}. */
|
|
252
|
+
getExtensions() {
|
|
253
|
+
const { gl: e } = this, r = {
|
|
254
|
+
anisotropicFiltering: e.getExtension("EXT_texture_filter_anisotropic"),
|
|
255
|
+
floatTextureLinear: e.getExtension("OES_texture_float_linear"),
|
|
256
|
+
s3tc: e.getExtension("WEBGL_compressed_texture_s3tc"),
|
|
257
|
+
s3tc_sRGB: e.getExtension("WEBGL_compressed_texture_s3tc_srgb"),
|
|
258
|
+
// eslint-disable-line camelcase
|
|
259
|
+
etc: e.getExtension("WEBGL_compressed_texture_etc"),
|
|
260
|
+
etc1: e.getExtension("WEBGL_compressed_texture_etc1"),
|
|
261
|
+
pvrtc: e.getExtension("WEBGL_compressed_texture_pvrtc") || e.getExtension("WEBKIT_WEBGL_compressed_texture_pvrtc"),
|
|
262
|
+
atc: e.getExtension("WEBGL_compressed_texture_atc"),
|
|
263
|
+
astc: e.getExtension("WEBGL_compressed_texture_astc"),
|
|
264
|
+
bptc: e.getExtension("EXT_texture_compression_bptc"),
|
|
265
|
+
rgtc: e.getExtension("EXT_texture_compression_rgtc"),
|
|
266
|
+
loseContext: e.getExtension("WEBGL_lose_context")
|
|
267
|
+
};
|
|
268
|
+
if (this.webGLVersion === 1)
|
|
269
|
+
this.extensions = {
|
|
270
|
+
...r,
|
|
271
|
+
drawBuffers: e.getExtension("WEBGL_draw_buffers"),
|
|
272
|
+
depthTexture: e.getExtension("WEBGL_depth_texture"),
|
|
273
|
+
vertexArrayObject: e.getExtension("OES_vertex_array_object") || e.getExtension("MOZ_OES_vertex_array_object") || e.getExtension("WEBKIT_OES_vertex_array_object"),
|
|
274
|
+
uint32ElementIndex: e.getExtension("OES_element_index_uint"),
|
|
275
|
+
// Floats and half-floats
|
|
276
|
+
floatTexture: e.getExtension("OES_texture_float"),
|
|
277
|
+
floatTextureLinear: e.getExtension("OES_texture_float_linear"),
|
|
278
|
+
textureHalfFloat: e.getExtension("OES_texture_half_float"),
|
|
279
|
+
textureHalfFloatLinear: e.getExtension("OES_texture_half_float_linear"),
|
|
280
|
+
vertexAttribDivisorANGLE: e.getExtension("ANGLE_instanced_arrays"),
|
|
281
|
+
srgb: e.getExtension("EXT_sRGB")
|
|
282
|
+
};
|
|
283
|
+
else {
|
|
284
|
+
this.extensions = {
|
|
285
|
+
...r,
|
|
286
|
+
colorBufferFloat: e.getExtension("EXT_color_buffer_float")
|
|
287
|
+
};
|
|
288
|
+
const n = e.getExtension("WEBGL_provoking_vertex");
|
|
289
|
+
n && n.provokingVertexWEBGL(n.FIRST_VERTEX_CONVENTION_WEBGL);
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
/**
|
|
293
|
+
* Handles a lost webgl context
|
|
294
|
+
* @param {WebGLContextEvent} event - The context lost event.
|
|
295
|
+
*/
|
|
296
|
+
handleContextLost(e) {
|
|
297
|
+
e.preventDefault(), this._contextLossForced && (this._contextLossForced = !1, setTimeout(() => {
|
|
298
|
+
var r;
|
|
299
|
+
this.gl.isContextLost() && ((r = this.extensions.loseContext) == null || r.restoreContext());
|
|
300
|
+
}, 0));
|
|
301
|
+
}
|
|
302
|
+
/** Handles a restored webgl context. */
|
|
303
|
+
handleContextRestored() {
|
|
304
|
+
this.getExtensions(), this._renderer.runners.contextChange.emit(this.gl);
|
|
305
|
+
}
|
|
306
|
+
destroy() {
|
|
307
|
+
var r;
|
|
308
|
+
const e = this._renderer.view.canvas;
|
|
309
|
+
this._renderer = null, e.removeEventListener("webglcontextlost", this.handleContextLost), e.removeEventListener("webglcontextrestored", this.handleContextRestored), this.gl.useProgram(null), (r = this.extensions.loseContext) == null || r.loseContext();
|
|
310
|
+
}
|
|
311
|
+
/**
|
|
312
|
+
* this function can be called to force a webGL context loss
|
|
313
|
+
* this will release all resources on the GPU.
|
|
314
|
+
* Useful if you need to put Pixi to sleep, and save some GPU memory
|
|
315
|
+
*
|
|
316
|
+
* As soon as render is called - all resources will be created again.
|
|
317
|
+
*/
|
|
318
|
+
forceContextLoss() {
|
|
319
|
+
var e;
|
|
320
|
+
(e = this.extensions.loseContext) == null || e.loseContext(), this._contextLossForced = !0;
|
|
321
|
+
}
|
|
322
|
+
/**
|
|
323
|
+
* Validate context.
|
|
324
|
+
* @param {WebGLRenderingContext} gl - Render context.
|
|
325
|
+
*/
|
|
326
|
+
validateContext(e) {
|
|
327
|
+
const r = e.getContextAttributes();
|
|
328
|
+
r && !r.stencil && p("Provided WebGL context does not have a stencil buffer, masks may not render correctly");
|
|
329
|
+
const n = this.supports, s = this.webGLVersion === 2, i = this.extensions;
|
|
330
|
+
n.uint32Indices = s || !!i.uint32ElementIndex, n.uniformBufferObject = s, n.vertexArrayObject = s || !!i.vertexArrayObject, n.srgbTextures = s || !!i.srgb, n.nonPowOf2wrapping = s, n.nonPowOf2mipmaps = s, n.msaa = s, n.uint32Indices || p("Provided WebGL context does not support 32 index buffer, large scenes may not render correctly");
|
|
331
|
+
}
|
|
332
|
+
};
|
|
333
|
+
L.extension = {
|
|
334
|
+
type: [
|
|
335
|
+
d.WebGLSystem
|
|
336
|
+
],
|
|
337
|
+
name: "context"
|
|
338
|
+
};
|
|
339
|
+
L.defaultOptions = {
|
|
340
|
+
/**
|
|
341
|
+
* {@link WebGLOptions.context}
|
|
342
|
+
* @default null
|
|
343
|
+
*/
|
|
344
|
+
context: null,
|
|
345
|
+
/**
|
|
346
|
+
* {@link WebGLOptions.premultipliedAlpha}
|
|
347
|
+
* @default true
|
|
348
|
+
*/
|
|
349
|
+
premultipliedAlpha: !0,
|
|
350
|
+
/**
|
|
351
|
+
* {@link WebGLOptions.preserveDrawingBuffer}
|
|
352
|
+
* @default false
|
|
353
|
+
*/
|
|
354
|
+
preserveDrawingBuffer: !1,
|
|
355
|
+
/**
|
|
356
|
+
* {@link WebGLOptions.powerPreference}
|
|
357
|
+
* @default default
|
|
358
|
+
*/
|
|
359
|
+
powerPreference: void 0,
|
|
360
|
+
/**
|
|
361
|
+
* {@link WebGLOptions.webGLVersion}
|
|
362
|
+
* @default 2
|
|
363
|
+
*/
|
|
364
|
+
preferWebGLVersion: 2,
|
|
365
|
+
/**
|
|
366
|
+
* {@link WebGLOptions.multiView}
|
|
367
|
+
* @default false
|
|
368
|
+
*/
|
|
369
|
+
multiView: !1
|
|
370
|
+
};
|
|
371
|
+
let $e = L;
|
|
372
|
+
var G = /* @__PURE__ */ ((t) => (t[t.RGBA = 6408] = "RGBA", t[t.RGB = 6407] = "RGB", t[t.RG = 33319] = "RG", t[t.RED = 6403] = "RED", t[t.RGBA_INTEGER = 36249] = "RGBA_INTEGER", t[t.RGB_INTEGER = 36248] = "RGB_INTEGER", t[t.RG_INTEGER = 33320] = "RG_INTEGER", t[t.RED_INTEGER = 36244] = "RED_INTEGER", t[t.ALPHA = 6406] = "ALPHA", t[t.LUMINANCE = 6409] = "LUMINANCE", t[t.LUMINANCE_ALPHA = 6410] = "LUMINANCE_ALPHA", t[t.DEPTH_COMPONENT = 6402] = "DEPTH_COMPONENT", t[t.DEPTH_STENCIL = 34041] = "DEPTH_STENCIL", t))(G || {}), w = /* @__PURE__ */ ((t) => (t[t.TEXTURE_2D = 3553] = "TEXTURE_2D", t[t.TEXTURE_CUBE_MAP = 34067] = "TEXTURE_CUBE_MAP", t[t.TEXTURE_2D_ARRAY = 35866] = "TEXTURE_2D_ARRAY", t[t.TEXTURE_CUBE_MAP_POSITIVE_X = 34069] = "TEXTURE_CUBE_MAP_POSITIVE_X", t[t.TEXTURE_CUBE_MAP_NEGATIVE_X = 34070] = "TEXTURE_CUBE_MAP_NEGATIVE_X", t[t.TEXTURE_CUBE_MAP_POSITIVE_Y = 34071] = "TEXTURE_CUBE_MAP_POSITIVE_Y", t[t.TEXTURE_CUBE_MAP_NEGATIVE_Y = 34072] = "TEXTURE_CUBE_MAP_NEGATIVE_Y", t[t.TEXTURE_CUBE_MAP_POSITIVE_Z = 34073] = "TEXTURE_CUBE_MAP_POSITIVE_Z", t[t.TEXTURE_CUBE_MAP_NEGATIVE_Z = 34074] = "TEXTURE_CUBE_MAP_NEGATIVE_Z", t))(w || {}), l = /* @__PURE__ */ ((t) => (t[t.UNSIGNED_BYTE = 5121] = "UNSIGNED_BYTE", t[t.UNSIGNED_SHORT = 5123] = "UNSIGNED_SHORT", t[t.UNSIGNED_SHORT_5_6_5 = 33635] = "UNSIGNED_SHORT_5_6_5", t[t.UNSIGNED_SHORT_4_4_4_4 = 32819] = "UNSIGNED_SHORT_4_4_4_4", t[t.UNSIGNED_SHORT_5_5_5_1 = 32820] = "UNSIGNED_SHORT_5_5_5_1", t[t.UNSIGNED_INT = 5125] = "UNSIGNED_INT", t[t.UNSIGNED_INT_10F_11F_11F_REV = 35899] = "UNSIGNED_INT_10F_11F_11F_REV", t[t.UNSIGNED_INT_2_10_10_10_REV = 33640] = "UNSIGNED_INT_2_10_10_10_REV", t[t.UNSIGNED_INT_24_8 = 34042] = "UNSIGNED_INT_24_8", t[t.UNSIGNED_INT_5_9_9_9_REV = 35902] = "UNSIGNED_INT_5_9_9_9_REV", t[t.BYTE = 5120] = "BYTE", t[t.SHORT = 5122] = "SHORT", t[t.INT = 5124] = "INT", t[t.FLOAT = 5126] = "FLOAT", t[t.FLOAT_32_UNSIGNED_INT_24_8_REV = 36269] = "FLOAT_32_UNSIGNED_INT_24_8_REV", t[t.HALF_FLOAT = 36193] = "HALF_FLOAT", t))(l || {});
|
|
373
|
+
const X = {
|
|
374
|
+
uint8x2: l.UNSIGNED_BYTE,
|
|
375
|
+
uint8x4: l.UNSIGNED_BYTE,
|
|
376
|
+
sint8x2: l.BYTE,
|
|
377
|
+
sint8x4: l.BYTE,
|
|
378
|
+
unorm8x2: l.UNSIGNED_BYTE,
|
|
379
|
+
unorm8x4: l.UNSIGNED_BYTE,
|
|
380
|
+
snorm8x2: l.BYTE,
|
|
381
|
+
snorm8x4: l.BYTE,
|
|
382
|
+
uint16x2: l.UNSIGNED_SHORT,
|
|
383
|
+
uint16x4: l.UNSIGNED_SHORT,
|
|
384
|
+
sint16x2: l.SHORT,
|
|
385
|
+
sint16x4: l.SHORT,
|
|
386
|
+
unorm16x2: l.UNSIGNED_SHORT,
|
|
387
|
+
unorm16x4: l.UNSIGNED_SHORT,
|
|
388
|
+
snorm16x2: l.SHORT,
|
|
389
|
+
snorm16x4: l.SHORT,
|
|
390
|
+
float16x2: l.HALF_FLOAT,
|
|
391
|
+
float16x4: l.HALF_FLOAT,
|
|
392
|
+
float32: l.FLOAT,
|
|
393
|
+
float32x2: l.FLOAT,
|
|
394
|
+
float32x3: l.FLOAT,
|
|
395
|
+
float32x4: l.FLOAT,
|
|
396
|
+
uint32: l.UNSIGNED_INT,
|
|
397
|
+
uint32x2: l.UNSIGNED_INT,
|
|
398
|
+
uint32x3: l.UNSIGNED_INT,
|
|
399
|
+
uint32x4: l.UNSIGNED_INT,
|
|
400
|
+
sint32: l.INT,
|
|
401
|
+
sint32x2: l.INT,
|
|
402
|
+
sint32x3: l.INT,
|
|
403
|
+
sint32x4: l.INT
|
|
404
|
+
};
|
|
405
|
+
function Ke(t) {
|
|
406
|
+
return X[t] ?? X.float32;
|
|
407
|
+
}
|
|
408
|
+
const Ye = {
|
|
409
|
+
"point-list": 0,
|
|
410
|
+
"line-list": 1,
|
|
411
|
+
"line-strip": 3,
|
|
412
|
+
"triangle-list": 4,
|
|
413
|
+
"triangle-strip": 5
|
|
414
|
+
};
|
|
415
|
+
class ze {
|
|
416
|
+
constructor() {
|
|
417
|
+
this.vaoCache = /* @__PURE__ */ Object.create(null);
|
|
418
|
+
}
|
|
419
|
+
destroy() {
|
|
420
|
+
this.vaoCache = /* @__PURE__ */ Object.create(null);
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
class ie {
|
|
424
|
+
/** @param renderer - The renderer this System works for. */
|
|
425
|
+
constructor(e) {
|
|
426
|
+
this._renderer = e, this._activeGeometry = null, this._activeVao = null, this.hasVao = !0, this.hasInstance = !0, this._managedGeometries = new P({
|
|
427
|
+
renderer: e,
|
|
428
|
+
type: "resource",
|
|
429
|
+
onUnload: this.onGeometryUnload.bind(this),
|
|
430
|
+
name: "glGeometry"
|
|
431
|
+
});
|
|
432
|
+
}
|
|
433
|
+
/** Sets up the renderer context and necessary buffers. */
|
|
434
|
+
contextChange() {
|
|
435
|
+
const e = this.gl = this._renderer.gl;
|
|
436
|
+
if (!this._renderer.context.supports.vertexArrayObject)
|
|
437
|
+
throw new Error("[PixiJS] Vertex Array Objects are not supported on this device");
|
|
438
|
+
this.destroyAll(!0);
|
|
439
|
+
const r = this._renderer.context.extensions.vertexArrayObject;
|
|
440
|
+
r && (e.createVertexArray = () => r.createVertexArrayOES(), e.bindVertexArray = (s) => r.bindVertexArrayOES(s), e.deleteVertexArray = (s) => r.deleteVertexArrayOES(s));
|
|
441
|
+
const n = this._renderer.context.extensions.vertexAttribDivisorANGLE;
|
|
442
|
+
n && (e.drawArraysInstanced = (s, i, a, o) => {
|
|
443
|
+
n.drawArraysInstancedANGLE(s, i, a, o);
|
|
444
|
+
}, e.drawElementsInstanced = (s, i, a, o, u) => {
|
|
445
|
+
n.drawElementsInstancedANGLE(s, i, a, o, u);
|
|
446
|
+
}, e.vertexAttribDivisor = (s, i) => n.vertexAttribDivisorANGLE(s, i)), this._activeGeometry = null, this._activeVao = null;
|
|
447
|
+
}
|
|
448
|
+
/**
|
|
449
|
+
* Binds geometry so that is can be drawn. Creating a Vao if required
|
|
450
|
+
* @param geometry - Instance of geometry to bind.
|
|
451
|
+
* @param program - Instance of program to use vao for.
|
|
452
|
+
*/
|
|
453
|
+
bind(e, r) {
|
|
454
|
+
const n = this.gl;
|
|
455
|
+
this._activeGeometry = e;
|
|
456
|
+
const s = this.getVao(e, r);
|
|
457
|
+
this._activeVao !== s && (this._activeVao = s, n.bindVertexArray(s)), this.updateBuffers();
|
|
458
|
+
}
|
|
459
|
+
/** Reset and unbind any active VAO and geometry. */
|
|
460
|
+
resetState() {
|
|
461
|
+
this.unbind();
|
|
462
|
+
}
|
|
463
|
+
/** Update buffers of the currently bound geometry. */
|
|
464
|
+
updateBuffers() {
|
|
465
|
+
const e = this._activeGeometry, r = this._renderer.buffer;
|
|
466
|
+
for (let n = 0; n < e.buffers.length; n++) {
|
|
467
|
+
const s = e.buffers[n];
|
|
468
|
+
r.updateBuffer(s);
|
|
469
|
+
}
|
|
470
|
+
e._gcLastUsed = this._renderer.gc.now;
|
|
471
|
+
}
|
|
472
|
+
/**
|
|
473
|
+
* Check compatibility between a geometry and a program
|
|
474
|
+
* @param geometry - Geometry instance.
|
|
475
|
+
* @param program - Program instance.
|
|
476
|
+
*/
|
|
477
|
+
checkCompatibility(e, r) {
|
|
478
|
+
const n = e.attributes, s = r._attributeData;
|
|
479
|
+
for (const i in s)
|
|
480
|
+
if (!n[i])
|
|
481
|
+
throw new Error(`shader and geometry incompatible, geometry missing the "${i}" attribute`);
|
|
482
|
+
}
|
|
483
|
+
/**
|
|
484
|
+
* Takes a geometry and program and generates a unique signature for them.
|
|
485
|
+
* @param geometry - To get signature from.
|
|
486
|
+
* @param program - To test geometry against.
|
|
487
|
+
* @returns - Unique signature of the geometry and program
|
|
488
|
+
*/
|
|
489
|
+
getSignature(e, r) {
|
|
490
|
+
const n = e.attributes, s = r._attributeData, i = ["g", e.uid];
|
|
491
|
+
for (const a in n)
|
|
492
|
+
s[a] && i.push(a, s[a].location);
|
|
493
|
+
return i.join("-");
|
|
494
|
+
}
|
|
495
|
+
getVao(e, r) {
|
|
496
|
+
var n;
|
|
497
|
+
return ((n = e._gpuData[this._renderer.uid]) == null ? void 0 : n.vaoCache[r._key]) || this.initGeometryVao(e, r);
|
|
498
|
+
}
|
|
499
|
+
/**
|
|
500
|
+
* Creates or gets Vao with the same structure as the geometry and stores it on the geometry.
|
|
501
|
+
* If vao is created, it is bound automatically. We use a shader to infer what and how to set up the
|
|
502
|
+
* attribute locations.
|
|
503
|
+
* @param geometry - Instance of geometry to to generate Vao for.
|
|
504
|
+
* @param program
|
|
505
|
+
* @param _incRefCount - Increment refCount of all geometry buffers.
|
|
506
|
+
*/
|
|
507
|
+
initGeometryVao(e, r, n = !0) {
|
|
508
|
+
const s = this._renderer.gl, i = this._renderer.buffer;
|
|
509
|
+
this._renderer.shader._getProgramData(r), this.checkCompatibility(e, r);
|
|
510
|
+
const a = this.getSignature(e, r);
|
|
511
|
+
let o = e._gpuData[this._renderer.uid];
|
|
512
|
+
o || (o = new ze(), e._gpuData[this._renderer.uid] = o, this._managedGeometries.add(e));
|
|
513
|
+
const u = o.vaoCache;
|
|
514
|
+
let c = u[a];
|
|
515
|
+
if (c)
|
|
516
|
+
return u[r._key] = c, c;
|
|
517
|
+
Pe(e, r._attributeData);
|
|
518
|
+
const _ = e.buffers;
|
|
519
|
+
c = s.createVertexArray(), s.bindVertexArray(c);
|
|
520
|
+
for (let f = 0; f < _.length; f++) {
|
|
521
|
+
const h = _[f];
|
|
522
|
+
i.bind(h);
|
|
523
|
+
}
|
|
524
|
+
return this.activateVao(e, r), u[r._key] = c, u[a] = c, s.bindVertexArray(null), c;
|
|
525
|
+
}
|
|
526
|
+
onGeometryUnload(e, r = !1) {
|
|
527
|
+
const n = e._gpuData[this._renderer.uid];
|
|
528
|
+
if (!n) return;
|
|
529
|
+
const s = n.vaoCache;
|
|
530
|
+
if (!r)
|
|
531
|
+
for (const i in s)
|
|
532
|
+
this._activeVao !== s[i] && this.resetState(), this.gl.deleteVertexArray(s[i]);
|
|
533
|
+
}
|
|
534
|
+
/**
|
|
535
|
+
* Dispose all WebGL resources of all managed geometries.
|
|
536
|
+
* @param [contextLost=false] - If context was lost, we suppress `gl.delete` calls
|
|
537
|
+
*/
|
|
538
|
+
destroyAll(e = !1) {
|
|
539
|
+
this._managedGeometries.removeAll(e);
|
|
540
|
+
}
|
|
541
|
+
/**
|
|
542
|
+
* Activate vertex array object.
|
|
543
|
+
* @param geometry - Geometry instance.
|
|
544
|
+
* @param program - Shader program instance.
|
|
545
|
+
*/
|
|
546
|
+
activateVao(e, r) {
|
|
547
|
+
var o;
|
|
548
|
+
const n = this._renderer.gl, s = this._renderer.buffer, i = e.attributes;
|
|
549
|
+
e.indexBuffer && s.bind(e.indexBuffer);
|
|
550
|
+
let a = null;
|
|
551
|
+
for (const u in i) {
|
|
552
|
+
const c = i[u], _ = c.buffer, f = s.getGlBuffer(_), h = r._attributeData[u];
|
|
553
|
+
if (h) {
|
|
554
|
+
a !== f && (s.bind(_), a = f);
|
|
555
|
+
const m = h.location;
|
|
556
|
+
n.enableVertexAttribArray(m);
|
|
557
|
+
const b = z(c.format), E = Ke(c.format);
|
|
558
|
+
if (((o = h.format) == null ? void 0 : o.substring(1, 4)) === "int" ? n.vertexAttribIPointer(
|
|
559
|
+
m,
|
|
560
|
+
b.size,
|
|
561
|
+
E,
|
|
562
|
+
c.stride,
|
|
563
|
+
c.offset
|
|
564
|
+
) : n.vertexAttribPointer(
|
|
565
|
+
m,
|
|
566
|
+
b.size,
|
|
567
|
+
E,
|
|
568
|
+
b.normalised,
|
|
569
|
+
c.stride,
|
|
570
|
+
c.offset
|
|
571
|
+
), c.instance)
|
|
572
|
+
if (this.hasInstance) {
|
|
573
|
+
const Be = c.divisor ?? 1;
|
|
574
|
+
n.vertexAttribDivisor(m, Be);
|
|
575
|
+
} else
|
|
576
|
+
throw new Error("geometry error, GPU Instancing is not supported on this device");
|
|
577
|
+
}
|
|
578
|
+
}
|
|
579
|
+
}
|
|
580
|
+
/**
|
|
581
|
+
* Draws the currently bound geometry.
|
|
582
|
+
* @param topology - The type primitive to render.
|
|
583
|
+
* @param size - The number of elements to be rendered. If not specified, all vertices after the
|
|
584
|
+
* starting vertex will be drawn.
|
|
585
|
+
* @param start - The starting vertex in the geometry to start drawing from. If not specified,
|
|
586
|
+
* drawing will start from the first vertex.
|
|
587
|
+
* @param instanceCount - The number of instances of the set of elements to execute. If not specified,
|
|
588
|
+
* all instances will be drawn.
|
|
589
|
+
* @returns This instance of the geometry system.
|
|
590
|
+
*/
|
|
591
|
+
draw(e, r, n, s) {
|
|
592
|
+
const { gl: i } = this._renderer, a = this._activeGeometry, o = Ye[e || a.topology];
|
|
593
|
+
if (s ?? (s = a.instanceCount), a.indexBuffer) {
|
|
594
|
+
const u = a.indexBuffer.data.BYTES_PER_ELEMENT, c = u === 2 ? i.UNSIGNED_SHORT : i.UNSIGNED_INT;
|
|
595
|
+
s !== 1 ? i.drawElementsInstanced(o, r || a.indexBuffer.data.length, c, (n || 0) * u, s) : i.drawElements(o, r || a.indexBuffer.data.length, c, (n || 0) * u);
|
|
596
|
+
} else s !== 1 ? i.drawArraysInstanced(o, n || 0, r || a.getSize(), s) : i.drawArrays(o, n || 0, r || a.getSize());
|
|
597
|
+
return this;
|
|
598
|
+
}
|
|
599
|
+
/** Unbind/reset everything. */
|
|
600
|
+
unbind() {
|
|
601
|
+
this.gl.bindVertexArray(null), this._activeVao = null, this._activeGeometry = null;
|
|
602
|
+
}
|
|
603
|
+
destroy() {
|
|
604
|
+
this._managedGeometries.destroy(), this._renderer = null, this.gl = null, this._activeVao = null, this._activeGeometry = null;
|
|
605
|
+
}
|
|
606
|
+
}
|
|
607
|
+
ie.extension = {
|
|
608
|
+
type: [
|
|
609
|
+
d.WebGLSystem
|
|
610
|
+
],
|
|
611
|
+
name: "geometry"
|
|
612
|
+
};
|
|
613
|
+
const qe = new Ce({
|
|
614
|
+
attributes: {
|
|
615
|
+
aPosition: [
|
|
616
|
+
-1,
|
|
617
|
+
-1,
|
|
618
|
+
// Bottom left corner
|
|
619
|
+
3,
|
|
620
|
+
-1,
|
|
621
|
+
// Bottom right corner, extending beyond right edge
|
|
622
|
+
-1,
|
|
623
|
+
3
|
|
624
|
+
// Top left corner, extending beyond top edge
|
|
625
|
+
]
|
|
626
|
+
}
|
|
627
|
+
}), H = class ae {
|
|
628
|
+
constructor(e) {
|
|
629
|
+
this.useBackBuffer = !1, this._useBackBufferThisRender = !1, this._renderer = e;
|
|
630
|
+
}
|
|
631
|
+
init(e = {}) {
|
|
632
|
+
const { useBackBuffer: r, antialias: n } = { ...ae.defaultOptions, ...e };
|
|
633
|
+
this.useBackBuffer = r, this._antialias = n, this._renderer.context.supports.msaa || (p("antialiasing, is not supported on when using the back buffer"), this._antialias = !1), this._state = F.for2d();
|
|
634
|
+
const s = new ye({
|
|
635
|
+
vertex: `
|
|
636
|
+
attribute vec2 aPosition;
|
|
637
|
+
out vec2 vUv;
|
|
638
|
+
|
|
639
|
+
void main() {
|
|
640
|
+
gl_Position = vec4(aPosition, 0.0, 1.0);
|
|
641
|
+
|
|
642
|
+
vUv = (aPosition + 1.0) / 2.0;
|
|
643
|
+
|
|
644
|
+
// flip dem UVs
|
|
645
|
+
vUv.y = 1.0 - vUv.y;
|
|
646
|
+
}`,
|
|
647
|
+
fragment: `
|
|
648
|
+
in vec2 vUv;
|
|
649
|
+
out vec4 finalColor;
|
|
650
|
+
|
|
651
|
+
uniform sampler2D uTexture;
|
|
652
|
+
|
|
653
|
+
void main() {
|
|
654
|
+
finalColor = texture(uTexture, vUv);
|
|
655
|
+
}`,
|
|
656
|
+
name: "big-triangle"
|
|
657
|
+
});
|
|
658
|
+
this._bigTriangleShader = new O({
|
|
659
|
+
glProgram: s,
|
|
660
|
+
resources: {
|
|
661
|
+
uTexture: S.WHITE.source
|
|
662
|
+
}
|
|
663
|
+
});
|
|
664
|
+
}
|
|
665
|
+
/**
|
|
666
|
+
* This is called before the RenderTargetSystem is started. This is where
|
|
667
|
+
* we replace the target with the back buffer if required.
|
|
668
|
+
* @param options - The options for this render.
|
|
669
|
+
*/
|
|
670
|
+
renderStart(e) {
|
|
671
|
+
const r = this._renderer.renderTarget.getRenderTarget(e.target);
|
|
672
|
+
if (this._useBackBufferThisRender = this.useBackBuffer && !!r.isRoot, this._useBackBufferThisRender) {
|
|
673
|
+
const n = this._renderer.renderTarget.getRenderTarget(e.target);
|
|
674
|
+
this._targetTexture = n.colorTexture, e.target = this._getBackBufferTexture(n.colorTexture);
|
|
675
|
+
}
|
|
676
|
+
}
|
|
677
|
+
renderEnd() {
|
|
678
|
+
this._presentBackBuffer();
|
|
679
|
+
}
|
|
680
|
+
_presentBackBuffer() {
|
|
681
|
+
const e = this._renderer;
|
|
682
|
+
e.renderTarget.finishRenderPass(), this._useBackBufferThisRender && (e.renderTarget.bind(this._targetTexture, !1), this._bigTriangleShader.resources.uTexture = this._backBufferTexture.source, e.encoder.draw({
|
|
683
|
+
geometry: qe,
|
|
684
|
+
shader: this._bigTriangleShader,
|
|
685
|
+
state: this._state
|
|
686
|
+
}));
|
|
687
|
+
}
|
|
688
|
+
_getBackBufferTexture(e) {
|
|
689
|
+
return this._backBufferTexture = this._backBufferTexture || new S({
|
|
690
|
+
source: new q({
|
|
691
|
+
width: e.width,
|
|
692
|
+
height: e.height,
|
|
693
|
+
resolution: e._resolution,
|
|
694
|
+
antialias: this._antialias
|
|
695
|
+
})
|
|
696
|
+
}), this._backBufferTexture.source.resize(
|
|
697
|
+
e.width,
|
|
698
|
+
e.height,
|
|
699
|
+
e._resolution
|
|
700
|
+
), this._backBufferTexture;
|
|
701
|
+
}
|
|
702
|
+
/** destroys the back buffer */
|
|
703
|
+
destroy() {
|
|
704
|
+
this._backBufferTexture && (this._backBufferTexture.destroy(), this._backBufferTexture = null);
|
|
705
|
+
}
|
|
706
|
+
};
|
|
707
|
+
H.extension = {
|
|
708
|
+
type: [
|
|
709
|
+
d.WebGLSystem
|
|
710
|
+
],
|
|
711
|
+
name: "backBuffer",
|
|
712
|
+
priority: 1
|
|
713
|
+
};
|
|
714
|
+
H.defaultOptions = {
|
|
715
|
+
/** if true will use the back buffer where required */
|
|
716
|
+
useBackBuffer: !1
|
|
717
|
+
};
|
|
718
|
+
let Ze = H;
|
|
719
|
+
class oe {
|
|
720
|
+
constructor(e) {
|
|
721
|
+
this._colorMaskCache = 15, this._renderer = e;
|
|
722
|
+
}
|
|
723
|
+
setMask(e) {
|
|
724
|
+
this._colorMaskCache !== e && (this._colorMaskCache = e, this._renderer.gl.colorMask(
|
|
725
|
+
!!(e & 8),
|
|
726
|
+
!!(e & 4),
|
|
727
|
+
!!(e & 2),
|
|
728
|
+
!!(e & 1)
|
|
729
|
+
));
|
|
730
|
+
}
|
|
731
|
+
}
|
|
732
|
+
oe.extension = {
|
|
733
|
+
type: [
|
|
734
|
+
d.WebGLSystem
|
|
735
|
+
],
|
|
736
|
+
name: "colorMask"
|
|
737
|
+
};
|
|
738
|
+
class ce {
|
|
739
|
+
constructor(e) {
|
|
740
|
+
this.commandFinished = Promise.resolve(), this._renderer = e;
|
|
741
|
+
}
|
|
742
|
+
setGeometry(e, r) {
|
|
743
|
+
this._renderer.geometry.bind(e, r.glProgram);
|
|
744
|
+
}
|
|
745
|
+
finishRenderPass() {
|
|
746
|
+
}
|
|
747
|
+
draw(e) {
|
|
748
|
+
const r = this._renderer, { geometry: n, shader: s, state: i, skipSync: a, topology: o, size: u, start: c, instanceCount: _ } = e;
|
|
749
|
+
r.shader.bind(s, a), r.geometry.bind(n, r.shader._activeProgram), i && r.state.set(i), r.geometry.draw(o, u, c, _ ?? n.instanceCount);
|
|
750
|
+
}
|
|
751
|
+
destroy() {
|
|
752
|
+
this._renderer = null;
|
|
753
|
+
}
|
|
754
|
+
}
|
|
755
|
+
ce.extension = {
|
|
756
|
+
type: [
|
|
757
|
+
d.WebGLSystem
|
|
758
|
+
],
|
|
759
|
+
name: "encoder"
|
|
760
|
+
};
|
|
761
|
+
class ue {
|
|
762
|
+
constructor(e) {
|
|
763
|
+
this._renderer = e;
|
|
764
|
+
}
|
|
765
|
+
contextChange() {
|
|
766
|
+
const e = this._renderer.gl;
|
|
767
|
+
this.maxTextures = e.getParameter(e.MAX_TEXTURE_IMAGE_UNITS), this.maxBatchableTextures = Ne(this.maxTextures, e);
|
|
768
|
+
const r = this._renderer.context.webGLVersion === 2;
|
|
769
|
+
this.maxUniformBindings = r ? e.getParameter(e.MAX_UNIFORM_BUFFER_BINDINGS) : 0;
|
|
770
|
+
}
|
|
771
|
+
destroy() {
|
|
772
|
+
}
|
|
773
|
+
}
|
|
774
|
+
ue.extension = {
|
|
775
|
+
type: [
|
|
776
|
+
d.WebGLSystem
|
|
777
|
+
],
|
|
778
|
+
name: "limits"
|
|
779
|
+
};
|
|
780
|
+
class Qe {
|
|
781
|
+
constructor() {
|
|
782
|
+
this.width = -1, this.height = -1, this.msaa = !1, this._attachedMipLevel = 0, this._attachedLayer = 0, this.msaaRenderBuffer = [];
|
|
783
|
+
}
|
|
784
|
+
}
|
|
785
|
+
class _e {
|
|
786
|
+
constructor(e) {
|
|
787
|
+
this._stencilCache = {
|
|
788
|
+
enabled: !1,
|
|
789
|
+
stencilReference: 0,
|
|
790
|
+
stencilMode: g.NONE
|
|
791
|
+
}, this._renderTargetStencilState = /* @__PURE__ */ Object.create(null), e.renderTarget.onRenderTargetChange.add(this);
|
|
792
|
+
}
|
|
793
|
+
contextChange(e) {
|
|
794
|
+
this._gl = e, this._comparisonFuncMapping = {
|
|
795
|
+
always: e.ALWAYS,
|
|
796
|
+
never: e.NEVER,
|
|
797
|
+
equal: e.EQUAL,
|
|
798
|
+
"not-equal": e.NOTEQUAL,
|
|
799
|
+
less: e.LESS,
|
|
800
|
+
"less-equal": e.LEQUAL,
|
|
801
|
+
greater: e.GREATER,
|
|
802
|
+
"greater-equal": e.GEQUAL
|
|
803
|
+
}, this._stencilOpsMapping = {
|
|
804
|
+
keep: e.KEEP,
|
|
805
|
+
zero: e.ZERO,
|
|
806
|
+
replace: e.REPLACE,
|
|
807
|
+
invert: e.INVERT,
|
|
808
|
+
"increment-clamp": e.INCR,
|
|
809
|
+
"decrement-clamp": e.DECR,
|
|
810
|
+
"increment-wrap": e.INCR_WRAP,
|
|
811
|
+
"decrement-wrap": e.DECR_WRAP
|
|
812
|
+
}, this.resetState();
|
|
813
|
+
}
|
|
814
|
+
onRenderTargetChange(e) {
|
|
815
|
+
if (this._activeRenderTarget === e) return;
|
|
816
|
+
this._activeRenderTarget = e;
|
|
817
|
+
let r = this._renderTargetStencilState[e.uid];
|
|
818
|
+
r || (r = this._renderTargetStencilState[e.uid] = {
|
|
819
|
+
stencilMode: g.DISABLED,
|
|
820
|
+
stencilReference: 0
|
|
821
|
+
}), this.setStencilMode(r.stencilMode, r.stencilReference);
|
|
822
|
+
}
|
|
823
|
+
resetState() {
|
|
824
|
+
this._stencilCache.enabled = !1, this._stencilCache.stencilMode = g.NONE, this._stencilCache.stencilReference = 0;
|
|
825
|
+
}
|
|
826
|
+
setStencilMode(e, r) {
|
|
827
|
+
const n = this._renderTargetStencilState[this._activeRenderTarget.uid], s = this._gl, i = Oe[e], a = this._stencilCache;
|
|
828
|
+
if (n.stencilMode = e, n.stencilReference = r, e === g.DISABLED) {
|
|
829
|
+
this._stencilCache.enabled && (this._stencilCache.enabled = !1, s.disable(s.STENCIL_TEST));
|
|
830
|
+
return;
|
|
831
|
+
}
|
|
832
|
+
this._stencilCache.enabled || (this._stencilCache.enabled = !0, s.enable(s.STENCIL_TEST)), (e !== a.stencilMode || a.stencilReference !== r) && (a.stencilMode = e, a.stencilReference = r, s.stencilFunc(this._comparisonFuncMapping[i.stencilBack.compare], r, 255), s.stencilOp(s.KEEP, s.KEEP, this._stencilOpsMapping[i.stencilBack.passOp]));
|
|
833
|
+
}
|
|
834
|
+
}
|
|
835
|
+
_e.extension = {
|
|
836
|
+
type: [
|
|
837
|
+
d.WebGLSystem
|
|
838
|
+
],
|
|
839
|
+
name: "stencil"
|
|
840
|
+
};
|
|
841
|
+
const fe = {
|
|
842
|
+
f32: 4,
|
|
843
|
+
i32: 4,
|
|
844
|
+
"vec2<f32>": 8,
|
|
845
|
+
"vec3<f32>": 12,
|
|
846
|
+
"vec4<f32>": 16,
|
|
847
|
+
"vec2<i32>": 8,
|
|
848
|
+
"vec3<i32>": 12,
|
|
849
|
+
"vec4<i32>": 16,
|
|
850
|
+
"mat2x2<f32>": 32,
|
|
851
|
+
"mat3x3<f32>": 48,
|
|
852
|
+
"mat4x4<f32>": 64
|
|
853
|
+
// TODO - not essential for now but support these in the future
|
|
854
|
+
// int: 4,
|
|
855
|
+
// ivec2: 8,
|
|
856
|
+
// ivec3: 12,
|
|
857
|
+
// ivec4: 16,
|
|
858
|
+
// uint: 4,
|
|
859
|
+
// uvec2: 8,
|
|
860
|
+
// uvec3: 12,
|
|
861
|
+
// uvec4: 16,
|
|
862
|
+
// bool: 4,
|
|
863
|
+
// bvec2: 8,
|
|
864
|
+
// bvec3: 12,
|
|
865
|
+
// bvec4: 16,
|
|
866
|
+
// mat2: 16 * 2,
|
|
867
|
+
// mat3: 16 * 3,
|
|
868
|
+
// mat4: 16 * 4,
|
|
869
|
+
};
|
|
870
|
+
function Je(t) {
|
|
871
|
+
const e = t.map((i) => ({
|
|
872
|
+
data: i,
|
|
873
|
+
offset: 0,
|
|
874
|
+
size: 0
|
|
875
|
+
})), r = 16;
|
|
876
|
+
let n = 0, s = 0;
|
|
877
|
+
for (let i = 0; i < e.length; i++) {
|
|
878
|
+
const a = e[i];
|
|
879
|
+
if (n = fe[a.data.type], !n)
|
|
880
|
+
throw new Error(`Unknown type ${a.data.type}`);
|
|
881
|
+
a.data.size > 1 && (n = Math.max(n, r) * a.data.size);
|
|
882
|
+
const o = n === 12 ? 16 : n;
|
|
883
|
+
a.size = n;
|
|
884
|
+
const u = s % r;
|
|
885
|
+
u > 0 && r - u < o ? s += (r - u) % 16 : s += (n - u % n) % n, a.offset = s, s += n;
|
|
886
|
+
}
|
|
887
|
+
return s = Math.ceil(s / 16) * 16, { uboElements: e, size: s };
|
|
888
|
+
}
|
|
889
|
+
function et(t, e) {
|
|
890
|
+
const r = Math.max(fe[t.data.type] / 16, 1), n = t.data.value.length / t.data.size, s = (4 - n % 4) % 4, i = t.data.type.indexOf("i32") >= 0 ? "dataInt32" : "data";
|
|
891
|
+
return `
|
|
892
|
+
v = uv.${t.data.name};
|
|
893
|
+
offset += ${e};
|
|
894
|
+
|
|
895
|
+
arrayOffset = offset;
|
|
896
|
+
|
|
897
|
+
t = 0;
|
|
898
|
+
|
|
899
|
+
for(var i=0; i < ${t.data.size * r}; i++)
|
|
900
|
+
{
|
|
901
|
+
for(var j = 0; j < ${n}; j++)
|
|
902
|
+
{
|
|
903
|
+
${i}[arrayOffset++] = v[t++];
|
|
904
|
+
}
|
|
905
|
+
${s !== 0 ? `arrayOffset += ${s};` : ""}
|
|
906
|
+
}
|
|
907
|
+
`;
|
|
908
|
+
}
|
|
909
|
+
function tt(t) {
|
|
910
|
+
return Me(
|
|
911
|
+
t,
|
|
912
|
+
"uboStd40",
|
|
913
|
+
et,
|
|
914
|
+
Le
|
|
915
|
+
);
|
|
916
|
+
}
|
|
917
|
+
class he extends we {
|
|
918
|
+
constructor() {
|
|
919
|
+
super({
|
|
920
|
+
createUboElements: Je,
|
|
921
|
+
generateUboSync: tt
|
|
922
|
+
});
|
|
923
|
+
}
|
|
924
|
+
}
|
|
925
|
+
he.extension = {
|
|
926
|
+
type: [d.WebGLSystem],
|
|
927
|
+
name: "ubo"
|
|
928
|
+
};
|
|
929
|
+
class rt {
|
|
930
|
+
constructor() {
|
|
931
|
+
this._clearColorCache = [0, 0, 0, 0], this._viewPortCache = new V();
|
|
932
|
+
}
|
|
933
|
+
init(e, r) {
|
|
934
|
+
this._renderer = e, this._renderTargetSystem = r, e.runners.contextChange.add(this);
|
|
935
|
+
}
|
|
936
|
+
contextChange() {
|
|
937
|
+
this._clearColorCache = [0, 0, 0, 0], this._viewPortCache = new V();
|
|
938
|
+
const e = this._renderer.gl;
|
|
939
|
+
this._drawBuffersCache = [];
|
|
940
|
+
for (let r = 1; r <= 16; r++)
|
|
941
|
+
this._drawBuffersCache[r] = Array.from({ length: r }, (n, s) => e.COLOR_ATTACHMENT0 + s);
|
|
942
|
+
}
|
|
943
|
+
copyToTexture(e, r, n, s, i) {
|
|
944
|
+
const a = this._renderTargetSystem, o = this._renderer, u = a.getGpuRenderTarget(e), c = o.gl;
|
|
945
|
+
return this.finishRenderPass(e), c.bindFramebuffer(c.FRAMEBUFFER, u.resolveTargetFramebuffer), o.texture.bind(r, 0), c.copyTexSubImage2D(
|
|
946
|
+
c.TEXTURE_2D,
|
|
947
|
+
0,
|
|
948
|
+
i.x,
|
|
949
|
+
i.y,
|
|
950
|
+
n.x,
|
|
951
|
+
n.y,
|
|
952
|
+
s.width,
|
|
953
|
+
s.height
|
|
954
|
+
), r;
|
|
955
|
+
}
|
|
956
|
+
startRenderPass(e, r = !0, n, s, i = 0, a = 0) {
|
|
957
|
+
const o = this._renderTargetSystem, u = e.colorTexture, c = o.getGpuRenderTarget(e);
|
|
958
|
+
if (a !== 0 && this._renderer.context.webGLVersion < 2)
|
|
959
|
+
throw new Error("[RenderTargetSystem] Rendering to array layers requires WebGL2.");
|
|
960
|
+
if (i > 0) {
|
|
961
|
+
if (c.msaa)
|
|
962
|
+
throw new Error("[RenderTargetSystem] Rendering to mip levels is not supported with MSAA render targets.");
|
|
963
|
+
if (this._renderer.context.webGLVersion < 2)
|
|
964
|
+
throw new Error("[RenderTargetSystem] Rendering to mip levels requires WebGL2.");
|
|
965
|
+
}
|
|
966
|
+
let _ = s.y;
|
|
967
|
+
e.isRoot && (_ = u.pixelHeight - s.height - s.y), e.colorTextures.forEach((m) => {
|
|
968
|
+
this._renderer.texture.unbind(m);
|
|
969
|
+
});
|
|
970
|
+
const f = this._renderer.gl;
|
|
971
|
+
f.bindFramebuffer(f.FRAMEBUFFER, c.framebuffer), !e.isRoot && (c._attachedMipLevel !== i || c._attachedLayer !== a) && (e.colorTextures.forEach((m, b) => {
|
|
972
|
+
const E = this._renderer.texture.getGlSource(m);
|
|
973
|
+
if (E.target === f.TEXTURE_2D) {
|
|
974
|
+
if (a !== 0)
|
|
975
|
+
throw new Error("[RenderTargetSystem] layer must be 0 when rendering to 2D textures in WebGL.");
|
|
976
|
+
f.framebufferTexture2D(
|
|
977
|
+
f.FRAMEBUFFER,
|
|
978
|
+
f.COLOR_ATTACHMENT0 + b,
|
|
979
|
+
f.TEXTURE_2D,
|
|
980
|
+
E.texture,
|
|
981
|
+
i
|
|
982
|
+
);
|
|
983
|
+
} else if (E.target === f.TEXTURE_2D_ARRAY) {
|
|
984
|
+
if (this._renderer.context.webGLVersion < 2)
|
|
985
|
+
throw new Error("[RenderTargetSystem] Rendering to 2D array textures requires WebGL2.");
|
|
986
|
+
f.framebufferTextureLayer(
|
|
987
|
+
f.FRAMEBUFFER,
|
|
988
|
+
f.COLOR_ATTACHMENT0 + b,
|
|
989
|
+
E.texture,
|
|
990
|
+
i,
|
|
991
|
+
a
|
|
992
|
+
);
|
|
993
|
+
} else if (E.target === f.TEXTURE_CUBE_MAP) {
|
|
994
|
+
if (a < 0 || a > 5)
|
|
995
|
+
throw new Error("[RenderTargetSystem] Cube map layer must be between 0 and 5.");
|
|
996
|
+
f.framebufferTexture2D(
|
|
997
|
+
f.FRAMEBUFFER,
|
|
998
|
+
f.COLOR_ATTACHMENT0 + b,
|
|
999
|
+
f.TEXTURE_CUBE_MAP_POSITIVE_X + a,
|
|
1000
|
+
E.texture,
|
|
1001
|
+
i
|
|
1002
|
+
);
|
|
1003
|
+
} else
|
|
1004
|
+
throw new Error("[RenderTargetSystem] Unsupported texture target for render-to-layer in WebGL.");
|
|
1005
|
+
}), c._attachedMipLevel = i, c._attachedLayer = a), e.colorTextures.length > 1 && this._setDrawBuffers(e, f);
|
|
1006
|
+
const h = this._viewPortCache;
|
|
1007
|
+
(h.x !== s.x || h.y !== _ || h.width !== s.width || h.height !== s.height) && (h.x = s.x, h.y = _, h.width = s.width, h.height = s.height, f.viewport(
|
|
1008
|
+
s.x,
|
|
1009
|
+
_,
|
|
1010
|
+
s.width,
|
|
1011
|
+
s.height
|
|
1012
|
+
)), !c.depthStencilRenderBuffer && (e.stencil || e.depth) && this._initStencil(c), this.clear(e, r, n);
|
|
1013
|
+
}
|
|
1014
|
+
finishRenderPass(e) {
|
|
1015
|
+
const n = this._renderTargetSystem.getGpuRenderTarget(e);
|
|
1016
|
+
if (!n.msaa) return;
|
|
1017
|
+
const s = this._renderer.gl;
|
|
1018
|
+
s.bindFramebuffer(s.FRAMEBUFFER, n.resolveTargetFramebuffer), s.bindFramebuffer(s.READ_FRAMEBUFFER, n.framebuffer), s.blitFramebuffer(
|
|
1019
|
+
0,
|
|
1020
|
+
0,
|
|
1021
|
+
n.width,
|
|
1022
|
+
n.height,
|
|
1023
|
+
0,
|
|
1024
|
+
0,
|
|
1025
|
+
n.width,
|
|
1026
|
+
n.height,
|
|
1027
|
+
s.COLOR_BUFFER_BIT,
|
|
1028
|
+
s.NEAREST
|
|
1029
|
+
), s.bindFramebuffer(s.FRAMEBUFFER, n.framebuffer);
|
|
1030
|
+
}
|
|
1031
|
+
initGpuRenderTarget(e) {
|
|
1032
|
+
const n = this._renderer.gl, s = new Qe();
|
|
1033
|
+
return s._attachedMipLevel = 0, s._attachedLayer = 0, e.colorTexture instanceof y ? (this._renderer.context.ensureCanvasSize(e.colorTexture.resource), s.framebuffer = null, s) : (this._initColor(e, s), n.bindFramebuffer(n.FRAMEBUFFER, null), s);
|
|
1034
|
+
}
|
|
1035
|
+
destroyGpuRenderTarget(e) {
|
|
1036
|
+
const r = this._renderer.gl;
|
|
1037
|
+
e.framebuffer && (r.deleteFramebuffer(e.framebuffer), e.framebuffer = null), e.resolveTargetFramebuffer && (r.deleteFramebuffer(e.resolveTargetFramebuffer), e.resolveTargetFramebuffer = null), e.depthStencilRenderBuffer && (r.deleteRenderbuffer(e.depthStencilRenderBuffer), e.depthStencilRenderBuffer = null), e.msaaRenderBuffer.forEach((n) => {
|
|
1038
|
+
r.deleteRenderbuffer(n);
|
|
1039
|
+
}), e.msaaRenderBuffer = null;
|
|
1040
|
+
}
|
|
1041
|
+
clear(e, r, n, s, i = 0, a = 0) {
|
|
1042
|
+
if (!r) return;
|
|
1043
|
+
if (a !== 0)
|
|
1044
|
+
throw new Error("[RenderTargetSystem] Clearing array layers is not supported in WebGL renderer.");
|
|
1045
|
+
const o = this._renderTargetSystem;
|
|
1046
|
+
typeof r == "boolean" && (r = r ? C.ALL : C.NONE);
|
|
1047
|
+
const u = this._renderer.gl;
|
|
1048
|
+
if (r & C.COLOR) {
|
|
1049
|
+
n ?? (n = o.defaultClearColor);
|
|
1050
|
+
const c = this._clearColorCache, _ = n;
|
|
1051
|
+
(c[0] !== _[0] || c[1] !== _[1] || c[2] !== _[2] || c[3] !== _[3]) && (c[0] = _[0], c[1] = _[1], c[2] = _[2], c[3] = _[3], u.clearColor(_[0], _[1], _[2], _[3]));
|
|
1052
|
+
}
|
|
1053
|
+
u.clear(r);
|
|
1054
|
+
}
|
|
1055
|
+
resizeGpuRenderTarget(e) {
|
|
1056
|
+
if (e.isRoot) return;
|
|
1057
|
+
const n = this._renderTargetSystem.getGpuRenderTarget(e);
|
|
1058
|
+
this._resizeColor(e, n), (e.stencil || e.depth) && this._resizeStencil(n);
|
|
1059
|
+
}
|
|
1060
|
+
_initColor(e, r) {
|
|
1061
|
+
const n = this._renderer, s = n.gl, i = s.createFramebuffer();
|
|
1062
|
+
if (r.resolveTargetFramebuffer = i, s.bindFramebuffer(s.FRAMEBUFFER, i), r.width = e.colorTexture.source.pixelWidth, r.height = e.colorTexture.source.pixelHeight, e.colorTextures.forEach((o, u) => {
|
|
1063
|
+
const c = o.source;
|
|
1064
|
+
c.antialias && (n.context.supports.msaa ? r.msaa = !0 : p("[RenderTexture] Antialiasing on textures is not supported in WebGL1")), n.texture.bindSource(c, 0);
|
|
1065
|
+
const _ = n.texture.getGlSource(c), f = _.texture;
|
|
1066
|
+
if (_.target === s.TEXTURE_2D)
|
|
1067
|
+
s.framebufferTexture2D(
|
|
1068
|
+
s.FRAMEBUFFER,
|
|
1069
|
+
s.COLOR_ATTACHMENT0 + u,
|
|
1070
|
+
s.TEXTURE_2D,
|
|
1071
|
+
f,
|
|
1072
|
+
0
|
|
1073
|
+
);
|
|
1074
|
+
else if (_.target === s.TEXTURE_2D_ARRAY) {
|
|
1075
|
+
if (n.context.webGLVersion < 2)
|
|
1076
|
+
throw new Error("[RenderTargetSystem] TEXTURE_2D_ARRAY requires WebGL2.");
|
|
1077
|
+
s.framebufferTextureLayer(
|
|
1078
|
+
s.FRAMEBUFFER,
|
|
1079
|
+
s.COLOR_ATTACHMENT0 + u,
|
|
1080
|
+
f,
|
|
1081
|
+
0,
|
|
1082
|
+
0
|
|
1083
|
+
);
|
|
1084
|
+
} else if (_.target === s.TEXTURE_CUBE_MAP)
|
|
1085
|
+
s.framebufferTexture2D(
|
|
1086
|
+
s.FRAMEBUFFER,
|
|
1087
|
+
s.COLOR_ATTACHMENT0 + u,
|
|
1088
|
+
s.TEXTURE_CUBE_MAP_POSITIVE_X,
|
|
1089
|
+
f,
|
|
1090
|
+
0
|
|
1091
|
+
);
|
|
1092
|
+
else
|
|
1093
|
+
throw new Error("[RenderTargetSystem] Unsupported texture target for framebuffer attachment.");
|
|
1094
|
+
}), r.msaa) {
|
|
1095
|
+
const o = s.createFramebuffer();
|
|
1096
|
+
r.framebuffer = o, s.bindFramebuffer(s.FRAMEBUFFER, o), e.colorTextures.forEach((u, c) => {
|
|
1097
|
+
const _ = s.createRenderbuffer();
|
|
1098
|
+
r.msaaRenderBuffer[c] = _;
|
|
1099
|
+
});
|
|
1100
|
+
} else
|
|
1101
|
+
r.framebuffer = i;
|
|
1102
|
+
this._resizeColor(e, r);
|
|
1103
|
+
}
|
|
1104
|
+
_resizeColor(e, r) {
|
|
1105
|
+
const n = e.colorTexture.source;
|
|
1106
|
+
if (r.width = n.pixelWidth, r.height = n.pixelHeight, r._attachedMipLevel = 0, r._attachedLayer = 0, e.colorTextures.forEach((s, i) => {
|
|
1107
|
+
i !== 0 && s.source.resize(n.width, n.height, n._resolution);
|
|
1108
|
+
}), r.msaa) {
|
|
1109
|
+
const s = this._renderer, i = s.gl, a = r.framebuffer;
|
|
1110
|
+
i.bindFramebuffer(i.FRAMEBUFFER, a), e.colorTextures.forEach((o, u) => {
|
|
1111
|
+
const c = o.source;
|
|
1112
|
+
s.texture.bindSource(c, 0);
|
|
1113
|
+
const f = s.texture.getGlSource(c).internalFormat, h = r.msaaRenderBuffer[u];
|
|
1114
|
+
i.bindRenderbuffer(
|
|
1115
|
+
i.RENDERBUFFER,
|
|
1116
|
+
h
|
|
1117
|
+
), i.renderbufferStorageMultisample(
|
|
1118
|
+
i.RENDERBUFFER,
|
|
1119
|
+
4,
|
|
1120
|
+
f,
|
|
1121
|
+
c.pixelWidth,
|
|
1122
|
+
c.pixelHeight
|
|
1123
|
+
), i.framebufferRenderbuffer(
|
|
1124
|
+
i.FRAMEBUFFER,
|
|
1125
|
+
i.COLOR_ATTACHMENT0 + u,
|
|
1126
|
+
i.RENDERBUFFER,
|
|
1127
|
+
h
|
|
1128
|
+
);
|
|
1129
|
+
});
|
|
1130
|
+
}
|
|
1131
|
+
}
|
|
1132
|
+
_initStencil(e) {
|
|
1133
|
+
if (e.framebuffer === null) return;
|
|
1134
|
+
const r = this._renderer.gl, n = r.createRenderbuffer();
|
|
1135
|
+
e.depthStencilRenderBuffer = n, r.bindRenderbuffer(
|
|
1136
|
+
r.RENDERBUFFER,
|
|
1137
|
+
n
|
|
1138
|
+
), r.framebufferRenderbuffer(
|
|
1139
|
+
r.FRAMEBUFFER,
|
|
1140
|
+
r.DEPTH_STENCIL_ATTACHMENT,
|
|
1141
|
+
r.RENDERBUFFER,
|
|
1142
|
+
n
|
|
1143
|
+
), this._resizeStencil(e);
|
|
1144
|
+
}
|
|
1145
|
+
_resizeStencil(e) {
|
|
1146
|
+
const r = this._renderer.gl;
|
|
1147
|
+
r.bindRenderbuffer(
|
|
1148
|
+
r.RENDERBUFFER,
|
|
1149
|
+
e.depthStencilRenderBuffer
|
|
1150
|
+
), e.msaa ? r.renderbufferStorageMultisample(
|
|
1151
|
+
r.RENDERBUFFER,
|
|
1152
|
+
4,
|
|
1153
|
+
r.DEPTH24_STENCIL8,
|
|
1154
|
+
e.width,
|
|
1155
|
+
e.height
|
|
1156
|
+
) : r.renderbufferStorage(
|
|
1157
|
+
r.RENDERBUFFER,
|
|
1158
|
+
this._renderer.context.webGLVersion === 2 ? r.DEPTH24_STENCIL8 : r.DEPTH_STENCIL,
|
|
1159
|
+
e.width,
|
|
1160
|
+
e.height
|
|
1161
|
+
);
|
|
1162
|
+
}
|
|
1163
|
+
prerender(e) {
|
|
1164
|
+
const r = e.colorTexture.resource;
|
|
1165
|
+
this._renderer.context.multiView && y.test(r) && this._renderer.context.ensureCanvasSize(r);
|
|
1166
|
+
}
|
|
1167
|
+
postrender(e) {
|
|
1168
|
+
if (this._renderer.context.multiView && y.test(e.colorTexture.resource)) {
|
|
1169
|
+
const r = this._renderer.context.canvas, n = e.colorTexture;
|
|
1170
|
+
n.context2D.drawImage(
|
|
1171
|
+
r,
|
|
1172
|
+
0,
|
|
1173
|
+
n.pixelHeight - r.height
|
|
1174
|
+
);
|
|
1175
|
+
}
|
|
1176
|
+
}
|
|
1177
|
+
_setDrawBuffers(e, r) {
|
|
1178
|
+
const n = e.colorTextures.length, s = this._drawBuffersCache[n];
|
|
1179
|
+
if (this._renderer.context.webGLVersion === 1) {
|
|
1180
|
+
const i = this._renderer.context.extensions.drawBuffers;
|
|
1181
|
+
i ? i.drawBuffersWEBGL(s) : p("[RenderTexture] This WebGL1 context does not support rendering to multiple targets");
|
|
1182
|
+
} else
|
|
1183
|
+
r.drawBuffers(s);
|
|
1184
|
+
}
|
|
1185
|
+
}
|
|
1186
|
+
class le extends Ve {
|
|
1187
|
+
constructor(e) {
|
|
1188
|
+
super(e), this.adaptor = new rt(), this.adaptor.init(e, this);
|
|
1189
|
+
}
|
|
1190
|
+
}
|
|
1191
|
+
le.extension = {
|
|
1192
|
+
type: [d.WebGLSystem],
|
|
1193
|
+
name: "renderTarget"
|
|
1194
|
+
};
|
|
1195
|
+
function nt(t, e) {
|
|
1196
|
+
const r = [], n = [`
|
|
1197
|
+
var g = s.groups;
|
|
1198
|
+
var sS = r.shader;
|
|
1199
|
+
var p = s.glProgram;
|
|
1200
|
+
var ugS = r.uniformGroup;
|
|
1201
|
+
var resources;
|
|
1202
|
+
`];
|
|
1203
|
+
let s = !1, i = 0;
|
|
1204
|
+
const a = e._getProgramData(t.glProgram);
|
|
1205
|
+
for (const u in t.groups) {
|
|
1206
|
+
const c = t.groups[u];
|
|
1207
|
+
r.push(`
|
|
1208
|
+
resources = g[${u}].resources;
|
|
1209
|
+
`);
|
|
1210
|
+
for (const _ in c.resources) {
|
|
1211
|
+
const f = c.resources[_];
|
|
1212
|
+
if (f instanceof M)
|
|
1213
|
+
if (f.ubo) {
|
|
1214
|
+
const h = t._uniformBindMap[u][Number(_)];
|
|
1215
|
+
r.push(`
|
|
1216
|
+
sS.bindUniformBlock(
|
|
1217
|
+
resources[${_}],
|
|
1218
|
+
'${h}',
|
|
1219
|
+
${t.glProgram._uniformBlockData[h].index}
|
|
1220
|
+
);
|
|
1221
|
+
`);
|
|
1222
|
+
} else
|
|
1223
|
+
r.push(`
|
|
1224
|
+
ugS.updateUniformGroup(resources[${_}], p, sD);
|
|
1225
|
+
`);
|
|
1226
|
+
else if (f instanceof ee) {
|
|
1227
|
+
const h = t._uniformBindMap[u][Number(_)];
|
|
1228
|
+
r.push(`
|
|
1229
|
+
sS.bindUniformBlock(
|
|
1230
|
+
resources[${_}],
|
|
1231
|
+
'${h}',
|
|
1232
|
+
${t.glProgram._uniformBlockData[h].index}
|
|
1233
|
+
);
|
|
1234
|
+
`);
|
|
1235
|
+
} else if (f instanceof q) {
|
|
1236
|
+
const h = t._uniformBindMap[u][_], m = a.uniformData[h];
|
|
1237
|
+
m && (s || (s = !0, n.push(`
|
|
1238
|
+
var tS = r.texture;
|
|
1239
|
+
`)), e._gl.uniform1i(m.location, i), r.push(`
|
|
1240
|
+
tS.bind(resources[${_}], ${i});
|
|
1241
|
+
`), i++);
|
|
1242
|
+
}
|
|
1243
|
+
}
|
|
1244
|
+
}
|
|
1245
|
+
const o = [...n, ...r].join(`
|
|
1246
|
+
`);
|
|
1247
|
+
return new Function("r", "s", "sD", o);
|
|
1248
|
+
}
|
|
1249
|
+
class st {
|
|
1250
|
+
/**
|
|
1251
|
+
* Makes a new Pixi program.
|
|
1252
|
+
* @param program - webgl program
|
|
1253
|
+
* @param uniformData - uniforms
|
|
1254
|
+
*/
|
|
1255
|
+
constructor(e, r) {
|
|
1256
|
+
this.program = e, this.uniformData = r, this.uniformGroups = {}, this.uniformDirtyGroups = {}, this.uniformBlockBindings = {};
|
|
1257
|
+
}
|
|
1258
|
+
/** Destroys this program. */
|
|
1259
|
+
destroy() {
|
|
1260
|
+
this.uniformData = null, this.uniformGroups = null, this.uniformDirtyGroups = null, this.uniformBlockBindings = null, this.program = null;
|
|
1261
|
+
}
|
|
1262
|
+
}
|
|
1263
|
+
function k(t, e, r) {
|
|
1264
|
+
const n = t.createShader(e);
|
|
1265
|
+
return t.shaderSource(n, r), t.compileShader(n), n;
|
|
1266
|
+
}
|
|
1267
|
+
function D(t) {
|
|
1268
|
+
const e = new Array(t);
|
|
1269
|
+
for (let r = 0; r < e.length; r++)
|
|
1270
|
+
e[r] = !1;
|
|
1271
|
+
return e;
|
|
1272
|
+
}
|
|
1273
|
+
function de(t, e) {
|
|
1274
|
+
switch (t) {
|
|
1275
|
+
case "float":
|
|
1276
|
+
return 0;
|
|
1277
|
+
case "vec2":
|
|
1278
|
+
return new Float32Array(2 * e);
|
|
1279
|
+
case "vec3":
|
|
1280
|
+
return new Float32Array(3 * e);
|
|
1281
|
+
case "vec4":
|
|
1282
|
+
return new Float32Array(4 * e);
|
|
1283
|
+
case "int":
|
|
1284
|
+
case "uint":
|
|
1285
|
+
case "sampler2D":
|
|
1286
|
+
case "sampler2DArray":
|
|
1287
|
+
return 0;
|
|
1288
|
+
case "ivec2":
|
|
1289
|
+
return new Int32Array(2 * e);
|
|
1290
|
+
case "ivec3":
|
|
1291
|
+
return new Int32Array(3 * e);
|
|
1292
|
+
case "ivec4":
|
|
1293
|
+
return new Int32Array(4 * e);
|
|
1294
|
+
case "uvec2":
|
|
1295
|
+
return new Uint32Array(2 * e);
|
|
1296
|
+
case "uvec3":
|
|
1297
|
+
return new Uint32Array(3 * e);
|
|
1298
|
+
case "uvec4":
|
|
1299
|
+
return new Uint32Array(4 * e);
|
|
1300
|
+
case "bool":
|
|
1301
|
+
return !1;
|
|
1302
|
+
case "bvec2":
|
|
1303
|
+
return D(2 * e);
|
|
1304
|
+
case "bvec3":
|
|
1305
|
+
return D(3 * e);
|
|
1306
|
+
case "bvec4":
|
|
1307
|
+
return D(4 * e);
|
|
1308
|
+
case "mat2":
|
|
1309
|
+
return new Float32Array([
|
|
1310
|
+
1,
|
|
1311
|
+
0,
|
|
1312
|
+
0,
|
|
1313
|
+
1
|
|
1314
|
+
]);
|
|
1315
|
+
case "mat3":
|
|
1316
|
+
return new Float32Array([
|
|
1317
|
+
1,
|
|
1318
|
+
0,
|
|
1319
|
+
0,
|
|
1320
|
+
0,
|
|
1321
|
+
1,
|
|
1322
|
+
0,
|
|
1323
|
+
0,
|
|
1324
|
+
0,
|
|
1325
|
+
1
|
|
1326
|
+
]);
|
|
1327
|
+
case "mat4":
|
|
1328
|
+
return new Float32Array([
|
|
1329
|
+
1,
|
|
1330
|
+
0,
|
|
1331
|
+
0,
|
|
1332
|
+
0,
|
|
1333
|
+
0,
|
|
1334
|
+
1,
|
|
1335
|
+
0,
|
|
1336
|
+
0,
|
|
1337
|
+
0,
|
|
1338
|
+
0,
|
|
1339
|
+
1,
|
|
1340
|
+
0,
|
|
1341
|
+
0,
|
|
1342
|
+
0,
|
|
1343
|
+
0,
|
|
1344
|
+
1
|
|
1345
|
+
]);
|
|
1346
|
+
}
|
|
1347
|
+
return null;
|
|
1348
|
+
}
|
|
1349
|
+
let T = null;
|
|
1350
|
+
const W = {
|
|
1351
|
+
FLOAT: "float",
|
|
1352
|
+
FLOAT_VEC2: "vec2",
|
|
1353
|
+
FLOAT_VEC3: "vec3",
|
|
1354
|
+
FLOAT_VEC4: "vec4",
|
|
1355
|
+
INT: "int",
|
|
1356
|
+
INT_VEC2: "ivec2",
|
|
1357
|
+
INT_VEC3: "ivec3",
|
|
1358
|
+
INT_VEC4: "ivec4",
|
|
1359
|
+
UNSIGNED_INT: "uint",
|
|
1360
|
+
UNSIGNED_INT_VEC2: "uvec2",
|
|
1361
|
+
UNSIGNED_INT_VEC3: "uvec3",
|
|
1362
|
+
UNSIGNED_INT_VEC4: "uvec4",
|
|
1363
|
+
BOOL: "bool",
|
|
1364
|
+
BOOL_VEC2: "bvec2",
|
|
1365
|
+
BOOL_VEC3: "bvec3",
|
|
1366
|
+
BOOL_VEC4: "bvec4",
|
|
1367
|
+
FLOAT_MAT2: "mat2",
|
|
1368
|
+
FLOAT_MAT3: "mat3",
|
|
1369
|
+
FLOAT_MAT4: "mat4",
|
|
1370
|
+
SAMPLER_2D: "sampler2D",
|
|
1371
|
+
INT_SAMPLER_2D: "sampler2D",
|
|
1372
|
+
UNSIGNED_INT_SAMPLER_2D: "sampler2D",
|
|
1373
|
+
SAMPLER_CUBE: "samplerCube",
|
|
1374
|
+
INT_SAMPLER_CUBE: "samplerCube",
|
|
1375
|
+
UNSIGNED_INT_SAMPLER_CUBE: "samplerCube",
|
|
1376
|
+
SAMPLER_2D_ARRAY: "sampler2DArray",
|
|
1377
|
+
INT_SAMPLER_2D_ARRAY: "sampler2DArray",
|
|
1378
|
+
UNSIGNED_INT_SAMPLER_2D_ARRAY: "sampler2DArray"
|
|
1379
|
+
}, it = {
|
|
1380
|
+
float: "float32",
|
|
1381
|
+
vec2: "float32x2",
|
|
1382
|
+
vec3: "float32x3",
|
|
1383
|
+
vec4: "float32x4",
|
|
1384
|
+
int: "sint32",
|
|
1385
|
+
ivec2: "sint32x2",
|
|
1386
|
+
ivec3: "sint32x3",
|
|
1387
|
+
ivec4: "sint32x4",
|
|
1388
|
+
uint: "uint32",
|
|
1389
|
+
uvec2: "uint32x2",
|
|
1390
|
+
uvec3: "uint32x3",
|
|
1391
|
+
uvec4: "uint32x4",
|
|
1392
|
+
bool: "uint32",
|
|
1393
|
+
bvec2: "uint32x2",
|
|
1394
|
+
bvec3: "uint32x3",
|
|
1395
|
+
bvec4: "uint32x4"
|
|
1396
|
+
};
|
|
1397
|
+
function me(t, e) {
|
|
1398
|
+
if (!T) {
|
|
1399
|
+
const r = Object.keys(W);
|
|
1400
|
+
T = {};
|
|
1401
|
+
for (let n = 0; n < r.length; ++n) {
|
|
1402
|
+
const s = r[n];
|
|
1403
|
+
T[t[s]] = W[s];
|
|
1404
|
+
}
|
|
1405
|
+
}
|
|
1406
|
+
return T[e];
|
|
1407
|
+
}
|
|
1408
|
+
function at(t, e) {
|
|
1409
|
+
const r = me(t, e);
|
|
1410
|
+
return it[r] || "float32";
|
|
1411
|
+
}
|
|
1412
|
+
function ot(t, e, r = !1) {
|
|
1413
|
+
const n = {}, s = e.getProgramParameter(t, e.ACTIVE_ATTRIBUTES);
|
|
1414
|
+
for (let a = 0; a < s; a++) {
|
|
1415
|
+
const o = e.getActiveAttrib(t, a);
|
|
1416
|
+
if (o.name.startsWith("gl_"))
|
|
1417
|
+
continue;
|
|
1418
|
+
const u = at(e, o.type);
|
|
1419
|
+
n[o.name] = {
|
|
1420
|
+
location: 0,
|
|
1421
|
+
// set further down..
|
|
1422
|
+
format: u,
|
|
1423
|
+
stride: z(u).stride,
|
|
1424
|
+
offset: 0,
|
|
1425
|
+
instance: !1,
|
|
1426
|
+
start: 0
|
|
1427
|
+
};
|
|
1428
|
+
}
|
|
1429
|
+
const i = Object.keys(n);
|
|
1430
|
+
if (r) {
|
|
1431
|
+
i.sort((a, o) => a > o ? 1 : -1);
|
|
1432
|
+
for (let a = 0; a < i.length; a++)
|
|
1433
|
+
n[i[a]].location = a, e.bindAttribLocation(t, a, i[a]);
|
|
1434
|
+
e.linkProgram(t);
|
|
1435
|
+
} else
|
|
1436
|
+
for (let a = 0; a < i.length; a++)
|
|
1437
|
+
n[i[a]].location = e.getAttribLocation(t, i[a]);
|
|
1438
|
+
return n;
|
|
1439
|
+
}
|
|
1440
|
+
function ct(t, e) {
|
|
1441
|
+
if (!e.ACTIVE_UNIFORM_BLOCKS) return {};
|
|
1442
|
+
const r = {}, n = e.getProgramParameter(t, e.ACTIVE_UNIFORM_BLOCKS);
|
|
1443
|
+
for (let s = 0; s < n; s++) {
|
|
1444
|
+
const i = e.getActiveUniformBlockName(t, s), a = e.getUniformBlockIndex(t, i), o = e.getActiveUniformBlockParameter(t, s, e.UNIFORM_BLOCK_DATA_SIZE);
|
|
1445
|
+
r[i] = {
|
|
1446
|
+
name: i,
|
|
1447
|
+
index: a,
|
|
1448
|
+
size: o
|
|
1449
|
+
};
|
|
1450
|
+
}
|
|
1451
|
+
return r;
|
|
1452
|
+
}
|
|
1453
|
+
function ut(t, e) {
|
|
1454
|
+
const r = {}, n = e.getProgramParameter(t, e.ACTIVE_UNIFORMS);
|
|
1455
|
+
for (let s = 0; s < n; s++) {
|
|
1456
|
+
const i = e.getActiveUniform(t, s), a = i.name.replace(/\[.*?\]$/, ""), o = !!i.name.match(/\[.*?\]$/), u = me(e, i.type);
|
|
1457
|
+
r[a] = {
|
|
1458
|
+
name: a,
|
|
1459
|
+
index: s,
|
|
1460
|
+
type: u,
|
|
1461
|
+
size: i.size,
|
|
1462
|
+
isArray: o,
|
|
1463
|
+
value: de(u, i.size)
|
|
1464
|
+
};
|
|
1465
|
+
}
|
|
1466
|
+
return r;
|
|
1467
|
+
}
|
|
1468
|
+
function j(t, e) {
|
|
1469
|
+
const r = t.getShaderSource(e).split(`
|
|
1470
|
+
`).map((c, _) => `${_}: ${c}`), n = t.getShaderInfoLog(e), s = n.split(`
|
|
1471
|
+
`), i = {}, a = s.map((c) => parseFloat(c.replace(/^ERROR\: 0\:([\d]+)\:.*$/, "$1"))).filter((c) => c && !i[c] ? (i[c] = !0, !0) : !1), o = [""];
|
|
1472
|
+
a.forEach((c) => {
|
|
1473
|
+
r[c - 1] = `%c${r[c - 1]}%c`, o.push("background: #FF0000; color:#FFFFFF; font-size: 10px", "font-size: 10px");
|
|
1474
|
+
});
|
|
1475
|
+
const u = r.join(`
|
|
1476
|
+
`);
|
|
1477
|
+
o[0] = u, console.error(n), console.groupCollapsed("click to view full shader code"), console.warn(...o), console.groupEnd();
|
|
1478
|
+
}
|
|
1479
|
+
function _t(t, e, r, n) {
|
|
1480
|
+
t.getProgramParameter(e, t.LINK_STATUS) || (t.getShaderParameter(r, t.COMPILE_STATUS) || j(t, r), t.getShaderParameter(n, t.COMPILE_STATUS) || j(t, n), console.error("PixiJS Error: Could not initialize shader."), t.getProgramInfoLog(e) !== "" && console.warn("PixiJS Warning: gl.getProgramInfoLog()", t.getProgramInfoLog(e)));
|
|
1481
|
+
}
|
|
1482
|
+
function ft(t, e) {
|
|
1483
|
+
const r = k(t, t.VERTEX_SHADER, e.vertex), n = k(t, t.FRAGMENT_SHADER, e.fragment), s = t.createProgram();
|
|
1484
|
+
t.attachShader(s, r), t.attachShader(s, n);
|
|
1485
|
+
const i = e.transformFeedbackVaryings;
|
|
1486
|
+
i && (typeof t.transformFeedbackVaryings != "function" ? p("TransformFeedback is not supported but TransformFeedbackVaryings are given.") : t.transformFeedbackVaryings(
|
|
1487
|
+
s,
|
|
1488
|
+
i.names,
|
|
1489
|
+
i.bufferMode === "separate" ? t.SEPARATE_ATTRIBS : t.INTERLEAVED_ATTRIBS
|
|
1490
|
+
)), t.linkProgram(s), t.getProgramParameter(s, t.LINK_STATUS) || _t(t, s, r, n), e._attributeData = ot(
|
|
1491
|
+
s,
|
|
1492
|
+
t,
|
|
1493
|
+
!/^[ \t]*#[ \t]*version[ \t]+300[ \t]+es[ \t]*$/m.test(e.vertex)
|
|
1494
|
+
), e._uniformData = ut(s, t), e._uniformBlockData = ct(s, t), t.deleteShader(r), t.deleteShader(n);
|
|
1495
|
+
const a = {};
|
|
1496
|
+
for (const u in e._uniformData) {
|
|
1497
|
+
const c = e._uniformData[u];
|
|
1498
|
+
a[u] = {
|
|
1499
|
+
location: t.getUniformLocation(s, u),
|
|
1500
|
+
value: de(c.type, c.size)
|
|
1501
|
+
};
|
|
1502
|
+
}
|
|
1503
|
+
return new st(s, a);
|
|
1504
|
+
}
|
|
1505
|
+
const x = {
|
|
1506
|
+
textureCount: 0,
|
|
1507
|
+
blockIndex: 0
|
|
1508
|
+
};
|
|
1509
|
+
class Ee {
|
|
1510
|
+
constructor(e) {
|
|
1511
|
+
this._activeProgram = null, this._programDataHash = /* @__PURE__ */ Object.create(null), this._shaderSyncFunctions = /* @__PURE__ */ Object.create(null), this._renderer = e;
|
|
1512
|
+
}
|
|
1513
|
+
contextChange(e) {
|
|
1514
|
+
this._gl = e, this._programDataHash = /* @__PURE__ */ Object.create(null), this._shaderSyncFunctions = /* @__PURE__ */ Object.create(null), this._activeProgram = null;
|
|
1515
|
+
}
|
|
1516
|
+
/**
|
|
1517
|
+
* Changes the current shader to the one given in parameter.
|
|
1518
|
+
* @param shader - the new shader
|
|
1519
|
+
* @param skipSync - false if the shader should automatically sync its uniforms.
|
|
1520
|
+
* @returns the glProgram that belongs to the shader.
|
|
1521
|
+
*/
|
|
1522
|
+
bind(e, r) {
|
|
1523
|
+
if (this._setProgram(e.glProgram), r) return;
|
|
1524
|
+
x.textureCount = 0, x.blockIndex = 0;
|
|
1525
|
+
let n = this._shaderSyncFunctions[e.glProgram._key];
|
|
1526
|
+
n || (n = this._shaderSyncFunctions[e.glProgram._key] = this._generateShaderSync(e, this)), this._renderer.buffer.nextBindBase(!!e.glProgram.transformFeedbackVaryings), n(this._renderer, e, x);
|
|
1527
|
+
}
|
|
1528
|
+
/**
|
|
1529
|
+
* Updates the uniform group.
|
|
1530
|
+
* @param uniformGroup - the uniform group to update
|
|
1531
|
+
*/
|
|
1532
|
+
updateUniformGroup(e) {
|
|
1533
|
+
this._renderer.uniformGroup.updateUniformGroup(e, this._activeProgram, x);
|
|
1534
|
+
}
|
|
1535
|
+
/**
|
|
1536
|
+
* Binds a uniform block to the shader.
|
|
1537
|
+
* @param uniformGroup - the uniform group to bind
|
|
1538
|
+
* @param name - the name of the uniform block
|
|
1539
|
+
* @param index - the index of the uniform block
|
|
1540
|
+
*/
|
|
1541
|
+
bindUniformBlock(e, r, n = 0) {
|
|
1542
|
+
const s = this._renderer.buffer, i = this._getProgramData(this._activeProgram), a = e._bufferResource;
|
|
1543
|
+
a || this._renderer.ubo.updateUniformGroup(e);
|
|
1544
|
+
const o = e.buffer, u = s.updateBuffer(o), c = s.freeLocationForBufferBase(u);
|
|
1545
|
+
if (a) {
|
|
1546
|
+
const { offset: f, size: h } = e;
|
|
1547
|
+
f === 0 && h === o.data.byteLength ? s.bindBufferBase(u, c) : s.bindBufferRange(u, c, f);
|
|
1548
|
+
} else s.getLastBindBaseLocation(u) !== c && s.bindBufferBase(u, c);
|
|
1549
|
+
const _ = this._activeProgram._uniformBlockData[r].index;
|
|
1550
|
+
i.uniformBlockBindings[n] !== c && (i.uniformBlockBindings[n] = c, this._renderer.gl.uniformBlockBinding(i.program, _, c));
|
|
1551
|
+
}
|
|
1552
|
+
_setProgram(e) {
|
|
1553
|
+
if (this._activeProgram === e) return;
|
|
1554
|
+
this._activeProgram = e;
|
|
1555
|
+
const r = this._getProgramData(e);
|
|
1556
|
+
this._gl.useProgram(r.program);
|
|
1557
|
+
}
|
|
1558
|
+
/**
|
|
1559
|
+
* @param program - the program to get the data for
|
|
1560
|
+
* @internal
|
|
1561
|
+
*/
|
|
1562
|
+
_getProgramData(e) {
|
|
1563
|
+
return this._programDataHash[e._key] || this._createProgramData(e);
|
|
1564
|
+
}
|
|
1565
|
+
_createProgramData(e) {
|
|
1566
|
+
const r = e._key;
|
|
1567
|
+
return this._programDataHash[r] = ft(this._gl, e), this._programDataHash[r];
|
|
1568
|
+
}
|
|
1569
|
+
destroy() {
|
|
1570
|
+
for (const e of Object.keys(this._programDataHash))
|
|
1571
|
+
this._programDataHash[e].destroy();
|
|
1572
|
+
this._programDataHash = null, this._shaderSyncFunctions = null, this._activeProgram = null, this._renderer = null, this._gl = null;
|
|
1573
|
+
}
|
|
1574
|
+
/**
|
|
1575
|
+
* Creates a function that can be executed that will sync the shader as efficiently as possible.
|
|
1576
|
+
* Overridden by the unsafe eval package if you don't want eval used in your project.
|
|
1577
|
+
* @param shader - the shader to generate the sync function for
|
|
1578
|
+
* @param shaderSystem - the shader system to use
|
|
1579
|
+
* @returns - the generated sync function
|
|
1580
|
+
* @ignore
|
|
1581
|
+
*/
|
|
1582
|
+
_generateShaderSync(e, r) {
|
|
1583
|
+
return nt(e, r);
|
|
1584
|
+
}
|
|
1585
|
+
resetState() {
|
|
1586
|
+
this._activeProgram = null;
|
|
1587
|
+
}
|
|
1588
|
+
}
|
|
1589
|
+
Ee.extension = {
|
|
1590
|
+
type: [
|
|
1591
|
+
d.WebGLSystem
|
|
1592
|
+
],
|
|
1593
|
+
name: "shader"
|
|
1594
|
+
};
|
|
1595
|
+
const ht = {
|
|
1596
|
+
f32: `if (cv !== v) {
|
|
1597
|
+
cu.value = v;
|
|
1598
|
+
gl.uniform1f(location, v);
|
|
1599
|
+
}`,
|
|
1600
|
+
"vec2<f32>": `if (cv[0] !== v[0] || cv[1] !== v[1]) {
|
|
1601
|
+
cv[0] = v[0];
|
|
1602
|
+
cv[1] = v[1];
|
|
1603
|
+
gl.uniform2f(location, v[0], v[1]);
|
|
1604
|
+
}`,
|
|
1605
|
+
"vec3<f32>": `if (cv[0] !== v[0] || cv[1] !== v[1] || cv[2] !== v[2]) {
|
|
1606
|
+
cv[0] = v[0];
|
|
1607
|
+
cv[1] = v[1];
|
|
1608
|
+
cv[2] = v[2];
|
|
1609
|
+
gl.uniform3f(location, v[0], v[1], v[2]);
|
|
1610
|
+
}`,
|
|
1611
|
+
"vec4<f32>": `if (cv[0] !== v[0] || cv[1] !== v[1] || cv[2] !== v[2] || cv[3] !== v[3]) {
|
|
1612
|
+
cv[0] = v[0];
|
|
1613
|
+
cv[1] = v[1];
|
|
1614
|
+
cv[2] = v[2];
|
|
1615
|
+
cv[3] = v[3];
|
|
1616
|
+
gl.uniform4f(location, v[0], v[1], v[2], v[3]);
|
|
1617
|
+
}`,
|
|
1618
|
+
i32: `if (cv !== v) {
|
|
1619
|
+
cu.value = v;
|
|
1620
|
+
gl.uniform1i(location, v);
|
|
1621
|
+
}`,
|
|
1622
|
+
"vec2<i32>": `if (cv[0] !== v[0] || cv[1] !== v[1]) {
|
|
1623
|
+
cv[0] = v[0];
|
|
1624
|
+
cv[1] = v[1];
|
|
1625
|
+
gl.uniform2i(location, v[0], v[1]);
|
|
1626
|
+
}`,
|
|
1627
|
+
"vec3<i32>": `if (cv[0] !== v[0] || cv[1] !== v[1] || cv[2] !== v[2]) {
|
|
1628
|
+
cv[0] = v[0];
|
|
1629
|
+
cv[1] = v[1];
|
|
1630
|
+
cv[2] = v[2];
|
|
1631
|
+
gl.uniform3i(location, v[0], v[1], v[2]);
|
|
1632
|
+
}`,
|
|
1633
|
+
"vec4<i32>": `if (cv[0] !== v[0] || cv[1] !== v[1] || cv[2] !== v[2] || cv[3] !== v[3]) {
|
|
1634
|
+
cv[0] = v[0];
|
|
1635
|
+
cv[1] = v[1];
|
|
1636
|
+
cv[2] = v[2];
|
|
1637
|
+
cv[3] = v[3];
|
|
1638
|
+
gl.uniform4i(location, v[0], v[1], v[2], v[3]);
|
|
1639
|
+
}`,
|
|
1640
|
+
u32: `if (cv !== v) {
|
|
1641
|
+
cu.value = v;
|
|
1642
|
+
gl.uniform1ui(location, v);
|
|
1643
|
+
}`,
|
|
1644
|
+
"vec2<u32>": `if (cv[0] !== v[0] || cv[1] !== v[1]) {
|
|
1645
|
+
cv[0] = v[0];
|
|
1646
|
+
cv[1] = v[1];
|
|
1647
|
+
gl.uniform2ui(location, v[0], v[1]);
|
|
1648
|
+
}`,
|
|
1649
|
+
"vec3<u32>": `if (cv[0] !== v[0] || cv[1] !== v[1] || cv[2] !== v[2]) {
|
|
1650
|
+
cv[0] = v[0];
|
|
1651
|
+
cv[1] = v[1];
|
|
1652
|
+
cv[2] = v[2];
|
|
1653
|
+
gl.uniform3ui(location, v[0], v[1], v[2]);
|
|
1654
|
+
}`,
|
|
1655
|
+
"vec4<u32>": `if (cv[0] !== v[0] || cv[1] !== v[1] || cv[2] !== v[2] || cv[3] !== v[3]) {
|
|
1656
|
+
cv[0] = v[0];
|
|
1657
|
+
cv[1] = v[1];
|
|
1658
|
+
cv[2] = v[2];
|
|
1659
|
+
cv[3] = v[3];
|
|
1660
|
+
gl.uniform4ui(location, v[0], v[1], v[2], v[3]);
|
|
1661
|
+
}`,
|
|
1662
|
+
bool: `if (cv !== v) {
|
|
1663
|
+
cu.value = v;
|
|
1664
|
+
gl.uniform1i(location, v);
|
|
1665
|
+
}`,
|
|
1666
|
+
"vec2<bool>": `if (cv[0] !== v[0] || cv[1] !== v[1]) {
|
|
1667
|
+
cv[0] = v[0];
|
|
1668
|
+
cv[1] = v[1];
|
|
1669
|
+
gl.uniform2i(location, v[0], v[1]);
|
|
1670
|
+
}`,
|
|
1671
|
+
"vec3<bool>": `if (cv[0] !== v[0] || cv[1] !== v[1] || cv[2] !== v[2]) {
|
|
1672
|
+
cv[0] = v[0];
|
|
1673
|
+
cv[1] = v[1];
|
|
1674
|
+
cv[2] = v[2];
|
|
1675
|
+
gl.uniform3i(location, v[0], v[1], v[2]);
|
|
1676
|
+
}`,
|
|
1677
|
+
"vec4<bool>": `if (cv[0] !== v[0] || cv[1] !== v[1] || cv[2] !== v[2] || cv[3] !== v[3]) {
|
|
1678
|
+
cv[0] = v[0];
|
|
1679
|
+
cv[1] = v[1];
|
|
1680
|
+
cv[2] = v[2];
|
|
1681
|
+
cv[3] = v[3];
|
|
1682
|
+
gl.uniform4i(location, v[0], v[1], v[2], v[3]);
|
|
1683
|
+
}`,
|
|
1684
|
+
"mat2x2<f32>": "gl.uniformMatrix2fv(location, false, v);",
|
|
1685
|
+
"mat3x3<f32>": "gl.uniformMatrix3fv(location, false, v);",
|
|
1686
|
+
"mat4x4<f32>": "gl.uniformMatrix4fv(location, false, v);"
|
|
1687
|
+
}, lt = {
|
|
1688
|
+
f32: "gl.uniform1fv(location, v);",
|
|
1689
|
+
"vec2<f32>": "gl.uniform2fv(location, v);",
|
|
1690
|
+
"vec3<f32>": "gl.uniform3fv(location, v);",
|
|
1691
|
+
"vec4<f32>": "gl.uniform4fv(location, v);",
|
|
1692
|
+
"mat2x2<f32>": "gl.uniformMatrix2fv(location, false, v);",
|
|
1693
|
+
"mat3x3<f32>": "gl.uniformMatrix3fv(location, false, v);",
|
|
1694
|
+
"mat4x4<f32>": "gl.uniformMatrix4fv(location, false, v);",
|
|
1695
|
+
i32: "gl.uniform1iv(location, v);",
|
|
1696
|
+
"vec2<i32>": "gl.uniform2iv(location, v);",
|
|
1697
|
+
"vec3<i32>": "gl.uniform3iv(location, v);",
|
|
1698
|
+
"vec4<i32>": "gl.uniform4iv(location, v);",
|
|
1699
|
+
u32: "gl.uniform1iv(location, v);",
|
|
1700
|
+
"vec2<u32>": "gl.uniform2iv(location, v);",
|
|
1701
|
+
"vec3<u32>": "gl.uniform3iv(location, v);",
|
|
1702
|
+
"vec4<u32>": "gl.uniform4iv(location, v);",
|
|
1703
|
+
bool: "gl.uniform1iv(location, v);",
|
|
1704
|
+
"vec2<bool>": "gl.uniform2iv(location, v);",
|
|
1705
|
+
"vec3<bool>": "gl.uniform3iv(location, v);",
|
|
1706
|
+
"vec4<bool>": "gl.uniform4iv(location, v);"
|
|
1707
|
+
};
|
|
1708
|
+
function dt(t, e) {
|
|
1709
|
+
const r = [`
|
|
1710
|
+
var v = null;
|
|
1711
|
+
var cv = null;
|
|
1712
|
+
var cu = null;
|
|
1713
|
+
var t = 0;
|
|
1714
|
+
var gl = renderer.gl;
|
|
1715
|
+
var name = null;
|
|
1716
|
+
`];
|
|
1717
|
+
for (const n in t.uniforms) {
|
|
1718
|
+
if (!e[n]) {
|
|
1719
|
+
t.uniforms[n] instanceof M ? t.uniforms[n].ubo ? r.push(`
|
|
1720
|
+
renderer.shader.bindUniformBlock(uv.${n}, "${n}");
|
|
1721
|
+
`) : r.push(`
|
|
1722
|
+
renderer.shader.updateUniformGroup(uv.${n});
|
|
1723
|
+
`) : t.uniforms[n] instanceof ee && r.push(`
|
|
1724
|
+
renderer.shader.bindBufferResource(uv.${n}, "${n}");
|
|
1725
|
+
`);
|
|
1726
|
+
continue;
|
|
1727
|
+
}
|
|
1728
|
+
const s = t.uniformStructures[n];
|
|
1729
|
+
let i = !1;
|
|
1730
|
+
for (let a = 0; a < N.length; a++) {
|
|
1731
|
+
const o = N[a];
|
|
1732
|
+
if (s.type === o.type && o.test(s)) {
|
|
1733
|
+
r.push(`name = "${n}";`, N[a].uniform), i = !0;
|
|
1734
|
+
break;
|
|
1735
|
+
}
|
|
1736
|
+
}
|
|
1737
|
+
if (!i) {
|
|
1738
|
+
const o = (s.size === 1 ? ht : lt)[s.type].replace("location", `ud["${n}"].location`);
|
|
1739
|
+
r.push(`
|
|
1740
|
+
cu = ud["${n}"];
|
|
1741
|
+
cv = cu.value;
|
|
1742
|
+
v = uv["${n}"];
|
|
1743
|
+
${o};`);
|
|
1744
|
+
}
|
|
1745
|
+
}
|
|
1746
|
+
return new Function("ud", "uv", "renderer", "syncData", r.join(`
|
|
1747
|
+
`));
|
|
1748
|
+
}
|
|
1749
|
+
class be {
|
|
1750
|
+
/** @param renderer - The renderer this System works for. */
|
|
1751
|
+
constructor(e) {
|
|
1752
|
+
this._cache = {}, this._uniformGroupSyncHash = {}, this._renderer = e, this.gl = null, this._cache = {};
|
|
1753
|
+
}
|
|
1754
|
+
contextChange(e) {
|
|
1755
|
+
this.gl = e;
|
|
1756
|
+
}
|
|
1757
|
+
/**
|
|
1758
|
+
* Uploads the uniforms values to the currently bound shader.
|
|
1759
|
+
* @param group - the uniforms values that be applied to the current shader
|
|
1760
|
+
* @param program
|
|
1761
|
+
* @param syncData
|
|
1762
|
+
* @param syncData.textureCount
|
|
1763
|
+
*/
|
|
1764
|
+
updateUniformGroup(e, r, n) {
|
|
1765
|
+
const s = this._renderer.shader._getProgramData(r);
|
|
1766
|
+
(!e.isStatic || e._dirtyId !== s.uniformDirtyGroups[e.uid]) && (s.uniformDirtyGroups[e.uid] = e._dirtyId, this._getUniformSyncFunction(e, r)(s.uniformData, e.uniforms, this._renderer, n));
|
|
1767
|
+
}
|
|
1768
|
+
/**
|
|
1769
|
+
* Overridable by the pixi.js/unsafe-eval package to use static syncUniforms instead.
|
|
1770
|
+
* @param group
|
|
1771
|
+
* @param program
|
|
1772
|
+
*/
|
|
1773
|
+
_getUniformSyncFunction(e, r) {
|
|
1774
|
+
var n;
|
|
1775
|
+
return ((n = this._uniformGroupSyncHash[e._signature]) == null ? void 0 : n[r._key]) || this._createUniformSyncFunction(e, r);
|
|
1776
|
+
}
|
|
1777
|
+
_createUniformSyncFunction(e, r) {
|
|
1778
|
+
const n = this._uniformGroupSyncHash[e._signature] || (this._uniformGroupSyncHash[e._signature] = {}), s = this._getSignature(e, r._uniformData, "u");
|
|
1779
|
+
return this._cache[s] || (this._cache[s] = this._generateUniformsSync(e, r._uniformData)), n[r._key] = this._cache[s], n[r._key];
|
|
1780
|
+
}
|
|
1781
|
+
_generateUniformsSync(e, r) {
|
|
1782
|
+
return dt(e, r);
|
|
1783
|
+
}
|
|
1784
|
+
/**
|
|
1785
|
+
* Takes a uniform group and data and generates a unique signature for them.
|
|
1786
|
+
* @param group - The uniform group to get signature of
|
|
1787
|
+
* @param group.uniforms
|
|
1788
|
+
* @param uniformData - Uniform information generated by the shader
|
|
1789
|
+
* @param preFix
|
|
1790
|
+
* @returns Unique signature of the uniform group
|
|
1791
|
+
*/
|
|
1792
|
+
_getSignature(e, r, n) {
|
|
1793
|
+
const s = e.uniforms, i = [`${n}-`];
|
|
1794
|
+
for (const a in s)
|
|
1795
|
+
i.push(a), r[a] && i.push(r[a].type);
|
|
1796
|
+
return i.join("-");
|
|
1797
|
+
}
|
|
1798
|
+
/** Destroys this System and removes all its textures. */
|
|
1799
|
+
destroy() {
|
|
1800
|
+
this._renderer = null, this._cache = null;
|
|
1801
|
+
}
|
|
1802
|
+
}
|
|
1803
|
+
be.extension = {
|
|
1804
|
+
type: [
|
|
1805
|
+
d.WebGLSystem
|
|
1806
|
+
],
|
|
1807
|
+
name: "uniformGroup"
|
|
1808
|
+
};
|
|
1809
|
+
function mt(t) {
|
|
1810
|
+
const e = {};
|
|
1811
|
+
if (e.normal = [t.ONE, t.ONE_MINUS_SRC_ALPHA], e.add = [t.ONE, t.ONE], e.multiply = [t.DST_COLOR, t.ONE_MINUS_SRC_ALPHA, t.ONE, t.ONE_MINUS_SRC_ALPHA], e.screen = [t.ONE, t.ONE_MINUS_SRC_COLOR, t.ONE, t.ONE_MINUS_SRC_ALPHA], e.none = [0, 0], e["normal-npm"] = [t.SRC_ALPHA, t.ONE_MINUS_SRC_ALPHA, t.ONE, t.ONE_MINUS_SRC_ALPHA], e["add-npm"] = [t.SRC_ALPHA, t.ONE, t.ONE, t.ONE], e["screen-npm"] = [t.SRC_ALPHA, t.ONE_MINUS_SRC_COLOR, t.ONE, t.ONE_MINUS_SRC_ALPHA], e.erase = [t.ZERO, t.ONE_MINUS_SRC_ALPHA], !(t instanceof R.get().getWebGLRenderingContext()))
|
|
1812
|
+
e.min = [t.ONE, t.ONE, t.ONE, t.ONE, t.MIN, t.MIN], e.max = [t.ONE, t.ONE, t.ONE, t.ONE, t.MAX, t.MAX];
|
|
1813
|
+
else {
|
|
1814
|
+
const n = t.getExtension("EXT_blend_minmax");
|
|
1815
|
+
n && (e.min = [t.ONE, t.ONE, t.ONE, t.ONE, n.MIN_EXT, n.MIN_EXT], e.max = [t.ONE, t.ONE, t.ONE, t.ONE, n.MAX_EXT, n.MAX_EXT]);
|
|
1816
|
+
}
|
|
1817
|
+
return e;
|
|
1818
|
+
}
|
|
1819
|
+
const Et = 0, bt = 1, pt = 2, St = 3, Rt = 4, gt = 5, pe = class U {
|
|
1820
|
+
constructor(e) {
|
|
1821
|
+
this._invertFrontFace = !1, this.gl = null, this.stateId = 0, this.polygonOffset = 0, this.blendMode = "none", this._blendEq = !1, this.map = [], this.map[Et] = this.setBlend, this.map[bt] = this.setOffset, this.map[pt] = this.setCullFace, this.map[St] = this.setDepthTest, this.map[Rt] = this.setFrontFace, this.map[gt] = this.setDepthMask, this.checks = [], this.defaultState = F.for2d(), e.renderTarget.onRenderTargetChange.add(this);
|
|
1822
|
+
}
|
|
1823
|
+
onRenderTargetChange(e) {
|
|
1824
|
+
this._invertFrontFace = !e.isRoot, this._cullFace ? this.setFrontFace(this._frontFace) : this._frontFaceDirty = !0;
|
|
1825
|
+
}
|
|
1826
|
+
contextChange(e) {
|
|
1827
|
+
this.gl = e, this.blendModesMap = mt(e), this.resetState();
|
|
1828
|
+
}
|
|
1829
|
+
/**
|
|
1830
|
+
* Sets the current state
|
|
1831
|
+
* @param {*} state - The state to set.
|
|
1832
|
+
*/
|
|
1833
|
+
set(e) {
|
|
1834
|
+
if (e || (e = this.defaultState), this.stateId !== e.data) {
|
|
1835
|
+
let r = this.stateId ^ e.data, n = 0;
|
|
1836
|
+
for (; r; )
|
|
1837
|
+
r & 1 && this.map[n].call(this, !!(e.data & 1 << n)), r >>= 1, n++;
|
|
1838
|
+
this.stateId = e.data;
|
|
1839
|
+
}
|
|
1840
|
+
for (let r = 0; r < this.checks.length; r++)
|
|
1841
|
+
this.checks[r](this, e);
|
|
1842
|
+
}
|
|
1843
|
+
/**
|
|
1844
|
+
* Sets the state, when previous state is unknown.
|
|
1845
|
+
* @param {*} state - The state to set
|
|
1846
|
+
*/
|
|
1847
|
+
forceState(e) {
|
|
1848
|
+
e || (e = this.defaultState);
|
|
1849
|
+
for (let r = 0; r < this.map.length; r++)
|
|
1850
|
+
this.map[r].call(this, !!(e.data & 1 << r));
|
|
1851
|
+
for (let r = 0; r < this.checks.length; r++)
|
|
1852
|
+
this.checks[r](this, e);
|
|
1853
|
+
this.stateId = e.data;
|
|
1854
|
+
}
|
|
1855
|
+
/**
|
|
1856
|
+
* Sets whether to enable or disable blending.
|
|
1857
|
+
* @param value - Turn on or off WebGl blending.
|
|
1858
|
+
*/
|
|
1859
|
+
setBlend(e) {
|
|
1860
|
+
this._updateCheck(U._checkBlendMode, e), this.gl[e ? "enable" : "disable"](this.gl.BLEND);
|
|
1861
|
+
}
|
|
1862
|
+
/**
|
|
1863
|
+
* Sets whether to enable or disable polygon offset fill.
|
|
1864
|
+
* @param value - Turn on or off webgl polygon offset testing.
|
|
1865
|
+
*/
|
|
1866
|
+
setOffset(e) {
|
|
1867
|
+
this._updateCheck(U._checkPolygonOffset, e), this.gl[e ? "enable" : "disable"](this.gl.POLYGON_OFFSET_FILL);
|
|
1868
|
+
}
|
|
1869
|
+
/**
|
|
1870
|
+
* Sets whether to enable or disable depth test.
|
|
1871
|
+
* @param value - Turn on or off webgl depth testing.
|
|
1872
|
+
*/
|
|
1873
|
+
setDepthTest(e) {
|
|
1874
|
+
this.gl[e ? "enable" : "disable"](this.gl.DEPTH_TEST);
|
|
1875
|
+
}
|
|
1876
|
+
/**
|
|
1877
|
+
* Sets whether to enable or disable depth mask.
|
|
1878
|
+
* @param value - Turn on or off webgl depth mask.
|
|
1879
|
+
*/
|
|
1880
|
+
setDepthMask(e) {
|
|
1881
|
+
this.gl.depthMask(e);
|
|
1882
|
+
}
|
|
1883
|
+
/**
|
|
1884
|
+
* Sets whether to enable or disable cull face.
|
|
1885
|
+
* @param {boolean} value - Turn on or off webgl cull face.
|
|
1886
|
+
*/
|
|
1887
|
+
setCullFace(e) {
|
|
1888
|
+
this._cullFace = e, this.gl[e ? "enable" : "disable"](this.gl.CULL_FACE), this._cullFace && this._frontFaceDirty && this.setFrontFace(this._frontFace);
|
|
1889
|
+
}
|
|
1890
|
+
/**
|
|
1891
|
+
* Sets the gl front face.
|
|
1892
|
+
* @param {boolean} value - true is clockwise and false is counter-clockwise
|
|
1893
|
+
*/
|
|
1894
|
+
setFrontFace(e) {
|
|
1895
|
+
this._frontFace = e, this._frontFaceDirty = !1;
|
|
1896
|
+
const r = this._invertFrontFace ? !e : e;
|
|
1897
|
+
this._glFrontFace !== r && (this._glFrontFace = r, this.gl.frontFace(this.gl[r ? "CW" : "CCW"]));
|
|
1898
|
+
}
|
|
1899
|
+
/**
|
|
1900
|
+
* Sets the blend mode.
|
|
1901
|
+
* @param {number} value - The blend mode to set to.
|
|
1902
|
+
*/
|
|
1903
|
+
setBlendMode(e) {
|
|
1904
|
+
if (this.blendModesMap[e] || (e = "normal"), e === this.blendMode)
|
|
1905
|
+
return;
|
|
1906
|
+
this.blendMode = e;
|
|
1907
|
+
const r = this.blendModesMap[e], n = this.gl;
|
|
1908
|
+
r.length === 2 ? n.blendFunc(r[0], r[1]) : n.blendFuncSeparate(r[0], r[1], r[2], r[3]), r.length === 6 ? (this._blendEq = !0, n.blendEquationSeparate(r[4], r[5])) : this._blendEq && (this._blendEq = !1, n.blendEquationSeparate(n.FUNC_ADD, n.FUNC_ADD));
|
|
1909
|
+
}
|
|
1910
|
+
/**
|
|
1911
|
+
* Sets the polygon offset.
|
|
1912
|
+
* @param {number} value - the polygon offset
|
|
1913
|
+
* @param {number} scale - the polygon offset scale
|
|
1914
|
+
*/
|
|
1915
|
+
setPolygonOffset(e, r) {
|
|
1916
|
+
this.gl.polygonOffset(e, r);
|
|
1917
|
+
}
|
|
1918
|
+
/** Resets all the logic and disables the VAOs. */
|
|
1919
|
+
resetState() {
|
|
1920
|
+
this._glFrontFace = !1, this._frontFace = !1, this._cullFace = !1, this._frontFaceDirty = !1, this._invertFrontFace = !1, this.gl.frontFace(this.gl.CCW), this.gl.pixelStorei(this.gl.UNPACK_FLIP_Y_WEBGL, !1), this.forceState(this.defaultState), this._blendEq = !0, this.blendMode = "", this.setBlendMode("normal");
|
|
1921
|
+
}
|
|
1922
|
+
/**
|
|
1923
|
+
* Checks to see which updates should be checked based on which settings have been activated.
|
|
1924
|
+
*
|
|
1925
|
+
* For example, if blend is enabled then we should check the blend modes each time the state is changed
|
|
1926
|
+
* or if polygon fill is activated then we need to check if the polygon offset changes.
|
|
1927
|
+
* The idea is that we only check what we have too.
|
|
1928
|
+
* @param func - the checking function to add or remove
|
|
1929
|
+
* @param value - should the check function be added or removed.
|
|
1930
|
+
*/
|
|
1931
|
+
_updateCheck(e, r) {
|
|
1932
|
+
const n = this.checks.indexOf(e);
|
|
1933
|
+
r && n === -1 ? this.checks.push(e) : !r && n !== -1 && this.checks.splice(n, 1);
|
|
1934
|
+
}
|
|
1935
|
+
/**
|
|
1936
|
+
* A private little wrapper function that we call to check the blend mode.
|
|
1937
|
+
* @param system - the System to perform the state check on
|
|
1938
|
+
* @param state - the state that the blendMode will pulled from
|
|
1939
|
+
*/
|
|
1940
|
+
static _checkBlendMode(e, r) {
|
|
1941
|
+
e.setBlendMode(r.blendMode);
|
|
1942
|
+
}
|
|
1943
|
+
/**
|
|
1944
|
+
* A private little wrapper function that we call to check the polygon offset.
|
|
1945
|
+
* @param system - the System to perform the state check on
|
|
1946
|
+
* @param state - the state that the blendMode will pulled from
|
|
1947
|
+
*/
|
|
1948
|
+
static _checkPolygonOffset(e, r) {
|
|
1949
|
+
e.setPolygonOffset(1, r.polygonOffset);
|
|
1950
|
+
}
|
|
1951
|
+
/** @ignore */
|
|
1952
|
+
destroy() {
|
|
1953
|
+
this.gl = null, this.checks.length = 0;
|
|
1954
|
+
}
|
|
1955
|
+
};
|
|
1956
|
+
pe.extension = {
|
|
1957
|
+
type: [
|
|
1958
|
+
d.WebGLSystem
|
|
1959
|
+
],
|
|
1960
|
+
name: "state"
|
|
1961
|
+
};
|
|
1962
|
+
let Tt = pe;
|
|
1963
|
+
class xt {
|
|
1964
|
+
constructor(e) {
|
|
1965
|
+
this.target = w.TEXTURE_2D, this._layerInitMask = 0, this.texture = e, this.width = -1, this.height = -1, this.type = l.UNSIGNED_BYTE, this.internalFormat = G.RGBA, this.format = G.RGBA, this.samplerType = 0;
|
|
1966
|
+
}
|
|
1967
|
+
destroy() {
|
|
1968
|
+
}
|
|
1969
|
+
}
|
|
1970
|
+
const vt = {
|
|
1971
|
+
id: "buffer",
|
|
1972
|
+
upload(t, e, r, n, s, i = !1) {
|
|
1973
|
+
const a = s || e.target;
|
|
1974
|
+
!i && e.width === t.width && e.height === t.height ? r.texSubImage2D(
|
|
1975
|
+
a,
|
|
1976
|
+
0,
|
|
1977
|
+
0,
|
|
1978
|
+
0,
|
|
1979
|
+
t.width,
|
|
1980
|
+
t.height,
|
|
1981
|
+
e.format,
|
|
1982
|
+
e.type,
|
|
1983
|
+
t.resource
|
|
1984
|
+
) : r.texImage2D(
|
|
1985
|
+
a,
|
|
1986
|
+
0,
|
|
1987
|
+
e.internalFormat,
|
|
1988
|
+
t.width,
|
|
1989
|
+
t.height,
|
|
1990
|
+
0,
|
|
1991
|
+
e.format,
|
|
1992
|
+
e.type,
|
|
1993
|
+
t.resource
|
|
1994
|
+
), e.width = t.width, e.height = t.height;
|
|
1995
|
+
}
|
|
1996
|
+
}, At = {
|
|
1997
|
+
"bc1-rgba-unorm": !0,
|
|
1998
|
+
"bc1-rgba-unorm-srgb": !0,
|
|
1999
|
+
"bc2-rgba-unorm": !0,
|
|
2000
|
+
"bc2-rgba-unorm-srgb": !0,
|
|
2001
|
+
"bc3-rgba-unorm": !0,
|
|
2002
|
+
"bc3-rgba-unorm-srgb": !0,
|
|
2003
|
+
"bc4-r-unorm": !0,
|
|
2004
|
+
"bc4-r-snorm": !0,
|
|
2005
|
+
"bc5-rg-unorm": !0,
|
|
2006
|
+
"bc5-rg-snorm": !0,
|
|
2007
|
+
"bc6h-rgb-ufloat": !0,
|
|
2008
|
+
"bc6h-rgb-float": !0,
|
|
2009
|
+
"bc7-rgba-unorm": !0,
|
|
2010
|
+
"bc7-rgba-unorm-srgb": !0,
|
|
2011
|
+
// ETC2 compressed formats usable if "texture-compression-etc2" is both
|
|
2012
|
+
// supported by the device/user agent and enabled in requestDevice.
|
|
2013
|
+
"etc2-rgb8unorm": !0,
|
|
2014
|
+
"etc2-rgb8unorm-srgb": !0,
|
|
2015
|
+
"etc2-rgb8a1unorm": !0,
|
|
2016
|
+
"etc2-rgb8a1unorm-srgb": !0,
|
|
2017
|
+
"etc2-rgba8unorm": !0,
|
|
2018
|
+
"etc2-rgba8unorm-srgb": !0,
|
|
2019
|
+
"eac-r11unorm": !0,
|
|
2020
|
+
"eac-r11snorm": !0,
|
|
2021
|
+
"eac-rg11unorm": !0,
|
|
2022
|
+
"eac-rg11snorm": !0,
|
|
2023
|
+
// ASTC compressed formats usable if "texture-compression-astc" is both
|
|
2024
|
+
// supported by the device/user agent and enabled in requestDevice.
|
|
2025
|
+
"astc-4x4-unorm": !0,
|
|
2026
|
+
"astc-4x4-unorm-srgb": !0,
|
|
2027
|
+
"astc-5x4-unorm": !0,
|
|
2028
|
+
"astc-5x4-unorm-srgb": !0,
|
|
2029
|
+
"astc-5x5-unorm": !0,
|
|
2030
|
+
"astc-5x5-unorm-srgb": !0,
|
|
2031
|
+
"astc-6x5-unorm": !0,
|
|
2032
|
+
"astc-6x5-unorm-srgb": !0,
|
|
2033
|
+
"astc-6x6-unorm": !0,
|
|
2034
|
+
"astc-6x6-unorm-srgb": !0,
|
|
2035
|
+
"astc-8x5-unorm": !0,
|
|
2036
|
+
"astc-8x5-unorm-srgb": !0,
|
|
2037
|
+
"astc-8x6-unorm": !0,
|
|
2038
|
+
"astc-8x6-unorm-srgb": !0,
|
|
2039
|
+
"astc-8x8-unorm": !0,
|
|
2040
|
+
"astc-8x8-unorm-srgb": !0,
|
|
2041
|
+
"astc-10x5-unorm": !0,
|
|
2042
|
+
"astc-10x5-unorm-srgb": !0,
|
|
2043
|
+
"astc-10x6-unorm": !0,
|
|
2044
|
+
"astc-10x6-unorm-srgb": !0,
|
|
2045
|
+
"astc-10x8-unorm": !0,
|
|
2046
|
+
"astc-10x8-unorm-srgb": !0,
|
|
2047
|
+
"astc-10x10-unorm": !0,
|
|
2048
|
+
"astc-10x10-unorm-srgb": !0,
|
|
2049
|
+
"astc-12x10-unorm": !0,
|
|
2050
|
+
"astc-12x10-unorm-srgb": !0,
|
|
2051
|
+
"astc-12x12-unorm": !0,
|
|
2052
|
+
"astc-12x12-unorm-srgb": !0
|
|
2053
|
+
}, Bt = {
|
|
2054
|
+
id: "compressed",
|
|
2055
|
+
upload(t, e, r, n, s, i) {
|
|
2056
|
+
const a = s ?? e.target;
|
|
2057
|
+
r.pixelStorei(r.UNPACK_ALIGNMENT, 4);
|
|
2058
|
+
let o = t.pixelWidth, u = t.pixelHeight;
|
|
2059
|
+
const c = !!At[t.format];
|
|
2060
|
+
for (let _ = 0; _ < t.resource.length; _++) {
|
|
2061
|
+
const f = t.resource[_];
|
|
2062
|
+
c ? r.compressedTexImage2D(
|
|
2063
|
+
a,
|
|
2064
|
+
_,
|
|
2065
|
+
e.internalFormat,
|
|
2066
|
+
o,
|
|
2067
|
+
u,
|
|
2068
|
+
0,
|
|
2069
|
+
f
|
|
2070
|
+
) : r.texImage2D(
|
|
2071
|
+
a,
|
|
2072
|
+
_,
|
|
2073
|
+
e.internalFormat,
|
|
2074
|
+
o,
|
|
2075
|
+
u,
|
|
2076
|
+
0,
|
|
2077
|
+
e.format,
|
|
2078
|
+
e.type,
|
|
2079
|
+
f
|
|
2080
|
+
), o = Math.max(o >> 1, 1), u = Math.max(u >> 1, 1);
|
|
2081
|
+
}
|
|
2082
|
+
}
|
|
2083
|
+
}, $ = ["right", "left", "top", "bottom", "front", "back"];
|
|
2084
|
+
function yt(t) {
|
|
2085
|
+
return {
|
|
2086
|
+
id: "cube",
|
|
2087
|
+
upload(e, r, n, s) {
|
|
2088
|
+
const i = e.faces;
|
|
2089
|
+
for (let a = 0; a < $.length; a++) {
|
|
2090
|
+
const o = $[a], u = i[o];
|
|
2091
|
+
(t[u.uploadMethodId] || t.image).upload(
|
|
2092
|
+
u,
|
|
2093
|
+
r,
|
|
2094
|
+
n,
|
|
2095
|
+
s,
|
|
2096
|
+
// Use the face target for the current face. cube faces ids go up 1 so
|
|
2097
|
+
// GL_TARGETS.TEXTURE_CUBE_MAP_POSITIVE_X + i addresses the i'th face target.
|
|
2098
|
+
w.TEXTURE_CUBE_MAP_POSITIVE_X + a,
|
|
2099
|
+
// Force allocation for the first upload of each face.
|
|
2100
|
+
(r._layerInitMask & 1 << a) === 0
|
|
2101
|
+
), r._layerInitMask |= 1 << a;
|
|
2102
|
+
}
|
|
2103
|
+
r.width = e.pixelWidth, r.height = e.pixelHeight;
|
|
2104
|
+
}
|
|
2105
|
+
};
|
|
2106
|
+
}
|
|
2107
|
+
const Se = {
|
|
2108
|
+
id: "image",
|
|
2109
|
+
upload(t, e, r, n, s, i = !1) {
|
|
2110
|
+
const a = s || e.target, o = t.pixelWidth, u = t.pixelHeight, c = t.resourceWidth, _ = t.resourceHeight, f = n === 2, h = i || e.width !== o || e.height !== u, m = c >= o && _ >= u, b = t.resource;
|
|
2111
|
+
(f ? Ct : Nt)(
|
|
2112
|
+
r,
|
|
2113
|
+
a,
|
|
2114
|
+
e,
|
|
2115
|
+
o,
|
|
2116
|
+
u,
|
|
2117
|
+
c,
|
|
2118
|
+
_,
|
|
2119
|
+
b,
|
|
2120
|
+
h,
|
|
2121
|
+
m
|
|
2122
|
+
), e.width = o, e.height = u;
|
|
2123
|
+
}
|
|
2124
|
+
};
|
|
2125
|
+
function Ct(t, e, r, n, s, i, a, o, u, c) {
|
|
2126
|
+
if (!c) {
|
|
2127
|
+
u && t.texImage2D(
|
|
2128
|
+
e,
|
|
2129
|
+
0,
|
|
2130
|
+
r.internalFormat,
|
|
2131
|
+
n,
|
|
2132
|
+
s,
|
|
2133
|
+
0,
|
|
2134
|
+
r.format,
|
|
2135
|
+
r.type,
|
|
2136
|
+
null
|
|
2137
|
+
), t.texSubImage2D(
|
|
2138
|
+
e,
|
|
2139
|
+
0,
|
|
2140
|
+
0,
|
|
2141
|
+
0,
|
|
2142
|
+
i,
|
|
2143
|
+
a,
|
|
2144
|
+
r.format,
|
|
2145
|
+
r.type,
|
|
2146
|
+
o
|
|
2147
|
+
);
|
|
2148
|
+
return;
|
|
2149
|
+
}
|
|
2150
|
+
if (!u) {
|
|
2151
|
+
t.texSubImage2D(
|
|
2152
|
+
e,
|
|
2153
|
+
0,
|
|
2154
|
+
0,
|
|
2155
|
+
0,
|
|
2156
|
+
r.format,
|
|
2157
|
+
r.type,
|
|
2158
|
+
o
|
|
2159
|
+
);
|
|
2160
|
+
return;
|
|
2161
|
+
}
|
|
2162
|
+
t.texImage2D(
|
|
2163
|
+
e,
|
|
2164
|
+
0,
|
|
2165
|
+
r.internalFormat,
|
|
2166
|
+
n,
|
|
2167
|
+
s,
|
|
2168
|
+
0,
|
|
2169
|
+
r.format,
|
|
2170
|
+
r.type,
|
|
2171
|
+
o
|
|
2172
|
+
);
|
|
2173
|
+
}
|
|
2174
|
+
function Nt(t, e, r, n, s, i, a, o, u, c) {
|
|
2175
|
+
if (!c) {
|
|
2176
|
+
u && t.texImage2D(
|
|
2177
|
+
e,
|
|
2178
|
+
0,
|
|
2179
|
+
r.internalFormat,
|
|
2180
|
+
n,
|
|
2181
|
+
s,
|
|
2182
|
+
0,
|
|
2183
|
+
r.format,
|
|
2184
|
+
r.type,
|
|
2185
|
+
null
|
|
2186
|
+
), t.texSubImage2D(
|
|
2187
|
+
e,
|
|
2188
|
+
0,
|
|
2189
|
+
0,
|
|
2190
|
+
0,
|
|
2191
|
+
r.format,
|
|
2192
|
+
r.type,
|
|
2193
|
+
o
|
|
2194
|
+
);
|
|
2195
|
+
return;
|
|
2196
|
+
}
|
|
2197
|
+
if (!u) {
|
|
2198
|
+
t.texSubImage2D(
|
|
2199
|
+
e,
|
|
2200
|
+
0,
|
|
2201
|
+
0,
|
|
2202
|
+
0,
|
|
2203
|
+
r.format,
|
|
2204
|
+
r.type,
|
|
2205
|
+
o
|
|
2206
|
+
);
|
|
2207
|
+
return;
|
|
2208
|
+
}
|
|
2209
|
+
t.texImage2D(
|
|
2210
|
+
e,
|
|
2211
|
+
0,
|
|
2212
|
+
r.internalFormat,
|
|
2213
|
+
r.format,
|
|
2214
|
+
r.type,
|
|
2215
|
+
o
|
|
2216
|
+
);
|
|
2217
|
+
}
|
|
2218
|
+
const Dt = We(), It = {
|
|
2219
|
+
id: "video",
|
|
2220
|
+
upload(t, e, r, n, s, i = Dt) {
|
|
2221
|
+
if (!t.isValid) {
|
|
2222
|
+
const a = s ?? e.target;
|
|
2223
|
+
r.texImage2D(
|
|
2224
|
+
a,
|
|
2225
|
+
0,
|
|
2226
|
+
e.internalFormat,
|
|
2227
|
+
1,
|
|
2228
|
+
1,
|
|
2229
|
+
0,
|
|
2230
|
+
e.format,
|
|
2231
|
+
e.type,
|
|
2232
|
+
null
|
|
2233
|
+
);
|
|
2234
|
+
return;
|
|
2235
|
+
}
|
|
2236
|
+
Se.upload(t, e, r, n, s, i);
|
|
2237
|
+
}
|
|
2238
|
+
}, K = {
|
|
2239
|
+
linear: 9729,
|
|
2240
|
+
nearest: 9728
|
|
2241
|
+
}, Gt = {
|
|
2242
|
+
linear: {
|
|
2243
|
+
linear: 9987,
|
|
2244
|
+
nearest: 9985
|
|
2245
|
+
},
|
|
2246
|
+
nearest: {
|
|
2247
|
+
linear: 9986,
|
|
2248
|
+
nearest: 9984
|
|
2249
|
+
}
|
|
2250
|
+
}, I = {
|
|
2251
|
+
"clamp-to-edge": 33071,
|
|
2252
|
+
repeat: 10497,
|
|
2253
|
+
"mirror-repeat": 33648
|
|
2254
|
+
}, Ut = {
|
|
2255
|
+
never: 512,
|
|
2256
|
+
less: 513,
|
|
2257
|
+
equal: 514,
|
|
2258
|
+
"less-equal": 515,
|
|
2259
|
+
greater: 516,
|
|
2260
|
+
"not-equal": 517,
|
|
2261
|
+
"greater-equal": 518,
|
|
2262
|
+
always: 519
|
|
2263
|
+
};
|
|
2264
|
+
function Y(t, e, r, n, s, i, a, o) {
|
|
2265
|
+
const u = i;
|
|
2266
|
+
if (!o || t.addressModeU !== "repeat" || t.addressModeV !== "repeat" || t.addressModeW !== "repeat") {
|
|
2267
|
+
const c = I[a ? "clamp-to-edge" : t.addressModeU], _ = I[a ? "clamp-to-edge" : t.addressModeV], f = I[a ? "clamp-to-edge" : t.addressModeW];
|
|
2268
|
+
e[s](u, e.TEXTURE_WRAP_S, c), e[s](u, e.TEXTURE_WRAP_T, _), e.TEXTURE_WRAP_R && e[s](u, e.TEXTURE_WRAP_R, f);
|
|
2269
|
+
}
|
|
2270
|
+
if ((!o || t.magFilter !== "linear") && e[s](u, e.TEXTURE_MAG_FILTER, K[t.magFilter]), r) {
|
|
2271
|
+
if (!o || t.mipmapFilter !== "linear") {
|
|
2272
|
+
const c = Gt[t.minFilter][t.mipmapFilter];
|
|
2273
|
+
e[s](u, e.TEXTURE_MIN_FILTER, c);
|
|
2274
|
+
}
|
|
2275
|
+
} else
|
|
2276
|
+
e[s](u, e.TEXTURE_MIN_FILTER, K[t.minFilter]);
|
|
2277
|
+
if (n && t.maxAnisotropy > 1) {
|
|
2278
|
+
const c = Math.min(t.maxAnisotropy, e.getParameter(n.MAX_TEXTURE_MAX_ANISOTROPY_EXT));
|
|
2279
|
+
e[s](u, n.TEXTURE_MAX_ANISOTROPY_EXT, c);
|
|
2280
|
+
}
|
|
2281
|
+
t.compare && e[s](u, e.TEXTURE_COMPARE_FUNC, Ut[t.compare]);
|
|
2282
|
+
}
|
|
2283
|
+
function Ft(t) {
|
|
2284
|
+
return {
|
|
2285
|
+
// 8-bit formats
|
|
2286
|
+
r8unorm: t.RED,
|
|
2287
|
+
r8snorm: t.RED,
|
|
2288
|
+
r8uint: t.RED,
|
|
2289
|
+
r8sint: t.RED,
|
|
2290
|
+
// 16-bit formats
|
|
2291
|
+
r16uint: t.RED,
|
|
2292
|
+
r16sint: t.RED,
|
|
2293
|
+
r16float: t.RED,
|
|
2294
|
+
rg8unorm: t.RG,
|
|
2295
|
+
rg8snorm: t.RG,
|
|
2296
|
+
rg8uint: t.RG,
|
|
2297
|
+
rg8sint: t.RG,
|
|
2298
|
+
// 32-bit formats
|
|
2299
|
+
r32uint: t.RED,
|
|
2300
|
+
r32sint: t.RED,
|
|
2301
|
+
r32float: t.RED,
|
|
2302
|
+
rg16uint: t.RG,
|
|
2303
|
+
rg16sint: t.RG,
|
|
2304
|
+
rg16float: t.RG,
|
|
2305
|
+
rgba8unorm: t.RGBA,
|
|
2306
|
+
"rgba8unorm-srgb": t.RGBA,
|
|
2307
|
+
// Packed 32-bit formats
|
|
2308
|
+
rgba8snorm: t.RGBA,
|
|
2309
|
+
rgba8uint: t.RGBA,
|
|
2310
|
+
rgba8sint: t.RGBA,
|
|
2311
|
+
bgra8unorm: t.RGBA,
|
|
2312
|
+
"bgra8unorm-srgb": t.RGBA,
|
|
2313
|
+
rgb9e5ufloat: t.RGB,
|
|
2314
|
+
rgb10a2unorm: t.RGBA,
|
|
2315
|
+
rg11b10ufloat: t.RGB,
|
|
2316
|
+
// 64-bit formats
|
|
2317
|
+
rg32uint: t.RG,
|
|
2318
|
+
rg32sint: t.RG,
|
|
2319
|
+
rg32float: t.RG,
|
|
2320
|
+
rgba16uint: t.RGBA,
|
|
2321
|
+
rgba16sint: t.RGBA,
|
|
2322
|
+
rgba16float: t.RGBA,
|
|
2323
|
+
// 128-bit formats
|
|
2324
|
+
rgba32uint: t.RGBA,
|
|
2325
|
+
rgba32sint: t.RGBA,
|
|
2326
|
+
rgba32float: t.RGBA,
|
|
2327
|
+
// Depth/stencil formats
|
|
2328
|
+
stencil8: t.STENCIL_INDEX8,
|
|
2329
|
+
depth16unorm: t.DEPTH_COMPONENT,
|
|
2330
|
+
depth24plus: t.DEPTH_COMPONENT,
|
|
2331
|
+
"depth24plus-stencil8": t.DEPTH_STENCIL,
|
|
2332
|
+
depth32float: t.DEPTH_COMPONENT,
|
|
2333
|
+
"depth32float-stencil8": t.DEPTH_STENCIL
|
|
2334
|
+
};
|
|
2335
|
+
}
|
|
2336
|
+
function Pt(t, e) {
|
|
2337
|
+
let r = {}, n = t.RGBA;
|
|
2338
|
+
return t instanceof R.get().getWebGLRenderingContext() ? e.srgb && (r = {
|
|
2339
|
+
"rgba8unorm-srgb": e.srgb.SRGB8_ALPHA8_EXT,
|
|
2340
|
+
"bgra8unorm-srgb": e.srgb.SRGB8_ALPHA8_EXT
|
|
2341
|
+
}) : (r = {
|
|
2342
|
+
"rgba8unorm-srgb": t.SRGB8_ALPHA8,
|
|
2343
|
+
"bgra8unorm-srgb": t.SRGB8_ALPHA8
|
|
2344
|
+
}, n = t.RGBA8), {
|
|
2345
|
+
// 8-bit formats
|
|
2346
|
+
r8unorm: t.R8,
|
|
2347
|
+
r8snorm: t.R8_SNORM,
|
|
2348
|
+
r8uint: t.R8UI,
|
|
2349
|
+
r8sint: t.R8I,
|
|
2350
|
+
// 16-bit formats
|
|
2351
|
+
r16uint: t.R16UI,
|
|
2352
|
+
r16sint: t.R16I,
|
|
2353
|
+
r16float: t.R16F,
|
|
2354
|
+
rg8unorm: t.RG8,
|
|
2355
|
+
rg8snorm: t.RG8_SNORM,
|
|
2356
|
+
rg8uint: t.RG8UI,
|
|
2357
|
+
rg8sint: t.RG8I,
|
|
2358
|
+
// 32-bit formats
|
|
2359
|
+
r32uint: t.R32UI,
|
|
2360
|
+
r32sint: t.R32I,
|
|
2361
|
+
r32float: t.R32F,
|
|
2362
|
+
rg16uint: t.RG16UI,
|
|
2363
|
+
rg16sint: t.RG16I,
|
|
2364
|
+
rg16float: t.RG16F,
|
|
2365
|
+
rgba8unorm: t.RGBA,
|
|
2366
|
+
...r,
|
|
2367
|
+
// Packed 32-bit formats
|
|
2368
|
+
rgba8snorm: t.RGBA8_SNORM,
|
|
2369
|
+
rgba8uint: t.RGBA8UI,
|
|
2370
|
+
rgba8sint: t.RGBA8I,
|
|
2371
|
+
bgra8unorm: n,
|
|
2372
|
+
rgb9e5ufloat: t.RGB9_E5,
|
|
2373
|
+
rgb10a2unorm: t.RGB10_A2,
|
|
2374
|
+
rg11b10ufloat: t.R11F_G11F_B10F,
|
|
2375
|
+
// 64-bit formats
|
|
2376
|
+
rg32uint: t.RG32UI,
|
|
2377
|
+
rg32sint: t.RG32I,
|
|
2378
|
+
rg32float: t.RG32F,
|
|
2379
|
+
rgba16uint: t.RGBA16UI,
|
|
2380
|
+
rgba16sint: t.RGBA16I,
|
|
2381
|
+
rgba16float: t.RGBA16F,
|
|
2382
|
+
// 128-bit formats
|
|
2383
|
+
rgba32uint: t.RGBA32UI,
|
|
2384
|
+
rgba32sint: t.RGBA32I,
|
|
2385
|
+
rgba32float: t.RGBA32F,
|
|
2386
|
+
// Depth/stencil formats
|
|
2387
|
+
stencil8: t.STENCIL_INDEX8,
|
|
2388
|
+
depth16unorm: t.DEPTH_COMPONENT16,
|
|
2389
|
+
depth24plus: t.DEPTH_COMPONENT24,
|
|
2390
|
+
"depth24plus-stencil8": t.DEPTH24_STENCIL8,
|
|
2391
|
+
depth32float: t.DEPTH_COMPONENT32F,
|
|
2392
|
+
"depth32float-stencil8": t.DEPTH32F_STENCIL8,
|
|
2393
|
+
// Compressed formats
|
|
2394
|
+
...e.s3tc ? {
|
|
2395
|
+
"bc1-rgba-unorm": e.s3tc.COMPRESSED_RGBA_S3TC_DXT1_EXT,
|
|
2396
|
+
"bc2-rgba-unorm": e.s3tc.COMPRESSED_RGBA_S3TC_DXT3_EXT,
|
|
2397
|
+
"bc3-rgba-unorm": e.s3tc.COMPRESSED_RGBA_S3TC_DXT5_EXT
|
|
2398
|
+
} : {},
|
|
2399
|
+
...e.s3tc_sRGB ? {
|
|
2400
|
+
"bc1-rgba-unorm-srgb": e.s3tc_sRGB.COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT,
|
|
2401
|
+
"bc2-rgba-unorm-srgb": e.s3tc_sRGB.COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT,
|
|
2402
|
+
"bc3-rgba-unorm-srgb": e.s3tc_sRGB.COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
|
|
2403
|
+
} : {},
|
|
2404
|
+
...e.rgtc ? {
|
|
2405
|
+
"bc4-r-unorm": e.rgtc.COMPRESSED_RED_RGTC1_EXT,
|
|
2406
|
+
"bc4-r-snorm": e.rgtc.COMPRESSED_SIGNED_RED_RGTC1_EXT,
|
|
2407
|
+
"bc5-rg-unorm": e.rgtc.COMPRESSED_RED_GREEN_RGTC2_EXT,
|
|
2408
|
+
"bc5-rg-snorm": e.rgtc.COMPRESSED_SIGNED_RED_GREEN_RGTC2_EXT
|
|
2409
|
+
} : {},
|
|
2410
|
+
...e.bptc ? {
|
|
2411
|
+
"bc6h-rgb-float": e.bptc.COMPRESSED_RGB_BPTC_SIGNED_FLOAT_EXT,
|
|
2412
|
+
"bc6h-rgb-ufloat": e.bptc.COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT_EXT,
|
|
2413
|
+
"bc7-rgba-unorm": e.bptc.COMPRESSED_RGBA_BPTC_UNORM_EXT,
|
|
2414
|
+
"bc7-rgba-unorm-srgb": e.bptc.COMPRESSED_SRGB_ALPHA_BPTC_UNORM_EXT
|
|
2415
|
+
} : {},
|
|
2416
|
+
...e.etc ? {
|
|
2417
|
+
"etc2-rgb8unorm": e.etc.COMPRESSED_RGB8_ETC2,
|
|
2418
|
+
"etc2-rgb8unorm-srgb": e.etc.COMPRESSED_SRGB8_ETC2,
|
|
2419
|
+
"etc2-rgb8a1unorm": e.etc.COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2,
|
|
2420
|
+
"etc2-rgb8a1unorm-srgb": e.etc.COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2,
|
|
2421
|
+
"etc2-rgba8unorm": e.etc.COMPRESSED_RGBA8_ETC2_EAC,
|
|
2422
|
+
"etc2-rgba8unorm-srgb": e.etc.COMPRESSED_SRGB8_ALPHA8_ETC2_EAC,
|
|
2423
|
+
"eac-r11unorm": e.etc.COMPRESSED_R11_EAC,
|
|
2424
|
+
// 'eac-r11snorm'
|
|
2425
|
+
"eac-rg11unorm": e.etc.COMPRESSED_SIGNED_RG11_EAC
|
|
2426
|
+
// 'eac-rg11snorm'
|
|
2427
|
+
} : {},
|
|
2428
|
+
...e.astc ? {
|
|
2429
|
+
"astc-4x4-unorm": e.astc.COMPRESSED_RGBA_ASTC_4x4_KHR,
|
|
2430
|
+
"astc-4x4-unorm-srgb": e.astc.COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR,
|
|
2431
|
+
"astc-5x4-unorm": e.astc.COMPRESSED_RGBA_ASTC_5x4_KHR,
|
|
2432
|
+
"astc-5x4-unorm-srgb": e.astc.COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR,
|
|
2433
|
+
"astc-5x5-unorm": e.astc.COMPRESSED_RGBA_ASTC_5x5_KHR,
|
|
2434
|
+
"astc-5x5-unorm-srgb": e.astc.COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR,
|
|
2435
|
+
"astc-6x5-unorm": e.astc.COMPRESSED_RGBA_ASTC_6x5_KHR,
|
|
2436
|
+
"astc-6x5-unorm-srgb": e.astc.COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR,
|
|
2437
|
+
"astc-6x6-unorm": e.astc.COMPRESSED_RGBA_ASTC_6x6_KHR,
|
|
2438
|
+
"astc-6x6-unorm-srgb": e.astc.COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR,
|
|
2439
|
+
"astc-8x5-unorm": e.astc.COMPRESSED_RGBA_ASTC_8x5_KHR,
|
|
2440
|
+
"astc-8x5-unorm-srgb": e.astc.COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR,
|
|
2441
|
+
"astc-8x6-unorm": e.astc.COMPRESSED_RGBA_ASTC_8x6_KHR,
|
|
2442
|
+
"astc-8x6-unorm-srgb": e.astc.COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR,
|
|
2443
|
+
"astc-8x8-unorm": e.astc.COMPRESSED_RGBA_ASTC_8x8_KHR,
|
|
2444
|
+
"astc-8x8-unorm-srgb": e.astc.COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR,
|
|
2445
|
+
"astc-10x5-unorm": e.astc.COMPRESSED_RGBA_ASTC_10x5_KHR,
|
|
2446
|
+
"astc-10x5-unorm-srgb": e.astc.COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR,
|
|
2447
|
+
"astc-10x6-unorm": e.astc.COMPRESSED_RGBA_ASTC_10x6_KHR,
|
|
2448
|
+
"astc-10x6-unorm-srgb": e.astc.COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR,
|
|
2449
|
+
"astc-10x8-unorm": e.astc.COMPRESSED_RGBA_ASTC_10x8_KHR,
|
|
2450
|
+
"astc-10x8-unorm-srgb": e.astc.COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR,
|
|
2451
|
+
"astc-10x10-unorm": e.astc.COMPRESSED_RGBA_ASTC_10x10_KHR,
|
|
2452
|
+
"astc-10x10-unorm-srgb": e.astc.COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR,
|
|
2453
|
+
"astc-12x10-unorm": e.astc.COMPRESSED_RGBA_ASTC_12x10_KHR,
|
|
2454
|
+
"astc-12x10-unorm-srgb": e.astc.COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR,
|
|
2455
|
+
"astc-12x12-unorm": e.astc.COMPRESSED_RGBA_ASTC_12x12_KHR,
|
|
2456
|
+
"astc-12x12-unorm-srgb": e.astc.COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR
|
|
2457
|
+
} : {}
|
|
2458
|
+
};
|
|
2459
|
+
}
|
|
2460
|
+
function Ot(t) {
|
|
2461
|
+
return {
|
|
2462
|
+
// 8-bit formats
|
|
2463
|
+
r8unorm: t.UNSIGNED_BYTE,
|
|
2464
|
+
r8snorm: t.BYTE,
|
|
2465
|
+
r8uint: t.UNSIGNED_BYTE,
|
|
2466
|
+
r8sint: t.BYTE,
|
|
2467
|
+
// 16-bit formats
|
|
2468
|
+
r16uint: t.UNSIGNED_SHORT,
|
|
2469
|
+
r16sint: t.SHORT,
|
|
2470
|
+
r16float: t.HALF_FLOAT,
|
|
2471
|
+
rg8unorm: t.UNSIGNED_BYTE,
|
|
2472
|
+
rg8snorm: t.BYTE,
|
|
2473
|
+
rg8uint: t.UNSIGNED_BYTE,
|
|
2474
|
+
rg8sint: t.BYTE,
|
|
2475
|
+
// 32-bit formats
|
|
2476
|
+
r32uint: t.UNSIGNED_INT,
|
|
2477
|
+
r32sint: t.INT,
|
|
2478
|
+
r32float: t.FLOAT,
|
|
2479
|
+
rg16uint: t.UNSIGNED_SHORT,
|
|
2480
|
+
rg16sint: t.SHORT,
|
|
2481
|
+
rg16float: t.HALF_FLOAT,
|
|
2482
|
+
rgba8unorm: t.UNSIGNED_BYTE,
|
|
2483
|
+
"rgba8unorm-srgb": t.UNSIGNED_BYTE,
|
|
2484
|
+
// Packed 32-bit formats
|
|
2485
|
+
rgba8snorm: t.BYTE,
|
|
2486
|
+
rgba8uint: t.UNSIGNED_BYTE,
|
|
2487
|
+
rgba8sint: t.BYTE,
|
|
2488
|
+
bgra8unorm: t.UNSIGNED_BYTE,
|
|
2489
|
+
"bgra8unorm-srgb": t.UNSIGNED_BYTE,
|
|
2490
|
+
rgb9e5ufloat: t.UNSIGNED_INT_5_9_9_9_REV,
|
|
2491
|
+
rgb10a2unorm: t.UNSIGNED_INT_2_10_10_10_REV,
|
|
2492
|
+
rg11b10ufloat: t.UNSIGNED_INT_10F_11F_11F_REV,
|
|
2493
|
+
// 64-bit formats
|
|
2494
|
+
rg32uint: t.UNSIGNED_INT,
|
|
2495
|
+
rg32sint: t.INT,
|
|
2496
|
+
rg32float: t.FLOAT,
|
|
2497
|
+
rgba16uint: t.UNSIGNED_SHORT,
|
|
2498
|
+
rgba16sint: t.SHORT,
|
|
2499
|
+
rgba16float: t.HALF_FLOAT,
|
|
2500
|
+
// 128-bit formats
|
|
2501
|
+
rgba32uint: t.UNSIGNED_INT,
|
|
2502
|
+
rgba32sint: t.INT,
|
|
2503
|
+
rgba32float: t.FLOAT,
|
|
2504
|
+
// Depth/stencil formats
|
|
2505
|
+
stencil8: t.UNSIGNED_BYTE,
|
|
2506
|
+
depth16unorm: t.UNSIGNED_SHORT,
|
|
2507
|
+
depth24plus: t.UNSIGNED_INT,
|
|
2508
|
+
"depth24plus-stencil8": t.UNSIGNED_INT_24_8,
|
|
2509
|
+
depth32float: t.FLOAT,
|
|
2510
|
+
"depth32float-stencil8": t.FLOAT_32_UNSIGNED_INT_24_8_REV
|
|
2511
|
+
};
|
|
2512
|
+
}
|
|
2513
|
+
function Mt(t) {
|
|
2514
|
+
return {
|
|
2515
|
+
"2d": t.TEXTURE_2D,
|
|
2516
|
+
cube: t.TEXTURE_CUBE_MAP,
|
|
2517
|
+
"1d": null,
|
|
2518
|
+
// WebGL2 only
|
|
2519
|
+
"3d": (t == null ? void 0 : t.TEXTURE_3D) || null,
|
|
2520
|
+
"2d-array": (t == null ? void 0 : t.TEXTURE_2D_ARRAY) || null,
|
|
2521
|
+
"cube-array": (t == null ? void 0 : t.TEXTURE_CUBE_MAP_ARRAY) || null
|
|
2522
|
+
};
|
|
2523
|
+
}
|
|
2524
|
+
const Lt = 4;
|
|
2525
|
+
class Re {
|
|
2526
|
+
constructor(e) {
|
|
2527
|
+
this._glSamplers = /* @__PURE__ */ Object.create(null), this._boundTextures = [], this._activeTextureLocation = -1, this._boundSamplers = /* @__PURE__ */ Object.create(null), this._premultiplyAlpha = !1, this._useSeparateSamplers = !1, this._renderer = e, this._managedTextures = new P({
|
|
2528
|
+
renderer: e,
|
|
2529
|
+
type: "resource",
|
|
2530
|
+
onUnload: this.onSourceUnload.bind(this),
|
|
2531
|
+
name: "glTexture"
|
|
2532
|
+
});
|
|
2533
|
+
const r = {
|
|
2534
|
+
image: Se,
|
|
2535
|
+
buffer: vt,
|
|
2536
|
+
video: It,
|
|
2537
|
+
compressed: Bt
|
|
2538
|
+
};
|
|
2539
|
+
this._uploads = {
|
|
2540
|
+
...r,
|
|
2541
|
+
cube: yt(r)
|
|
2542
|
+
};
|
|
2543
|
+
}
|
|
2544
|
+
/**
|
|
2545
|
+
* @deprecated since 8.15.0
|
|
2546
|
+
*/
|
|
2547
|
+
get managedTextures() {
|
|
2548
|
+
return Object.values(this._managedTextures.items);
|
|
2549
|
+
}
|
|
2550
|
+
contextChange(e) {
|
|
2551
|
+
this._gl = e, this._mapFormatToInternalFormat || (this._mapFormatToInternalFormat = Pt(e, this._renderer.context.extensions), this._mapFormatToType = Ot(e), this._mapFormatToFormat = Ft(e), this._mapViewDimensionToGlTarget = Mt(e)), this._managedTextures.removeAll(!0), this._glSamplers = /* @__PURE__ */ Object.create(null), this._boundSamplers = /* @__PURE__ */ Object.create(null), this._premultiplyAlpha = !1;
|
|
2552
|
+
for (let r = 0; r < 16; r++)
|
|
2553
|
+
this.bind(S.EMPTY, r);
|
|
2554
|
+
}
|
|
2555
|
+
/**
|
|
2556
|
+
* Initializes a texture source, if it has already been initialized nothing will happen.
|
|
2557
|
+
* @param source - The texture source to initialize.
|
|
2558
|
+
* @returns The initialized texture source.
|
|
2559
|
+
*/
|
|
2560
|
+
initSource(e) {
|
|
2561
|
+
this.bind(e);
|
|
2562
|
+
}
|
|
2563
|
+
bind(e, r = 0) {
|
|
2564
|
+
const n = e.source;
|
|
2565
|
+
e ? (this.bindSource(n, r), this._useSeparateSamplers && this._bindSampler(n.style, r)) : (this.bindSource(null, r), this._useSeparateSamplers && this._bindSampler(null, r));
|
|
2566
|
+
}
|
|
2567
|
+
bindSource(e, r = 0) {
|
|
2568
|
+
const n = this._gl;
|
|
2569
|
+
if (e._gcLastUsed = this._renderer.gc.now, this._boundTextures[r] !== e) {
|
|
2570
|
+
this._boundTextures[r] = e, this._activateLocation(r), e || (e = S.EMPTY.source);
|
|
2571
|
+
const s = this.getGlSource(e);
|
|
2572
|
+
n.bindTexture(s.target, s.texture);
|
|
2573
|
+
}
|
|
2574
|
+
}
|
|
2575
|
+
_bindSampler(e, r = 0) {
|
|
2576
|
+
const n = this._gl;
|
|
2577
|
+
if (!e) {
|
|
2578
|
+
this._boundSamplers[r] = null, n.bindSampler(r, null);
|
|
2579
|
+
return;
|
|
2580
|
+
}
|
|
2581
|
+
const s = this._getGlSampler(e);
|
|
2582
|
+
this._boundSamplers[r] !== s && (this._boundSamplers[r] = s, n.bindSampler(r, s));
|
|
2583
|
+
}
|
|
2584
|
+
unbind(e) {
|
|
2585
|
+
const r = e.source, n = this._boundTextures, s = this._gl;
|
|
2586
|
+
for (let i = 0; i < n.length; i++)
|
|
2587
|
+
if (n[i] === r) {
|
|
2588
|
+
this._activateLocation(i);
|
|
2589
|
+
const a = this.getGlSource(r);
|
|
2590
|
+
s.bindTexture(a.target, null), n[i] = null;
|
|
2591
|
+
}
|
|
2592
|
+
}
|
|
2593
|
+
_activateLocation(e) {
|
|
2594
|
+
this._activeTextureLocation !== e && (this._activeTextureLocation = e, this._gl.activeTexture(this._gl.TEXTURE0 + e));
|
|
2595
|
+
}
|
|
2596
|
+
_initSource(e) {
|
|
2597
|
+
const r = this._gl, n = new xt(r.createTexture());
|
|
2598
|
+
if (n.type = this._mapFormatToType[e.format], n.internalFormat = this._mapFormatToInternalFormat[e.format], n.format = this._mapFormatToFormat[e.format], n.target = this._mapViewDimensionToGlTarget[e.viewDimension], n.target === null)
|
|
2599
|
+
throw new Error(`Unsupported view dimension: ${e.viewDimension} with this webgl version: ${this._renderer.context.webGLVersion}`);
|
|
2600
|
+
if (e.uploadMethodId === "cube" && (n.target = r.TEXTURE_CUBE_MAP), e.autoGenerateMipmaps && (this._renderer.context.supports.nonPowOf2mipmaps || e.isPowerOfTwo)) {
|
|
2601
|
+
const i = Math.max(e.width, e.height);
|
|
2602
|
+
e.mipLevelCount = Math.floor(Math.log2(i)) + 1;
|
|
2603
|
+
}
|
|
2604
|
+
return e._gpuData[this._renderer.uid] = n, this._managedTextures.add(e) && (e.on("update", this.onSourceUpdate, this), e.on("resize", this.onSourceUpdate, this), e.on("styleChange", this.onStyleChange, this), e.on("updateMipmaps", this.onUpdateMipmaps, this)), this.onSourceUpdate(e), this.updateStyle(e, !1), n;
|
|
2605
|
+
}
|
|
2606
|
+
onStyleChange(e) {
|
|
2607
|
+
this.updateStyle(e, !1);
|
|
2608
|
+
}
|
|
2609
|
+
updateStyle(e, r) {
|
|
2610
|
+
const n = this._gl, s = this.getGlSource(e);
|
|
2611
|
+
n.bindTexture(s.target, s.texture), this._boundTextures[this._activeTextureLocation] = e, Y(
|
|
2612
|
+
e.style,
|
|
2613
|
+
n,
|
|
2614
|
+
e.mipLevelCount > 1,
|
|
2615
|
+
this._renderer.context.extensions.anisotropicFiltering,
|
|
2616
|
+
"texParameteri",
|
|
2617
|
+
s.target,
|
|
2618
|
+
// will force a clamp to edge if the texture is not a power of two
|
|
2619
|
+
!this._renderer.context.supports.nonPowOf2wrapping && !e.isPowerOfTwo,
|
|
2620
|
+
r
|
|
2621
|
+
);
|
|
2622
|
+
}
|
|
2623
|
+
onSourceUnload(e, r = !1) {
|
|
2624
|
+
const n = e._gpuData[this._renderer.uid];
|
|
2625
|
+
n && (r || (this.unbind(e), this._gl.deleteTexture(n.texture)), e.off("update", this.onSourceUpdate, this), e.off("resize", this.onSourceUpdate, this), e.off("styleChange", this.onStyleChange, this), e.off("updateMipmaps", this.onUpdateMipmaps, this));
|
|
2626
|
+
}
|
|
2627
|
+
onSourceUpdate(e) {
|
|
2628
|
+
const r = this._gl, n = this.getGlSource(e);
|
|
2629
|
+
r.bindTexture(n.target, n.texture), this._boundTextures[this._activeTextureLocation] = e;
|
|
2630
|
+
const s = e.alphaMode === "premultiply-alpha-on-upload";
|
|
2631
|
+
if (this._premultiplyAlpha !== s && (this._premultiplyAlpha = s, r.pixelStorei(r.UNPACK_PREMULTIPLY_ALPHA_WEBGL, s)), this._uploads[e.uploadMethodId])
|
|
2632
|
+
this._uploads[e.uploadMethodId].upload(e, n, r, this._renderer.context.webGLVersion);
|
|
2633
|
+
else if (n.target === r.TEXTURE_2D)
|
|
2634
|
+
this._initEmptyTexture2D(n, e);
|
|
2635
|
+
else if (n.target === r.TEXTURE_2D_ARRAY)
|
|
2636
|
+
this._initEmptyTexture2DArray(n, e);
|
|
2637
|
+
else if (n.target === r.TEXTURE_CUBE_MAP)
|
|
2638
|
+
this._initEmptyTextureCube(n, e);
|
|
2639
|
+
else
|
|
2640
|
+
throw new Error("[GlTextureSystem] Unsupported texture target for empty allocation.");
|
|
2641
|
+
this._applyMipRange(n, e), e.autoGenerateMipmaps && e.mipLevelCount > 1 && this.onUpdateMipmaps(e, !1);
|
|
2642
|
+
}
|
|
2643
|
+
onUpdateMipmaps(e, r = !0) {
|
|
2644
|
+
r && this.bindSource(e, 0);
|
|
2645
|
+
const n = this.getGlSource(e);
|
|
2646
|
+
this._gl.generateMipmap(n.target);
|
|
2647
|
+
}
|
|
2648
|
+
_initEmptyTexture2D(e, r) {
|
|
2649
|
+
const n = this._gl;
|
|
2650
|
+
n.texImage2D(
|
|
2651
|
+
n.TEXTURE_2D,
|
|
2652
|
+
0,
|
|
2653
|
+
e.internalFormat,
|
|
2654
|
+
r.pixelWidth,
|
|
2655
|
+
r.pixelHeight,
|
|
2656
|
+
0,
|
|
2657
|
+
e.format,
|
|
2658
|
+
e.type,
|
|
2659
|
+
null
|
|
2660
|
+
);
|
|
2661
|
+
let s = Math.max(r.pixelWidth >> 1, 1), i = Math.max(r.pixelHeight >> 1, 1);
|
|
2662
|
+
for (let a = 1; a < r.mipLevelCount; a++)
|
|
2663
|
+
n.texImage2D(
|
|
2664
|
+
n.TEXTURE_2D,
|
|
2665
|
+
a,
|
|
2666
|
+
e.internalFormat,
|
|
2667
|
+
s,
|
|
2668
|
+
i,
|
|
2669
|
+
0,
|
|
2670
|
+
e.format,
|
|
2671
|
+
e.type,
|
|
2672
|
+
null
|
|
2673
|
+
), s = Math.max(s >> 1, 1), i = Math.max(i >> 1, 1);
|
|
2674
|
+
}
|
|
2675
|
+
_initEmptyTexture2DArray(e, r) {
|
|
2676
|
+
if (this._renderer.context.webGLVersion !== 2)
|
|
2677
|
+
throw new Error("[GlTextureSystem] TEXTURE_2D_ARRAY requires WebGL2.");
|
|
2678
|
+
const n = this._gl, s = Math.max(r.arrayLayerCount | 0, 1);
|
|
2679
|
+
n.texImage3D(
|
|
2680
|
+
n.TEXTURE_2D_ARRAY,
|
|
2681
|
+
0,
|
|
2682
|
+
e.internalFormat,
|
|
2683
|
+
r.pixelWidth,
|
|
2684
|
+
r.pixelHeight,
|
|
2685
|
+
s,
|
|
2686
|
+
0,
|
|
2687
|
+
e.format,
|
|
2688
|
+
e.type,
|
|
2689
|
+
null
|
|
2690
|
+
);
|
|
2691
|
+
let i = Math.max(r.pixelWidth >> 1, 1), a = Math.max(r.pixelHeight >> 1, 1);
|
|
2692
|
+
for (let o = 1; o < r.mipLevelCount; o++)
|
|
2693
|
+
n.texImage3D(
|
|
2694
|
+
n.TEXTURE_2D_ARRAY,
|
|
2695
|
+
o,
|
|
2696
|
+
e.internalFormat,
|
|
2697
|
+
i,
|
|
2698
|
+
a,
|
|
2699
|
+
s,
|
|
2700
|
+
0,
|
|
2701
|
+
e.format,
|
|
2702
|
+
e.type,
|
|
2703
|
+
null
|
|
2704
|
+
), i = Math.max(i >> 1, 1), a = Math.max(a >> 1, 1);
|
|
2705
|
+
}
|
|
2706
|
+
_initEmptyTextureCube(e, r) {
|
|
2707
|
+
const n = this._gl, s = 6;
|
|
2708
|
+
for (let o = 0; o < s; o++)
|
|
2709
|
+
n.texImage2D(
|
|
2710
|
+
n.TEXTURE_CUBE_MAP_POSITIVE_X + o,
|
|
2711
|
+
0,
|
|
2712
|
+
e.internalFormat,
|
|
2713
|
+
r.pixelWidth,
|
|
2714
|
+
r.pixelHeight,
|
|
2715
|
+
0,
|
|
2716
|
+
e.format,
|
|
2717
|
+
e.type,
|
|
2718
|
+
null
|
|
2719
|
+
);
|
|
2720
|
+
let i = Math.max(r.pixelWidth >> 1, 1), a = Math.max(r.pixelHeight >> 1, 1);
|
|
2721
|
+
for (let o = 1; o < r.mipLevelCount; o++) {
|
|
2722
|
+
for (let u = 0; u < s; u++)
|
|
2723
|
+
n.texImage2D(
|
|
2724
|
+
n.TEXTURE_CUBE_MAP_POSITIVE_X + u,
|
|
2725
|
+
o,
|
|
2726
|
+
e.internalFormat,
|
|
2727
|
+
i,
|
|
2728
|
+
a,
|
|
2729
|
+
0,
|
|
2730
|
+
e.format,
|
|
2731
|
+
e.type,
|
|
2732
|
+
null
|
|
2733
|
+
);
|
|
2734
|
+
i = Math.max(i >> 1, 1), a = Math.max(a >> 1, 1);
|
|
2735
|
+
}
|
|
2736
|
+
}
|
|
2737
|
+
/**
|
|
2738
|
+
* Applies a mip range to the currently-bound texture so WebGL2 considers the texture "mipmap complete"
|
|
2739
|
+
* for the declared `mipLevelCount` (especially important for partial mip chains rendered via FBO).
|
|
2740
|
+
* @param glTexture - The GL texture wrapper.
|
|
2741
|
+
* @param source - The texture source describing mipLevelCount.
|
|
2742
|
+
*/
|
|
2743
|
+
_applyMipRange(e, r) {
|
|
2744
|
+
if (this._renderer.context.webGLVersion !== 2) return;
|
|
2745
|
+
const n = this._gl, s = Math.max((r.mipLevelCount | 0) - 1, 0);
|
|
2746
|
+
n.texParameteri(e.target, n.TEXTURE_BASE_LEVEL, 0), n.texParameteri(e.target, n.TEXTURE_MAX_LEVEL, s);
|
|
2747
|
+
}
|
|
2748
|
+
_initSampler(e) {
|
|
2749
|
+
const r = this._gl, n = this._gl.createSampler();
|
|
2750
|
+
return this._glSamplers[e._resourceId] = n, Y(
|
|
2751
|
+
e,
|
|
2752
|
+
r,
|
|
2753
|
+
this._boundTextures[this._activeTextureLocation].mipLevelCount > 1,
|
|
2754
|
+
this._renderer.context.extensions.anisotropicFiltering,
|
|
2755
|
+
"samplerParameteri",
|
|
2756
|
+
n,
|
|
2757
|
+
!1,
|
|
2758
|
+
!0
|
|
2759
|
+
), this._glSamplers[e._resourceId];
|
|
2760
|
+
}
|
|
2761
|
+
_getGlSampler(e) {
|
|
2762
|
+
return this._glSamplers[e._resourceId] || this._initSampler(e);
|
|
2763
|
+
}
|
|
2764
|
+
getGlSource(e) {
|
|
2765
|
+
return e._gcLastUsed = this._renderer.gc.now, e._gpuData[this._renderer.uid] || this._initSource(e);
|
|
2766
|
+
}
|
|
2767
|
+
generateCanvas(e) {
|
|
2768
|
+
const { pixels: r, width: n, height: s } = this.getPixels(e), i = R.get().createCanvas();
|
|
2769
|
+
i.width = n, i.height = s;
|
|
2770
|
+
const a = i.getContext("2d");
|
|
2771
|
+
if (a) {
|
|
2772
|
+
const o = a.createImageData(n, s);
|
|
2773
|
+
o.data.set(r), a.putImageData(o, 0, 0);
|
|
2774
|
+
}
|
|
2775
|
+
return i;
|
|
2776
|
+
}
|
|
2777
|
+
getPixels(e) {
|
|
2778
|
+
const r = e.source.resolution, n = e.frame, s = Math.max(Math.round(n.width * r), 1), i = Math.max(Math.round(n.height * r), 1), a = new Uint8Array(Lt * s * i), o = this._renderer, u = o.renderTarget.getRenderTarget(e), c = o.renderTarget.getGpuRenderTarget(u), _ = o.gl;
|
|
2779
|
+
return _.bindFramebuffer(_.FRAMEBUFFER, c.resolveTargetFramebuffer), _.readPixels(
|
|
2780
|
+
Math.round(n.x * r),
|
|
2781
|
+
Math.round(n.y * r),
|
|
2782
|
+
s,
|
|
2783
|
+
i,
|
|
2784
|
+
_.RGBA,
|
|
2785
|
+
_.UNSIGNED_BYTE,
|
|
2786
|
+
a
|
|
2787
|
+
), { pixels: new Uint8ClampedArray(a.buffer), width: s, height: i };
|
|
2788
|
+
}
|
|
2789
|
+
destroy() {
|
|
2790
|
+
this._managedTextures.destroy(), this._glSamplers = null, this._boundTextures = null, this._boundSamplers = null, this._mapFormatToInternalFormat = null, this._mapFormatToType = null, this._mapFormatToFormat = null, this._uploads = null, this._renderer = null;
|
|
2791
|
+
}
|
|
2792
|
+
resetState() {
|
|
2793
|
+
this._activeTextureLocation = -1, this._boundTextures.fill(S.EMPTY.source), this._boundSamplers = /* @__PURE__ */ Object.create(null);
|
|
2794
|
+
const e = this._gl;
|
|
2795
|
+
this._premultiplyAlpha = !1, e.pixelStorei(e.UNPACK_PREMULTIPLY_ALPHA_WEBGL, this._premultiplyAlpha);
|
|
2796
|
+
}
|
|
2797
|
+
}
|
|
2798
|
+
Re.extension = {
|
|
2799
|
+
type: [
|
|
2800
|
+
d.WebGLSystem
|
|
2801
|
+
],
|
|
2802
|
+
name: "texture"
|
|
2803
|
+
};
|
|
2804
|
+
class ge {
|
|
2805
|
+
contextChange(e) {
|
|
2806
|
+
const r = new M({
|
|
2807
|
+
uColor: { value: new Float32Array([1, 1, 1, 1]), type: "vec4<f32>" },
|
|
2808
|
+
uTransformMatrix: { value: new Z(), type: "mat3x3<f32>" },
|
|
2809
|
+
uRound: { value: 0, type: "f32" }
|
|
2810
|
+
}), n = e.limits.maxBatchableTextures, s = Q({
|
|
2811
|
+
name: "graphics",
|
|
2812
|
+
bits: [
|
|
2813
|
+
De,
|
|
2814
|
+
Ie(n),
|
|
2815
|
+
te,
|
|
2816
|
+
J
|
|
2817
|
+
]
|
|
2818
|
+
});
|
|
2819
|
+
this.shader = new O({
|
|
2820
|
+
glProgram: s,
|
|
2821
|
+
resources: {
|
|
2822
|
+
localUniforms: r,
|
|
2823
|
+
batchSamplers: Ge(n)
|
|
2824
|
+
}
|
|
2825
|
+
});
|
|
2826
|
+
}
|
|
2827
|
+
execute(e, r) {
|
|
2828
|
+
const n = r.context, s = n.customShader || this.shader, i = e.renderer, a = i.graphicsContext, {
|
|
2829
|
+
batcher: o,
|
|
2830
|
+
instructions: u
|
|
2831
|
+
} = a.getContextRenderData(n);
|
|
2832
|
+
s.groups[0] = i.globalUniforms.bindGroup, i.state.set(e.state), i.shader.bind(s), i.geometry.bind(o.geometry, s.glProgram);
|
|
2833
|
+
const c = u.instructions;
|
|
2834
|
+
for (let _ = 0; _ < u.instructionSize; _++) {
|
|
2835
|
+
const f = c[_];
|
|
2836
|
+
if (f.size) {
|
|
2837
|
+
for (let h = 0; h < f.textures.count; h++)
|
|
2838
|
+
i.texture.bind(f.textures.textures[h], h);
|
|
2839
|
+
i.geometry.draw(f.topology, f.size, f.start);
|
|
2840
|
+
}
|
|
2841
|
+
}
|
|
2842
|
+
}
|
|
2843
|
+
destroy() {
|
|
2844
|
+
this.shader.destroy(!0), this.shader = null;
|
|
2845
|
+
}
|
|
2846
|
+
}
|
|
2847
|
+
ge.extension = {
|
|
2848
|
+
type: [
|
|
2849
|
+
d.WebGLPipesAdaptor
|
|
2850
|
+
],
|
|
2851
|
+
name: "graphics"
|
|
2852
|
+
};
|
|
2853
|
+
class Te {
|
|
2854
|
+
init() {
|
|
2855
|
+
const e = Q({
|
|
2856
|
+
name: "mesh",
|
|
2857
|
+
bits: [
|
|
2858
|
+
te,
|
|
2859
|
+
He,
|
|
2860
|
+
J
|
|
2861
|
+
]
|
|
2862
|
+
});
|
|
2863
|
+
this._shader = new O({
|
|
2864
|
+
glProgram: e,
|
|
2865
|
+
resources: {
|
|
2866
|
+
uTexture: S.EMPTY.source,
|
|
2867
|
+
textureUniforms: {
|
|
2868
|
+
uTextureMatrix: { type: "mat3x3<f32>", value: new Z() }
|
|
2869
|
+
}
|
|
2870
|
+
}
|
|
2871
|
+
});
|
|
2872
|
+
}
|
|
2873
|
+
execute(e, r) {
|
|
2874
|
+
const n = e.renderer;
|
|
2875
|
+
let s = r._shader;
|
|
2876
|
+
if (s) {
|
|
2877
|
+
if (!s.glProgram) {
|
|
2878
|
+
p("Mesh shader has no glProgram", r.shader);
|
|
2879
|
+
return;
|
|
2880
|
+
}
|
|
2881
|
+
} else {
|
|
2882
|
+
s = this._shader;
|
|
2883
|
+
const i = r.texture, a = i.source;
|
|
2884
|
+
s.resources.uTexture = a, s.resources.uSampler = a.style, s.resources.textureUniforms.uniforms.uTextureMatrix = i.textureMatrix.mapCoord;
|
|
2885
|
+
}
|
|
2886
|
+
s.groups[100] = n.globalUniforms.bindGroup, s.groups[101] = e.localUniformsBindGroup, n.encoder.draw({
|
|
2887
|
+
geometry: r._geometry,
|
|
2888
|
+
shader: s,
|
|
2889
|
+
state: r.state
|
|
2890
|
+
});
|
|
2891
|
+
}
|
|
2892
|
+
destroy() {
|
|
2893
|
+
this._shader.destroy(!0), this._shader = null;
|
|
2894
|
+
}
|
|
2895
|
+
}
|
|
2896
|
+
Te.extension = {
|
|
2897
|
+
type: [
|
|
2898
|
+
d.WebGLPipesAdaptor
|
|
2899
|
+
],
|
|
2900
|
+
name: "mesh"
|
|
2901
|
+
};
|
|
2902
|
+
const wt = [
|
|
2903
|
+
...Xe,
|
|
2904
|
+
he,
|
|
2905
|
+
Ze,
|
|
2906
|
+
$e,
|
|
2907
|
+
ue,
|
|
2908
|
+
ne,
|
|
2909
|
+
Re,
|
|
2910
|
+
le,
|
|
2911
|
+
ie,
|
|
2912
|
+
be,
|
|
2913
|
+
Ee,
|
|
2914
|
+
ce,
|
|
2915
|
+
Tt,
|
|
2916
|
+
_e,
|
|
2917
|
+
oe
|
|
2918
|
+
], Ht = [...ke], Vt = [re, Te, ge], xe = [], ve = [], Ae = [];
|
|
2919
|
+
A.handleByNamedList(d.WebGLSystem, xe);
|
|
2920
|
+
A.handleByNamedList(d.WebGLPipes, ve);
|
|
2921
|
+
A.handleByNamedList(d.WebGLPipesAdaptor, Ae);
|
|
2922
|
+
A.add(...wt, ...Ht, ...Vt);
|
|
2923
|
+
class jt extends Ue {
|
|
2924
|
+
constructor() {
|
|
2925
|
+
const e = {
|
|
2926
|
+
name: "webgl",
|
|
2927
|
+
type: Fe.WEBGL,
|
|
2928
|
+
systems: xe,
|
|
2929
|
+
renderPipes: ve,
|
|
2930
|
+
renderPipeAdaptors: Ae
|
|
2931
|
+
};
|
|
2932
|
+
super(e);
|
|
2933
|
+
}
|
|
2934
|
+
}
|
|
2935
|
+
export {
|
|
2936
|
+
jt as WebGLRenderer
|
|
2937
|
+
};
|
|
2938
|
+
//# sourceMappingURL=WebGLRenderer-D18tg5um.js.map
|