wave-roll
Version:
JavaScript Library for Comparative MIDI Piano-Roll Visualization
1,433 lines (1,425 loc) • 90.6 kB
JavaScript
import { E as d, B as T, w as m, i as S, X as j, H as Te, z as G, A as b, ab as Be, o as K, ac as Ae, S as p, _ as L, n as B, m as A, q as U, M as $, ad as z, ae as Ne, af as ye, ag as Y, ah as Ce, F as Ie, R as De, f as v } from "./index-C4TFo-hd.js";
import { S as F, b as q } from "./colorToUniform-zJcCVLeu.js";
import { e as Ge, G as Ue, c as Fe, b as Oe, U as Pe, R as Me, B as Z, d as N, f as Le, S as He, a as we } from "./SharedSystems-B50M1M-P.js";
class Q {
constructor() {
this._tempState = F.for2d(), this._didUploadHash = {};
}
init(e) {
e.renderer.runners.contextChange.add(this);
}
contextChange() {
this._didUploadHash = {};
}
start(e, r, s) {
const n = e.renderer, i = this._didUploadHash[s.uid];
n.shader.bind(s, i), i || (this._didUploadHash[s.uid] = !0), n.shader.updateUniformGroup(n.globalUniforms.uniformGroup), n.geometry.bind(r, s.glProgram);
}
execute(e, r) {
const s = e.renderer;
this._tempState.blendMode = r.blendMode, s.state.set(this._tempState);
const n = r.textures.textures;
for (let i = 0; i < r.textures.count; i++)
s.texture.bind(n[i], i);
s.geometry.draw(r.topology, r.size, r.start);
}
}
Q.extension = {
type: [
d.WebGLPipesAdaptor
],
name: "batch"
};
var x = /* @__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))(x || {});
class Ve {
constructor(e, r) {
this._lastBindBaseLocation = -1, this._lastBindCallId = -1, this.buffer = e || null, this.updateID = -1, this.byteLength = -1, this.type = r;
}
}
class J {
/**
* @param {Renderer} renderer - The renderer this System works for.
*/
constructor(e) {
this._gpuBuffers = /* @__PURE__ */ Object.create(null), this._boundBufferBases = /* @__PURE__ */ Object.create(null), this._minBaseLocation = 0, this._nextBindBaseIndex = this._minBaseLocation, this._bindCallId = 0, this._renderer = e, this._renderer.renderableGC.addManagedHash(this, "_gpuBuffers");
}
/** @ignore */
destroy() {
this._renderer = null, this._gl = null, this._gpuBuffers = null, this._boundBufferBases = null;
}
/** Sets up the renderer context and necessary buffers. */
contextChange() {
this._gl = this._renderer.gl, this._gpuBuffers = /* @__PURE__ */ Object.create(null), this._maxBindings = this._renderer.limits.maxUniformBindings;
}
getGlBuffer(e) {
return this._gpuBuffers[e.uid] || this.createGLBuffer(e);
}
/**
* This binds specified buffer. On first run, it will create the webGL buffers for the context too
* @param buffer - the buffer to bind to the renderer
*/
bind(e) {
const { _gl: r } = this, s = this.getGlBuffer(e);
r.bindBuffer(s.type, s.buffer);
}
/**
* Binds an uniform buffer to at the given index.
*
* A cache is used so a buffer will not be bound again if already bound.
* @param glBuffer - the buffer to bind
* @param index - the base index to bind it to.
*/
bindBufferBase(e, r) {
const { _gl: s } = this;
this._boundBufferBases[r] !== e && (this._boundBufferBases[r] = e, e._lastBindBaseLocation = r, s.bindBufferBase(s.UNIFORM_BUFFER, r, e.buffer));
}
nextBindBase(e) {
this._bindCallId++, this._minBaseLocation = 0, e && (this._boundBufferBases[0] = null, this._minBaseLocation = 1, this._nextBindBaseIndex < 1 && (this._nextBindBaseIndex = 1));
}
freeLocationForBufferBase(e) {
let r = this.getLastBindBaseLocation(e);
if (r >= this._minBaseLocation)
return e._lastBindCallId = this._bindCallId, r;
let s = 0, n = this._nextBindBaseIndex;
for (; s < 2; ) {
n >= this._maxBindings && (n = this._minBaseLocation, s++);
const i = this._boundBufferBases[n];
if (i && i._lastBindCallId === this._bindCallId) {
n++;
continue;
}
break;
}
return r = n, this._nextBindBaseIndex = n + 1, s >= 2 ? -1 : (e._lastBindCallId = this._bindCallId, this._boundBufferBases[r] = null, r);
}
getLastBindBaseLocation(e) {
const r = e._lastBindBaseLocation;
return this._boundBufferBases[r] === e ? r : -1;
}
/**
* Binds a buffer whilst also binding its range.
* This will make the buffer start from the offset supplied rather than 0 when it is read.
* @param glBuffer - the buffer to bind
* @param index - the base index to bind at, defaults to 0
* @param offset - the offset to bind at (this is blocks of 256). 0 = 0, 1 = 256, 2 = 512 etc
* @param size - the size to bind at (this is blocks of 256).
*/
bindBufferRange(e, r, s, n) {
const { _gl: i } = this;
s || (s = 0), r || (r = 0), this._boundBufferBases[r] = null, i.bindBufferRange(i.UNIFORM_BUFFER, r || 0, e.buffer, s * 256, n || 256);
}
/**
* Will ensure the data in the buffer is uploaded to the GPU.
* @param {Buffer} buffer - the buffer to update
*/
updateBuffer(e) {
const { _gl: r } = this, s = this.getGlBuffer(e);
if (e._updateID === s.updateID)
return s;
s.updateID = e._updateID, r.bindBuffer(s.type, s.buffer);
const n = e.data, i = e.descriptor.usage & T.STATIC ? r.STATIC_DRAW : r.DYNAMIC_DRAW;
return n ? s.byteLength >= n.byteLength ? r.bufferSubData(s.type, 0, n, 0, e._updateSize / n.BYTES_PER_ELEMENT) : (s.byteLength = n.byteLength, r.bufferData(s.type, n, i)) : (s.byteLength = e.descriptor.size, r.bufferData(s.type, s.byteLength, i)), s;
}
/** dispose all WebGL resources of all managed buffers */
destroyAll() {
const e = this._gl;
for (const r in this._gpuBuffers)
e.deleteBuffer(this._gpuBuffers[r].buffer);
this._gpuBuffers = /* @__PURE__ */ Object.create(null);
}
/**
* Disposes buffer
* @param {Buffer} buffer - buffer with data
* @param {boolean} [contextLost=false] - If context was lost, we suppress deleteVertexArray
*/
onBufferDestroy(e, r) {
const s = this._gpuBuffers[e.uid], n = this._gl;
r || n.deleteBuffer(s.buffer), this._gpuBuffers[e.uid] = null;
}
/**
* creates and attaches a GLBuffer object tied to the current context.
* @param buffer
* @protected
*/
createGLBuffer(e) {
const { _gl: r } = this;
let s = x.ARRAY_BUFFER;
e.descriptor.usage & T.INDEX ? s = x.ELEMENT_ARRAY_BUFFER : e.descriptor.usage & T.UNIFORM && (s = x.UNIFORM_BUFFER);
const n = new Ve(r.createBuffer(), s);
return this._gpuBuffers[e.uid] = n, e.on("destroy", this.onBufferDestroy, this), n;
}
resetState() {
this._boundBufferBases = /* @__PURE__ */ Object.create(null);
}
}
J.extension = {
type: [
d.WebGLSystem
],
name: "buffer"
};
const O = class ee {
/** @param renderer - The renderer this System works for. */
constructor(e) {
this.supports = {
/** Support for 32-bit indices buffer. */
uint32Indices: !0,
/** Support for UniformBufferObjects */
uniformBufferObject: !0,
/** Support for VertexArrayObjects */
vertexArrayObject: !0,
/** Support for SRGB texture format */
srgbTextures: !0,
/** Support for wrapping modes if a texture is non-power of two */
nonPowOf2wrapping: !0,
/** Support for MSAA (antialiasing of dynamic textures) */
msaa: !0,
/** Support for mipmaps if a texture is non-power of two */
nonPowOf2mipmaps: !0
}, this._renderer = e, this.extensions = /* @__PURE__ */ Object.create(null), this.handleContextLost = this.handleContextLost.bind(this), this.handleContextRestored = this.handleContextRestored.bind(this);
}
/**
* `true` if the context is lost
* @readonly
*/
get isLost() {
return !this.gl || this.gl.isContextLost();
}
/**
* Handles the context change event.
* @param {WebGLRenderingContext} gl - New WebGL context.
*/
contextChange(e) {
this.gl = e, this._renderer.gl = e;
}
init(e) {
e = { ...ee.defaultOptions, ...e };
let r = this.multiView = e.multiView;
if (e.context && r && (m("Renderer created with both a context and multiview enabled. Disabling multiView as both cannot work together."), r = !1), r ? this.canvas = S.get().createCanvas(this._renderer.canvas.width, this._renderer.canvas.height) : this.canvas = this._renderer.view.canvas, e.context)
this.initFromContext(e.context);
else {
const s = this._renderer.background.alpha < 1, n = e.premultipliedAlpha ?? !0, i = e.antialias && !this._renderer.backBuffer.useBackBuffer;
this.createContext(e.preferWebGLVersion, {
alpha: s,
premultipliedAlpha: n,
antialias: i,
stencil: !0,
preserveDrawingBuffer: e.preserveDrawingBuffer,
powerPreference: e.powerPreference ?? "default"
});
}
}
ensureCanvasSize(e) {
if (!this.multiView) {
e !== this.canvas && m("multiView is disabled, but targetCanvas is not the main canvas");
return;
}
const { canvas: r } = this;
(r.width < e.width || r.height < e.height) && (r.width = Math.max(e.width, e.width), r.height = Math.max(e.height, e.height));
}
/**
* Initializes the context.
* @protected
* @param {WebGLRenderingContext} gl - WebGL context
*/
initFromContext(e) {
this.gl = e, this.webGLVersion = e instanceof S.get().getWebGLRenderingContext() ? 1 : 2, this.getExtensions(), this.validateContext(e), this._renderer.runners.contextChange.emit(e);
const r = this._renderer.view.canvas;
r.addEventListener("webglcontextlost", this.handleContextLost, !1), r.addEventListener("webglcontextrestored", this.handleContextRestored, !1);
}
/**
* Initialize from context options
* @protected
* @see https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/getContext
* @param preferWebGLVersion
* @param {object} options - context attributes
*/
createContext(e, r) {
let s;
const n = this.canvas;
if (e === 2 && (s = n.getContext("webgl2", r)), !s && (s = n.getContext("webgl", r), !s))
throw new Error("This browser does not support WebGL. Try using the canvas renderer");
this.gl = s, this.initFromContext(this.gl);
}
/** Auto-populate the {@link GlContextSystem.extensions extensions}. */
getExtensions() {
const { gl: e } = this, r = {
anisotropicFiltering: e.getExtension("EXT_texture_filter_anisotropic"),
floatTextureLinear: e.getExtension("OES_texture_float_linear"),
s3tc: e.getExtension("WEBGL_compressed_texture_s3tc"),
s3tc_sRGB: e.getExtension("WEBGL_compressed_texture_s3tc_srgb"),
// eslint-disable-line camelcase
etc: e.getExtension("WEBGL_compressed_texture_etc"),
etc1: e.getExtension("WEBGL_compressed_texture_etc1"),
pvrtc: e.getExtension("WEBGL_compressed_texture_pvrtc") || e.getExtension("WEBKIT_WEBGL_compressed_texture_pvrtc"),
atc: e.getExtension("WEBGL_compressed_texture_atc"),
astc: e.getExtension("WEBGL_compressed_texture_astc"),
bptc: e.getExtension("EXT_texture_compression_bptc"),
rgtc: e.getExtension("EXT_texture_compression_rgtc"),
loseContext: e.getExtension("WEBGL_lose_context")
};
if (this.webGLVersion === 1)
this.extensions = {
...r,
drawBuffers: e.getExtension("WEBGL_draw_buffers"),
depthTexture: e.getExtension("WEBGL_depth_texture"),
vertexArrayObject: e.getExtension("OES_vertex_array_object") || e.getExtension("MOZ_OES_vertex_array_object") || e.getExtension("WEBKIT_OES_vertex_array_object"),
uint32ElementIndex: e.getExtension("OES_element_index_uint"),
// Floats and half-floats
floatTexture: e.getExtension("OES_texture_float"),
floatTextureLinear: e.getExtension("OES_texture_float_linear"),
textureHalfFloat: e.getExtension("OES_texture_half_float"),
textureHalfFloatLinear: e.getExtension("OES_texture_half_float_linear"),
vertexAttribDivisorANGLE: e.getExtension("ANGLE_instanced_arrays"),
srgb: e.getExtension("EXT_sRGB")
};
else {
this.extensions = {
...r,
colorBufferFloat: e.getExtension("EXT_color_buffer_float")
};
const s = e.getExtension("WEBGL_provoking_vertex");
s && s.provokingVertexWEBGL(s.FIRST_VERTEX_CONVENTION_WEBGL);
}
}
/**
* Handles a lost webgl context
* @param {WebGLContextEvent} event - The context lost event.
*/
handleContextLost(e) {
e.preventDefault(), this._contextLossForced && (this._contextLossForced = !1, setTimeout(() => {
this.gl.isContextLost() && this.extensions.loseContext?.restoreContext();
}, 0));
}
/** Handles a restored webgl context. */
handleContextRestored() {
this.getExtensions(), this._renderer.runners.contextChange.emit(this.gl);
}
destroy() {
const e = this._renderer.view.canvas;
this._renderer = null, e.removeEventListener("webglcontextlost", this.handleContextLost), e.removeEventListener("webglcontextrestored", this.handleContextRestored), this.gl.useProgram(null), this.extensions.loseContext?.loseContext();
}
/**
* this function can be called to force a webGL context loss
* this will release all resources on the GPU.
* Useful if you need to put Pixi to sleep, and save some GPU memory
*
* As soon as render is called - all resources will be created again.
*/
forceContextLoss() {
this.extensions.loseContext?.loseContext(), this._contextLossForced = !0;
}
/**
* Validate context.
* @param {WebGLRenderingContext} gl - Render context.
*/
validateContext(e) {
const r = e.getContextAttributes();
r && !r.stencil && m("Provided WebGL context does not have a stencil buffer, masks may not render correctly");
const s = this.supports, n = this.webGLVersion === 2, i = this.extensions;
s.uint32Indices = n || !!i.uint32ElementIndex, s.uniformBufferObject = n, s.vertexArrayObject = n || !!i.vertexArrayObject, s.srgbTextures = n || !!i.srgb, s.nonPowOf2wrapping = n, s.nonPowOf2mipmaps = n, s.msaa = n, s.uint32Indices || m("Provided WebGL context does not support 32 index buffer, large scenes may not render correctly");
}
};
O.extension = {
type: [
d.WebGLSystem
],
name: "context"
};
O.defaultOptions = {
/**
* {@link WebGLOptions.context}
* @default null
*/
context: null,
/**
* {@link WebGLOptions.premultipliedAlpha}
* @default true
*/
premultipliedAlpha: !0,
/**
* {@link WebGLOptions.preserveDrawingBuffer}
* @default false
*/
preserveDrawingBuffer: !1,
/**
* {@link WebGLOptions.powerPreference}
* @default default
*/
powerPreference: void 0,
/**
* {@link WebGLOptions.webGLVersion}
* @default 2
*/
preferWebGLVersion: 2,
/**
* {@link WebGLOptions.multiView}
* @default false
*/
multiView: !1
};
let ke = O;
var I = /* @__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))(I || {}), te = /* @__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))(te || {}), f = /* @__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))(f || {});
const H = {
uint8x2: f.UNSIGNED_BYTE,
uint8x4: f.UNSIGNED_BYTE,
sint8x2: f.BYTE,
sint8x4: f.BYTE,
unorm8x2: f.UNSIGNED_BYTE,
unorm8x4: f.UNSIGNED_BYTE,
snorm8x2: f.BYTE,
snorm8x4: f.BYTE,
uint16x2: f.UNSIGNED_SHORT,
uint16x4: f.UNSIGNED_SHORT,
sint16x2: f.SHORT,
sint16x4: f.SHORT,
unorm16x2: f.UNSIGNED_SHORT,
unorm16x4: f.UNSIGNED_SHORT,
snorm16x2: f.SHORT,
snorm16x4: f.SHORT,
float16x2: f.HALF_FLOAT,
float16x4: f.HALF_FLOAT,
float32: f.FLOAT,
float32x2: f.FLOAT,
float32x3: f.FLOAT,
float32x4: f.FLOAT,
uint32: f.UNSIGNED_INT,
uint32x2: f.UNSIGNED_INT,
uint32x3: f.UNSIGNED_INT,
uint32x4: f.UNSIGNED_INT,
sint32: f.INT,
sint32x2: f.INT,
sint32x3: f.INT,
sint32x4: f.INT
};
function Xe(t) {
return H[t] ?? H.float32;
}
const We = {
"point-list": 0,
"line-list": 1,
"line-strip": 3,
"triangle-list": 4,
"triangle-strip": 5
};
class re {
/** @param renderer - The renderer this System works for. */
constructor(e) {
this._geometryVaoHash = /* @__PURE__ */ Object.create(null), this._renderer = e, this._activeGeometry = null, this._activeVao = null, this.hasVao = !0, this.hasInstance = !0, this._renderer.renderableGC.addManagedHash(this, "_geometryVaoHash");
}
/** Sets up the renderer context and necessary buffers. */
contextChange() {
const e = this.gl = this._renderer.gl;
if (!this._renderer.context.supports.vertexArrayObject)
throw new Error("[PixiJS] Vertex Array Objects are not supported on this device");
const r = this._renderer.context.extensions.vertexArrayObject;
r && (e.createVertexArray = () => r.createVertexArrayOES(), e.bindVertexArray = (n) => r.bindVertexArrayOES(n), e.deleteVertexArray = (n) => r.deleteVertexArrayOES(n));
const s = this._renderer.context.extensions.vertexAttribDivisorANGLE;
s && (e.drawArraysInstanced = (n, i, a, o) => {
s.drawArraysInstancedANGLE(n, i, a, o);
}, e.drawElementsInstanced = (n, i, a, o, c) => {
s.drawElementsInstancedANGLE(n, i, a, o, c);
}, e.vertexAttribDivisor = (n, i) => s.vertexAttribDivisorANGLE(n, i)), this._activeGeometry = null, this._activeVao = null, this._geometryVaoHash = /* @__PURE__ */ Object.create(null);
}
/**
* Binds geometry so that is can be drawn. Creating a Vao if required
* @param geometry - Instance of geometry to bind.
* @param program - Instance of program to use vao for.
*/
bind(e, r) {
const s = this.gl;
this._activeGeometry = e;
const n = this.getVao(e, r);
this._activeVao !== n && (this._activeVao = n, s.bindVertexArray(n)), this.updateBuffers();
}
/** Reset and unbind any active VAO and geometry. */
resetState() {
this.unbind();
}
/** Update buffers of the currently bound geometry. */
updateBuffers() {
const e = this._activeGeometry, r = this._renderer.buffer;
for (let s = 0; s < e.buffers.length; s++) {
const n = e.buffers[s];
r.updateBuffer(n);
}
}
/**
* Check compatibility between a geometry and a program
* @param geometry - Geometry instance.
* @param program - Program instance.
*/
checkCompatibility(e, r) {
const s = e.attributes, n = r._attributeData;
for (const i in n)
if (!s[i])
throw new Error(`shader and geometry incompatible, geometry missing the "${i}" attribute`);
}
/**
* Takes a geometry and program and generates a unique signature for them.
* @param geometry - To get signature from.
* @param program - To test geometry against.
* @returns - Unique signature of the geometry and program
*/
getSignature(e, r) {
const s = e.attributes, n = r._attributeData, i = ["g", e.uid];
for (const a in s)
n[a] && i.push(a, n[a].location);
return i.join("-");
}
getVao(e, r) {
return this._geometryVaoHash[e.uid]?.[r._key] || this.initGeometryVao(e, r);
}
/**
* Creates or gets Vao with the same structure as the geometry and stores it on the geometry.
* If vao is created, it is bound automatically. We use a shader to infer what and how to set up the
* attribute locations.
* @param geometry - Instance of geometry to to generate Vao for.
* @param program
* @param _incRefCount - Increment refCount of all geometry buffers.
*/
initGeometryVao(e, r, s = !0) {
const n = this._renderer.gl, i = this._renderer.buffer;
this._renderer.shader._getProgramData(r), this.checkCompatibility(e, r);
const a = this.getSignature(e, r);
this._geometryVaoHash[e.uid] || (this._geometryVaoHash[e.uid] = /* @__PURE__ */ Object.create(null), e.on("destroy", this.onGeometryDestroy, this));
const o = this._geometryVaoHash[e.uid];
let c = o[a];
if (c)
return o[r._key] = c, c;
Ge(e, r._attributeData);
const u = e.buffers;
c = n.createVertexArray(), n.bindVertexArray(c);
for (let _ = 0; _ < u.length; _++) {
const h = u[_];
i.bind(h);
}
return this.activateVao(e, r), o[r._key] = c, o[a] = c, n.bindVertexArray(null), c;
}
/**
* Disposes geometry.
* @param geometry - Geometry with buffers. Only VAO will be disposed
* @param [contextLost=false] - If context was lost, we suppress deleteVertexArray
*/
onGeometryDestroy(e, r) {
const s = this._geometryVaoHash[e.uid], n = this.gl;
if (s) {
if (r)
for (const i in s)
this._activeVao !== s[i] && this.unbind(), n.deleteVertexArray(s[i]);
this._geometryVaoHash[e.uid] = null;
}
}
/**
* Dispose all WebGL resources of all managed geometries.
* @param [contextLost=false] - If context was lost, we suppress `gl.delete` calls
*/
destroyAll(e = !1) {
const r = this.gl;
for (const s in this._geometryVaoHash) {
if (e)
for (const n in this._geometryVaoHash[s]) {
const i = this._geometryVaoHash[s];
this._activeVao !== i && this.unbind(), r.deleteVertexArray(i[n]);
}
this._geometryVaoHash[s] = null;
}
}
/**
* Activate vertex array object.
* @param geometry - Geometry instance.
* @param program - Shader program instance.
*/
activateVao(e, r) {
const s = this._renderer.gl, n = this._renderer.buffer, i = e.attributes;
e.indexBuffer && n.bind(e.indexBuffer);
let a = null;
for (const o in i) {
const c = i[o], u = c.buffer, _ = n.getGlBuffer(u), h = r._attributeData[o];
if (h) {
a !== _ && (n.bind(u), a = _);
const l = h.location;
s.enableVertexAttribArray(l);
const E = j(c.format), M = Xe(c.format);
if (h.format?.substring(1, 4) === "int" ? s.vertexAttribIPointer(
l,
E.size,
M,
c.stride,
c.offset
) : s.vertexAttribPointer(
l,
E.size,
M,
E.normalised,
c.stride,
c.offset
), c.instance)
if (this.hasInstance) {
const ve = c.divisor ?? 1;
s.vertexAttribDivisor(l, ve);
} else
throw new Error("geometry error, GPU Instancing is not supported on this device");
}
}
}
/**
* Draws the currently bound geometry.
* @param topology - The type primitive to render.
* @param size - The number of elements to be rendered. If not specified, all vertices after the
* starting vertex will be drawn.
* @param start - The starting vertex in the geometry to start drawing from. If not specified,
* drawing will start from the first vertex.
* @param instanceCount - The number of instances of the set of elements to execute. If not specified,
* all instances will be drawn.
* @returns This instance of the geometry system.
*/
draw(e, r, s, n) {
const { gl: i } = this._renderer, a = this._activeGeometry, o = We[e || a.topology];
if (n ?? (n = a.instanceCount), a.indexBuffer) {
const c = a.indexBuffer.data.BYTES_PER_ELEMENT, u = c === 2 ? i.UNSIGNED_SHORT : i.UNSIGNED_INT;
n > 1 ? i.drawElementsInstanced(o, r || a.indexBuffer.data.length, u, (s || 0) * c, n) : i.drawElements(o, r || a.indexBuffer.data.length, u, (s || 0) * c);
} else n > 1 ? i.drawArraysInstanced(o, s || 0, r || a.getSize(), n) : i.drawArrays(o, s || 0, r || a.getSize());
return this;
}
/** Unbind/reset everything. */
unbind() {
this.gl.bindVertexArray(null), this._activeVao = null, this._activeGeometry = null;
}
destroy() {
this._renderer = null, this.gl = null, this._activeVao = null, this._activeGeometry = null;
}
}
re.extension = {
type: [
d.WebGLSystem
],
name: "geometry"
};
const je = new Be({
attributes: {
aPosition: [
-1,
-1,
// Bottom left corner
3,
-1,
// Bottom right corner, extending beyond right edge
-1,
3
// Top left corner, extending beyond top edge
]
}
}), P = class se {
constructor(e) {
this.useBackBuffer = !1, this._useBackBufferThisRender = !1, this._renderer = e;
}
init(e = {}) {
const { useBackBuffer: r, antialias: s } = { ...se.defaultOptions, ...e };
this.useBackBuffer = r, this._antialias = s, this._renderer.context.supports.msaa || (m("antialiasing, is not supported on when using the back buffer"), this._antialias = !1), this._state = F.for2d();
const n = new Te({
vertex: `
attribute vec2 aPosition;
out vec2 vUv;
void main() {
gl_Position = vec4(aPosition, 0.0, 1.0);
vUv = (aPosition + 1.0) / 2.0;
// flip dem UVs
vUv.y = 1.0 - vUv.y;
}`,
fragment: `
in vec2 vUv;
out vec4 finalColor;
uniform sampler2D uTexture;
void main() {
finalColor = texture(uTexture, vUv);
}`,
name: "big-triangle"
});
this._bigTriangleShader = new G({
glProgram: n,
resources: {
uTexture: b.WHITE.source
}
});
}
/**
* This is called before the RenderTargetSystem is started. This is where
* we replace the target with the back buffer if required.
* @param options - The options for this render.
*/
renderStart(e) {
const r = this._renderer.renderTarget.getRenderTarget(e.target);
if (this._useBackBufferThisRender = this.useBackBuffer && !!r.isRoot, this._useBackBufferThisRender) {
const s = this._renderer.renderTarget.getRenderTarget(e.target);
this._targetTexture = s.colorTexture, e.target = this._getBackBufferTexture(s.colorTexture);
}
}
renderEnd() {
this._presentBackBuffer();
}
_presentBackBuffer() {
const e = this._renderer;
e.renderTarget.finishRenderPass(), this._useBackBufferThisRender && (e.renderTarget.bind(this._targetTexture, !1), this._bigTriangleShader.resources.uTexture = this._backBufferTexture.source, e.encoder.draw({
geometry: je,
shader: this._bigTriangleShader,
state: this._state
}));
}
_getBackBufferTexture(e) {
return this._backBufferTexture = this._backBufferTexture || new b({
source: new K({
width: e.width,
height: e.height,
resolution: e._resolution,
antialias: this._antialias
})
}), this._backBufferTexture.source.resize(
e.width,
e.height,
e._resolution
), this._backBufferTexture;
}
/** destroys the back buffer */
destroy() {
this._backBufferTexture && (this._backBufferTexture.destroy(), this._backBufferTexture = null);
}
};
P.extension = {
type: [
d.WebGLSystem
],
name: "backBuffer",
priority: 1
};
P.defaultOptions = {
/** if true will use the back buffer where required */
useBackBuffer: !1
};
let Ke = P;
class ne {
constructor(e) {
this._colorMaskCache = 15, this._renderer = e;
}
setMask(e) {
this._colorMaskCache !== e && (this._colorMaskCache = e, this._renderer.gl.colorMask(
!!(e & 8),
!!(e & 4),
!!(e & 2),
!!(e & 1)
));
}
}
ne.extension = {
type: [
d.WebGLSystem
],
name: "colorMask"
};
class ie {
constructor(e) {
this.commandFinished = Promise.resolve(), this._renderer = e;
}
setGeometry(e, r) {
this._renderer.geometry.bind(e, r.glProgram);
}
finishRenderPass() {
}
draw(e) {
const r = this._renderer, { geometry: s, shader: n, state: i, skipSync: a, topology: o, size: c, start: u, instanceCount: _ } = e;
r.shader.bind(n, a), r.geometry.bind(s, r.shader._activeProgram), i && r.state.set(i), r.geometry.draw(o, c, u, _ ?? s.instanceCount);
}
destroy() {
this._renderer = null;
}
}
ie.extension = {
type: [
d.WebGLSystem
],
name: "encoder"
};
class ae {
constructor(e) {
this._renderer = e;
}
contextChange() {
const e = this._renderer.gl;
this.maxTextures = e.getParameter(e.MAX_TEXTURE_IMAGE_UNITS), this.maxBatchableTextures = Ae(this.maxTextures, e), this.maxUniformBindings = e.getParameter(e.MAX_UNIFORM_BUFFER_BINDINGS);
}
destroy() {
}
}
ae.extension = {
type: [
d.WebGLSystem
],
name: "limits"
};
class $e {
constructor() {
this.width = -1, this.height = -1, this.msaa = !1, this.msaaRenderBuffer = [];
}
}
class oe {
constructor(e) {
this._stencilCache = {
enabled: !1,
stencilReference: 0,
stencilMode: p.NONE
}, this._renderTargetStencilState = /* @__PURE__ */ Object.create(null), e.renderTarget.onRenderTargetChange.add(this);
}
contextChange(e) {
this._gl = e, this._comparisonFuncMapping = {
always: e.ALWAYS,
never: e.NEVER,
equal: e.EQUAL,
"not-equal": e.NOTEQUAL,
less: e.LESS,
"less-equal": e.LEQUAL,
greater: e.GREATER,
"greater-equal": e.GEQUAL
}, this._stencilOpsMapping = {
keep: e.KEEP,
zero: e.ZERO,
replace: e.REPLACE,
invert: e.INVERT,
"increment-clamp": e.INCR,
"decrement-clamp": e.DECR,
"increment-wrap": e.INCR_WRAP,
"decrement-wrap": e.DECR_WRAP
}, this.resetState();
}
onRenderTargetChange(e) {
if (this._activeRenderTarget === e)
return;
this._activeRenderTarget = e;
let r = this._renderTargetStencilState[e.uid];
r || (r = this._renderTargetStencilState[e.uid] = {
stencilMode: p.DISABLED,
stencilReference: 0
}), this.setStencilMode(r.stencilMode, r.stencilReference);
}
resetState() {
this._stencilCache.enabled = !1, this._stencilCache.stencilMode = p.NONE, this._stencilCache.stencilReference = 0;
}
setStencilMode(e, r) {
const s = this._renderTargetStencilState[this._activeRenderTarget.uid], n = this._gl, i = Ue[e], a = this._stencilCache;
if (s.stencilMode = e, s.stencilReference = r, e === p.DISABLED) {
this._stencilCache.enabled && (this._stencilCache.enabled = !1, n.disable(n.STENCIL_TEST));
return;
}
this._stencilCache.enabled || (this._stencilCache.enabled = !0, n.enable(n.STENCIL_TEST)), (e !== a.stencilMode || a.stencilReference !== r) && (a.stencilMode = e, a.stencilReference = r, n.stencilFunc(this._comparisonFuncMapping[i.stencilBack.compare], r, 255), n.stencilOp(n.KEEP, n.KEEP, this._stencilOpsMapping[i.stencilBack.passOp]));
}
}
oe.extension = {
type: [
d.WebGLSystem
],
name: "stencil"
};
const ce = {
f32: 4,
i32: 4,
"vec2<f32>": 8,
"vec3<f32>": 12,
"vec4<f32>": 16,
"vec2<i32>": 8,
"vec3<i32>": 12,
"vec4<i32>": 16,
"mat2x2<f32>": 32,
"mat3x3<f32>": 48,
"mat4x4<f32>": 64
// TODO - not essential for now but support these in the future
// int: 4,
// ivec2: 8,
// ivec3: 12,
// ivec4: 16,
// uint: 4,
// uvec2: 8,
// uvec3: 12,
// uvec4: 16,
// bool: 4,
// bvec2: 8,
// bvec3: 12,
// bvec4: 16,
// mat2: 16 * 2,
// mat3: 16 * 3,
// mat4: 16 * 4,
};
function ze(t) {
const e = t.map((i) => ({
data: i,
offset: 0,
size: 0
})), r = 16;
let s = 0, n = 0;
for (let i = 0; i < e.length; i++) {
const a = e[i];
if (s = ce[a.data.type], !s)
throw new Error(`Unknown type ${a.data.type}`);
a.data.size > 1 && (s = Math.max(s, r) * a.data.size);
const o = s === 12 ? 16 : s;
a.size = s;
const c = n % r;
c > 0 && r - c < o ? n += (r - c) % 16 : n += (s - c % s) % s, a.offset = n, n += s;
}
return n = Math.ceil(n / 16) * 16, { uboElements: e, size: n };
}
function Ye(t, e) {
const r = Math.max(ce[t.data.type] / 16, 1), s = t.data.value.length / t.data.size, n = (4 - s % 4) % 4, i = t.data.type.indexOf("i32") >= 0 ? "dataInt32" : "data";
return `
v = uv.${t.data.name};
offset += ${e};
arrayOffset = offset;
t = 0;
for(var i=0; i < ${t.data.size * r}; i++)
{
for(var j = 0; j < ${s}; j++)
{
${i}[arrayOffset++] = v[t++];
}
${n !== 0 ? `arrayOffset += ${n};` : ""}
}
`;
}
function qe(t) {
return Fe(
t,
"uboStd40",
Ye,
Oe
);
}
class ue extends Pe {
constructor() {
super({
createUboElements: ze,
generateUboSync: qe
});
}
}
ue.extension = {
type: [d.WebGLSystem],
name: "ubo"
};
class Ze {
constructor() {
this._clearColorCache = [0, 0, 0, 0], this._viewPortCache = new L();
}
init(e, r) {
this._renderer = e, this._renderTargetSystem = r, e.runners.contextChange.add(this);
}
contextChange() {
this._clearColorCache = [0, 0, 0, 0], this._viewPortCache = new L();
}
copyToTexture(e, r, s, n, i) {
const a = this._renderTargetSystem, o = this._renderer, c = a.getGpuRenderTarget(e), u = o.gl;
return this.finishRenderPass(e), u.bindFramebuffer(u.FRAMEBUFFER, c.resolveTargetFramebuffer), o.texture.bind(r, 0), u.copyTexSubImage2D(
u.TEXTURE_2D,
0,
i.x,
i.y,
s.x,
s.y,
n.width,
n.height
), r;
}
startRenderPass(e, r = !0, s, n) {
const i = this._renderTargetSystem, a = e.colorTexture, o = i.getGpuRenderTarget(e);
let c = n.y;
e.isRoot && (c = a.pixelHeight - n.height), e.colorTextures.forEach((h) => {
this._renderer.texture.unbind(h);
});
const u = this._renderer.gl;
u.bindFramebuffer(u.FRAMEBUFFER, o.framebuffer);
const _ = this._viewPortCache;
(_.x !== n.x || _.y !== c || _.width !== n.width || _.height !== n.height) && (_.x = n.x, _.y = c, _.width = n.width, _.height = n.height, u.viewport(
n.x,
c,
n.width,
n.height
)), !o.depthStencilRenderBuffer && (e.stencil || e.depth) && this._initStencil(o), this.clear(e, r, s);
}
finishRenderPass(e) {
const s = this._renderTargetSystem.getGpuRenderTarget(e);
if (!s.msaa)
return;
const n = this._renderer.gl;
n.bindFramebuffer(n.FRAMEBUFFER, s.resolveTargetFramebuffer), n.bindFramebuffer(n.READ_FRAMEBUFFER, s.framebuffer), n.blitFramebuffer(
0,
0,
s.width,
s.height,
0,
0,
s.width,
s.height,
n.COLOR_BUFFER_BIT,
n.NEAREST
), n.bindFramebuffer(n.FRAMEBUFFER, s.framebuffer);
}
initGpuRenderTarget(e) {
const s = this._renderer.gl, n = new $e();
return e.colorTexture instanceof B ? (this._renderer.context.ensureCanvasSize(e.colorTexture.resource), n.framebuffer = null, n) : (this._initColor(e, n), s.bindFramebuffer(s.FRAMEBUFFER, null), n);
}
destroyGpuRenderTarget(e) {
const r = this._renderer.gl;
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((s) => {
r.deleteRenderbuffer(s);
}), e.msaaRenderBuffer = null;
}
clear(e, r, s) {
if (!r)
return;
const n = this._renderTargetSystem;
typeof r == "boolean" && (r = r ? A.ALL : A.NONE);
const i = this._renderer.gl;
if (r & A.COLOR) {
s ?? (s = n.defaultClearColor);
const a = this._clearColorCache, o = s;
(a[0] !== o[0] || a[1] !== o[1] || a[2] !== o[2] || a[3] !== o[3]) && (a[0] = o[0], a[1] = o[1], a[2] = o[2], a[3] = o[3], i.clearColor(o[0], o[1], o[2], o[3]));
}
i.clear(r);
}
resizeGpuRenderTarget(e) {
if (e.isRoot)
return;
const s = this._renderTargetSystem.getGpuRenderTarget(e);
this._resizeColor(e, s), (e.stencil || e.depth) && this._resizeStencil(s);
}
_initColor(e, r) {
const s = this._renderer, n = s.gl, i = n.createFramebuffer();
if (r.resolveTargetFramebuffer = i, n.bindFramebuffer(n.FRAMEBUFFER, i), r.width = e.colorTexture.source.pixelWidth, r.height = e.colorTexture.source.pixelHeight, e.colorTextures.forEach((a, o) => {
const c = a.source;
c.antialias && (s.context.supports.msaa ? r.msaa = !0 : m("[RenderTexture] Antialiasing on textures is not supported in WebGL1")), s.texture.bindSource(c, 0);
const _ = s.texture.getGlSource(c).texture;
n.framebufferTexture2D(
n.FRAMEBUFFER,
n.COLOR_ATTACHMENT0 + o,
3553,
// texture.target,
_,
0
);
}), r.msaa) {
const a = n.createFramebuffer();
r.framebuffer = a, n.bindFramebuffer(n.FRAMEBUFFER, a), e.colorTextures.forEach((o, c) => {
const u = n.createRenderbuffer();
r.msaaRenderBuffer[c] = u;
});
} else
r.framebuffer = i;
this._resizeColor(e, r);
}
_resizeColor(e, r) {
const s = e.colorTexture.source;
if (r.width = s.pixelWidth, r.height = s.pixelHeight, e.colorTextures.forEach((n, i) => {
i !== 0 && n.source.resize(s.width, s.height, s._resolution);
}), r.msaa) {
const n = this._renderer, i = n.gl, a = r.framebuffer;
i.bindFramebuffer(i.FRAMEBUFFER, a), e.colorTextures.forEach((o, c) => {
const u = o.source;
n.texture.bindSource(u, 0);
const h = n.texture.getGlSource(u).internalFormat, l = r.msaaRenderBuffer[c];
i.bindRenderbuffer(
i.RENDERBUFFER,
l
), i.renderbufferStorageMultisample(
i.RENDERBUFFER,
4,
h,
u.pixelWidth,
u.pixelHeight
), i.framebufferRenderbuffer(
i.FRAMEBUFFER,
i.COLOR_ATTACHMENT0 + c,
i.RENDERBUFFER,
l
);
});
}
}
_initStencil(e) {
if (e.framebuffer === null)
return;
const r = this._renderer.gl, s = r.createRenderbuffer();
e.depthStencilRenderBuffer = s, r.bindRenderbuffer(
r.RENDERBUFFER,
s
), r.framebufferRenderbuffer(
r.FRAMEBUFFER,
r.DEPTH_STENCIL_ATTACHMENT,
r.RENDERBUFFER,
s
), this._resizeStencil(e);
}
_resizeStencil(e) {
const r = this._renderer.gl;
r.bindRenderbuffer(
r.RENDERBUFFER,
e.depthStencilRenderBuffer
), e.msaa ? r.renderbufferStorageMultisample(
r.RENDERBUFFER,
4,
r.DEPTH24_STENCIL8,
e.width,
e.height
) : r.renderbufferStorage(
r.RENDERBUFFER,
this._renderer.context.webGLVersion === 2 ? r.DEPTH24_STENCIL8 : r.DEPTH_STENCIL,
e.width,
e.height
);
}
prerender(e) {
const r = e.colorTexture.resource;
this._renderer.context.multiView && B.test(r) && this._renderer.context.ensureCanvasSize(r);
}
postrender(e) {
if (this._renderer.context.multiView && B.test(e.colorTexture.resource)) {
const r = this._renderer.context.canvas, s = e.colorTexture;
s.context2D.drawImage(
r,
0,
s.pixelHeight - r.height
);
}
}
}
class _e extends Me {
constructor(e) {
super(e), this.adaptor = new Ze(), this.adaptor.init(e, this);
}
}
_e.extension = {
type: [d.WebGLSystem],
name: "renderTarget"
};
function Qe(t, e) {
const r = [], s = [`
var g = s.groups;
var sS = r.shader;
var p = s.glProgram;
var ugS = r.uniformGroup;
var resources;
`];
let n = !1, i = 0;
const a = e._getProgramData(t.glProgram);
for (const c in t.groups) {
const u = t.groups[c];
r.push(`
resources = g[${c}].resources;
`);
for (const _ in u.resources) {
const h = u.resources[_];
if (h instanceof U)
if (h.ubo) {
const l = t._uniformBindMap[c][Number(_)];
r.push(`
sS.bindUniformBlock(
resources[${_}],
'${l}',
${t.glProgram._uniformBlockData[l].index}
);
`);
} else
r.push(`
ugS.updateUniformGroup(resources[${_}], p, sD);
`);
else if (h instanceof Z) {
const l = t._uniformBindMap[c][Number(_)];
r.push(`
sS.bindUniformBlock(
resources[${_}],
'${l}',
${t.glProgram._uniformBlockData[l].index}
);
`);
} else if (h instanceof K) {
const l = t._uniformBindMap[c][_], E = a.uniformData[l];
E && (n || (n = !0, s.push(`
var tS = r.texture;
`)), e._gl.uniform1i(E.location, i), r.push(`
tS.bind(resources[${_}], ${i});
`), i++);
}
}
}
const o = [...s, ...r].join(`
`);
return new Function("r", "s", "sD", o);
}
class Je {
/**
* Makes a new Pixi program.
* @param program - webgl program
* @param uniformData - uniforms
*/
constructor(e, r) {
this.program = e, this.uniformData = r, this.uniformGroups = {}, this.uniformDirtyGroups = {}, this.uniformBlockBindings = {};
}
/** Destroys this program. */
destroy() {
this.uniformData = null, this.uniformGroups = null, this.uniformDirtyGroups = null, this.uniformBlockBindings = null, this.program = null;
}
}
function w(t, e, r) {
const s = t.createShader(e);
return t.shaderSource(s, r), t.compileShader(s), s;
}
function y(t) {
const e = new Array(t);
for (let r = 0; r < e.length; r++)
e[r] = !1;
return e;
}
function fe(t, e) {
switch (t) {
case "float":
return 0;
case "vec2":
return new Float32Array(2 * e);
case "vec3":
return new Float32Array(3 * e);
case "vec4":
return new Float32Array(4 * e);
case "int":
case "uint":
case "sampler2D":
case "sampler2DArray":
return 0;
case "ivec2":
return new Int32Array(2 * e);
case "ivec3":
return new Int32Array(3 * e);
case "ivec4":
return new Int32Array(4 * e);
case "uvec2":
return new Uint32Array(2 * e);
case "uvec3":
return new Uint32Array(3 * e);
case "uvec4":
return new Uint32Array(4 * e);
case "bool":
return !1;
case "bvec2":
return y(2 * e);
case "bvec3":
return y(3 * e);
case "bvec4":
return y(4 * e);
case "mat2":
return new Float32Array([
1,
0,
0,
1
]);
case "mat3":
return new Float32Array([
1,
0,
0,
0,
1,
0,
0,
0,
1
]);
case "mat4":
return new Float32Array([
1,
0,
0,
0,
0,
1,
0,
0,
0,
0,
1,
0,
0,
0,
0,
1
]);
}
return null;
}
let g = null;
const V = {
FLOAT: "float",
FLOAT_VEC2: "vec2",
FLOAT_VEC3: "vec3",
FLOAT_VEC4: "vec4",
INT: "int",
INT_VEC2: "ivec2",
INT_VEC3: "ivec3",
INT_VEC4: "ivec4",
UNSIGNED_INT: "uint",
UNSIGNED_INT_VEC2: "uvec2",
UNSIGNED_INT_VEC3: "uvec3",
UNSIGNED_INT_VEC4: "uvec4",
BOOL: "bool",
BOOL_VEC2: "bvec2",
BOOL_VEC3: "bvec3",
BOOL_VEC4: "bvec4",
FLOAT_MAT2: "mat2",
FLOAT_MAT3: "mat3",
FLOAT_MAT4: "mat4",
SAMPLER_2D: "sampler2D",
INT_SAMPLER_2D: "sampler2D",
UNSIGNED_INT_SAMPLER_2D: "sampler2D",
SAMPLER_CUBE: "samplerCube",
INT_SAMPLER_CUBE: "samplerCube",
UNSIGNED_INT_SAMPLER_CUBE: "samplerCube",
SAMPLER_2D_ARRAY: "sampler2DArray",
INT_SAMPLER_2D_ARRAY: "sampler2DArray",
UNSIGNED_INT_SAMPLER_2D_ARRAY: "sampler2DArray"
}, et = {
float: "float32",
vec2: "float32x2",
vec3: "float32x3",
vec4: "float32x4",
int: "sint32",
ivec2: "sint32x2",
ivec3: "sint32x3",
ivec4: "sint32x4",
uint: "uint32",
uvec2: "uint32x2",
uvec3: "uint32x3",
uvec4: "uint32x4",
bool: "uint32",
bvec2: "uint32x2",
bvec3: "uint32x3",
bvec4: "uint32x4"
};
function he(t, e) {
if (!g) {
const r = Object.keys(V);
g = {};
for (let s = 0; s < r.length; ++s) {
const n = r[s];
g[t[n]] = V[n];
}
}
return g[e];
}
function tt(t, e) {
const r = he(t, e);
return et[r] || "float32";
}
function rt(t, e, r = !1) {
const s = {}, n = e.getProgramParameter(t, e.ACTIVE_ATTRIBUTES);
for (let a = 0; a < n; a++) {
const o = e.getActiveAttrib(t, a);
if (o.name.startsWith("gl_"))
continue;
const c = tt(e, o.type);
s[o.name] = {
location: 0,
// set further down..
format: c,
stride: j(c).stride,
offset: 0,
instance: !1,
start: 0
};
}
const i = Object.keys(s);
if (r) {
i.sort((a, o) => a > o ? 1 : -1);
for (let a = 0; a < i.length; a++)
s[i[a]].location = a, e.bindAttribLocation(t, a, i[a]);
e.linkProgram(t);
} else
for (let a = 0; a < i.length; a++)
s[i[a]].location = e.getAttribLocation(t, i[a]);
return s;
}
function st(t, e) {
if (!e.ACTIVE_UNIFORM_BLOCKS)
return {};
const r = {}, s = e.getProgramParameter(t, e.ACTIVE_UNIFORM_BLOCKS);
for (let n = 0; n < s; n++) {
const i = e.getActiveUniformBlockName(t, n), a = e.getUniformBlockIndex(t, i), o = e.getActiveUniformBlockParameter(t, n, e.UNIFORM_BLOCK_DATA_SIZE);
r[i] = {
name: i,
index: a,
size: o
};
}
return r;
}
function nt(t, e) {
const r = {}, s = e.getProgramParameter(t, e.ACTIVE_UNIFORMS);
for (let n = 0; n < s; n++) {
const i = e.getActiveUniform(t, n), a = i.name.replace(/\[.*?\]$/, ""), o = !!i.name.match(/\[.*?\]$/), c = he(e, i.type);
r[a] = {
name: a,
index: n,
type: c,
size: i.size,
isArray: o,
value: fe(c, i.size)
};
}
return r;
}
function k(t, e) {
const r = t.getShaderSource(e).split(`
`).map((u, _) => `${_}: ${u}`), s = t.getShaderInfoLog(e), n = s.split(`
`), i = {}, a = n.map((u) => parseFloat(u.replace(/^ERROR\: 0\:([\d]+)\:.*$/, "$1"))).filter((u) => u && !i[u] ? (i[u] = !0, !0) : !1), o = [""];
a.forEach((u) => {
r[u - 1] = `%c${r[u - 1]}%c`, o.push("background: #FF0000; color:#FFFFFF; font-size: 10px", "font-size: 10px");
});
const c = r.join(`
`);
o[0] = c, console.error(s), console.groupCollapsed("click to view full shader code"), console.warn(...o), console.groupEnd();
}
function it(t, e, r, s) {
t.getProgramParameter(e, t.LINK_STATUS) || (t.getShaderParameter(r, t.COMPILE_STATUS) || k(t, r), t.getShaderParameter(s, t.COMPILE_STATUS) || k(t, s), console.error("PixiJS Error: Could not initialize shader."), t.getProgramInfoLog(e) !== "" && console.warn("PixiJS Warning: gl.getProgramInfoLog()", t.getProgramInfoLog(e)));
}
function at(t, e) {
const r = w(t, t.VERTEX_SHADER, e.vertex), s = w(t, t.FRAGMENT_SHADER, e.fragment), n = t.createProgram();
t.attachShader(n, r), t.attachShader(n, s);
const i = e.transformFeedbackVaryings;
i && (typeof t.transformFeedbackVaryings != "function" ? m("TransformFeedback is not supported but TransformFeedbackVaryings are given.") : t.transformFeedbackVaryings(
n,
i.names,
i.bufferMode === "separate" ? t.SEPARATE_ATTRIBS : t.INTERLEAVED_ATTRIBS
)), t.linkProgram(n), t.getProgramParameter(n, t.LINK_STATUS) || it(t, n, r, s), e._attributeData = rt(
n,
t,
!/^[ \t]*#[ \t]*version[ \t]+300[ \t]+es[ \t]*$/m.test(e.vertex)
), e._uniformData = nt(n, t), e._uniformBlockData = st(n, t), t.deleteShader(r), t.deleteShader(s);
const a = {};
for (const c in e._uniformData) {
const u = e._uniformData[c];
a[c] = {
location: t.getUniformLocation(n, c),
value: fe(u.type, u.size)
};
}
return new Je(n, a);
}
const R = {
textureCount: 0,
blockIndex: 0
};
class le {
constructor(e) {
this._activeProgram = null, this._programDataHash = /* @__PURE__ */ Object.create(null), this._shaderSyncFunctions = /* @__PURE__ */ Object.create(null), this._renderer = e, this._renderer.renderableGC.addManagedHash(this, "_programDataHash");
}
contextChange(e) {
this._gl = e, this._programDataHash = /* @__PURE__ */ Object.create(null), this._shaderSyncFunctions = /* @__PURE__ */ Object.create(null), this._activeProgram = null;
}
/**
* Changes the current shader to the one given in parameter.
* @param shader - the new shader
* @param skipSync - false if the shader sho