@vib3code/sdk 2.0.1

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 (258) hide show
  1. package/CHANGELOG.md +118 -0
  2. package/DOCS/BLUEPRINT_EXECUTION_PLAN_2026-01-07.md +34 -0
  3. package/DOCS/CI_TESTING.md +38 -0
  4. package/DOCS/CLI_ONBOARDING.md +75 -0
  5. package/DOCS/CONTROL_REFERENCE.md +64 -0
  6. package/DOCS/DEV_TRACK_ANALYSIS.md +77 -0
  7. package/DOCS/DEV_TRACK_PLAN_2026-01-07.md +42 -0
  8. package/DOCS/DEV_TRACK_SESSION_2026-01-31.md +220 -0
  9. package/DOCS/ENV_SETUP.md +189 -0
  10. package/DOCS/EXPORT_FORMATS.md +417 -0
  11. package/DOCS/GPU_DISPOSAL_GUIDE.md +21 -0
  12. package/DOCS/LICENSING_TIERS.md +275 -0
  13. package/DOCS/MASTER_PLAN_2026-01-31.md +570 -0
  14. package/DOCS/OBS_SETUP_GUIDE.md +98 -0
  15. package/DOCS/PROJECT_SETUP.md +66 -0
  16. package/DOCS/RENDERER_LIFECYCLE.md +40 -0
  17. package/DOCS/REPO_MANIFEST.md +121 -0
  18. package/DOCS/SESSION_014_PLAN.md +195 -0
  19. package/DOCS/SESSION_LOG_2026-01-07.md +56 -0
  20. package/DOCS/STRATEGIC_BLUEPRINT_2026-01-07.md +72 -0
  21. package/DOCS/SYSTEM_AUDIT_2026-01-30.md +738 -0
  22. package/DOCS/SYSTEM_INVENTORY.md +520 -0
  23. package/DOCS/TELEMETRY_EXPORTS.md +34 -0
  24. package/DOCS/WEBGPU_STATUS.md +38 -0
  25. package/DOCS/XR_BENCHMARKS.md +608 -0
  26. package/LICENSE +21 -0
  27. package/README.md +426 -0
  28. package/docs/.nojekyll +0 -0
  29. package/docs/01-dissolution_of_euclidean_hegemony.html +346 -0
  30. package/docs/02-hyperspatial_ego_death.html +346 -0
  31. package/docs/03-post_cartesian_sublime.html +346 -0
  32. package/docs/04-crystalline_void_meditation.html +346 -0
  33. package/docs/05-quantum_decoherence_ballet.html +346 -0
  34. package/docs/06-dissolution_of_euclidean_hegemony.html +346 -0
  35. package/docs/07-hyperspatial_ego_death.html +346 -0
  36. package/docs/08-post_cartesian_sublime.html +346 -0
  37. package/docs/09-crystalline_void_meditation.html +346 -0
  38. package/docs/10-quantum_decoherence_ballet.html +346 -0
  39. package/docs/11-dissolution_of_euclidean_hegemony.html +346 -0
  40. package/docs/12-hyperspatial_ego_death.html +346 -0
  41. package/docs/13-post_cartesian_sublime.html +346 -0
  42. package/docs/index.html +794 -0
  43. package/docs/test-hub.html +441 -0
  44. package/docs/url-state.js +102 -0
  45. package/docs/vib3-exports/01-quantum-quantum-tetrahedron-lattice.html +489 -0
  46. package/docs/vib3-exports/02-quantum-quantum-hypersphere-matrix.html +489 -0
  47. package/docs/vib3-exports/03-quantum-quantum-hypertetra-fractal.html +489 -0
  48. package/docs/vib3-exports/04-faceted-faceted-crystal-structure.html +407 -0
  49. package/docs/vib3-exports/05-faceted-faceted-klein-bottle.html +407 -0
  50. package/docs/vib3-exports/06-faceted-faceted-hypertetra-torus.html +407 -0
  51. package/docs/vib3-exports/07-holographic-holographic-wave-field.html +457 -0
  52. package/docs/vib3-exports/08-holographic-holographic-hypersphere-sphere.html +457 -0
  53. package/docs/vib3-exports/09-holographic-holographic-hypertetra-crystal.html +457 -0
  54. package/docs/vib3-exports/index.html +238 -0
  55. package/docs/webgpu-live.html +702 -0
  56. package/package.json +367 -0
  57. package/src/advanced/AIPresetGenerator.js +777 -0
  58. package/src/advanced/MIDIController.js +703 -0
  59. package/src/advanced/OffscreenWorker.js +1051 -0
  60. package/src/advanced/WebGPUCompute.js +1051 -0
  61. package/src/advanced/WebXRRenderer.js +680 -0
  62. package/src/agent/cli/AgentCLI.js +615 -0
  63. package/src/agent/cli/index.js +14 -0
  64. package/src/agent/index.js +73 -0
  65. package/src/agent/mcp/MCPServer.js +950 -0
  66. package/src/agent/mcp/index.js +9 -0
  67. package/src/agent/mcp/tools.js +548 -0
  68. package/src/agent/telemetry/EventStream.js +669 -0
  69. package/src/agent/telemetry/Instrumentation.js +618 -0
  70. package/src/agent/telemetry/TelemetryExporters.js +427 -0
  71. package/src/agent/telemetry/TelemetryService.js +464 -0
  72. package/src/agent/telemetry/index.js +52 -0
  73. package/src/benchmarks/BenchmarkRunner.js +381 -0
  74. package/src/benchmarks/MetricsCollector.js +299 -0
  75. package/src/benchmarks/index.js +9 -0
  76. package/src/benchmarks/scenes.js +259 -0
  77. package/src/cli/index.js +675 -0
  78. package/src/config/ApiConfig.js +88 -0
  79. package/src/core/CanvasManager.js +217 -0
  80. package/src/core/ErrorReporter.js +117 -0
  81. package/src/core/ParameterMapper.js +333 -0
  82. package/src/core/Parameters.js +396 -0
  83. package/src/core/RendererContracts.js +200 -0
  84. package/src/core/UnifiedResourceManager.js +370 -0
  85. package/src/core/VIB3Engine.js +636 -0
  86. package/src/core/renderers/FacetedRendererAdapter.js +32 -0
  87. package/src/core/renderers/HolographicRendererAdapter.js +29 -0
  88. package/src/core/renderers/QuantumRendererAdapter.js +29 -0
  89. package/src/core/renderers/RendererLifecycleManager.js +63 -0
  90. package/src/creative/ColorPresetsSystem.js +980 -0
  91. package/src/creative/ParameterTimeline.js +1061 -0
  92. package/src/creative/PostProcessingPipeline.js +1113 -0
  93. package/src/creative/TransitionAnimator.js +683 -0
  94. package/src/export/CSSExporter.js +226 -0
  95. package/src/export/CardGeneratorBase.js +279 -0
  96. package/src/export/ExportManager.js +580 -0
  97. package/src/export/FacetedCardGenerator.js +279 -0
  98. package/src/export/HolographicCardGenerator.js +543 -0
  99. package/src/export/LottieExporter.js +552 -0
  100. package/src/export/QuantumCardGenerator.js +315 -0
  101. package/src/export/SVGExporter.js +519 -0
  102. package/src/export/ShaderExporter.js +903 -0
  103. package/src/export/TradingCardGenerator.js +3055 -0
  104. package/src/export/TradingCardManager.js +181 -0
  105. package/src/export/VIB3PackageExporter.js +559 -0
  106. package/src/export/index.js +14 -0
  107. package/src/export/systems/TradingCardSystemFaceted.js +494 -0
  108. package/src/export/systems/TradingCardSystemHolographic.js +452 -0
  109. package/src/export/systems/TradingCardSystemQuantum.js +411 -0
  110. package/src/faceted/FacetedSystem.js +963 -0
  111. package/src/features/CollectionManager.js +433 -0
  112. package/src/gallery/CollectionManager.js +240 -0
  113. package/src/gallery/GallerySystem.js +485 -0
  114. package/src/geometry/GeometryFactory.js +314 -0
  115. package/src/geometry/GeometryLibrary.js +72 -0
  116. package/src/geometry/buffers/BufferBuilder.js +338 -0
  117. package/src/geometry/buffers/index.js +18 -0
  118. package/src/geometry/generators/Crystal.js +420 -0
  119. package/src/geometry/generators/Fractal.js +298 -0
  120. package/src/geometry/generators/KleinBottle.js +197 -0
  121. package/src/geometry/generators/Sphere.js +192 -0
  122. package/src/geometry/generators/Tesseract.js +160 -0
  123. package/src/geometry/generators/Tetrahedron.js +225 -0
  124. package/src/geometry/generators/Torus.js +304 -0
  125. package/src/geometry/generators/Wave.js +341 -0
  126. package/src/geometry/index.js +142 -0
  127. package/src/geometry/warp/HypersphereCore.js +211 -0
  128. package/src/geometry/warp/HypertetraCore.js +386 -0
  129. package/src/geometry/warp/index.js +57 -0
  130. package/src/holograms/HolographicVisualizer.js +1073 -0
  131. package/src/holograms/RealHolographicSystem.js +966 -0
  132. package/src/holograms/variantRegistry.js +69 -0
  133. package/src/integrations/FigmaPlugin.js +854 -0
  134. package/src/integrations/OBSMode.js +754 -0
  135. package/src/integrations/ThreeJsPackage.js +660 -0
  136. package/src/integrations/TouchDesignerExport.js +552 -0
  137. package/src/integrations/frameworks/Vib3React.js +591 -0
  138. package/src/integrations/frameworks/Vib3Svelte.js +654 -0
  139. package/src/integrations/frameworks/Vib3Vue.js +628 -0
  140. package/src/llm/LLMParameterInterface.js +240 -0
  141. package/src/llm/LLMParameterUI.js +577 -0
  142. package/src/math/Mat4x4.js +708 -0
  143. package/src/math/Projection.js +341 -0
  144. package/src/math/Rotor4D.js +637 -0
  145. package/src/math/Vec4.js +476 -0
  146. package/src/math/constants.js +164 -0
  147. package/src/math/index.js +68 -0
  148. package/src/math/projections.js +54 -0
  149. package/src/math/rotations.js +196 -0
  150. package/src/quantum/QuantumEngine.js +906 -0
  151. package/src/quantum/QuantumVisualizer.js +1103 -0
  152. package/src/reactivity/ReactivityConfig.js +499 -0
  153. package/src/reactivity/ReactivityManager.js +586 -0
  154. package/src/reactivity/SpatialInputSystem.js +1783 -0
  155. package/src/reactivity/index.js +93 -0
  156. package/src/render/CommandBuffer.js +465 -0
  157. package/src/render/MultiCanvasBridge.js +340 -0
  158. package/src/render/RenderCommand.js +514 -0
  159. package/src/render/RenderResourceRegistry.js +523 -0
  160. package/src/render/RenderState.js +552 -0
  161. package/src/render/RenderTarget.js +512 -0
  162. package/src/render/ShaderLoader.js +253 -0
  163. package/src/render/ShaderProgram.js +599 -0
  164. package/src/render/UnifiedRenderBridge.js +496 -0
  165. package/src/render/backends/WebGLBackend.js +1108 -0
  166. package/src/render/backends/WebGPUBackend.js +1409 -0
  167. package/src/render/commands/CommandBufferExecutor.js +607 -0
  168. package/src/render/commands/RenderCommandBuffer.js +661 -0
  169. package/src/render/commands/index.js +17 -0
  170. package/src/render/index.js +367 -0
  171. package/src/scene/Disposable.js +498 -0
  172. package/src/scene/MemoryPool.js +618 -0
  173. package/src/scene/Node4D.js +697 -0
  174. package/src/scene/ResourceManager.js +599 -0
  175. package/src/scene/Scene4D.js +540 -0
  176. package/src/scene/index.js +98 -0
  177. package/src/schemas/error.schema.json +84 -0
  178. package/src/schemas/extension.schema.json +88 -0
  179. package/src/schemas/index.js +214 -0
  180. package/src/schemas/parameters.schema.json +142 -0
  181. package/src/schemas/tool-pack.schema.json +44 -0
  182. package/src/schemas/tool-response.schema.json +127 -0
  183. package/src/shaders/common/fullscreen.vert.glsl +5 -0
  184. package/src/shaders/common/fullscreen.vert.wgsl +17 -0
  185. package/src/shaders/common/geometry24.glsl +65 -0
  186. package/src/shaders/common/geometry24.wgsl +54 -0
  187. package/src/shaders/common/rotation4d.glsl +85 -0
  188. package/src/shaders/common/rotation4d.wgsl +86 -0
  189. package/src/shaders/common/uniforms.glsl +44 -0
  190. package/src/shaders/common/uniforms.wgsl +48 -0
  191. package/src/shaders/faceted/faceted.frag.glsl +129 -0
  192. package/src/shaders/faceted/faceted.frag.wgsl +164 -0
  193. package/src/shaders/holographic/holographic.frag.glsl +406 -0
  194. package/src/shaders/holographic/holographic.frag.wgsl +185 -0
  195. package/src/shaders/quantum/quantum.frag.glsl +513 -0
  196. package/src/shaders/quantum/quantum.frag.wgsl +361 -0
  197. package/src/testing/ParallelTestFramework.js +519 -0
  198. package/src/testing/__snapshots__/exportFormats.test.js.snap +24 -0
  199. package/src/testing/exportFormats.test.js +8 -0
  200. package/src/testing/projections.test.js +14 -0
  201. package/src/testing/rotations.test.js +37 -0
  202. package/src/ui/InteractivityMenu.js +516 -0
  203. package/src/ui/StatusManager.js +96 -0
  204. package/src/ui/adaptive/renderers/webgpu/BufferLayout.ts +252 -0
  205. package/src/ui/adaptive/renderers/webgpu/PolytopeInstanceBuffer.ts +144 -0
  206. package/src/ui/adaptive/renderers/webgpu/TripleBufferedUniform.ts +170 -0
  207. package/src/ui/adaptive/renderers/webgpu/WebGPURenderer.ts +735 -0
  208. package/src/ui/adaptive/renderers/webgpu/index.ts +112 -0
  209. package/src/variations/VariationManager.js +431 -0
  210. package/src/viewer/AudioReactivity.js +505 -0
  211. package/src/viewer/CardBending.js +481 -0
  212. package/src/viewer/GalleryUI.js +832 -0
  213. package/src/viewer/ReactivityManager.js +590 -0
  214. package/src/viewer/TradingCardExporter.js +600 -0
  215. package/src/viewer/ViewerPortal.js +374 -0
  216. package/src/viewer/index.js +12 -0
  217. package/src/wasm/WasmLoader.js +296 -0
  218. package/src/wasm/index.js +132 -0
  219. package/tools/agentic/mcpTools.js +88 -0
  220. package/tools/cli/agent-cli.js +92 -0
  221. package/tools/export/formats.js +24 -0
  222. package/tools/math/rotation-baseline.mjs +64 -0
  223. package/tools/shader-sync-verify.js +937 -0
  224. package/tools/telemetry/manifestPipeline.js +141 -0
  225. package/tools/telemetry/telemetryEvents.js +35 -0
  226. package/types/adaptive-sdk.d.ts +185 -0
  227. package/types/advanced/AIPresetGenerator.d.ts +81 -0
  228. package/types/advanced/MIDIController.d.ts +100 -0
  229. package/types/advanced/OffscreenWorker.d.ts +82 -0
  230. package/types/advanced/WebGPUCompute.d.ts +52 -0
  231. package/types/advanced/WebXRRenderer.d.ts +77 -0
  232. package/types/advanced/index.d.ts +46 -0
  233. package/types/core/ErrorReporter.d.ts +50 -0
  234. package/types/core/VIB3Engine.d.ts +204 -0
  235. package/types/creative/ColorPresetsSystem.d.ts +91 -0
  236. package/types/creative/ParameterTimeline.d.ts +74 -0
  237. package/types/creative/PostProcessingPipeline.d.ts +109 -0
  238. package/types/creative/TransitionAnimator.d.ts +71 -0
  239. package/types/creative/index.d.ts +35 -0
  240. package/types/integrations/FigmaPlugin.d.ts +46 -0
  241. package/types/integrations/OBSMode.d.ts +74 -0
  242. package/types/integrations/ThreeJsPackage.d.ts +62 -0
  243. package/types/integrations/TouchDesignerExport.d.ts +36 -0
  244. package/types/integrations/Vib3React.d.ts +74 -0
  245. package/types/integrations/Vib3Svelte.d.ts +63 -0
  246. package/types/integrations/Vib3Vue.d.ts +55 -0
  247. package/types/integrations/index.d.ts +52 -0
  248. package/types/reactivity/SpatialInputSystem.d.ts +173 -0
  249. package/types/reactivity/index.d.ts +394 -0
  250. package/types/render/CommandBuffer.d.ts +169 -0
  251. package/types/render/RenderCommand.d.ts +312 -0
  252. package/types/render/RenderState.d.ts +279 -0
  253. package/types/render/RenderTarget.d.ts +254 -0
  254. package/types/render/ShaderProgram.d.ts +277 -0
  255. package/types/render/UnifiedRenderBridge.d.ts +143 -0
  256. package/types/render/WebGLBackend.d.ts +168 -0
  257. package/types/render/WebGPUBackend.d.ts +186 -0
  258. package/types/render/index.d.ts +141 -0
@@ -0,0 +1,512 @@
1
+ /**
2
+ * RenderTarget - Framebuffer abstraction for off-screen rendering
3
+ *
4
+ * Supports:
5
+ * - Multiple color attachments (MRT)
6
+ * - Depth and stencil attachments
7
+ * - Texture and renderbuffer formats
8
+ * - Automatic resize
9
+ */
10
+
11
+ let renderTargetIdCounter = 0;
12
+
13
+ /**
14
+ * Texture formats
15
+ */
16
+ export const TextureFormat = {
17
+ // Color formats
18
+ RGBA8: 'rgba8',
19
+ RGBA16F: 'rgba16f',
20
+ RGBA32F: 'rgba32f',
21
+ RGB8: 'rgb8',
22
+ RG8: 'rg8',
23
+ R8: 'r8',
24
+
25
+ // Depth formats
26
+ DEPTH16: 'depth16',
27
+ DEPTH24: 'depth24',
28
+ DEPTH32F: 'depth32f',
29
+
30
+ // Depth-stencil formats
31
+ DEPTH24_STENCIL8: 'depth24_stencil8',
32
+ DEPTH32F_STENCIL8: 'depth32f_stencil8'
33
+ };
34
+
35
+ /**
36
+ * Attachment types
37
+ */
38
+ export const AttachmentType = {
39
+ COLOR: 'color',
40
+ DEPTH: 'depth',
41
+ STENCIL: 'stencil',
42
+ DEPTH_STENCIL: 'depth_stencil'
43
+ };
44
+
45
+ /**
46
+ * Texture filtering modes
47
+ */
48
+ export const FilterMode = {
49
+ NEAREST: 'nearest',
50
+ LINEAR: 'linear',
51
+ NEAREST_MIPMAP_NEAREST: 'nearest_mipmap_nearest',
52
+ LINEAR_MIPMAP_NEAREST: 'linear_mipmap_nearest',
53
+ NEAREST_MIPMAP_LINEAR: 'nearest_mipmap_linear',
54
+ LINEAR_MIPMAP_LINEAR: 'linear_mipmap_linear'
55
+ };
56
+
57
+ /**
58
+ * Texture wrap modes
59
+ */
60
+ export const WrapMode = {
61
+ REPEAT: 'repeat',
62
+ CLAMP_TO_EDGE: 'clamp_to_edge',
63
+ MIRRORED_REPEAT: 'mirrored_repeat'
64
+ };
65
+
66
+ /**
67
+ * Attachment descriptor
68
+ */
69
+ export class AttachmentDescriptor {
70
+ /**
71
+ * @param {object} options
72
+ */
73
+ constructor(options = {}) {
74
+ /** @type {string} */
75
+ this.type = options.type || AttachmentType.COLOR;
76
+
77
+ /** @type {string} */
78
+ this.format = options.format || TextureFormat.RGBA8;
79
+
80
+ /** @type {number} Attachment index (for MRT) */
81
+ this.index = options.index || 0;
82
+
83
+ /** @type {boolean} Use texture (true) or renderbuffer (false) */
84
+ this.useTexture = options.useTexture !== false;
85
+
86
+ /** @type {string} Minification filter */
87
+ this.minFilter = options.minFilter || FilterMode.LINEAR;
88
+
89
+ /** @type {string} Magnification filter */
90
+ this.magFilter = options.magFilter || FilterMode.LINEAR;
91
+
92
+ /** @type {string} Wrap mode S */
93
+ this.wrapS = options.wrapS || WrapMode.CLAMP_TO_EDGE;
94
+
95
+ /** @type {string} Wrap mode T */
96
+ this.wrapT = options.wrapT || WrapMode.CLAMP_TO_EDGE;
97
+
98
+ /** @type {boolean} Generate mipmaps */
99
+ this.generateMipmaps = options.generateMipmaps || false;
100
+
101
+ /** @type {number} MSAA samples (0 or 1 = no MSAA) */
102
+ this.samples = options.samples || 0;
103
+ }
104
+
105
+ /**
106
+ * Create color attachment descriptor
107
+ * @param {object} options
108
+ * @returns {AttachmentDescriptor}
109
+ */
110
+ static color(options = {}) {
111
+ return new AttachmentDescriptor({
112
+ type: AttachmentType.COLOR,
113
+ format: TextureFormat.RGBA8,
114
+ ...options
115
+ });
116
+ }
117
+
118
+ /**
119
+ * Create depth attachment descriptor
120
+ * @param {object} options
121
+ * @returns {AttachmentDescriptor}
122
+ */
123
+ static depth(options = {}) {
124
+ return new AttachmentDescriptor({
125
+ type: AttachmentType.DEPTH,
126
+ format: TextureFormat.DEPTH24,
127
+ useTexture: false,
128
+ ...options
129
+ });
130
+ }
131
+
132
+ /**
133
+ * Create depth-stencil attachment descriptor
134
+ * @param {object} options
135
+ * @returns {AttachmentDescriptor}
136
+ */
137
+ static depthStencil(options = {}) {
138
+ return new AttachmentDescriptor({
139
+ type: AttachmentType.DEPTH_STENCIL,
140
+ format: TextureFormat.DEPTH24_STENCIL8,
141
+ useTexture: false,
142
+ ...options
143
+ });
144
+ }
145
+
146
+ /**
147
+ * Check if this is a depth format
148
+ * @returns {boolean}
149
+ */
150
+ isDepthFormat() {
151
+ return this.type === AttachmentType.DEPTH ||
152
+ this.type === AttachmentType.DEPTH_STENCIL;
153
+ }
154
+ }
155
+
156
+ /**
157
+ * RenderTarget class
158
+ */
159
+ export class RenderTarget {
160
+ /**
161
+ * @param {number} width
162
+ * @param {number} height
163
+ * @param {object} [options]
164
+ */
165
+ constructor(width, height, options = {}) {
166
+ /** @type {number} */
167
+ this.id = ++renderTargetIdCounter;
168
+
169
+ /** @type {number} */
170
+ this.width = width;
171
+
172
+ /** @type {number} */
173
+ this.height = height;
174
+
175
+ /** @type {AttachmentDescriptor[]} Color attachments */
176
+ this.colorAttachments = options.colorAttachments || [
177
+ AttachmentDescriptor.color()
178
+ ];
179
+
180
+ /** @type {AttachmentDescriptor|null} Depth/stencil attachment */
181
+ this.depthAttachment = options.depthAttachment !== undefined
182
+ ? options.depthAttachment
183
+ : AttachmentDescriptor.depth();
184
+
185
+ /** @type {string|null} Debug label */
186
+ this.label = options.label || null;
187
+
188
+ /** @type {boolean} Auto-resize with window */
189
+ this.autoResize = options.autoResize || false;
190
+
191
+ /** @type {number} Scale factor for auto-resize */
192
+ this.resizeScale = options.resizeScale || 1;
193
+
194
+ /** @type {object|null} Backend-specific handle */
195
+ this._handle = null;
196
+
197
+ /** @type {object[]} Texture handles for color attachments */
198
+ this._colorTextures = [];
199
+
200
+ /** @type {object|null} Depth texture handle */
201
+ this._depthTexture = null;
202
+
203
+ /** @type {boolean} Whether resources are allocated */
204
+ this._allocated = false;
205
+
206
+ /** @type {boolean} Whether target is disposed */
207
+ this._disposed = false;
208
+ }
209
+
210
+ /**
211
+ * Get aspect ratio
212
+ * @returns {number}
213
+ */
214
+ get aspectRatio() {
215
+ return this.width / this.height;
216
+ }
217
+
218
+ /**
219
+ * Check if target has depth attachment
220
+ * @returns {boolean}
221
+ */
222
+ get hasDepth() {
223
+ return this.depthAttachment !== null;
224
+ }
225
+
226
+ /**
227
+ * Get number of color attachments
228
+ * @returns {number}
229
+ */
230
+ get colorAttachmentCount() {
231
+ return this.colorAttachments.length;
232
+ }
233
+
234
+ /**
235
+ * Resize the render target
236
+ * @param {number} width
237
+ * @param {number} height
238
+ */
239
+ resize(width, height) {
240
+ if (width === this.width && height === this.height) return;
241
+
242
+ this.width = width;
243
+ this.height = height;
244
+
245
+ // Mark for reallocation
246
+ if (this._allocated) {
247
+ this._needsReallocation = true;
248
+ }
249
+ }
250
+
251
+ /**
252
+ * Get color texture at index
253
+ * @param {number} index
254
+ * @returns {object|null}
255
+ */
256
+ getColorTexture(index = 0) {
257
+ return this._colorTextures[index] || null;
258
+ }
259
+
260
+ /**
261
+ * Get depth texture
262
+ * @returns {object|null}
263
+ */
264
+ getDepthTexture() {
265
+ return this._depthTexture;
266
+ }
267
+
268
+ /**
269
+ * Set backend handle
270
+ * @param {object} handle
271
+ */
272
+ setHandle(handle) {
273
+ this._handle = handle;
274
+ this._allocated = true;
275
+ }
276
+
277
+ /**
278
+ * Get backend handle
279
+ * @returns {object|null}
280
+ */
281
+ getHandle() {
282
+ return this._handle;
283
+ }
284
+
285
+ /**
286
+ * Dispose resources
287
+ */
288
+ dispose() {
289
+ this._handle = null;
290
+ this._colorTextures = [];
291
+ this._depthTexture = null;
292
+ this._allocated = false;
293
+ this._disposed = true;
294
+ }
295
+
296
+ /**
297
+ * Create simple render target (single color + depth)
298
+ * @param {number} width
299
+ * @param {number} height
300
+ * @param {object} [options]
301
+ * @returns {RenderTarget}
302
+ */
303
+ static create(width, height, options = {}) {
304
+ return new RenderTarget(width, height, {
305
+ colorAttachments: [AttachmentDescriptor.color({
306
+ format: options.colorFormat || TextureFormat.RGBA8
307
+ })],
308
+ depthAttachment: options.depth !== false
309
+ ? AttachmentDescriptor.depth()
310
+ : null,
311
+ ...options
312
+ });
313
+ }
314
+
315
+ /**
316
+ * Create HDR render target
317
+ * @param {number} width
318
+ * @param {number} height
319
+ * @param {object} [options]
320
+ * @returns {RenderTarget}
321
+ */
322
+ static createHDR(width, height, options = {}) {
323
+ return new RenderTarget(width, height, {
324
+ colorAttachments: [AttachmentDescriptor.color({
325
+ format: TextureFormat.RGBA16F
326
+ })],
327
+ depthAttachment: AttachmentDescriptor.depth(),
328
+ ...options
329
+ });
330
+ }
331
+
332
+ /**
333
+ * Create G-buffer for deferred rendering
334
+ * @param {number} width
335
+ * @param {number} height
336
+ * @returns {RenderTarget}
337
+ */
338
+ static createGBuffer(width, height) {
339
+ return new RenderTarget(width, height, {
340
+ colorAttachments: [
341
+ // Position
342
+ AttachmentDescriptor.color({
343
+ index: 0,
344
+ format: TextureFormat.RGBA16F
345
+ }),
346
+ // Normal
347
+ AttachmentDescriptor.color({
348
+ index: 1,
349
+ format: TextureFormat.RGBA16F
350
+ }),
351
+ // Albedo + Specular
352
+ AttachmentDescriptor.color({
353
+ index: 2,
354
+ format: TextureFormat.RGBA8
355
+ })
356
+ ],
357
+ depthAttachment: AttachmentDescriptor.depthStencil(),
358
+ label: 'GBuffer'
359
+ });
360
+ }
361
+
362
+ /**
363
+ * Create shadow map
364
+ * @param {number} size
365
+ * @param {object} [options]
366
+ * @returns {RenderTarget}
367
+ */
368
+ static createShadowMap(size, options = {}) {
369
+ return new RenderTarget(size, size, {
370
+ colorAttachments: [],
371
+ depthAttachment: AttachmentDescriptor.depth({
372
+ format: TextureFormat.DEPTH32F,
373
+ useTexture: true
374
+ }),
375
+ label: 'ShadowMap',
376
+ ...options
377
+ });
378
+ }
379
+
380
+ /**
381
+ * Create MSAA render target
382
+ * @param {number} width
383
+ * @param {number} height
384
+ * @param {number} samples
385
+ * @returns {RenderTarget}
386
+ */
387
+ static createMSAA(width, height, samples = 4) {
388
+ return new RenderTarget(width, height, {
389
+ colorAttachments: [AttachmentDescriptor.color({
390
+ samples,
391
+ useTexture: false
392
+ })],
393
+ depthAttachment: AttachmentDescriptor.depth({
394
+ samples
395
+ }),
396
+ label: `MSAA_${samples}x`
397
+ });
398
+ }
399
+ }
400
+
401
+ /**
402
+ * RenderTargetPool - Manages pooled render targets
403
+ */
404
+ export class RenderTargetPool {
405
+ constructor() {
406
+ /** @type {Map<string, RenderTarget[]>} */
407
+ this._pools = new Map();
408
+
409
+ /** @type {Set<RenderTarget>} */
410
+ this._inUse = new Set();
411
+ }
412
+
413
+ /**
414
+ * Generate pool key from dimensions and format
415
+ * @private
416
+ */
417
+ _getKey(width, height, format) {
418
+ return `${width}x${height}_${format}`;
419
+ }
420
+
421
+ /**
422
+ * Acquire a render target
423
+ * @param {number} width
424
+ * @param {number} height
425
+ * @param {string} format
426
+ * @returns {RenderTarget}
427
+ */
428
+ acquire(width, height, format = TextureFormat.RGBA8) {
429
+ const key = this._getKey(width, height, format);
430
+
431
+ if (!this._pools.has(key)) {
432
+ this._pools.set(key, []);
433
+ }
434
+
435
+ const pool = this._pools.get(key);
436
+ let target;
437
+
438
+ if (pool.length > 0) {
439
+ target = pool.pop();
440
+ } else {
441
+ target = RenderTarget.create(width, height, {
442
+ colorFormat: format
443
+ });
444
+ }
445
+
446
+ this._inUse.add(target);
447
+ return target;
448
+ }
449
+
450
+ /**
451
+ * Release a render target back to pool
452
+ * @param {RenderTarget} target
453
+ */
454
+ release(target) {
455
+ if (!this._inUse.has(target)) return;
456
+
457
+ this._inUse.delete(target);
458
+
459
+ const key = this._getKey(
460
+ target.width,
461
+ target.height,
462
+ target.colorAttachments[0]?.format || 'default'
463
+ );
464
+
465
+ if (!this._pools.has(key)) {
466
+ this._pools.set(key, []);
467
+ }
468
+
469
+ this._pools.get(key).push(target);
470
+ }
471
+
472
+ /**
473
+ * Clear all pools
474
+ */
475
+ clear() {
476
+ for (const pool of this._pools.values()) {
477
+ for (const target of pool) {
478
+ target.dispose();
479
+ }
480
+ }
481
+ this._pools.clear();
482
+
483
+ for (const target of this._inUse) {
484
+ target.dispose();
485
+ }
486
+ this._inUse.clear();
487
+ }
488
+
489
+ /**
490
+ * Get pool statistics
491
+ * @returns {object}
492
+ */
493
+ getStats() {
494
+ let pooled = 0;
495
+ for (const pool of this._pools.values()) {
496
+ pooled += pool.length;
497
+ }
498
+
499
+ return {
500
+ pooled,
501
+ inUse: this._inUse.size,
502
+ poolCount: this._pools.size
503
+ };
504
+ }
505
+ }
506
+
507
+ /**
508
+ * Global render target pool
509
+ */
510
+ export const renderTargetPool = new RenderTargetPool();
511
+
512
+ export default RenderTarget;