@carbonenginejs/runtime 0.1.0-alpha.4 → 0.1.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/dist/global/blue/BlueClasses.js +200 -0
- package/dist/global/blue/BlueClasses.js.map +1 -0
- package/dist/global/blue/IBlueClasses.js +79 -0
- package/dist/global/blue/IBlueClasses.js.map +1 -0
- package/dist/global/blue/IBlueDynamicResourceConstructor.js +16 -0
- package/dist/global/blue/IBlueDynamicResourceConstructor.js.map +1 -1
- package/dist/global/blue/blue.js +8 -2
- package/dist/global/blue/blue.js.map +1 -1
- package/dist/global/blue/index.js +2 -0
- package/dist/global/blue/index.js.map +1 -1
- package/dist/global/consts/index.js +0 -1
- package/dist/global/consts/index.js.map +1 -1
- package/dist/global/consts/renderContext/formats.js +26 -25
- package/dist/global/consts/renderContext/formats.js.map +1 -1
- package/dist/{trinityal/Tr2BitmapDimensions.js → global/imageio/BitmapDimensions.js} +19 -15
- package/dist/global/imageio/BitmapDimensions.js.map +1 -0
- package/dist/global/imageio/Cutout.js +28 -0
- package/dist/global/imageio/Cutout.js.map +1 -0
- package/dist/global/imageio/HostBitmap.js +1106 -0
- package/dist/global/imageio/HostBitmap.js.map +1 -0
- package/dist/global/imageio/ImageIOResult.js +99 -0
- package/dist/global/imageio/ImageIOResult.js.map +1 -0
- package/dist/global/imageio/ImageUtility.js +205 -0
- package/dist/global/imageio/ImageUtility.js.map +1 -0
- package/dist/global/imageio/LoadParameters.js +86 -0
- package/dist/global/imageio/LoadParameters.js.map +1 -0
- package/dist/global/imageio/Metadata.js +22 -0
- package/dist/global/imageio/Metadata.js.map +1 -0
- package/dist/global/imageio/index.js +8 -0
- package/dist/global/{consts/webgpu → imageio}/index.js.map +1 -1
- package/dist/global/index.js +2 -1
- package/dist/global/index.js.map +1 -1
- package/dist/global/math/color.js +1 -1
- package/dist/global/math/color.js.map +1 -1
- package/dist/global/schema/CjsSchema.js +8 -0
- package/dist/global/schema/CjsSchema.js.map +1 -1
- package/dist/index.js +12 -4
- package/dist/index.js.map +1 -1
- package/dist/resource/CjsResMan.js +47 -7
- package/dist/resource/CjsResMan.js.map +1 -1
- package/dist/resource/Tr2LightProfileRes.js +37 -0
- package/dist/resource/Tr2LightProfileRes.js.map +1 -1
- package/dist/resource/format/CjsByteWriter.js +46 -46
- package/dist/resource/format/CjsByteWriter.js.map +1 -1
- package/dist/resource/format/CjsFormat.js +7 -8
- package/dist/resource/format/CjsFormat.js.map +1 -1
- package/dist/resource/format/CjsFormatStore.js +8 -8
- package/dist/resource/format/CjsFormatStore.js.map +1 -1
- package/dist/resource/format/CjsGeometryFormat.js +114 -0
- package/dist/resource/format/CjsGeometryFormat.js.map +1 -0
- package/dist/resource/format/CjsImageFormat.js +282 -0
- package/dist/resource/format/CjsImageFormat.js.map +1 -0
- package/dist/resource/format/CjsResourceProbe.js +12 -48
- package/dist/resource/format/CjsResourceProbe.js.map +1 -1
- package/dist/resource/format/CjsStringTable.js +37 -37
- package/dist/resource/format/CjsStringTable.js.map +1 -1
- package/dist/resource/format/carbonEffect/CjsCarbonEffectReader.js +10 -10
- package/dist/resource/format/carbonEffect/CjsCarbonEffectReader.js.map +1 -1
- package/dist/resource/format/carbonEffect/CjsCarbonEffectWriter.js +37 -37
- package/dist/resource/format/carbonEffect/CjsCarbonEffectWriter.js.map +1 -1
- package/dist/resource/format/carbonEffect/carbonEffectBackendBlock.js +35 -7
- package/dist/resource/format/carbonEffect/carbonEffectBackendBlock.js.map +1 -1
- package/dist/resource/format/index.js +3 -1
- package/dist/resource/format/index.js.map +1 -1
- package/dist/resource/formats/black/CjsBlackFormat.js +130 -137
- package/dist/resource/formats/black/CjsBlackFormat.js.map +1 -1
- package/dist/resource/formats/bnk/CjsBnkFormat.js +12 -19
- package/dist/resource/formats/bnk/CjsBnkFormat.js.map +1 -1
- package/dist/resource/formats/bnk/core/helpers.js +1 -3
- package/dist/resource/formats/bnk/core/helpers.js.map +1 -1
- package/dist/resource/formats/cmf/CjsCmfFormat.js +19 -82
- package/dist/resource/formats/cmf/CjsCmfFormat.js.map +1 -1
- package/dist/resource/formats/cmf/core/constants.js +1 -2
- package/dist/resource/formats/cmf/core/constants.js.map +1 -1
- package/dist/resource/formats/{stl/core/targets.js → cmf/core/flatShared.js} +9 -8
- package/dist/resource/formats/cmf/core/flatShared.js.map +1 -0
- package/dist/resource/formats/cmf/core/helpers.js +13 -13
- package/dist/resource/formats/cmf/core/helpers.js.map +1 -1
- package/dist/resource/formats/cmf/core/writer.js +24 -24
- package/dist/resource/formats/cmf/core/writer.js.map +1 -1
- package/dist/resource/formats/dds/CjsDdsFormat.js +134 -17
- package/dist/resource/formats/dds/CjsDdsFormat.js.map +1 -1
- package/dist/resource/formats/dds/core/helpers.js +125 -40
- package/dist/resource/formats/dds/core/helpers.js.map +1 -1
- package/dist/resource/formats/dxbc/CjsDxbcFormat.js +14 -16
- package/dist/resource/formats/dxbc/CjsDxbcFormat.js.map +1 -1
- package/dist/resource/formats/dxbc/core/{container.js → DxbcContainer.js} +2 -2
- package/dist/resource/formats/dxbc/core/DxbcContainer.js.map +1 -0
- package/dist/resource/formats/dxbc/core/{errors.js → DxbcReadError.js} +1 -1
- package/dist/resource/formats/dxbc/core/DxbcReadError.js.map +1 -0
- package/dist/resource/formats/dxbc/core/DxbcReader.js +1 -1
- package/dist/resource/formats/dxbc/core/DxbcReader.js.map +1 -1
- package/dist/resource/formats/dxbc/core/{program.js → DxbcShaderProgram.js} +2 -2
- package/dist/resource/formats/dxbc/core/DxbcShaderProgram.js.map +1 -0
- package/dist/resource/formats/dxbc/core/{signature.js → DxbcSignatureChunk.js} +2 -2
- package/dist/resource/formats/dxbc/core/DxbcSignatureChunk.js.map +1 -0
- package/dist/resource/formats/dxbc/core/decoder.js +2 -2
- package/dist/resource/formats/dxbc/core/decoder.js.map +1 -1
- package/dist/resource/formats/dxbc/core/helpers.js +3 -3
- package/dist/resource/formats/dxbc/core/helpers.js.map +1 -1
- package/dist/resource/formats/fbx/CjsFbxFormat.js +18 -20
- package/dist/resource/formats/fbx/CjsFbxFormat.js.map +1 -1
- package/dist/resource/formats/flac/CjsFlacFormat.js +7 -13
- package/dist/resource/formats/flac/CjsFlacFormat.js.map +1 -1
- package/dist/resource/formats/fsd/32/CjsFsd32Format.js +29 -29
- package/dist/resource/formats/fsd/32/CjsFsd32Format.js.map +1 -1
- package/dist/resource/formats/fsd/64/CjsFsd64Format.js +3 -3
- package/dist/resource/formats/fsd/64/CjsFsd64Format.js.map +1 -1
- package/dist/resource/formats/fsd/64/core/CjsFsd64Binary.js +23 -23
- package/dist/resource/formats/fsd/64/core/CjsFsd64Binary.js.map +1 -1
- package/dist/resource/formats/fsd/64/core/CjsFsd64Reader.js +8 -8
- package/dist/resource/formats/fsd/64/core/CjsFsd64Reader.js.map +1 -1
- package/dist/resource/formats/fsd/CjsFsdFormat.js +23 -23
- package/dist/resource/formats/fsd/CjsFsdFormat.js.map +1 -1
- package/dist/resource/formats/gif/CjsGifFormat.js +24 -15
- package/dist/resource/formats/gif/CjsGifFormat.js.map +1 -1
- package/dist/resource/formats/gltf/CjsGltfFormat.js +33 -98
- package/dist/resource/formats/gltf/CjsGltfFormat.js.map +1 -1
- package/dist/resource/formats/gltf/core/helpers.js +3 -12
- package/dist/resource/formats/gltf/core/helpers.js.map +1 -1
- package/dist/resource/formats/gr2/CjsGr2Format.js +27 -91
- package/dist/resource/formats/gr2/CjsGr2Format.js.map +1 -1
- package/dist/resource/formats/hlsl/CjsHlslFormat.js +22 -25
- package/dist/resource/formats/hlsl/CjsHlslFormat.js.map +1 -1
- package/dist/resource/formats/hlsl/core/carbonDescriptionToRuntime.js +1 -1
- package/dist/resource/formats/hlsl/core/carbonDescriptionToRuntime.js.map +1 -1
- package/dist/resource/formats/hlsl/core/tr2/shader/HlslEffectStageInput.js +3 -3
- package/dist/resource/formats/hlsl/core/tr2/shader/HlslEffectStageInput.js.map +1 -1
- package/dist/resource/formats/ies/CjsIESFormat.js +29 -29
- package/dist/resource/formats/ies/CjsIESFormat.js.map +1 -1
- package/dist/resource/formats/jpeg/CjsJpegFormat.js +24 -15
- package/dist/resource/formats/jpeg/CjsJpegFormat.js.map +1 -1
- package/dist/resource/formats/jpeg/core/helpers.js +3 -5
- package/dist/resource/formats/jpeg/core/helpers.js.map +1 -1
- package/dist/resource/formats/jpeg/core/jpeg.js +58 -58
- package/dist/resource/formats/jpeg/core/jpeg.js.map +1 -1
- package/dist/resource/formats/jsonl/CjsJsonlFormat.js +3 -3
- package/dist/resource/formats/jsonl/CjsJsonlFormat.js.map +1 -1
- package/dist/resource/formats/mp3/CjsMp3Format.js +7 -14
- package/dist/resource/formats/mp3/CjsMp3Format.js.map +1 -1
- package/dist/resource/formats/mp3/core/helpers.js +3 -5
- package/dist/resource/formats/mp3/core/helpers.js.map +1 -1
- package/dist/resource/formats/mp4/CjsMp4Format.js +7 -13
- package/dist/resource/formats/mp4/CjsMp4Format.js.map +1 -1
- package/dist/resource/formats/mp4/core/helpers.js +3 -5
- package/dist/resource/formats/mp4/core/helpers.js.map +1 -1
- package/dist/resource/formats/obj/CjsObjFormat.js +92 -157
- package/dist/resource/formats/obj/CjsObjFormat.js.map +1 -1
- package/dist/resource/formats/obj/core/helpers.js +5 -113
- package/dist/resource/formats/obj/core/helpers.js.map +1 -1
- package/dist/resource/formats/ogg/CjsOggFormat.js +7 -14
- package/dist/resource/formats/ogg/CjsOggFormat.js.map +1 -1
- package/dist/resource/formats/pickle/CjsPickleFormat.js +7 -12
- package/dist/resource/formats/pickle/CjsPickleFormat.js.map +1 -1
- package/dist/resource/formats/pickle/core/CjsPickleProtocol0Reader.js +7 -7
- package/dist/resource/formats/pickle/core/CjsPickleProtocol0Reader.js.map +1 -1
- package/dist/resource/formats/pickle/core/CjsPickleProtocol4Reader.js +7 -7
- package/dist/resource/formats/pickle/core/CjsPickleProtocol4Reader.js.map +1 -1
- package/dist/resource/formats/png/CjsPngFormat.js +40 -15
- package/dist/resource/formats/png/CjsPngFormat.js.map +1 -1
- package/dist/resource/formats/png/core/helpers.js +4 -6
- package/dist/resource/formats/png/core/helpers.js.map +1 -1
- package/dist/resource/formats/red/CjsRedFormat.js +22 -28
- package/dist/resource/formats/red/CjsRedFormat.js.map +1 -1
- package/dist/resource/formats/schemabound/CjsSchemaBoundFormat.js +3 -7
- package/dist/resource/formats/schemabound/CjsSchemaBoundFormat.js.map +1 -1
- package/dist/resource/formats/schemabound/core/schemaBoundValues.js +5 -0
- package/dist/resource/formats/schemabound/core/schemaBoundValues.js.map +1 -1
- package/dist/resource/formats/sqlite/CjsSqliteFormat.js +4 -9
- package/dist/resource/formats/sqlite/CjsSqliteFormat.js.map +1 -1
- package/dist/resource/formats/static/CjsStaticFormat.js +4 -4
- package/dist/resource/formats/static/CjsStaticFormat.js.map +1 -1
- package/dist/resource/formats/stl/CjsStlFormat.js +39 -104
- package/dist/resource/formats/stl/CjsStlFormat.js.map +1 -1
- package/dist/resource/formats/stl/core/helpers.js +5 -19
- package/dist/resource/formats/stl/core/helpers.js.map +1 -1
- package/dist/resource/formats/tga/CjsTgaFormat.js +26 -15
- package/dist/resource/formats/tga/CjsTgaFormat.js.map +1 -1
- package/dist/resource/formats/tga/core/helpers.js +3 -5
- package/dist/resource/formats/tga/core/helpers.js.map +1 -1
- package/dist/resource/formats/vta/CjsVtaFormat.js +8 -15
- package/dist/resource/formats/vta/CjsVtaFormat.js.map +1 -1
- package/dist/resource/formats/wav/CjsWavFormat.js +7 -14
- package/dist/resource/formats/wav/CjsWavFormat.js.map +1 -1
- package/dist/resource/formats/wav/core/helpers.js +3 -5
- package/dist/resource/formats/wav/core/helpers.js.map +1 -1
- package/dist/resource/formats/webgl/CjsWebglFormat.js +103 -105
- package/dist/resource/formats/webgl/CjsWebglFormat.js.map +1 -1
- package/dist/resource/formats/webgl/core/{errors.js → WebglReadError.js} +1 -1
- package/dist/resource/formats/webgl/core/WebglReadError.js.map +1 -0
- package/dist/resource/formats/webgl/core/effectPackage.js +1 -1
- package/dist/resource/formats/webgl/core/effectPackage.js.map +1 -1
- package/dist/resource/formats/webgl/core/glsl/DxbcGlslEmitter.js +3 -3
- package/dist/resource/formats/webgl/core/glsl/DxbcGlslEmitter.js.map +1 -1
- package/dist/resource/formats/webgl/core/glsl/{DxbcGlslHelpers.js → DxbcGlslHelperRegistry.js} +2 -2
- package/dist/resource/formats/webgl/core/glsl/DxbcGlslHelperRegistry.js.map +1 -0
- package/dist/resource/formats/webgl/core/glsl/DxbcGlslOperandFormatter.js +1 -1
- package/dist/resource/formats/webgl/core/glsl/DxbcGlslOperandFormatter.js.map +1 -1
- package/dist/resource/formats/webgl/core/glslBackendBlock.js +1 -1
- package/dist/resource/formats/webgl/core/glslBackendBlock.js.map +1 -1
- package/dist/resource/formats/webgl/core/helpers.js.map +1 -1
- package/dist/resource/formats/webgpu/CjsWebgpuFormat.js +28 -29
- package/dist/resource/formats/webgpu/CjsWebgpuFormat.js.map +1 -1
- package/dist/resource/formats/webgpu/core/{errors.js → WebgpuReadError.js} +1 -1
- package/dist/resource/formats/webgpu/core/WebgpuReadError.js.map +1 -0
- package/dist/resource/formats/webgpu/core/carbonWebgpu/validateContainer.js +1 -1
- package/dist/resource/formats/webgpu/core/carbonWebgpu/validateContainer.js.map +1 -1
- package/dist/resource/formats/webgpu/core/helpers.js +1 -1
- package/dist/resource/formats/webgpu/core/helpers.js.map +1 -1
- package/dist/resource/formats/webgpu/core/ir/lowerDxbcToIr.js +1 -1
- package/dist/resource/formats/webgpu/core/ir/lowerDxbcToIr.js.map +1 -1
- package/dist/resource/formats/webgpu/core/wgsl/buildWgslSet.js +18 -6
- package/dist/resource/formats/webgpu/core/wgsl/buildWgslSet.js.map +1 -1
- package/dist/resource/formats/webgpu/core/wgsl/lowerBindingLayout.js +39 -13
- package/dist/resource/formats/webgpu/core/wgsl/lowerBindingLayout.js.map +1 -1
- package/dist/resource/formats/webgpu/core/wgsl/lowerCreateHistogramsComputeProgram.js +16 -14
- package/dist/resource/formats/webgpu/core/wgsl/lowerCreateHistogramsComputeProgram.js.map +1 -1
- package/dist/resource/formats/webm/CjsWebmFormat.js +8 -13
- package/dist/resource/formats/webm/CjsWebmFormat.js.map +1 -1
- package/dist/resource/formats/webm/core/helpers.js +3 -5
- package/dist/resource/formats/webm/core/helpers.js.map +1 -1
- package/dist/resource/formats/webp/CjsWebpFormat.js +8 -12
- package/dist/resource/formats/webp/CjsWebpFormat.js.map +1 -1
- package/dist/resource/formats/wem/CjsWemFormat.js +9 -17
- package/dist/resource/formats/wem/CjsWemFormat.js.map +1 -1
- package/dist/resource/formats/wem/core/bitStream.js +35 -35
- package/dist/resource/formats/wem/core/bitStream.js.map +1 -1
- package/dist/resource/formats/wem/core/helpers.js +1 -3
- package/dist/resource/formats/wem/core/helpers.js.map +1 -1
- package/dist/resource/formats/yaml/CjsYamlFormat.js +28 -37
- package/dist/resource/formats/yaml/CjsYamlFormat.js.map +1 -1
- package/dist/resource/imageio/ImageIO.js +142 -0
- package/dist/resource/imageio/ImageIO.js.map +1 -0
- package/dist/resource/imageio/index.js +17 -0
- package/dist/resource/imageio/index.js.map +1 -0
- package/dist/resource/index.js +7 -0
- package/dist/resource/index.js.map +1 -1
- package/dist/resource/shader/reflection/Tr2EffectResource.js +24 -2
- package/dist/resource/shader/reflection/Tr2EffectResource.js.map +1 -1
- package/dist/resource/shader/reflection/Tr2Pass.js +76 -5
- package/dist/resource/shader/reflection/Tr2Pass.js.map +1 -1
- package/dist/resource/texture/CjsTextureArrayConstructor.js +97 -0
- package/dist/resource/texture/CjsTextureArrayConstructor.js.map +1 -0
- package/dist/resource/texture/CjsTexturePackConstructor.js +160 -0
- package/dist/resource/texture/CjsTexturePackConstructor.js.map +1 -0
- package/dist/resource/texture/CjsTexturePipelineStepArray.js +72 -0
- package/dist/resource/texture/CjsTexturePipelineStepArray.js.map +1 -0
- package/dist/resource/texture/CjsTexturePipelineStepConvert.js +73 -0
- package/dist/resource/texture/CjsTexturePipelineStepConvert.js.map +1 -0
- package/dist/resource/texture/CjsTexturePipelineStepPack.js +71 -0
- package/dist/resource/texture/CjsTexturePipelineStepPack.js.map +1 -0
- package/dist/resource/texture/CjsTexturePipelineStepResize.js +123 -0
- package/dist/resource/texture/CjsTexturePipelineStepResize.js.map +1 -0
- package/dist/resource/texture/SolidColorTextureConstructor.js +11 -1
- package/dist/resource/texture/SolidColorTextureConstructor.js.map +1 -1
- package/dist/resource/texture/Tr2ImageRes.js +100 -68
- package/dist/resource/texture/Tr2ImageRes.js.map +1 -1
- package/dist/resource/texture/Tr2TexturePipeline.js +45 -25
- package/dist/resource/texture/Tr2TexturePipeline.js.map +1 -1
- package/dist/resource/texture/Tr2TexturePipelineStepCompress.js +34 -1
- package/dist/resource/texture/Tr2TexturePipelineStepCompress.js.map +1 -1
- package/dist/resource/texture/Tr2TexturePipelineStepGenerateMips.js +30 -3
- package/dist/resource/texture/Tr2TexturePipelineStepGenerateMips.js.map +1 -1
- package/dist/resource/texture/Tr2TexturePipelineStepLimitSize.js +81 -1
- package/dist/resource/texture/Tr2TexturePipelineStepLimitSize.js.map +1 -1
- package/dist/resource/texture/Tr2TexturePipelineStepLoad.js +36 -1
- package/dist/resource/texture/Tr2TexturePipelineStepLoad.js.map +1 -1
- package/dist/resource/texture/Tr2TexturePipelineStepPack.js +146 -24
- package/dist/resource/texture/Tr2TexturePipelineStepPack.js.map +1 -1
- package/dist/resource/texture/TriTextureRes.js +151 -29
- package/dist/resource/texture/TriTextureRes.js.map +1 -1
- package/dist/resource/texture/index.js +7 -0
- package/dist/resource/texture/index.js.map +1 -1
- package/dist/resource/texture/registerTextureResources.js +83 -0
- package/dist/resource/texture/registerTextureResources.js.map +1 -0
- package/dist/resource/texture/solidColorTexture.js +10 -19
- package/dist/resource/texture/solidColorTexture.js.map +1 -1
- package/dist/sof/EveSOF.js +39 -7
- package/dist/sof/EveSOF.js.map +1 -1
- package/dist/trinity/core/Tr2GpuResourcePool/Tr2GpuResourcePool.js +2 -2
- package/dist/trinity/core/Tr2GpuResourcePool/Tr2GpuResourcePool.js.map +1 -1
- package/dist/trinity/core/Tr2ImageIOHelpers.js +80 -17
- package/dist/trinity/core/Tr2ImageIOHelpers.js.map +1 -1
- package/dist/trinity/core/Tr2RenderUtils.js +1 -1
- package/dist/trinity/core/Tr2TextureArray/Tr2TextureArray.js +49 -62
- package/dist/trinity/core/Tr2TextureArray/Tr2TextureArray.js.map +1 -1
- package/dist/trinity/core/Tr2TextureReference.js +114 -0
- package/dist/trinity/core/Tr2TextureReference.js.map +1 -0
- package/dist/trinity/core/device/Tr2DepthStencil.js +2 -2
- package/dist/trinity/core/device/Tr2DepthStencil.js.map +1 -1
- package/dist/trinity/core/device/Tr2RingBuffer/Tr2RingBuffer.js +1 -1
- package/dist/trinity/core/index.js +1 -0
- package/dist/trinity/core/index.js.map +1 -1
- package/dist/trinity/core/lighting/Tr2LightManager.js +5 -4
- package/dist/trinity/core/lighting/Tr2LightManager.js.map +1 -1
- package/dist/trinity/core/procedural/GradientTextureConstructor.js +5 -4
- package/dist/trinity/core/procedural/GradientTextureConstructor.js.map +1 -1
- package/dist/trinity/core/procedural/gradientTexture.js +10 -13
- package/dist/trinity/core/procedural/gradientTexture.js.map +1 -1
- package/dist/trinity/core/volumetrics/Tr2VolumetricsRenderer.js +1 -1
- package/dist/trinity/core/volumetrics/Tr2VolumetricsRenderer.js.map +1 -1
- package/dist/trinity/eve/EveImpactOverlay.js +102 -50
- package/dist/trinity/eve/EveImpactOverlay.js.map +1 -1
- package/dist/trinity/eve/EveModularObjectModifier.js +9 -18
- package/dist/trinity/eve/EveModularObjectModifier.js.map +1 -1
- package/dist/trinity/eve/attachment/turrets/EveTurretSet.js +175 -157
- package/dist/trinity/eve/attachment/turrets/EveTurretSet.js.map +1 -1
- package/dist/trinity/eve/attachment/turrets/EveTurretTarget.js +100 -83
- package/dist/trinity/eve/attachment/turrets/EveTurretTarget.js.map +1 -1
- package/dist/trinity/eve/child/EveChildInstancedMeshes/EveChildInstancedMesh.js +26 -20
- package/dist/trinity/eve/child/EveChildInstancedMeshes/EveChildInstancedMesh.js.map +1 -1
- package/dist/trinity/eve/child/EveChildInstancedMeshes/EveChildInstancedMeshes.js +368 -179
- package/dist/trinity/eve/child/EveChildInstancedMeshes/EveChildInstancedMeshes.js.map +1 -1
- package/dist/trinity/eve/child/EveChildMesh.js +242 -234
- package/dist/trinity/eve/child/EveChildMesh.js.map +1 -1
- package/dist/trinity/eve/child/EveChildTurret.js +57 -16
- package/dist/trinity/eve/child/EveChildTurret.js.map +1 -1
- package/dist/trinity/eve/child/EveSpaceObjectChild.js +28 -1
- package/dist/trinity/eve/child/EveSpaceObjectChild.js.map +1 -1
- package/dist/trinity/eve/index.js +2 -2
- package/dist/trinity/eve/overlays/EveDamageOverlay.js +5 -1
- package/dist/trinity/eve/overlays/EveDamageOverlay.js.map +1 -1
- package/dist/trinity/eve/scene/EveSpaceScene.js +234 -233
- package/dist/trinity/eve/scene/EveSpaceScene.js.map +1 -1
- package/dist/trinity/eve/scene/EveSpaceSceneRenderDriver.js +2 -0
- package/dist/trinity/eve/scene/EveSpaceSceneRenderDriver.js.map +1 -1
- package/dist/trinity/eve/spaceObject/EveSpaceObject2.js +492 -437
- package/dist/trinity/eve/spaceObject/EveSpaceObject2.js.map +1 -1
- package/dist/trinity/generated/index.js +0 -1
- package/dist/trinity/generated/index.js.map +1 -1
- package/dist/trinity/generated/trinityCore/index.js +0 -1
- package/dist/trinity/generated/trinityCore/index.js.map +1 -1
- package/dist/trinity/index.js +3 -3
- package/dist/trinity/particle/emitter/Tr2GpuSharedEmitter.js +10 -1
- package/dist/trinity/particle/emitter/Tr2GpuSharedEmitter.js.map +1 -1
- package/dist/trinity/shader/Tr2DataTextureManager.js +152 -66
- package/dist/trinity/shader/Tr2DataTextureManager.js.map +1 -1
- package/dist/trinity/shader/Tr2Material.js +1 -1
- package/dist/trinityal/Tr2HalHelperStructures/Tr2TextureSubresource.js +5 -5
- package/dist/trinityal/Tr2HalHelperStructures/Tr2TextureSubresource.js.map +1 -1
- package/dist/trinityal/index.js +1 -1
- package/dist/trinityal/stub/Tr2RenderContextALStub/Tr2RenderContextALStub.js +2 -2
- package/dist/trinityal/stub/Tr2RenderContextALStub/Tr2RenderContextALStub.js.map +1 -1
- package/dist/trinityal/stub/Tr2SwapChainALStub.js +45 -45
- package/dist/trinityal/stub/Tr2SwapChainALStub.js.map +1 -1
- package/dist/trinityal/stub/Tr2TextureALStub.js +170 -170
- package/dist/trinityal/stub/Tr2TextureALStub.js.map +1 -1
- package/dist/trinityal/webgpu/CjsWebgpuDevice.js +234 -164
- package/dist/trinityal/webgpu/CjsWebgpuDevice.js.map +1 -1
- package/dist/trinityal/webgpu/CjsWebgpuRenderContextAL.js +7 -0
- package/dist/trinityal/webgpu/CjsWebgpuRenderContextAL.js.map +1 -1
- package/dist/trinityal/webgpu/CjsWebgpuTextureAL.js +78 -14
- package/dist/trinityal/webgpu/CjsWebgpuTextureAL.js.map +1 -1
- package/dist/trinityal/webgpu/core/CjsWebgpuUtils.js +94 -0
- package/dist/trinityal/webgpu/core/CjsWebgpuUtils.js.map +1 -0
- package/dist/trinityal/webgpu/internal.js +1 -0
- package/dist/trinityal/webgpu/internal.js.map +1 -1
- package/docs/global/reference/classes/README.md +90 -0
- package/docs/resource/concepts/format-capabilities.md +3 -3
- package/docs/resource/formats/README.md +1 -1
- package/docs/resource/reference/classes/core.md +31 -1
- package/docs/resource/reference/classes/formats.md +7 -7
- package/docs/resource/reference/classes/resources.md +76 -16
- package/docs/trinity/reference/classes/generated.md +0 -10
- package/docs/trinity/reference/classes/trinity-core.md +1692 -1682
- package/docs/trinityal/reference/classes/README.md +0 -10
- package/docs/trinityal/webgpu/reference/classes/README.md +276 -266
- package/package.json +4 -3
- package/dist/global/consts/webgpu/index.js +0 -2
- package/dist/global/consts/webgpu/textureFormats.js +0 -180
- package/dist/global/consts/webgpu/textureFormats.js.map +0 -1
- package/dist/resource/formats/dxbc/core/container.js.map +0 -1
- package/dist/resource/formats/dxbc/core/errors.js.map +0 -1
- package/dist/resource/formats/dxbc/core/program.js.map +0 -1
- package/dist/resource/formats/dxbc/core/signature.js.map +0 -1
- package/dist/resource/formats/stl/core/targets.js.map +0 -1
- package/dist/resource/formats/webgl/core/errors.js.map +0 -1
- package/dist/resource/formats/webgl/core/glsl/DxbcGlslHelpers.js.map +0 -1
- package/dist/resource/formats/webgpu/core/errors.js.map +0 -1
- package/dist/resource/texture/texturePipelineBehavior.js +0 -332
- package/dist/resource/texture/texturePipelineBehavior.js.map +0 -1
- package/dist/trinity/generated/trinityCore/Tr2TextureReference.js +0 -40
- package/dist/trinity/generated/trinityCore/Tr2TextureReference.js.map +0 -1
- package/dist/trinityal/Tr2BitmapDimensions.js.map +0 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { BitmapDimensions } from '#imageio';
|
|
2
2
|
import '../../../global/consts/renderContext/formats.js';
|
|
3
3
|
import '../../../global/consts/renderContext/pipeline.js';
|
|
4
4
|
import '../../../trinityal/Tr2DeviceResourceAL/Tr2BaseDeviceResourceAL.js';
|
|
@@ -256,7 +256,7 @@ class Tr2GpuResourcePool {
|
|
|
256
256
|
//
|
|
257
257
|
// The dimensions spread carries type, depth and mipCount, so an array or a
|
|
258
258
|
// 3D texture is expressible here and always was.
|
|
259
|
-
return this.#renderContext.CreateTexture(new
|
|
259
|
+
return this.#renderContext.CreateTexture(new BitmapDimensions(dimensions), {
|
|
260
260
|
gpuUsage,
|
|
261
261
|
cpuUsage,
|
|
262
262
|
msaa,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Tr2GpuResourcePool.js","sources":["../../../../../src/trinity/core/Tr2GpuResourcePool/Tr2GpuResourcePool.js"],"sourcesContent":["// Source: trinity/trinity/Tr2GpuResourcePool.h\n// Source: trinity/trinity/Tr2GpuResourcePool.cpp\n//\n// Where a render pass gets a scratch texture or buffer, and how one is kept\n// alive only as long as something holds it.\n//\n// THIS IS THE CLASS FOUR INVENTED ONES WERE STANDING IN FOR. Carbon's\n// `Tr2ShadowMap::PrepareShadowRendering( gpuResourcePool, renderContext )` and\n// the whole `EveSpaceScene` volumetrics family take a pool and do their own\n// work. Ours had the methods but bounced them to an engine-supplied executor,\n// because there was no pool to hand them. So an interface was invented per\n// subsystem rather than porting the one class they all needed.\n//\n// TWO LIFETIMES, and the distinction is the whole design. A TEMP resource is\n// recycled as soon as nothing holds it and it has not been touched for a few\n// frames; a PERSISTENT one is initialized once and kept. Asking for a temp\n// texture with the same shape twice in a frame therefore gets the same texture\n// only if the first handle has been released - which is what makes a pass able\n// to say \"give me a working surface\" without owning one.\n//\n// THE HANDLE IS THE LIFETIME. Carbon's `GpuResourceHandle` counts locks on copy\n// and release, and a record with a live lock is never recycled. JavaScript has\n// no destructor, so `Release()` is explicit here - see the note on the class.\n//\n// NESTING IS CARBON'S: a pool may have an OUTER pool, and a lookup that misses\n// walks outward. That is how a scene-local pool shares the global one's\n// resources without owning them.\n\nimport { Tr2BitmapDimensions } from \"../../../trinityal/index.js\";\nimport { GpuResourceHandle } from \"./GpuResourceHandle.js\";\n\n/** Throws a resource-pool error with the supplied diagnostic. */\nexport function fail(message)\n{\n const error = new Error(`Tr2GpuResourcePool: ${message}`);\n error.code = \"CJS_GPU_POOL_INVALID\";\n throw error;\n}\n\n/**\n * Pooled scratch textures and buffers.\n */\nexport class Tr2GpuResourcePool\n{\n /** m_outer - the pool a miss falls through to. */\n #outer = null;\n\n #tempTextures = [];\n\n #persistentTextures = [];\n\n #tempBuffers = [];\n\n #persistentBuffers = [];\n\n /** m_debugMode */\n #debugMode = false;\n\n /** The frame a lookup counts as \"now\". */\n #frame = 0;\n\n /**\n * The backend resources are created against.\n *\n * Carbon's pool is a `Tr2DeviceResource` and reaches its device that way.\n * This runtime has no process-wide device, so the context is handed in - the\n * same arrangement `Tr2EffectStateManager` uses.\n */\n #renderContext = null;\n\n /**\n * @param {Tr2GpuResourcePool} [outer] A pool to fall through to on a miss.\n */\n constructor(outer = null)\n {\n this.#outer = outer;\n }\n\n /**\n * Binds the backend resources are created against.\n *\n * @param {object} renderContext A render-context abstraction layer.\n * @returns {Tr2GpuResourcePool} This pool, for chaining.\n */\n SetRenderContext(renderContext)\n {\n this.#renderContext = renderContext;\n\n return this;\n }\n\n /**\n * Advances the pool's idea of the current frame.\n *\n * @param {number} frame The frame number.\n */\n SetFrame(frame)\n {\n this.#frame = frame;\n }\n\n /**\n * Borrows a scratch texture, creating one only if no free match exists.\n *\n * A FREE MATCH IS ONE NOBODY HOLDS. A record with a live lock is never handed\n * out again, which is what lets two passes ask for \"a 512 square\" and get\n * different surfaces when both are in flight, and the same one when they are\n * not.\n *\n * @param {string} name A debug name.\n * @param {object} description A `Tr2BitmapDimensions` shape (`type`, `width`,\n * `height`, `depth`, `mipCount`, `format`) plus `gpuUsage`, `cpuUsage`,\n * `msaa` and `initialData`.\n * @returns {GpuResourceHandle} The borrowed texture.\n */\n GetTempTexture(name, description)\n {\n return this.#Borrow(this.#tempTextures, name, description, () => this.#CreateTexture(description));\n }\n\n /**\n * Borrows a persistent texture, initializing it the first time only.\n *\n * @param {string} name A debug name.\n * @param {object} description As `GetTempTexture`.\n * @param {Function} [initialize] Called once, with the new texture.\n * @returns {GpuResourceHandle} The texture.\n */\n GetPersistentTexture(name, description, initialize = null)\n {\n const existing = this.#Find(this.#persistentTextures, name, description, false);\n\n if (existing) return new GpuResourceHandle(existing);\n\n const texture = this.#CreateTexture(description);\n\n if (initialize) initialize(texture);\n\n return new GpuResourceHandle(this.#Add(this.#persistentTextures, name, description, texture));\n }\n\n /**\n * Borrows a scratch buffer.\n *\n * @param {string} name A debug name.\n * @param {object} description A `Tr2BufferDescriptionAL`.\n * @returns {GpuResourceHandle} The borrowed buffer.\n */\n GetTempBuffer(name, description)\n {\n return this.#Borrow(this.#tempBuffers, name, description, () => this.#CreateBuffer(description));\n }\n\n /**\n * Borrows a persistent buffer, initializing it the first time only.\n *\n * @param {string} name A debug name.\n * @param {object} description A `Tr2BufferDescriptionAL`.\n * @param {Function} [initialize] Called once, with the new buffer.\n * @returns {GpuResourceHandle} The buffer.\n */\n GetPersistentBuffer(name, description, initialize = null)\n {\n const existing = this.#Find(this.#persistentBuffers, name, description, false);\n\n if (existing) return new GpuResourceHandle(existing);\n\n const buffer = this.#CreateBuffer(description);\n\n if (initialize) initialize(buffer);\n\n return new GpuResourceHandle(this.#Add(this.#persistentBuffers, name, description, buffer));\n }\n\n /**\n * Returns a borrowed resource, as Carbon's allocators do.\n *\n * @param {GpuResourceHandle} handle The handle to give back.\n * @returns {boolean} Whether a claim was dropped.\n */\n Free(handle)\n {\n if (!handle) fail(\"Free needs a handle\");\n\n return handle.Detach();\n }\n\n /**\n * Drops temp resources nobody holds and nobody has touched recently.\n *\n * @param {number} [frameThreshold] How many frames of disuse to allow.\n * @returns {number} How many resources were dropped.\n */\n ClearUnusedResources(frameThreshold = 3)\n {\n let dropped = 0;\n\n for (const list of [ this.#tempTextures, this.#tempBuffers ])\n {\n for (let index = list.length - 1; index >= 0; index -= 1)\n {\n const record = list[index];\n\n if (record.lockCount > 0) continue;\n if (this.#frame - record.lastAccessFrame < frameThreshold) continue;\n\n record.resource.Destroy();\n list.splice(index, 1);\n dropped += 1;\n }\n }\n\n return dropped;\n }\n\n /** @param {boolean} enable Whether to keep debug detail. */\n SetDebugMode(enable)\n {\n this.#debugMode = !!enable;\n }\n\n /** @returns {boolean} Whether debug mode is on. */\n GetDebugMode()\n {\n return this.#debugMode;\n }\n\n /**\n * Every temp texture the pool holds, for a caller that must assert.\n *\n * @returns {object[]} The textures.\n */\n DebugGetAllTempTextures()\n {\n return this.#tempTextures.map(record => record.resource);\n }\n\n /**\n * How many resources are currently held by a handle.\n *\n * Not Carbon's - JavaScript has no destructor to release on, so a caller\n * needs a way to prove it released what it borrowed.\n *\n * @returns {number} The count.\n */\n GetHeldCount()\n {\n return [ this.#tempTextures, this.#persistentTextures, this.#tempBuffers, this.#persistentBuffers ]\n .reduce((total, list) => total + list.filter(record => record.lockCount > 0).length, 0);\n }\n\n /** Splits the pool's flat description into the AL's two arguments. */\n #CreateTexture(description)\n {\n if (!this.#renderContext) fail(\"a pool creates against a render context; none is bound\");\n\n const { gpuUsage, cpuUsage, msaa, initialData, ...dimensions } = description;\n\n // THE CONTEXT IS THE FACTORY. This used to be `new Tr2TextureALStub()`,\n // which named the backend at authoring time: every texture the pool handed\n // out was a stub no matter which backend was bound, so a WebGPU pass would\n // have been handed textures that reach no device and drawn nothing, with\n // no error anywhere. Tr2Blitter's head comment names this exact defect.\n //\n // The dimensions spread carries type, depth and mipCount, so an array or a\n // 3D texture is expressible here and always was.\n return this.#renderContext.CreateTexture(\n new Tr2BitmapDimensions(dimensions),\n { gpuUsage, cpuUsage, msaa, initialData }\n );\n }\n\n /**\n * Creates a stub buffer from the description against the pool's render\n * context.\n */\n #CreateBuffer(description)\n {\n if (!this.#renderContext) fail(\"a pool creates against a render context; none is bound\");\n\n // Through the context for the same reason as the texture above. The\n // previous form also passed the context as `initialData`, leaving\n // renderContext undefined and throwing a TypeError on the first line of\n // Create that touched it - which is why neither buffer accessor had ever\n // run. Both faults go together.\n return this.#renderContext.CreateBuffer(description, null);\n }\n\n /**\n * Borrows a matching free resource from this pool or its outer pool,\n * allocating when necessary.\n */\n #Borrow(list, name, description, create)\n {\n const free = this.#Find(list, name, description, true);\n\n if (free) return new GpuResourceHandle(free);\n\n if (this.#outer) return this.#outer.#Borrow(list === this.#tempTextures\n ? this.#outer.#tempTextures\n : this.#outer.#tempBuffers, name, description, create);\n\n return new GpuResourceHandle(this.#Add(list, name, description, create()));\n }\n\n /** Finds a matching pool record and updates its last-access frame. */\n #Find(list, name, description, freeOnly)\n {\n const match = list.find(record =>\n record.name === name\n && SameDescription(record.description, description)\n && (!freeOnly || record.lockCount === 0));\n\n if (match) match.lastAccessFrame = this.#frame;\n\n return match ?? null;\n }\n\n /** Adds an unlocked resource record stamped with the current frame. */\n #Add(list, name, description, resource)\n {\n const record = { resource, name, description, lockCount: 0, lastAccessFrame: this.#frame };\n\n list.push(record);\n\n return record;\n }\n}\n\nfunction SameDescription(left, right)\n{\n if (left === right) return true;\n if (!left || !right) return false;\n\n const keys = new Set([ ...Object.keys(left), ...Object.keys(right) ]);\n\n for (const key of keys)\n {\n if (left[key] !== right[key]) return false;\n }\n\n return true;\n}\n\nlet globalPool = null;\n\n/**\n * Carbon's `GetGlobalGpuResourcePool`.\n *\n * @returns {Tr2GpuResourcePool} The process-wide pool.\n */\nexport function GetGlobalGpuResourcePool()\n{\n globalPool ??= new Tr2GpuResourcePool();\n\n return globalPool;\n}\n"],"names":["fail","message","error","Error","code","Tr2GpuResourcePool","constructor","outer","SetRenderContext","renderContext","SetFrame","frame","GetTempTexture","name","description","GetPersistentTexture","initialize","existing","GpuResourceHandle","texture","GetTempBuffer","GetPersistentBuffer","buffer","Free","handle","Detach","ClearUnusedResources","frameThreshold","dropped","list","index","length","record","lockCount","lastAccessFrame","resource","Destroy","splice","SetDebugMode","enable","GetDebugMode","DebugGetAllTempTextures","map","GetHeldCount","reduce","total","filter","#CreateTexture","gpuUsage","cpuUsage","msaa","initialData","dimensions","CreateTexture","Tr2BitmapDimensions","#CreateBuffer","CreateBuffer","#Borrow","create","free","#Find","freeOnly","match","find","SameDescription","#Add","push","left","right","keys","Set","Object","key","globalPool","GetGlobalGpuResourcePool"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AAKA;AACO,SAASA,IAAIA,CAACC,OAAO,EAC5B;EACE,MAAMC,KAAK,GAAG,IAAIC,KAAK,CAAC,CAAA,oBAAA,EAAuBF,OAAO,EAAE,CAAC;EACzDC,KAAK,CAACE,IAAI,GAAG,sBAAsB;AACnC,EAAA,MAAMF,KAAK;AACb;;AAEA;AACA;AACA;AAC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AAI,CAACD,IAAI,IAAI,CAACC,KAAK,EAAE,OAAO,KAAK;EAEjC,MAAMC,IAAI,GAAG,IAAIC,GAAG,CAAC,CAAE,GAAGC,MAAM,CAACF,IAAI,CAACF,IAAI,CAAC,EAAE,GAAGI,MAAM,CAACF,IAAI,CAACD,KAAK,CAAC,CAAE,CAAC;AAErE,EAAA,KAAK,MAAMI,GAAG,IAAIH,IAAI,EACtB;IACE,IAAIF,IAAI,CAACK,GAAG,CAAC,KAAKJ,KAAK,CAACI,GAAG,CAAC,EAAE,OAAO,KAAK;AAC5C,EAAA;AAEA,EAAA,OAAO,IAAI;AACb;AAEA,IAAIC,UAAU,GAAG,IAAI;;AAErB;AACA;AACA;AACA;AACA;AACO,SAASC,wBAAwBA,GACxC;AACED,EAAAA,UAAU,KAAK,IAAIpE,kBAAkB,EAAE;AAEvC,EAAA,OAAOoE,UAAU;AACnB;;;;"}
|
|
1
|
+
{"version":3,"file":"Tr2GpuResourcePool.js","sources":["../../../../../src/trinity/core/Tr2GpuResourcePool/Tr2GpuResourcePool.js"],"sourcesContent":["// Source: trinity/trinity/Tr2GpuResourcePool.h\n// Source: trinity/trinity/Tr2GpuResourcePool.cpp\n//\n// Where a render pass gets a scratch texture or buffer, and how one is kept\n// alive only as long as something holds it.\n//\n// THIS IS THE CLASS FOUR INVENTED ONES WERE STANDING IN FOR. Carbon's\n// `Tr2ShadowMap::PrepareShadowRendering( gpuResourcePool, renderContext )` and\n// the whole `EveSpaceScene` volumetrics family take a pool and do their own\n// work. Ours had the methods but bounced them to an engine-supplied executor,\n// because there was no pool to hand them. So an interface was invented per\n// subsystem rather than porting the one class they all needed.\n//\n// TWO LIFETIMES, and the distinction is the whole design. A TEMP resource is\n// recycled as soon as nothing holds it and it has not been touched for a few\n// frames; a PERSISTENT one is initialized once and kept. Asking for a temp\n// texture with the same shape twice in a frame therefore gets the same texture\n// only if the first handle has been released - which is what makes a pass able\n// to say \"give me a working surface\" without owning one.\n//\n// THE HANDLE IS THE LIFETIME. Carbon's `GpuResourceHandle` counts locks on copy\n// and release, and a record with a live lock is never recycled. JavaScript has\n// no destructor, so `Release()` is explicit here - see the note on the class.\n//\n// NESTING IS CARBON'S: a pool may have an OUTER pool, and a lookup that misses\n// walks outward. That is how a scene-local pool shares the global one's\n// resources without owning them.\n\nimport { Tr2BitmapDimensions } from \"../../../trinityal/index.js\";\nimport { GpuResourceHandle } from \"./GpuResourceHandle.js\";\n\n/** Throws a resource-pool error with the supplied diagnostic. */\nexport function fail(message)\n{\n const error = new Error(`Tr2GpuResourcePool: ${message}`);\n error.code = \"CJS_GPU_POOL_INVALID\";\n throw error;\n}\n\n/**\n * Pooled scratch textures and buffers.\n */\nexport class Tr2GpuResourcePool\n{\n /** m_outer - the pool a miss falls through to. */\n #outer = null;\n\n #tempTextures = [];\n\n #persistentTextures = [];\n\n #tempBuffers = [];\n\n #persistentBuffers = [];\n\n /** m_debugMode */\n #debugMode = false;\n\n /** The frame a lookup counts as \"now\". */\n #frame = 0;\n\n /**\n * The backend resources are created against.\n *\n * Carbon's pool is a `Tr2DeviceResource` and reaches its device that way.\n * This runtime has no process-wide device, so the context is handed in - the\n * same arrangement `Tr2EffectStateManager` uses.\n */\n #renderContext = null;\n\n /**\n * @param {Tr2GpuResourcePool} [outer] A pool to fall through to on a miss.\n */\n constructor(outer = null)\n {\n this.#outer = outer;\n }\n\n /**\n * Binds the backend resources are created against.\n *\n * @param {object} renderContext A render-context abstraction layer.\n * @returns {Tr2GpuResourcePool} This pool, for chaining.\n */\n SetRenderContext(renderContext)\n {\n this.#renderContext = renderContext;\n\n return this;\n }\n\n /**\n * Advances the pool's idea of the current frame.\n *\n * @param {number} frame The frame number.\n */\n SetFrame(frame)\n {\n this.#frame = frame;\n }\n\n /**\n * Borrows a scratch texture, creating one only if no free match exists.\n *\n * A FREE MATCH IS ONE NOBODY HOLDS. A record with a live lock is never handed\n * out again, which is what lets two passes ask for \"a 512 square\" and get\n * different surfaces when both are in flight, and the same one when they are\n * not.\n *\n * @param {string} name A debug name.\n * @param {object} description A `Tr2BitmapDimensions` shape (`type`, `width`,\n * `height`, `depth`, `mipCount`, `format`) plus `gpuUsage`, `cpuUsage`,\n * `msaa` and `initialData`.\n * @returns {GpuResourceHandle} The borrowed texture.\n */\n GetTempTexture(name, description)\n {\n return this.#Borrow(this.#tempTextures, name, description, () => this.#CreateTexture(description));\n }\n\n /**\n * Borrows a persistent texture, initializing it the first time only.\n *\n * @param {string} name A debug name.\n * @param {object} description As `GetTempTexture`.\n * @param {Function} [initialize] Called once, with the new texture.\n * @returns {GpuResourceHandle} The texture.\n */\n GetPersistentTexture(name, description, initialize = null)\n {\n const existing = this.#Find(this.#persistentTextures, name, description, false);\n\n if (existing) return new GpuResourceHandle(existing);\n\n const texture = this.#CreateTexture(description);\n\n if (initialize) initialize(texture);\n\n return new GpuResourceHandle(this.#Add(this.#persistentTextures, name, description, texture));\n }\n\n /**\n * Borrows a scratch buffer.\n *\n * @param {string} name A debug name.\n * @param {object} description A `Tr2BufferDescriptionAL`.\n * @returns {GpuResourceHandle} The borrowed buffer.\n */\n GetTempBuffer(name, description)\n {\n return this.#Borrow(this.#tempBuffers, name, description, () => this.#CreateBuffer(description));\n }\n\n /**\n * Borrows a persistent buffer, initializing it the first time only.\n *\n * @param {string} name A debug name.\n * @param {object} description A `Tr2BufferDescriptionAL`.\n * @param {Function} [initialize] Called once, with the new buffer.\n * @returns {GpuResourceHandle} The buffer.\n */\n GetPersistentBuffer(name, description, initialize = null)\n {\n const existing = this.#Find(this.#persistentBuffers, name, description, false);\n\n if (existing) return new GpuResourceHandle(existing);\n\n const buffer = this.#CreateBuffer(description);\n\n if (initialize) initialize(buffer);\n\n return new GpuResourceHandle(this.#Add(this.#persistentBuffers, name, description, buffer));\n }\n\n /**\n * Returns a borrowed resource, as Carbon's allocators do.\n *\n * @param {GpuResourceHandle} handle The handle to give back.\n * @returns {boolean} Whether a claim was dropped.\n */\n Free(handle)\n {\n if (!handle) fail(\"Free needs a handle\");\n\n return handle.Detach();\n }\n\n /**\n * Drops temp resources nobody holds and nobody has touched recently.\n *\n * @param {number} [frameThreshold] How many frames of disuse to allow.\n * @returns {number} How many resources were dropped.\n */\n ClearUnusedResources(frameThreshold = 3)\n {\n let dropped = 0;\n\n for (const list of [ this.#tempTextures, this.#tempBuffers ])\n {\n for (let index = list.length - 1; index >= 0; index -= 1)\n {\n const record = list[index];\n\n if (record.lockCount > 0) continue;\n if (this.#frame - record.lastAccessFrame < frameThreshold) continue;\n\n record.resource.Destroy();\n list.splice(index, 1);\n dropped += 1;\n }\n }\n\n return dropped;\n }\n\n /** @param {boolean} enable Whether to keep debug detail. */\n SetDebugMode(enable)\n {\n this.#debugMode = !!enable;\n }\n\n /** @returns {boolean} Whether debug mode is on. */\n GetDebugMode()\n {\n return this.#debugMode;\n }\n\n /**\n * Every temp texture the pool holds, for a caller that must assert.\n *\n * @returns {object[]} The textures.\n */\n DebugGetAllTempTextures()\n {\n return this.#tempTextures.map(record => record.resource);\n }\n\n /**\n * How many resources are currently held by a handle.\n *\n * Not Carbon's - JavaScript has no destructor to release on, so a caller\n * needs a way to prove it released what it borrowed.\n *\n * @returns {number} The count.\n */\n GetHeldCount()\n {\n return [ this.#tempTextures, this.#persistentTextures, this.#tempBuffers, this.#persistentBuffers ]\n .reduce((total, list) => total + list.filter(record => record.lockCount > 0).length, 0);\n }\n\n /** Splits the pool's flat description into the AL's two arguments. */\n #CreateTexture(description)\n {\n if (!this.#renderContext) fail(\"a pool creates against a render context; none is bound\");\n\n const { gpuUsage, cpuUsage, msaa, initialData, ...dimensions } = description;\n\n // THE CONTEXT IS THE FACTORY. This used to be `new Tr2TextureALStub()`,\n // which named the backend at authoring time: every texture the pool handed\n // out was a stub no matter which backend was bound, so a WebGPU pass would\n // have been handed textures that reach no device and drawn nothing, with\n // no error anywhere. Tr2Blitter's head comment names this exact defect.\n //\n // The dimensions spread carries type, depth and mipCount, so an array or a\n // 3D texture is expressible here and always was.\n return this.#renderContext.CreateTexture(\n new Tr2BitmapDimensions(dimensions),\n { gpuUsage, cpuUsage, msaa, initialData }\n );\n }\n\n /**\n * Creates a stub buffer from the description against the pool's render\n * context.\n */\n #CreateBuffer(description)\n {\n if (!this.#renderContext) fail(\"a pool creates against a render context; none is bound\");\n\n // Through the context for the same reason as the texture above. The\n // previous form also passed the context as `initialData`, leaving\n // renderContext undefined and throwing a TypeError on the first line of\n // Create that touched it - which is why neither buffer accessor had ever\n // run. Both faults go together.\n return this.#renderContext.CreateBuffer(description, null);\n }\n\n /**\n * Borrows a matching free resource from this pool or its outer pool,\n * allocating when necessary.\n */\n #Borrow(list, name, description, create)\n {\n const free = this.#Find(list, name, description, true);\n\n if (free) return new GpuResourceHandle(free);\n\n if (this.#outer) return this.#outer.#Borrow(list === this.#tempTextures\n ? this.#outer.#tempTextures\n : this.#outer.#tempBuffers, name, description, create);\n\n return new GpuResourceHandle(this.#Add(list, name, description, create()));\n }\n\n /** Finds a matching pool record and updates its last-access frame. */\n #Find(list, name, description, freeOnly)\n {\n const match = list.find(record =>\n record.name === name\n && SameDescription(record.description, description)\n && (!freeOnly || record.lockCount === 0));\n\n if (match) match.lastAccessFrame = this.#frame;\n\n return match ?? null;\n }\n\n /** Adds an unlocked resource record stamped with the current frame. */\n #Add(list, name, description, resource)\n {\n const record = { resource, name, description, lockCount: 0, lastAccessFrame: this.#frame };\n\n list.push(record);\n\n return record;\n }\n}\n\nfunction SameDescription(left, right)\n{\n if (left === right) return true;\n if (!left || !right) return false;\n\n const keys = new Set([ ...Object.keys(left), ...Object.keys(right) ]);\n\n for (const key of keys)\n {\n if (left[key] !== right[key]) return false;\n }\n\n return true;\n}\n\nlet globalPool = null;\n\n/**\n * Carbon's `GetGlobalGpuResourcePool`.\n *\n * @returns {Tr2GpuResourcePool} The process-wide pool.\n */\nexport function GetGlobalGpuResourcePool()\n{\n globalPool ??= new Tr2GpuResourcePool();\n\n return globalPool;\n}\n"],"names":["fail","message","error","Error","code","Tr2GpuResourcePool","constructor","outer","SetRenderContext","renderContext","SetFrame","frame","GetTempTexture","name","description","GetPersistentTexture","initialize","existing","GpuResourceHandle","texture","GetTempBuffer","GetPersistentBuffer","buffer","Free","handle","Detach","ClearUnusedResources","frameThreshold","dropped","list","index","length","record","lockCount","lastAccessFrame","resource","Destroy","splice","SetDebugMode","enable","GetDebugMode","DebugGetAllTempTextures","map","GetHeldCount","reduce","total","filter","#CreateTexture","gpuUsage","cpuUsage","msaa","initialData","dimensions","CreateTexture","Tr2BitmapDimensions","#CreateBuffer","CreateBuffer","#Borrow","create","free","#Find","freeOnly","match","find","SameDescription","#Add","push","left","right","keys","Set","Object","key","globalPool","GetGlobalGpuResourcePool"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AAKA;AACO,SAASA,IAAIA,CAACC,OAAO,EAC5B;EACE,MAAMC,KAAK,GAAG,IAAIC,KAAK,CAAC,CAAA,oBAAA,EAAuBF,OAAO,EAAE,CAAC;EACzDC,KAAK,CAACE,IAAI,GAAG,sBAAsB;AACnC,EAAA,MAAMF,KAAK;AACb;;AAEA;AACA;AACA;AACO,MAAMG,kBAAkB,CAC/B;AACE;EACA,MAAM,GAAG,IAAI;EAEb,aAAa,GAAG,EAAE;EAElB,mBAAmB,GAAG,EAAE;EAExB,YAAY,GAAG,EAAE;EAEjB,kBAAkB,GAAG,EAAE;;AAEvB;EACA,UAAU,GAAG,KAAK;;AAElB;EACA,MAAM,GAAG,CAAC;;AAEV;AACF;AACA;AACA;AACA;AACA;AACA;EACE,cAAc,GAAG,IAAI;;AAErB;AACF;AACA;AACEC,EAAAA,WAAWA,CAACC,KAAK,GAAG,IAAI,EACxB;AACE,IAAA,IAAI,CAAC,MAAM,GAAGA,KAAK;AACrB,EAAA;;AAEA;AACF;AACA;AACA;AACA;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ErB;AACA;AACA;AACA;AACA;AACO,SAASC,wBAAwBA,GACxC;AACED,EAAAA,UAAU,KAAK,IAAIpE,kBAAkB,EAAE;AAEvC,EAAA,OAAOoE,UAAU;AACnB;;;;"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { BitmapDimensions } from '#imageio';
|
|
2
|
+
import { Tr2SubresourceData } from '#trinityal';
|
|
2
3
|
import { TextureType, Tr2CpuUsage, Tr2GpuUsage, PixelFormat, PixelFormatFromCanonical } from '#consts/render-context';
|
|
3
4
|
|
|
4
5
|
// Source: trinity/trinity/Tr2ImageIOHelpers.h
|
|
@@ -29,6 +30,11 @@ const TYPE_OF_DIMENSION = Object.freeze({
|
|
|
29
30
|
/**
|
|
30
31
|
* The description and initial data a texture payload describes.
|
|
31
32
|
*
|
|
33
|
+
* TRANSITIONAL. Carbon uploads from an `ImageIO::HostBitmap`
|
|
34
|
+
* (`DescribeBitmap`), and the plain payload is ours, not Carbon's. This route
|
|
35
|
+
* stays only until every texture reader publishes a bitmap
|
|
36
|
+
* (/docs/projects/hostbitmap-port.md).
|
|
37
|
+
*
|
|
32
38
|
* @param {object} payload A `"texture"` or `"rgba"` payload.
|
|
33
39
|
* @returns {{desc: Tr2BitmapDimensions, initialData: object[]}|null} What to
|
|
34
40
|
* create, or null when the payload is not one a texture can be made from.
|
|
@@ -39,12 +45,8 @@ function DescribeTexturePayload(payload) {
|
|
|
39
45
|
if (!(payload.data instanceof Uint8Array) || payload.pixelFormat !== "rgba8unorm") return null;
|
|
40
46
|
const srgb = payload.colorSpace === "srgb";
|
|
41
47
|
return {
|
|
42
|
-
desc:
|
|
43
|
-
initialData: [
|
|
44
|
-
sysMem: payload.data,
|
|
45
|
-
sysMemPitch: payload.strideBytes ?? payload.width * 4,
|
|
46
|
-
sysMemSlicePitch: payload.data.byteLength
|
|
47
|
-
}]
|
|
48
|
+
desc: BitmapDimensions.texture2D(payload.width, payload.height, 1, srgb ? PixelFormat.PIXEL_FORMAT_R8G8B8A8_UNORM_SRGB : PixelFormat.PIXEL_FORMAT_R8G8B8A8_UNORM),
|
|
49
|
+
initialData: [new Tr2SubresourceData(payload.data, payload.strideBytes ?? payload.width * 4, payload.data.byteLength)]
|
|
48
50
|
};
|
|
49
51
|
}
|
|
50
52
|
if (payload.payloadType !== "texture") return null;
|
|
@@ -62,7 +64,7 @@ function DescribeTexturePayload(payload) {
|
|
|
62
64
|
// grey disc on a polished hull, which is a long way from an array count.
|
|
63
65
|
const faces = payload.dimension === "cube" ? Math.max(1, payload.faces | 0) : 1;
|
|
64
66
|
const arraySize = payload.dimension === "3d" ? 1 : Math.max(1, payload.arraySize | 0) * faces;
|
|
65
|
-
const desc = new
|
|
67
|
+
const desc = new BitmapDimensions({
|
|
66
68
|
type,
|
|
67
69
|
format,
|
|
68
70
|
width: payload.width,
|
|
@@ -77,11 +79,7 @@ function DescribeTexturePayload(payload) {
|
|
|
77
79
|
for (const subresource of payload.subresources ?? []) {
|
|
78
80
|
const index = (subresource.mip | 0) + (subresource.layer | 0) * mipCount;
|
|
79
81
|
if (index < 0 || index >= initialData.length) continue;
|
|
80
|
-
initialData[index] =
|
|
81
|
-
sysMem: payload.data.subarray(subresource.offset, subresource.offset + subresource.byteLength),
|
|
82
|
-
sysMemPitch: subresource.rowPitch,
|
|
83
|
-
sysMemSlicePitch: subresource.slicePitch
|
|
84
|
-
};
|
|
82
|
+
initialData[index] = new Tr2SubresourceData(payload.data.subarray(subresource.offset, subresource.offset + subresource.byteLength), subresource.rowPitch, subresource.slicePitch);
|
|
85
83
|
}
|
|
86
84
|
return {
|
|
87
85
|
desc,
|
|
@@ -89,6 +87,70 @@ function DescribeTexturePayload(payload) {
|
|
|
89
87
|
};
|
|
90
88
|
}
|
|
91
89
|
|
|
90
|
+
/**
|
|
91
|
+
* The description and initial data a HostBitmap describes: Carbon's own
|
|
92
|
+
* `CreateTexture` loop (`Tr2ImageIOHelpers.cpp:104-128`), one
|
|
93
|
+
* `Tr2SubresourceData` per (mip, layer) indexed `i + j * trueMipCount`.
|
|
94
|
+
*
|
|
95
|
+
* @param {import("#imageio").HostBitmap} bitmap A valid bitmap.
|
|
96
|
+
* @returns {{desc: Tr2BitmapDimensions, initialData: object[], memoryUse: number}|null}
|
|
97
|
+
* What to create, or null when the bitmap cannot be uploaded.
|
|
98
|
+
*/
|
|
99
|
+
function DescribeBitmap(bitmap) {
|
|
100
|
+
if (!bitmap || !bitmap.IsValid()) return null;
|
|
101
|
+
const mipCount = bitmap.GetTrueMipCount();
|
|
102
|
+
const arraySize = bitmap.GetArraySize();
|
|
103
|
+
const initialData = new Array(mipCount * arraySize);
|
|
104
|
+
let memoryUse = 0;
|
|
105
|
+
for (let layer = 0; layer < arraySize; ++layer) {
|
|
106
|
+
for (let mip = 0; mip < mipCount; ++mip) {
|
|
107
|
+
const sysMem = bitmap.GetMipRawData(mip, layer);
|
|
108
|
+
if (!sysMem) return null;
|
|
109
|
+
const sysMemSlicePitch = bitmap.GetMipSize(mip);
|
|
110
|
+
initialData[mip + layer * mipCount] = new Tr2SubresourceData(sysMem, bitmap.GetMipPitch(mip), sysMemSlicePitch);
|
|
111
|
+
memoryUse += sysMemSlicePitch;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
return {
|
|
115
|
+
desc: new BitmapDimensions({
|
|
116
|
+
type: bitmap.GetType(),
|
|
117
|
+
format: bitmap.GetFormat(),
|
|
118
|
+
width: bitmap.GetWidth(),
|
|
119
|
+
height: bitmap.GetHeight(),
|
|
120
|
+
depth: bitmap.GetDepth(),
|
|
121
|
+
mipCount,
|
|
122
|
+
arraySize
|
|
123
|
+
}),
|
|
124
|
+
initialData,
|
|
125
|
+
memoryUse
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Carbon's `Tr2ImageIOHelpers::CreateTexture( bitmap, out, memoryUse, ctx,
|
|
131
|
+
* USAGE_IMMUTABLE )` (`Tr2ImageIOHelpers.cpp:93-128`): shader-resource usage,
|
|
132
|
+
* CPU read, every mip supplied at creation.
|
|
133
|
+
*
|
|
134
|
+
* adapted: Carbon fills an out-param texture and an out-param memoryUse and
|
|
135
|
+
* returns a bool; this returns the texture, or null.
|
|
136
|
+
*
|
|
137
|
+
* @param {import("#imageio").HostBitmap} bitmap The decoded bitmap.
|
|
138
|
+
* @param {object} renderContext The `Tr2RenderContext` to create through.
|
|
139
|
+
* @param {string} [name] Debug name for the texture.
|
|
140
|
+
* @returns {object|null} A `Tr2TextureAL`, or null.
|
|
141
|
+
*/
|
|
142
|
+
function CreateTextureFromBitmap(bitmap, renderContext, name = "") {
|
|
143
|
+
const described = DescribeBitmap(bitmap);
|
|
144
|
+
if (!described || !renderContext) return null;
|
|
145
|
+
const texture = renderContext.CreateTexture(described.desc, {
|
|
146
|
+
gpuUsage: Tr2GpuUsage.SHADER_RESOURCE,
|
|
147
|
+
cpuUsage: Tr2CpuUsage.READ,
|
|
148
|
+
initialData: described.initialData
|
|
149
|
+
});
|
|
150
|
+
if (texture && name) texture.SetName(name);
|
|
151
|
+
return texture;
|
|
152
|
+
}
|
|
153
|
+
|
|
92
154
|
/**
|
|
93
155
|
* Creates the running backend's texture from a prepared texture resource.
|
|
94
156
|
*
|
|
@@ -100,6 +162,8 @@ function DescribeTexturePayload(payload) {
|
|
|
100
162
|
* @returns {object|null} A `Tr2TextureAL`, or null when nothing could be made.
|
|
101
163
|
*/
|
|
102
164
|
function CreateTexture(resource, renderContext) {
|
|
165
|
+
const bitmap = resource.GetBitmap();
|
|
166
|
+
if (bitmap) return CreateTextureFromBitmap(bitmap, renderContext, resource.GetPath() || resource.name || "TriTextureRes");
|
|
103
167
|
const described = DescribeTexturePayload(resource.GetPayload());
|
|
104
168
|
if (!described) return null;
|
|
105
169
|
const texture = renderContext.CreateTexture(described.desc, {
|
|
@@ -117,19 +181,18 @@ function CreateTexture(resource, renderContext) {
|
|
|
117
181
|
* This is `TriTextureRes::DoPrepare`'s creation step (`TriTextureRes.cpp:690-704`)
|
|
118
182
|
* moved to the first bind, for the reason in the head note.
|
|
119
183
|
*
|
|
120
|
-
* @param {object} resource A `TriTextureRes
|
|
184
|
+
* @param {object} resource A `TriTextureRes`.
|
|
121
185
|
* @param {object} renderContext The `Tr2RenderContext` to create through.
|
|
122
186
|
* @returns {object|null} The texture, or null while the resource is not ready.
|
|
123
187
|
*/
|
|
124
188
|
function RealizeTexture(resource, renderContext) {
|
|
125
|
-
if (!resource || typeof resource.GetTexture !== "function") return null;
|
|
126
189
|
const existing = resource.GetTexture();
|
|
127
190
|
if (existing) return existing;
|
|
128
|
-
if (!renderContext ||
|
|
191
|
+
if (!renderContext || !resource.IsPrepared()) return null;
|
|
129
192
|
const texture = CreateTexture(resource, renderContext);
|
|
130
193
|
if (texture) resource.SetTexture(texture);
|
|
131
194
|
return texture;
|
|
132
195
|
}
|
|
133
196
|
|
|
134
|
-
export { CreateTexture, DescribeTexturePayload, RealizeTexture };
|
|
197
|
+
export { CreateTexture, CreateTextureFromBitmap, DescribeBitmap, DescribeTexturePayload, RealizeTexture };
|
|
135
198
|
//# sourceMappingURL=Tr2ImageIOHelpers.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Tr2ImageIOHelpers.js","sources":["../../../../src/trinity/core/Tr2ImageIOHelpers.js"],"sourcesContent":["// Source: trinity/trinity/Tr2ImageIOHelpers.h\n// trinity/trinity/Tr2ImageIOHelpers.cpp:47-145\n// trinity/trinity/Resources/TriTextureRes.cpp:662-705 (DoPrepare)\n//\n// Carbon's bridge from a decoded bitmap to a `Tr2TextureAL`: `CreateTexture`\n// builds one `Tr2SubresourceData` per (mip, layer), indexed\n// `mip + layer * mipCount`, and calls the texture's `Create` with them as\n// initial data (`Tr2ImageIOHelpers.cpp:104-128`). The texture resource calls it\n// from `DoPrepare` on the main thread through `USE_MAIN_THREAD_RENDER_CONTEXT`\n// and stores the result with `SetTexture` (`TriTextureRes.cpp:690-704`).\n//\n// WHERE OURS DIFFERS, AND WHY. The resource layer cannot reach a render\n// context - `layers.json` forbids it - so the texture is made the first time a\n// PREPARED resource is bound, through the context that binds it, and stored on\n// the resource exactly where Carbon stores it. A resource not yet prepared\n// yields null, and the parameter binds Carbon's fallback instead.\nimport { Tr2BitmapDimensions } from \"../../trinityal/Tr2BitmapDimensions.js\";\nimport { PixelFormat, PixelFormatFromCanonical, TextureType, Tr2CpuUsage, Tr2GpuUsage } from \"#consts/render-context\";\n\n\n/** The payload's `dimension` to Carbon's texture type. */\nconst TYPE_OF_DIMENSION = Object.freeze({\n \"2d\": TextureType.TEX_TYPE_2D,\n \"array\": TextureType.TEX_TYPE_2D,\n \"cube\": TextureType.TEX_TYPE_CUBE,\n \"3d\": TextureType.TEX_TYPE_3D\n});\n\n\n/**\n * The description and initial data a texture payload describes.\n *\n * @param {object} payload A `\"texture\"` or `\"rgba\"` payload.\n * @returns {{desc: Tr2BitmapDimensions, initialData: object[]}|null} What to\n * create, or null when the payload is not one a texture can be made from.\n */\nexport function DescribeTexturePayload(payload)\n{\n if (!payload) return null;\n\n if (payload.payloadType === \"rgba\")\n {\n if (!(payload.data instanceof Uint8Array) || payload.pixelFormat !== \"rgba8unorm\") return null;\n\n const srgb = payload.colorSpace === \"srgb\";\n\n return {\n desc: Tr2BitmapDimensions.Texture2D(\n payload.width,\n payload.height,\n 1,\n srgb ? PixelFormat.PIXEL_FORMAT_R8G8B8A8_UNORM_SRGB : PixelFormat.PIXEL_FORMAT_R8G8B8A8_UNORM\n ),\n initialData: [ {\n sysMem: payload.data,\n sysMemPitch: payload.strideBytes ?? payload.width * 4,\n sysMemSlicePitch: payload.data.byteLength\n } ]\n };\n }\n\n if (payload.payloadType !== \"texture\") return null;\n\n const format = PixelFormatFromCanonical[payload.pixelFormat];\n const type = TYPE_OF_DIMENSION[payload.dimension];\n\n if (format === undefined || type === undefined) return null;\n\n const mipCount = Math.max(1, payload.mipCount | 0);\n\n // A CUBE'S LAYERS ARE ITS FACES TIMES ITS ARRAY SIZE, and reading `arraySize`\n // alone loses the six. An image reader reports a cube as `faces: 6` with\n // `arraySize: 1` - six faces of a single cube - so this described a cube one\n // layer deep, and the backend refused it: `Tr2TextureAL` checks\n // `arraySize % 6` and returns E_INVALIDARG. The slot then took the dummy, so\n // every reflection sampled a black 1x1 cube. A ship's sun came back as a dark\n // grey disc on a polished hull, which is a long way from an array count.\n const faces = payload.dimension === \"cube\" ? Math.max(1, payload.faces | 0) : 1;\n const arraySize = payload.dimension === \"3d\" ? 1 : Math.max(1, payload.arraySize | 0) * faces;\n const desc = new Tr2BitmapDimensions({\n type,\n format,\n width: payload.width,\n height: payload.height,\n depth: payload.dimension === \"3d\" ? Math.max(1, payload.depth | 0) : 1,\n mipCount,\n arraySize\n });\n const initialData = new Array(mipCount * arraySize).fill(null);\n\n // Carbon's index: `i + j * trueMipLevelCount` for mip i of layer j.\n for (const subresource of payload.subresources ?? [])\n {\n const index = (subresource.mip | 0) + (subresource.layer | 0) * mipCount;\n\n if (index < 0 || index >= initialData.length) continue;\n\n initialData[index] = {\n sysMem: payload.data.subarray(subresource.offset, subresource.offset + subresource.byteLength),\n sysMemPitch: subresource.rowPitch,\n sysMemSlicePitch: subresource.slicePitch\n };\n }\n\n return { desc, initialData };\n}\n\n\n/**\n * Creates the running backend's texture from a prepared texture resource.\n *\n * Carbon's `Tr2ImageIOHelpers::CreateTexture( bitmap, out, memoryUse, ctx,\n * USAGE_IMMUTABLE )`: shader-resource usage, CPU read, all data at creation.\n *\n * @param {object} resource A prepared `TriTextureRes`.\n * @param {object} renderContext The `Tr2RenderContext` to create through.\n * @returns {object|null} A `Tr2TextureAL`, or null when nothing could be made.\n */\nexport function CreateTexture(resource, renderContext)\n{\n const described = DescribeTexturePayload(resource.GetPayload());\n\n if (!described) return null;\n\n const texture = renderContext.CreateTexture(described.desc, {\n gpuUsage: Tr2GpuUsage.SHADER_RESOURCE,\n cpuUsage: Tr2CpuUsage.READ,\n initialData: described.initialData\n });\n\n if (texture) texture.SetName(resource.GetPath() || resource.name || \"TriTextureRes\");\n\n return texture;\n}\n\n\n/**\n * The resource's texture, made on first request once the resource is prepared.\n *\n * This is `TriTextureRes::DoPrepare`'s creation step (`TriTextureRes.cpp:690-704`)\n * moved to the first bind, for the reason in the head note.\n *\n * @param {object} resource A `TriTextureRes`, or anything else (which yields null).\n * @param {object} renderContext The `Tr2RenderContext` to create through.\n * @returns {object|null} The texture, or null while the resource is not ready.\n */\nexport function RealizeTexture(resource, renderContext)\n{\n if (!resource || typeof resource.GetTexture !== \"function\") return null;\n\n const existing = resource.GetTexture();\n\n if (existing) return existing;\n if (!renderContext || typeof resource.IsPrepared !== \"function\" || !resource.IsPrepared()) return null;\n\n const texture = CreateTexture(resource, renderContext);\n\n if (texture) resource.SetTexture(texture);\n\n return texture;\n}\n"],"names":["TYPE_OF_DIMENSION","Object","freeze","TextureType","TEX_TYPE_2D","TEX_TYPE_CUBE","TEX_TYPE_3D","DescribeTexturePayload","payload","payloadType","data","Uint8Array","pixelFormat","srgb","colorSpace","desc","Tr2BitmapDimensions","Texture2D","width","height","PixelFormat","PIXEL_FORMAT_R8G8B8A8_UNORM_SRGB","PIXEL_FORMAT_R8G8B8A8_UNORM","initialData","sysMem","sysMemPitch","strideBytes","sysMemSlicePitch","byteLength","format","PixelFormatFromCanonical","type","dimension","undefined","mipCount","Math","max","faces","arraySize","depth","Array","fill","subresource","subresources","index","mip","layer","length","subarray","offset","rowPitch","slicePitch","CreateTexture","resource","renderContext","described","GetPayload","texture","gpuUsage","Tr2GpuUsage","SHADER_RESOURCE","cpuUsage","Tr2CpuUsage","READ","SetName","GetPath","name","RealizeTexture","GetTexture","existing","IsPrepared","SetTexture"],"mappings":";;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAKA;AACA,MAAMA,iBAAiB,GAAGC,MAAM,CAACC,MAAM,CAAC;EACtC,IAAI,EAAEC,WAAW,CAACC,WAAW;EAC7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K,UAAU,IAAI,CAACjB,QAAQ,CAACiB,UAAU,EAAE,EAAE,OAAO,IAAI;AAEtG,EAAA,MAAMb,OAAO,GAAGL,aAAa,CAACC,QAAQ,EAAEC,aAAa,CAAC;AAEtD,EAAA,IAAIG,OAAO,EAAEJ,QAAQ,CAACkB,UAAU,CAACd,OAAO,CAAC;AAEzC,EAAA,OAAOA,OAAO;AAChB;;;;"}
|
|
1
|
+
{"version":3,"file":"Tr2ImageIOHelpers.js","sources":["../../../../src/trinity/core/Tr2ImageIOHelpers.js"],"sourcesContent":["// Source: trinity/trinity/Tr2ImageIOHelpers.h\n// trinity/trinity/Tr2ImageIOHelpers.cpp:47-145\n// trinity/trinity/Resources/TriTextureRes.cpp:662-705 (DoPrepare)\n//\n// Carbon's bridge from a decoded bitmap to a `Tr2TextureAL`: `CreateTexture`\n// builds one `Tr2SubresourceData` per (mip, layer), indexed\n// `mip + layer * mipCount`, and calls the texture's `Create` with them as\n// initial data (`Tr2ImageIOHelpers.cpp:104-128`). The texture resource calls it\n// from `DoPrepare` on the main thread through `USE_MAIN_THREAD_RENDER_CONTEXT`\n// and stores the result with `SetTexture` (`TriTextureRes.cpp:690-704`).\n//\n// WHERE OURS DIFFERS, AND WHY. The resource layer cannot reach a render\n// context - `layers.json` forbids it - so the texture is made the first time a\n// PREPARED resource is bound, through the context that binds it, and stored on\n// the resource exactly where Carbon stores it. A resource not yet prepared\n// yields null, and the parameter binds Carbon's fallback instead.\nimport { BitmapDimensions as Tr2BitmapDimensions } from \"#imageio\";\nimport { Tr2SubresourceData } from \"#trinityal\";\nimport { PixelFormat, PixelFormatFromCanonical, TextureType, Tr2CpuUsage, Tr2GpuUsage } from \"#consts/render-context\";\n\n\n/** The payload's `dimension` to Carbon's texture type. */\nconst TYPE_OF_DIMENSION = Object.freeze({\n \"2d\": TextureType.TEX_TYPE_2D,\n \"array\": TextureType.TEX_TYPE_2D,\n \"cube\": TextureType.TEX_TYPE_CUBE,\n \"3d\": TextureType.TEX_TYPE_3D\n});\n\n\n/**\n * The description and initial data a texture payload describes.\n *\n * TRANSITIONAL. Carbon uploads from an `ImageIO::HostBitmap`\n * (`DescribeBitmap`), and the plain payload is ours, not Carbon's. This route\n * stays only until every texture reader publishes a bitmap\n * (/docs/projects/hostbitmap-port.md).\n *\n * @param {object} payload A `\"texture\"` or `\"rgba\"` payload.\n * @returns {{desc: Tr2BitmapDimensions, initialData: object[]}|null} What to\n * create, or null when the payload is not one a texture can be made from.\n */\nexport function DescribeTexturePayload(payload)\n{\n if (!payload) return null;\n\n if (payload.payloadType === \"rgba\")\n {\n if (!(payload.data instanceof Uint8Array) || payload.pixelFormat !== \"rgba8unorm\") return null;\n\n const srgb = payload.colorSpace === \"srgb\";\n\n return {\n desc: Tr2BitmapDimensions.texture2D(\n payload.width,\n payload.height,\n 1,\n srgb ? PixelFormat.PIXEL_FORMAT_R8G8B8A8_UNORM_SRGB : PixelFormat.PIXEL_FORMAT_R8G8B8A8_UNORM\n ),\n initialData: [ new Tr2SubresourceData(\n payload.data,\n payload.strideBytes ?? payload.width * 4,\n payload.data.byteLength\n ) ]\n };\n }\n\n if (payload.payloadType !== \"texture\") return null;\n\n const format = PixelFormatFromCanonical[payload.pixelFormat];\n const type = TYPE_OF_DIMENSION[payload.dimension];\n\n if (format === undefined || type === undefined) return null;\n\n const mipCount = Math.max(1, payload.mipCount | 0);\n\n // A CUBE'S LAYERS ARE ITS FACES TIMES ITS ARRAY SIZE, and reading `arraySize`\n // alone loses the six. An image reader reports a cube as `faces: 6` with\n // `arraySize: 1` - six faces of a single cube - so this described a cube one\n // layer deep, and the backend refused it: `Tr2TextureAL` checks\n // `arraySize % 6` and returns E_INVALIDARG. The slot then took the dummy, so\n // every reflection sampled a black 1x1 cube. A ship's sun came back as a dark\n // grey disc on a polished hull, which is a long way from an array count.\n const faces = payload.dimension === \"cube\" ? Math.max(1, payload.faces | 0) : 1;\n const arraySize = payload.dimension === \"3d\" ? 1 : Math.max(1, payload.arraySize | 0) * faces;\n const desc = new Tr2BitmapDimensions({\n type,\n format,\n width: payload.width,\n height: payload.height,\n depth: payload.dimension === \"3d\" ? Math.max(1, payload.depth | 0) : 1,\n mipCount,\n arraySize\n });\n const initialData = new Array(mipCount * arraySize).fill(null);\n\n // Carbon's index: `i + j * trueMipLevelCount` for mip i of layer j.\n for (const subresource of payload.subresources ?? [])\n {\n const index = (subresource.mip | 0) + (subresource.layer | 0) * mipCount;\n\n if (index < 0 || index >= initialData.length) continue;\n\n initialData[index] = new Tr2SubresourceData(\n payload.data.subarray(subresource.offset, subresource.offset + subresource.byteLength),\n subresource.rowPitch,\n subresource.slicePitch\n );\n }\n\n return { desc, initialData };\n}\n\n\n/**\n * The description and initial data a HostBitmap describes: Carbon's own\n * `CreateTexture` loop (`Tr2ImageIOHelpers.cpp:104-128`), one\n * `Tr2SubresourceData` per (mip, layer) indexed `i + j * trueMipCount`.\n *\n * @param {import(\"#imageio\").HostBitmap} bitmap A valid bitmap.\n * @returns {{desc: Tr2BitmapDimensions, initialData: object[], memoryUse: number}|null}\n * What to create, or null when the bitmap cannot be uploaded.\n */\nexport function DescribeBitmap(bitmap)\n{\n if (!bitmap || !bitmap.IsValid()) return null;\n\n const mipCount = bitmap.GetTrueMipCount();\n const arraySize = bitmap.GetArraySize();\n const initialData = new Array(mipCount * arraySize);\n let memoryUse = 0;\n\n for (let layer = 0; layer < arraySize; ++layer)\n {\n for (let mip = 0; mip < mipCount; ++mip)\n {\n const sysMem = bitmap.GetMipRawData(mip, layer);\n\n if (!sysMem) return null;\n\n const sysMemSlicePitch = bitmap.GetMipSize(mip);\n\n initialData[mip + layer * mipCount] = new Tr2SubresourceData(sysMem, bitmap.GetMipPitch(mip), sysMemSlicePitch);\n memoryUse += sysMemSlicePitch;\n }\n }\n\n return {\n desc: new Tr2BitmapDimensions({\n type: bitmap.GetType(),\n format: bitmap.GetFormat(),\n width: bitmap.GetWidth(),\n height: bitmap.GetHeight(),\n depth: bitmap.GetDepth(),\n mipCount,\n arraySize\n }),\n initialData,\n memoryUse\n };\n}\n\n\n/**\n * Carbon's `Tr2ImageIOHelpers::CreateTexture( bitmap, out, memoryUse, ctx,\n * USAGE_IMMUTABLE )` (`Tr2ImageIOHelpers.cpp:93-128`): shader-resource usage,\n * CPU read, every mip supplied at creation.\n *\n * adapted: Carbon fills an out-param texture and an out-param memoryUse and\n * returns a bool; this returns the texture, or null.\n *\n * @param {import(\"#imageio\").HostBitmap} bitmap The decoded bitmap.\n * @param {object} renderContext The `Tr2RenderContext` to create through.\n * @param {string} [name] Debug name for the texture.\n * @returns {object|null} A `Tr2TextureAL`, or null.\n */\nexport function CreateTextureFromBitmap(bitmap, renderContext, name = \"\")\n{\n const described = DescribeBitmap(bitmap);\n\n if (!described || !renderContext) return null;\n\n const texture = renderContext.CreateTexture(described.desc, {\n gpuUsage: Tr2GpuUsage.SHADER_RESOURCE,\n cpuUsage: Tr2CpuUsage.READ,\n initialData: described.initialData\n });\n\n if (texture && name) texture.SetName(name);\n\n return texture;\n}\n\n\n/**\n * Creates the running backend's texture from a prepared texture resource.\n *\n * Carbon's `Tr2ImageIOHelpers::CreateTexture( bitmap, out, memoryUse, ctx,\n * USAGE_IMMUTABLE )`: shader-resource usage, CPU read, all data at creation.\n *\n * @param {object} resource A prepared `TriTextureRes`.\n * @param {object} renderContext The `Tr2RenderContext` to create through.\n * @returns {object|null} A `Tr2TextureAL`, or null when nothing could be made.\n */\nexport function CreateTexture(resource, renderContext)\n{\n const bitmap = resource.GetBitmap();\n\n if (bitmap) return CreateTextureFromBitmap(bitmap, renderContext, resource.GetPath() || resource.name || \"TriTextureRes\");\n\n const described = DescribeTexturePayload(resource.GetPayload());\n\n if (!described) return null;\n\n const texture = renderContext.CreateTexture(described.desc, {\n gpuUsage: Tr2GpuUsage.SHADER_RESOURCE,\n cpuUsage: Tr2CpuUsage.READ,\n initialData: described.initialData\n });\n\n if (texture) texture.SetName(resource.GetPath() || resource.name || \"TriTextureRes\");\n\n return texture;\n}\n\n\n/**\n * The resource's texture, made on first request once the resource is prepared.\n *\n * This is `TriTextureRes::DoPrepare`'s creation step (`TriTextureRes.cpp:690-704`)\n * moved to the first bind, for the reason in the head note.\n *\n * @param {object} resource A `TriTextureRes`.\n * @param {object} renderContext The `Tr2RenderContext` to create through.\n * @returns {object|null} The texture, or null while the resource is not ready.\n */\nexport function RealizeTexture(resource, renderContext)\n{\n const existing = resource.GetTexture();\n\n if (existing) return existing;\n if (!renderContext || !resource.IsPrepared()) return null;\n\n const texture = CreateTexture(resource, renderContext);\n\n if (texture) resource.SetTexture(texture);\n\n return texture;\n}\n"],"names":["TYPE_OF_DIMENSION","Object","freeze","TextureType","TEX_TYPE_2D","TEX_TYPE_CUBE","TEX_TYPE_3D","DescribeTexturePayload","payload","payloadType","data","Uint8Array","pixelFormat","srgb","colorSpace","desc","Tr2BitmapDimensions","texture2D","width","height","PixelFormat","PIXEL_FORMAT_R8G8B8A8_UNORM_SRGB","PIXEL_FORMAT_R8G8B8A8_UNORM","initialData","Tr2SubresourceData","strideBytes","byteLength","format","PixelFormatFromCanonical","type","dimension","undefined","mipCount","Math","max","faces","arraySize","depth","Array","fill","subresource","subresources","index","mip","layer","length","subarray","offset","rowPitch","slicePitch","DescribeBitmap","bitmap","IsValid","GetTrueMipCount","GetArraySize","memoryUse","sysMem","GetMipRawData","sysMemSlicePitch","GetMipSize","GetMipPitch","GetType","GetFormat","GetWidth","GetHeight","GetDepth","CreateTextureFromBitmap","renderContext","name","described","texture","CreateTexture","gpuUsage","Tr2GpuUsage","SHADER_RESOURCE","cpuUsage","Tr2CpuUsage","READ","SetName","resource","GetBitmap","GetPath","GetPayload","RealizeTexture","existing","GetTexture","IsPrepared","SetTexture"],"mappings":";;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAMA;AACA,MAAMA,iBAAiB,GAAGC,MAAM,CAACC,MAAM,CAAC;EACtC,IAAI,EAAEC,WAAW,CAACC,WA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Q,CAACE,OAAO,EAAE,IAAIF,QAAQ,CAACX,IAAI,IAAI,eAAe,CAAC;EAEzH,MAAMC,SAAS,GAAG9D,sBAAsB,CAACwE,QAAQ,CAACG,UAAU,EAAE,CAAC;AAE/D,EAAA,IAAI,CAACb,SAAS,EAAE,OAAO,IAAI;EAE3B,MAAMC,OAAO,GAAGH,aAAa,CAACI,aAAa,CAACF,SAAS,CAACtD,IAAI,EAAE;IAC1DyD,QAAQ,EAAEC,WAAW,CAACC,eAAe;IACrCC,QAAQ,EAAEC,WAAW,CAACC,IAAI;IAC1BtD,WAAW,EAAE8C,SAAS,CAAC9C;AACzB,GAAC,CAAC;AAEF,EAAA,IAAI+C,OAAO,EAAEA,OAAO,CAACQ,OAAO,CAACC,QAAQ,CAACE,OAAO,EAAE,IAAIF,QAAQ,CAACX,IAAI,IAAI,eAAe,CAAC;AAEpF,EAAA,OAAOE,OAAO;AAChB;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASa,cAAcA,CAACJ,QAAQ,EAAEZ,aAAa,EACtD;AACE,EAAA,MAAMiB,QAAQ,GAAGL,QAAQ,CAACM,UAAU,EAAE;EAEtC,IAAID,QAAQ,EAAE,OAAOA,QAAQ;EAC7B,IAAI,CAACjB,aAAa,IAAI,CAACY,QAAQ,CAACO,UAAU,EAAE,EAAE,OAAO,IAAI;AAEzD,EAAA,MAAMhB,OAAO,GAAGC,aAAa,CAACQ,QAAQ,EAAEZ,aAAa,CAAC;AAEtD,EAAA,IAAIG,OAAO,EAAES,QAAQ,CAACQ,UAAU,CAACjB,OAAO,CAAC;AAEzC,EAAA,OAAOA,OAAO;AAChB;;;;"}
|
|
@@ -2,7 +2,7 @@ import { ShaderType } from '#consts/render-context';
|
|
|
2
2
|
import { mat4 } from '#math/mat4';
|
|
3
3
|
import { vec3 } from '#math/vec3';
|
|
4
4
|
import { Failed } from '../../trinityal/ALResult.js';
|
|
5
|
-
import '
|
|
5
|
+
import '#imageio';
|
|
6
6
|
import '../../global/consts/renderContext/formats.js';
|
|
7
7
|
import '../../global/consts/renderContext/pipeline.js';
|
|
8
8
|
import '../../trinityal/Tr2DeviceResourceAL/Tr2BaseDeviceResourceAL.js';
|
|
@@ -2,6 +2,7 @@ import { identity as _identity, applyDecs2311 as _applyDecs2311 } from '../../..
|
|
|
2
2
|
import { type } from '#schema';
|
|
3
3
|
import { CjsModel } from '#model';
|
|
4
4
|
import { Tr2CpuUsage, Tr2GpuUsage } from '#consts/render-context';
|
|
5
|
+
import { HostBitmap, BitmapDimensions } from '#imageio';
|
|
5
6
|
import { Tr2TextureArrayElement } from './Tr2TextureArrayElement.js';
|
|
6
7
|
|
|
7
8
|
let _initClass, _init_elements, _init_extra_elements, _init_texture, _init_extra_texture, _init_dimensions, _init_extra_dimensions, _init_onTextureChange, _init_extra_onTextureChange, _init_increment, _init_extra_increment, _init_cpuUsage, _init_extra_cpuUsage, _init_gpuUsage, _init_extra_gpuUsage;
|
|
@@ -40,62 +41,63 @@ new class extends _identity {
|
|
|
40
41
|
|
|
41
42
|
/** m_gpuUsage (Tr2GpuUsage::Type - enum Tr2GpuUsage) */
|
|
42
43
|
gpuUsage = (_init_extra_cpuUsage(this), _init_gpuUsage(this, 16));
|
|
43
|
-
#
|
|
44
|
-
#listeners = [];
|
|
44
|
+
#listeners = (_init_extra_gpuUsage(this), []);
|
|
45
45
|
#revision = 0;
|
|
46
46
|
|
|
47
47
|
/**
|
|
48
48
|
* Pins the dimension gate before the first element arrives
|
|
49
|
-
* (
|
|
49
|
+
* (Tr2TextureArray.cpp:9-15): ignored once a texture exists.
|
|
50
50
|
*
|
|
51
|
-
* @param {
|
|
51
|
+
* @param {BitmapDimensions} dimensions The dimensions every element must have.
|
|
52
52
|
*/
|
|
53
53
|
SetExpectedElementDimensions(dimensions) {
|
|
54
|
-
this
|
|
55
|
-
|
|
54
|
+
if (this.texture) return;
|
|
55
|
+
this.dimensions = dimensions;
|
|
56
56
|
}
|
|
57
57
|
|
|
58
58
|
/**
|
|
59
|
-
* Adds one element (Tr2TextureArray.cpp:18-79)
|
|
59
|
+
* Adds one element (Tr2TextureArray.cpp:18-79).
|
|
60
60
|
*
|
|
61
|
-
* Carbon's dimension gate REJECTS
|
|
62
|
-
* height, depth or mip count differs from the array's - silently,
|
|
63
|
-
* invalid handle - which is
|
|
64
|
-
*
|
|
65
|
-
*
|
|
66
|
-
* of `increment` (16). The GPU texture rebuild (cpp:66-72, CreateTexture)
|
|
67
|
-
* is the abstraction layer's job; this side bumps the revision and
|
|
68
|
-
* notifies listeners, matching m_onTextureChange.
|
|
61
|
+
* Carbon's dimension gate REJECTS a bitmap whose type, format, width,
|
|
62
|
+
* height, depth or true mip count differs from the array's - silently, with
|
|
63
|
+
* an invalid handle - which is how a wrong-mip-count light profile fails to
|
|
64
|
+
* register. Slots are reused first-fit over released elements, the bitmap
|
|
65
|
+
* is copied in, and the array size rounds up to a multiple of `increment`.
|
|
69
66
|
*
|
|
70
|
-
*
|
|
71
|
-
*
|
|
72
|
-
*
|
|
73
|
-
*
|
|
67
|
+
* adapted: Carbon rebuilds the GPU texture here (`CreateTexture`,
|
|
68
|
+
* cpp:66-72) and fires m_onTextureChange. Trinity cannot reach a device from
|
|
69
|
+
* this class, so it bumps the revision and notifies listeners; the backend
|
|
70
|
+
* rebuilds from the elements.
|
|
71
|
+
*
|
|
72
|
+
* @param {HostBitmap} bitmap The element's bitmap.
|
|
73
|
+
* @returns {Tr2TextureArrayElement} A valid handle, or an invalid one.
|
|
74
74
|
*/
|
|
75
75
|
AddElement(bitmap) {
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
const gate = this.dimensions || this.#expectedDimensions;
|
|
80
|
-
if (gate && (gate.dimension !== described.dimension || gate.format !== described.format || gate.width !== described.width || gate.height !== described.height || gate.depth !== described.depth || gate.mipCount !== described.mipCount)) {
|
|
76
|
+
if (!bitmap || !bitmap.IsValid()) return new Tr2TextureArrayElement();
|
|
77
|
+
const gate = this.dimensions;
|
|
78
|
+
if (gate && (gate.GetType() !== bitmap.GetType() || gate.GetFormat() !== bitmap.GetFormat() || gate.GetWidth() !== bitmap.GetWidth() || gate.GetHeight() !== bitmap.GetHeight() || gate.GetDepth() !== bitmap.GetDepth() || gate.GetTrueMipCount() !== bitmap.GetTrueMipCount())) {
|
|
81
79
|
return new Tr2TextureArrayElement();
|
|
82
80
|
}
|
|
83
81
|
let index = this.elements.length;
|
|
84
82
|
for (let i = 0; i < this.elements.length; i++) {
|
|
85
|
-
if (this.elements[i]
|
|
83
|
+
if (!this.elements[i].IsValid()) {
|
|
86
84
|
index = i;
|
|
87
85
|
break;
|
|
88
86
|
}
|
|
89
87
|
}
|
|
90
|
-
if (index === this.elements.length) this.elements.push(
|
|
91
|
-
this.elements[index]
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
88
|
+
if (index === this.elements.length) this.elements.push(new HostBitmap());
|
|
89
|
+
const element = this.elements[index];
|
|
90
|
+
element.CreateFromBitmapDimensions(bitmap);
|
|
91
|
+
element.GetRawData().set(bitmap.GetRawData());
|
|
92
|
+
this.dimensions = new BitmapDimensions({
|
|
93
|
+
type: bitmap.GetType(),
|
|
94
|
+
format: bitmap.GetFormat(),
|
|
95
|
+
width: bitmap.GetWidth(),
|
|
96
|
+
height: bitmap.GetHeight(),
|
|
97
|
+
depth: bitmap.GetDepth(),
|
|
98
|
+
mipCount: bitmap.GetTrueMipCount(),
|
|
97
99
|
arraySize: Math.ceil(this.elements.length / this.increment) * this.increment
|
|
98
|
-
};
|
|
100
|
+
});
|
|
99
101
|
this.#revision += 1;
|
|
100
102
|
for (const listener of this.#listeners) listener(this);
|
|
101
103
|
return new Tr2TextureArrayElement(this, index);
|
|
@@ -110,7 +112,7 @@ new class extends _identity {
|
|
|
110
112
|
*/
|
|
111
113
|
RemoveElement(index) {
|
|
112
114
|
if (index >= 0 && index < this.elements.length) {
|
|
113
|
-
this.elements[index] =
|
|
115
|
+
this.elements[index] = new HostBitmap();
|
|
114
116
|
this.#revision += 1;
|
|
115
117
|
for (const listener of this.#listeners) listener(this);
|
|
116
118
|
}
|
|
@@ -130,16 +132,18 @@ new class extends _identity {
|
|
|
130
132
|
};
|
|
131
133
|
}
|
|
132
134
|
|
|
133
|
-
/**
|
|
135
|
+
/** An element's bitmap, or null for a released or missing slot. */
|
|
134
136
|
GetElement(index) {
|
|
135
|
-
|
|
137
|
+
const element = this.elements[index];
|
|
138
|
+
return element && element.IsValid() ? element : null;
|
|
136
139
|
}
|
|
137
140
|
|
|
138
|
-
/**
|
|
141
|
+
/**
|
|
142
|
+
* Slots in the array, released ones included - Carbon returns
|
|
143
|
+
* `m_elements.size()` (cpp:91-94).
|
|
144
|
+
*/
|
|
139
145
|
GetElementCount() {
|
|
140
|
-
|
|
141
|
-
for (const element of this.elements) if (element !== null) count += 1;
|
|
142
|
-
return count;
|
|
146
|
+
return this.elements.length;
|
|
143
147
|
}
|
|
144
148
|
|
|
145
149
|
/** Current dimensions, or null before the first element. */
|
|
@@ -149,50 +153,33 @@ new class extends _identity {
|
|
|
149
153
|
|
|
150
154
|
/** Element width; 0 before the first element (Carbon cpp:101-104). */
|
|
151
155
|
GetWidth() {
|
|
152
|
-
return this.dimensions ? this.dimensions.
|
|
156
|
+
return this.dimensions ? this.dimensions.GetWidth() : 0;
|
|
153
157
|
}
|
|
154
158
|
|
|
155
159
|
/** Element height; 0 before the first element. */
|
|
156
160
|
GetHeight() {
|
|
157
|
-
return this.dimensions ? this.dimensions.
|
|
161
|
+
return this.dimensions ? this.dimensions.GetHeight() : 0;
|
|
158
162
|
}
|
|
159
163
|
|
|
160
164
|
/** Slice capacity rounded to the increment; 0 before the first element. */
|
|
161
165
|
GetArraySize() {
|
|
162
|
-
return this.dimensions ? this.dimensions.
|
|
166
|
+
return this.dimensions ? this.dimensions.GetArraySize() : 0;
|
|
163
167
|
}
|
|
164
168
|
|
|
165
169
|
/** Element pixel format, or null before the first element. */
|
|
166
170
|
GetFormat() {
|
|
167
|
-
return this.dimensions ? this.dimensions.
|
|
171
|
+
return this.dimensions ? this.dimensions.GetFormat() : null;
|
|
168
172
|
}
|
|
169
173
|
|
|
170
174
|
/** Element mip count; 0 before the first element. */
|
|
171
175
|
GetMipCount() {
|
|
172
|
-
return this.dimensions ? this.dimensions.
|
|
176
|
+
return this.dimensions ? this.dimensions.GetTrueMipCount() : 0;
|
|
173
177
|
}
|
|
174
178
|
|
|
175
179
|
/** Monotonic change counter for AL-side re-upload decisions. */
|
|
176
180
|
GetRevision() {
|
|
177
181
|
return this.#revision;
|
|
178
182
|
}
|
|
179
|
-
|
|
180
|
-
/**
|
|
181
|
-
* Normalizes a bitmap-shaped payload to the compared dimension keys.
|
|
182
|
-
*
|
|
183
|
-
* @param {object} bitmap Payload or dimensions object.
|
|
184
|
-
* @returns {object} Comparable dimension description.
|
|
185
|
-
*/
|
|
186
|
-
static describe(bitmap) {
|
|
187
|
-
return {
|
|
188
|
-
dimension: bitmap.dimension ?? "2d",
|
|
189
|
-
format: bitmap.format ?? null,
|
|
190
|
-
width: bitmap.width ?? 0,
|
|
191
|
-
height: bitmap.height ?? 0,
|
|
192
|
-
depth: bitmap.depth ?? 1,
|
|
193
|
-
mipCount: bitmap.mipCount ?? 1
|
|
194
|
-
};
|
|
195
|
-
}
|
|
196
183
|
}];
|
|
197
184
|
Tr2CpuUsage = Tr2CpuUsage;
|
|
198
185
|
Tr2GpuUsage = Tr2GpuUsage;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Tr2TextureArray.js","sources":["../../../../../src/trinity/core/Tr2TextureArray/Tr2TextureArray.js"],"sourcesContent":["// Source: trinity/trinity/Tr2TextureArray.h\n// trinity/trinity/Tr2TextureArray.cpp\n\nimport { type } from \"#schema\";\nimport { CjsModel } from \"#model\";\nimport { Tr2CpuUsage, Tr2GpuUsage } from \"#consts/render-context\";\nimport { Tr2TextureArrayElement } from \"./Tr2TextureArrayElement.js\";\n\n/** Describes a texture array's elements, dimensions, resource usage, upload increment, backing texture, and change callback. */\n@type.define({ className: \"Tr2TextureArray\", family: \"trinityCore\", purpose: \"Describes a texture array's elements, dimensions, resource usage, upload increment, backing texture, and change callback.\" })\nexport class Tr2TextureArray extends CjsModel\n{\n\n /** m_elements (std::vector<ImageIO::HostBitmap>) */\n @type.list(\"ImageIO::HostBitmap\")\n elements = [];\n\n /** m_texture (Tr2TextureAL) */\n @type.rawStruct(\"Tr2TextureAL\")\n texture = null;\n\n /** m_dimensions (Tr2BitmapDimensions) */\n @type.rawStruct(\"Tr2BitmapDimensions\")\n dimensions = null;\n\n /** m_onTextureChange (OnTextureChangeEvent) */\n @type.rawStruct(\"OnTextureChangeEvent\")\n onTextureChange = null;\n\n /** m_increment (uint32_t) */\n @type.uint32\n increment = 16;\n\n /** m_cpuUsage (Tr2CpuUsage::Type - enum Tr2CpuUsage) */\n @type.int32\n @type.enum(\"Tr2CpuUsage\")\n cpuUsage = 0;\n\n /** m_gpuUsage (Tr2GpuUsage::Type - enum Tr2GpuUsage) */\n @type.int32\n @type.enum(\"Tr2GpuUsage\")\n gpuUsage = 16;\n\n #expectedDimensions = null;\n\n #listeners = [];\n\n #revision = 0;\n\n /**\n * Pins the dimension gate before the first element arrives\n * (Carbon SetExpectedElementDimensions).\n *\n * @param {object} dimensions Bitmap-shaped dimensions.\n */\n SetExpectedElementDimensions(dimensions)\n {\n this.#expectedDimensions = dimensions ? Tr2TextureArray.describe(dimensions) : null;\n if (!this.dimensions) this.dimensions = this.#expectedDimensions;\n }\n\n /**\n * Adds one element (Tr2TextureArray.cpp:18-79), CPU description side.\n *\n * Carbon's dimension gate REJECTS any bitmap whose type, format, width,\n * height, depth or mip count differs from the array's - silently, via an\n * invalid handle - which is exactly how a wrong-mip-count light profile\n * fails to register. Slot reuse is first-fit over released elements, the\n * element data is copied in, and the array size rounds up to a multiple\n * of `increment` (16). The GPU texture rebuild (cpp:66-72, CreateTexture)\n * is the abstraction layer's job; this side bumps the revision and\n * notifies listeners, matching m_onTextureChange.\n *\n * @param {object} bitmap Element payload: format, width, height,\n * mipCount, samples (or data), with optional dimension and depth.\n * @returns {Tr2TextureArrayElement} A valid handle, or an invalid one\n * when the payload is missing or incompatible.\n */\n AddElement(bitmap)\n {\n const payload = bitmap && (bitmap.samples || bitmap.data);\n if (!payload) return new Tr2TextureArrayElement();\n\n const described = Tr2TextureArray.describe(bitmap);\n const gate = this.dimensions || this.#expectedDimensions;\n if (gate && (\n gate.dimension !== described.dimension\n || gate.format !== described.format\n || gate.width !== described.width\n || gate.height !== described.height\n || gate.depth !== described.depth\n || gate.mipCount !== described.mipCount))\n {\n return new Tr2TextureArrayElement();\n }\n\n let index = this.elements.length;\n for (let i = 0; i < this.elements.length; i++)\n {\n if (this.elements[i] === null)\n {\n index = i;\n break;\n }\n }\n if (index === this.elements.length) this.elements.push(null);\n\n this.elements[index] = { ...bitmap, samples: payload.slice() };\n\n this.dimensions = {\n ...described,\n arraySize: Math.ceil(this.elements.length / this.increment) * this.increment\n };\n this.#revision += 1;\n for (const listener of this.#listeners) listener(this);\n\n return new Tr2TextureArrayElement(this, index);\n }\n\n /**\n * Frees one slice (cpp:127-130): the slot becomes reusable; dimensions\n * and array size are deliberately untouched, exactly as Carbon leaves\n * the vector sized and the slot invalid.\n *\n * @param {number} index Slice index.\n */\n RemoveElement(index)\n {\n if (index >= 0 && index < this.elements.length)\n {\n this.elements[index] = null;\n this.#revision += 1;\n for (const listener of this.#listeners) listener(this);\n }\n }\n\n /**\n * Registers a texture-change listener (Carbon's OnTextureChange event).\n *\n * @param {Function} listener Called with this array after each change.\n * @returns {Function} Unsubscribe.\n */\n OnTextureChange(listener)\n {\n this.#listeners.push(listener);\n return () =>\n {\n const at = this.#listeners.indexOf(listener);\n if (at !== -1) this.#listeners.splice(at, 1);\n };\n }\n\n /** Element payload at an index, or null for a released slot. */\n GetElement(index)\n {\n return this.elements[index] ?? null;\n }\n\n /** Live (non-released) element count. */\n GetElementCount()\n {\n let count = 0;\n for (const element of this.elements) if (element !== null) count += 1;\n return count;\n }\n\n /** Current dimensions, or null before the first element. */\n GetDimensions()\n {\n return this.dimensions;\n }\n\n /** Element width; 0 before the first element (Carbon cpp:101-104). */\n GetWidth()\n {\n return this.dimensions ? this.dimensions.width : 0;\n }\n\n /** Element height; 0 before the first element. */\n GetHeight()\n {\n return this.dimensions ? this.dimensions.height : 0;\n }\n\n /** Slice capacity rounded to the increment; 0 before the first element. */\n GetArraySize()\n {\n return this.dimensions ? this.dimensions.arraySize ?? 0 : 0;\n }\n\n /** Element pixel format, or null before the first element. */\n GetFormat()\n {\n return this.dimensions ? this.dimensions.format : null;\n }\n\n /** Element mip count; 0 before the first element. */\n GetMipCount()\n {\n return this.dimensions ? this.dimensions.mipCount : 0;\n }\n\n /** Monotonic change counter for AL-side re-upload decisions. */\n GetRevision()\n {\n return this.#revision;\n }\n\n /**\n * Normalizes a bitmap-shaped payload to the compared dimension keys.\n *\n * @param {object} bitmap Payload or dimensions object.\n * @returns {object} Comparable dimension description.\n */\n static describe(bitmap)\n {\n return {\n dimension: bitmap.dimension ?? \"2d\",\n format: bitmap.format ?? null,\n width: bitmap.width ?? 0,\n height: bitmap.height ?? 0,\n depth: bitmap.depth ?? 1,\n mipCount: bitmap.mipCount ?? 1\n };\n }\n\n static Tr2CpuUsage = Tr2CpuUsage;\n\n static Tr2GpuUsage = Tr2GpuUsage;\n\n}\n"],"names":["_Tr2TextureArray","_identity","Tr2TextureArray","CjsModel","e","_init_elements","_init_extra_elements","_init_texture","_init_extra_texture","_init_dimensions","_init_extra_dimensions","_init_onTextureChange","_init_extra_onTextureChange","_init_increment","_init_extra_increment","_init_cpuUsage","_init_extra_cpuUsage","_init_gpuUsage","_init_extra_gpuUsage","c","_initClass","_applyDecs","type","define","className","family","purpose","list","rawStruct","uint32","int32","enum","elements","texture","dimensions","onTextureChange","increment","cpuUsage","gpuUsage","SetExpectedElementDimensions","describe","AddElement","bitmap","payload","samples","data","Tr2TextureArrayElement","described","gate","dimension","format","width","height","depth","mipCount","index","length","i","push","slice","arraySize","Math","ceil","listener","RemoveElement","OnTextureChange","at","indexOf","splice","GetElement","GetElementCount","count","element","GetDimensions","GetWidth","GetHeight","GetArraySize","GetFormat","GetMipCount","GetRevision","Tr2CpuUsage","Tr2GpuUsage","constructor"],"mappings":";;;;;;;;AAQA;AAAA,IAAAA;AAAA,IAAA,cAAAC,SAAA,CAAA;AAAA,EAAA,QACA,MAAAC,eAAA,SACqCC,QAAQ,CAC7C;AAAA,IAAA;AAAA,MAAA,CAAA;QAAAC,CAAA,EAAA,CAAAC,cAAA,EAAAC,oBAAA,EAAAC,aAAA,EAAAC,mBAAA,EAAAC,gBAAA,EAAAC,sBAAA,EAAAC,qBAAA,EAAAC,2BAAA,EAAAC,eAAA,EAAAC,qBAAA,EAAAC,cAAA,EAAAC,oBAAA,EAAAC,cAAA,EAAAC,oBAAA,CAAA;QAAAC,CAAA,EAAA,CAAAnB,gBAAA,EAAAoB,UAAA;AAAA,OAAA,GAAAC,cAAA,CAAA,IAAA,EAAA,CAFCC,IAAI,CAACC,MAAM,CAAC;AAAEC,QAAAA,SAAS,EAAE,iBAAiB;AAAEC,QAAAA,MAAM,EAAE,aAAa;AAAEC,QAAAA,OAAO,EAAE;AAA4H,OAAC,CAAC,CAAA,EAAA,CAAA,CAKtMJ,IAAI,CAACK,IAAI,CAAC,qBAAqB,CAAC,EAAA,CAAA,EAAA,UAAA,CAAA,EAAA,CAIhCL,IAAI,CAACM,SAAS,CAAC,cAAc,CAAC,EAAA,CAAA,EAAA,SAAA,CAAA,EAAA,CAI9BN,IAAI,CAACM,SAAS,CAAC,qBAAqB,CAAC,EAAA,CAAA,EAAA,YAAA,CAAA,EAAA,CAIrCN,IAAI,CAACM,SAAS,CAAC,sBAAsB,CAAC,EAAA,CAAA,EAAA,iBAAA,CAAA,EAAA,CAAA,CAItCN,IAAI,EAAJA,IAAI,CAACO,MAAM,CAAA,EAAA,EAAA,EAAA,WAAA,CAA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AI,CAAC,SAAS;AACzB,IAAA;;AAEA;AACJ;AACA;AACA;AACA;AACA;IACI,OAAOvC,QAAQA,CAACE,MAAM,EACtB;MACI,OAAO;AACHO,QAAAA,SAAS,EAAEP,MAAM,CAACO,SAAS,IAAI,IAAI;AACnCC,QAAAA,MAAM,EAAER,MAAM,CAACQ,MAAM,IAAI,IAAI;AAC7BC,QAAAA,KAAK,EAAET,MAAM,CAACS,KAAK,IAAI,CAAC;AACxBC,QAAAA,MAAM,EAAEV,MAAM,CAACU,MAAM,IAAI,CAAC;AAC1BC,QAAAA,KAAK,EAAEX,MAAM,CAACW,KAAK,IAAI,CAAC;AACxBC,QAAAA,QAAQ,EAAEZ,MAAM,CAACY,QAAQ,IAAI;OAChC;AACL,IAAA;GAMH;AAJU0B,EAAAA,WAAW,GAAGA,WAAW;AAEzBC,EAAAA,WAAW,GAAGA,WAAW;EAACC,WAAAA,GAAA;IAAA,KAAA,CAAAlF,gBAAA,GAAAoB,UAAA,EAAA;AAAA,EAAA;AAAA,CAAA,EAAA;;;;"}
|
|
1
|
+
{"version":3,"file":"Tr2TextureArray.js","sources":["../../../../../src/trinity/core/Tr2TextureArray/Tr2TextureArray.js"],"sourcesContent":["// Source: trinity/trinity/Tr2TextureArray.h\n// trinity/trinity/Tr2TextureArray.cpp\n\nimport { type } from \"#schema\";\nimport { CjsModel } from \"#model\";\nimport { Tr2CpuUsage, Tr2GpuUsage } from \"#consts/render-context\";\nimport { BitmapDimensions, HostBitmap } from \"#imageio\";\nimport { Tr2TextureArrayElement } from \"./Tr2TextureArrayElement.js\";\n\n/** Describes a texture array's elements, dimensions, resource usage, upload increment, backing texture, and change callback. */\n@type.define({ className: \"Tr2TextureArray\", family: \"trinityCore\", purpose: \"Describes a texture array's elements, dimensions, resource usage, upload increment, backing texture, and change callback.\" })\nexport class Tr2TextureArray extends CjsModel\n{\n\n /** m_elements (std::vector<ImageIO::HostBitmap>) */\n @type.list(\"ImageIO::HostBitmap\")\n elements = [];\n\n /** m_texture (Tr2TextureAL) */\n @type.rawStruct(\"Tr2TextureAL\")\n texture = null;\n\n /** m_dimensions (Tr2BitmapDimensions) */\n @type.rawStruct(\"Tr2BitmapDimensions\")\n dimensions = null;\n\n /** m_onTextureChange (OnTextureChangeEvent) */\n @type.rawStruct(\"OnTextureChangeEvent\")\n onTextureChange = null;\n\n /** m_increment (uint32_t) */\n @type.uint32\n increment = 16;\n\n /** m_cpuUsage (Tr2CpuUsage::Type - enum Tr2CpuUsage) */\n @type.int32\n @type.enum(\"Tr2CpuUsage\")\n cpuUsage = 0;\n\n /** m_gpuUsage (Tr2GpuUsage::Type - enum Tr2GpuUsage) */\n @type.int32\n @type.enum(\"Tr2GpuUsage\")\n gpuUsage = 16;\n\n\n #listeners = [];\n\n #revision = 0;\n\n /**\n * Pins the dimension gate before the first element arrives\n * (Tr2TextureArray.cpp:9-15): ignored once a texture exists.\n *\n * @param {BitmapDimensions} dimensions The dimensions every element must have.\n */\n SetExpectedElementDimensions(dimensions)\n {\n if (this.texture) return;\n this.dimensions = dimensions;\n }\n\n /**\n * Adds one element (Tr2TextureArray.cpp:18-79).\n *\n * Carbon's dimension gate REJECTS a bitmap whose type, format, width,\n * height, depth or true mip count differs from the array's - silently, with\n * an invalid handle - which is how a wrong-mip-count light profile fails to\n * register. Slots are reused first-fit over released elements, the bitmap\n * is copied in, and the array size rounds up to a multiple of `increment`.\n *\n * adapted: Carbon rebuilds the GPU texture here (`CreateTexture`,\n * cpp:66-72) and fires m_onTextureChange. Trinity cannot reach a device from\n * this class, so it bumps the revision and notifies listeners; the backend\n * rebuilds from the elements.\n *\n * @param {HostBitmap} bitmap The element's bitmap.\n * @returns {Tr2TextureArrayElement} A valid handle, or an invalid one.\n */\n AddElement(bitmap)\n {\n if (!bitmap || !bitmap.IsValid()) return new Tr2TextureArrayElement();\n\n const gate = this.dimensions;\n if (gate && (\n gate.GetType() !== bitmap.GetType()\n || gate.GetFormat() !== bitmap.GetFormat()\n || gate.GetWidth() !== bitmap.GetWidth()\n || gate.GetHeight() !== bitmap.GetHeight()\n || gate.GetDepth() !== bitmap.GetDepth()\n || gate.GetTrueMipCount() !== bitmap.GetTrueMipCount()))\n {\n return new Tr2TextureArrayElement();\n }\n\n let index = this.elements.length;\n for (let i = 0; i < this.elements.length; i++)\n {\n if (!this.elements[i].IsValid())\n {\n index = i;\n break;\n }\n }\n if (index === this.elements.length) this.elements.push(new HostBitmap());\n\n const element = this.elements[index];\n element.CreateFromBitmapDimensions(bitmap);\n element.GetRawData().set(bitmap.GetRawData());\n\n this.dimensions = new BitmapDimensions({\n type: bitmap.GetType(),\n format: bitmap.GetFormat(),\n width: bitmap.GetWidth(),\n height: bitmap.GetHeight(),\n depth: bitmap.GetDepth(),\n mipCount: bitmap.GetTrueMipCount(),\n arraySize: Math.ceil(this.elements.length / this.increment) * this.increment\n });\n\n this.#revision += 1;\n for (const listener of this.#listeners) listener(this);\n return new Tr2TextureArrayElement(this, index);\n }\n\n /**\n * Frees one slice (cpp:127-130): the slot becomes reusable; dimensions\n * and array size are deliberately untouched, exactly as Carbon leaves\n * the vector sized and the slot invalid.\n *\n * @param {number} index Slice index.\n */\n RemoveElement(index)\n {\n if (index >= 0 && index < this.elements.length)\n {\n this.elements[index] = new HostBitmap();\n this.#revision += 1;\n for (const listener of this.#listeners) listener(this);\n }\n }\n\n /**\n * Registers a texture-change listener (Carbon's OnTextureChange event).\n *\n * @param {Function} listener Called with this array after each change.\n * @returns {Function} Unsubscribe.\n */\n OnTextureChange(listener)\n {\n this.#listeners.push(listener);\n return () =>\n {\n const at = this.#listeners.indexOf(listener);\n if (at !== -1) this.#listeners.splice(at, 1);\n };\n }\n\n /** An element's bitmap, or null for a released or missing slot. */\n GetElement(index)\n {\n const element = this.elements[index];\n return element && element.IsValid() ? element : null;\n }\n\n /**\n * Slots in the array, released ones included - Carbon returns\n * `m_elements.size()` (cpp:91-94).\n */\n GetElementCount()\n {\n return this.elements.length;\n }\n\n /** Current dimensions, or null before the first element. */\n GetDimensions()\n {\n return this.dimensions;\n }\n\n /** Element width; 0 before the first element (Carbon cpp:101-104). */\n GetWidth()\n {\n return this.dimensions ? this.dimensions.GetWidth() : 0;\n }\n\n /** Element height; 0 before the first element. */\n GetHeight()\n {\n return this.dimensions ? this.dimensions.GetHeight() : 0;\n }\n\n /** Slice capacity rounded to the increment; 0 before the first element. */\n GetArraySize()\n {\n return this.dimensions ? this.dimensions.GetArraySize() : 0;\n }\n\n /** Element pixel format, or null before the first element. */\n GetFormat()\n {\n return this.dimensions ? this.dimensions.GetFormat() : null;\n }\n\n /** Element mip count; 0 before the first element. */\n GetMipCount()\n {\n return this.dimensions ? this.dimensions.GetTrueMipCount() : 0;\n }\n\n /** Monotonic change counter for AL-side re-upload decisions. */\n GetRevision()\n {\n return this.#revision;\n }\n\n static Tr2CpuUsage = Tr2CpuUsage;\n\n static Tr2GpuUsage = Tr2GpuUsage;\n\n}\n"],"names":["_Tr2TextureArray","_identity","Tr2TextureArray","CjsModel","e","_init_elements","_init_extra_elements","_init_texture","_init_extra_texture","_init_dimensions","_init_extra_dimensions","_init_onTextureChange","_init_extra_onTextureChange","_init_increment","_init_extra_increment","_init_cpuUsage","_init_extra_cpuUsage","_init_gpuUsage","_init_extra_gpuUsage","c","_initClass","_applyDecs","type","define","className","family","purpose","list","rawStruct","uint32","int32","enum","elements","texture","dimensions","onTextureChange","increment","cpuUsage","gpuUsage","SetExpectedElementDimensions","AddElement","bitmap","IsValid","Tr2TextureArrayElement","gate","GetType","GetFormat","GetWidth","GetHeight","GetDepth","GetTrueMipCount","index","length","i","push","HostBitmap","element","CreateFromBitmapDimensions","GetRawData","set","BitmapDimensions","format","width","height","depth","mipCount","arraySize","Math","ceil","listener","RemoveElement","OnTextureChange","at","indexOf","splice","GetElement","GetElementCount","GetDimensions","GetArraySize","GetMipCount","GetRevision","Tr2CpuUsage","Tr2GpuUsage","constructor"],"mappings":";;;;;;;;;AASA;AAAA,IAAAA;AAAA,IAAA,cAAAC,SAAA,CAA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