@luma.gl/engine 10.0.0-alpha.3 → 10.0.0-alpha.5
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/README.md +9 -0
- package/dist/animation/animation-clip.cjs +36 -0
- package/dist/animation/animation-interpolation.cjs +115 -0
- package/dist/animation/animation-mixer.cjs +302 -0
- package/dist/animation/animation-track.cjs +55 -0
- package/dist/animation/animator.cjs +75 -0
- package/dist/animation/deform-positions.cjs +69 -0
- package/dist/animation/deform-positions.d.ts +13 -0
- package/dist/animation/deform-positions.d.ts.map +1 -0
- package/dist/animation/deform-positions.js +49 -0
- package/dist/animation/deform-positions.js.map +1 -0
- package/dist/animation/key-frames.cjs +81 -0
- package/dist/animation/morph-targets.cjs +162 -0
- package/dist/animation/node-animation-binding.cjs +67 -0
- package/dist/animation/node-animation-binding.d.ts +9 -0
- package/dist/animation/node-animation-binding.d.ts.map +1 -0
- package/dist/animation/node-animation-binding.js +45 -0
- package/dist/animation/node-animation-binding.js.map +1 -0
- package/dist/animation/property-animation-binding.cjs +159 -0
- package/dist/animation/property-animation-binding.d.ts +29 -0
- package/dist/animation/property-animation-binding.d.ts.map +1 -0
- package/dist/animation/property-animation-binding.js +138 -0
- package/dist/animation/property-animation-binding.js.map +1 -0
- package/dist/animation/scenegraph-animator.cjs +122 -0
- package/dist/animation/scenegraph-animator.d.ts +37 -0
- package/dist/animation/scenegraph-animator.d.ts.map +1 -0
- package/dist/animation/scenegraph-animator.js +99 -0
- package/dist/animation/scenegraph-animator.js.map +1 -0
- package/dist/animation/skin.cjs +49 -0
- package/dist/animation/texture-transform.cjs +41 -0
- package/dist/animation/texture-transform.d.ts +8 -0
- package/dist/animation/texture-transform.d.ts.map +1 -0
- package/dist/animation/texture-transform.js +17 -0
- package/dist/animation/texture-transform.js.map +1 -0
- package/dist/animation/timeline.cjs +129 -0
- package/dist/animation-loop/animation-loop-template.cjs +33 -0
- package/dist/animation-loop/animation-loop.cjs +498 -0
- package/dist/animation-loop/animation-loop.d.ts +2 -1
- package/dist/animation-loop/animation-loop.d.ts.map +1 -1
- package/dist/animation-loop/animation-loop.js +9 -3
- package/dist/animation-loop/animation-loop.js.map +1 -1
- package/dist/animation-loop/animation-props.cjs +15 -0
- package/dist/animation-loop/make-animation-loop.cjs +104 -0
- package/dist/animation-loop/request-animation-frame.cjs +43 -0
- package/dist/application-utils/load-file.cjs +77 -0
- package/dist/application-utils/random.cjs +38 -0
- package/dist/audio/audio-controller.cjs +429 -0
- package/dist/audio/audio-controller.d.ts +146 -0
- package/dist/audio/audio-controller.d.ts.map +1 -0
- package/dist/audio/audio-controller.js +445 -0
- package/dist/audio/audio-controller.js.map +1 -0
- package/dist/audio/audio-environment.cjs +157 -0
- package/dist/audio/audio-environment.d.ts +49 -0
- package/dist/audio/audio-environment.d.ts.map +1 -0
- package/dist/audio/audio-environment.js +148 -0
- package/dist/audio/audio-environment.js.map +1 -0
- package/dist/audio/audio-graph.cjs +182 -0
- package/dist/audio/audio-graph.d.ts +58 -0
- package/dist/audio/audio-graph.d.ts.map +1 -0
- package/dist/audio/audio-graph.js +181 -0
- package/dist/audio/audio-graph.js.map +1 -0
- package/dist/compute/buffer-transform.cjs +146 -0
- package/dist/compute/buffer-transform.d.ts +15 -5
- package/dist/compute/buffer-transform.d.ts.map +1 -1
- package/dist/compute/buffer-transform.js +56 -12
- package/dist/compute/buffer-transform.js.map +1 -1
- package/dist/compute/computation.cjs +331 -0
- package/dist/compute/computation.d.ts +2 -4
- package/dist/compute/computation.d.ts.map +1 -1
- package/dist/compute/computation.js +3 -14
- package/dist/compute/computation.js.map +1 -1
- package/dist/compute/swap.cjs +132 -0
- package/dist/compute/texture-transform.cjs +142 -0
- package/dist/compute/texture-transform.d.ts +11 -7
- package/dist/compute/texture-transform.d.ts.map +1 -1
- package/dist/compute/texture-transform.js +16 -6
- package/dist/compute/texture-transform.js.map +1 -1
- package/dist/controls/orbit-controls.cjs +283 -0
- package/dist/controls/orbit-controls.d.ts +2 -0
- package/dist/controls/orbit-controls.d.ts.map +1 -1
- package/dist/controls/orbit-controls.js +2 -1
- package/dist/controls/orbit-controls.js.map +1 -1
- package/dist/debug/copy-texture-to-image.cjs +84 -0
- package/dist/debug/debug-framebuffer.cjs +113 -0
- package/dist/debug/debug-shader-layout.cjs +45 -0
- package/dist/debug/pixel-data-utils.cjs +54 -0
- package/dist/dist.dev.js +11517 -6015
- package/dist/dist.min.js +39 -35
- package/dist/dynamic-buffer/dynamic-buffer.cjs +39 -0
- package/dist/dynamic-buffer/dynamic-buffer.d.ts +1 -170
- package/dist/dynamic-buffer/dynamic-buffer.d.ts.map +1 -1
- package/dist/dynamic-buffer/dynamic-buffer.js +2 -312
- package/dist/dynamic-buffer/dynamic-buffer.js.map +1 -1
- package/dist/dynamic-texture/dynamic-texture.cjs +27 -0
- package/dist/dynamic-texture/dynamic-texture.d.ts +1 -114
- package/dist/dynamic-texture/dynamic-texture.d.ts.map +1 -1
- package/dist/dynamic-texture/dynamic-texture.js +2 -584
- package/dist/dynamic-texture/dynamic-texture.js.map +1 -1
- package/dist/dynamic-texture/texture-binding-source.cjs +31 -0
- package/dist/dynamic-texture/texture-binding-source.d.ts +1 -54
- package/dist/dynamic-texture/texture-binding-source.d.ts.map +1 -1
- package/dist/dynamic-texture/texture-binding-source.js +2 -51
- package/dist/dynamic-texture/texture-binding-source.js.map +1 -1
- package/dist/dynamic-texture/texture-data.cjs +53 -0
- package/dist/dynamic-texture/texture-data.d.ts +1 -145
- package/dist/dynamic-texture/texture-data.d.ts.map +1 -1
- package/dist/dynamic-texture/texture-data.js +2 -209
- package/dist/dynamic-texture/texture-data.js.map +1 -1
- package/dist/dynamic-texture/video-texture.cjs +269 -0
- package/dist/dynamic-texture/video-texture.d.ts +1 -1
- package/dist/dynamic-texture/video-texture.d.ts.map +1 -1
- package/dist/experimental/controls/comparison-splitter.cjs +231 -0
- package/dist/experimental/controls/comparison-splitter.d.ts +54 -0
- package/dist/experimental/controls/comparison-splitter.d.ts.map +1 -0
- package/dist/experimental/controls/comparison-splitter.js +215 -0
- package/dist/experimental/controls/comparison-splitter.js.map +1 -0
- package/dist/experimental/controls/flat-controller.cjs +301 -0
- package/dist/experimental/controls/flat-controller.d.ts +80 -0
- package/dist/experimental/controls/flat-controller.d.ts.map +1 -0
- package/dist/experimental/controls/flat-controller.js +295 -0
- package/dist/experimental/controls/flat-controller.js.map +1 -0
- package/dist/experimental/controls/index.cjs +35 -0
- package/dist/experimental/controls/index.cjs.map +6 -0
- package/dist/experimental/controls/index.d.ts +7 -0
- package/dist/experimental/controls/index.d.ts.map +1 -0
- package/dist/experimental/controls/index.js +7 -0
- package/dist/experimental/controls/index.js.map +1 -0
- package/dist/experimental/controls/orbit-controls.cjs +27 -0
- package/dist/experimental/controls/orbit-controls.d.ts +3 -0
- package/dist/experimental/controls/orbit-controls.d.ts.map +1 -0
- package/dist/experimental/controls/orbit-controls.js +5 -0
- package/dist/experimental/controls/orbit-controls.js.map +1 -0
- package/dist/experimental/materials/emissive-material.cjs +126 -0
- package/dist/experimental/materials/emissive-material.d.ts +38 -0
- package/dist/experimental/materials/emissive-material.d.ts.map +1 -0
- package/dist/experimental/materials/emissive-material.js +100 -0
- package/dist/experimental/materials/emissive-material.js.map +1 -0
- package/dist/experimental/materials/glass-material.cjs +570 -0
- package/dist/experimental/materials/glass-material.d.ts +107 -0
- package/dist/experimental/materials/glass-material.d.ts.map +1 -0
- package/dist/experimental/materials/glass-material.js +544 -0
- package/dist/experimental/materials/glass-material.js.map +1 -0
- package/dist/experimental/materials/glass-transmission.cjs +954 -0
- package/dist/experimental/materials/glass-transmission.d.ts +193 -0
- package/dist/experimental/materials/glass-transmission.d.ts.map +1 -0
- package/dist/experimental/materials/glass-transmission.js +928 -0
- package/dist/experimental/materials/glass-transmission.js.map +1 -0
- package/dist/experimental/materials/index.cjs +61 -0
- package/dist/experimental/materials/index.cjs.map +6 -0
- package/dist/experimental/materials/index.d.ts +14 -0
- package/dist/experimental/materials/index.d.ts.map +1 -0
- package/dist/experimental/materials/index.js +11 -0
- package/dist/experimental/materials/index.js.map +1 -0
- package/dist/experimental/materials/optical-caustics.cjs +201 -0
- package/dist/experimental/materials/optical-caustics.d.ts +69 -0
- package/dist/experimental/materials/optical-caustics.d.ts.map +1 -0
- package/dist/experimental/materials/optical-caustics.js +180 -0
- package/dist/experimental/materials/optical-caustics.js.map +1 -0
- package/dist/experimental/materials/optical-lighting.cjs +169 -0
- package/dist/experimental/materials/optical-lighting.d.ts +7 -0
- package/dist/experimental/materials/optical-lighting.d.ts.map +1 -0
- package/dist/experimental/materials/optical-lighting.js +144 -0
- package/dist/experimental/materials/optical-lighting.js.map +1 -0
- package/dist/experimental/materials/optical-point-lights.cjs +258 -0
- package/dist/experimental/materials/optical-point-lights.d.ts +68 -0
- package/dist/experimental/materials/optical-point-lights.d.ts.map +1 -0
- package/dist/experimental/materials/optical-point-lights.js +237 -0
- package/dist/experimental/materials/optical-point-lights.js.map +1 -0
- package/dist/experimental/materials/reflective-material.cjs +216 -0
- package/dist/experimental/materials/reflective-material.d.ts +46 -0
- package/dist/experimental/materials/reflective-material.d.ts.map +1 -0
- package/dist/experimental/materials/reflective-material.js +190 -0
- package/dist/experimental/materials/reflective-material.js.map +1 -0
- package/dist/experimental/textures/html-texture.cjs +221 -0
- package/dist/experimental/textures/html-texture.d.ts +85 -0
- package/dist/experimental/textures/html-texture.d.ts.map +1 -0
- package/dist/experimental/textures/html-texture.js +206 -0
- package/dist/experimental/textures/html-texture.js.map +1 -0
- package/dist/experimental/textures/index.cjs +33 -0
- package/dist/experimental/textures/index.cjs.map +6 -0
- package/dist/experimental/textures/index.d.ts +5 -0
- package/dist/experimental/textures/index.d.ts.map +1 -0
- package/dist/experimental/textures/index.js +7 -0
- package/dist/experimental/textures/index.js.map +1 -0
- package/dist/experimental/textures/packed-pixels.cjs +248 -0
- package/dist/experimental/textures/packed-pixels.d.ts +17 -0
- package/dist/experimental/textures/packed-pixels.d.ts.map +1 -0
- package/dist/experimental/textures/packed-pixels.js +237 -0
- package/dist/experimental/textures/packed-pixels.js.map +1 -0
- package/dist/experimental/textures/rgba-decoder.cjs +60 -0
- package/dist/experimental/textures/rgba-decoder.d.ts +29 -0
- package/dist/experimental/textures/rgba-decoder.d.ts.map +1 -0
- package/dist/experimental/textures/rgba-decoder.js +43 -0
- package/dist/experimental/textures/rgba-decoder.js.map +1 -0
- package/dist/experimental/webxr/index.cjs +38 -0
- package/dist/experimental/webxr/index.cjs.map +6 -0
- package/dist/experimental/webxr/index.d.ts +9 -0
- package/dist/experimental/webxr/index.d.ts.map +1 -0
- package/dist/experimental/webxr/index.js +8 -0
- package/dist/experimental/webxr/index.js.map +1 -0
- package/dist/experimental/webxr/webxr-animation-frame-provider.cjs +38 -0
- package/dist/experimental/webxr/webxr-animation-frame-provider.d.ts +9 -0
- package/dist/experimental/webxr/webxr-animation-frame-provider.d.ts.map +1 -0
- package/dist/experimental/webxr/webxr-animation-frame-provider.js +17 -0
- package/dist/experimental/webxr/webxr-animation-frame-provider.js.map +1 -0
- package/dist/experimental/webxr/webxr-camera-texture.cjs +157 -0
- package/dist/experimental/webxr/webxr-camera-texture.d.ts +48 -0
- package/dist/experimental/webxr/webxr-camera-texture.d.ts.map +1 -0
- package/dist/experimental/webxr/webxr-camera-texture.js +144 -0
- package/dist/experimental/webxr/webxr-camera-texture.js.map +1 -0
- package/dist/experimental/webxr/webxr-input.cjs +93 -0
- package/dist/experimental/webxr/webxr-input.d.ts +24 -0
- package/dist/experimental/webxr/webxr-input.d.ts.map +1 -0
- package/dist/experimental/webxr/webxr-input.js +70 -0
- package/dist/experimental/webxr/webxr-input.js.map +1 -0
- package/dist/experimental/webxr/webxr-manager.cjs +356 -0
- package/dist/experimental/webxr/webxr-manager.d.ts +91 -0
- package/dist/experimental/webxr/webxr-manager.d.ts.map +1 -0
- package/dist/experimental/webxr/webxr-manager.js +354 -0
- package/dist/experimental/webxr/webxr-manager.js.map +1 -0
- package/dist/experimental/webxr/webxr-types.cjs +15 -0
- package/dist/experimental/webxr/webxr-types.d.ts +152 -0
- package/dist/experimental/webxr/webxr-types.d.ts.map +1 -0
- package/dist/experimental/webxr/webxr-types.js +5 -0
- package/dist/experimental/webxr/webxr-types.js.map +1 -0
- package/dist/geometry/edge-geometry.cjs +171 -0
- package/dist/geometry/edge-geometry.d.ts +3 -2
- package/dist/geometry/edge-geometry.d.ts.map +1 -1
- package/dist/geometry/edge-geometry.js.map +1 -1
- package/dist/geometry/geometry-primitives.cjs +189 -0
- package/dist/geometry/geometry-primitives.d.ts +60 -0
- package/dist/geometry/geometry-primitives.d.ts.map +1 -0
- package/dist/geometry/geometry-primitives.js +161 -0
- package/dist/geometry/geometry-primitives.js.map +1 -0
- package/dist/geometry/geometry-table.cjs +15 -0
- package/dist/geometry/geometry-utils.cjs +147 -0
- package/dist/geometry/geometry-utils.d.ts +7 -15
- package/dist/geometry/geometry-utils.d.ts.map +1 -1
- package/dist/geometry/geometry-utils.js +9 -55
- package/dist/geometry/geometry-utils.js.map +1 -1
- package/dist/geometry/geometry.cjs +90 -0
- package/dist/geometry/geometry.d.ts +9 -69
- package/dist/geometry/geometry.d.ts.map +1 -1
- package/dist/geometry/geometry.js +27 -93
- package/dist/geometry/geometry.js.map +1 -1
- package/dist/geometry/gpu-geometry.cjs +130 -0
- package/dist/geometry/gpu-geometry.d.ts +4 -2
- package/dist/geometry/gpu-geometry.d.ts.map +1 -1
- package/dist/geometry/gpu-geometry.js +3 -3
- package/dist/geometry/gpu-geometry.js.map +1 -1
- package/dist/geometry/gpu-vector-geometry-adapter.cjs +88 -0
- package/dist/geometry/gpu-vector-geometry-adapter.d.ts +5 -0
- package/dist/geometry/gpu-vector-geometry-adapter.d.ts.map +1 -0
- package/dist/geometry/gpu-vector-geometry-adapter.js +73 -0
- package/dist/geometry/gpu-vector-geometry-adapter.js.map +1 -0
- package/dist/geometry/gpu-vector-geometry.cjs +40 -0
- package/dist/geometry/gpu-vector-geometry.d.ts +21 -0
- package/dist/geometry/gpu-vector-geometry.d.ts.map +1 -0
- package/dist/geometry/gpu-vector-geometry.js +19 -0
- package/dist/geometry/gpu-vector-geometry.js.map +1 -0
- package/dist/geometry/mesh-simplification.cjs +385 -0
- package/dist/geometry/ring-geometry.cjs +104 -0
- package/dist/geometry/ring-geometry.d.ts +17 -0
- package/dist/geometry/ring-geometry.d.ts.map +1 -0
- package/dist/geometry/ring-geometry.js +94 -0
- package/dist/geometry/ring-geometry.js.map +1 -0
- package/dist/geometry/stroke-geometry.cjs +171 -0
- package/dist/graph/models/index.cjs +66 -0
- package/dist/graph/models/index.cjs.map +6 -0
- package/dist/graph/models/index.d.ts +7 -0
- package/dist/graph/models/index.d.ts.map +1 -0
- package/dist/graph/models/index.js +10 -0
- package/dist/graph/models/index.js.map +1 -0
- package/dist/graph/models/path/path-attribute-model.cjs +421 -0
- package/dist/graph/models/path/path-attribute-model.d.ts +142 -0
- package/dist/graph/models/path/path-attribute-model.d.ts.map +1 -0
- package/dist/graph/models/path/path-attribute-model.js +409 -0
- package/dist/graph/models/path/path-attribute-model.js.map +1 -0
- package/dist/graph/models/path/path-storage-model.cjs +711 -0
- package/dist/graph/models/path/path-storage-model.d.ts +174 -0
- package/dist/graph/models/path/path-storage-model.d.ts.map +1 -0
- package/dist/graph/models/path/path-storage-model.js +720 -0
- package/dist/graph/models/path/path-storage-model.js.map +1 -0
- package/dist/graph/models/path/path-trips-storage-model.cjs +271 -0
- package/dist/graph/models/path/path-trips-storage-model.d.ts +58 -0
- package/dist/graph/models/path/path-trips-storage-model.d.ts.map +1 -0
- package/dist/graph/models/path/path-trips-storage-model.js +248 -0
- package/dist/graph/models/path/path-trips-storage-model.js.map +1 -0
- package/dist/graph/models/polygon/polygon-attribute-model.cjs +117 -0
- package/dist/graph/models/polygon/polygon-attribute-model.d.ts +53 -0
- package/dist/graph/models/polygon/polygon-attribute-model.d.ts.map +1 -0
- package/dist/graph/models/polygon/polygon-attribute-model.js +101 -0
- package/dist/graph/models/polygon/polygon-attribute-model.js.map +1 -0
- package/dist/graph/models/polygon/polygon-shaders.cjs +283 -0
- package/dist/graph/models/polygon/polygon-shaders.d.ts +77 -0
- package/dist/graph/models/polygon/polygon-shaders.d.ts.map +1 -0
- package/dist/graph/models/polygon/polygon-shaders.js +242 -0
- package/dist/graph/models/polygon/polygon-shaders.js.map +1 -0
- package/dist/graph/models/polygon/polygon-storage-model.cjs +111 -0
- package/dist/graph/models/polygon/polygon-storage-model.d.ts +53 -0
- package/dist/graph/models/polygon/polygon-storage-model.d.ts.map +1 -0
- package/dist/graph/models/polygon/polygon-storage-model.js +92 -0
- package/dist/graph/models/polygon/polygon-storage-model.js.map +1 -0
- package/dist/graph/physics/index.cjs +50 -0
- package/dist/graph/physics/index.cjs.map +6 -0
- package/dist/graph/physics/index.d.ts +12 -0
- package/dist/graph/physics/index.d.ts.map +1 -0
- package/dist/graph/physics/index.js +12 -0
- package/dist/graph/physics/index.js.map +1 -0
- package/dist/graph/physics/physics-scenegraph.cjs +92 -0
- package/dist/graph/physics/physics-scenegraph.d.ts +35 -0
- package/dist/graph/physics/physics-scenegraph.d.ts.map +1 -0
- package/dist/graph/physics/physics-scenegraph.js +80 -0
- package/dist/graph/physics/physics-scenegraph.js.map +1 -0
- package/dist/graph/physics/scenegraph-behaviors.cjs +164 -0
- package/dist/graph/physics/scenegraph-behaviors.d.ts +37 -0
- package/dist/graph/physics/scenegraph-behaviors.d.ts.map +1 -0
- package/dist/graph/physics/scenegraph-behaviors.js +145 -0
- package/dist/graph/physics/scenegraph-behaviors.js.map +1 -0
- package/dist/graph/physics/scenegraph-instance.cjs +246 -0
- package/dist/graph/physics/scenegraph-instance.d.ts +59 -0
- package/dist/graph/physics/scenegraph-instance.d.ts.map +1 -0
- package/dist/graph/physics/scenegraph-instance.js +241 -0
- package/dist/graph/physics/scenegraph-instance.js.map +1 -0
- package/dist/graph/physics/scenegraph-joints.cjs +51 -0
- package/dist/graph/physics/scenegraph-joints.d.ts +5 -0
- package/dist/graph/physics/scenegraph-joints.d.ts.map +1 -0
- package/dist/graph/physics/scenegraph-joints.js +31 -0
- package/dist/graph/physics/scenegraph-joints.js.map +1 -0
- package/dist/graph/physics/scenegraph-motion.cjs +177 -0
- package/dist/graph/physics/scenegraph-motion.d.ts +37 -0
- package/dist/graph/physics/scenegraph-motion.d.ts.map +1 -0
- package/dist/graph/physics/scenegraph-motion.js +168 -0
- package/dist/graph/physics/scenegraph-motion.js.map +1 -0
- package/dist/graph/physics/scenegraph-properties.cjs +170 -0
- package/dist/graph/physics/scenegraph-properties.d.ts +37 -0
- package/dist/graph/physics/scenegraph-properties.d.ts.map +1 -0
- package/dist/graph/physics/scenegraph-properties.js +186 -0
- package/dist/graph/physics/scenegraph-properties.js.map +1 -0
- package/dist/graph/physics/scenegraph-publication.cjs +112 -0
- package/dist/graph/physics/scenegraph-publication.d.ts +23 -0
- package/dist/graph/physics/scenegraph-publication.d.ts.map +1 -0
- package/dist/graph/physics/scenegraph-publication.js +99 -0
- package/dist/graph/physics/scenegraph-publication.js.map +1 -0
- package/dist/graph/physics/scenegraph-session.cjs +256 -0
- package/dist/graph/physics/scenegraph-session.d.ts +68 -0
- package/dist/graph/physics/scenegraph-session.d.ts.map +1 -0
- package/dist/graph/physics/scenegraph-session.js +249 -0
- package/dist/graph/physics/scenegraph-session.js.map +1 -0
- package/dist/graph/tables/gpu-table-geometry.cjs +84 -0
- package/dist/graph/tables/gpu-table-geometry.d.ts +32 -0
- package/dist/graph/tables/gpu-table-geometry.d.ts.map +1 -0
- package/dist/graph/tables/gpu-table-geometry.js +67 -0
- package/dist/graph/tables/gpu-table-geometry.js.map +1 -0
- package/dist/graph/tables/gpu-table-model.cjs +459 -0
- package/dist/graph/tables/gpu-table-model.d.ts +67 -0
- package/dist/graph/tables/gpu-table-model.d.ts.map +1 -0
- package/dist/graph/tables/gpu-table-model.js +457 -0
- package/dist/graph/tables/gpu-table-model.js.map +1 -0
- package/dist/graph/tables/gpu-table-transform.cjs +341 -0
- package/dist/graph/tables/gpu-table-transform.d.ts +61 -0
- package/dist/graph/tables/gpu-table-transform.d.ts.map +1 -0
- package/dist/graph/tables/gpu-table-transform.js +333 -0
- package/dist/graph/tables/gpu-table-transform.js.map +1 -0
- package/dist/graph/tables/index.cjs +33 -0
- package/dist/graph/tables/index.cjs.map +6 -0
- package/dist/graph/tables/index.d.ts +4 -0
- package/dist/graph/tables/index.d.ts.map +1 -0
- package/dist/graph/tables/index.js +7 -0
- package/dist/graph/tables/index.js.map +1 -0
- package/dist/index.cjs +303 -10629
- package/dist/index.cjs.map +3 -3
- package/dist/index.d.ts +46 -19
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +33 -10
- package/dist/index.js.map +1 -1
- package/dist/interactivity/interactivity.cjs +570 -0
- package/dist/interactivity/interactivity.d.ts +107 -0
- package/dist/interactivity/interactivity.d.ts.map +1 -0
- package/dist/interactivity/interactivity.js +575 -0
- package/dist/interactivity/interactivity.js.map +1 -0
- package/dist/interactivity/physics.cjs +15 -0
- package/dist/interactivity/physics.d.ts +12 -0
- package/dist/interactivity/physics.d.ts.map +1 -0
- package/dist/interactivity/physics.js +5 -0
- package/dist/interactivity/physics.js.map +1 -0
- package/dist/material/material-factory.cjs +99 -0
- package/dist/material/material-factory.d.ts +1 -1
- package/dist/material/material-factory.d.ts.map +1 -1
- package/dist/material/material.cjs +239 -0
- package/dist/material/material.d.ts +2 -2
- package/dist/material/material.d.ts.map +1 -1
- package/dist/material/material.js +2 -2
- package/dist/material/material.js.map +1 -1
- package/dist/model/gpu-vector-bindings.cjs +226 -0
- package/dist/model/gpu-vector-bindings.d.ts +36 -0
- package/dist/model/gpu-vector-bindings.d.ts.map +1 -0
- package/dist/model/gpu-vector-bindings.js +217 -0
- package/dist/model/gpu-vector-bindings.js.map +1 -0
- package/dist/model/gpu-vector-draw-batches.cjs +82 -0
- package/dist/model/gpu-vector-draw-batches.d.ts +5 -0
- package/dist/model/gpu-vector-draw-batches.d.ts.map +1 -0
- package/dist/model/gpu-vector-draw-batches.js +73 -0
- package/dist/model/gpu-vector-draw-batches.js.map +1 -0
- package/dist/model/gpu-vector-model-batches.cjs +94 -0
- package/dist/model/gpu-vector-model-batches.d.ts +41 -0
- package/dist/model/gpu-vector-model-batches.d.ts.map +1 -0
- package/dist/model/gpu-vector-model-batches.js +77 -0
- package/dist/model/gpu-vector-model-batches.js.map +1 -0
- package/dist/model/gpu-vector-model.cjs +1264 -0
- package/dist/model/gpu-vector-model.d.ts +352 -0
- package/dist/model/gpu-vector-model.d.ts.map +1 -0
- package/dist/model/gpu-vector-model.js +1375 -0
- package/dist/model/gpu-vector-model.js.map +1 -0
- package/dist/model/model.cjs +134 -0
- package/dist/model/model.d.ts +22 -306
- package/dist/model/model.d.ts.map +1 -1
- package/dist/model/model.js +68 -1092
- package/dist/model/model.js.map +1 -1
- package/dist/model/split-uniforms-and-bindings.cjs +44 -0
- package/dist/model/split-uniforms-and-bindings.d.ts +1 -1
- package/dist/model/split-uniforms-and-bindings.d.ts.map +1 -1
- package/dist/model/split-uniforms-and-bindings.js +5 -2
- package/dist/model/split-uniforms-and-bindings.js.map +1 -1
- package/dist/models/billboard-texture-model.cjs +167 -0
- package/dist/models/billboard-texture-model.d.ts +1 -1
- package/dist/models/billboard-texture-model.d.ts.map +1 -1
- package/dist/models/billboard-texture-model.js +1 -1
- package/dist/models/billboard-texture-model.js.map +1 -1
- package/dist/models/billboard-texture-module.cjs +61 -0
- package/dist/models/clip-space.cjs +103 -0
- package/dist/models/clip-space.d.ts +4 -1
- package/dist/models/clip-space.d.ts.map +1 -1
- package/dist/models/clip-space.js +16 -13
- package/dist/models/clip-space.js.map +1 -1
- package/dist/models/directional-light-model.cjs +45 -0
- package/dist/models/directional-light-model.js +1 -1
- package/dist/models/directional-light-model.js.map +1 -1
- package/dist/models/light-model-utils.cjs +426 -0
- package/dist/models/point-light-model.cjs +44 -0
- package/dist/models/point-light-model.js +1 -1
- package/dist/models/point-light-model.js.map +1 -1
- package/dist/models/spot-light-model.cjs +45 -0
- package/dist/models/spot-light-model.js +1 -1
- package/dist/models/spot-light-model.js.map +1 -1
- package/dist/modules/picking/color-picking.cjs +209 -0
- package/dist/modules/picking/color-picking.d.ts +1 -1
- package/dist/modules/picking/index-color-picking.cjs +230 -0
- package/dist/modules/picking/index-color-picking.d.ts +1 -1
- package/dist/modules/picking/index-picking.cjs +201 -0
- package/dist/modules/picking/index-picking.d.ts +1 -1
- package/dist/modules/picking/legacy-color-picking.cjs +28 -0
- package/dist/modules/picking/legacy-color-picking.d.ts +1 -1
- package/dist/modules/picking/legacy-picking-manager.cjs +92 -0
- package/dist/modules/picking/picking-manager.cjs +360 -0
- package/dist/modules/picking/picking-uniforms.cjs +140 -0
- package/dist/modules/picking/picking-uniforms.d.ts +1 -1
- package/dist/modules/picking/picking-uniforms.d.ts.map +1 -1
- package/dist/modules/picking/picking.cjs +43 -0
- package/dist/modules/picking/picking.d.ts +1 -1
- package/dist/passes/get-fragment-shader.cjs +119 -0
- package/dist/passes/shader-pass-renderer.cjs +722 -0
- package/dist/passes/shader-pass-renderer.d.ts +2 -2
- package/dist/passes/shader-pass-renderer.d.ts.map +1 -1
- package/dist/passes/shader-pass-renderer.js +1 -1
- package/dist/passes/shader-pass-renderer.js.map +1 -1
- package/dist/passes/texture-transform-module.cjs +78 -0
- package/dist/scenegraph/controllers/area-light-controller.cjs +143 -0
- package/dist/scenegraph/controllers/area-light-controller.d.ts +31 -0
- package/dist/scenegraph/controllers/area-light-controller.d.ts.map +1 -0
- package/dist/scenegraph/controllers/area-light-controller.js +130 -0
- package/dist/scenegraph/controllers/area-light-controller.js.map +1 -0
- package/dist/scenegraph/controllers/billboard-controller.cjs +156 -0
- package/dist/scenegraph/controllers/billboard-controller.d.ts +45 -0
- package/dist/scenegraph/controllers/billboard-controller.d.ts.map +1 -0
- package/dist/scenegraph/controllers/billboard-controller.js +156 -0
- package/dist/scenegraph/controllers/billboard-controller.js.map +1 -0
- package/dist/scenegraph/controllers/joint-controller.cjs +71 -0
- package/dist/scenegraph/controllers/joint-controller.d.ts +30 -0
- package/dist/scenegraph/controllers/joint-controller.d.ts.map +1 -0
- package/dist/scenegraph/controllers/joint-controller.js +53 -0
- package/dist/scenegraph/controllers/joint-controller.js.map +1 -0
- package/dist/scenegraph/controllers/material-variants.cjs +61 -0
- package/dist/scenegraph/controllers/material-variants.d.ts +42 -0
- package/dist/scenegraph/controllers/material-variants.d.ts.map +1 -0
- package/dist/scenegraph/controllers/material-variants.js +40 -0
- package/dist/scenegraph/controllers/material-variants.js.map +1 -0
- package/dist/scenegraph/controllers/morph-controller.cjs +61 -0
- package/dist/scenegraph/controllers/morph-controller.d.ts +19 -0
- package/dist/scenegraph/controllers/morph-controller.d.ts.map +1 -0
- package/dist/scenegraph/controllers/morph-controller.js +41 -0
- package/dist/scenegraph/controllers/morph-controller.js.map +1 -0
- package/dist/scenegraph/controllers/skin-controller.cjs +111 -0
- package/dist/scenegraph/controllers/skin-controller.d.ts +36 -0
- package/dist/scenegraph/controllers/skin-controller.d.ts.map +1 -0
- package/dist/scenegraph/controllers/skin-controller.js +90 -0
- package/dist/scenegraph/controllers/skin-controller.js.map +1 -0
- package/dist/scenegraph/group-node.cjs +129 -0
- package/dist/scenegraph/model-node.cjs +68 -0
- package/dist/scenegraph/physics-transforms.cjs +95 -0
- package/dist/scenegraph/physics-transforms.d.ts +13 -0
- package/dist/scenegraph/physics-transforms.d.ts.map +1 -0
- package/dist/scenegraph/physics-transforms.js +72 -0
- package/dist/scenegraph/physics-transforms.js.map +1 -0
- package/dist/scenegraph/published-transforms.cjs +37 -0
- package/dist/scenegraph/published-transforms.d.ts +17 -0
- package/dist/scenegraph/published-transforms.d.ts.map +1 -0
- package/dist/scenegraph/published-transforms.js +16 -0
- package/dist/scenegraph/published-transforms.js.map +1 -0
- package/dist/scenegraph/scenegraph-bounds.cjs +51 -0
- package/dist/scenegraph/scenegraph-node.cjs +182 -0
- package/dist/shader-inputs.cjs +231 -0
- package/dist/shader-inputs.d.ts +1 -1
- package/dist/shader-inputs.d.ts.map +1 -1
- package/dist/utils/buffer-layout-helper.cjs +52 -0
- package/dist/utils/buffer-layout-order.cjs +37 -0
- package/dist/utils/deep-equal.cjs +65 -0
- package/dist/utils/get-platform-info.cjs +21 -0
- package/dist/utils/get-platform-info.d.ts +2 -0
- package/dist/utils/get-platform-info.d.ts.map +1 -0
- package/dist/utils/get-platform-info.js +5 -0
- package/dist/utils/get-platform-info.js.map +1 -0
- package/dist/utils/gpu-vector-batch-structure.cjs +45 -0
- package/dist/utils/gpu-vector-batch-structure.d.ts +12 -0
- package/dist/utils/gpu-vector-batch-structure.d.ts.map +1 -0
- package/dist/utils/gpu-vector-batch-structure.js +27 -0
- package/dist/utils/gpu-vector-batch-structure.js.map +1 -0
- package/dist/utils/shader-module-utils.cjs +148 -0
- package/dist/utils/uid.cjs +32 -0
- package/package.json +47 -8
- package/src/animation/deform-positions.ts +62 -0
- package/src/animation/node-animation-binding.ts +54 -0
- package/src/animation/property-animation-binding.ts +212 -0
- package/src/animation/scenegraph-animator.ts +117 -0
- package/src/animation/texture-transform.ts +59 -0
- package/src/animation-loop/animation-loop.ts +10 -3
- package/src/audio/audio-controller.ts +583 -0
- package/src/audio/audio-environment.ts +202 -0
- package/src/audio/audio-graph.ts +253 -0
- package/src/compute/buffer-transform.ts +71 -16
- package/src/compute/computation.ts +4 -19
- package/src/compute/texture-transform.ts +25 -12
- package/src/controls/orbit-controls.ts +4 -1
- package/src/dynamic-buffer/dynamic-buffer.ts +15 -449
- package/src/dynamic-texture/dynamic-texture.ts +5 -760
- package/src/dynamic-texture/texture-binding-source.ts +8 -90
- package/src/dynamic-texture/texture-data.ts +31 -340
- package/src/dynamic-texture/video-texture.ts +1 -1
- package/src/experimental/controls/comparison-splitter.ts +269 -0
- package/src/experimental/controls/flat-controller.ts +403 -0
- package/src/experimental/controls/index.ts +16 -0
- package/src/experimental/controls/orbit-controls.ts +6 -0
- package/src/experimental/materials/emissive-material.ts +120 -0
- package/src/experimental/materials/glass-material.ts +607 -0
- package/src/experimental/materials/glass-transmission.ts +1023 -0
- package/src/experimental/materials/index.ts +49 -0
- package/src/experimental/materials/optical-caustics.ts +234 -0
- package/src/experimental/materials/optical-lighting.ts +148 -0
- package/src/experimental/materials/optical-point-lights.ts +288 -0
- package/src/experimental/materials/reflective-material.ts +214 -0
- package/src/experimental/textures/html-texture.ts +285 -0
- package/src/experimental/textures/index.ts +8 -0
- package/src/experimental/textures/packed-pixels.ts +351 -0
- package/src/experimental/textures/rgba-decoder.ts +79 -0
- package/src/experimental/webxr/index.ts +21 -0
- package/src/experimental/webxr/webxr-animation-frame-provider.ts +22 -0
- package/src/experimental/webxr/webxr-camera-texture.ts +195 -0
- package/src/experimental/webxr/webxr-input.ts +117 -0
- package/src/experimental/webxr/webxr-manager.ts +524 -0
- package/src/experimental/webxr/webxr-types.ts +192 -0
- package/src/geometry/edge-geometry.ts +7 -3
- package/src/geometry/geometry-primitives.ts +226 -0
- package/src/geometry/geometry-utils.ts +16 -71
- package/src/geometry/geometry.ts +36 -163
- package/src/geometry/gpu-geometry.ts +9 -4
- package/src/geometry/gpu-vector-geometry-adapter.ts +78 -0
- package/src/geometry/gpu-vector-geometry.ts +33 -0
- package/src/geometry/ring-geometry.ts +117 -0
- package/src/graph/models/index.ts +45 -0
- package/src/graph/models/path/path-attribute-model.ts +563 -0
- package/src/graph/models/path/path-storage-model.ts +996 -0
- package/src/graph/models/path/path-trips-storage-model.ts +286 -0
- package/src/graph/models/polygon/polygon-attribute-model.ts +165 -0
- package/src/graph/models/polygon/polygon-shaders.ts +279 -0
- package/src/graph/models/polygon/polygon-storage-model.ts +146 -0
- package/src/graph/physics/index.ts +24 -0
- package/src/graph/physics/physics-scenegraph.ts +112 -0
- package/src/graph/physics/scenegraph-behaviors.ts +169 -0
- package/src/graph/physics/scenegraph-instance.ts +296 -0
- package/src/graph/physics/scenegraph-joints.ts +37 -0
- package/src/graph/physics/scenegraph-motion.ts +175 -0
- package/src/graph/physics/scenegraph-properties.ts +241 -0
- package/src/graph/physics/scenegraph-publication.ts +116 -0
- package/src/graph/physics/scenegraph-session.ts +317 -0
- package/src/graph/tables/gpu-table-geometry.ts +88 -0
- package/src/graph/tables/gpu-table-model.ts +661 -0
- package/src/graph/tables/gpu-table-transform.ts +497 -0
- package/src/graph/tables/index.ts +18 -0
- package/src/index.ts +144 -27
- package/src/interactivity/interactivity.ts +670 -0
- package/src/interactivity/physics.ts +19 -0
- package/src/material/material-factory.ts +1 -1
- package/src/material/material.ts +2 -2
- package/src/model/gpu-vector-bindings.ts +276 -0
- package/src/model/gpu-vector-draw-batches.ts +116 -0
- package/src/model/gpu-vector-model-batches.ts +142 -0
- package/src/model/gpu-vector-model.ts +1819 -0
- package/src/model/model.ts +91 -1444
- package/src/model/split-uniforms-and-bindings.ts +6 -3
- package/src/models/billboard-texture-model.ts +1 -1
- package/src/models/clip-space.ts +21 -14
- package/src/models/directional-light-model.ts +1 -1
- package/src/models/point-light-model.ts +1 -1
- package/src/models/spot-light-model.ts +1 -1
- package/src/modules/picking/legacy-picking-manager.ts +1 -1
- package/src/modules/picking/picking-uniforms.ts +1 -1
- package/src/passes/shader-pass-renderer.ts +2 -2
- package/src/scenegraph/controllers/area-light-controller.ts +152 -0
- package/src/scenegraph/controllers/billboard-controller.ts +204 -0
- package/src/scenegraph/controllers/joint-controller.ts +81 -0
- package/src/scenegraph/controllers/material-variants.ts +70 -0
- package/src/scenegraph/controllers/morph-controller.ts +61 -0
- package/src/scenegraph/controllers/skin-controller.ts +125 -0
- package/src/scenegraph/physics-transforms.ts +82 -0
- package/src/scenegraph/published-transforms.ts +18 -0
- package/src/shader-inputs.ts +1 -1
- package/src/utils/get-platform-info.ts +5 -0
- package/src/utils/gpu-vector-batch-structure.ts +36 -0
- package/dist/compute/kernel.d.ts +0 -54
- package/dist/compute/kernel.d.ts.map +0 -1
- package/dist/compute/kernel.js +0 -103
- package/dist/compute/kernel.js.map +0 -1
- package/dist/compute/render-kernel.d.ts +0 -65
- package/dist/compute/render-kernel.d.ts.map +0 -1
- package/dist/compute/render-kernel.js +0 -129
- package/dist/compute/render-kernel.js.map +0 -1
- package/dist/geometries/cone-geometry.d.ts +0 -12
- package/dist/geometries/cone-geometry.d.ts.map +0 -1
- package/dist/geometries/cone-geometry.js +0 -19
- package/dist/geometries/cone-geometry.js.map +0 -1
- package/dist/geometries/cube-geometry.d.ts +0 -14
- package/dist/geometries/cube-geometry.d.ts.map +0 -1
- package/dist/geometries/cube-geometry.js +0 -222
- package/dist/geometries/cube-geometry.js.map +0 -1
- package/dist/geometries/cylinder-geometry.d.ts +0 -11
- package/dist/geometries/cylinder-geometry.d.ts.map +0 -1
- package/dist/geometries/cylinder-geometry.js +0 -17
- package/dist/geometries/cylinder-geometry.js.map +0 -1
- package/dist/geometries/ico-sphere-geometry.d.ts +0 -11
- package/dist/geometries/ico-sphere-geometry.d.ts.map +0 -1
- package/dist/geometries/ico-sphere-geometry.js +0 -158
- package/dist/geometries/ico-sphere-geometry.js.map +0 -1
- package/dist/geometries/plane-geometry.d.ts +0 -20
- package/dist/geometries/plane-geometry.d.ts.map +0 -1
- package/dist/geometries/plane-geometry.js +0 -106
- package/dist/geometries/plane-geometry.js.map +0 -1
- package/dist/geometries/sphere-geometry.d.ts +0 -12
- package/dist/geometries/sphere-geometry.d.ts.map +0 -1
- package/dist/geometries/sphere-geometry.js +0 -88
- package/dist/geometries/sphere-geometry.js.map +0 -1
- package/dist/geometries/truncated-cone-geometry.d.ts +0 -23
- package/dist/geometries/truncated-cone-geometry.d.ts.map +0 -1
- package/dist/geometries/truncated-cone-geometry.js +0 -112
- package/dist/geometries/truncated-cone-geometry.js.map +0 -1
- package/src/compute/kernel.ts +0 -146
- package/src/compute/render-kernel.ts +0 -192
- package/src/geometries/cone-geometry.ts +0 -31
- package/src/geometries/cube-geometry.ts +0 -258
- package/src/geometries/cylinder-geometry.ts +0 -28
- package/src/geometries/ico-sphere-geometry.ts +0 -193
- package/src/geometries/plane-geometry.ts +0 -142
- package/src/geometries/sphere-geometry.ts +0 -113
- package/src/geometries/truncated-cone-geometry.ts +0 -145
|
@@ -0,0 +1,1375 @@
|
|
|
1
|
+
// luma.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
|
|
4
|
+
import { Buffer, ExternalTexture, Texture, TextureView, RenderPipeline, PipelineFactory, ShaderFactory, UniformStore, assert, log, dataTypeDecoder, getAttributeInfosFromLayouts, normalizeBindingsByGroup } from '@luma.gl/core';
|
|
5
|
+
import { mergeShaderPluginModules, resolveShaderPlugins, ShaderAssembler } from '@luma.gl/shadertools';
|
|
6
|
+
import { getDebugTableForShaderLayout } from "../debug/debug-shader-layout.js";
|
|
7
|
+
import { debugFramebuffer } from "../debug/debug-framebuffer.js";
|
|
8
|
+
import { deepEqual } from "../utils/deep-equal.js";
|
|
9
|
+
import { BufferLayoutHelper } from "../utils/buffer-layout-helper.js";
|
|
10
|
+
import { sortedBufferLayoutByShaderSourceLocations } from "../utils/buffer-layout-order.js";
|
|
11
|
+
import { getShaderModuleUniformBlockLayouts, mergeInferredShaderLayout, mergeShaderModules, mergeShaderModuleBindingsIntoLayout, shaderModuleHasUniforms } from "../utils/shader-module-utils.js";
|
|
12
|
+
import { getPlatformInfo } from "../utils/get-platform-info.js";
|
|
13
|
+
import { uid } from "../utils/uid.js";
|
|
14
|
+
import { getGPUVectorModelBatches, validateGPUVectorModelLayouts } from "./gpu-vector-model-batches.js";
|
|
15
|
+
export { getGPUVectorModelBatches } from "./gpu-vector-model-batches.js";
|
|
16
|
+
import { validateGPUVectorBatchStructure } from "../utils/gpu-vector-batch-structure.js";
|
|
17
|
+
import { drawGPUVectorGroups } from "./gpu-vector-draw-batches.js";
|
|
18
|
+
import { GPUVectorBindings } from "./gpu-vector-bindings.js";
|
|
19
|
+
import { ShaderInputs } from "../shader-inputs.js";
|
|
20
|
+
import { DynamicBuffer, isBufferRangeBinding, resolveBufferRangeBinding } from '@luma.gl/core/dynamic';
|
|
21
|
+
import { getTextureBindingLayout, isTextureBindingSource } from '@luma.gl/core/dynamic';
|
|
22
|
+
const LOG_DRAW_PRIORITY = 2;
|
|
23
|
+
const LOG_DRAW_TIMEOUT = 10000;
|
|
24
|
+
const PIPELINE_INITIALIZATION_FAILED = 'render pipeline initialization failed';
|
|
25
|
+
const DEPTH_STENCIL_ATTACHMENT_FORMATS = [
|
|
26
|
+
'stencil8',
|
|
27
|
+
'depth16unorm',
|
|
28
|
+
'depth24plus',
|
|
29
|
+
'depth24plus-stencil8',
|
|
30
|
+
'depth32float',
|
|
31
|
+
'depth32float-stencil8'
|
|
32
|
+
];
|
|
33
|
+
/**
|
|
34
|
+
* High level draw API for luma.gl.
|
|
35
|
+
*
|
|
36
|
+
* A `GPUVectorModel` encapsulates shaders, geometry attributes, bindings and render
|
|
37
|
+
* pipeline state into a single object. It automatically reuses and rebuilds
|
|
38
|
+
* pipelines as render parameters change and exposes convenient hooks for
|
|
39
|
+
* updating uniforms and attributes.
|
|
40
|
+
*
|
|
41
|
+
* Features:
|
|
42
|
+
* - Reuses and lazily recompiles {@link RenderPipeline | pipelines} as needed.
|
|
43
|
+
* - Integrates with `@luma.gl/shadertools` to assemble GLSL or WGSL from shader modules.
|
|
44
|
+
* - Manages geometry attributes and buffer bindings.
|
|
45
|
+
* - Accepts textures, samplers and uniform buffers as bindings, including texture binding sources.
|
|
46
|
+
* - Provides detailed debug logging and optional shader source inspection.
|
|
47
|
+
*/
|
|
48
|
+
export class GPUVectorModel {
|
|
49
|
+
/** Creates a model while allowing the backend to compile its render pipeline asynchronously. */
|
|
50
|
+
static async createAsync(device, props) {
|
|
51
|
+
const ownsCompilation = !PipelineFactory.getAsyncCompilation(device);
|
|
52
|
+
const asyncCompilation = ownsCompilation
|
|
53
|
+
? PipelineFactory.beginAsyncCompilation(device)
|
|
54
|
+
: PipelineFactory.getAsyncCompilation(device);
|
|
55
|
+
let model;
|
|
56
|
+
try {
|
|
57
|
+
model = new this(device, props);
|
|
58
|
+
}
|
|
59
|
+
finally {
|
|
60
|
+
if (ownsCompilation)
|
|
61
|
+
PipelineFactory.endAsyncCompilation(device, asyncCompilation);
|
|
62
|
+
}
|
|
63
|
+
try {
|
|
64
|
+
if (ownsCompilation) {
|
|
65
|
+
await Promise.all(asyncCompilation);
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
await model._pipelineInitialization;
|
|
69
|
+
}
|
|
70
|
+
return model;
|
|
71
|
+
}
|
|
72
|
+
catch (error) {
|
|
73
|
+
model.destroy();
|
|
74
|
+
throw error;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
static defaultProps = {
|
|
78
|
+
...RenderPipeline.defaultProps,
|
|
79
|
+
gpuVectorCount: 'instance',
|
|
80
|
+
geometry: null,
|
|
81
|
+
attributeVectors: undefined,
|
|
82
|
+
source: undefined,
|
|
83
|
+
sourceLanguage: undefined,
|
|
84
|
+
vs: null,
|
|
85
|
+
fs: null,
|
|
86
|
+
id: 'unnamed',
|
|
87
|
+
handle: undefined,
|
|
88
|
+
userData: {},
|
|
89
|
+
defines: {},
|
|
90
|
+
modules: [],
|
|
91
|
+
plugins: [],
|
|
92
|
+
indexBuffer: null,
|
|
93
|
+
indexCount: undefined,
|
|
94
|
+
firstVertex: 0,
|
|
95
|
+
firstIndex: 0,
|
|
96
|
+
attributes: {},
|
|
97
|
+
constantAttributes: {},
|
|
98
|
+
bindings: {},
|
|
99
|
+
uniforms: {},
|
|
100
|
+
varyings: [],
|
|
101
|
+
isInstanced: undefined,
|
|
102
|
+
instanceCount: 0,
|
|
103
|
+
vertexCount: 0,
|
|
104
|
+
shaderInputs: undefined,
|
|
105
|
+
pipelineFactory: undefined,
|
|
106
|
+
shaderFactory: undefined,
|
|
107
|
+
transformFeedback: undefined,
|
|
108
|
+
shaderAssembler: ShaderAssembler.getDefaultShaderAssembler('glsl'),
|
|
109
|
+
debugShaders: undefined,
|
|
110
|
+
disableWarnings: undefined
|
|
111
|
+
};
|
|
112
|
+
/** Device that created this model */
|
|
113
|
+
device;
|
|
114
|
+
/** Application provided identifier */
|
|
115
|
+
id;
|
|
116
|
+
/** WGSL shader source when using unified shader */
|
|
117
|
+
// @ts-expect-error assigned in function called from constructor
|
|
118
|
+
source;
|
|
119
|
+
/** GLSL vertex shader source */
|
|
120
|
+
// @ts-expect-error assigned in function called from constructor
|
|
121
|
+
vs;
|
|
122
|
+
/** GLSL fragment shader source */
|
|
123
|
+
// @ts-expect-error assigned in function called from constructor
|
|
124
|
+
fs;
|
|
125
|
+
/** Factory used to create render pipelines */
|
|
126
|
+
pipelineFactory;
|
|
127
|
+
/** Factory used to create shaders */
|
|
128
|
+
shaderFactory;
|
|
129
|
+
/** User-supplied per-model data */
|
|
130
|
+
userData = {};
|
|
131
|
+
// Fixed properties (change can trigger pipeline rebuild)
|
|
132
|
+
/** The render pipeline GPU parameters, depth testing etc */
|
|
133
|
+
parameters;
|
|
134
|
+
/** The primitive topology */
|
|
135
|
+
topology;
|
|
136
|
+
/** Buffer layout */
|
|
137
|
+
bufferLayout;
|
|
138
|
+
// Dynamic properties
|
|
139
|
+
/** Use instanced rendering */
|
|
140
|
+
isInstanced = undefined;
|
|
141
|
+
/** instance count. `undefined` means not instanced */
|
|
142
|
+
instanceCount = 0;
|
|
143
|
+
/** Vertex count */
|
|
144
|
+
vertexCount;
|
|
145
|
+
/** Indexed draw count override. Undefined uses vertexCount, then the full bound index buffer. */
|
|
146
|
+
indexCount;
|
|
147
|
+
/** First vertex byte offset for WebGL indexed draws or first vertex for non-indexed draws. */
|
|
148
|
+
firstVertex;
|
|
149
|
+
/** First index element for WebGPU indexed draws. */
|
|
150
|
+
firstIndex;
|
|
151
|
+
/** Index buffer */
|
|
152
|
+
indexBuffer = null;
|
|
153
|
+
/** Buffer-valued attributes */
|
|
154
|
+
bufferAttributes = {};
|
|
155
|
+
/** Constant-valued attributes */
|
|
156
|
+
constantAttributes = {};
|
|
157
|
+
/** Bindings (textures, samplers, uniform buffers) */
|
|
158
|
+
bindings = {};
|
|
159
|
+
/**
|
|
160
|
+
* VertexArray
|
|
161
|
+
* @note not implemented: if bufferLayout is updated, vertex array has to be rebuilt!
|
|
162
|
+
* @todo - allow application to define multiple vertex arrays?
|
|
163
|
+
* */
|
|
164
|
+
vertexArray;
|
|
165
|
+
/** TransformFeedback, WebGL 2 only. */
|
|
166
|
+
transformFeedback = null;
|
|
167
|
+
/** The underlying GPU "program". @note May be recreated if parameters change */
|
|
168
|
+
pipeline;
|
|
169
|
+
/** ShaderInputs instance */
|
|
170
|
+
// @ts-expect-error Assigned in function called by constructor
|
|
171
|
+
shaderInputs;
|
|
172
|
+
// @ts-expect-error Assigned in function called by constructor
|
|
173
|
+
_uniformStore;
|
|
174
|
+
_attributeInfos = {};
|
|
175
|
+
props;
|
|
176
|
+
geometryVectorBindings;
|
|
177
|
+
attributeVectorBindings;
|
|
178
|
+
explicitBufferLayout = [];
|
|
179
|
+
constructorDrawCounts;
|
|
180
|
+
constructorDrawOffsets;
|
|
181
|
+
drawingVectorBatches = false;
|
|
182
|
+
indexVector = null;
|
|
183
|
+
currentAttributes = {};
|
|
184
|
+
currentAttributeByteOffsets = {};
|
|
185
|
+
_dynamicIndexBufferSource = null;
|
|
186
|
+
_dynamicAttributeBufferSources = {};
|
|
187
|
+
_colorAttachmentFormats;
|
|
188
|
+
_depthStencilAttachmentFormat;
|
|
189
|
+
_pipelineNeedsUpdate = 'newly created';
|
|
190
|
+
_needsRedraw = 'initializing';
|
|
191
|
+
_drawBlockedReason = false;
|
|
192
|
+
_destroyed = false;
|
|
193
|
+
_vertexCountSet = false;
|
|
194
|
+
/** "Time" of last draw. Monotonically increasing timestamp */
|
|
195
|
+
_lastDrawTimestamp = -1;
|
|
196
|
+
_bindingTable = [];
|
|
197
|
+
_pipelineInitialization;
|
|
198
|
+
get [Symbol.toStringTag]() {
|
|
199
|
+
return 'Model';
|
|
200
|
+
}
|
|
201
|
+
toString() {
|
|
202
|
+
return `Model(${this.id})`;
|
|
203
|
+
}
|
|
204
|
+
constructor(device, props) {
|
|
205
|
+
this.constructorDrawOffsets = { firstVertex: props.firstVertex, firstIndex: props.firstIndex };
|
|
206
|
+
const defaultProps = this.constructor.defaultProps;
|
|
207
|
+
this.constructorDrawCounts = {
|
|
208
|
+
vertexCount: props.vertexCount ?? (defaultProps.vertexCount || undefined),
|
|
209
|
+
instanceCount: props.instanceCount ?? (defaultProps.instanceCount || undefined)
|
|
210
|
+
};
|
|
211
|
+
const defaultShaderAssembler = defaultProps.shaderAssembler;
|
|
212
|
+
const vertexCountSet = Object.hasOwn(props, 'vertexCount');
|
|
213
|
+
this.props = {
|
|
214
|
+
...defaultProps,
|
|
215
|
+
...props,
|
|
216
|
+
shaderAssembler: props.shaderAssembler ??
|
|
217
|
+
(isShaderAssemblerForLanguage(defaultShaderAssembler, device.info.shadingLanguage)
|
|
218
|
+
? defaultShaderAssembler
|
|
219
|
+
: ShaderAssembler.getDefaultShaderAssembler(device.info.shadingLanguage))
|
|
220
|
+
};
|
|
221
|
+
this._vertexCountSet = vertexCountSet;
|
|
222
|
+
props = this.props;
|
|
223
|
+
this.id = props.id || uid('model');
|
|
224
|
+
this.device = device;
|
|
225
|
+
Object.assign(this.userData, props.userData);
|
|
226
|
+
this.vertexCount = this.props.vertexCount;
|
|
227
|
+
this.indexCount = this.props.indexCount;
|
|
228
|
+
this.firstVertex = this.props.firstVertex;
|
|
229
|
+
this.firstIndex = this.props.firstIndex;
|
|
230
|
+
this.instanceCount = this.props.instanceCount;
|
|
231
|
+
this.topology = this.props.topology;
|
|
232
|
+
this.bufferLayout = this.props.bufferLayout;
|
|
233
|
+
this.parameters = this.props.parameters;
|
|
234
|
+
// Seed attachment formats before creating the initial WebGPU pipeline. This is required for
|
|
235
|
+
// depth-only models whose intentional empty color target list must not fall back to the canvas
|
|
236
|
+
// format before the first render pass can synchronize attachment state.
|
|
237
|
+
this._colorAttachmentFormats = this.props.colorAttachmentFormats;
|
|
238
|
+
this._depthStencilAttachmentFormat = this.props.depthStencilAttachmentFormat;
|
|
239
|
+
this.isInstanced = props.isInstanced ?? (props.instanceCount ? true : undefined);
|
|
240
|
+
this.explicitBufferLayout = this.bufferLayout;
|
|
241
|
+
this.geometryVectorBindings = new GPUVectorBindings(device, `${this.id}-geometry`);
|
|
242
|
+
this.attributeVectorBindings = new GPUVectorBindings(device, `${this.id}-attributes`);
|
|
243
|
+
this._initializeProps(props);
|
|
244
|
+
const platformInfo = getPlatformInfo(device);
|
|
245
|
+
const resolvedPlugins = resolveShaderPlugins(this.props.plugins, platformInfo.shaderLanguage);
|
|
246
|
+
// Setup shader module inputs
|
|
247
|
+
const shaderInputModules = mergeShaderPluginModules(this.props.modules, resolvedPlugins.modules);
|
|
248
|
+
const moduleMap = Object.fromEntries(shaderInputModules.map(module => [module.name, module]));
|
|
249
|
+
const shaderInputs = props.shaderInputs ||
|
|
250
|
+
new ShaderInputs(moduleMap, { disableWarnings: this.props.disableWarnings });
|
|
251
|
+
if (props.shaderInputs && resolvedPlugins.modules.length > 0) {
|
|
252
|
+
shaderInputs.addModules(resolvedPlugins.modules);
|
|
253
|
+
}
|
|
254
|
+
// @ts-ignore
|
|
255
|
+
this.setShaderInputs(shaderInputs);
|
|
256
|
+
// Setup shader assembler
|
|
257
|
+
const modules = mergeShaderModules(this.props.modules, shaderInputs.getModules());
|
|
258
|
+
const defines = { ...resolvedPlugins.defines, ...this.props.defines };
|
|
259
|
+
if (this.device.type === 'webgl') {
|
|
260
|
+
this.props._uniformBlockLayouts = getShaderModuleUniformBlockLayouts(modules);
|
|
261
|
+
}
|
|
262
|
+
this.props.shaderLayout =
|
|
263
|
+
mergeShaderModuleBindingsIntoLayout(this.props.shaderLayout, modules) || null;
|
|
264
|
+
const isWebGPU = this.device.type === 'webgpu';
|
|
265
|
+
// WebGPU
|
|
266
|
+
// TODO - hack to support unified WGSL shader
|
|
267
|
+
// TODO - this is wrong, compile a single shader
|
|
268
|
+
if (isWebGPU && this.props.source) {
|
|
269
|
+
// WGSL
|
|
270
|
+
const shaderAssembler = this.props.shaderAssembler;
|
|
271
|
+
// WGSL sources require an assembler with WGSL-specific hooks and binding state.
|
|
272
|
+
assert(isShaderAssemblerForLanguage(shaderAssembler, 'wgsl'));
|
|
273
|
+
const { source, getUniforms, bindingTable, entryPoints = {}, shaderLayout: assembledShaderLayout } = shaderAssembler.assembleWGSLShader({
|
|
274
|
+
platformInfo,
|
|
275
|
+
...this.props,
|
|
276
|
+
modules,
|
|
277
|
+
defines,
|
|
278
|
+
pluginInjections: resolvedPlugins.injections,
|
|
279
|
+
pluginVertexInputs: resolvedPlugins.vertexInputs,
|
|
280
|
+
pluginVaryings: resolvedPlugins.varyings
|
|
281
|
+
});
|
|
282
|
+
this.source = source;
|
|
283
|
+
this.props.vertexEntryPoint = entryPoints.vertex || this.props.vertexEntryPoint;
|
|
284
|
+
this.props.fragmentEntryPoint = entryPoints.fragment || this.props.fragmentEntryPoint;
|
|
285
|
+
// @ts-expect-error
|
|
286
|
+
this._getModuleUniforms = getUniforms;
|
|
287
|
+
this._bindingTable = bindingTable;
|
|
288
|
+
// Infer the layout after modules have been added so their bindings are included.
|
|
289
|
+
const scannedOrReflectedShaderLayout = assembledShaderLayout ??
|
|
290
|
+
device.getShaderLayout?.(this.source);
|
|
291
|
+
const inferredShaderLayout = normalizeShaderPluginAttributeNames(scannedOrReflectedShaderLayout, resolvedPlugins.vertexInputs);
|
|
292
|
+
const shaderLayout = mergeInferredShaderLayout(this.props.shaderLayout, inferredShaderLayout, Object.keys(resolvedPlugins.vertexInputs));
|
|
293
|
+
this.props.shaderLayout =
|
|
294
|
+
mergeShaderModuleBindingsIntoLayout(shaderLayout || null, modules) || null;
|
|
295
|
+
}
|
|
296
|
+
else {
|
|
297
|
+
// GLSL
|
|
298
|
+
const shaderAssembler = this.props.shaderAssembler;
|
|
299
|
+
// GLSL shader pairs require an assembler with GLSL-specific hooks.
|
|
300
|
+
assert(isShaderAssemblerForLanguage(shaderAssembler, 'glsl'));
|
|
301
|
+
const { vs, fs, getUniforms } = shaderAssembler.assembleGLSLShaderPair({
|
|
302
|
+
platformInfo,
|
|
303
|
+
...this.props,
|
|
304
|
+
modules,
|
|
305
|
+
defines,
|
|
306
|
+
pluginInjections: resolvedPlugins.injections,
|
|
307
|
+
pluginVertexInputs: resolvedPlugins.vertexInputs,
|
|
308
|
+
pluginVaryings: resolvedPlugins.varyings
|
|
309
|
+
});
|
|
310
|
+
this.vs = vs;
|
|
311
|
+
this.fs = fs;
|
|
312
|
+
// @ts-expect-error
|
|
313
|
+
this._getModuleUniforms = getUniforms;
|
|
314
|
+
this._bindingTable = [];
|
|
315
|
+
}
|
|
316
|
+
this.pipelineFactory =
|
|
317
|
+
props.pipelineFactory || PipelineFactory.getDefaultPipelineFactory(this.device);
|
|
318
|
+
this.shaderFactory = props.shaderFactory || ShaderFactory.getDefaultShaderFactory(this.device);
|
|
319
|
+
const asyncCompilation = PipelineFactory.getAsyncCompilation(this.device);
|
|
320
|
+
if (asyncCompilation) {
|
|
321
|
+
this._pipelineInitialization = this._initializePipelineAsync(props);
|
|
322
|
+
asyncCompilation.push(this._pipelineInitialization);
|
|
323
|
+
}
|
|
324
|
+
else {
|
|
325
|
+
this.pipeline = this._updatePipeline();
|
|
326
|
+
this._initializePipelineResources(props);
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
/** Initializes subclass input policies before shader and pipeline creation. */
|
|
330
|
+
_initializeProps(props) {
|
|
331
|
+
if (props.geometry)
|
|
332
|
+
this.setGeometry(props.geometry);
|
|
333
|
+
if (props.attributeVectors)
|
|
334
|
+
this.setAttributeVectors(props.attributeVectors);
|
|
335
|
+
}
|
|
336
|
+
/** Whether this model manages the uniform buffer for a shader-input module. */
|
|
337
|
+
_usesManagedUniformBuffer(moduleName) {
|
|
338
|
+
void moduleName;
|
|
339
|
+
return true;
|
|
340
|
+
}
|
|
341
|
+
async _initializePipelineAsync(props) {
|
|
342
|
+
await this._updatePipelineAsync();
|
|
343
|
+
this._initializePipelineResources(props);
|
|
344
|
+
}
|
|
345
|
+
/** Initializes subclass attributes before explicit constructor bindings are applied. */
|
|
346
|
+
_initializeAttributes() {
|
|
347
|
+
this.applyVectorAttributes();
|
|
348
|
+
if (this.indexVector)
|
|
349
|
+
this.bindIndexVector();
|
|
350
|
+
}
|
|
351
|
+
_initializePipelineResources(props) {
|
|
352
|
+
this.vertexArray = this.device.createVertexArray({
|
|
353
|
+
shaderLayout: this.pipeline.shaderLayout,
|
|
354
|
+
bufferLayout: this.pipeline.bufferLayout
|
|
355
|
+
});
|
|
356
|
+
this._initializeAttributes();
|
|
357
|
+
if (props.indexBuffer)
|
|
358
|
+
this.setIndexBuffer(props.indexBuffer);
|
|
359
|
+
if (props.indexCount !== undefined)
|
|
360
|
+
this.setIndexCount(props.indexCount);
|
|
361
|
+
if (this.constructorDrawOffsets.firstVertex !== undefined)
|
|
362
|
+
this.firstVertex = this.constructorDrawOffsets.firstVertex;
|
|
363
|
+
if (this.constructorDrawOffsets.firstIndex !== undefined)
|
|
364
|
+
this.firstIndex = this.constructorDrawOffsets.firstIndex;
|
|
365
|
+
if (props.isInstanced !== undefined)
|
|
366
|
+
this.isInstanced = props.isInstanced;
|
|
367
|
+
if (this.constructorDrawCounts.instanceCount !== undefined)
|
|
368
|
+
this.setInstanceCount(this.constructorDrawCounts.instanceCount);
|
|
369
|
+
if (this.constructorDrawCounts.vertexCount !== undefined)
|
|
370
|
+
this.setVertexCount(this.constructorDrawCounts.vertexCount);
|
|
371
|
+
if (props.attributes)
|
|
372
|
+
this.setAttributes(props.attributes);
|
|
373
|
+
if (props.constantAttributes)
|
|
374
|
+
this.setConstantAttributes(props.constantAttributes);
|
|
375
|
+
if (props.bindings)
|
|
376
|
+
this.setBindings(props.bindings);
|
|
377
|
+
if (props.transformFeedback)
|
|
378
|
+
this.transformFeedback = props.transformFeedback;
|
|
379
|
+
}
|
|
380
|
+
destroy() {
|
|
381
|
+
if (!this._destroyed) {
|
|
382
|
+
// Release pipeline before we destroy the shaders used by the pipeline
|
|
383
|
+
if (this.pipeline) {
|
|
384
|
+
this.pipelineFactory.release(this.pipeline);
|
|
385
|
+
// Release the shaders
|
|
386
|
+
this.shaderFactory.release(this.pipeline.vs);
|
|
387
|
+
if (this.pipeline.fs && this.pipeline.fs !== this.pipeline.vs) {
|
|
388
|
+
this.shaderFactory.release(this.pipeline.fs);
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
this.geometryVectorBindings.destroy();
|
|
392
|
+
this.attributeVectorBindings.destroy();
|
|
393
|
+
this._uniformStore.destroy();
|
|
394
|
+
this._destroyed = true;
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
// Draw call
|
|
398
|
+
/** Query redraw status. Clears the status. */
|
|
399
|
+
needsRedraw() {
|
|
400
|
+
// Catch any writes to already bound resources
|
|
401
|
+
if (this._getBindingsUpdateTimestamp() > this._lastDrawTimestamp) {
|
|
402
|
+
this.setNeedsRedraw('contents of bound textures or buffers updated');
|
|
403
|
+
}
|
|
404
|
+
const needsRedraw = this._needsRedraw;
|
|
405
|
+
this._needsRedraw = false;
|
|
406
|
+
return needsRedraw;
|
|
407
|
+
}
|
|
408
|
+
/** Mark the model as needing a redraw */
|
|
409
|
+
setNeedsRedraw(reason) {
|
|
410
|
+
this._needsRedraw ||= reason;
|
|
411
|
+
}
|
|
412
|
+
/** Returns WGSL binding debug rows for the assembled shader. Returns an empty array for GLSL models. */
|
|
413
|
+
getBindingDebugTable() {
|
|
414
|
+
return this._bindingTable;
|
|
415
|
+
}
|
|
416
|
+
/**
|
|
417
|
+
* Updates uniforms and pipeline state before opening a render pass.
|
|
418
|
+
*
|
|
419
|
+
* @param commandEncoder - Encoder that should own any GPU uploads emitted
|
|
420
|
+
* during draw preparation.
|
|
421
|
+
*/
|
|
422
|
+
predraw(commandEncoder) {
|
|
423
|
+
// Update uniform buffers if needed
|
|
424
|
+
this._syncDynamicBuffers();
|
|
425
|
+
this.updateShaderInputs(commandEncoder);
|
|
426
|
+
// Check if the pipeline is invalidated
|
|
427
|
+
this.pipeline = this._updatePipeline();
|
|
428
|
+
}
|
|
429
|
+
/**
|
|
430
|
+
* Issue one draw call.
|
|
431
|
+
* @param renderPass - render pass to draw into
|
|
432
|
+
* @returns `true` if the draw call was executed, `false` if resources were not ready.
|
|
433
|
+
*/
|
|
434
|
+
draw(renderPass) {
|
|
435
|
+
if (this.indexVector?.length === 0) {
|
|
436
|
+
this._lastDrawTimestamp = this.device.timestamp;
|
|
437
|
+
this._needsRedraw = false;
|
|
438
|
+
return true;
|
|
439
|
+
}
|
|
440
|
+
if (!this.drawingVectorBatches &&
|
|
441
|
+
(this.geometryVectorBindings.batchCount !== 1 ||
|
|
442
|
+
this.attributeVectorBindings.batchCount !== 1)) {
|
|
443
|
+
return this.drawVectorGroups(renderPass);
|
|
444
|
+
}
|
|
445
|
+
if (this._drawBlockedReason && !this._pipelineNeedsUpdate) {
|
|
446
|
+
log.info(LOG_DRAW_PRIORITY, `>>> DRAWING ABORTED ${this.id}: ${this._drawBlockedReason}`)();
|
|
447
|
+
return false;
|
|
448
|
+
}
|
|
449
|
+
const loadingBinding = this._areBindingsLoading();
|
|
450
|
+
if (loadingBinding) {
|
|
451
|
+
log.info(LOG_DRAW_PRIORITY, `>>> DRAWING ABORTED ${this.id}: ${loadingBinding} not loaded`)();
|
|
452
|
+
return false;
|
|
453
|
+
}
|
|
454
|
+
this._syncAttachmentFormats(renderPass);
|
|
455
|
+
try {
|
|
456
|
+
renderPass.pushDebugGroup(`${this}.predraw(${renderPass})`);
|
|
457
|
+
if (this.device.type === 'webgpu') {
|
|
458
|
+
// WebGPU uploads cannot be encoded once the render pass is already open.
|
|
459
|
+
// Keep the implicit draw() path working for existing callers by falling
|
|
460
|
+
// back to immediate writes here; callers that need upload ordering
|
|
461
|
+
// across multiple draws/viewports must call predraw(commandEncoder)
|
|
462
|
+
// before beginRenderPass().
|
|
463
|
+
this.updateShaderInputs();
|
|
464
|
+
this._syncDynamicBuffers();
|
|
465
|
+
this.pipeline = this._updatePipeline();
|
|
466
|
+
}
|
|
467
|
+
else {
|
|
468
|
+
this.predraw(this.device.commandEncoder);
|
|
469
|
+
}
|
|
470
|
+
}
|
|
471
|
+
finally {
|
|
472
|
+
renderPass.popDebugGroup();
|
|
473
|
+
}
|
|
474
|
+
let drawSuccess;
|
|
475
|
+
let pipelineErrored = this.pipeline.isErrored;
|
|
476
|
+
try {
|
|
477
|
+
renderPass.pushDebugGroup(`${this}.draw(${renderPass})`);
|
|
478
|
+
this._logDrawCallStart();
|
|
479
|
+
// Update the pipeline if invalidated
|
|
480
|
+
// TODO - inside RenderPass is likely the worst place to do this from performance perspective.
|
|
481
|
+
// Application can call GPUVectorModel.predraw() to avoid this.
|
|
482
|
+
this.pipeline = this._updatePipeline();
|
|
483
|
+
pipelineErrored = this.pipeline.isErrored;
|
|
484
|
+
if (pipelineErrored) {
|
|
485
|
+
log.info(LOG_DRAW_PRIORITY, `>>> DRAWING ABORTED ${this.id}: ${PIPELINE_INITIALIZATION_FAILED}`)();
|
|
486
|
+
drawSuccess = false;
|
|
487
|
+
}
|
|
488
|
+
else {
|
|
489
|
+
const drawValidationError = this.vertexArray.getDrawValidationError();
|
|
490
|
+
if (drawValidationError) {
|
|
491
|
+
log.info(LOG_DRAW_PRIORITY, `>>> DRAWING ABORTED ${this.id}: ${drawValidationError}`)();
|
|
492
|
+
this._drawBlockedReason = drawValidationError;
|
|
493
|
+
drawSuccess = false;
|
|
494
|
+
}
|
|
495
|
+
else {
|
|
496
|
+
const shaderLayout = this._getCurrentShaderLayout();
|
|
497
|
+
const syncBindings = this._getBindings(shaderLayout);
|
|
498
|
+
const syncBindGroups = this._getBindGroups(shaderLayout, syncBindings);
|
|
499
|
+
const { indexBuffer } = this.vertexArray;
|
|
500
|
+
const indexCount = indexBuffer
|
|
501
|
+
? (this.indexCount ??
|
|
502
|
+
(this._vertexCountSet
|
|
503
|
+
? this.vertexCount
|
|
504
|
+
: indexBuffer.byteLength / (indexBuffer.indexType === 'uint32' ? 4 : 2)))
|
|
505
|
+
: undefined;
|
|
506
|
+
renderPass.setPipeline(this.pipeline);
|
|
507
|
+
renderPass.setBindings(syncBindGroups, {
|
|
508
|
+
_bindGroupCacheKeys: this._getBindGroupCacheKeys()
|
|
509
|
+
});
|
|
510
|
+
renderPass.setVertexArray(this.vertexArray);
|
|
511
|
+
const hasNoInstances = this.isInstanced === true && this.instanceCount === 0;
|
|
512
|
+
drawSuccess = hasNoInstances
|
|
513
|
+
? true
|
|
514
|
+
: renderPass.draw({
|
|
515
|
+
isInstanced: this.isInstanced,
|
|
516
|
+
vertexCount: this.vertexCount,
|
|
517
|
+
instanceCount: this.isInstanced ? this.instanceCount : undefined,
|
|
518
|
+
indexCount,
|
|
519
|
+
firstVertex: this.firstVertex,
|
|
520
|
+
firstIndex: this.firstIndex,
|
|
521
|
+
transformFeedback: this.transformFeedback || undefined,
|
|
522
|
+
uniforms: this.props.uniforms,
|
|
523
|
+
// WebGL shares underlying cached programs even for models that have different
|
|
524
|
+
// parameters and topology, so those compatibility overrides remain per draw.
|
|
525
|
+
parameters: this.parameters,
|
|
526
|
+
topology: this.topology
|
|
527
|
+
});
|
|
528
|
+
}
|
|
529
|
+
}
|
|
530
|
+
}
|
|
531
|
+
finally {
|
|
532
|
+
renderPass.popDebugGroup();
|
|
533
|
+
this._logDrawCallEnd();
|
|
534
|
+
}
|
|
535
|
+
this._logFramebuffer(renderPass);
|
|
536
|
+
// Update needsRedraw flag
|
|
537
|
+
if (drawSuccess) {
|
|
538
|
+
this._lastDrawTimestamp = this.device.timestamp;
|
|
539
|
+
this._needsRedraw = false;
|
|
540
|
+
}
|
|
541
|
+
else if (pipelineErrored) {
|
|
542
|
+
this._needsRedraw = PIPELINE_INITIALIZATION_FAILED;
|
|
543
|
+
this._drawBlockedReason = PIPELINE_INITIALIZATION_FAILED;
|
|
544
|
+
}
|
|
545
|
+
else if (this._drawBlockedReason) {
|
|
546
|
+
this._needsRedraw = this._drawBlockedReason;
|
|
547
|
+
}
|
|
548
|
+
else {
|
|
549
|
+
this._needsRedraw = 'waiting for resource initialization';
|
|
550
|
+
}
|
|
551
|
+
return drawSuccess;
|
|
552
|
+
}
|
|
553
|
+
/** Binds a GPU-only mesh. CPU geometry adaptation belongs in Model. */
|
|
554
|
+
setGeometry(geometry) {
|
|
555
|
+
if (geometry)
|
|
556
|
+
this.setTopology(geometry.topology);
|
|
557
|
+
this.setGeometryVectors(geometry?.attributes ?? {}, geometry?.bufferLayout);
|
|
558
|
+
this.setIndexVector(geometry?.indices ?? null);
|
|
559
|
+
if (geometry?.vertexCount !== undefined)
|
|
560
|
+
this.setVertexCount(geometry.vertexCount);
|
|
561
|
+
}
|
|
562
|
+
/** Replaces per-vertex mesh vectors while preserving supplemental attributes. */
|
|
563
|
+
setGeometryVectors(vectors, bufferLayouts) {
|
|
564
|
+
bufferLayouts ??=
|
|
565
|
+
this.getExplicitVectorLayouts(vectors) ??
|
|
566
|
+
this.getExplicitVectorLayouts(vectors, this.geometryVectorBindings.sourceLayouts);
|
|
567
|
+
validateGPUVectorBatchStructure(vectors);
|
|
568
|
+
if (!this.isInstanced || this.attributeVectorBindings.vertexCount !== undefined)
|
|
569
|
+
validateGPUVectorBatchStructure([
|
|
570
|
+
...Object.values(vectors),
|
|
571
|
+
...Object.values(this.attributeVectorBindings.inputs)
|
|
572
|
+
]);
|
|
573
|
+
this.geometryVectorBindings.setInputs(vectors, bufferLayouts, 'vertex');
|
|
574
|
+
this.claimVectorLayouts(this.geometryVectorBindings);
|
|
575
|
+
this.syncVectorBindings();
|
|
576
|
+
const rowCount = this.geometryVectorBindings.rowCount;
|
|
577
|
+
assert(rowCount === undefined ||
|
|
578
|
+
this.attributeVectorBindings.vertexCount === undefined ||
|
|
579
|
+
rowCount === this.attributeVectorBindings.vertexCount);
|
|
580
|
+
this.setVertexCount(rowCount ?? this.attributeVectorBindings.vertexCount ?? 0);
|
|
581
|
+
}
|
|
582
|
+
/** Replaces supplemental vectors; instanced models default these inputs to instance step mode. */
|
|
583
|
+
setAttributeVectors(vectors, bufferLayouts) {
|
|
584
|
+
bufferLayouts ??=
|
|
585
|
+
this.getExplicitVectorLayouts(vectors) ??
|
|
586
|
+
this.getExplicitVectorLayouts(vectors, this.attributeVectorBindings.sourceLayouts);
|
|
587
|
+
if (this.isInstanced === undefined &&
|
|
588
|
+
(bufferLayouts?.some(layout => layout.stepMode === 'instance') ||
|
|
589
|
+
Object.values(vectors).some(vector => vector && 'data' in vector && vector.bufferLayout?.stepMode === 'instance')))
|
|
590
|
+
this.isInstanced = true;
|
|
591
|
+
const usesVertexRows = !this.isInstanced ||
|
|
592
|
+
Object.entries(vectors).some(([name, vector]) => vector &&
|
|
593
|
+
'data' in vector &&
|
|
594
|
+
(bufferLayouts?.find(layout => layout.name === name ||
|
|
595
|
+
layout.attributes?.some(attribute => attribute.attribute === name))?.stepMode ?? vector.bufferLayout?.stepMode) === 'vertex');
|
|
596
|
+
if (usesVertexRows)
|
|
597
|
+
validateGPUVectorBatchStructure([
|
|
598
|
+
...Object.values(this.geometryVectorBindings.inputs),
|
|
599
|
+
...Object.values(vectors)
|
|
600
|
+
]);
|
|
601
|
+
this.attributeVectorBindings.setInputs(vectors, bufferLayouts, this.isInstanced ? 'instance' : 'vertex');
|
|
602
|
+
this.claimVectorLayouts(this.attributeVectorBindings);
|
|
603
|
+
this.syncVectorBindings();
|
|
604
|
+
if (this.attributeVectorBindings.instanceCount !== undefined)
|
|
605
|
+
this.setInstanceCount(this.attributeVectorBindings.instanceCount);
|
|
606
|
+
const vertexCount = this.attributeVectorBindings.vertexCount;
|
|
607
|
+
if (vertexCount !== undefined) {
|
|
608
|
+
const geometryRowCount = this.geometryVectorBindings.rowCount;
|
|
609
|
+
// Supplemental vertex columns describe the same rows as the geometry columns.
|
|
610
|
+
assert(geometryRowCount === undefined || geometryRowCount === vertexCount);
|
|
611
|
+
if (geometryRowCount === undefined)
|
|
612
|
+
this.setVertexCount(vertexCount);
|
|
613
|
+
}
|
|
614
|
+
}
|
|
615
|
+
/** Binds typed columns using caller-resolved layouts, including packed groups. */
|
|
616
|
+
setGPUAttributes(vectors, bufferLayouts) {
|
|
617
|
+
this.setAttributeVectors(vectors, bufferLayouts);
|
|
618
|
+
}
|
|
619
|
+
/** Replaces the borrowed contiguous uint16/uint32 index vector. */
|
|
620
|
+
setIndexVector(vector) {
|
|
621
|
+
if (vector) {
|
|
622
|
+
// Indexed draws consume one contiguous, tightly packed index stream.
|
|
623
|
+
assert(vector.format === 'uint8' || vector.format === 'uint16' || vector.format === 'uint32');
|
|
624
|
+
assert(vector.data.length <= 1);
|
|
625
|
+
assert(vector.byteStride === (vector.format === 'uint32' ? 4 : vector.format === 'uint16' ? 2 : 1));
|
|
626
|
+
}
|
|
627
|
+
this.indexVector = vector;
|
|
628
|
+
if (this.vertexArray)
|
|
629
|
+
this.bindIndexVector();
|
|
630
|
+
}
|
|
631
|
+
bindIndexVector() {
|
|
632
|
+
const vector = this.indexVector;
|
|
633
|
+
const chunk = vector?.data[0];
|
|
634
|
+
if (chunk && this.indexVector) {
|
|
635
|
+
const buffer = chunk.buffer instanceof DynamicBuffer ? chunk.buffer.buffer : chunk.buffer;
|
|
636
|
+
// Core index-buffer metadata must agree with the vector format and aligned byte offset.
|
|
637
|
+
assert(buffer.indexType === this.indexVector.format &&
|
|
638
|
+
chunk.byteOffset % this.indexVector.byteStride === 0);
|
|
639
|
+
}
|
|
640
|
+
this.indexVector = null;
|
|
641
|
+
this.setIndexBuffer(chunk?.buffer ?? null);
|
|
642
|
+
this.indexVector = vector;
|
|
643
|
+
this.indexCount = vector?.length;
|
|
644
|
+
this.setDrawOffsets({
|
|
645
|
+
firstVertex: chunk?.byteOffset ?? 0,
|
|
646
|
+
firstIndex: chunk ? chunk.byteOffset / this.indexVector.byteStride : 0
|
|
647
|
+
});
|
|
648
|
+
}
|
|
649
|
+
claimVectorLayouts(group) {
|
|
650
|
+
this.explicitBufferLayout = this.explicitBufferLayout.filter(layout => !group.claimedNames.has(layout.name) &&
|
|
651
|
+
!layout.attributes?.some(attribute => group.claimedNames.has(attribute.attribute)));
|
|
652
|
+
}
|
|
653
|
+
getExplicitVectorLayouts(vectors, sourceLayouts = this.explicitBufferLayout) {
|
|
654
|
+
const names = new Set(Object.keys(vectors));
|
|
655
|
+
const layouts = sourceLayouts.filter(layout => names.has(layout.name) ||
|
|
656
|
+
layout.attributes?.some(attribute => names.has(attribute.attribute)));
|
|
657
|
+
return layouts.length ? layouts : undefined;
|
|
658
|
+
}
|
|
659
|
+
getVectorBufferLayout() {
|
|
660
|
+
const groups = [this.geometryVectorBindings, this.attributeVectorBindings];
|
|
661
|
+
const explicitLayouts = this.explicitBufferLayout.filter(layout => !groups.some(group => group.claimedNames.has(layout.name) ||
|
|
662
|
+
layout.attributes?.some(attribute => group.claimedNames.has(attribute.attribute))));
|
|
663
|
+
return [
|
|
664
|
+
...explicitLayouts,
|
|
665
|
+
...this.geometryVectorBindings.layouts,
|
|
666
|
+
...this.attributeVectorBindings.layouts
|
|
667
|
+
];
|
|
668
|
+
}
|
|
669
|
+
syncVectorBindings() {
|
|
670
|
+
const layouts = this.getVectorBufferLayout();
|
|
671
|
+
if (this.vertexArray) {
|
|
672
|
+
this.applyBufferLayout(layouts);
|
|
673
|
+
this.applyVectorAttributes();
|
|
674
|
+
}
|
|
675
|
+
else
|
|
676
|
+
this.bufferLayout = layouts;
|
|
677
|
+
}
|
|
678
|
+
applyVectorAttributes() {
|
|
679
|
+
const activeNames = new Set(this.bufferLayout.map(layout => layout.name));
|
|
680
|
+
for (const name of Object.keys(this.currentAttributes)) {
|
|
681
|
+
if (!activeNames.has(name))
|
|
682
|
+
delete this.currentAttributes[name];
|
|
683
|
+
}
|
|
684
|
+
this.setAttributes({
|
|
685
|
+
...this.currentAttributes,
|
|
686
|
+
...this.geometryVectorBindings.buffers,
|
|
687
|
+
...this.attributeVectorBindings.buffers
|
|
688
|
+
}, {
|
|
689
|
+
byteOffsets: {
|
|
690
|
+
...this.currentAttributeByteOffsets,
|
|
691
|
+
...this.geometryVectorBindings.byteOffsets,
|
|
692
|
+
...this.attributeVectorBindings.byteOffsets
|
|
693
|
+
},
|
|
694
|
+
disableWarnings: true
|
|
695
|
+
});
|
|
696
|
+
if (this.device.type === 'webgl')
|
|
697
|
+
this.setConstantAttributes({
|
|
698
|
+
...this.geometryVectorBindings.constants,
|
|
699
|
+
...this.attributeVectorBindings.constants
|
|
700
|
+
});
|
|
701
|
+
}
|
|
702
|
+
/** Binds contiguous borrowed vectors; use drawBatches() for multi-chunk inputs. */
|
|
703
|
+
setGPUVectors(vectors, options) {
|
|
704
|
+
const batches = getGPUVectorModelBatches(this.id, vectors);
|
|
705
|
+
// Direct binding requires one physical chunk per vector; never concatenate implicitly.
|
|
706
|
+
assert(batches.length <= 1);
|
|
707
|
+
validateGPUVectorModelLayouts(this.id, vectors, this.bufferLayout);
|
|
708
|
+
if (batches[0])
|
|
709
|
+
this.setGPUData(batches[0].data);
|
|
710
|
+
this.setBatchDrawCount(batches[0]?.rowCount ?? 0, options?.count);
|
|
711
|
+
}
|
|
712
|
+
drawVectorGroups(renderPass) {
|
|
713
|
+
const drawingVectorBatches = this.drawingVectorBatches;
|
|
714
|
+
const vertexCountSet = this._vertexCountSet;
|
|
715
|
+
this.drawingVectorBatches = true;
|
|
716
|
+
try {
|
|
717
|
+
const success = drawGPUVectorGroups(this, this.geometryVectorBindings, this.attributeVectorBindings, () => this.syncVectorBindings(), () => GPUVectorModel.prototype.draw.call(this, renderPass));
|
|
718
|
+
if (success) {
|
|
719
|
+
this._lastDrawTimestamp = this.device.timestamp;
|
|
720
|
+
this._needsRedraw = false;
|
|
721
|
+
}
|
|
722
|
+
return success;
|
|
723
|
+
}
|
|
724
|
+
finally {
|
|
725
|
+
this._vertexCountSet = vertexCountSet;
|
|
726
|
+
this.drawingVectorBatches = drawingVectorBatches;
|
|
727
|
+
}
|
|
728
|
+
}
|
|
729
|
+
/** Draws each aligned physical chunk without retaining or taking ownership of input vectors. */
|
|
730
|
+
drawBatches(renderPass, { vectors, onBatch }) {
|
|
731
|
+
const batches = getGPUVectorModelBatches(this.id, vectors);
|
|
732
|
+
validateGPUVectorModelLayouts(this.id, vectors, this.bufferLayout);
|
|
733
|
+
for (const name of Object.keys(vectors)) {
|
|
734
|
+
// Transient batches replace existing attributes so every binding can be restored afterward.
|
|
735
|
+
assert(!vectors[name] || this.currentAttributes[name]);
|
|
736
|
+
}
|
|
737
|
+
const previousAttributes = { ...this.currentAttributes };
|
|
738
|
+
const previousAttributeByteOffsets = { ...this.currentAttributeByteOffsets };
|
|
739
|
+
const previousBindings = { ...this.bindings };
|
|
740
|
+
const previousInstanceCount = this.instanceCount;
|
|
741
|
+
const previousVertexCount = this.vertexCount;
|
|
742
|
+
const previousIsInstanced = this.isInstanced;
|
|
743
|
+
const previousVertexCountSet = this._vertexCountSet;
|
|
744
|
+
const drawingVectorBatches = this.drawingVectorBatches;
|
|
745
|
+
this.drawingVectorBatches = true;
|
|
746
|
+
let drawSuccess = true;
|
|
747
|
+
try {
|
|
748
|
+
for (const batch of batches) {
|
|
749
|
+
this.setGPUData(batch.data);
|
|
750
|
+
this.setBatchDrawCount(batch.rowCount);
|
|
751
|
+
onBatch?.(batch);
|
|
752
|
+
drawSuccess = GPUVectorModel.prototype.draw.call(this, renderPass) && drawSuccess;
|
|
753
|
+
}
|
|
754
|
+
}
|
|
755
|
+
finally {
|
|
756
|
+
this.setAttributes(previousAttributes, { byteOffsets: previousAttributeByteOffsets });
|
|
757
|
+
for (const name of Object.keys(this.bindings)) {
|
|
758
|
+
if (!(name in previousBindings))
|
|
759
|
+
delete this.bindings[name];
|
|
760
|
+
}
|
|
761
|
+
this.setBindings(previousBindings);
|
|
762
|
+
this.setInstanceCount(previousInstanceCount);
|
|
763
|
+
this.setVertexCount(previousVertexCount);
|
|
764
|
+
this.isInstanced = previousIsInstanced;
|
|
765
|
+
this._vertexCountSet = previousVertexCountSet;
|
|
766
|
+
this.drawingVectorBatches = drawingVectorBatches;
|
|
767
|
+
}
|
|
768
|
+
return drawSuccess;
|
|
769
|
+
}
|
|
770
|
+
setGPUData(data) {
|
|
771
|
+
this.setAttributes(Object.fromEntries(Object.entries(data).map(([name, chunk]) => [name, chunk.buffer])), {
|
|
772
|
+
byteOffsets: Object.fromEntries(Object.entries(data).map(([name, chunk]) => {
|
|
773
|
+
const layout = this.bufferLayout.find(layout => layout.name === name);
|
|
774
|
+
const byteOffset = chunk.byteOffset - (layout?.attributes?.[0]?.byteOffset ?? 0);
|
|
775
|
+
// The layout offset and binding offset together address the start of the chunk.
|
|
776
|
+
assert(byteOffset >= 0);
|
|
777
|
+
return [name, byteOffset];
|
|
778
|
+
}))
|
|
779
|
+
});
|
|
780
|
+
}
|
|
781
|
+
setBatchDrawCount(rowCount, count = this.props.gpuVectorCount) {
|
|
782
|
+
if (count === 'instance') {
|
|
783
|
+
this.setInstanceCount(rowCount);
|
|
784
|
+
}
|
|
785
|
+
else if (count === 'vertex') {
|
|
786
|
+
this.setVertexCount(rowCount);
|
|
787
|
+
}
|
|
788
|
+
}
|
|
789
|
+
// Update fixed fields (can trigger pipeline rebuild)
|
|
790
|
+
/**
|
|
791
|
+
* Updates the primitive topology ('triangle-list', 'triangle-strip' etc).
|
|
792
|
+
* @note Triggers a pipeline rebuild / pipeline cache fetch on WebGPU
|
|
793
|
+
*/
|
|
794
|
+
setTopology(topology) {
|
|
795
|
+
if (topology !== this.topology) {
|
|
796
|
+
this.topology = topology;
|
|
797
|
+
this._setPipelineNeedsUpdate('topology');
|
|
798
|
+
}
|
|
799
|
+
}
|
|
800
|
+
/**
|
|
801
|
+
* Updates the buffer layout.
|
|
802
|
+
* @note Triggers a pipeline rebuild / pipeline cache fetch
|
|
803
|
+
*/
|
|
804
|
+
setBufferLayout(bufferLayout) {
|
|
805
|
+
this.explicitBufferLayout = bufferLayout;
|
|
806
|
+
const geometry = this.geometryVectorBindings;
|
|
807
|
+
const attributes = this.attributeVectorBindings;
|
|
808
|
+
const geometryLayouts = this.getExplicitVectorLayouts(geometry.inputs) ?? geometry.sourceLayouts;
|
|
809
|
+
const attributeLayouts = this.getExplicitVectorLayouts(attributes.inputs) ?? attributes.sourceLayouts;
|
|
810
|
+
geometry.setInputs(geometry.inputs, geometryLayouts, 'vertex');
|
|
811
|
+
attributes.setInputs(attributes.inputs, attributeLayouts, this.isInstanced ? 'instance' : 'vertex');
|
|
812
|
+
if (!this.isInstanced || attributes.vertexCount !== undefined)
|
|
813
|
+
validateGPUVectorBatchStructure([
|
|
814
|
+
...Object.values(geometry.inputs),
|
|
815
|
+
...Object.values(attributes.inputs)
|
|
816
|
+
]);
|
|
817
|
+
this.claimVectorLayouts(geometry);
|
|
818
|
+
this.claimVectorLayouts(attributes);
|
|
819
|
+
this.applyBufferLayout(this.getVectorBufferLayout());
|
|
820
|
+
}
|
|
821
|
+
applyBufferLayout(nextBufferLayout) {
|
|
822
|
+
nextBufferLayout = sortedBufferLayoutByShaderSourceLocations(this.pipeline.shaderLayout, nextBufferLayout);
|
|
823
|
+
if (deepEqual(nextBufferLayout, this.bufferLayout, -1)) {
|
|
824
|
+
return;
|
|
825
|
+
}
|
|
826
|
+
this.bufferLayout = nextBufferLayout;
|
|
827
|
+
this._setPipelineNeedsUpdate('bufferLayout');
|
|
828
|
+
// Recreate the pipeline
|
|
829
|
+
this.pipeline = this._updatePipeline();
|
|
830
|
+
// vertex array needs to be updated if we update buffer layout,
|
|
831
|
+
// but not if we update parameters
|
|
832
|
+
this.vertexArray = this.device.createVertexArray({
|
|
833
|
+
shaderLayout: this.pipeline.shaderLayout,
|
|
834
|
+
bufferLayout: this.pipeline.bufferLayout
|
|
835
|
+
});
|
|
836
|
+
this._dynamicAttributeBufferSources = {};
|
|
837
|
+
this.applyVectorAttributes();
|
|
838
|
+
if (this.indexBuffer)
|
|
839
|
+
this.vertexArray.setIndexBuffer(this.indexBuffer);
|
|
840
|
+
}
|
|
841
|
+
/**
|
|
842
|
+
* Set GPU parameters.
|
|
843
|
+
* @note Can trigger a pipeline rebuild / pipeline cache fetch on WebGPU.
|
|
844
|
+
* On WebGL, parameters are applied at each draw call, so the pipeline is kept.
|
|
845
|
+
* @param parameters
|
|
846
|
+
*/
|
|
847
|
+
setParameters(parameters) {
|
|
848
|
+
if (!deepEqual(parameters, this.parameters, 2)) {
|
|
849
|
+
this.parameters = parameters;
|
|
850
|
+
if (this.device.type === 'webgl') {
|
|
851
|
+
this.setNeedsRedraw('parameters');
|
|
852
|
+
}
|
|
853
|
+
else {
|
|
854
|
+
this._setPipelineNeedsUpdate('parameters');
|
|
855
|
+
}
|
|
856
|
+
}
|
|
857
|
+
}
|
|
858
|
+
// Update dynamic fields
|
|
859
|
+
/**
|
|
860
|
+
* Updates the instance count (used in draw calls)
|
|
861
|
+
* @note Any attributes with stepMode=instance need to be at least this big
|
|
862
|
+
*/
|
|
863
|
+
setInstanceCount(instanceCount) {
|
|
864
|
+
this.instanceCount = instanceCount;
|
|
865
|
+
// luma.gl examples don't set props.isInstanced and rely on auto-detection
|
|
866
|
+
// but deck.gl sets instanceCount even for models that are not instanced.
|
|
867
|
+
if (this.isInstanced === undefined && instanceCount > 0) {
|
|
868
|
+
this.isInstanced = true;
|
|
869
|
+
}
|
|
870
|
+
this.setNeedsRedraw('instanceCount');
|
|
871
|
+
}
|
|
872
|
+
/**
|
|
873
|
+
* Updates the vertex count (used in draw calls)
|
|
874
|
+
* @note Any attributes with stepMode=vertex need to be at least this big
|
|
875
|
+
*/
|
|
876
|
+
setVertexCount(vertexCount) {
|
|
877
|
+
this.vertexCount = vertexCount;
|
|
878
|
+
this._vertexCountSet = true;
|
|
879
|
+
this.setNeedsRedraw('vertexCount');
|
|
880
|
+
}
|
|
881
|
+
/** Updates the indexed draw count override. */
|
|
882
|
+
setIndexCount(indexCount) {
|
|
883
|
+
this.indexCount = indexCount;
|
|
884
|
+
this.setNeedsRedraw('indexCount');
|
|
885
|
+
}
|
|
886
|
+
/** Updates the first indexed/non-indexed draw offsets. */
|
|
887
|
+
setDrawOffsets({ firstVertex, firstIndex }) {
|
|
888
|
+
this.firstVertex = firstVertex;
|
|
889
|
+
this.firstIndex = firstIndex;
|
|
890
|
+
this.setNeedsRedraw('drawOffsets');
|
|
891
|
+
}
|
|
892
|
+
/** Set the shader inputs */
|
|
893
|
+
setShaderInputs(shaderInputs) {
|
|
894
|
+
this.shaderInputs = shaderInputs;
|
|
895
|
+
this._uniformStore = new UniformStore(this.device, this.shaderInputs.modules);
|
|
896
|
+
// Create uniform buffer bindings for all modules that actually have uniforms
|
|
897
|
+
for (const [moduleName, module] of Object.entries(this.shaderInputs.modules)) {
|
|
898
|
+
if (shaderModuleHasUniforms(module) && this._usesManagedUniformBuffer(moduleName)) {
|
|
899
|
+
const uniformBuffer = this._uniformStore.getManagedUniformBuffer(moduleName);
|
|
900
|
+
this.bindings[`${moduleName}Uniforms`] = uniformBuffer;
|
|
901
|
+
}
|
|
902
|
+
}
|
|
903
|
+
this.setNeedsRedraw('shaderInputs');
|
|
904
|
+
}
|
|
905
|
+
/** Update uniform buffers from the model's shader inputs */
|
|
906
|
+
/**
|
|
907
|
+
* Flushes current shader-input values into managed uniform buffers and
|
|
908
|
+
* resource bindings.
|
|
909
|
+
*
|
|
910
|
+
* @param commandEncoder - Optional encoder used to order uniform uploads with
|
|
911
|
+
* subsequent draw commands.
|
|
912
|
+
*/
|
|
913
|
+
updateShaderInputs(commandEncoder) {
|
|
914
|
+
this._uniformStore.setUniforms(this.shaderInputs.getUniformValues(), commandEncoder);
|
|
915
|
+
this.setBindings(this._getShaderInputBindings());
|
|
916
|
+
// TODO - this is already tracked through buffer/texture update times?
|
|
917
|
+
this.setNeedsRedraw('shaderInputs');
|
|
918
|
+
}
|
|
919
|
+
/** Resolves resource bindings supplied by shader inputs. */
|
|
920
|
+
_getShaderInputBindings() {
|
|
921
|
+
return this.shaderInputs.getBindingValues();
|
|
922
|
+
}
|
|
923
|
+
/**
|
|
924
|
+
* Sets bindings (textures, samplers, uniform buffers)
|
|
925
|
+
*/
|
|
926
|
+
setBindings(bindings) {
|
|
927
|
+
Object.assign(this.bindings, bindings);
|
|
928
|
+
this.setNeedsRedraw('bindings');
|
|
929
|
+
}
|
|
930
|
+
/**
|
|
931
|
+
* Updates optional transform feedback. WebGL only.
|
|
932
|
+
*/
|
|
933
|
+
setTransformFeedback(transformFeedback) {
|
|
934
|
+
this.transformFeedback = transformFeedback;
|
|
935
|
+
this.setNeedsRedraw('transformFeedback');
|
|
936
|
+
}
|
|
937
|
+
/**
|
|
938
|
+
* Sets the index buffer
|
|
939
|
+
* @todo - how to unset it if we change geometry?
|
|
940
|
+
*/
|
|
941
|
+
setIndexBuffer(indexBuffer) {
|
|
942
|
+
if (this.indexVector) {
|
|
943
|
+
this.indexCount = undefined;
|
|
944
|
+
this.firstVertex = 0;
|
|
945
|
+
this.firstIndex = 0;
|
|
946
|
+
}
|
|
947
|
+
this.indexVector = null;
|
|
948
|
+
const resolvedIndexBuffer = indexBuffer instanceof DynamicBuffer ? indexBuffer.buffer : indexBuffer;
|
|
949
|
+
this.indexBuffer = resolvedIndexBuffer;
|
|
950
|
+
this._dynamicIndexBufferSource =
|
|
951
|
+
indexBuffer instanceof DynamicBuffer
|
|
952
|
+
? { source: indexBuffer, generation: indexBuffer.generation }
|
|
953
|
+
: null;
|
|
954
|
+
this.vertexArray.setIndexBuffer(resolvedIndexBuffer);
|
|
955
|
+
this.setNeedsRedraw('indexBuffer');
|
|
956
|
+
}
|
|
957
|
+
/**
|
|
958
|
+
* Sets attributes (buffers)
|
|
959
|
+
* @param options.byteOffsets Optional byte offsets, keyed by buffer name, where each buffer's
|
|
960
|
+
* vertex data starts. Buffers without an entry are bound at offset 0.
|
|
961
|
+
* @note Overrides any attributes previously set with the same name
|
|
962
|
+
*/
|
|
963
|
+
setAttributes(buffers, options) {
|
|
964
|
+
Object.assign(this.currentAttributes, buffers);
|
|
965
|
+
for (const name of Object.keys(buffers)) {
|
|
966
|
+
this.currentAttributeByteOffsets[name] = options?.byteOffsets?.[name] ?? 0;
|
|
967
|
+
}
|
|
968
|
+
this._drawBlockedReason = false;
|
|
969
|
+
const disableWarnings = options?.disableWarnings ?? this.props.disableWarnings;
|
|
970
|
+
if (buffers['indices']) {
|
|
971
|
+
log.warn(`Model:${this.id} setAttributes() - indexBuffer should be set using setIndexBuffer()`)();
|
|
972
|
+
}
|
|
973
|
+
// ensure bufferLayout order matches source layout so we bind
|
|
974
|
+
// the correct buffers to the correct indices in webgpu.
|
|
975
|
+
this.bufferLayout = sortedBufferLayoutByShaderSourceLocations(this.pipeline.shaderLayout, this.bufferLayout);
|
|
976
|
+
const bufferLayoutHelper = new BufferLayoutHelper(this.bufferLayout);
|
|
977
|
+
// Check if all buffers have a layout
|
|
978
|
+
for (const [bufferName, buffer] of Object.entries(buffers)) {
|
|
979
|
+
const resolvedBuffer = buffer instanceof DynamicBuffer ? buffer.buffer : buffer;
|
|
980
|
+
const bufferLayout = bufferLayoutHelper.getBufferLayout(bufferName);
|
|
981
|
+
if (!bufferLayout) {
|
|
982
|
+
if (!disableWarnings) {
|
|
983
|
+
log.warn(`Model(${this.id}): Missing layout for buffer "${bufferName}".`)();
|
|
984
|
+
}
|
|
985
|
+
continue; // eslint-disable-line no-continue
|
|
986
|
+
}
|
|
987
|
+
// In WebGL, for an interleaved attribute we may need to set multiple attributes
|
|
988
|
+
// but in WebGPU, we set it according to the buffer's position in the vertexArray
|
|
989
|
+
const attributeNames = bufferLayoutHelper.getAttributeNamesForBuffer(bufferLayout);
|
|
990
|
+
let set = false;
|
|
991
|
+
for (const attributeName of attributeNames) {
|
|
992
|
+
const attributeInfo = this._attributeInfos[attributeName];
|
|
993
|
+
if (attributeInfo) {
|
|
994
|
+
const bufferSlot = this.device.type === 'webgpu'
|
|
995
|
+
? this.vertexArray.getBufferSlot(attributeInfo.bufferName)
|
|
996
|
+
: attributeInfo.location;
|
|
997
|
+
if (bufferSlot === null) {
|
|
998
|
+
if (!disableWarnings) {
|
|
999
|
+
log.warn(`Model(${this.id}): Missing vertex array slot for buffer "${attributeInfo.bufferName}".`)();
|
|
1000
|
+
}
|
|
1001
|
+
continue; // eslint-disable-line no-continue
|
|
1002
|
+
}
|
|
1003
|
+
const byteOffset = options?.byteOffsets?.[bufferName] ?? 0;
|
|
1004
|
+
this.vertexArray.setBuffer(bufferSlot, resolvedBuffer, byteOffset);
|
|
1005
|
+
if (buffer instanceof DynamicBuffer) {
|
|
1006
|
+
this._dynamicAttributeBufferSources[bufferSlot] = {
|
|
1007
|
+
source: buffer,
|
|
1008
|
+
generation: buffer.generation,
|
|
1009
|
+
byteOffset
|
|
1010
|
+
};
|
|
1011
|
+
}
|
|
1012
|
+
else {
|
|
1013
|
+
delete this._dynamicAttributeBufferSources[bufferSlot];
|
|
1014
|
+
}
|
|
1015
|
+
set = true;
|
|
1016
|
+
}
|
|
1017
|
+
}
|
|
1018
|
+
if (!set && !disableWarnings) {
|
|
1019
|
+
log.warn(`Model(${this.id}): Ignoring buffer "${resolvedBuffer.id}" for unknown attribute "${bufferName}"`)();
|
|
1020
|
+
}
|
|
1021
|
+
}
|
|
1022
|
+
this.setNeedsRedraw('attributes');
|
|
1023
|
+
}
|
|
1024
|
+
/**
|
|
1025
|
+
* Sets constant attributes
|
|
1026
|
+
* @note Overrides any attributes previously set with the same name
|
|
1027
|
+
* Constant attributes are only supported in WebGL, not in WebGPU
|
|
1028
|
+
* Any attribute that is disabled in the current vertex array object
|
|
1029
|
+
* is read from the context's global constant value for that attribute location.
|
|
1030
|
+
* @param constantAttributes
|
|
1031
|
+
*/
|
|
1032
|
+
setConstantAttributes(attributes, options) {
|
|
1033
|
+
for (const [attributeName, value] of Object.entries(attributes)) {
|
|
1034
|
+
const attributeInfo = this._attributeInfos[attributeName];
|
|
1035
|
+
if (attributeInfo) {
|
|
1036
|
+
this.vertexArray.setConstantWebGL(attributeInfo.location, value);
|
|
1037
|
+
}
|
|
1038
|
+
else if (!(options?.disableWarnings ?? this.props.disableWarnings)) {
|
|
1039
|
+
log.warn(`Model "${this.id}: Ignoring constant supplied for unknown attribute "${attributeName}"`)();
|
|
1040
|
+
}
|
|
1041
|
+
}
|
|
1042
|
+
this.setNeedsRedraw('constants');
|
|
1043
|
+
}
|
|
1044
|
+
// INTERNAL METHODS
|
|
1045
|
+
/** Check that bindings are loaded. Returns id of first binding that is still loading. */
|
|
1046
|
+
_areBindingsLoading() {
|
|
1047
|
+
for (const binding of Object.values(this.bindings)) {
|
|
1048
|
+
if (isTextureBindingSource(binding) && !binding.isReady) {
|
|
1049
|
+
return binding.id;
|
|
1050
|
+
}
|
|
1051
|
+
}
|
|
1052
|
+
return false;
|
|
1053
|
+
}
|
|
1054
|
+
/**
|
|
1055
|
+
* Resolves ready model bindings for the current shader layout.
|
|
1056
|
+
* @param shaderLayout Reflected bindings used to select copied or external texture resolution.
|
|
1057
|
+
*/
|
|
1058
|
+
_getBindings(shaderLayout = this._getCurrentShaderLayout()) {
|
|
1059
|
+
const validBindings = {};
|
|
1060
|
+
for (const [name, binding] of Object.entries(this.bindings)) {
|
|
1061
|
+
const resolvedBinding = resolveModelBinding(name, binding, shaderLayout);
|
|
1062
|
+
if (resolvedBinding) {
|
|
1063
|
+
validBindings[name] = resolvedBinding;
|
|
1064
|
+
}
|
|
1065
|
+
}
|
|
1066
|
+
return validBindings;
|
|
1067
|
+
}
|
|
1068
|
+
/**
|
|
1069
|
+
* Groups resolved resource bindings for the current shader layout.
|
|
1070
|
+
* @param shaderLayout Reflected bindings used to group logical binding names.
|
|
1071
|
+
* @param bindings GPUVectorModel bindings already resolved for this draw preparation.
|
|
1072
|
+
*/
|
|
1073
|
+
_getBindGroups(shaderLayout = this._getCurrentShaderLayout(), bindings = this._getBindings(shaderLayout)) {
|
|
1074
|
+
return shaderLayout.bindings.length
|
|
1075
|
+
? normalizeBindingsByGroup(shaderLayout, bindings)
|
|
1076
|
+
: { 0: bindings };
|
|
1077
|
+
}
|
|
1078
|
+
_getBindGroupCacheKeys() {
|
|
1079
|
+
return {};
|
|
1080
|
+
}
|
|
1081
|
+
/** Get the timestamp of the latest updated bound GPU memory resource (buffer/texture). */
|
|
1082
|
+
_getBindingsUpdateTimestamp() {
|
|
1083
|
+
let timestamp = 0;
|
|
1084
|
+
if (this._dynamicIndexBufferSource) {
|
|
1085
|
+
timestamp = Math.max(timestamp, this._dynamicIndexBufferSource.source.updateTimestamp);
|
|
1086
|
+
}
|
|
1087
|
+
for (const entry of Object.values(this._dynamicAttributeBufferSources)) {
|
|
1088
|
+
timestamp = Math.max(timestamp, entry.source.updateTimestamp);
|
|
1089
|
+
}
|
|
1090
|
+
for (const binding of Object.values(this.bindings)) {
|
|
1091
|
+
if (binding instanceof TextureView) {
|
|
1092
|
+
timestamp = Math.max(timestamp, binding.texture.updateTimestamp);
|
|
1093
|
+
}
|
|
1094
|
+
else if (binding instanceof Buffer ||
|
|
1095
|
+
binding instanceof Texture ||
|
|
1096
|
+
binding instanceof ExternalTexture) {
|
|
1097
|
+
timestamp = Math.max(timestamp, binding.updateTimestamp);
|
|
1098
|
+
}
|
|
1099
|
+
else if (binding instanceof DynamicBuffer) {
|
|
1100
|
+
timestamp = Math.max(timestamp, binding.updateTimestamp);
|
|
1101
|
+
}
|
|
1102
|
+
else if (isTextureBindingSource(binding)) {
|
|
1103
|
+
timestamp = binding.isReady
|
|
1104
|
+
? Math.max(timestamp, binding.updateTimestamp)
|
|
1105
|
+
: // The texture will become available in the future
|
|
1106
|
+
Infinity;
|
|
1107
|
+
}
|
|
1108
|
+
else if (isBufferRangeBinding(binding)) {
|
|
1109
|
+
timestamp = Math.max(timestamp, binding.buffer instanceof DynamicBuffer
|
|
1110
|
+
? binding.buffer.updateTimestamp
|
|
1111
|
+
: binding.buffer.updateTimestamp);
|
|
1112
|
+
}
|
|
1113
|
+
}
|
|
1114
|
+
return timestamp;
|
|
1115
|
+
}
|
|
1116
|
+
/** Mark pipeline as needing update */
|
|
1117
|
+
_setPipelineNeedsUpdate(reason) {
|
|
1118
|
+
this._pipelineNeedsUpdate ||= reason;
|
|
1119
|
+
this._drawBlockedReason = false;
|
|
1120
|
+
this.setNeedsRedraw(reason);
|
|
1121
|
+
}
|
|
1122
|
+
/** Update pipeline if needed */
|
|
1123
|
+
_updatePipeline() {
|
|
1124
|
+
const update = this._preparePipelineUpdate();
|
|
1125
|
+
if (update) {
|
|
1126
|
+
this.pipeline = this.pipelineFactory.createRenderPipeline(update.props);
|
|
1127
|
+
this._finishPipelineUpdate(update);
|
|
1128
|
+
}
|
|
1129
|
+
return this.pipeline;
|
|
1130
|
+
}
|
|
1131
|
+
/** Creates or replaces the render pipeline through the backend's asynchronous compilation path. */
|
|
1132
|
+
async _updatePipelineAsync() {
|
|
1133
|
+
const update = this._preparePipelineUpdate();
|
|
1134
|
+
if (update) {
|
|
1135
|
+
try {
|
|
1136
|
+
this.pipeline = await this.pipelineFactory.createRenderPipelineAsync(update.props);
|
|
1137
|
+
}
|
|
1138
|
+
catch (error) {
|
|
1139
|
+
this._releasePipelineShaders(update.vertexShader, update.fragmentShader);
|
|
1140
|
+
this._pipelineNeedsUpdate = 'asynchronous pipeline creation failed';
|
|
1141
|
+
throw error;
|
|
1142
|
+
}
|
|
1143
|
+
this._finishPipelineUpdate(update);
|
|
1144
|
+
}
|
|
1145
|
+
return this.pipeline;
|
|
1146
|
+
}
|
|
1147
|
+
_preparePipelineUpdate() {
|
|
1148
|
+
if (!this._pipelineNeedsUpdate)
|
|
1149
|
+
return null;
|
|
1150
|
+
const previousVertexShader = this.pipeline?.vs ?? null;
|
|
1151
|
+
const previousFragmentShader = this.pipeline?.fs ?? null;
|
|
1152
|
+
if (this.pipeline) {
|
|
1153
|
+
log.log(1, `GPUVectorModel ${this.id}: Recreating pipeline because "${this._pipelineNeedsUpdate}".`)();
|
|
1154
|
+
}
|
|
1155
|
+
this._pipelineNeedsUpdate = false;
|
|
1156
|
+
const vertexShader = this.shaderFactory.createShader({
|
|
1157
|
+
id: `${this.id}-vertex`,
|
|
1158
|
+
stage: 'vertex',
|
|
1159
|
+
source: this.source || this.vs,
|
|
1160
|
+
debugShaders: this.props.debugShaders
|
|
1161
|
+
});
|
|
1162
|
+
let fragmentShader = null;
|
|
1163
|
+
if (this.source) {
|
|
1164
|
+
fragmentShader = vertexShader;
|
|
1165
|
+
}
|
|
1166
|
+
else if (this.fs) {
|
|
1167
|
+
fragmentShader = this.shaderFactory.createShader({
|
|
1168
|
+
id: `${this.id}-fragment`,
|
|
1169
|
+
stage: 'fragment',
|
|
1170
|
+
source: this.fs,
|
|
1171
|
+
debugShaders: this.props.debugShaders
|
|
1172
|
+
});
|
|
1173
|
+
}
|
|
1174
|
+
return {
|
|
1175
|
+
props: {
|
|
1176
|
+
...this.props,
|
|
1177
|
+
bindings: undefined,
|
|
1178
|
+
bufferLayout: this.bufferLayout,
|
|
1179
|
+
colorAttachmentFormats: this._colorAttachmentFormats,
|
|
1180
|
+
depthStencilAttachmentFormat: this._depthStencilAttachmentFormat,
|
|
1181
|
+
topology: this.topology,
|
|
1182
|
+
parameters: this.parameters,
|
|
1183
|
+
bindGroups: undefined,
|
|
1184
|
+
vs: vertexShader,
|
|
1185
|
+
fs: fragmentShader
|
|
1186
|
+
},
|
|
1187
|
+
vertexShader,
|
|
1188
|
+
fragmentShader,
|
|
1189
|
+
previousVertexShader,
|
|
1190
|
+
previousFragmentShader
|
|
1191
|
+
};
|
|
1192
|
+
}
|
|
1193
|
+
_finishPipelineUpdate(update) {
|
|
1194
|
+
this._attributeInfos = getAttributeInfosFromLayouts(this.pipeline.shaderLayout, this.bufferLayout);
|
|
1195
|
+
this._releasePipelineShaders(update.previousVertexShader, update.previousFragmentShader);
|
|
1196
|
+
}
|
|
1197
|
+
_releasePipelineShaders(vertexShader, fragmentShader) {
|
|
1198
|
+
if (vertexShader)
|
|
1199
|
+
this.shaderFactory.release(vertexShader);
|
|
1200
|
+
if (fragmentShader && fragmentShader !== vertexShader) {
|
|
1201
|
+
this.shaderFactory.release(fragmentShader);
|
|
1202
|
+
}
|
|
1203
|
+
}
|
|
1204
|
+
/** Throttle draw call logging */
|
|
1205
|
+
_lastLogTime = 0;
|
|
1206
|
+
_logOpen = false;
|
|
1207
|
+
_logDrawCallStart() {
|
|
1208
|
+
// IF level is 4 or higher, log every frame.
|
|
1209
|
+
const logDrawTimeout = log.level > 3 ? 0 : LOG_DRAW_TIMEOUT;
|
|
1210
|
+
if (log.level < 2 || Date.now() - this._lastLogTime < logDrawTimeout) {
|
|
1211
|
+
return;
|
|
1212
|
+
}
|
|
1213
|
+
this._lastLogTime = Date.now();
|
|
1214
|
+
this._logOpen = true;
|
|
1215
|
+
log.group(LOG_DRAW_PRIORITY, `>>> DRAWING MODEL ${this.id}`, { collapsed: log.level <= 2 })();
|
|
1216
|
+
}
|
|
1217
|
+
_logDrawCallEnd() {
|
|
1218
|
+
if (this._logOpen) {
|
|
1219
|
+
const shaderLayoutTable = getDebugTableForShaderLayout(this.pipeline.shaderLayout, this.id);
|
|
1220
|
+
// log.table(logLevel, attributeTable)();
|
|
1221
|
+
// log.table(logLevel, uniformTable)();
|
|
1222
|
+
log.table(LOG_DRAW_PRIORITY, shaderLayoutTable)();
|
|
1223
|
+
const uniformTable = this.shaderInputs.getDebugTable();
|
|
1224
|
+
log.table(LOG_DRAW_PRIORITY, uniformTable)();
|
|
1225
|
+
const attributeTable = this._getAttributeDebugTable();
|
|
1226
|
+
log.table(LOG_DRAW_PRIORITY, this._attributeInfos)();
|
|
1227
|
+
log.table(LOG_DRAW_PRIORITY, attributeTable)();
|
|
1228
|
+
log.groupEnd(LOG_DRAW_PRIORITY)();
|
|
1229
|
+
this._logOpen = false;
|
|
1230
|
+
}
|
|
1231
|
+
}
|
|
1232
|
+
_drawCount = 0;
|
|
1233
|
+
_logFramebuffer(renderPass) {
|
|
1234
|
+
const debugFramebuffers = this.device.props.debugFramebuffers;
|
|
1235
|
+
this._drawCount++;
|
|
1236
|
+
// Update first 3 frames and then every 60 frames
|
|
1237
|
+
if (!debugFramebuffers) {
|
|
1238
|
+
// } || (this._drawCount++ > 3 && this._drawCount % 60)) {
|
|
1239
|
+
return;
|
|
1240
|
+
}
|
|
1241
|
+
const framebuffer = renderPass.props.framebuffer;
|
|
1242
|
+
debugFramebuffer(renderPass, framebuffer, {
|
|
1243
|
+
id: framebuffer?.id || `${this.id}-framebuffer`,
|
|
1244
|
+
minimap: true
|
|
1245
|
+
});
|
|
1246
|
+
}
|
|
1247
|
+
_getAttributeDebugTable() {
|
|
1248
|
+
const table = {};
|
|
1249
|
+
for (const [name, attributeInfo] of Object.entries(this._attributeInfos)) {
|
|
1250
|
+
const values = this.vertexArray.attributes[attributeInfo.location];
|
|
1251
|
+
table[attributeInfo.location] = {
|
|
1252
|
+
name,
|
|
1253
|
+
type: attributeInfo.shaderType,
|
|
1254
|
+
values: values
|
|
1255
|
+
? this._getBufferOrConstantValues(values, attributeInfo.bufferDataType)
|
|
1256
|
+
: 'null'
|
|
1257
|
+
};
|
|
1258
|
+
}
|
|
1259
|
+
if (this.vertexArray.indexBuffer) {
|
|
1260
|
+
const { indexBuffer } = this.vertexArray;
|
|
1261
|
+
const values = indexBuffer.indexType === 'uint32'
|
|
1262
|
+
? new Uint32Array(indexBuffer.debugData)
|
|
1263
|
+
: new Uint16Array(indexBuffer.debugData);
|
|
1264
|
+
table['indices'] = {
|
|
1265
|
+
name: 'indices',
|
|
1266
|
+
type: indexBuffer.indexType,
|
|
1267
|
+
values: values.toString()
|
|
1268
|
+
};
|
|
1269
|
+
}
|
|
1270
|
+
return table;
|
|
1271
|
+
}
|
|
1272
|
+
// TODO - fix typing of luma data types
|
|
1273
|
+
_getBufferOrConstantValues(attribute, dataType) {
|
|
1274
|
+
const TypedArrayConstructor = dataTypeDecoder.getTypedArrayConstructor(dataType);
|
|
1275
|
+
const typedArray = attribute instanceof Buffer ? new TypedArrayConstructor(attribute.debugData) : attribute;
|
|
1276
|
+
return typedArray.toString();
|
|
1277
|
+
}
|
|
1278
|
+
/** Returns the current reflected shader layout or the pre-reflection empty layout. */
|
|
1279
|
+
_getCurrentShaderLayout() {
|
|
1280
|
+
return this.pipeline?.shaderLayout || this.props.shaderLayout || { bindings: [] };
|
|
1281
|
+
}
|
|
1282
|
+
_syncDynamicBuffers() {
|
|
1283
|
+
if (this._dynamicIndexBufferSource &&
|
|
1284
|
+
this._dynamicIndexBufferSource.generation !== this._dynamicIndexBufferSource.source.generation) {
|
|
1285
|
+
const resolvedIndexBuffer = this._dynamicIndexBufferSource.source.buffer;
|
|
1286
|
+
this.indexBuffer = resolvedIndexBuffer;
|
|
1287
|
+
this.vertexArray.setIndexBuffer(resolvedIndexBuffer);
|
|
1288
|
+
this._dynamicIndexBufferSource.generation = this._dynamicIndexBufferSource.source.generation;
|
|
1289
|
+
this.setNeedsRedraw('dynamic index buffer');
|
|
1290
|
+
}
|
|
1291
|
+
for (const [locationKey, entry] of Object.entries(this._dynamicAttributeBufferSources)) {
|
|
1292
|
+
if (entry.generation !== entry.source.generation) {
|
|
1293
|
+
this.vertexArray.setBuffer(Number(locationKey), entry.source.buffer, entry.byteOffset);
|
|
1294
|
+
entry.generation = entry.source.generation;
|
|
1295
|
+
this.setNeedsRedraw('dynamic attribute buffer');
|
|
1296
|
+
}
|
|
1297
|
+
}
|
|
1298
|
+
}
|
|
1299
|
+
_syncAttachmentFormats(renderPass) {
|
|
1300
|
+
if (this.device.type !== 'webgpu') {
|
|
1301
|
+
return;
|
|
1302
|
+
}
|
|
1303
|
+
const framebuffer = renderPass.framebuffer || renderPass.props.framebuffer;
|
|
1304
|
+
const renderBundleProps = renderPass.props;
|
|
1305
|
+
const nextColorAttachmentFormats = renderBundleProps.colorAttachmentFormats ??
|
|
1306
|
+
framebuffer?.colorAttachments?.map(colorAttachment => asColorAttachmentFormat(colorAttachment?.texture?.format));
|
|
1307
|
+
const nextDepthStencilAttachmentFormat = renderBundleProps.depthStencilAttachmentFormat === false
|
|
1308
|
+
? undefined
|
|
1309
|
+
: (renderBundleProps.depthStencilAttachmentFormat ??
|
|
1310
|
+
asDepthStencilAttachmentFormat(framebuffer?.depthStencilAttachment?.texture?.format));
|
|
1311
|
+
if (!deepEqual(this._colorAttachmentFormats, nextColorAttachmentFormats, 1) ||
|
|
1312
|
+
this._depthStencilAttachmentFormat !== nextDepthStencilAttachmentFormat) {
|
|
1313
|
+
this._colorAttachmentFormats = nextColorAttachmentFormats;
|
|
1314
|
+
this._depthStencilAttachmentFormat = nextDepthStencilAttachmentFormat;
|
|
1315
|
+
this._setPipelineNeedsUpdate('attachment formats');
|
|
1316
|
+
}
|
|
1317
|
+
}
|
|
1318
|
+
}
|
|
1319
|
+
function isShaderAssemblerForLanguage(shaderAssembler, shaderLanguage) {
|
|
1320
|
+
if (shaderAssembler.shaderLanguage !== undefined &&
|
|
1321
|
+
shaderAssembler.shaderLanguage !== shaderLanguage) {
|
|
1322
|
+
return false;
|
|
1323
|
+
}
|
|
1324
|
+
return shaderLanguage === 'glsl'
|
|
1325
|
+
? 'assembleGLSLShaderPair' in shaderAssembler &&
|
|
1326
|
+
typeof shaderAssembler.assembleGLSLShaderPair === 'function'
|
|
1327
|
+
: 'assembleWGSLShader' in shaderAssembler &&
|
|
1328
|
+
typeof shaderAssembler.assembleWGSLShader === 'function';
|
|
1329
|
+
}
|
|
1330
|
+
function normalizeShaderPluginAttributeNames(shaderLayout, vertexInputs) {
|
|
1331
|
+
if (!shaderLayout || Object.keys(vertexInputs).length === 0) {
|
|
1332
|
+
return shaderLayout;
|
|
1333
|
+
}
|
|
1334
|
+
return {
|
|
1335
|
+
...shaderLayout,
|
|
1336
|
+
attributes: shaderLayout.attributes.map(attribute => {
|
|
1337
|
+
const publicName = attribute.name.startsWith('_luma_')
|
|
1338
|
+
? attribute.name.slice('_luma_'.length)
|
|
1339
|
+
: null;
|
|
1340
|
+
return publicName && vertexInputs[publicName] ? { ...attribute, name: publicName } : attribute;
|
|
1341
|
+
})
|
|
1342
|
+
};
|
|
1343
|
+
}
|
|
1344
|
+
/**
|
|
1345
|
+
* Resolves one model binding against the current shader layout.
|
|
1346
|
+
* @param bindingName Logical model binding name.
|
|
1347
|
+
* @param binding GPUVectorModel binding or deferred engine binding source.
|
|
1348
|
+
* @param shaderLayout Reflected bindings used to select copied or external texture resolution.
|
|
1349
|
+
* @returns Concrete core binding, or `null` while a deferred source is unavailable.
|
|
1350
|
+
*/
|
|
1351
|
+
function resolveModelBinding(bindingName, binding, shaderLayout) {
|
|
1352
|
+
if (isTextureBindingSource(binding)) {
|
|
1353
|
+
const bindingLayout = getTextureBindingLayout(shaderLayout, bindingName, {
|
|
1354
|
+
fallbackGroup: 0
|
|
1355
|
+
});
|
|
1356
|
+
return bindingLayout ? binding.resolveTextureBinding(bindingLayout) : null;
|
|
1357
|
+
}
|
|
1358
|
+
if (binding instanceof DynamicBuffer) {
|
|
1359
|
+
return binding.buffer;
|
|
1360
|
+
}
|
|
1361
|
+
if (isBufferRangeBinding(binding)) {
|
|
1362
|
+
return resolveBufferRangeBinding(binding);
|
|
1363
|
+
}
|
|
1364
|
+
return binding;
|
|
1365
|
+
}
|
|
1366
|
+
function asColorAttachmentFormat(format) {
|
|
1367
|
+
return format && !isDepthStencilAttachmentFormat(format) ? format : null;
|
|
1368
|
+
}
|
|
1369
|
+
function asDepthStencilAttachmentFormat(format) {
|
|
1370
|
+
return format && isDepthStencilAttachmentFormat(format) ? format : undefined;
|
|
1371
|
+
}
|
|
1372
|
+
function isDepthStencilAttachmentFormat(format) {
|
|
1373
|
+
return DEPTH_STENCIL_ATTACHMENT_FORMATS.includes(format);
|
|
1374
|
+
}
|
|
1375
|
+
//# sourceMappingURL=gpu-vector-model.js.map
|