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