@industry-theme/repository-composition-panels 0.7.14 → 0.7.16

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.
Files changed (147) hide show
  1. package/dist/assets/orchestrators/index.d.ts +28 -0
  2. package/dist/assets/orchestrators/index.d.ts.map +1 -0
  3. package/dist/browserAll-XNN46GKF.js +7 -0
  4. package/dist/browserAll-XNN46GKF.js.map +1 -0
  5. package/dist/{index-pPFTSf2O.js → index-Bt-XsLNt.js} +16092 -689
  6. package/dist/{index-pPFTSf2O.js.map → index-Bt-XsLNt.js.map} +1 -1
  7. package/dist/index.d.ts +35 -0
  8. package/dist/index.d.ts.map +1 -0
  9. package/dist/init-Ccb5WXmw.js +4 -0
  10. package/dist/init-Ccb5WXmw.js.map +1 -0
  11. package/dist/mocks/panelContext.d.ts +24 -0
  12. package/dist/mocks/panelContext.d.ts.map +1 -0
  13. package/dist/panels/CollectionMapPanel.d.ts +132 -0
  14. package/dist/panels/CollectionMapPanel.d.ts.map +1 -0
  15. package/dist/panels/GitChangesPanel.d.ts +48 -0
  16. package/dist/panels/GitChangesPanel.d.ts.map +1 -0
  17. package/dist/panels/PackageCompositionPanel.d.ts +37 -0
  18. package/dist/panels/PackageCompositionPanel.d.ts.map +1 -0
  19. package/dist/panels/SearchPanel.d.ts +33 -0
  20. package/dist/panels/SearchPanel.d.ts.map +1 -0
  21. package/dist/panels/TelemetryCoveragePanel.d.ts +48 -0
  22. package/dist/panels/TelemetryCoveragePanel.d.ts.map +1 -0
  23. package/dist/panels/components/DependencyInfoModal.d.ts +8 -0
  24. package/dist/panels/components/DependencyInfoModal.d.ts.map +1 -0
  25. package/dist/panels/components/DependencyRow.d.ts +8 -0
  26. package/dist/panels/components/DependencyRow.d.ts.map +1 -0
  27. package/dist/panels/components/EmptyDependencies.d.ts +7 -0
  28. package/dist/panels/components/EmptyDependencies.d.ts.map +1 -0
  29. package/dist/panels/components/FilterBar.d.ts +19 -0
  30. package/dist/panels/components/FilterBar.d.ts.map +1 -0
  31. package/dist/panels/components/InheritedConfigIndicator.d.ts +27 -0
  32. package/dist/panels/components/InheritedConfigIndicator.d.ts.map +1 -0
  33. package/dist/panels/components/LensReadinessSection.d.ts +8 -0
  34. package/dist/panels/components/LensReadinessSection.d.ts.map +1 -0
  35. package/dist/panels/components/OrchestratorBadge.d.ts +11 -0
  36. package/dist/panels/components/OrchestratorBadge.d.ts.map +1 -0
  37. package/dist/panels/components/OtherScriptsSection.d.ts +9 -0
  38. package/dist/panels/components/OtherScriptsSection.d.ts.map +1 -0
  39. package/dist/panels/components/PackageDetailCard.d.ts +18 -0
  40. package/dist/panels/components/PackageDetailCard.d.ts.map +1 -0
  41. package/dist/panels/components/PackageLoadingGraph.d.ts +3 -0
  42. package/dist/panels/components/PackageLoadingGraph.d.ts.map +1 -0
  43. package/dist/panels/components/PackageManagerIcon.d.ts +10 -0
  44. package/dist/panels/components/PackageManagerIcon.d.ts.map +1 -0
  45. package/dist/panels/components/PackageSummaryCard.d.ts +10 -0
  46. package/dist/panels/components/PackageSummaryCard.d.ts.map +1 -0
  47. package/dist/panels/components/index.d.ts +11 -0
  48. package/dist/panels/components/index.d.ts.map +1 -0
  49. package/dist/panels/dependency-graph/DependencyGraphPanel.d.ts +20 -0
  50. package/dist/panels/dependency-graph/DependencyGraphPanel.d.ts.map +1 -0
  51. package/dist/panels/dependency-graph/dependencyToCanvas.d.ts +20 -0
  52. package/dist/panels/dependency-graph/dependencyToCanvas.d.ts.map +1 -0
  53. package/dist/panels/dependency-graph/forceLayout.d.ts +38 -0
  54. package/dist/panels/dependency-graph/forceLayout.d.ts.map +1 -0
  55. package/dist/panels/dependency-graph/index.d.ts +5 -0
  56. package/dist/panels/dependency-graph/index.d.ts.map +1 -0
  57. package/dist/panels/overworld-map/BuildingSizeTest.d.ts +11 -0
  58. package/dist/panels/overworld-map/BuildingSizeTest.d.ts.map +1 -0
  59. package/dist/panels/overworld-map/LayoutEngineTest.d.ts +24 -0
  60. package/dist/panels/overworld-map/LayoutEngineTest.d.ts.map +1 -0
  61. package/dist/panels/overworld-map/LicenseSignTest.d.ts +7 -0
  62. package/dist/panels/overworld-map/LicenseSignTest.d.ts.map +1 -0
  63. package/dist/panels/overworld-map/OverworldMapPanel.d.ts +62 -0
  64. package/dist/panels/overworld-map/OverworldMapPanel.d.ts.map +1 -0
  65. package/dist/panels/overworld-map/PackageExpansionTest.d.ts +25 -0
  66. package/dist/panels/overworld-map/PackageExpansionTest.d.ts.map +1 -0
  67. package/dist/panels/overworld-map/RegionEditingTest.d.ts +10 -0
  68. package/dist/panels/overworld-map/RegionEditingTest.d.ts.map +1 -0
  69. package/dist/panels/overworld-map/collaboratorDecoration.d.ts +38 -0
  70. package/dist/panels/overworld-map/collaboratorDecoration.d.ts.map +1 -0
  71. package/dist/panels/overworld-map/components/IsometricInteractionManager.d.ts +159 -0
  72. package/dist/panels/overworld-map/components/IsometricInteractionManager.d.ts.map +1 -0
  73. package/dist/panels/overworld-map/components/IsometricPathManager.d.ts +50 -0
  74. package/dist/panels/overworld-map/components/IsometricPathManager.d.ts.map +1 -0
  75. package/dist/panels/overworld-map/components/IsometricPixiCanvas.d.ts +88 -0
  76. package/dist/panels/overworld-map/components/IsometricPixiCanvas.d.ts.map +1 -0
  77. package/dist/panels/overworld-map/components/IsometricRenderer.d.ts +141 -0
  78. package/dist/panels/overworld-map/components/IsometricRenderer.d.ts.map +1 -0
  79. package/dist/panels/overworld-map/components/RegionTracker.d.ts +62 -0
  80. package/dist/panels/overworld-map/components/RegionTracker.d.ts.map +1 -0
  81. package/dist/panels/overworld-map/components/RepoSprite.d.ts +47 -0
  82. package/dist/panels/overworld-map/components/RepoSprite.d.ts.map +1 -0
  83. package/dist/panels/overworld-map/components/buildingSpriteGenerator.d.ts +19 -0
  84. package/dist/panels/overworld-map/components/buildingSpriteGenerator.d.ts.map +1 -0
  85. package/dist/panels/overworld-map/components/collaboratorDecorationSprites.d.ts +25 -0
  86. package/dist/panels/overworld-map/components/collaboratorDecorationSprites.d.ts.map +1 -0
  87. package/dist/panels/overworld-map/components/licenseSignSprites.d.ts +122 -0
  88. package/dist/panels/overworld-map/components/licenseSignSprites.d.ts.map +1 -0
  89. package/dist/panels/overworld-map/components/starDecorationSprites.d.ts +18 -0
  90. package/dist/panels/overworld-map/components/starDecorationSprites.d.ts.map +1 -0
  91. package/dist/panels/overworld-map/genericMapper.d.ts +81 -0
  92. package/dist/panels/overworld-map/genericMapper.d.ts.map +1 -0
  93. package/dist/panels/overworld-map/index.d.ts +13 -0
  94. package/dist/panels/overworld-map/index.d.ts.map +1 -0
  95. package/dist/panels/overworld-map/isometricUtils.d.ts +150 -0
  96. package/dist/panels/overworld-map/isometricUtils.d.ts.map +1 -0
  97. package/dist/panels/overworld-map/packageExpansion.d.ts +15 -0
  98. package/dist/panels/overworld-map/packageExpansion.d.ts.map +1 -0
  99. package/dist/panels/overworld-map/spriteLayoutEngine.d.ts +103 -0
  100. package/dist/panels/overworld-map/spriteLayoutEngine.d.ts.map +1 -0
  101. package/dist/panels/overworld-map/starDecoration.d.ts +37 -0
  102. package/dist/panels/overworld-map/starDecoration.d.ts.map +1 -0
  103. package/dist/panels/overworld-map/test-setup.d.ts +6 -0
  104. package/dist/panels/overworld-map/test-setup.d.ts.map +1 -0
  105. package/dist/panels/overworld-map/types.d.ts +228 -0
  106. package/dist/panels/overworld-map/types.d.ts.map +1 -0
  107. package/dist/panels.bundle.js +32 -31
  108. package/dist/services/LocalSearchService.d.ts +70 -0
  109. package/dist/services/LocalSearchService.d.ts.map +1 -0
  110. package/dist/tools/index.d.ts +32 -0
  111. package/dist/tools/index.d.ts.map +1 -0
  112. package/dist/tools.bundle.js +106 -0
  113. package/dist/types/composition.d.ts +22 -0
  114. package/dist/types/composition.d.ts.map +1 -0
  115. package/dist/types/dependencies.d.ts +26 -0
  116. package/dist/types/dependencies.d.ts.map +1 -0
  117. package/dist/types/index.d.ts +94 -0
  118. package/dist/types/index.d.ts.map +1 -0
  119. package/dist/utils/envParser.d.ts +29 -0
  120. package/dist/utils/envParser.d.ts.map +1 -0
  121. package/dist/utils/licenseColors.d.ts +13 -0
  122. package/dist/utils/licenseColors.d.ts.map +1 -0
  123. package/dist/utils/repositoryAging.d.ts +26 -0
  124. package/dist/utils/repositoryAging.d.ts.map +1 -0
  125. package/dist/utils/repositoryScaling.d.ts +40 -0
  126. package/dist/utils/repositoryScaling.d.ts.map +1 -0
  127. package/dist/webworkerAll-Ez5pUZRt.js +3 -0
  128. package/dist/webworkerAll-Ez5pUZRt.js.map +1 -0
  129. package/package.json +1 -1
  130. package/dist/BufferResource-DME1VWVJ.js +0 -593
  131. package/dist/BufferResource-DME1VWVJ.js.map +0 -1
  132. package/dist/CanvasRenderer-Md8Ayshs.js +0 -1525
  133. package/dist/CanvasRenderer-Md8Ayshs.js.map +0 -1
  134. package/dist/Filter-Bi2t_gmW.js +0 -81
  135. package/dist/Filter-Bi2t_gmW.js.map +0 -1
  136. package/dist/RenderTargetSystem-D98tiHim.js +0 -3046
  137. package/dist/RenderTargetSystem-D98tiHim.js.map +0 -1
  138. package/dist/WebGLRenderer-2YtxQhbh.js +0 -3884
  139. package/dist/WebGLRenderer-2YtxQhbh.js.map +0 -1
  140. package/dist/WebGPURenderer-kS6gO2Xc.js +0 -2142
  141. package/dist/WebGPURenderer-kS6gO2Xc.js.map +0 -1
  142. package/dist/browserAll-TZZf5l7B.js +0 -2687
  143. package/dist/browserAll-TZZf5l7B.js.map +0 -1
  144. package/dist/init-CfSmqCnm.js +0 -670
  145. package/dist/init-CfSmqCnm.js.map +0 -1
  146. package/dist/webworkerAll-TcJuZTza.js +0 -3
  147. package/dist/webworkerAll-TcJuZTza.js.map +0 -1
@@ -1,3046 +0,0 @@
1
- import { Z as TextureMatrix, U as UniformGroup, M as Matrix, G as GpuProgram, b as GlProgram, a as State, _ as DefaultBatcher, E as ExtensionType, f as extensions, $ as BigPool, a0 as getGlobalBounds, e as Bounds, T as TexturePool, R as RendererType, a1 as FilterEffect, a2 as Sprite, c as Texture, h as STENCIL_MODES, N as CLEAR, a3 as BatchableSprite, w as warn, a4 as RenderGroup, a5 as multiplyColors, a6 as UPDATE_VISIBLE, a7 as UPDATE_COLOR, a8 as UPDATE_BLEND, H as Container, a9 as TextureStyle, C as Color, D as DOMAdapter, O as TextureSource, aa as Rectangle, ab as getLocalBounds, P as Point, ac as color32BitToUniform, B as BindGroup, x as Ticker, ad as VERSION, ae as deprecation, l as uid$1, v as CanvasSource, af as GlobalResourceRegistry, ag as v8_0_0, ah as RendererInitHook, ai as SystemRunner } from "./index-pPFTSf2O.js";
2
- import { F as Filter } from "./Filter-Bi2t_gmW.js";
3
- var fragment = "in vec2 vMaskCoord;\nin vec2 vTextureCoord;\n\nuniform sampler2D uTexture;\nuniform sampler2D uMaskTexture;\n\nuniform float uAlpha;\nuniform vec4 uMaskClamp;\nuniform float uInverse;\n\nout vec4 finalColor;\n\nvoid main(void)\n{\n float clip = step(3.5,\n step(uMaskClamp.x, vMaskCoord.x) +\n step(uMaskClamp.y, vMaskCoord.y) +\n step(vMaskCoord.x, uMaskClamp.z) +\n step(vMaskCoord.y, uMaskClamp.w));\n\n // TODO look into why this is needed\n float npmAlpha = uAlpha;\n vec4 original = texture(uTexture, vTextureCoord);\n vec4 masky = texture(uMaskTexture, vMaskCoord);\n float alphaMul = 1.0 - npmAlpha * (1.0 - masky.a);\n\n float a = alphaMul * masky.r * npmAlpha * clip;\n\n if (uInverse == 1.0) {\n a = 1.0 - a;\n }\n\n finalColor = original * a;\n}\n";
4
- var vertex = "in vec2 aPosition;\n\nout vec2 vTextureCoord;\nout vec2 vMaskCoord;\n\n\nuniform vec4 uInputSize;\nuniform vec4 uOutputFrame;\nuniform vec4 uOutputTexture;\nuniform mat3 uFilterMatrix;\n\nvec4 filterVertexPosition( vec2 aPosition )\n{\n vec2 position = aPosition * uOutputFrame.zw + uOutputFrame.xy;\n \n position.x = position.x * (2.0 / uOutputTexture.x) - 1.0;\n position.y = position.y * (2.0*uOutputTexture.z / uOutputTexture.y) - uOutputTexture.z;\n\n return vec4(position, 0.0, 1.0);\n}\n\nvec2 filterTextureCoord( vec2 aPosition )\n{\n return aPosition * (uOutputFrame.zw * uInputSize.zw);\n}\n\nvec2 getFilterCoord( vec2 aPosition )\n{\n return ( uFilterMatrix * vec3( filterTextureCoord(aPosition), 1.0) ).xy;\n} \n\nvoid main(void)\n{\n gl_Position = filterVertexPosition(aPosition);\n vTextureCoord = filterTextureCoord(aPosition);\n vMaskCoord = getFilterCoord(aPosition);\n}\n";
5
- var source = "struct GlobalFilterUniforms {\n uInputSize:vec4<f32>,\n uInputPixel:vec4<f32>,\n uInputClamp:vec4<f32>,\n uOutputFrame:vec4<f32>,\n uGlobalFrame:vec4<f32>,\n uOutputTexture:vec4<f32>,\n};\n\nstruct MaskUniforms {\n uFilterMatrix:mat3x3<f32>,\n uMaskClamp:vec4<f32>,\n uAlpha:f32,\n uInverse:f32,\n};\n\n@group(0) @binding(0) var<uniform> gfu: GlobalFilterUniforms;\n@group(0) @binding(1) var uTexture: texture_2d<f32>;\n@group(0) @binding(2) var uSampler : sampler;\n\n@group(1) @binding(0) var<uniform> filterUniforms : MaskUniforms;\n@group(1) @binding(1) var uMaskTexture: texture_2d<f32>;\n\nstruct VSOutput {\n @builtin(position) position: vec4<f32>,\n @location(0) uv : vec2<f32>,\n @location(1) filterUv : vec2<f32>,\n};\n\nfn filterVertexPosition(aPosition:vec2<f32>) -> vec4<f32>\n{\n var position = aPosition * gfu.uOutputFrame.zw + gfu.uOutputFrame.xy;\n\n position.x = position.x * (2.0 / gfu.uOutputTexture.x) - 1.0;\n position.y = position.y * (2.0*gfu.uOutputTexture.z / gfu.uOutputTexture.y) - gfu.uOutputTexture.z;\n\n return vec4(position, 0.0, 1.0);\n}\n\nfn filterTextureCoord( aPosition:vec2<f32> ) -> vec2<f32>\n{\n return aPosition * (gfu.uOutputFrame.zw * gfu.uInputSize.zw);\n}\n\nfn globalTextureCoord( aPosition:vec2<f32> ) -> vec2<f32>\n{\n return (aPosition.xy / gfu.uGlobalFrame.zw) + (gfu.uGlobalFrame.xy / gfu.uGlobalFrame.zw);\n}\n\nfn getFilterCoord(aPosition:vec2<f32> ) -> vec2<f32>\n{\n return ( filterUniforms.uFilterMatrix * vec3( filterTextureCoord(aPosition), 1.0) ).xy;\n}\n\nfn getSize() -> vec2<f32>\n{\n return gfu.uGlobalFrame.zw;\n}\n\n@vertex\nfn mainVertex(\n @location(0) aPosition : vec2<f32>,\n) -> VSOutput {\n return VSOutput(\n filterVertexPosition(aPosition),\n filterTextureCoord(aPosition),\n getFilterCoord(aPosition)\n );\n}\n\n@fragment\nfn mainFragment(\n @location(0) uv: vec2<f32>,\n @location(1) filterUv: vec2<f32>,\n @builtin(position) position: vec4<f32>\n) -> @location(0) vec4<f32> {\n\n var maskClamp = filterUniforms.uMaskClamp;\n var uAlpha = filterUniforms.uAlpha;\n\n var clip = step(3.5,\n step(maskClamp.x, filterUv.x) +\n step(maskClamp.y, filterUv.y) +\n step(filterUv.x, maskClamp.z) +\n step(filterUv.y, maskClamp.w));\n\n var mask = textureSample(uMaskTexture, uSampler, filterUv);\n var source = textureSample(uTexture, uSampler, uv);\n var alphaMul = 1.0 - uAlpha * (1.0 - mask.a);\n\n var a: f32 = alphaMul * mask.r * uAlpha * clip;\n\n if (filterUniforms.uInverse == 1.0) {\n a = 1.0 - a;\n }\n\n return source * a;\n}\n";
6
- class MaskFilter extends Filter {
7
- constructor(options) {
8
- const { sprite, ...rest } = options;
9
- const textureMatrix = new TextureMatrix(sprite.texture);
10
- const filterUniforms = new UniformGroup({
11
- uFilterMatrix: { value: new Matrix(), type: "mat3x3<f32>" },
12
- uMaskClamp: { value: textureMatrix.uClampFrame, type: "vec4<f32>" },
13
- uAlpha: { value: 1, type: "f32" },
14
- uInverse: { value: options.inverse ? 1 : 0, type: "f32" }
15
- });
16
- const gpuProgram = GpuProgram.from({
17
- vertex: {
18
- source,
19
- entryPoint: "mainVertex"
20
- },
21
- fragment: {
22
- source,
23
- entryPoint: "mainFragment"
24
- }
25
- });
26
- const glProgram = GlProgram.from({
27
- vertex,
28
- fragment,
29
- name: "mask-filter"
30
- });
31
- super({
32
- ...rest,
33
- gpuProgram,
34
- glProgram,
35
- clipToViewport: false,
36
- resources: {
37
- filterUniforms,
38
- uMaskTexture: sprite.texture.source
39
- }
40
- });
41
- this.sprite = sprite;
42
- this._textureMatrix = textureMatrix;
43
- }
44
- set inverse(value) {
45
- this.resources.filterUniforms.uniforms.uInverse = value ? 1 : 0;
46
- }
47
- get inverse() {
48
- return this.resources.filterUniforms.uniforms.uInverse === 1;
49
- }
50
- apply(filterManager, input, output, clearMode) {
51
- this._textureMatrix.texture = this.sprite.texture;
52
- filterManager.calculateSpriteMatrix(
53
- this.resources.filterUniforms.uniforms.uFilterMatrix,
54
- this.sprite
55
- ).prepend(this._textureMatrix.mapCoord);
56
- this.resources.uMaskTexture = this.sprite.texture.source;
57
- filterManager.applyFilter(this, input, output, clearMode);
58
- }
59
- }
60
- const _BatcherPipe = class _BatcherPipe2 {
61
- constructor(renderer, adaptor) {
62
- var _a, _b;
63
- this.state = State.for2d();
64
- this._batchersByInstructionSet = /* @__PURE__ */ Object.create(null);
65
- this._activeBatches = /* @__PURE__ */ Object.create(null);
66
- this.renderer = renderer;
67
- this._adaptor = adaptor;
68
- (_b = (_a = this._adaptor).init) == null ? void 0 : _b.call(_a, this);
69
- }
70
- static getBatcher(name) {
71
- return new this._availableBatchers[name]();
72
- }
73
- buildStart(instructionSet) {
74
- let batchers = this._batchersByInstructionSet[instructionSet.uid];
75
- if (!batchers) {
76
- batchers = this._batchersByInstructionSet[instructionSet.uid] = /* @__PURE__ */ Object.create(null);
77
- batchers.default || (batchers.default = new DefaultBatcher({
78
- maxTextures: this.renderer.limits.maxBatchableTextures
79
- }));
80
- }
81
- this._activeBatches = batchers;
82
- this._activeBatch = this._activeBatches.default;
83
- for (const i in this._activeBatches) {
84
- this._activeBatches[i].begin();
85
- }
86
- }
87
- addToBatch(batchableObject, instructionSet) {
88
- if (this._activeBatch.name !== batchableObject.batcherName) {
89
- this._activeBatch.break(instructionSet);
90
- let batch = this._activeBatches[batchableObject.batcherName];
91
- if (!batch) {
92
- batch = this._activeBatches[batchableObject.batcherName] = _BatcherPipe2.getBatcher(batchableObject.batcherName);
93
- batch.begin();
94
- }
95
- this._activeBatch = batch;
96
- }
97
- this._activeBatch.add(batchableObject);
98
- }
99
- break(instructionSet) {
100
- this._activeBatch.break(instructionSet);
101
- }
102
- buildEnd(instructionSet) {
103
- this._activeBatch.break(instructionSet);
104
- const batches = this._activeBatches;
105
- for (const i in batches) {
106
- const batch = batches[i];
107
- const geometry = batch.geometry;
108
- geometry.indexBuffer.setDataWithSize(batch.indexBuffer, batch.indexSize, true);
109
- geometry.buffers[0].setDataWithSize(batch.attributeBuffer.float32View, batch.attributeSize, false);
110
- }
111
- }
112
- upload(instructionSet) {
113
- const batchers = this._batchersByInstructionSet[instructionSet.uid];
114
- for (const i in batchers) {
115
- const batcher = batchers[i];
116
- const geometry = batcher.geometry;
117
- if (batcher.dirty) {
118
- batcher.dirty = false;
119
- geometry.buffers[0].update(batcher.attributeSize * 4);
120
- }
121
- }
122
- }
123
- execute(batch) {
124
- if (batch.action === "startBatch") {
125
- const batcher = batch.batcher;
126
- const geometry = batcher.geometry;
127
- const shader = batcher.shader;
128
- this._adaptor.start(this, geometry, shader);
129
- }
130
- this._adaptor.execute(this, batch);
131
- }
132
- destroy() {
133
- this.state = null;
134
- this.renderer = null;
135
- this._adaptor = null;
136
- for (const i in this._activeBatches) {
137
- this._activeBatches[i].destroy();
138
- }
139
- this._activeBatches = null;
140
- }
141
- };
142
- _BatcherPipe.extension = {
143
- type: [
144
- ExtensionType.WebGLPipes,
145
- ExtensionType.WebGPUPipes,
146
- ExtensionType.CanvasPipes
147
- ],
148
- name: "batch"
149
- };
150
- _BatcherPipe._availableBatchers = /* @__PURE__ */ Object.create(null);
151
- let BatcherPipe = _BatcherPipe;
152
- extensions.handleByMap(ExtensionType.Batcher, BatcherPipe._availableBatchers);
153
- extensions.add(DefaultBatcher);
154
- const tempBounds$1 = new Bounds();
155
- class AlphaMaskEffect extends FilterEffect {
156
- constructor() {
157
- super();
158
- this.filters = [new MaskFilter({
159
- sprite: new Sprite(Texture.EMPTY),
160
- inverse: false,
161
- resolution: "inherit",
162
- antialias: "inherit"
163
- })];
164
- }
165
- get sprite() {
166
- return this.filters[0].sprite;
167
- }
168
- set sprite(value) {
169
- this.filters[0].sprite = value;
170
- }
171
- get inverse() {
172
- return this.filters[0].inverse;
173
- }
174
- set inverse(value) {
175
- this.filters[0].inverse = value;
176
- }
177
- }
178
- class AlphaMaskPipe {
179
- constructor(renderer) {
180
- this._activeMaskStage = [];
181
- this._renderer = renderer;
182
- }
183
- push(mask, maskedContainer, instructionSet) {
184
- const renderer = this._renderer;
185
- renderer.renderPipes.batch.break(instructionSet);
186
- instructionSet.add({
187
- renderPipeId: "alphaMask",
188
- action: "pushMaskBegin",
189
- mask,
190
- inverse: maskedContainer._maskOptions.inverse,
191
- canBundle: false,
192
- maskedContainer
193
- });
194
- mask.inverse = maskedContainer._maskOptions.inverse;
195
- if (mask.renderMaskToTexture) {
196
- const maskContainer = mask.mask;
197
- maskContainer.includeInBuild = true;
198
- maskContainer.collectRenderables(
199
- instructionSet,
200
- renderer,
201
- null
202
- );
203
- maskContainer.includeInBuild = false;
204
- }
205
- renderer.renderPipes.batch.break(instructionSet);
206
- instructionSet.add({
207
- renderPipeId: "alphaMask",
208
- action: "pushMaskEnd",
209
- mask,
210
- maskedContainer,
211
- inverse: maskedContainer._maskOptions.inverse,
212
- canBundle: false
213
- });
214
- }
215
- pop(mask, _maskedContainer, instructionSet) {
216
- const renderer = this._renderer;
217
- renderer.renderPipes.batch.break(instructionSet);
218
- instructionSet.add({
219
- renderPipeId: "alphaMask",
220
- action: "popMaskEnd",
221
- mask,
222
- inverse: _maskedContainer._maskOptions.inverse,
223
- canBundle: false
224
- });
225
- }
226
- execute(instruction) {
227
- const renderer = this._renderer;
228
- const renderMask = instruction.mask.renderMaskToTexture;
229
- if (instruction.action === "pushMaskBegin") {
230
- const filterEffect = BigPool.get(AlphaMaskEffect);
231
- filterEffect.inverse = instruction.inverse;
232
- if (renderMask) {
233
- instruction.mask.mask.measurable = true;
234
- const bounds = getGlobalBounds(instruction.mask.mask, true, tempBounds$1);
235
- instruction.mask.mask.measurable = false;
236
- bounds.ceil();
237
- const colorTextureSource = renderer.renderTarget.renderTarget.colorTexture.source;
238
- const filterTexture = TexturePool.getOptimalTexture(
239
- bounds.width,
240
- bounds.height,
241
- colorTextureSource._resolution,
242
- colorTextureSource.antialias
243
- );
244
- renderer.renderTarget.push(filterTexture, true);
245
- renderer.globalUniforms.push({
246
- offset: bounds,
247
- worldColor: 4294967295
248
- });
249
- const sprite = filterEffect.sprite;
250
- sprite.texture = filterTexture;
251
- sprite.worldTransform.tx = bounds.minX;
252
- sprite.worldTransform.ty = bounds.minY;
253
- this._activeMaskStage.push({
254
- filterEffect,
255
- maskedContainer: instruction.maskedContainer,
256
- filterTexture
257
- });
258
- } else {
259
- filterEffect.sprite = instruction.mask.mask;
260
- this._activeMaskStage.push({
261
- filterEffect,
262
- maskedContainer: instruction.maskedContainer
263
- });
264
- }
265
- } else if (instruction.action === "pushMaskEnd") {
266
- const maskData = this._activeMaskStage[this._activeMaskStage.length - 1];
267
- if (renderMask) {
268
- if (renderer.type === RendererType.WEBGL) {
269
- renderer.renderTarget.finishRenderPass();
270
- }
271
- renderer.renderTarget.pop();
272
- renderer.globalUniforms.pop();
273
- }
274
- renderer.filter.push({
275
- renderPipeId: "filter",
276
- action: "pushFilter",
277
- container: maskData.maskedContainer,
278
- filterEffect: maskData.filterEffect,
279
- canBundle: false
280
- });
281
- } else if (instruction.action === "popMaskEnd") {
282
- renderer.filter.pop();
283
- const maskData = this._activeMaskStage.pop();
284
- if (renderMask) {
285
- TexturePool.returnTexture(maskData.filterTexture);
286
- }
287
- BigPool.return(maskData.filterEffect);
288
- }
289
- }
290
- destroy() {
291
- this._renderer = null;
292
- this._activeMaskStage = null;
293
- }
294
- }
295
- AlphaMaskPipe.extension = {
296
- type: [
297
- ExtensionType.WebGLPipes,
298
- ExtensionType.WebGPUPipes,
299
- ExtensionType.CanvasPipes
300
- ],
301
- name: "alphaMask"
302
- };
303
- class ColorMaskPipe {
304
- constructor(renderer) {
305
- this._colorStack = [];
306
- this._colorStackIndex = 0;
307
- this._currentColor = 0;
308
- this._renderer = renderer;
309
- }
310
- buildStart() {
311
- this._colorStack[0] = 15;
312
- this._colorStackIndex = 1;
313
- this._currentColor = 15;
314
- }
315
- push(mask, _container, instructionSet) {
316
- const renderer = this._renderer;
317
- renderer.renderPipes.batch.break(instructionSet);
318
- const colorStack = this._colorStack;
319
- colorStack[this._colorStackIndex] = colorStack[this._colorStackIndex - 1] & mask.mask;
320
- const currentColor = this._colorStack[this._colorStackIndex];
321
- if (currentColor !== this._currentColor) {
322
- this._currentColor = currentColor;
323
- instructionSet.add({
324
- renderPipeId: "colorMask",
325
- colorMask: currentColor,
326
- canBundle: false
327
- });
328
- }
329
- this._colorStackIndex++;
330
- }
331
- pop(_mask, _container, instructionSet) {
332
- const renderer = this._renderer;
333
- renderer.renderPipes.batch.break(instructionSet);
334
- const colorStack = this._colorStack;
335
- this._colorStackIndex--;
336
- const currentColor = colorStack[this._colorStackIndex - 1];
337
- if (currentColor !== this._currentColor) {
338
- this._currentColor = currentColor;
339
- instructionSet.add({
340
- renderPipeId: "colorMask",
341
- colorMask: currentColor,
342
- canBundle: false
343
- });
344
- }
345
- }
346
- execute(instruction) {
347
- const renderer = this._renderer;
348
- renderer.colorMask.setMask(instruction.colorMask);
349
- }
350
- destroy() {
351
- this._renderer = null;
352
- this._colorStack = null;
353
- }
354
- }
355
- ColorMaskPipe.extension = {
356
- type: [
357
- ExtensionType.WebGLPipes,
358
- ExtensionType.WebGPUPipes
359
- ],
360
- name: "colorMask"
361
- };
362
- class StencilMaskPipe {
363
- constructor(renderer) {
364
- this._maskStackHash = {};
365
- this._maskHash = /* @__PURE__ */ new WeakMap();
366
- this._renderer = renderer;
367
- }
368
- push(mask, _container, instructionSet) {
369
- var _a;
370
- const effect = mask;
371
- const renderer = this._renderer;
372
- renderer.renderPipes.batch.break(instructionSet);
373
- renderer.renderPipes.blendMode.setBlendMode(effect.mask, "none", instructionSet);
374
- instructionSet.add({
375
- renderPipeId: "stencilMask",
376
- action: "pushMaskBegin",
377
- mask,
378
- inverse: _container._maskOptions.inverse,
379
- canBundle: false
380
- });
381
- const maskContainer = effect.mask;
382
- maskContainer.includeInBuild = true;
383
- if (!this._maskHash.has(effect)) {
384
- this._maskHash.set(effect, {
385
- instructionsStart: 0,
386
- instructionsLength: 0
387
- });
388
- }
389
- const maskData = this._maskHash.get(effect);
390
- maskData.instructionsStart = instructionSet.instructionSize;
391
- maskContainer.collectRenderables(
392
- instructionSet,
393
- renderer,
394
- null
395
- );
396
- maskContainer.includeInBuild = false;
397
- renderer.renderPipes.batch.break(instructionSet);
398
- instructionSet.add({
399
- renderPipeId: "stencilMask",
400
- action: "pushMaskEnd",
401
- mask,
402
- inverse: _container._maskOptions.inverse,
403
- canBundle: false
404
- });
405
- const instructionsLength = instructionSet.instructionSize - maskData.instructionsStart - 1;
406
- maskData.instructionsLength = instructionsLength;
407
- const renderTargetUid = renderer.renderTarget.renderTarget.uid;
408
- (_a = this._maskStackHash)[renderTargetUid] ?? (_a[renderTargetUid] = 0);
409
- }
410
- pop(mask, _container, instructionSet) {
411
- const effect = mask;
412
- const renderer = this._renderer;
413
- renderer.renderPipes.batch.break(instructionSet);
414
- renderer.renderPipes.blendMode.setBlendMode(effect.mask, "none", instructionSet);
415
- instructionSet.add({
416
- renderPipeId: "stencilMask",
417
- action: "popMaskBegin",
418
- inverse: _container._maskOptions.inverse,
419
- canBundle: false
420
- });
421
- const maskData = this._maskHash.get(mask);
422
- for (let i = 0; i < maskData.instructionsLength; i++) {
423
- instructionSet.instructions[instructionSet.instructionSize++] = instructionSet.instructions[maskData.instructionsStart++];
424
- }
425
- instructionSet.add({
426
- renderPipeId: "stencilMask",
427
- action: "popMaskEnd",
428
- canBundle: false
429
- });
430
- }
431
- execute(instruction) {
432
- var _a;
433
- const renderer = this._renderer;
434
- const gpuRenderer = renderer;
435
- const renderTargetUid = renderer.renderTarget.renderTarget.uid;
436
- let maskStackIndex = (_a = this._maskStackHash)[renderTargetUid] ?? (_a[renderTargetUid] = 0);
437
- if (instruction.action === "pushMaskBegin") {
438
- gpuRenderer.renderTarget.ensureDepthStencil();
439
- gpuRenderer.stencil.setStencilMode(STENCIL_MODES.RENDERING_MASK_ADD, maskStackIndex);
440
- maskStackIndex++;
441
- gpuRenderer.colorMask.setMask(0);
442
- } else if (instruction.action === "pushMaskEnd") {
443
- if (instruction.inverse) {
444
- gpuRenderer.stencil.setStencilMode(STENCIL_MODES.INVERSE_MASK_ACTIVE, maskStackIndex);
445
- } else {
446
- gpuRenderer.stencil.setStencilMode(STENCIL_MODES.MASK_ACTIVE, maskStackIndex);
447
- }
448
- gpuRenderer.colorMask.setMask(15);
449
- } else if (instruction.action === "popMaskBegin") {
450
- gpuRenderer.colorMask.setMask(0);
451
- if (maskStackIndex !== 0) {
452
- gpuRenderer.stencil.setStencilMode(STENCIL_MODES.RENDERING_MASK_REMOVE, maskStackIndex);
453
- } else {
454
- gpuRenderer.renderTarget.clear(null, CLEAR.STENCIL);
455
- gpuRenderer.stencil.setStencilMode(STENCIL_MODES.DISABLED, maskStackIndex);
456
- }
457
- maskStackIndex--;
458
- } else if (instruction.action === "popMaskEnd") {
459
- if (instruction.inverse) {
460
- gpuRenderer.stencil.setStencilMode(STENCIL_MODES.INVERSE_MASK_ACTIVE, maskStackIndex);
461
- } else {
462
- gpuRenderer.stencil.setStencilMode(STENCIL_MODES.MASK_ACTIVE, maskStackIndex);
463
- }
464
- gpuRenderer.colorMask.setMask(15);
465
- }
466
- this._maskStackHash[renderTargetUid] = maskStackIndex;
467
- }
468
- destroy() {
469
- this._renderer = null;
470
- this._maskStackHash = null;
471
- this._maskHash = null;
472
- }
473
- }
474
- StencilMaskPipe.extension = {
475
- type: [
476
- ExtensionType.WebGLPipes,
477
- ExtensionType.WebGPUPipes
478
- ],
479
- name: "stencilMask"
480
- };
481
- class CustomRenderPipe {
482
- constructor(renderer) {
483
- this._renderer = renderer;
484
- }
485
- updateRenderable() {
486
- }
487
- destroyRenderable() {
488
- }
489
- validateRenderable() {
490
- return false;
491
- }
492
- addRenderable(container, instructionSet) {
493
- this._renderer.renderPipes.batch.break(instructionSet);
494
- instructionSet.add(container);
495
- }
496
- execute(container) {
497
- if (!container.isRenderable) return;
498
- container.render(this._renderer);
499
- }
500
- destroy() {
501
- this._renderer = null;
502
- }
503
- }
504
- CustomRenderPipe.extension = {
505
- type: [
506
- ExtensionType.WebGLPipes,
507
- ExtensionType.WebGPUPipes,
508
- ExtensionType.CanvasPipes
509
- ],
510
- name: "customRender"
511
- };
512
- function executeInstructions(renderGroup, renderer) {
513
- const instructionSet = renderGroup.instructionSet;
514
- const instructions = instructionSet.instructions;
515
- for (let i = 0; i < instructionSet.instructionSize; i++) {
516
- const instruction = instructions[i];
517
- renderer[instruction.renderPipeId].execute(instruction);
518
- }
519
- }
520
- class RenderGroupPipe {
521
- constructor(renderer) {
522
- this._renderer = renderer;
523
- }
524
- addRenderGroup(renderGroup, instructionSet) {
525
- if (renderGroup.isCachedAsTexture) {
526
- this._addRenderableCacheAsTexture(renderGroup, instructionSet);
527
- } else {
528
- this._addRenderableDirect(renderGroup, instructionSet);
529
- }
530
- }
531
- execute(renderGroup) {
532
- if (!renderGroup.isRenderable) return;
533
- if (renderGroup.isCachedAsTexture) {
534
- this._executeCacheAsTexture(renderGroup);
535
- } else {
536
- this._executeDirect(renderGroup);
537
- }
538
- }
539
- destroy() {
540
- this._renderer = null;
541
- }
542
- _addRenderableDirect(renderGroup, instructionSet) {
543
- this._renderer.renderPipes.batch.break(instructionSet);
544
- if (renderGroup._batchableRenderGroup) {
545
- BigPool.return(renderGroup._batchableRenderGroup);
546
- renderGroup._batchableRenderGroup = null;
547
- }
548
- instructionSet.add(renderGroup);
549
- }
550
- _addRenderableCacheAsTexture(renderGroup, instructionSet) {
551
- const batchableRenderGroup = renderGroup._batchableRenderGroup ?? (renderGroup._batchableRenderGroup = BigPool.get(BatchableSprite));
552
- batchableRenderGroup.renderable = renderGroup.root;
553
- batchableRenderGroup.transform = renderGroup.root.relativeGroupTransform;
554
- batchableRenderGroup.texture = renderGroup.texture;
555
- batchableRenderGroup.bounds = renderGroup._textureBounds;
556
- instructionSet.add(renderGroup);
557
- this._renderer.renderPipes.blendMode.pushBlendMode(renderGroup, renderGroup.root.groupBlendMode, instructionSet);
558
- this._renderer.renderPipes.batch.addToBatch(batchableRenderGroup, instructionSet);
559
- this._renderer.renderPipes.blendMode.popBlendMode(instructionSet);
560
- }
561
- _executeCacheAsTexture(renderGroup) {
562
- if (renderGroup.textureNeedsUpdate) {
563
- renderGroup.textureNeedsUpdate = false;
564
- const worldTransformMatrix = new Matrix().translate(
565
- -renderGroup._textureBounds.x,
566
- -renderGroup._textureBounds.y
567
- );
568
- this._renderer.renderTarget.push(renderGroup.texture, true, null, renderGroup.texture.frame);
569
- this._renderer.globalUniforms.push({
570
- worldTransformMatrix,
571
- worldColor: 4294967295,
572
- offset: { x: 0, y: 0 }
573
- });
574
- executeInstructions(renderGroup, this._renderer.renderPipes);
575
- this._renderer.renderTarget.finishRenderPass();
576
- this._renderer.renderTarget.pop();
577
- this._renderer.globalUniforms.pop();
578
- }
579
- renderGroup._batchableRenderGroup._batcher.updateElement(renderGroup._batchableRenderGroup);
580
- renderGroup._batchableRenderGroup._batcher.geometry.buffers[0].update();
581
- }
582
- _executeDirect(renderGroup) {
583
- this._renderer.globalUniforms.push({
584
- worldTransformMatrix: renderGroup.inverseParentTextureTransform,
585
- worldColor: renderGroup.worldColorAlpha
586
- });
587
- executeInstructions(renderGroup, this._renderer.renderPipes);
588
- this._renderer.globalUniforms.pop();
589
- }
590
- }
591
- RenderGroupPipe.extension = {
592
- type: [
593
- ExtensionType.WebGLPipes,
594
- ExtensionType.WebGPUPipes,
595
- ExtensionType.CanvasPipes
596
- ],
597
- name: "renderGroup"
598
- };
599
- class SpritePipe {
600
- constructor(renderer) {
601
- this._renderer = renderer;
602
- }
603
- addRenderable(sprite, instructionSet) {
604
- const gpuSprite = this._getGpuSprite(sprite);
605
- if (sprite.didViewUpdate) this._updateBatchableSprite(sprite, gpuSprite);
606
- this._renderer.renderPipes.batch.addToBatch(gpuSprite, instructionSet);
607
- }
608
- updateRenderable(sprite) {
609
- const gpuSprite = this._getGpuSprite(sprite);
610
- if (sprite.didViewUpdate) this._updateBatchableSprite(sprite, gpuSprite);
611
- gpuSprite._batcher.updateElement(gpuSprite);
612
- }
613
- validateRenderable(sprite) {
614
- const gpuSprite = this._getGpuSprite(sprite);
615
- return !gpuSprite._batcher.checkAndUpdateTexture(
616
- gpuSprite,
617
- sprite._texture
618
- );
619
- }
620
- _updateBatchableSprite(sprite, batchableSprite) {
621
- batchableSprite.bounds = sprite.visualBounds;
622
- batchableSprite.texture = sprite._texture;
623
- }
624
- _getGpuSprite(sprite) {
625
- return sprite._gpuData[this._renderer.uid] || this._initGPUSprite(sprite);
626
- }
627
- _initGPUSprite(sprite) {
628
- const batchableSprite = new BatchableSprite();
629
- batchableSprite.renderable = sprite;
630
- batchableSprite.transform = sprite.groupTransform;
631
- batchableSprite.texture = sprite._texture;
632
- batchableSprite.bounds = sprite.visualBounds;
633
- batchableSprite.roundPixels = this._renderer._roundPixels | sprite._roundPixels;
634
- sprite._gpuData[this._renderer.uid] = batchableSprite;
635
- return batchableSprite;
636
- }
637
- destroy() {
638
- this._renderer = null;
639
- }
640
- }
641
- SpritePipe.extension = {
642
- type: [
643
- ExtensionType.WebGLPipes,
644
- ExtensionType.WebGPUPipes,
645
- ExtensionType.CanvasPipes
646
- ],
647
- name: "sprite"
648
- };
649
- const BLEND_MODE_FILTERS = {};
650
- extensions.handle(ExtensionType.BlendMode, (value) => {
651
- if (!value.name) {
652
- throw new Error("BlendMode extension must have a name property");
653
- }
654
- BLEND_MODE_FILTERS[value.name] = value.ref;
655
- }, (value) => {
656
- delete BLEND_MODE_FILTERS[value.name];
657
- });
658
- class BlendModePipe {
659
- constructor(renderer) {
660
- this._blendModeStack = [];
661
- this._isAdvanced = false;
662
- this._filterHash = /* @__PURE__ */ Object.create(null);
663
- this._renderer = renderer;
664
- this._renderer.runners.prerender.add(this);
665
- }
666
- prerender() {
667
- this._activeBlendMode = "normal";
668
- this._isAdvanced = false;
669
- }
670
- /**
671
- * Push a blend mode onto the internal stack and apply it to the instruction set if needed.
672
- * @param renderable - The renderable or {@link RenderGroup} associated with the change.
673
- * @param blendMode - The blend mode to activate.
674
- * @param instructionSet - The instruction set being built.
675
- */
676
- pushBlendMode(renderable, blendMode, instructionSet) {
677
- this._blendModeStack.push(blendMode);
678
- this.setBlendMode(renderable, blendMode, instructionSet);
679
- }
680
- /**
681
- * Pop the last blend mode from the stack and apply the new top-of-stack mode.
682
- * @param instructionSet - The instruction set being built.
683
- */
684
- popBlendMode(instructionSet) {
685
- this._blendModeStack.pop();
686
- const blendMode = this._blendModeStack[this._activeBlendMode.length - 1] ?? "normal";
687
- this.setBlendMode(null, blendMode, instructionSet);
688
- }
689
- /**
690
- * Ensure a blend mode switch is added to the instruction set when the mode changes.
691
- * If an advanced blend mode is active, subsequent renderables will be collected so they can be
692
- * rendered within a single filter pass.
693
- * @param renderable - The renderable or {@link RenderGroup} to associate with the change, or null when unwinding.
694
- * @param blendMode - The target blend mode.
695
- * @param instructionSet - The instruction set being built.
696
- */
697
- setBlendMode(renderable, blendMode, instructionSet) {
698
- var _a;
699
- const isRenderGroup = renderable instanceof RenderGroup;
700
- if (this._activeBlendMode === blendMode) {
701
- if (this._isAdvanced && renderable && !isRenderGroup) {
702
- (_a = this._renderableList) == null ? void 0 : _a.push(renderable);
703
- }
704
- return;
705
- }
706
- if (this._isAdvanced) this._endAdvancedBlendMode(instructionSet);
707
- this._activeBlendMode = blendMode;
708
- if (!renderable) return;
709
- this._isAdvanced = !!BLEND_MODE_FILTERS[blendMode];
710
- if (this._isAdvanced) this._beginAdvancedBlendMode(renderable, instructionSet);
711
- }
712
- _beginAdvancedBlendMode(renderable, instructionSet) {
713
- this._renderer.renderPipes.batch.break(instructionSet);
714
- const blendMode = this._activeBlendMode;
715
- if (!BLEND_MODE_FILTERS[blendMode]) {
716
- warn(`Unable to assign BlendMode: '${blendMode}'. You may want to include: import 'pixi.js/advanced-blend-modes'`);
717
- return;
718
- }
719
- const filterEffect = this._ensureFilterEffect(blendMode);
720
- const isRenderGroup = renderable instanceof RenderGroup;
721
- const instruction = {
722
- renderPipeId: "filter",
723
- action: "pushFilter",
724
- filterEffect,
725
- renderables: isRenderGroup ? null : [renderable],
726
- container: isRenderGroup ? renderable.root : null,
727
- canBundle: false
728
- };
729
- this._renderableList = instruction.renderables;
730
- instructionSet.add(instruction);
731
- }
732
- _ensureFilterEffect(blendMode) {
733
- let filterEffect = this._filterHash[blendMode];
734
- if (!filterEffect) {
735
- filterEffect = this._filterHash[blendMode] = new FilterEffect();
736
- filterEffect.filters = [new BLEND_MODE_FILTERS[blendMode]()];
737
- }
738
- return filterEffect;
739
- }
740
- _endAdvancedBlendMode(instructionSet) {
741
- this._isAdvanced = false;
742
- this._renderableList = null;
743
- this._renderer.renderPipes.batch.break(instructionSet);
744
- instructionSet.add({
745
- renderPipeId: "filter",
746
- action: "popFilter",
747
- canBundle: false
748
- });
749
- }
750
- /**
751
- * called when the instruction build process is starting this will reset internally to the default blend mode
752
- * @internal
753
- */
754
- buildStart() {
755
- this._isAdvanced = false;
756
- }
757
- /**
758
- * called when the instruction build process is finished, ensuring that if there is an advanced blend mode
759
- * active, we add the final render instructions added to the instruction set
760
- * @param instructionSet - The instruction set we are adding to
761
- * @internal
762
- */
763
- buildEnd(instructionSet) {
764
- if (!this._isAdvanced) return;
765
- this._endAdvancedBlendMode(instructionSet);
766
- }
767
- /** @internal */
768
- destroy() {
769
- this._renderer = null;
770
- this._renderableList = null;
771
- for (const i in this._filterHash) {
772
- this._filterHash[i].destroy();
773
- }
774
- this._filterHash = null;
775
- }
776
- }
777
- BlendModePipe.extension = {
778
- type: [
779
- ExtensionType.WebGLPipes,
780
- ExtensionType.WebGPUPipes,
781
- ExtensionType.CanvasPipes
782
- ],
783
- name: "blendMode"
784
- };
785
- function clearList(list, index) {
786
- index || (index = 0);
787
- for (let j = index; j < list.length; j++) {
788
- if (list[j]) {
789
- list[j] = null;
790
- } else {
791
- break;
792
- }
793
- }
794
- }
795
- const tempContainer = new Container();
796
- const UPDATE_BLEND_COLOR_VISIBLE = UPDATE_VISIBLE | UPDATE_COLOR | UPDATE_BLEND;
797
- function updateRenderGroupTransforms(renderGroup, updateChildRenderGroups = false) {
798
- updateRenderGroupTransform(renderGroup);
799
- const childrenToUpdate = renderGroup.childrenToUpdate;
800
- const updateTick = renderGroup.updateTick++;
801
- for (const j in childrenToUpdate) {
802
- const renderGroupDepth = Number(j);
803
- const childrenAtDepth = childrenToUpdate[j];
804
- const list = childrenAtDepth.list;
805
- const index = childrenAtDepth.index;
806
- for (let i = 0; i < index; i++) {
807
- const child = list[i];
808
- if (child.parentRenderGroup === renderGroup && child.relativeRenderGroupDepth === renderGroupDepth) {
809
- updateTransformAndChildren(child, updateTick, 0);
810
- }
811
- }
812
- clearList(list, index);
813
- childrenAtDepth.index = 0;
814
- }
815
- if (updateChildRenderGroups) {
816
- for (let i = 0; i < renderGroup.renderGroupChildren.length; i++) {
817
- updateRenderGroupTransforms(renderGroup.renderGroupChildren[i], updateChildRenderGroups);
818
- }
819
- }
820
- }
821
- function updateRenderGroupTransform(renderGroup) {
822
- const root = renderGroup.root;
823
- let worldAlpha;
824
- if (renderGroup.renderGroupParent) {
825
- const renderGroupParent = renderGroup.renderGroupParent;
826
- renderGroup.worldTransform.appendFrom(
827
- root.relativeGroupTransform,
828
- renderGroupParent.worldTransform
829
- );
830
- renderGroup.worldColor = multiplyColors(
831
- root.groupColor,
832
- renderGroupParent.worldColor
833
- );
834
- worldAlpha = root.groupAlpha * renderGroupParent.worldAlpha;
835
- } else {
836
- renderGroup.worldTransform.copyFrom(root.localTransform);
837
- renderGroup.worldColor = root.localColor;
838
- worldAlpha = root.localAlpha;
839
- }
840
- worldAlpha = worldAlpha < 0 ? 0 : worldAlpha > 1 ? 1 : worldAlpha;
841
- renderGroup.worldAlpha = worldAlpha;
842
- renderGroup.worldColorAlpha = renderGroup.worldColor + ((worldAlpha * 255 | 0) << 24);
843
- }
844
- function updateTransformAndChildren(container, updateTick, updateFlags) {
845
- if (updateTick === container.updateTick) return;
846
- container.updateTick = updateTick;
847
- container.didChange = false;
848
- const localTransform = container.localTransform;
849
- container.updateLocalTransform();
850
- const parent = container.parent;
851
- if (parent && !parent.renderGroup) {
852
- updateFlags |= container._updateFlags;
853
- container.relativeGroupTransform.appendFrom(
854
- localTransform,
855
- parent.relativeGroupTransform
856
- );
857
- if (updateFlags & UPDATE_BLEND_COLOR_VISIBLE) {
858
- updateColorBlendVisibility(container, parent, updateFlags);
859
- }
860
- } else {
861
- updateFlags = container._updateFlags;
862
- container.relativeGroupTransform.copyFrom(localTransform);
863
- if (updateFlags & UPDATE_BLEND_COLOR_VISIBLE) {
864
- updateColorBlendVisibility(container, tempContainer, updateFlags);
865
- }
866
- }
867
- if (!container.renderGroup) {
868
- const children = container.children;
869
- const length = children.length;
870
- for (let i = 0; i < length; i++) {
871
- updateTransformAndChildren(children[i], updateTick, updateFlags);
872
- }
873
- const renderGroup = container.parentRenderGroup;
874
- const renderable = container;
875
- if (renderable.renderPipeId && !renderGroup.structureDidChange) {
876
- renderGroup.updateRenderable(renderable);
877
- }
878
- }
879
- }
880
- function updateColorBlendVisibility(container, parent, updateFlags) {
881
- if (updateFlags & UPDATE_COLOR) {
882
- container.groupColor = multiplyColors(
883
- container.localColor,
884
- parent.groupColor
885
- );
886
- let groupAlpha = container.localAlpha * parent.groupAlpha;
887
- groupAlpha = groupAlpha < 0 ? 0 : groupAlpha > 1 ? 1 : groupAlpha;
888
- container.groupAlpha = groupAlpha;
889
- container.groupColorAlpha = container.groupColor + ((groupAlpha * 255 | 0) << 24);
890
- }
891
- if (updateFlags & UPDATE_BLEND) {
892
- container.groupBlendMode = container.localBlendMode === "inherit" ? parent.groupBlendMode : container.localBlendMode;
893
- }
894
- if (updateFlags & UPDATE_VISIBLE) {
895
- container.globalDisplayStatus = container.localDisplayStatus & parent.globalDisplayStatus;
896
- }
897
- container._updateFlags = 0;
898
- }
899
- function validateRenderables(renderGroup, renderPipes) {
900
- const { list } = renderGroup.childrenRenderablesToUpdate;
901
- let rebuildRequired = false;
902
- for (let i = 0; i < renderGroup.childrenRenderablesToUpdate.index; i++) {
903
- const container = list[i];
904
- const renderable = container;
905
- const pipe = renderPipes[renderable.renderPipeId];
906
- rebuildRequired = pipe.validateRenderable(container);
907
- if (rebuildRequired) {
908
- break;
909
- }
910
- }
911
- renderGroup.structureDidChange = rebuildRequired;
912
- return rebuildRequired;
913
- }
914
- const tempMatrix = new Matrix();
915
- class RenderGroupSystem {
916
- constructor(renderer) {
917
- this._renderer = renderer;
918
- }
919
- render({ container, transform }) {
920
- const parent = container.parent;
921
- const renderGroupParent = container.renderGroup.renderGroupParent;
922
- container.parent = null;
923
- container.renderGroup.renderGroupParent = null;
924
- const renderer = this._renderer;
925
- const originalLocalTransform = tempMatrix;
926
- if (transform) {
927
- originalLocalTransform.copyFrom(container.renderGroup.localTransform);
928
- container.renderGroup.localTransform.copyFrom(transform);
929
- }
930
- const renderPipes = renderer.renderPipes;
931
- this._updateCachedRenderGroups(container.renderGroup, null);
932
- this._updateRenderGroups(container.renderGroup);
933
- renderer.globalUniforms.start({
934
- worldTransformMatrix: transform ? container.renderGroup.localTransform : container.renderGroup.worldTransform,
935
- worldColor: container.renderGroup.worldColorAlpha
936
- });
937
- executeInstructions(container.renderGroup, renderPipes);
938
- if (renderPipes.uniformBatch) {
939
- renderPipes.uniformBatch.renderEnd();
940
- }
941
- if (transform) {
942
- container.renderGroup.localTransform.copyFrom(originalLocalTransform);
943
- }
944
- container.parent = parent;
945
- container.renderGroup.renderGroupParent = renderGroupParent;
946
- }
947
- destroy() {
948
- this._renderer = null;
949
- }
950
- _updateCachedRenderGroups(renderGroup, closestCacheAsTexture) {
951
- renderGroup._parentCacheAsTextureRenderGroup = closestCacheAsTexture;
952
- if (renderGroup.isCachedAsTexture) {
953
- if (!renderGroup.textureNeedsUpdate) return;
954
- closestCacheAsTexture = renderGroup;
955
- }
956
- for (let i = renderGroup.renderGroupChildren.length - 1; i >= 0; i--) {
957
- this._updateCachedRenderGroups(renderGroup.renderGroupChildren[i], closestCacheAsTexture);
958
- }
959
- renderGroup.invalidateMatrices();
960
- if (renderGroup.isCachedAsTexture) {
961
- if (renderGroup.textureNeedsUpdate) {
962
- const bounds = renderGroup.root.getLocalBounds();
963
- const renderer = this._renderer;
964
- const resolution = renderGroup.textureOptions.resolution || renderer.view.resolution;
965
- const antialias = renderGroup.textureOptions.antialias ?? renderer.view.antialias;
966
- const scaleMode = renderGroup.textureOptions.scaleMode ?? "linear";
967
- const lastTexture = renderGroup.texture;
968
- bounds.ceil();
969
- if (renderGroup.texture) {
970
- TexturePool.returnTexture(renderGroup.texture, true);
971
- }
972
- const texture = TexturePool.getOptimalTexture(
973
- bounds.width,
974
- bounds.height,
975
- resolution,
976
- antialias
977
- );
978
- texture._source.style = new TextureStyle({ scaleMode });
979
- renderGroup.texture = texture;
980
- renderGroup._textureBounds || (renderGroup._textureBounds = new Bounds());
981
- renderGroup._textureBounds.copyFrom(bounds);
982
- if (lastTexture !== renderGroup.texture) {
983
- if (renderGroup.renderGroupParent) {
984
- renderGroup.renderGroupParent.structureDidChange = true;
985
- }
986
- }
987
- }
988
- } else if (renderGroup.texture) {
989
- TexturePool.returnTexture(renderGroup.texture, true);
990
- renderGroup.texture = null;
991
- }
992
- }
993
- _updateRenderGroups(renderGroup) {
994
- const renderer = this._renderer;
995
- const renderPipes = renderer.renderPipes;
996
- renderGroup.runOnRender(renderer);
997
- renderGroup.instructionSet.renderPipes = renderPipes;
998
- if (!renderGroup.structureDidChange) {
999
- validateRenderables(renderGroup, renderPipes);
1000
- } else {
1001
- clearList(renderGroup.childrenRenderablesToUpdate.list, 0);
1002
- }
1003
- updateRenderGroupTransforms(renderGroup);
1004
- if (renderGroup.structureDidChange) {
1005
- renderGroup.structureDidChange = false;
1006
- this._buildInstructions(renderGroup, renderer);
1007
- } else {
1008
- this._updateRenderables(renderGroup);
1009
- }
1010
- renderGroup.childrenRenderablesToUpdate.index = 0;
1011
- renderer.renderPipes.batch.upload(renderGroup.instructionSet);
1012
- if (renderGroup.isCachedAsTexture && !renderGroup.textureNeedsUpdate) return;
1013
- for (let i = 0; i < renderGroup.renderGroupChildren.length; i++) {
1014
- this._updateRenderGroups(renderGroup.renderGroupChildren[i]);
1015
- }
1016
- }
1017
- _updateRenderables(renderGroup) {
1018
- const { list, index } = renderGroup.childrenRenderablesToUpdate;
1019
- for (let i = 0; i < index; i++) {
1020
- const container = list[i];
1021
- if (container.didViewUpdate) {
1022
- renderGroup.updateRenderable(container);
1023
- }
1024
- }
1025
- clearList(list, index);
1026
- }
1027
- _buildInstructions(renderGroup, rendererOrPipes) {
1028
- const root = renderGroup.root;
1029
- const instructionSet = renderGroup.instructionSet;
1030
- instructionSet.reset();
1031
- const renderer = rendererOrPipes.renderPipes ? rendererOrPipes : rendererOrPipes.batch.renderer;
1032
- const renderPipes = renderer.renderPipes;
1033
- renderPipes.batch.buildStart(instructionSet);
1034
- renderPipes.blendMode.buildStart();
1035
- renderPipes.colorMask.buildStart();
1036
- if (root.sortableChildren) {
1037
- root.sortChildren();
1038
- }
1039
- root.collectRenderablesWithEffects(instructionSet, renderer, null);
1040
- renderPipes.batch.buildEnd(instructionSet);
1041
- renderPipes.blendMode.buildEnd(instructionSet);
1042
- }
1043
- }
1044
- RenderGroupSystem.extension = {
1045
- type: [
1046
- ExtensionType.WebGLSystem,
1047
- ExtensionType.WebGPUSystem,
1048
- ExtensionType.CanvasSystem
1049
- ],
1050
- name: "renderGroup"
1051
- };
1052
- const _BackgroundSystem = class _BackgroundSystem2 {
1053
- constructor() {
1054
- this.clearBeforeRender = true;
1055
- this._backgroundColor = new Color(0);
1056
- this.color = this._backgroundColor;
1057
- this.alpha = 1;
1058
- }
1059
- /**
1060
- * initiates the background system
1061
- * @param options - the options for the background colors
1062
- */
1063
- init(options) {
1064
- options = { ..._BackgroundSystem2.defaultOptions, ...options };
1065
- this.clearBeforeRender = options.clearBeforeRender;
1066
- this.color = options.background || options.backgroundColor || this._backgroundColor;
1067
- this.alpha = options.backgroundAlpha;
1068
- this._backgroundColor.setAlpha(options.backgroundAlpha);
1069
- }
1070
- /** The background color to fill if not transparent */
1071
- get color() {
1072
- return this._backgroundColor;
1073
- }
1074
- set color(value) {
1075
- const incoming = Color.shared.setValue(value);
1076
- if (incoming.alpha < 1 && this._backgroundColor.alpha === 1) {
1077
- warn(
1078
- "Cannot set a transparent background on an opaque canvas. To enable transparency, set backgroundAlpha < 1 when initializing your Application."
1079
- );
1080
- }
1081
- this._backgroundColor.setValue(value);
1082
- }
1083
- /** The background color alpha. Setting this to 0 will make the canvas transparent. */
1084
- get alpha() {
1085
- return this._backgroundColor.alpha;
1086
- }
1087
- set alpha(value) {
1088
- this._backgroundColor.setAlpha(value);
1089
- }
1090
- /** The background color as an [R, G, B, A] array. */
1091
- get colorRgba() {
1092
- return this._backgroundColor.toArray();
1093
- }
1094
- /**
1095
- * destroys the background system
1096
- * @internal
1097
- */
1098
- destroy() {
1099
- }
1100
- };
1101
- _BackgroundSystem.extension = {
1102
- type: [
1103
- ExtensionType.WebGLSystem,
1104
- ExtensionType.WebGPUSystem,
1105
- ExtensionType.CanvasSystem
1106
- ],
1107
- name: "background",
1108
- priority: 0
1109
- };
1110
- _BackgroundSystem.defaultOptions = {
1111
- /**
1112
- * {@link WebGLOptions.backgroundAlpha}
1113
- * @default 1
1114
- */
1115
- backgroundAlpha: 1,
1116
- /**
1117
- * {@link WebGLOptions.backgroundColor}
1118
- * @default 0x000000
1119
- */
1120
- backgroundColor: 0,
1121
- /**
1122
- * {@link WebGLOptions.clearBeforeRender}
1123
- * @default true
1124
- */
1125
- clearBeforeRender: true
1126
- };
1127
- let BackgroundSystem = _BackgroundSystem;
1128
- const imageTypes = {
1129
- png: "image/png",
1130
- jpg: "image/jpeg",
1131
- webp: "image/webp"
1132
- };
1133
- const _ExtractSystem = class _ExtractSystem2 {
1134
- /** @param renderer - The renderer this System works for. */
1135
- constructor(renderer) {
1136
- this._renderer = renderer;
1137
- }
1138
- _normalizeOptions(options, defaults = {}) {
1139
- if (options instanceof Container || options instanceof Texture) {
1140
- return {
1141
- target: options,
1142
- ...defaults
1143
- };
1144
- }
1145
- return {
1146
- ...defaults,
1147
- ...options
1148
- };
1149
- }
1150
- /**
1151
- * Creates an IImage from a display object or texture.
1152
- * @param options - Options for creating the image, or the target to extract
1153
- * @returns Promise that resolves with the generated IImage
1154
- * @example
1155
- * ```ts
1156
- * // Basic usage with a sprite
1157
- * const sprite = new Sprite(texture);
1158
- * const image = await renderer.extract.image(sprite);
1159
- * document.body.appendChild(image);
1160
- *
1161
- * // Advanced usage with options
1162
- * const image = await renderer.extract.image({
1163
- * target: container,
1164
- * format: 'webp',
1165
- * quality: 0.8,
1166
- * frame: new Rectangle(0, 0, 100, 100),
1167
- * resolution: 2,
1168
- * clearColor: '#ff0000',
1169
- * antialias: true
1170
- * });
1171
- *
1172
- * // Extract directly from a texture
1173
- * const texture = Texture.from('myTexture.png');
1174
- * const image = await renderer.extract.image(texture);
1175
- * ```
1176
- * @see {@link ExtractImageOptions} For detailed options
1177
- * @see {@link ExtractSystem.base64} For base64 string output
1178
- * @see {@link ExtractSystem.canvas} For canvas output
1179
- * @see {@link ImageLike} For the image interface
1180
- * @category rendering
1181
- */
1182
- async image(options) {
1183
- const image = DOMAdapter.get().createImage();
1184
- image.src = await this.base64(options);
1185
- return image;
1186
- }
1187
- /**
1188
- * Converts the target into a base64 encoded string.
1189
- *
1190
- * This method works by first creating
1191
- * a canvas using `Extract.canvas` and then converting it to a base64 string.
1192
- * @param options - The options for creating the base64 string, or the target to extract
1193
- * @returns Promise that resolves with the base64 encoded string
1194
- * @example
1195
- * ```ts
1196
- * // Basic usage with a sprite
1197
- * const sprite = new Sprite(texture);
1198
- * const base64 = await renderer.extract.base64(sprite);
1199
- * console.log(base64); // data:image/png;base64,...
1200
- *
1201
- * // Advanced usage with options
1202
- * const base64 = await renderer.extract.base64({
1203
- * target: container,
1204
- * format: 'webp',
1205
- * quality: 0.8,
1206
- * frame: new Rectangle(0, 0, 100, 100),
1207
- * resolution: 2
1208
- * });
1209
- * ```
1210
- * @throws Will throw an error if the platform doesn't support any of:
1211
- * - ICanvas.toDataURL
1212
- * - ICanvas.toBlob
1213
- * - ICanvas.convertToBlob
1214
- * @see {@link ExtractImageOptions} For detailed options
1215
- * @see {@link ExtractSystem.canvas} For canvas output
1216
- * @see {@link ExtractSystem.image} For HTMLImage output
1217
- * @category rendering
1218
- */
1219
- async base64(options) {
1220
- options = this._normalizeOptions(
1221
- options,
1222
- _ExtractSystem2.defaultImageOptions
1223
- );
1224
- const { format, quality } = options;
1225
- const canvas = this.canvas(options);
1226
- if (canvas.toBlob !== void 0) {
1227
- return new Promise((resolve, reject) => {
1228
- canvas.toBlob((blob) => {
1229
- if (!blob) {
1230
- reject(new Error("ICanvas.toBlob failed!"));
1231
- return;
1232
- }
1233
- const reader = new FileReader();
1234
- reader.onload = () => resolve(reader.result);
1235
- reader.onerror = reject;
1236
- reader.readAsDataURL(blob);
1237
- }, imageTypes[format], quality);
1238
- });
1239
- }
1240
- if (canvas.toDataURL !== void 0) {
1241
- return canvas.toDataURL(imageTypes[format], quality);
1242
- }
1243
- if (canvas.convertToBlob !== void 0) {
1244
- const blob = await canvas.convertToBlob({ type: imageTypes[format], quality });
1245
- return new Promise((resolve, reject) => {
1246
- const reader = new FileReader();
1247
- reader.onload = () => resolve(reader.result);
1248
- reader.onerror = reject;
1249
- reader.readAsDataURL(blob);
1250
- });
1251
- }
1252
- throw new Error("Extract.base64() requires ICanvas.toDataURL, ICanvas.toBlob, or ICanvas.convertToBlob to be implemented");
1253
- }
1254
- /**
1255
- * Creates a Canvas element, renders the target to it and returns it.
1256
- * This method is useful for creating static images or when you need direct canvas access.
1257
- * @param options - The options for creating the canvas, or the target to extract
1258
- * @returns A Canvas element with the texture rendered on
1259
- * @example
1260
- * ```ts
1261
- * // Basic canvas extraction from a sprite
1262
- * const sprite = new Sprite(texture);
1263
- * const canvas = renderer.extract.canvas(sprite);
1264
- * document.body.appendChild(canvas);
1265
- *
1266
- * // Extract with custom region
1267
- * const canvas = renderer.extract.canvas({
1268
- * target: container,
1269
- * frame: new Rectangle(0, 0, 100, 100)
1270
- * });
1271
- *
1272
- * // Extract with high resolution
1273
- * const canvas = renderer.extract.canvas({
1274
- * target: sprite,
1275
- * resolution: 2,
1276
- * clearColor: '#ff0000'
1277
- * });
1278
- *
1279
- * // Extract directly from a texture
1280
- * const texture = Texture.from('myTexture.png');
1281
- * const canvas = renderer.extract.canvas(texture);
1282
- *
1283
- * // Extract with anti-aliasing
1284
- * const canvas = renderer.extract.canvas({
1285
- * target: graphics,
1286
- * antialias: true
1287
- * });
1288
- * ```
1289
- * @see {@link ExtractOptions} For detailed options
1290
- * @see {@link ExtractSystem.image} For HTMLImage output
1291
- * @see {@link ExtractSystem.pixels} For raw pixel data
1292
- * @category rendering
1293
- */
1294
- canvas(options) {
1295
- options = this._normalizeOptions(options);
1296
- const target = options.target;
1297
- const renderer = this._renderer;
1298
- if (target instanceof Texture) {
1299
- return renderer.texture.generateCanvas(target);
1300
- }
1301
- const texture = renderer.textureGenerator.generateTexture(options);
1302
- const canvas = renderer.texture.generateCanvas(texture);
1303
- texture.destroy(true);
1304
- return canvas;
1305
- }
1306
- /**
1307
- * Returns a one-dimensional array containing the pixel data of the entire texture in RGBA order,
1308
- * with integer values between 0 and 255 (inclusive).
1309
- * > [!NOE] The returned array is a flat Uint8Array where every 4 values represent RGBA
1310
- * @param options - The options for extracting the image, or the target to extract
1311
- * @returns One-dimensional Uint8Array containing the pixel data in RGBA format
1312
- * @example
1313
- * ```ts
1314
- * // Basic pixel extraction
1315
- * const sprite = new Sprite(texture);
1316
- * const pixels = renderer.extract.pixels(sprite);
1317
- * console.log(pixels[0], pixels[1], pixels[2], pixels[3]); // R,G,B,A values
1318
- *
1319
- * // Extract with custom region
1320
- * const pixels = renderer.extract.pixels({
1321
- * target: sprite,
1322
- * frame: new Rectangle(0, 0, 100, 100)
1323
- * });
1324
- *
1325
- * // Extract with high resolution
1326
- * const pixels = renderer.extract.pixels({
1327
- * target: sprite,
1328
- * resolution: 2
1329
- * });
1330
- * ```
1331
- * @see {@link ExtractOptions} For detailed options
1332
- * @see {@link ExtractSystem.canvas} For canvas output
1333
- * @see {@link ExtractSystem.image} For image output
1334
- * @category rendering
1335
- */
1336
- pixels(options) {
1337
- options = this._normalizeOptions(options);
1338
- const target = options.target;
1339
- const renderer = this._renderer;
1340
- const texture = target instanceof Texture ? target : renderer.textureGenerator.generateTexture(options);
1341
- const pixelInfo = renderer.texture.getPixels(texture);
1342
- if (target instanceof Container) {
1343
- texture.destroy(true);
1344
- }
1345
- return pixelInfo;
1346
- }
1347
- /**
1348
- * Creates a texture from a display object or existing texture.
1349
- *
1350
- * This is useful for creating
1351
- * reusable textures from rendered content or making copies of existing textures.
1352
- * > [!NOTE] The returned texture should be destroyed when no longer needed
1353
- * @param options - The options for creating the texture, or the target to extract
1354
- * @returns A new texture containing the extracted content
1355
- * @example
1356
- * ```ts
1357
- * // Basic texture extraction from a sprite
1358
- * const sprite = new Sprite(texture);
1359
- * const extractedTexture = renderer.extract.texture(sprite);
1360
- *
1361
- * // Extract with custom region
1362
- * const regionTexture = renderer.extract.texture({
1363
- * target: container,
1364
- * frame: new Rectangle(0, 0, 100, 100)
1365
- * });
1366
- *
1367
- * // Extract with high resolution
1368
- * const hiResTexture = renderer.extract.texture({
1369
- * target: sprite,
1370
- * resolution: 2,
1371
- * clearColor: '#ff0000'
1372
- * });
1373
- *
1374
- * // Create a new sprite from extracted texture
1375
- * const newSprite = new Sprite(
1376
- * renderer.extract.texture({
1377
- * target: graphics,
1378
- * antialias: true
1379
- * })
1380
- * );
1381
- *
1382
- * // Clean up when done
1383
- * extractedTexture.destroy(true);
1384
- * ```
1385
- * @see {@link ExtractOptions} For detailed options
1386
- * @see {@link Texture} For texture management
1387
- * @see {@link GenerateTextureSystem} For texture generation
1388
- * @category rendering
1389
- */
1390
- texture(options) {
1391
- options = this._normalizeOptions(options);
1392
- if (options.target instanceof Texture) return options.target;
1393
- return this._renderer.textureGenerator.generateTexture(options);
1394
- }
1395
- /**
1396
- * Extracts and downloads content from the renderer as an image file.
1397
- * This is a convenient way to save screenshots or export rendered content.
1398
- * > [!NOTE] The download will use PNG format regardless of the filename extension
1399
- * @param options - The options for downloading and extracting the image, or the target to extract
1400
- * @example
1401
- * ```ts
1402
- * // Basic download with default filename
1403
- * const sprite = new Sprite(texture);
1404
- * renderer.extract.download(sprite); // Downloads as 'image.png'
1405
- *
1406
- * // Download with custom filename
1407
- * renderer.extract.download({
1408
- * target: sprite,
1409
- * filename: 'screenshot.png'
1410
- * });
1411
- *
1412
- * // Download with custom region
1413
- * renderer.extract.download({
1414
- * target: container,
1415
- * filename: 'region.png',
1416
- * frame: new Rectangle(0, 0, 100, 100)
1417
- * });
1418
- *
1419
- * // Download with high resolution and background
1420
- * renderer.extract.download({
1421
- * target: stage,
1422
- * filename: 'hd-screenshot.png',
1423
- * resolution: 2,
1424
- * clearColor: '#ff0000'
1425
- * });
1426
- *
1427
- * // Download with anti-aliasing
1428
- * renderer.extract.download({
1429
- * target: graphics,
1430
- * filename: 'smooth.png',
1431
- * antialias: true
1432
- * });
1433
- * ```
1434
- * @see {@link ExtractDownloadOptions} For detailed options
1435
- * @see {@link ExtractSystem.image} For creating images without download
1436
- * @see {@link ExtractSystem.canvas} For canvas output
1437
- * @category rendering
1438
- */
1439
- download(options) {
1440
- options = this._normalizeOptions(options);
1441
- const canvas = this.canvas(options);
1442
- const link = document.createElement("a");
1443
- link.download = options.filename ?? "image.png";
1444
- link.href = canvas.toDataURL("image/png");
1445
- document.body.appendChild(link);
1446
- link.click();
1447
- document.body.removeChild(link);
1448
- }
1449
- /**
1450
- * Logs the target to the console as an image. This is a useful way to debug what's happening in the renderer.
1451
- * The image will be displayed in the browser's console using CSS background images.
1452
- * @param options - The options for logging the image, or the target to log
1453
- * @param options.width - The width of the logged image preview in the console (in pixels)
1454
- * @example
1455
- * ```ts
1456
- * // Basic usage
1457
- * const sprite = new Sprite(texture);
1458
- * renderer.extract.log(sprite);
1459
- * ```
1460
- * @see {@link ExtractSystem.canvas} For getting raw canvas output
1461
- * @see {@link ExtractSystem.pixels} For raw pixel data
1462
- * @category rendering
1463
- * @advanced
1464
- */
1465
- log(options) {
1466
- const width = options.width ?? 200;
1467
- options = this._normalizeOptions(options);
1468
- const canvas = this.canvas(options);
1469
- const base64 = canvas.toDataURL();
1470
- console.log(`[Pixi Texture] ${canvas.width}px ${canvas.height}px`);
1471
- const style = [
1472
- "font-size: 1px;",
1473
- `padding: ${width}px ${300}px;`,
1474
- `background: url(${base64}) no-repeat;`,
1475
- "background-size: contain;"
1476
- ].join(" ");
1477
- console.log("%c ", style);
1478
- }
1479
- destroy() {
1480
- this._renderer = null;
1481
- }
1482
- };
1483
- _ExtractSystem.extension = {
1484
- type: [
1485
- ExtensionType.WebGLSystem,
1486
- ExtensionType.WebGPUSystem,
1487
- ExtensionType.CanvasSystem
1488
- ],
1489
- name: "extract"
1490
- };
1491
- _ExtractSystem.defaultImageOptions = {
1492
- format: "png",
1493
- quality: 1
1494
- };
1495
- let ExtractSystem = _ExtractSystem;
1496
- class RenderTexture extends Texture {
1497
- /**
1498
- * Creates a RenderTexture. Pass `dynamic: true` in options to allow resizing after creation.
1499
- * @param options - Options for the RenderTexture, including width, height, and dynamic.
1500
- * @returns A new RenderTexture instance.
1501
- * @example
1502
- * const rt = RenderTexture.create({ width: 100, height: 100, dynamic: true });
1503
- * rt.resize(500, 500);
1504
- */
1505
- static create(options) {
1506
- const { dynamic, ...rest } = options;
1507
- return new RenderTexture({
1508
- source: new TextureSource(rest),
1509
- dynamic: dynamic ?? false
1510
- });
1511
- }
1512
- /**
1513
- * Resizes the render texture.
1514
- * @param width - The new width of the render texture.
1515
- * @param height - The new height of the render texture.
1516
- * @param resolution - The new resolution of the render texture.
1517
- * @returns This texture.
1518
- */
1519
- resize(width, height, resolution) {
1520
- this.source.resize(width, height, resolution);
1521
- return this;
1522
- }
1523
- }
1524
- const tempRect = new Rectangle();
1525
- const tempBounds = new Bounds();
1526
- const noColor = [0, 0, 0, 0];
1527
- class GenerateTextureSystem {
1528
- constructor(renderer) {
1529
- this._renderer = renderer;
1530
- }
1531
- /**
1532
- * Creates a texture from a display object that can be used for creating sprites and other textures.
1533
- * This is particularly useful for optimizing performance when a complex container needs to be reused.
1534
- * @param options - Generate texture options or a container to convert to texture
1535
- * @returns A new RenderTexture containing the rendered display object
1536
- * @example
1537
- * ```ts
1538
- * // Basic usage with a container
1539
- * const container = new Container();
1540
- * container.addChild(
1541
- * new Graphics()
1542
- * .circle(0, 0, 50)
1543
- * .fill('red')
1544
- * );
1545
- *
1546
- * const texture = renderer.textureGenerator.generateTexture(container);
1547
- *
1548
- * // Advanced usage with options
1549
- * const texture = renderer.textureGenerator.generateTexture({
1550
- * target: container,
1551
- * frame: new Rectangle(0, 0, 100, 100), // Specific region
1552
- * resolution: 2, // High DPI
1553
- * clearColor: '#ff0000', // Red background
1554
- * antialias: true // Smooth edges
1555
- * });
1556
- *
1557
- * // Create a sprite from the generated texture
1558
- * const sprite = new Sprite(texture);
1559
- *
1560
- * // Clean up when done
1561
- * texture.destroy(true);
1562
- * ```
1563
- * @see {@link GenerateTextureOptions} For detailed texture generation options
1564
- * @see {@link RenderTexture} For the type of texture created
1565
- * @category rendering
1566
- */
1567
- generateTexture(options) {
1568
- var _a;
1569
- if (options instanceof Container) {
1570
- options = {
1571
- target: options,
1572
- frame: void 0,
1573
- textureSourceOptions: {},
1574
- resolution: void 0
1575
- };
1576
- }
1577
- const resolution = options.resolution || this._renderer.resolution;
1578
- const antialias = options.antialias || this._renderer.view.antialias;
1579
- const container = options.target;
1580
- let clearColor = options.clearColor;
1581
- if (clearColor) {
1582
- const isRGBAArray = Array.isArray(clearColor) && clearColor.length === 4;
1583
- clearColor = isRGBAArray ? clearColor : Color.shared.setValue(clearColor).toArray();
1584
- } else {
1585
- clearColor = noColor;
1586
- }
1587
- const region = ((_a = options.frame) == null ? void 0 : _a.copyTo(tempRect)) || getLocalBounds(container, tempBounds).rectangle;
1588
- region.width = Math.max(region.width, 1 / resolution) | 0;
1589
- region.height = Math.max(region.height, 1 / resolution) | 0;
1590
- const target = RenderTexture.create({
1591
- ...options.textureSourceOptions,
1592
- width: region.width,
1593
- height: region.height,
1594
- resolution,
1595
- antialias
1596
- });
1597
- const transform = Matrix.shared.translate(-region.x, -region.y);
1598
- this._renderer.render({
1599
- container,
1600
- transform,
1601
- target,
1602
- clearColor
1603
- });
1604
- target.source.updateMipmaps();
1605
- return target;
1606
- }
1607
- destroy() {
1608
- this._renderer = null;
1609
- }
1610
- }
1611
- GenerateTextureSystem.extension = {
1612
- type: [
1613
- ExtensionType.WebGLSystem,
1614
- ExtensionType.WebGPUSystem,
1615
- ExtensionType.CanvasSystem
1616
- ],
1617
- name: "textureGenerator"
1618
- };
1619
- function cleanHash(hash) {
1620
- let clean = false;
1621
- for (const i in hash) {
1622
- if (hash[i] == void 0) {
1623
- clean = true;
1624
- break;
1625
- }
1626
- }
1627
- if (!clean) return hash;
1628
- const cleanHash2 = /* @__PURE__ */ Object.create(null);
1629
- for (const i in hash) {
1630
- const value = hash[i];
1631
- if (value) {
1632
- cleanHash2[i] = value;
1633
- }
1634
- }
1635
- return cleanHash2;
1636
- }
1637
- function cleanArray(arr) {
1638
- let offset = 0;
1639
- for (let i = 0; i < arr.length; i++) {
1640
- if (arr[i] == void 0) {
1641
- offset++;
1642
- } else {
1643
- arr[i - offset] = arr[i];
1644
- }
1645
- }
1646
- arr.length -= offset;
1647
- return arr;
1648
- }
1649
- const _GCSystem = class _GCSystem2 {
1650
- /**
1651
- * Creates a new GCSystem instance.
1652
- * @param renderer - The renderer this garbage collection system works for
1653
- */
1654
- constructor(renderer) {
1655
- this._managedResources = [];
1656
- this._managedResourceHashes = [];
1657
- this._managedCollections = [];
1658
- this._ready = false;
1659
- this._renderer = renderer;
1660
- }
1661
- /**
1662
- * Initializes the garbage collection system with the provided options.
1663
- * @param options - Configuration options
1664
- */
1665
- init(options) {
1666
- options = { ..._GCSystem2.defaultOptions, ...options };
1667
- this.maxUnusedTime = options.gcMaxUnusedTime;
1668
- this._frequency = options.gcFrequency;
1669
- this.enabled = options.gcActive;
1670
- this.now = performance.now();
1671
- }
1672
- /**
1673
- * Gets whether the garbage collection system is currently enabled.
1674
- * @returns True if GC is enabled, false otherwise
1675
- */
1676
- get enabled() {
1677
- return !!this._handler;
1678
- }
1679
- /**
1680
- * Enables or disables the garbage collection system.
1681
- * When enabled, schedules periodic cleanup of resources.
1682
- * When disabled, cancels all scheduled cleanups.
1683
- */
1684
- set enabled(value) {
1685
- if (this.enabled === value) return;
1686
- if (value) {
1687
- this._handler = this._renderer.scheduler.repeat(
1688
- () => {
1689
- this._ready = true;
1690
- },
1691
- this._frequency,
1692
- false
1693
- );
1694
- this._collectionsHandler = this._renderer.scheduler.repeat(
1695
- () => {
1696
- for (const hash of this._managedCollections) {
1697
- const { context, collection, type } = hash;
1698
- if (type === "hash") {
1699
- context[collection] = cleanHash(context[collection]);
1700
- } else {
1701
- context[collection] = cleanArray(context[collection]);
1702
- }
1703
- }
1704
- },
1705
- this._frequency
1706
- );
1707
- } else {
1708
- this._renderer.scheduler.cancel(this._handler);
1709
- this._renderer.scheduler.cancel(this._collectionsHandler);
1710
- this._handler = 0;
1711
- this._collectionsHandler = 0;
1712
- }
1713
- }
1714
- /**
1715
- * Called before rendering. Updates the current timestamp.
1716
- * @param options - The render options
1717
- * @param options.container - The container to render
1718
- */
1719
- prerender({ container }) {
1720
- this.now = performance.now();
1721
- container.renderGroup.gcTick = this._renderer.tick++;
1722
- this._updateInstructionGCTick(container.renderGroup, container.renderGroup.gcTick);
1723
- }
1724
- /** Performs garbage collection after rendering. */
1725
- postrender() {
1726
- if (!this._ready || !this.enabled) return;
1727
- this.run();
1728
- this._ready = false;
1729
- }
1730
- /**
1731
- * Updates the GC tick counter for a render group and its children.
1732
- * @param renderGroup - The render group to update
1733
- * @param gcTick - The new tick value
1734
- */
1735
- _updateInstructionGCTick(renderGroup, gcTick) {
1736
- renderGroup.instructionSet.gcTick = gcTick;
1737
- renderGroup.gcTick = gcTick;
1738
- for (const child of renderGroup.renderGroupChildren) {
1739
- this._updateInstructionGCTick(child, gcTick);
1740
- }
1741
- }
1742
- /**
1743
- * Registers a collection for garbage collection tracking.
1744
- * @param context - The object containing the collection
1745
- * @param collection - The property name on context that holds the collection
1746
- * @param type - The type of collection to track ('hash' or 'array')
1747
- */
1748
- addCollection(context, collection, type) {
1749
- this._managedCollections.push({
1750
- context,
1751
- collection,
1752
- type
1753
- });
1754
- }
1755
- /**
1756
- * Registers a resource for garbage collection tracking.
1757
- * @param resource - The resource to track
1758
- * @param type - The type of resource to track
1759
- */
1760
- addResource(resource, type) {
1761
- var _a, _b;
1762
- if (resource._gcLastUsed !== -1) {
1763
- resource._gcLastUsed = this.now;
1764
- (_a = resource._onTouch) == null ? void 0 : _a.call(resource, this.now);
1765
- return;
1766
- }
1767
- const index = this._managedResources.length;
1768
- resource._gcData = {
1769
- index,
1770
- type
1771
- };
1772
- resource._gcLastUsed = this.now;
1773
- (_b = resource._onTouch) == null ? void 0 : _b.call(resource, this.now);
1774
- resource.once("unload", this.removeResource, this);
1775
- this._managedResources.push(resource);
1776
- }
1777
- /**
1778
- * Removes a resource from garbage collection tracking.
1779
- * Call this when manually destroying a resource.
1780
- * @param resource - The resource to stop tracking
1781
- */
1782
- removeResource(resource) {
1783
- const gcData = resource._gcData;
1784
- if (!gcData) return;
1785
- const index = gcData.index;
1786
- const last = this._managedResources.length - 1;
1787
- if (index !== last) {
1788
- const lastResource = this._managedResources[last];
1789
- this._managedResources[index] = lastResource;
1790
- lastResource._gcData.index = index;
1791
- }
1792
- this._managedResources.length--;
1793
- resource._gcData = null;
1794
- resource._gcLastUsed = -1;
1795
- }
1796
- /**
1797
- * Registers a hash-based resource collection for garbage collection tracking.
1798
- * Resources in the hash will be automatically tracked and cleaned up when unused.
1799
- * @param context - The object containing the hash property
1800
- * @param hash - The property name on context that holds the resource hash
1801
- * @param type - The type of resources in the hash ('resource' or 'renderable')
1802
- * @param priority - Processing priority (lower values are processed first)
1803
- */
1804
- addResourceHash(context, hash, type, priority = 0) {
1805
- this._managedResourceHashes.push({
1806
- context,
1807
- hash,
1808
- type,
1809
- priority
1810
- });
1811
- this._managedResourceHashes.sort((a, b) => a.priority - b.priority);
1812
- }
1813
- /**
1814
- * Performs garbage collection by cleaning up unused resources.
1815
- * Removes resources that haven't been used for longer than maxUnusedTime.
1816
- */
1817
- run() {
1818
- const now = performance.now();
1819
- const managedResourceHashes = this._managedResourceHashes;
1820
- for (const hashEntry of managedResourceHashes) {
1821
- this.runOnHash(hashEntry, now);
1822
- }
1823
- let writeIndex = 0;
1824
- for (let i = 0; i < this._managedResources.length; i++) {
1825
- const resource = this._managedResources[i];
1826
- writeIndex = this.runOnResource(resource, now, writeIndex);
1827
- }
1828
- this._managedResources.length = writeIndex;
1829
- }
1830
- updateRenderableGCTick(renderable, now) {
1831
- var _a, _b;
1832
- const renderGroup = renderable.renderGroup ?? renderable.parentRenderGroup;
1833
- const currentTick = ((_a = renderGroup == null ? void 0 : renderGroup.instructionSet) == null ? void 0 : _a.gcTick) ?? -1;
1834
- if (((renderGroup == null ? void 0 : renderGroup.gcTick) ?? 0) === currentTick) {
1835
- renderable._gcLastUsed = now;
1836
- (_b = renderable._onTouch) == null ? void 0 : _b.call(renderable, now);
1837
- }
1838
- }
1839
- runOnResource(resource, now, writeIndex) {
1840
- const gcData = resource._gcData;
1841
- if (gcData.type === "renderable") {
1842
- this.updateRenderableGCTick(resource, now);
1843
- }
1844
- const isRecentlyUsed = now - resource._gcLastUsed < this.maxUnusedTime;
1845
- if (isRecentlyUsed || !resource.autoGarbageCollect) {
1846
- this._managedResources[writeIndex] = resource;
1847
- gcData.index = writeIndex;
1848
- writeIndex++;
1849
- } else {
1850
- resource.unload();
1851
- resource._gcData = null;
1852
- resource._gcLastUsed = -1;
1853
- resource.off("unload", this.removeResource, this);
1854
- }
1855
- return writeIndex;
1856
- }
1857
- /**
1858
- * Creates a clone of the hash, copying all non-null entries up to (but not including) the stop key.
1859
- * @param hashValue - The original hash to clone from
1860
- * @param stopKey - The key to stop at (exclusive)
1861
- * @returns A new hash object with copied entries
1862
- */
1863
- _createHashClone(hashValue, stopKey) {
1864
- const hashClone = /* @__PURE__ */ Object.create(null);
1865
- for (const k in hashValue) {
1866
- if (k === stopKey) break;
1867
- if (hashValue[k] !== null) hashClone[k] = hashValue[k];
1868
- }
1869
- return hashClone;
1870
- }
1871
- runOnHash(hashEntry, now) {
1872
- var _a;
1873
- const { context, hash, type } = hashEntry;
1874
- const hashValue = context[hash];
1875
- let hashClone = null;
1876
- let nullCount = 0;
1877
- for (const key in hashValue) {
1878
- const resource = hashValue[key];
1879
- if (resource === null) {
1880
- nullCount++;
1881
- if (nullCount === 1e4 && !hashClone) {
1882
- hashClone = this._createHashClone(hashValue, key);
1883
- }
1884
- continue;
1885
- }
1886
- if (resource._gcLastUsed === -1) {
1887
- resource._gcLastUsed = now;
1888
- (_a = resource._onTouch) == null ? void 0 : _a.call(resource, now);
1889
- if (hashClone) hashClone[key] = resource;
1890
- continue;
1891
- }
1892
- if (type === "renderable") {
1893
- this.updateRenderableGCTick(resource, now);
1894
- }
1895
- const isRecentlyUsed = now - resource._gcLastUsed < this.maxUnusedTime;
1896
- if (!isRecentlyUsed && resource.autoGarbageCollect) {
1897
- if (!hashClone) {
1898
- if (nullCount + 1 !== 1e4) {
1899
- hashValue[key] = null;
1900
- nullCount++;
1901
- } else {
1902
- hashClone = this._createHashClone(hashValue, key);
1903
- }
1904
- }
1905
- if (type === "renderable") {
1906
- const res = resource;
1907
- const renderGroup = res.renderGroup ?? res.parentRenderGroup;
1908
- if (renderGroup) renderGroup.structureDidChange = true;
1909
- }
1910
- resource.unload();
1911
- resource._gcData = null;
1912
- resource._gcLastUsed = -1;
1913
- } else if (hashClone) {
1914
- hashClone[key] = resource;
1915
- }
1916
- }
1917
- if (hashClone) {
1918
- context[hash] = hashClone;
1919
- }
1920
- }
1921
- /** Cleans up the garbage collection system. Disables GC and removes all tracked resources. */
1922
- destroy() {
1923
- this.enabled = false;
1924
- this._managedResources.forEach((resource) => {
1925
- resource.off("unload", this.removeResource, this);
1926
- });
1927
- this._managedResources.length = 0;
1928
- this._managedResourceHashes.length = 0;
1929
- this._managedCollections.length = 0;
1930
- this._renderer = null;
1931
- }
1932
- };
1933
- _GCSystem.extension = {
1934
- type: [
1935
- ExtensionType.WebGLSystem,
1936
- ExtensionType.WebGPUSystem,
1937
- ExtensionType.CanvasSystem
1938
- ],
1939
- name: "gc",
1940
- priority: 0
1941
- };
1942
- _GCSystem.defaultOptions = {
1943
- /** Enable/disable the garbage collector */
1944
- gcActive: true,
1945
- /** Time in ms before an unused resource is collected (default 1 minute) */
1946
- gcMaxUnusedTime: 6e4,
1947
- /** How often to run garbage collection in ms (default 30 seconds) */
1948
- gcFrequency: 3e4
1949
- };
1950
- let GCSystem = _GCSystem;
1951
- class GlobalUniformSystem {
1952
- constructor(renderer) {
1953
- this._stackIndex = 0;
1954
- this._globalUniformDataStack = [];
1955
- this._uniformsPool = [];
1956
- this._activeUniforms = [];
1957
- this._bindGroupPool = [];
1958
- this._activeBindGroups = [];
1959
- this._renderer = renderer;
1960
- }
1961
- reset() {
1962
- this._stackIndex = 0;
1963
- for (let i = 0; i < this._activeUniforms.length; i++) {
1964
- this._uniformsPool.push(this._activeUniforms[i]);
1965
- }
1966
- for (let i = 0; i < this._activeBindGroups.length; i++) {
1967
- this._bindGroupPool.push(this._activeBindGroups[i]);
1968
- }
1969
- this._activeUniforms.length = 0;
1970
- this._activeBindGroups.length = 0;
1971
- }
1972
- start(options) {
1973
- this.reset();
1974
- this.push(options);
1975
- }
1976
- bind({
1977
- size,
1978
- projectionMatrix,
1979
- worldTransformMatrix,
1980
- worldColor,
1981
- offset
1982
- }) {
1983
- const renderTarget = this._renderer.renderTarget.renderTarget;
1984
- const currentGlobalUniformData = this._stackIndex ? this._globalUniformDataStack[this._stackIndex - 1] : {
1985
- worldTransformMatrix: new Matrix(),
1986
- worldColor: 4294967295,
1987
- offset: new Point()
1988
- };
1989
- const globalUniformData = {
1990
- projectionMatrix: projectionMatrix || this._renderer.renderTarget.projectionMatrix,
1991
- resolution: size || renderTarget.size,
1992
- worldTransformMatrix: worldTransformMatrix || currentGlobalUniformData.worldTransformMatrix,
1993
- worldColor: worldColor || currentGlobalUniformData.worldColor,
1994
- offset: offset || currentGlobalUniformData.offset,
1995
- bindGroup: null
1996
- };
1997
- const uniformGroup = this._uniformsPool.pop() || this._createUniforms();
1998
- this._activeUniforms.push(uniformGroup);
1999
- const uniforms = uniformGroup.uniforms;
2000
- uniforms.uProjectionMatrix = globalUniformData.projectionMatrix;
2001
- uniforms.uResolution = globalUniformData.resolution;
2002
- uniforms.uWorldTransformMatrix.copyFrom(globalUniformData.worldTransformMatrix);
2003
- uniforms.uWorldTransformMatrix.tx -= globalUniformData.offset.x;
2004
- uniforms.uWorldTransformMatrix.ty -= globalUniformData.offset.y;
2005
- color32BitToUniform(
2006
- globalUniformData.worldColor,
2007
- uniforms.uWorldColorAlpha,
2008
- 0
2009
- );
2010
- uniformGroup.update();
2011
- let bindGroup;
2012
- if (this._renderer.renderPipes.uniformBatch) {
2013
- bindGroup = this._renderer.renderPipes.uniformBatch.getUniformBindGroup(uniformGroup, false);
2014
- } else {
2015
- bindGroup = this._bindGroupPool.pop() || new BindGroup();
2016
- this._activeBindGroups.push(bindGroup);
2017
- bindGroup.setResource(uniformGroup, 0);
2018
- }
2019
- globalUniformData.bindGroup = bindGroup;
2020
- this._currentGlobalUniformData = globalUniformData;
2021
- }
2022
- push(options) {
2023
- this.bind(options);
2024
- this._globalUniformDataStack[this._stackIndex++] = this._currentGlobalUniformData;
2025
- }
2026
- pop() {
2027
- this._currentGlobalUniformData = this._globalUniformDataStack[--this._stackIndex - 1];
2028
- if (this._renderer.type === RendererType.WEBGL) {
2029
- this._currentGlobalUniformData.bindGroup.resources[0].update();
2030
- }
2031
- }
2032
- get bindGroup() {
2033
- return this._currentGlobalUniformData.bindGroup;
2034
- }
2035
- get globalUniformData() {
2036
- return this._currentGlobalUniformData;
2037
- }
2038
- get uniformGroup() {
2039
- return this._currentGlobalUniformData.bindGroup.resources[0];
2040
- }
2041
- _createUniforms() {
2042
- const globalUniforms = new UniformGroup({
2043
- uProjectionMatrix: { value: new Matrix(), type: "mat3x3<f32>" },
2044
- uWorldTransformMatrix: { value: new Matrix(), type: "mat3x3<f32>" },
2045
- // TODO - someone smart - set this to be a unorm8x4 rather than a vec4<f32>
2046
- uWorldColorAlpha: { value: new Float32Array(4), type: "vec4<f32>" },
2047
- uResolution: { value: [0, 0], type: "vec2<f32>" }
2048
- }, {
2049
- isStatic: true
2050
- });
2051
- return globalUniforms;
2052
- }
2053
- destroy() {
2054
- this._renderer = null;
2055
- this._globalUniformDataStack.length = 0;
2056
- this._uniformsPool.length = 0;
2057
- this._activeUniforms.length = 0;
2058
- this._bindGroupPool.length = 0;
2059
- this._activeBindGroups.length = 0;
2060
- this._currentGlobalUniformData = null;
2061
- }
2062
- }
2063
- GlobalUniformSystem.extension = {
2064
- type: [
2065
- ExtensionType.WebGLSystem,
2066
- ExtensionType.WebGPUSystem,
2067
- ExtensionType.CanvasSystem
2068
- ],
2069
- name: "globalUniforms"
2070
- };
2071
- let uid = 1;
2072
- class SchedulerSystem {
2073
- constructor() {
2074
- this._tasks = [];
2075
- this._offset = 0;
2076
- }
2077
- /** Initializes the scheduler system and starts the ticker. */
2078
- init() {
2079
- Ticker.system.add(this._update, this);
2080
- }
2081
- /**
2082
- * Schedules a repeating task.
2083
- * @param func - The function to execute.
2084
- * @param duration - The interval duration in milliseconds.
2085
- * @param useOffset - this will spread out tasks so that they do not all run at the same time
2086
- * @returns The unique identifier for the scheduled task.
2087
- */
2088
- repeat(func, duration, useOffset = true) {
2089
- const id = uid++;
2090
- let offset = 0;
2091
- if (useOffset) {
2092
- this._offset += 1e3;
2093
- offset = this._offset;
2094
- }
2095
- this._tasks.push({
2096
- func,
2097
- duration,
2098
- start: performance.now(),
2099
- offset,
2100
- last: performance.now(),
2101
- repeat: true,
2102
- id
2103
- });
2104
- return id;
2105
- }
2106
- /**
2107
- * Cancels a scheduled task.
2108
- * @param id - The unique identifier of the task to cancel.
2109
- */
2110
- cancel(id) {
2111
- for (let i = 0; i < this._tasks.length; i++) {
2112
- if (this._tasks[i].id === id) {
2113
- this._tasks.splice(i, 1);
2114
- return;
2115
- }
2116
- }
2117
- }
2118
- /**
2119
- * Updates and executes the scheduled tasks.
2120
- * @private
2121
- */
2122
- _update() {
2123
- const now = performance.now();
2124
- for (let i = 0; i < this._tasks.length; i++) {
2125
- const task = this._tasks[i];
2126
- if (now - task.offset - task.last >= task.duration) {
2127
- const elapsed = now - task.start;
2128
- task.func(elapsed);
2129
- task.last = now;
2130
- }
2131
- }
2132
- }
2133
- /**
2134
- * Destroys the scheduler system and removes all tasks.
2135
- * @internal
2136
- */
2137
- destroy() {
2138
- Ticker.system.remove(this._update, this);
2139
- this._tasks.length = 0;
2140
- }
2141
- }
2142
- SchedulerSystem.extension = {
2143
- type: [
2144
- ExtensionType.WebGLSystem,
2145
- ExtensionType.WebGPUSystem,
2146
- ExtensionType.CanvasSystem
2147
- ],
2148
- name: "scheduler",
2149
- priority: 0
2150
- };
2151
- let saidHello = false;
2152
- function sayHello(type) {
2153
- if (saidHello) {
2154
- return;
2155
- }
2156
- if (DOMAdapter.get().getNavigator().userAgent.toLowerCase().indexOf("chrome") > -1) {
2157
- const args = [
2158
- `%c %c %c %c %c PixiJS %c v${VERSION} (${type}) http://www.pixijs.com/
2159
-
2160
- `,
2161
- "background: #E72264; padding:5px 0;",
2162
- "background: #6CA2EA; padding:5px 0;",
2163
- "background: #B5D33D; padding:5px 0;",
2164
- "background: #FED23F; padding:5px 0;",
2165
- "color: #FFFFFF; background: #E72264; padding:5px 0;",
2166
- "color: #E72264; background: #FFFFFF; padding:5px 0;"
2167
- ];
2168
- globalThis.console.log(...args);
2169
- } else if (globalThis.console) {
2170
- globalThis.console.log(`PixiJS ${VERSION} - ${type} - http://www.pixijs.com/`);
2171
- }
2172
- saidHello = true;
2173
- }
2174
- class HelloSystem {
2175
- constructor(renderer) {
2176
- this._renderer = renderer;
2177
- }
2178
- /**
2179
- * It all starts here! This initiates every system, passing in the options for any system by name.
2180
- * @param options - the config for the renderer and all its systems
2181
- */
2182
- init(options) {
2183
- if (options.hello) {
2184
- let name = this._renderer.name;
2185
- if (this._renderer.type === RendererType.WEBGL) {
2186
- name += ` ${this._renderer.context.webGLVersion}`;
2187
- }
2188
- sayHello(name);
2189
- }
2190
- }
2191
- }
2192
- HelloSystem.extension = {
2193
- type: [
2194
- ExtensionType.WebGLSystem,
2195
- ExtensionType.WebGPUSystem,
2196
- ExtensionType.CanvasSystem
2197
- ],
2198
- name: "hello",
2199
- priority: -2
2200
- };
2201
- HelloSystem.defaultOptions = {
2202
- /** {@link WebGLOptions.hello} */
2203
- hello: false
2204
- };
2205
- const _RenderableGCSystem = class _RenderableGCSystem2 {
2206
- /**
2207
- * Creates a new RenderableGCSystem instance.
2208
- * @param renderer - The renderer this garbage collection system works for
2209
- */
2210
- constructor(renderer) {
2211
- this._renderer = renderer;
2212
- }
2213
- /**
2214
- * Initializes the garbage collection system with the provided options.
2215
- * @param options - Configuration options for the renderer
2216
- */
2217
- init(options) {
2218
- options = { ..._RenderableGCSystem2.defaultOptions, ...options };
2219
- this.maxUnusedTime = options.renderableGCMaxUnusedTime;
2220
- }
2221
- /**
2222
- * Gets whether the garbage collection system is currently enabled.
2223
- * @returns True if GC is enabled, false otherwise
2224
- */
2225
- get enabled() {
2226
- deprecation("8.15.0", "RenderableGCSystem.enabled is deprecated, please use the GCSystem.enabled instead.");
2227
- return this._renderer.gc.enabled;
2228
- }
2229
- /**
2230
- * Enables or disables the garbage collection system.
2231
- * When enabled, schedules periodic cleanup of resources.
2232
- * When disabled, cancels all scheduled cleanups.
2233
- */
2234
- set enabled(value) {
2235
- deprecation("8.15.0", "RenderableGCSystem.enabled is deprecated, please use the GCSystem.enabled instead.");
2236
- this._renderer.gc.enabled = value;
2237
- }
2238
- /**
2239
- * Adds a hash table to be managed by the garbage collector.
2240
- * @param context - The object containing the hash table
2241
- * @param hash - The property name of the hash table
2242
- */
2243
- addManagedHash(context, hash) {
2244
- deprecation("8.15.0", "RenderableGCSystem.addManagedHash is deprecated, please use the GCSystem.addCollection instead.");
2245
- this._renderer.gc.addCollection(context, hash, "hash");
2246
- }
2247
- /**
2248
- * Adds an array to be managed by the garbage collector.
2249
- * @param context - The object containing the array
2250
- * @param hash - The property name of the array
2251
- */
2252
- addManagedArray(context, hash) {
2253
- deprecation("8.15.0", "RenderableGCSystem.addManagedArray is deprecated, please use the GCSystem.addCollection instead.");
2254
- this._renderer.gc.addCollection(context, hash, "array");
2255
- }
2256
- /**
2257
- * Starts tracking a renderable for garbage collection.
2258
- * @param _renderable - The renderable to track
2259
- * @deprecated since 8.15.0
2260
- */
2261
- addRenderable(_renderable) {
2262
- deprecation("8.15.0", "RenderableGCSystem.addRenderable is deprecated, please use the GCSystem instead.");
2263
- this._renderer.gc.addResource(_renderable, "renderable");
2264
- }
2265
- /**
2266
- * Performs garbage collection by cleaning up unused renderables.
2267
- * Removes renderables that haven't been used for longer than maxUnusedTime.
2268
- */
2269
- run() {
2270
- deprecation("8.15.0", "RenderableGCSystem.run is deprecated, please use the GCSystem instead.");
2271
- this._renderer.gc.run();
2272
- }
2273
- /** Cleans up the garbage collection system. Disables GC and removes all tracked resources. */
2274
- destroy() {
2275
- this._renderer = null;
2276
- }
2277
- };
2278
- _RenderableGCSystem.extension = {
2279
- type: [
2280
- ExtensionType.WebGLSystem,
2281
- ExtensionType.WebGPUSystem,
2282
- ExtensionType.CanvasSystem
2283
- ],
2284
- name: "renderableGC",
2285
- priority: 0
2286
- };
2287
- _RenderableGCSystem.defaultOptions = {
2288
- /** Enable/disable the garbage collector */
2289
- renderableGCActive: true,
2290
- /** Time in ms before an unused resource is collected (default 1 minute) */
2291
- renderableGCMaxUnusedTime: 6e4,
2292
- /** How often to run garbage collection in ms (default 30 seconds) */
2293
- renderableGCFrequency: 3e4
2294
- };
2295
- let RenderableGCSystem = _RenderableGCSystem;
2296
- const _TextureGCSystem = class _TextureGCSystem2 {
2297
- /**
2298
- * Frame count since started.
2299
- * @readonly
2300
- * @deprecated since 8.15.0
2301
- */
2302
- get count() {
2303
- return this._renderer.tick;
2304
- }
2305
- /**
2306
- * Frame count since last garbage collection.
2307
- * @readonly
2308
- * @deprecated since 8.15.0
2309
- */
2310
- get checkCount() {
2311
- return this._checkCount;
2312
- }
2313
- set checkCount(value) {
2314
- deprecation("8.15.0", "TextureGCSystem.run is deprecated, please use the GCSystem instead.");
2315
- this._checkCount = value;
2316
- }
2317
- /**
2318
- * Maximum idle frames before a texture is destroyed by garbage collection.
2319
- * @see TextureGCSystem.defaultMaxIdle
2320
- * @deprecated since 8.15.0
2321
- */
2322
- get maxIdle() {
2323
- return this._renderer.gc.maxUnusedTime / 1e3 * 60;
2324
- }
2325
- set maxIdle(value) {
2326
- deprecation("8.15.0", "TextureGCSystem.run is deprecated, please use the GCSystem instead.");
2327
- this._renderer.gc.maxUnusedTime = value / 60 * 1e3;
2328
- }
2329
- /**
2330
- * Frames between two garbage collections.
2331
- * @see TextureGCSystem.defaultCheckCountMax
2332
- * @deprecated since 8.15.0
2333
- */
2334
- // eslint-disable-next-line dot-notation
2335
- get checkCountMax() {
2336
- return Math.floor(this._renderer.gc["_frequency"] / 1e3);
2337
- }
2338
- set checkCountMax(_value) {
2339
- deprecation("8.15.0", "TextureGCSystem.run is deprecated, please use the GCSystem instead.");
2340
- }
2341
- /**
2342
- * Current garbage collection mode.
2343
- * @see TextureGCSystem.defaultMode
2344
- * @deprecated since 8.15.0
2345
- */
2346
- get active() {
2347
- return this._renderer.gc.enabled;
2348
- }
2349
- set active(value) {
2350
- deprecation("8.15.0", "TextureGCSystem.run is deprecated, please use the GCSystem instead.");
2351
- this._renderer.gc.enabled = value;
2352
- }
2353
- /** @param renderer - The renderer this System works for. */
2354
- constructor(renderer) {
2355
- this._renderer = renderer;
2356
- this._checkCount = 0;
2357
- }
2358
- init(options) {
2359
- if (options.textureGCActive !== _TextureGCSystem2.defaultOptions.textureGCActive) {
2360
- this.active = options.textureGCActive;
2361
- }
2362
- if (options.textureGCMaxIdle !== _TextureGCSystem2.defaultOptions.textureGCMaxIdle) {
2363
- this.maxIdle = options.textureGCMaxIdle;
2364
- }
2365
- if (options.textureGCCheckCountMax !== _TextureGCSystem2.defaultOptions.textureGCCheckCountMax) {
2366
- this.checkCountMax = options.textureGCCheckCountMax;
2367
- }
2368
- }
2369
- /**
2370
- * Checks to see when the last time a texture was used.
2371
- * If the texture has not been used for a specified amount of time, it will be removed from the GPU.
2372
- * @deprecated since 8.15.0
2373
- */
2374
- run() {
2375
- deprecation("8.15.0", "TextureGCSystem.run is deprecated, please use the GCSystem instead.");
2376
- this._renderer.gc.run();
2377
- }
2378
- destroy() {
2379
- this._renderer = null;
2380
- }
2381
- };
2382
- _TextureGCSystem.extension = {
2383
- type: [
2384
- ExtensionType.WebGLSystem,
2385
- ExtensionType.WebGPUSystem
2386
- ],
2387
- name: "textureGC"
2388
- };
2389
- _TextureGCSystem.defaultOptions = {
2390
- /**
2391
- * If set to true, this will enable the garbage collector on the GPU.
2392
- * @default true
2393
- */
2394
- textureGCActive: true,
2395
- /**
2396
- * @deprecated since 8.3.0
2397
- * @see {@link TextureGCSystemOptions.textureGCMaxIdle}
2398
- */
2399
- textureGCAMaxIdle: null,
2400
- /**
2401
- * The maximum idle frames before a texture is destroyed by garbage collection.
2402
- * @default 60 * 60
2403
- */
2404
- textureGCMaxIdle: 60 * 60,
2405
- /**
2406
- * Frames between two garbage collections.
2407
- * @default 600
2408
- */
2409
- textureGCCheckCountMax: 600
2410
- };
2411
- let TextureGCSystem = _TextureGCSystem;
2412
- const _RenderTarget = class _RenderTarget2 {
2413
- /**
2414
- * @param [descriptor] - Options for creating a render target.
2415
- */
2416
- constructor(descriptor = {}) {
2417
- this.uid = uid$1("renderTarget");
2418
- this.colorTextures = [];
2419
- this.dirtyId = 0;
2420
- this.isRoot = false;
2421
- this._size = new Float32Array(2);
2422
- this._managedColorTextures = false;
2423
- descriptor = { ..._RenderTarget2.defaultOptions, ...descriptor };
2424
- this.stencil = descriptor.stencil;
2425
- this.depth = descriptor.depth;
2426
- this.isRoot = descriptor.isRoot;
2427
- if (typeof descriptor.colorTextures === "number") {
2428
- this._managedColorTextures = true;
2429
- for (let i = 0; i < descriptor.colorTextures; i++) {
2430
- this.colorTextures.push(
2431
- new TextureSource({
2432
- width: descriptor.width,
2433
- height: descriptor.height,
2434
- resolution: descriptor.resolution,
2435
- antialias: descriptor.antialias
2436
- })
2437
- );
2438
- }
2439
- } else {
2440
- this.colorTextures = [...descriptor.colorTextures.map((texture) => texture.source)];
2441
- const colorSource = this.colorTexture.source;
2442
- this.resize(colorSource.width, colorSource.height, colorSource._resolution);
2443
- }
2444
- this.colorTexture.source.on("resize", this.onSourceResize, this);
2445
- if (descriptor.depthStencilTexture || this.stencil) {
2446
- if (descriptor.depthStencilTexture instanceof Texture || descriptor.depthStencilTexture instanceof TextureSource) {
2447
- this.depthStencilTexture = descriptor.depthStencilTexture.source;
2448
- } else {
2449
- this.ensureDepthStencilTexture();
2450
- }
2451
- }
2452
- }
2453
- get size() {
2454
- const _size = this._size;
2455
- _size[0] = this.pixelWidth;
2456
- _size[1] = this.pixelHeight;
2457
- return _size;
2458
- }
2459
- get width() {
2460
- return this.colorTexture.source.width;
2461
- }
2462
- get height() {
2463
- return this.colorTexture.source.height;
2464
- }
2465
- get pixelWidth() {
2466
- return this.colorTexture.source.pixelWidth;
2467
- }
2468
- get pixelHeight() {
2469
- return this.colorTexture.source.pixelHeight;
2470
- }
2471
- get resolution() {
2472
- return this.colorTexture.source._resolution;
2473
- }
2474
- get colorTexture() {
2475
- return this.colorTextures[0];
2476
- }
2477
- onSourceResize(source2) {
2478
- this.resize(source2.width, source2.height, source2._resolution, true);
2479
- }
2480
- /**
2481
- * This will ensure a depthStencil texture is created for this render target.
2482
- * Most likely called by the mask system to make sure we have stencil buffer added.
2483
- * @internal
2484
- */
2485
- ensureDepthStencilTexture() {
2486
- if (!this.depthStencilTexture) {
2487
- this.depthStencilTexture = new TextureSource({
2488
- width: this.width,
2489
- height: this.height,
2490
- resolution: this.resolution,
2491
- format: "depth24plus-stencil8",
2492
- autoGenerateMipmaps: false,
2493
- antialias: false,
2494
- mipLevelCount: 1
2495
- // sampleCount: handled by the render target system..
2496
- });
2497
- }
2498
- }
2499
- resize(width, height, resolution = this.resolution, skipColorTexture = false) {
2500
- this.dirtyId++;
2501
- this.colorTextures.forEach((colorTexture, i) => {
2502
- if (skipColorTexture && i === 0) return;
2503
- colorTexture.source.resize(width, height, resolution);
2504
- });
2505
- if (this.depthStencilTexture) {
2506
- this.depthStencilTexture.source.resize(width, height, resolution);
2507
- }
2508
- }
2509
- destroy() {
2510
- this.colorTexture.source.off("resize", this.onSourceResize, this);
2511
- if (this._managedColorTextures) {
2512
- this.colorTextures.forEach((texture) => {
2513
- texture.destroy();
2514
- });
2515
- }
2516
- if (this.depthStencilTexture) {
2517
- this.depthStencilTexture.destroy();
2518
- delete this.depthStencilTexture;
2519
- }
2520
- }
2521
- };
2522
- _RenderTarget.defaultOptions = {
2523
- /** the width of the RenderTarget */
2524
- width: 0,
2525
- /** the height of the RenderTarget */
2526
- height: 0,
2527
- /** the resolution of the RenderTarget */
2528
- resolution: 1,
2529
- /** an array of textures, or a number indicating how many color textures there should be */
2530
- colorTextures: 1,
2531
- /** should this render target have a stencil buffer? */
2532
- stencil: false,
2533
- /** should this render target have a depth buffer? */
2534
- depth: false,
2535
- /** should this render target be antialiased? */
2536
- antialias: false,
2537
- // save on perf by default!
2538
- /** is this a root element, true if this is gl context owners render target */
2539
- isRoot: false
2540
- };
2541
- let RenderTarget = _RenderTarget;
2542
- const canvasCache = /* @__PURE__ */ new Map();
2543
- GlobalResourceRegistry.register(canvasCache);
2544
- function getCanvasTexture(canvas, options) {
2545
- if (!canvasCache.has(canvas)) {
2546
- const texture = new Texture({
2547
- source: new CanvasSource({
2548
- resource: canvas,
2549
- ...options
2550
- })
2551
- });
2552
- const onDestroy = () => {
2553
- if (canvasCache.get(canvas) === texture) {
2554
- canvasCache.delete(canvas);
2555
- }
2556
- };
2557
- texture.once("destroy", onDestroy);
2558
- texture.source.once("destroy", onDestroy);
2559
- canvasCache.set(canvas, texture);
2560
- }
2561
- return canvasCache.get(canvas);
2562
- }
2563
- const _ViewSystem = class _ViewSystem2 {
2564
- /**
2565
- * Whether CSS dimensions of canvas view should be resized to screen dimensions automatically.
2566
- * This is only supported for HTMLCanvasElement and will be ignored if the canvas is an OffscreenCanvas.
2567
- * @type {boolean}
2568
- */
2569
- get autoDensity() {
2570
- return this.texture.source.autoDensity;
2571
- }
2572
- set autoDensity(value) {
2573
- this.texture.source.autoDensity = value;
2574
- }
2575
- /** The resolution / device pixel ratio of the renderer. */
2576
- get resolution() {
2577
- return this.texture.source._resolution;
2578
- }
2579
- set resolution(value) {
2580
- this.texture.source.resize(
2581
- this.texture.source.width,
2582
- this.texture.source.height,
2583
- value
2584
- );
2585
- }
2586
- /**
2587
- * initiates the view system
2588
- * @param options - the options for the view
2589
- */
2590
- init(options) {
2591
- options = {
2592
- ..._ViewSystem2.defaultOptions,
2593
- ...options
2594
- };
2595
- if (options.view) {
2596
- deprecation(v8_0_0, "ViewSystem.view has been renamed to ViewSystem.canvas");
2597
- options.canvas = options.view;
2598
- }
2599
- this.screen = new Rectangle(0, 0, options.width, options.height);
2600
- this.canvas = options.canvas || DOMAdapter.get().createCanvas();
2601
- this.antialias = !!options.antialias;
2602
- this.texture = getCanvasTexture(this.canvas, options);
2603
- this.renderTarget = new RenderTarget({
2604
- colorTextures: [this.texture],
2605
- depth: !!options.depth,
2606
- isRoot: true
2607
- });
2608
- this.texture.source.transparent = options.backgroundAlpha < 1;
2609
- this.resolution = options.resolution;
2610
- }
2611
- /**
2612
- * Resizes the screen and canvas to the specified dimensions.
2613
- * @param desiredScreenWidth - The new width of the screen.
2614
- * @param desiredScreenHeight - The new height of the screen.
2615
- * @param resolution
2616
- */
2617
- resize(desiredScreenWidth, desiredScreenHeight, resolution) {
2618
- this.texture.source.resize(desiredScreenWidth, desiredScreenHeight, resolution);
2619
- this.screen.width = this.texture.frame.width;
2620
- this.screen.height = this.texture.frame.height;
2621
- }
2622
- /**
2623
- * Destroys this System and optionally removes the canvas from the dom.
2624
- * @param {options | false} options - The options for destroying the view, or "false".
2625
- * @example
2626
- * viewSystem.destroy();
2627
- * viewSystem.destroy(true);
2628
- * viewSystem.destroy({ removeView: true });
2629
- */
2630
- destroy(options = false) {
2631
- const removeView = typeof options === "boolean" ? options : !!(options == null ? void 0 : options.removeView);
2632
- if (removeView && this.canvas.parentNode) {
2633
- this.canvas.parentNode.removeChild(this.canvas);
2634
- }
2635
- this.texture.destroy();
2636
- }
2637
- };
2638
- _ViewSystem.extension = {
2639
- type: [
2640
- ExtensionType.WebGLSystem,
2641
- ExtensionType.WebGPUSystem,
2642
- ExtensionType.CanvasSystem
2643
- ],
2644
- name: "view",
2645
- priority: 0
2646
- };
2647
- _ViewSystem.defaultOptions = {
2648
- /**
2649
- * {@link WebGLOptions.width}
2650
- * @default 800
2651
- */
2652
- width: 800,
2653
- /**
2654
- * {@link WebGLOptions.height}
2655
- * @default 600
2656
- */
2657
- height: 600,
2658
- /**
2659
- * {@link WebGLOptions.autoDensity}
2660
- * @default false
2661
- */
2662
- autoDensity: false,
2663
- /**
2664
- * {@link WebGLOptions.antialias}
2665
- * @default false
2666
- */
2667
- antialias: false
2668
- };
2669
- let ViewSystem = _ViewSystem;
2670
- const SharedSystems = [
2671
- BackgroundSystem,
2672
- GlobalUniformSystem,
2673
- HelloSystem,
2674
- ViewSystem,
2675
- RenderGroupSystem,
2676
- GCSystem,
2677
- TextureGCSystem,
2678
- GenerateTextureSystem,
2679
- ExtractSystem,
2680
- RendererInitHook,
2681
- RenderableGCSystem,
2682
- SchedulerSystem
2683
- ];
2684
- const SharedRenderPipes = [
2685
- BlendModePipe,
2686
- BatcherPipe,
2687
- SpritePipe,
2688
- RenderGroupPipe,
2689
- AlphaMaskPipe,
2690
- StencilMaskPipe,
2691
- ColorMaskPipe,
2692
- CustomRenderPipe
2693
- ];
2694
- function calculateProjection(pm, x, y, width, height, flipY) {
2695
- const sign = flipY ? 1 : -1;
2696
- pm.identity();
2697
- pm.a = 1 / width * 2;
2698
- pm.d = sign * (1 / height * 2);
2699
- pm.tx = -1 - x * pm.a;
2700
- pm.ty = -sign - y * pm.d;
2701
- return pm;
2702
- }
2703
- function isRenderingToScreen(renderTarget) {
2704
- const resource = renderTarget.colorTexture.source.resource;
2705
- return globalThis.HTMLCanvasElement && resource instanceof HTMLCanvasElement && document.body.contains(resource);
2706
- }
2707
- class RenderTargetSystem {
2708
- constructor(renderer) {
2709
- this.rootViewPort = new Rectangle();
2710
- this.viewport = new Rectangle();
2711
- this.mipLevel = 0;
2712
- this.layer = 0;
2713
- this.onRenderTargetChange = new SystemRunner("onRenderTargetChange");
2714
- this.projectionMatrix = new Matrix();
2715
- this.defaultClearColor = [0, 0, 0, 0];
2716
- this._renderSurfaceToRenderTargetHash = /* @__PURE__ */ new Map();
2717
- this._gpuRenderTargetHash = /* @__PURE__ */ Object.create(null);
2718
- this._renderTargetStack = [];
2719
- this._renderer = renderer;
2720
- renderer.gc.addCollection(this, "_gpuRenderTargetHash", "hash");
2721
- }
2722
- /** called when dev wants to finish a render pass */
2723
- finishRenderPass() {
2724
- this.adaptor.finishRenderPass(this.renderTarget);
2725
- }
2726
- /**
2727
- * called when the renderer starts to render a scene.
2728
- * @param options
2729
- * @param options.target - the render target to render to
2730
- * @param options.clear - the clear mode to use. Can be true or a CLEAR number 'COLOR | DEPTH | STENCIL' 0b111
2731
- * @param options.clearColor - the color to clear to
2732
- * @param options.frame - the frame to render to
2733
- * @param options.mipLevel - the mip level to render to
2734
- * @param options.layer - The layer of the render target to render to. Used for array or 3D textures, or when rendering
2735
- * to a specific layer of a layered render target. Optional.
2736
- */
2737
- renderStart({
2738
- target,
2739
- clear,
2740
- clearColor,
2741
- frame,
2742
- mipLevel,
2743
- layer
2744
- }) {
2745
- var _a, _b;
2746
- this._renderTargetStack.length = 0;
2747
- this.push(
2748
- target,
2749
- clear,
2750
- clearColor,
2751
- frame,
2752
- mipLevel ?? 0,
2753
- layer ?? 0
2754
- );
2755
- this.rootViewPort.copyFrom(this.viewport);
2756
- this.rootRenderTarget = this.renderTarget;
2757
- this.renderingToScreen = isRenderingToScreen(this.rootRenderTarget);
2758
- (_b = (_a = this.adaptor).prerender) == null ? void 0 : _b.call(_a, this.rootRenderTarget);
2759
- }
2760
- postrender() {
2761
- var _a, _b;
2762
- (_b = (_a = this.adaptor).postrender) == null ? void 0 : _b.call(_a, this.rootRenderTarget);
2763
- }
2764
- /**
2765
- * Binding a render surface! This is the main function of the render target system.
2766
- * It will take the RenderSurface (which can be a texture, canvas, or render target) and bind it to the renderer.
2767
- * Once bound all draw calls will be rendered to the render surface.
2768
- *
2769
- * If a frame is not provided and the render surface is a {@link Texture}, the frame of the texture will be used.
2770
- *
2771
- * IMPORTANT:
2772
- * - `frame` is treated as **base mip (mip 0) pixel space**.
2773
- * - When `mipLevel > 0`, the viewport derived from `frame` is scaled by \(2^{mipLevel}\) and clamped to the
2774
- * mip dimensions. This keeps "render the same region" semantics consistent across mip levels.
2775
- * - When `renderSurface` is a {@link Texture}, `renderer.render({ container, target: texture, mipLevel })` will
2776
- * render into
2777
- * the underlying {@link TextureSource} (Pixi will create/use a {@link RenderTarget} for the source) using the
2778
- * texture's frame to define the region (in mip 0 space).
2779
- * @param renderSurface - the render surface to bind
2780
- * @param clear - the clear mode to use. Can be true or a CLEAR number 'COLOR | DEPTH | STENCIL' 0b111
2781
- * @param clearColor - the color to clear to
2782
- * @param frame - the frame to render to
2783
- * @param mipLevel - the mip level to render to
2784
- * @param layer - the layer (or slice) of the render surface to render to. For array textures,
2785
- * 3D textures, or cubemaps, this specifies the target layer or face. Defaults to 0 (the first layer/face).
2786
- * Ignored for surfaces that do not support layers.
2787
- * @returns the render target that was bound
2788
- */
2789
- bind(renderSurface, clear = true, clearColor, frame, mipLevel = 0, layer = 0) {
2790
- const renderTarget = this.getRenderTarget(renderSurface);
2791
- const didChange = this.renderTarget !== renderTarget;
2792
- this.renderTarget = renderTarget;
2793
- this.renderSurface = renderSurface;
2794
- const gpuRenderTarget = this.getGpuRenderTarget(renderTarget);
2795
- if (renderTarget.pixelWidth !== gpuRenderTarget.width || renderTarget.pixelHeight !== gpuRenderTarget.height) {
2796
- this.adaptor.resizeGpuRenderTarget(renderTarget);
2797
- gpuRenderTarget.width = renderTarget.pixelWidth;
2798
- gpuRenderTarget.height = renderTarget.pixelHeight;
2799
- }
2800
- const source2 = renderTarget.colorTexture;
2801
- const viewport = this.viewport;
2802
- const arrayLayerCount = source2.arrayLayerCount || 1;
2803
- if ((layer | 0) !== layer) {
2804
- layer |= 0;
2805
- }
2806
- if (layer < 0 || layer >= arrayLayerCount) {
2807
- throw new Error(`[RenderTargetSystem] layer ${layer} is out of bounds (arrayLayerCount=${arrayLayerCount}).`);
2808
- }
2809
- this.mipLevel = mipLevel | 0;
2810
- this.layer = layer | 0;
2811
- const pixelWidth = Math.max(source2.pixelWidth >> mipLevel, 1);
2812
- const pixelHeight = Math.max(source2.pixelHeight >> mipLevel, 1);
2813
- if (!frame && renderSurface instanceof Texture) {
2814
- frame = renderSurface.frame;
2815
- }
2816
- if (frame) {
2817
- const resolution = source2._resolution;
2818
- const scale = 1 << Math.max(mipLevel | 0, 0);
2819
- const baseX = frame.x * resolution + 0.5 | 0;
2820
- const baseY = frame.y * resolution + 0.5 | 0;
2821
- const baseW = frame.width * resolution + 0.5 | 0;
2822
- const baseH = frame.height * resolution + 0.5 | 0;
2823
- let x = Math.floor(baseX / scale);
2824
- let y = Math.floor(baseY / scale);
2825
- let w = Math.ceil(baseW / scale);
2826
- let h = Math.ceil(baseH / scale);
2827
- x = Math.min(Math.max(x, 0), pixelWidth - 1);
2828
- y = Math.min(Math.max(y, 0), pixelHeight - 1);
2829
- w = Math.min(Math.max(w, 1), pixelWidth - x);
2830
- h = Math.min(Math.max(h, 1), pixelHeight - y);
2831
- viewport.x = x;
2832
- viewport.y = y;
2833
- viewport.width = w;
2834
- viewport.height = h;
2835
- } else {
2836
- viewport.x = 0;
2837
- viewport.y = 0;
2838
- viewport.width = pixelWidth;
2839
- viewport.height = pixelHeight;
2840
- }
2841
- calculateProjection(
2842
- this.projectionMatrix,
2843
- 0,
2844
- 0,
2845
- viewport.width / source2.resolution,
2846
- viewport.height / source2.resolution,
2847
- !renderTarget.isRoot
2848
- );
2849
- this.adaptor.startRenderPass(renderTarget, clear, clearColor, viewport, mipLevel, layer);
2850
- if (didChange) {
2851
- this.onRenderTargetChange.emit(renderTarget);
2852
- }
2853
- return renderTarget;
2854
- }
2855
- clear(target, clear = CLEAR.ALL, clearColor, mipLevel = this.mipLevel, layer = this.layer) {
2856
- if (!clear) return;
2857
- if (target) {
2858
- target = this.getRenderTarget(target);
2859
- }
2860
- this.adaptor.clear(
2861
- target || this.renderTarget,
2862
- clear,
2863
- clearColor,
2864
- this.viewport,
2865
- mipLevel,
2866
- layer
2867
- );
2868
- }
2869
- contextChange() {
2870
- this._gpuRenderTargetHash = /* @__PURE__ */ Object.create(null);
2871
- }
2872
- /**
2873
- * Push a render surface to the renderer. This will bind the render surface to the renderer,
2874
- * @param renderSurface - the render surface to push
2875
- * @param clear - the clear mode to use. Can be true or a CLEAR number 'COLOR | DEPTH | STENCIL' 0b111
2876
- * @param clearColor - the color to clear to
2877
- * @param frame - the frame to use when rendering to the render surface
2878
- * @param mipLevel - the mip level to render to
2879
- * @param layer - The layer of the render surface to render to. For array textures or cube maps, this specifies
2880
- * which layer or face to target. Defaults to 0 (the first layer).
2881
- */
2882
- push(renderSurface, clear = CLEAR.ALL, clearColor, frame, mipLevel = 0, layer = 0) {
2883
- const renderTarget = this.bind(renderSurface, clear, clearColor, frame, mipLevel, layer);
2884
- this._renderTargetStack.push({
2885
- renderTarget,
2886
- frame,
2887
- mipLevel,
2888
- layer
2889
- });
2890
- return renderTarget;
2891
- }
2892
- /** Pops the current render target from the renderer and restores the previous render target. */
2893
- pop() {
2894
- this._renderTargetStack.pop();
2895
- const currentRenderTargetData = this._renderTargetStack[this._renderTargetStack.length - 1];
2896
- this.bind(
2897
- currentRenderTargetData.renderTarget,
2898
- false,
2899
- null,
2900
- currentRenderTargetData.frame,
2901
- currentRenderTargetData.mipLevel,
2902
- currentRenderTargetData.layer
2903
- );
2904
- }
2905
- /**
2906
- * Gets the render target from the provide render surface. Eg if its a texture,
2907
- * it will return the render target for the texture.
2908
- * If its a render target, it will return the same render target.
2909
- * @param renderSurface - the render surface to get the render target for
2910
- * @returns the render target for the render surface
2911
- */
2912
- getRenderTarget(renderSurface) {
2913
- if (renderSurface.isTexture) {
2914
- renderSurface = renderSurface.source;
2915
- }
2916
- return this._renderSurfaceToRenderTargetHash.get(renderSurface) ?? this._initRenderTarget(renderSurface);
2917
- }
2918
- /**
2919
- * Copies a render surface to another texture.
2920
- *
2921
- * NOTE:
2922
- * for sourceRenderSurfaceTexture, The render target must be something that is written too by the renderer
2923
- *
2924
- * The following is not valid:
2925
- * @example
2926
- * const canvas = document.createElement('canvas')
2927
- * canvas.width = 200;
2928
- * canvas.height = 200;
2929
- *
2930
- * const ctx = canvas2.getContext('2d')!
2931
- * ctx.fillStyle = 'red'
2932
- * ctx.fillRect(0, 0, 200, 200);
2933
- *
2934
- * const texture = RenderTexture.create({
2935
- * width: 200,
2936
- * height: 200,
2937
- * })
2938
- * const renderTarget = renderer.renderTarget.getRenderTarget(canvas2);
2939
- *
2940
- * renderer.renderTarget.copyToTexture(renderTarget,texture, {x:0,y:0},{width:200,height:200},{x:0,y:0});
2941
- *
2942
- * The best way to copy a canvas is to create a texture from it. Then render with that.
2943
- *
2944
- * Parsing in a RenderTarget canvas context (with a 2d context)
2945
- * @param sourceRenderSurfaceTexture - the render surface to copy from
2946
- * @param {Texture} destinationTexture - the texture to copy to
2947
- * @param {object} originSrc - the origin of the copy
2948
- * @param {number} originSrc.x - the x origin of the copy
2949
- * @param {number} originSrc.y - the y origin of the copy
2950
- * @param {object} size - the size of the copy
2951
- * @param {number} size.width - the width of the copy
2952
- * @param {number} size.height - the height of the copy
2953
- * @param {object} originDest - the destination origin (top left to paste from!)
2954
- * @param {number} originDest.x - the x origin of the paste
2955
- * @param {number} originDest.y - the y origin of the paste
2956
- */
2957
- copyToTexture(sourceRenderSurfaceTexture, destinationTexture, originSrc, size, originDest) {
2958
- if (originSrc.x < 0) {
2959
- size.width += originSrc.x;
2960
- originDest.x -= originSrc.x;
2961
- originSrc.x = 0;
2962
- }
2963
- if (originSrc.y < 0) {
2964
- size.height += originSrc.y;
2965
- originDest.y -= originSrc.y;
2966
- originSrc.y = 0;
2967
- }
2968
- const { pixelWidth, pixelHeight } = sourceRenderSurfaceTexture;
2969
- size.width = Math.min(size.width, pixelWidth - originSrc.x);
2970
- size.height = Math.min(size.height, pixelHeight - originSrc.y);
2971
- return this.adaptor.copyToTexture(
2972
- sourceRenderSurfaceTexture,
2973
- destinationTexture,
2974
- originSrc,
2975
- size,
2976
- originDest
2977
- );
2978
- }
2979
- /**
2980
- * ensures that we have a depth stencil buffer available to render to
2981
- * This is used by the mask system to make sure we have a stencil buffer.
2982
- */
2983
- ensureDepthStencil() {
2984
- if (!this.renderTarget.stencil) {
2985
- this.renderTarget.stencil = true;
2986
- this.adaptor.startRenderPass(this.renderTarget, false, null, this.viewport, 0, this.layer);
2987
- }
2988
- }
2989
- /** nukes the render target system */
2990
- destroy() {
2991
- this._renderer = null;
2992
- this._renderSurfaceToRenderTargetHash.forEach((renderTarget, key) => {
2993
- if (renderTarget !== key) {
2994
- renderTarget.destroy();
2995
- }
2996
- });
2997
- this._renderSurfaceToRenderTargetHash.clear();
2998
- this._gpuRenderTargetHash = /* @__PURE__ */ Object.create(null);
2999
- }
3000
- _initRenderTarget(renderSurface) {
3001
- let renderTarget = null;
3002
- if (CanvasSource.test(renderSurface)) {
3003
- renderSurface = getCanvasTexture(renderSurface).source;
3004
- }
3005
- if (renderSurface instanceof RenderTarget) {
3006
- renderTarget = renderSurface;
3007
- } else if (renderSurface instanceof TextureSource) {
3008
- renderTarget = new RenderTarget({
3009
- colorTextures: [renderSurface]
3010
- });
3011
- if (renderSurface.source instanceof CanvasSource) {
3012
- renderTarget.isRoot = true;
3013
- }
3014
- renderSurface.once("destroy", () => {
3015
- renderTarget.destroy();
3016
- this._renderSurfaceToRenderTargetHash.delete(renderSurface);
3017
- const gpuRenderTarget = this._gpuRenderTargetHash[renderTarget.uid];
3018
- if (gpuRenderTarget) {
3019
- this._gpuRenderTargetHash[renderTarget.uid] = null;
3020
- this.adaptor.destroyGpuRenderTarget(gpuRenderTarget);
3021
- }
3022
- });
3023
- }
3024
- this._renderSurfaceToRenderTargetHash.set(renderSurface, renderTarget);
3025
- return renderTarget;
3026
- }
3027
- getGpuRenderTarget(renderTarget) {
3028
- return this._gpuRenderTargetHash[renderTarget.uid] || (this._gpuRenderTargetHash[renderTarget.uid] = this.adaptor.initGpuRenderTarget(renderTarget));
3029
- }
3030
- resetState() {
3031
- this.renderTarget = null;
3032
- this.renderSurface = null;
3033
- }
3034
- }
3035
- export {
3036
- AlphaMaskPipe as A,
3037
- BlendModePipe as B,
3038
- CustomRenderPipe as C,
3039
- RenderTargetSystem as R,
3040
- SharedSystems as S,
3041
- BatcherPipe as a,
3042
- SpritePipe as b,
3043
- RenderGroupPipe as c,
3044
- SharedRenderPipes as d
3045
- };
3046
- //# sourceMappingURL=RenderTargetSystem-D98tiHim.js.map