@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.
- package/CHANGELOG.md +118 -0
- package/DOCS/BLUEPRINT_EXECUTION_PLAN_2026-01-07.md +34 -0
- package/DOCS/CI_TESTING.md +38 -0
- package/DOCS/CLI_ONBOARDING.md +75 -0
- package/DOCS/CONTROL_REFERENCE.md +64 -0
- package/DOCS/DEV_TRACK_ANALYSIS.md +77 -0
- package/DOCS/DEV_TRACK_PLAN_2026-01-07.md +42 -0
- package/DOCS/DEV_TRACK_SESSION_2026-01-31.md +220 -0
- package/DOCS/ENV_SETUP.md +189 -0
- package/DOCS/EXPORT_FORMATS.md +417 -0
- package/DOCS/GPU_DISPOSAL_GUIDE.md +21 -0
- package/DOCS/LICENSING_TIERS.md +275 -0
- package/DOCS/MASTER_PLAN_2026-01-31.md +570 -0
- package/DOCS/OBS_SETUP_GUIDE.md +98 -0
- package/DOCS/PROJECT_SETUP.md +66 -0
- package/DOCS/RENDERER_LIFECYCLE.md +40 -0
- package/DOCS/REPO_MANIFEST.md +121 -0
- package/DOCS/SESSION_014_PLAN.md +195 -0
- package/DOCS/SESSION_LOG_2026-01-07.md +56 -0
- package/DOCS/STRATEGIC_BLUEPRINT_2026-01-07.md +72 -0
- package/DOCS/SYSTEM_AUDIT_2026-01-30.md +738 -0
- package/DOCS/SYSTEM_INVENTORY.md +520 -0
- package/DOCS/TELEMETRY_EXPORTS.md +34 -0
- package/DOCS/WEBGPU_STATUS.md +38 -0
- package/DOCS/XR_BENCHMARKS.md +608 -0
- package/LICENSE +21 -0
- package/README.md +426 -0
- package/docs/.nojekyll +0 -0
- package/docs/01-dissolution_of_euclidean_hegemony.html +346 -0
- package/docs/02-hyperspatial_ego_death.html +346 -0
- package/docs/03-post_cartesian_sublime.html +346 -0
- package/docs/04-crystalline_void_meditation.html +346 -0
- package/docs/05-quantum_decoherence_ballet.html +346 -0
- package/docs/06-dissolution_of_euclidean_hegemony.html +346 -0
- package/docs/07-hyperspatial_ego_death.html +346 -0
- package/docs/08-post_cartesian_sublime.html +346 -0
- package/docs/09-crystalline_void_meditation.html +346 -0
- package/docs/10-quantum_decoherence_ballet.html +346 -0
- package/docs/11-dissolution_of_euclidean_hegemony.html +346 -0
- package/docs/12-hyperspatial_ego_death.html +346 -0
- package/docs/13-post_cartesian_sublime.html +346 -0
- package/docs/index.html +794 -0
- package/docs/test-hub.html +441 -0
- package/docs/url-state.js +102 -0
- package/docs/vib3-exports/01-quantum-quantum-tetrahedron-lattice.html +489 -0
- package/docs/vib3-exports/02-quantum-quantum-hypersphere-matrix.html +489 -0
- package/docs/vib3-exports/03-quantum-quantum-hypertetra-fractal.html +489 -0
- package/docs/vib3-exports/04-faceted-faceted-crystal-structure.html +407 -0
- package/docs/vib3-exports/05-faceted-faceted-klein-bottle.html +407 -0
- package/docs/vib3-exports/06-faceted-faceted-hypertetra-torus.html +407 -0
- package/docs/vib3-exports/07-holographic-holographic-wave-field.html +457 -0
- package/docs/vib3-exports/08-holographic-holographic-hypersphere-sphere.html +457 -0
- package/docs/vib3-exports/09-holographic-holographic-hypertetra-crystal.html +457 -0
- package/docs/vib3-exports/index.html +238 -0
- package/docs/webgpu-live.html +702 -0
- package/package.json +367 -0
- package/src/advanced/AIPresetGenerator.js +777 -0
- package/src/advanced/MIDIController.js +703 -0
- package/src/advanced/OffscreenWorker.js +1051 -0
- package/src/advanced/WebGPUCompute.js +1051 -0
- package/src/advanced/WebXRRenderer.js +680 -0
- package/src/agent/cli/AgentCLI.js +615 -0
- package/src/agent/cli/index.js +14 -0
- package/src/agent/index.js +73 -0
- package/src/agent/mcp/MCPServer.js +950 -0
- package/src/agent/mcp/index.js +9 -0
- package/src/agent/mcp/tools.js +548 -0
- package/src/agent/telemetry/EventStream.js +669 -0
- package/src/agent/telemetry/Instrumentation.js +618 -0
- package/src/agent/telemetry/TelemetryExporters.js +427 -0
- package/src/agent/telemetry/TelemetryService.js +464 -0
- package/src/agent/telemetry/index.js +52 -0
- package/src/benchmarks/BenchmarkRunner.js +381 -0
- package/src/benchmarks/MetricsCollector.js +299 -0
- package/src/benchmarks/index.js +9 -0
- package/src/benchmarks/scenes.js +259 -0
- package/src/cli/index.js +675 -0
- package/src/config/ApiConfig.js +88 -0
- package/src/core/CanvasManager.js +217 -0
- package/src/core/ErrorReporter.js +117 -0
- package/src/core/ParameterMapper.js +333 -0
- package/src/core/Parameters.js +396 -0
- package/src/core/RendererContracts.js +200 -0
- package/src/core/UnifiedResourceManager.js +370 -0
- package/src/core/VIB3Engine.js +636 -0
- package/src/core/renderers/FacetedRendererAdapter.js +32 -0
- package/src/core/renderers/HolographicRendererAdapter.js +29 -0
- package/src/core/renderers/QuantumRendererAdapter.js +29 -0
- package/src/core/renderers/RendererLifecycleManager.js +63 -0
- package/src/creative/ColorPresetsSystem.js +980 -0
- package/src/creative/ParameterTimeline.js +1061 -0
- package/src/creative/PostProcessingPipeline.js +1113 -0
- package/src/creative/TransitionAnimator.js +683 -0
- package/src/export/CSSExporter.js +226 -0
- package/src/export/CardGeneratorBase.js +279 -0
- package/src/export/ExportManager.js +580 -0
- package/src/export/FacetedCardGenerator.js +279 -0
- package/src/export/HolographicCardGenerator.js +543 -0
- package/src/export/LottieExporter.js +552 -0
- package/src/export/QuantumCardGenerator.js +315 -0
- package/src/export/SVGExporter.js +519 -0
- package/src/export/ShaderExporter.js +903 -0
- package/src/export/TradingCardGenerator.js +3055 -0
- package/src/export/TradingCardManager.js +181 -0
- package/src/export/VIB3PackageExporter.js +559 -0
- package/src/export/index.js +14 -0
- package/src/export/systems/TradingCardSystemFaceted.js +494 -0
- package/src/export/systems/TradingCardSystemHolographic.js +452 -0
- package/src/export/systems/TradingCardSystemQuantum.js +411 -0
- package/src/faceted/FacetedSystem.js +963 -0
- package/src/features/CollectionManager.js +433 -0
- package/src/gallery/CollectionManager.js +240 -0
- package/src/gallery/GallerySystem.js +485 -0
- package/src/geometry/GeometryFactory.js +314 -0
- package/src/geometry/GeometryLibrary.js +72 -0
- package/src/geometry/buffers/BufferBuilder.js +338 -0
- package/src/geometry/buffers/index.js +18 -0
- package/src/geometry/generators/Crystal.js +420 -0
- package/src/geometry/generators/Fractal.js +298 -0
- package/src/geometry/generators/KleinBottle.js +197 -0
- package/src/geometry/generators/Sphere.js +192 -0
- package/src/geometry/generators/Tesseract.js +160 -0
- package/src/geometry/generators/Tetrahedron.js +225 -0
- package/src/geometry/generators/Torus.js +304 -0
- package/src/geometry/generators/Wave.js +341 -0
- package/src/geometry/index.js +142 -0
- package/src/geometry/warp/HypersphereCore.js +211 -0
- package/src/geometry/warp/HypertetraCore.js +386 -0
- package/src/geometry/warp/index.js +57 -0
- package/src/holograms/HolographicVisualizer.js +1073 -0
- package/src/holograms/RealHolographicSystem.js +966 -0
- package/src/holograms/variantRegistry.js +69 -0
- package/src/integrations/FigmaPlugin.js +854 -0
- package/src/integrations/OBSMode.js +754 -0
- package/src/integrations/ThreeJsPackage.js +660 -0
- package/src/integrations/TouchDesignerExport.js +552 -0
- package/src/integrations/frameworks/Vib3React.js +591 -0
- package/src/integrations/frameworks/Vib3Svelte.js +654 -0
- package/src/integrations/frameworks/Vib3Vue.js +628 -0
- package/src/llm/LLMParameterInterface.js +240 -0
- package/src/llm/LLMParameterUI.js +577 -0
- package/src/math/Mat4x4.js +708 -0
- package/src/math/Projection.js +341 -0
- package/src/math/Rotor4D.js +637 -0
- package/src/math/Vec4.js +476 -0
- package/src/math/constants.js +164 -0
- package/src/math/index.js +68 -0
- package/src/math/projections.js +54 -0
- package/src/math/rotations.js +196 -0
- package/src/quantum/QuantumEngine.js +906 -0
- package/src/quantum/QuantumVisualizer.js +1103 -0
- package/src/reactivity/ReactivityConfig.js +499 -0
- package/src/reactivity/ReactivityManager.js +586 -0
- package/src/reactivity/SpatialInputSystem.js +1783 -0
- package/src/reactivity/index.js +93 -0
- package/src/render/CommandBuffer.js +465 -0
- package/src/render/MultiCanvasBridge.js +340 -0
- package/src/render/RenderCommand.js +514 -0
- package/src/render/RenderResourceRegistry.js +523 -0
- package/src/render/RenderState.js +552 -0
- package/src/render/RenderTarget.js +512 -0
- package/src/render/ShaderLoader.js +253 -0
- package/src/render/ShaderProgram.js +599 -0
- package/src/render/UnifiedRenderBridge.js +496 -0
- package/src/render/backends/WebGLBackend.js +1108 -0
- package/src/render/backends/WebGPUBackend.js +1409 -0
- package/src/render/commands/CommandBufferExecutor.js +607 -0
- package/src/render/commands/RenderCommandBuffer.js +661 -0
- package/src/render/commands/index.js +17 -0
- package/src/render/index.js +367 -0
- package/src/scene/Disposable.js +498 -0
- package/src/scene/MemoryPool.js +618 -0
- package/src/scene/Node4D.js +697 -0
- package/src/scene/ResourceManager.js +599 -0
- package/src/scene/Scene4D.js +540 -0
- package/src/scene/index.js +98 -0
- package/src/schemas/error.schema.json +84 -0
- package/src/schemas/extension.schema.json +88 -0
- package/src/schemas/index.js +214 -0
- package/src/schemas/parameters.schema.json +142 -0
- package/src/schemas/tool-pack.schema.json +44 -0
- package/src/schemas/tool-response.schema.json +127 -0
- package/src/shaders/common/fullscreen.vert.glsl +5 -0
- package/src/shaders/common/fullscreen.vert.wgsl +17 -0
- package/src/shaders/common/geometry24.glsl +65 -0
- package/src/shaders/common/geometry24.wgsl +54 -0
- package/src/shaders/common/rotation4d.glsl +85 -0
- package/src/shaders/common/rotation4d.wgsl +86 -0
- package/src/shaders/common/uniforms.glsl +44 -0
- package/src/shaders/common/uniforms.wgsl +48 -0
- package/src/shaders/faceted/faceted.frag.glsl +129 -0
- package/src/shaders/faceted/faceted.frag.wgsl +164 -0
- package/src/shaders/holographic/holographic.frag.glsl +406 -0
- package/src/shaders/holographic/holographic.frag.wgsl +185 -0
- package/src/shaders/quantum/quantum.frag.glsl +513 -0
- package/src/shaders/quantum/quantum.frag.wgsl +361 -0
- package/src/testing/ParallelTestFramework.js +519 -0
- package/src/testing/__snapshots__/exportFormats.test.js.snap +24 -0
- package/src/testing/exportFormats.test.js +8 -0
- package/src/testing/projections.test.js +14 -0
- package/src/testing/rotations.test.js +37 -0
- package/src/ui/InteractivityMenu.js +516 -0
- package/src/ui/StatusManager.js +96 -0
- package/src/ui/adaptive/renderers/webgpu/BufferLayout.ts +252 -0
- package/src/ui/adaptive/renderers/webgpu/PolytopeInstanceBuffer.ts +144 -0
- package/src/ui/adaptive/renderers/webgpu/TripleBufferedUniform.ts +170 -0
- package/src/ui/adaptive/renderers/webgpu/WebGPURenderer.ts +735 -0
- package/src/ui/adaptive/renderers/webgpu/index.ts +112 -0
- package/src/variations/VariationManager.js +431 -0
- package/src/viewer/AudioReactivity.js +505 -0
- package/src/viewer/CardBending.js +481 -0
- package/src/viewer/GalleryUI.js +832 -0
- package/src/viewer/ReactivityManager.js +590 -0
- package/src/viewer/TradingCardExporter.js +600 -0
- package/src/viewer/ViewerPortal.js +374 -0
- package/src/viewer/index.js +12 -0
- package/src/wasm/WasmLoader.js +296 -0
- package/src/wasm/index.js +132 -0
- package/tools/agentic/mcpTools.js +88 -0
- package/tools/cli/agent-cli.js +92 -0
- package/tools/export/formats.js +24 -0
- package/tools/math/rotation-baseline.mjs +64 -0
- package/tools/shader-sync-verify.js +937 -0
- package/tools/telemetry/manifestPipeline.js +141 -0
- package/tools/telemetry/telemetryEvents.js +35 -0
- package/types/adaptive-sdk.d.ts +185 -0
- package/types/advanced/AIPresetGenerator.d.ts +81 -0
- package/types/advanced/MIDIController.d.ts +100 -0
- package/types/advanced/OffscreenWorker.d.ts +82 -0
- package/types/advanced/WebGPUCompute.d.ts +52 -0
- package/types/advanced/WebXRRenderer.d.ts +77 -0
- package/types/advanced/index.d.ts +46 -0
- package/types/core/ErrorReporter.d.ts +50 -0
- package/types/core/VIB3Engine.d.ts +204 -0
- package/types/creative/ColorPresetsSystem.d.ts +91 -0
- package/types/creative/ParameterTimeline.d.ts +74 -0
- package/types/creative/PostProcessingPipeline.d.ts +109 -0
- package/types/creative/TransitionAnimator.d.ts +71 -0
- package/types/creative/index.d.ts +35 -0
- package/types/integrations/FigmaPlugin.d.ts +46 -0
- package/types/integrations/OBSMode.d.ts +74 -0
- package/types/integrations/ThreeJsPackage.d.ts +62 -0
- package/types/integrations/TouchDesignerExport.d.ts +36 -0
- package/types/integrations/Vib3React.d.ts +74 -0
- package/types/integrations/Vib3Svelte.d.ts +63 -0
- package/types/integrations/Vib3Vue.d.ts +55 -0
- package/types/integrations/index.d.ts +52 -0
- package/types/reactivity/SpatialInputSystem.d.ts +173 -0
- package/types/reactivity/index.d.ts +394 -0
- package/types/render/CommandBuffer.d.ts +169 -0
- package/types/render/RenderCommand.d.ts +312 -0
- package/types/render/RenderState.d.ts +279 -0
- package/types/render/RenderTarget.d.ts +254 -0
- package/types/render/ShaderProgram.d.ts +277 -0
- package/types/render/UnifiedRenderBridge.d.ts +143 -0
- package/types/render/WebGLBackend.d.ts +168 -0
- package/types/render/WebGPUBackend.d.ts +186 -0
- package/types/render/index.d.ts +141 -0
|
@@ -0,0 +1,607 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CommandBufferExecutor - Executes RenderCommandBuffer against rendering backends
|
|
3
|
+
*
|
|
4
|
+
* Supports:
|
|
5
|
+
* - WebGL 2.0 backend execution
|
|
6
|
+
* - WebGPU backend execution
|
|
7
|
+
* - Validation mode for debugging
|
|
8
|
+
*
|
|
9
|
+
* The executor translates abstract commands to backend-specific API calls,
|
|
10
|
+
* enabling the same command buffer to run on multiple platforms.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import {
|
|
14
|
+
CommandType,
|
|
15
|
+
BlendMode,
|
|
16
|
+
DepthFunc,
|
|
17
|
+
Topology
|
|
18
|
+
} from './RenderCommandBuffer.js';
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* WebGL blend mode mapping
|
|
22
|
+
*/
|
|
23
|
+
const GL_BLEND_FACTORS = {
|
|
24
|
+
[BlendMode.NONE]: null,
|
|
25
|
+
[BlendMode.ALPHA]: { src: 'SRC_ALPHA', dst: 'ONE_MINUS_SRC_ALPHA' },
|
|
26
|
+
[BlendMode.ADDITIVE]: { src: 'SRC_ALPHA', dst: 'ONE' },
|
|
27
|
+
[BlendMode.MULTIPLY]: { src: 'DST_COLOR', dst: 'ZERO' },
|
|
28
|
+
[BlendMode.SCREEN]: { src: 'ONE', dst: 'ONE_MINUS_SRC_COLOR' },
|
|
29
|
+
[BlendMode.PREMULTIPLIED]: { src: 'ONE', dst: 'ONE_MINUS_SRC_ALPHA' }
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* WebGL depth function mapping
|
|
34
|
+
*/
|
|
35
|
+
const GL_DEPTH_FUNCS = {
|
|
36
|
+
[DepthFunc.NEVER]: 'NEVER',
|
|
37
|
+
[DepthFunc.LESS]: 'LESS',
|
|
38
|
+
[DepthFunc.EQUAL]: 'EQUAL',
|
|
39
|
+
[DepthFunc.LEQUAL]: 'LEQUAL',
|
|
40
|
+
[DepthFunc.GREATER]: 'GREATER',
|
|
41
|
+
[DepthFunc.NOTEQUAL]: 'NOTEQUAL',
|
|
42
|
+
[DepthFunc.GEQUAL]: 'GEQUAL',
|
|
43
|
+
[DepthFunc.ALWAYS]: 'ALWAYS'
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* WebGL primitive topology mapping
|
|
48
|
+
*/
|
|
49
|
+
const GL_TOPOLOGY = {
|
|
50
|
+
[Topology.POINT_LIST]: 'POINTS',
|
|
51
|
+
[Topology.LINE_LIST]: 'LINES',
|
|
52
|
+
[Topology.LINE_STRIP]: 'LINE_STRIP',
|
|
53
|
+
[Topology.TRIANGLE_LIST]: 'TRIANGLES',
|
|
54
|
+
[Topology.TRIANGLE_STRIP]: 'TRIANGLE_STRIP',
|
|
55
|
+
[Topology.TRIANGLE_FAN]: 'TRIANGLE_FAN'
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Execution context for tracking state during command execution
|
|
60
|
+
*/
|
|
61
|
+
class ExecutionContext {
|
|
62
|
+
constructor() {
|
|
63
|
+
this.viewport = { x: 0, y: 0, width: 0, height: 0 };
|
|
64
|
+
this.scissor = null;
|
|
65
|
+
this.currentPipeline = null;
|
|
66
|
+
this.blendMode = BlendMode.ALPHA;
|
|
67
|
+
this.depthState = { enabled: true, write: true, func: DepthFunc.LESS };
|
|
68
|
+
this.boundVertexBuffers = new Map();
|
|
69
|
+
this.boundIndexBuffer = null;
|
|
70
|
+
this.boundTextures = new Map();
|
|
71
|
+
this.uniforms = {};
|
|
72
|
+
this.rotor = null;
|
|
73
|
+
this.projection = null;
|
|
74
|
+
|
|
75
|
+
/** @type {Array<object>} */
|
|
76
|
+
this.stateStack = [];
|
|
77
|
+
|
|
78
|
+
this.stats = {
|
|
79
|
+
commandsExecuted: 0,
|
|
80
|
+
drawCalls: 0,
|
|
81
|
+
stateChanges: 0,
|
|
82
|
+
errors: 0
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
pushState() {
|
|
87
|
+
this.stateStack.push({
|
|
88
|
+
viewport: { ...this.viewport },
|
|
89
|
+
scissor: this.scissor ? { ...this.scissor } : null,
|
|
90
|
+
currentPipeline: this.currentPipeline,
|
|
91
|
+
blendMode: this.blendMode,
|
|
92
|
+
depthState: { ...this.depthState },
|
|
93
|
+
uniforms: { ...this.uniforms }
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
popState() {
|
|
98
|
+
const state = this.stateStack.pop();
|
|
99
|
+
if (state) {
|
|
100
|
+
Object.assign(this.viewport, state.viewport);
|
|
101
|
+
this.scissor = state.scissor;
|
|
102
|
+
this.currentPipeline = state.currentPipeline;
|
|
103
|
+
this.blendMode = state.blendMode;
|
|
104
|
+
Object.assign(this.depthState, state.depthState);
|
|
105
|
+
this.uniforms = state.uniforms;
|
|
106
|
+
return true;
|
|
107
|
+
}
|
|
108
|
+
return false;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Command buffer executor
|
|
114
|
+
*/
|
|
115
|
+
export class CommandBufferExecutor {
|
|
116
|
+
/**
|
|
117
|
+
* @param {object} [options]
|
|
118
|
+
* @param {boolean} [options.validateOnly] - Only validate, don't execute
|
|
119
|
+
* @param {boolean} [options.debug] - Enable debug logging
|
|
120
|
+
*/
|
|
121
|
+
constructor(options = {}) {
|
|
122
|
+
this.validateOnly = options.validateOnly || false;
|
|
123
|
+
this.debug = options.debug || false;
|
|
124
|
+
|
|
125
|
+
/** @type {Map<string|number, WebGLBuffer|GPUBuffer>} */
|
|
126
|
+
this._bufferRegistry = new Map();
|
|
127
|
+
|
|
128
|
+
/** @type {Map<string|number, WebGLTexture|GPUTexture>} */
|
|
129
|
+
this._textureRegistry = new Map();
|
|
130
|
+
|
|
131
|
+
/** @type {Map<string, object>} */
|
|
132
|
+
this._pipelineRegistry = new Map();
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Register a buffer for reference in commands
|
|
137
|
+
* @param {string|number} id
|
|
138
|
+
* @param {WebGLBuffer|GPUBuffer} buffer
|
|
139
|
+
*/
|
|
140
|
+
registerBuffer(id, buffer) {
|
|
141
|
+
this._bufferRegistry.set(id, buffer);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* Register a texture for reference in commands
|
|
146
|
+
* @param {string|number} id
|
|
147
|
+
* @param {WebGLTexture|GPUTexture} texture
|
|
148
|
+
*/
|
|
149
|
+
registerTexture(id, texture) {
|
|
150
|
+
this._textureRegistry.set(id, texture);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* Register a pipeline for reference in commands
|
|
155
|
+
* @param {string} id
|
|
156
|
+
* @param {object} pipeline - Backend-specific pipeline object
|
|
157
|
+
*/
|
|
158
|
+
registerPipeline(id, pipeline) {
|
|
159
|
+
this._pipelineRegistry.set(id, pipeline);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* Execute command buffer against WebGL context
|
|
164
|
+
* @param {RenderCommandBuffer} commandBuffer
|
|
165
|
+
* @param {WebGL2RenderingContext} gl
|
|
166
|
+
* @param {object} [options]
|
|
167
|
+
* @returns {ExecutionContext}
|
|
168
|
+
*/
|
|
169
|
+
executeWebGL(commandBuffer, gl, options = {}) {
|
|
170
|
+
const ctx = new ExecutionContext();
|
|
171
|
+
|
|
172
|
+
for (const cmd of commandBuffer.getCommands()) {
|
|
173
|
+
try {
|
|
174
|
+
this._executeWebGLCommand(cmd, gl, ctx, options);
|
|
175
|
+
ctx.stats.commandsExecuted++;
|
|
176
|
+
} catch (error) {
|
|
177
|
+
ctx.stats.errors++;
|
|
178
|
+
if (this.debug) {
|
|
179
|
+
console.error('WebGL command error:', CommandType[cmd.type], error);
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
return ctx;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
* Execute single WebGL command
|
|
189
|
+
* @private
|
|
190
|
+
*/
|
|
191
|
+
_executeWebGLCommand(cmd, gl, ctx, options) {
|
|
192
|
+
if (this.validateOnly) {
|
|
193
|
+
this._validateCommand(cmd);
|
|
194
|
+
return;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
switch (cmd.type) {
|
|
198
|
+
case CommandType.CLEAR:
|
|
199
|
+
this._glClear(gl, cmd.data);
|
|
200
|
+
break;
|
|
201
|
+
|
|
202
|
+
case CommandType.SET_VIEWPORT:
|
|
203
|
+
gl.viewport(cmd.data.x, cmd.data.y, cmd.data.width, cmd.data.height);
|
|
204
|
+
Object.assign(ctx.viewport, cmd.data);
|
|
205
|
+
ctx.stats.stateChanges++;
|
|
206
|
+
break;
|
|
207
|
+
|
|
208
|
+
case CommandType.SET_SCISSOR:
|
|
209
|
+
gl.enable(gl.SCISSOR_TEST);
|
|
210
|
+
gl.scissor(cmd.data.x, cmd.data.y, cmd.data.width, cmd.data.height);
|
|
211
|
+
ctx.scissor = { ...cmd.data };
|
|
212
|
+
ctx.stats.stateChanges++;
|
|
213
|
+
break;
|
|
214
|
+
|
|
215
|
+
case CommandType.SET_PIPELINE:
|
|
216
|
+
ctx.currentPipeline = cmd.data.pipelineId;
|
|
217
|
+
const pipeline = this._pipelineRegistry.get(cmd.data.pipelineId);
|
|
218
|
+
if (pipeline && pipeline.program) {
|
|
219
|
+
gl.useProgram(pipeline.program);
|
|
220
|
+
}
|
|
221
|
+
ctx.stats.stateChanges++;
|
|
222
|
+
break;
|
|
223
|
+
|
|
224
|
+
case CommandType.SET_UNIFORMS:
|
|
225
|
+
this._glSetUniforms(gl, ctx, cmd.data.values);
|
|
226
|
+
ctx.stats.stateChanges++;
|
|
227
|
+
break;
|
|
228
|
+
|
|
229
|
+
case CommandType.SET_ROTOR:
|
|
230
|
+
ctx.rotor = cmd.data.rotor;
|
|
231
|
+
// Rotor uniform will be set when pipeline is active
|
|
232
|
+
this._glSetRotorUniform(gl, ctx);
|
|
233
|
+
break;
|
|
234
|
+
|
|
235
|
+
case CommandType.SET_PROJECTION:
|
|
236
|
+
ctx.projection = cmd.data;
|
|
237
|
+
break;
|
|
238
|
+
|
|
239
|
+
case CommandType.BIND_VERTEX_BUFFER:
|
|
240
|
+
const vb = this._bufferRegistry.get(cmd.data.bufferId);
|
|
241
|
+
if (vb) {
|
|
242
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, vb);
|
|
243
|
+
ctx.boundVertexBuffers.set(cmd.data.slot, cmd.data.bufferId);
|
|
244
|
+
}
|
|
245
|
+
ctx.stats.stateChanges++;
|
|
246
|
+
break;
|
|
247
|
+
|
|
248
|
+
case CommandType.BIND_INDEX_BUFFER:
|
|
249
|
+
const ib = this._bufferRegistry.get(cmd.data.bufferId);
|
|
250
|
+
if (ib) {
|
|
251
|
+
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, ib);
|
|
252
|
+
ctx.boundIndexBuffer = {
|
|
253
|
+
id: cmd.data.bufferId,
|
|
254
|
+
format: cmd.data.format
|
|
255
|
+
};
|
|
256
|
+
}
|
|
257
|
+
ctx.stats.stateChanges++;
|
|
258
|
+
break;
|
|
259
|
+
|
|
260
|
+
case CommandType.BIND_TEXTURE:
|
|
261
|
+
const tex = this._textureRegistry.get(cmd.data.textureId);
|
|
262
|
+
if (tex) {
|
|
263
|
+
gl.activeTexture(gl.TEXTURE0 + cmd.data.slot);
|
|
264
|
+
gl.bindTexture(gl.TEXTURE_2D, tex);
|
|
265
|
+
ctx.boundTextures.set(cmd.data.slot, cmd.data.textureId);
|
|
266
|
+
}
|
|
267
|
+
ctx.stats.stateChanges++;
|
|
268
|
+
break;
|
|
269
|
+
|
|
270
|
+
case CommandType.SET_BLEND_MODE:
|
|
271
|
+
this._glSetBlendMode(gl, cmd.data.mode);
|
|
272
|
+
ctx.blendMode = cmd.data.mode;
|
|
273
|
+
ctx.stats.stateChanges++;
|
|
274
|
+
break;
|
|
275
|
+
|
|
276
|
+
case CommandType.SET_DEPTH_STATE:
|
|
277
|
+
this._glSetDepthState(gl, cmd.data);
|
|
278
|
+
ctx.depthState = { ...cmd.data };
|
|
279
|
+
ctx.stats.stateChanges++;
|
|
280
|
+
break;
|
|
281
|
+
|
|
282
|
+
case CommandType.DRAW:
|
|
283
|
+
gl.drawArrays(gl[GL_TOPOLOGY[cmd.data.topology]], cmd.data.firstVertex, cmd.data.vertexCount);
|
|
284
|
+
ctx.stats.drawCalls++;
|
|
285
|
+
break;
|
|
286
|
+
|
|
287
|
+
case CommandType.DRAW_INDEXED:
|
|
288
|
+
const indexType = ctx.boundIndexBuffer?.format === 'uint32'
|
|
289
|
+
? gl.UNSIGNED_INT
|
|
290
|
+
: gl.UNSIGNED_SHORT;
|
|
291
|
+
const byteOffset = cmd.data.firstIndex * (indexType === gl.UNSIGNED_INT ? 4 : 2);
|
|
292
|
+
gl.drawElements(
|
|
293
|
+
gl[GL_TOPOLOGY[cmd.data.topology]],
|
|
294
|
+
cmd.data.indexCount,
|
|
295
|
+
indexType,
|
|
296
|
+
byteOffset
|
|
297
|
+
);
|
|
298
|
+
ctx.stats.drawCalls++;
|
|
299
|
+
break;
|
|
300
|
+
|
|
301
|
+
case CommandType.DRAW_INSTANCED:
|
|
302
|
+
gl.drawArraysInstanced(
|
|
303
|
+
gl[GL_TOPOLOGY[cmd.data.topology]],
|
|
304
|
+
cmd.data.firstVertex,
|
|
305
|
+
cmd.data.vertexCount,
|
|
306
|
+
cmd.data.instanceCount
|
|
307
|
+
);
|
|
308
|
+
ctx.stats.drawCalls++;
|
|
309
|
+
break;
|
|
310
|
+
|
|
311
|
+
case CommandType.PUSH_STATE:
|
|
312
|
+
ctx.pushState();
|
|
313
|
+
break;
|
|
314
|
+
|
|
315
|
+
case CommandType.POP_STATE:
|
|
316
|
+
if (ctx.popState()) {
|
|
317
|
+
// Restore GL state
|
|
318
|
+
gl.viewport(ctx.viewport.x, ctx.viewport.y, ctx.viewport.width, ctx.viewport.height);
|
|
319
|
+
this._glSetBlendMode(gl, ctx.blendMode);
|
|
320
|
+
this._glSetDepthState(gl, ctx.depthState);
|
|
321
|
+
}
|
|
322
|
+
break;
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
/**
|
|
327
|
+
* WebGL clear implementation
|
|
328
|
+
* @private
|
|
329
|
+
*/
|
|
330
|
+
_glClear(gl, data) {
|
|
331
|
+
let mask = 0;
|
|
332
|
+
|
|
333
|
+
if (data.clearColor) {
|
|
334
|
+
gl.clearColor(data.color[0], data.color[1], data.color[2], data.color[3]);
|
|
335
|
+
mask |= gl.COLOR_BUFFER_BIT;
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
if (data.clearDepth) {
|
|
339
|
+
gl.clearDepth(data.depth);
|
|
340
|
+
mask |= gl.DEPTH_BUFFER_BIT;
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
if (data.clearStencil) {
|
|
344
|
+
gl.clearStencil(data.stencil);
|
|
345
|
+
mask |= gl.STENCIL_BUFFER_BIT;
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
if (mask) {
|
|
349
|
+
gl.clear(mask);
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
/**
|
|
354
|
+
* WebGL blend mode implementation
|
|
355
|
+
* @private
|
|
356
|
+
*/
|
|
357
|
+
_glSetBlendMode(gl, mode) {
|
|
358
|
+
const blend = GL_BLEND_FACTORS[mode];
|
|
359
|
+
|
|
360
|
+
if (!blend) {
|
|
361
|
+
gl.disable(gl.BLEND);
|
|
362
|
+
return;
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
gl.enable(gl.BLEND);
|
|
366
|
+
gl.blendFunc(gl[blend.src], gl[blend.dst]);
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
/**
|
|
370
|
+
* WebGL depth state implementation
|
|
371
|
+
* @private
|
|
372
|
+
*/
|
|
373
|
+
_glSetDepthState(gl, state) {
|
|
374
|
+
if (state.enabled) {
|
|
375
|
+
gl.enable(gl.DEPTH_TEST);
|
|
376
|
+
gl.depthFunc(gl[GL_DEPTH_FUNCS[state.func]]);
|
|
377
|
+
gl.depthMask(state.write);
|
|
378
|
+
} else {
|
|
379
|
+
gl.disable(gl.DEPTH_TEST);
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
/**
|
|
384
|
+
* WebGL uniform setting
|
|
385
|
+
* @private
|
|
386
|
+
*/
|
|
387
|
+
_glSetUniforms(gl, ctx, values) {
|
|
388
|
+
Object.assign(ctx.uniforms, values);
|
|
389
|
+
// Actual uniform upload happens through pipeline-specific code
|
|
390
|
+
// This stores values for later use
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
/**
|
|
394
|
+
* WebGL rotor uniform
|
|
395
|
+
* @private
|
|
396
|
+
*/
|
|
397
|
+
_glSetRotorUniform(gl, ctx) {
|
|
398
|
+
// Rotor is stored in context for pipeline to use
|
|
399
|
+
// Actual uniform location depends on active shader
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
/**
|
|
403
|
+
* Execute command buffer against WebGPU backend
|
|
404
|
+
* @param {RenderCommandBuffer} commandBuffer
|
|
405
|
+
* @param {WebGPUBackend} backend
|
|
406
|
+
* @param {object} [options]
|
|
407
|
+
* @returns {ExecutionContext}
|
|
408
|
+
*/
|
|
409
|
+
executeWebGPU(commandBuffer, backend, options = {}) {
|
|
410
|
+
const ctx = new ExecutionContext();
|
|
411
|
+
const device = backend.device;
|
|
412
|
+
|
|
413
|
+
// Start render pass
|
|
414
|
+
const { encoder, pass } = backend.beginRenderPass({
|
|
415
|
+
clearColor: [0, 0, 0, 1]
|
|
416
|
+
});
|
|
417
|
+
|
|
418
|
+
for (const cmd of commandBuffer.getCommands()) {
|
|
419
|
+
try {
|
|
420
|
+
this._executeWebGPUCommand(cmd, backend, pass, ctx, options);
|
|
421
|
+
ctx.stats.commandsExecuted++;
|
|
422
|
+
} catch (error) {
|
|
423
|
+
ctx.stats.errors++;
|
|
424
|
+
if (this.debug) {
|
|
425
|
+
console.error('WebGPU command error:', CommandType[cmd.type], error);
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
// End render pass
|
|
431
|
+
backend.endRenderPass(encoder, pass);
|
|
432
|
+
|
|
433
|
+
return ctx;
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
/**
|
|
437
|
+
* Execute single WebGPU command
|
|
438
|
+
* @private
|
|
439
|
+
*/
|
|
440
|
+
_executeWebGPUCommand(cmd, backend, pass, ctx, options) {
|
|
441
|
+
if (this.validateOnly) {
|
|
442
|
+
this._validateCommand(cmd);
|
|
443
|
+
return;
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
switch (cmd.type) {
|
|
447
|
+
case CommandType.CLEAR:
|
|
448
|
+
// Clear is handled by render pass configuration
|
|
449
|
+
break;
|
|
450
|
+
|
|
451
|
+
case CommandType.SET_VIEWPORT:
|
|
452
|
+
pass.setViewport(
|
|
453
|
+
cmd.data.x, cmd.data.y,
|
|
454
|
+
cmd.data.width, cmd.data.height,
|
|
455
|
+
0, 1
|
|
456
|
+
);
|
|
457
|
+
Object.assign(ctx.viewport, cmd.data);
|
|
458
|
+
ctx.stats.stateChanges++;
|
|
459
|
+
break;
|
|
460
|
+
|
|
461
|
+
case CommandType.SET_SCISSOR:
|
|
462
|
+
pass.setScissorRect(
|
|
463
|
+
cmd.data.x, cmd.data.y,
|
|
464
|
+
cmd.data.width, cmd.data.height
|
|
465
|
+
);
|
|
466
|
+
ctx.scissor = { ...cmd.data };
|
|
467
|
+
ctx.stats.stateChanges++;
|
|
468
|
+
break;
|
|
469
|
+
|
|
470
|
+
case CommandType.SET_PIPELINE:
|
|
471
|
+
const pipeline = this._pipelineRegistry.get(cmd.data.pipelineId);
|
|
472
|
+
if (pipeline) {
|
|
473
|
+
pass.setPipeline(pipeline);
|
|
474
|
+
ctx.currentPipeline = cmd.data.pipelineId;
|
|
475
|
+
}
|
|
476
|
+
ctx.stats.stateChanges++;
|
|
477
|
+
break;
|
|
478
|
+
|
|
479
|
+
case CommandType.SET_UNIFORMS:
|
|
480
|
+
Object.assign(ctx.uniforms, cmd.data.values);
|
|
481
|
+
backend.updateUniforms(ctx.uniforms);
|
|
482
|
+
ctx.stats.stateChanges++;
|
|
483
|
+
break;
|
|
484
|
+
|
|
485
|
+
case CommandType.SET_ROTOR:
|
|
486
|
+
ctx.rotor = cmd.data.rotor;
|
|
487
|
+
// Update rotor in uniform buffer
|
|
488
|
+
break;
|
|
489
|
+
|
|
490
|
+
case CommandType.SET_PROJECTION:
|
|
491
|
+
ctx.projection = cmd.data;
|
|
492
|
+
break;
|
|
493
|
+
|
|
494
|
+
case CommandType.BIND_VERTEX_BUFFER:
|
|
495
|
+
const vb = this._bufferRegistry.get(cmd.data.bufferId);
|
|
496
|
+
if (vb) {
|
|
497
|
+
pass.setVertexBuffer(cmd.data.slot, vb, cmd.data.offset || 0);
|
|
498
|
+
ctx.boundVertexBuffers.set(cmd.data.slot, cmd.data.bufferId);
|
|
499
|
+
}
|
|
500
|
+
ctx.stats.stateChanges++;
|
|
501
|
+
break;
|
|
502
|
+
|
|
503
|
+
case CommandType.BIND_INDEX_BUFFER:
|
|
504
|
+
const ib = this._bufferRegistry.get(cmd.data.bufferId);
|
|
505
|
+
if (ib) {
|
|
506
|
+
pass.setIndexBuffer(ib, cmd.data.format, cmd.data.offset || 0);
|
|
507
|
+
ctx.boundIndexBuffer = {
|
|
508
|
+
id: cmd.data.bufferId,
|
|
509
|
+
format: cmd.data.format
|
|
510
|
+
};
|
|
511
|
+
}
|
|
512
|
+
ctx.stats.stateChanges++;
|
|
513
|
+
break;
|
|
514
|
+
|
|
515
|
+
case CommandType.DRAW:
|
|
516
|
+
pass.draw(cmd.data.vertexCount, 1, cmd.data.firstVertex, 0);
|
|
517
|
+
ctx.stats.drawCalls++;
|
|
518
|
+
break;
|
|
519
|
+
|
|
520
|
+
case CommandType.DRAW_INDEXED:
|
|
521
|
+
pass.drawIndexed(
|
|
522
|
+
cmd.data.indexCount,
|
|
523
|
+
1,
|
|
524
|
+
cmd.data.firstIndex,
|
|
525
|
+
cmd.data.baseVertex,
|
|
526
|
+
0
|
|
527
|
+
);
|
|
528
|
+
ctx.stats.drawCalls++;
|
|
529
|
+
break;
|
|
530
|
+
|
|
531
|
+
case CommandType.DRAW_INSTANCED:
|
|
532
|
+
pass.draw(
|
|
533
|
+
cmd.data.vertexCount,
|
|
534
|
+
cmd.data.instanceCount,
|
|
535
|
+
cmd.data.firstVertex,
|
|
536
|
+
cmd.data.firstInstance
|
|
537
|
+
);
|
|
538
|
+
ctx.stats.drawCalls++;
|
|
539
|
+
break;
|
|
540
|
+
|
|
541
|
+
case CommandType.PUSH_STATE:
|
|
542
|
+
ctx.pushState();
|
|
543
|
+
break;
|
|
544
|
+
|
|
545
|
+
case CommandType.POP_STATE:
|
|
546
|
+
ctx.popState();
|
|
547
|
+
break;
|
|
548
|
+
}
|
|
549
|
+
}
|
|
550
|
+
|
|
551
|
+
/**
|
|
552
|
+
* Validate command structure
|
|
553
|
+
* @private
|
|
554
|
+
*/
|
|
555
|
+
_validateCommand(cmd) {
|
|
556
|
+
if (typeof cmd.type !== 'number') {
|
|
557
|
+
throw new Error('Invalid command type');
|
|
558
|
+
}
|
|
559
|
+
|
|
560
|
+
switch (cmd.type) {
|
|
561
|
+
case CommandType.CLEAR:
|
|
562
|
+
if (!Array.isArray(cmd.data.color) || cmd.data.color.length !== 4) {
|
|
563
|
+
throw new Error('CLEAR requires color array of 4 elements');
|
|
564
|
+
}
|
|
565
|
+
break;
|
|
566
|
+
|
|
567
|
+
case CommandType.SET_VIEWPORT:
|
|
568
|
+
case CommandType.SET_SCISSOR:
|
|
569
|
+
if (typeof cmd.data.width !== 'number' || typeof cmd.data.height !== 'number') {
|
|
570
|
+
throw new Error('Viewport/Scissor requires width and height');
|
|
571
|
+
}
|
|
572
|
+
break;
|
|
573
|
+
|
|
574
|
+
case CommandType.DRAW:
|
|
575
|
+
if (typeof cmd.data.vertexCount !== 'number') {
|
|
576
|
+
throw new Error('DRAW requires vertexCount');
|
|
577
|
+
}
|
|
578
|
+
break;
|
|
579
|
+
|
|
580
|
+
case CommandType.DRAW_INDEXED:
|
|
581
|
+
if (typeof cmd.data.indexCount !== 'number') {
|
|
582
|
+
throw new Error('DRAW_INDEXED requires indexCount');
|
|
583
|
+
}
|
|
584
|
+
break;
|
|
585
|
+
}
|
|
586
|
+
}
|
|
587
|
+
|
|
588
|
+
/**
|
|
589
|
+
* Get registered buffer
|
|
590
|
+
* @param {string|number} id
|
|
591
|
+
* @returns {WebGLBuffer|GPUBuffer|undefined}
|
|
592
|
+
*/
|
|
593
|
+
getBuffer(id) {
|
|
594
|
+
return this._bufferRegistry.get(id);
|
|
595
|
+
}
|
|
596
|
+
|
|
597
|
+
/**
|
|
598
|
+
* Clear all registered resources
|
|
599
|
+
*/
|
|
600
|
+
clearRegistries() {
|
|
601
|
+
this._bufferRegistry.clear();
|
|
602
|
+
this._textureRegistry.clear();
|
|
603
|
+
this._pipelineRegistry.clear();
|
|
604
|
+
}
|
|
605
|
+
}
|
|
606
|
+
|
|
607
|
+
export default CommandBufferExecutor;
|