From fedecdf762246e084953f4b55d791b1afd8650a7 Mon Sep 17 00:00:00 2001 From: Ib Green Date: Mon, 26 Feb 2024 11:36:48 -0500 Subject: [PATCH 1/6] chore: Enable prettier --- .prettierignore | 19 +------------------ modules/engine/src/model/model.ts | 10 +++++----- 2 files changed, 6 insertions(+), 23 deletions(-) diff --git a/.prettierignore b/.prettierignore index d26453d6b1..97b835a1cf 100644 --- a/.prettierignore +++ b/.prettierignore @@ -1,4 +1,4 @@ -**/dist*/**/*.js +**/dist workers/ *.min.js wip/ @@ -8,20 +8,3 @@ examples modules test .ocularrc.js - -# TODO(v9): Restore formatting on remainder of the codebase. -!modules/core/src/adapter/device.ts -!modules/core/src/adapter/resources/render-pipeline.ts -!modules/core/src/adapter/resources/transform-feedback.ts -!modules/core/src/adapter/types/shader-layout.ts -!modules/core/src/index.ts -!modules/engine/src/model/model.ts -!modules/engine/src/lib/shader-factory.ts -!modules/webgl/src/adapter/resources/webgl-buffer.ts -!modules/webgl/src/adapter/resources/webgl-render-pipeline.ts -!modules/webgl/src/adapter/resources/webgl-transform-feedback.ts -!modules/webgl/src/adapter/webgl-device.ts -!modules/webgl/src/index.ts -!modules/webgl/test/adapter/resources/webgl-transform-feedback.spec.ts -!modules/webgl/test/index.ts -!modules/webgpu/src/adapter/webgpu-device.ts diff --git a/modules/engine/src/model/model.ts b/modules/engine/src/model/model.ts index 56f1de6946..7921f41f41 100644 --- a/modules/engine/src/model/model.ts +++ b/modules/engine/src/model/model.ts @@ -599,11 +599,11 @@ export class Model { const fs = this.fs ? this.shaderFactory.createShader({ - id: `${this.id}-fragment`, - stage: 'fragment', - source: this.fs, - debug: this.props.debugShaders - }) + id: `${this.id}-fragment`, + stage: 'fragment', + source: this.fs, + debug: this.props.debugShaders + }) : null; this.pipeline = this.pipelineFactory.createRenderPipeline({ From 07871fdbec3477343480c3b3c28fdada597412c4 Mon Sep 17 00:00:00 2001 From: Ib Green Date: Mon, 26 Feb 2024 11:39:10 -0500 Subject: [PATCH 2/6] lint --- .ocularrc.js | 2 +- .prettierignore | 7 +- examples/api/animation/app.ts | 8 +- examples/api/animation/vite.config.ts | 6 +- examples/api/cubemap/app.ts | 14 +- examples/api/cubemap/vite.config.ts | 6 +- examples/api/texture-3d/app.ts | 8 +- examples/api/texture-3d/vite.config.ts | 6 +- examples/glfx/app.js | 293 ++++++++++-------- examples/portable/instanced-cubes/app.ts | 22 +- .../portable/instanced-cubes/vite.config.ts | 12 +- examples/portable/rotating-cube/app.ts | 19 +- .../portable/rotating-cube/vite.config.ts | 12 +- examples/portable/triangle/app.ts | 8 +- examples/portable/triangle/vite.config.ts | 12 +- examples/portable/two-cubes/app.ts | 4 +- examples/portable/two-cubes/vite.config.ts | 12 +- .../script/webgl/transform-feedback/app.ts | 10 +- .../webgl/transform-feedback/vite.config.ts | 6 +- examples/showcase/instancing/app.ts | 11 +- examples/showcase/instancing/vite.config.ts | 6 +- examples/showcase/persistence/app.ts | 6 +- examples/showcase/persistence/vite.config.ts | 6 +- examples/tutorials/hello-cube/vite.config.ts | 6 +- examples/tutorials/hello-gltf/app.ts | 2 +- examples/tutorials/hello-instancing/app.ts | 12 +- .../tutorials/hello-instancing/vite.config.ts | 6 +- examples/tutorials/hello-triangle/app.ts | 16 +- .../tutorials/hello-triangle/vite.config.ts | 6 +- examples/tutorials/lighting/app-old.ts | 2 +- examples/tutorials/lighting/app.ts | 11 +- examples/tutorials/lighting/vite.config.ts | 12 +- examples/tutorials/shader-hooks/app.ts | 9 +- .../tutorials/shader-hooks/vite.config.ts | 6 +- examples/tutorials/shader-modules/app.ts | 1 - .../tutorials/shader-modules/vite.config.ts | 6 +- examples/webgpu/compute/app.ts | 22 +- examples/webgpu/computeboids/app.ts | 58 ++-- examples/webgpu/computeboids/vite.config.ts | 12 +- examples/webgpu/textured-cube/app.ts | 8 +- examples/webgpu/textured-cube/vite.config.ts | 12 +- modules/constants/src/index.ts | 2 +- modules/constants/src/webgl-types.ts | 24 +- .../constants/test/webgl-constants.spec.ts | 4 +- modules/core-tests/src/index.ts | 2 +- .../test/adapter/canvas-context.spec.ts | 9 +- .../device-helpers/device-info.spec.ts | 2 +- .../device-helpers/device-limits.spec.ts | 2 +- .../set-device-parameters.spec.ts | 17 +- .../core-tests/test/adapter/device.spec.ts | 10 +- .../helpers/parse-shader-compiler-log.spec.ts | 42 +-- .../test/adapter/resources/buffer.spec.ts | 11 +- .../adapter/resources/command-buffer.spec.ts | 23 +- .../adapter/resources/framebuffer.spec.ts | 14 +- .../test/adapter/resources/sampler.spec.ts | 23 +- .../test/adapter/resources/shader.spec.ts | 2 +- .../test/adapter/resources/texture.spec.ts | 6 +- .../test/adapter/texture-formats.spec.ts | 4 +- .../get-attribute-from-layouts.ts | 8 +- modules/core/src/adapter/canvas-context.ts | 8 +- modules/core/src/adapter/resources/buffer.ts | 21 +- .../src/adapter/resources/command-buffer.ts | 7 +- .../src/adapter/resources/command-encoder.ts | 18 +- .../src/adapter/resources/compute-pass.ts | 2 +- .../src/adapter/resources/compute-pipeline.ts | 2 +- .../src/adapter/resources/external-texture.ts | 6 +- .../core/src/adapter/resources/framebuffer.ts | 12 +- .../core/src/adapter/resources/render-pass.ts | 17 +- .../core/src/adapter/resources/resource.ts | 18 +- modules/core/src/adapter/resources/sampler.ts | 4 +- .../src/adapter/resources/texture-view.ts | 2 +- modules/core/src/adapter/resources/texture.ts | 25 +- .../src/adapter/resources/vertex-array.ts | 2 +- .../type-utils/decode-attribute-type.ts | 29 +- .../adapter/type-utils/decode-data-type.ts | 2 +- .../adapter/type-utils/decode-shader-types.ts | 18 +- .../type-utils/decode-texture-format.ts | 29 +- .../core/src/adapter/type-utils/wgsl-utils.ts | 4 +- modules/core/src/adapter/types/accessor.ts | 2 +- .../core/src/adapter/types/buffer-layout.ts | 15 +- .../core/src/adapter/types/shader-layout.ts | 7 +- .../core/src/adapter/types/texture-formats.ts | 250 +++++++-------- modules/core/src/adapter/types/types.ts | 13 +- .../core/src/adapter/types/vertex-formats.ts | 6 +- modules/core/src/index.ts | 14 +- modules/core/src/init.ts | 10 +- .../src/lib/compiler-log/compiler-message.ts | 2 +- .../lib/compiler-log/format-compiler-log.ts | 6 +- modules/core/src/lib/luma.ts | 11 +- .../core/src/lib/uniforms/uniform-block.ts | 4 +- .../src/lib/uniforms/uniform-buffer-layout.ts | 21 +- modules/core/src/lib/uniforms/uniform.ts | 14 +- modules/core/src/types.ts | 6 +- modules/core/src/utils/array-utils-flat.ts | 9 +- modules/core/src/utils/check-props.ts | 6 +- modules/core/src/utils/format-value.ts | 7 +- modules/core/src/utils/load-file.ts | 3 +- modules/core/src/utils/stats-manager.ts | 4 +- modules/core/src/utils/stub-methods.ts | 7 +- .../get-attribute-from-layout.spec.ts | 6 +- .../core/test/adapter/canvas-context.spec.ts | 6 +- .../type-utils/decode-texture-format.spec.ts | 2 +- .../type-utils/decode-vertex-format.spec.ts | 2 +- .../vertex-format-from-attribute.spec.ts | 19 +- .../compiler-log/format-compiler-log.spec.ts | 49 +-- .../test/lib/utils/array-utils-flat.spec.ts | 4 +- .../core/test/lib/utils/format-value.spec.ts | 4 +- modules/core/test/lib/utils/uniform.spec.ts | 28 +- modules/core/test/lib/utils/utils.spec.ts | 2 +- .../animation-loop/animation-loop-template.ts | 18 +- .../src/animation-loop/animation-loop.ts | 24 +- .../src/animation-loop/animation-props.ts | 2 +- .../src/animation-loop/make-animation-loop.ts | 20 +- modules/engine/src/animation/timeline.ts | 37 ++- .../engine/src/debug/copy-texture-to-image.ts | 9 +- modules/engine/src/debug/debug-framebuffer.ts | 19 +- .../engine/src/debug/debug-shader-layout.ts | 2 +- modules/engine/src/debug/pixel-data-utils.ts | 6 +- .../engine/src/geometries/cube-geometry.ts | 30 +- .../src/geometries/ico-sphere-geometry.ts | 2 +- .../engine/src/geometries/plane-geometry.ts | 2 +- .../engine/src/geometries/sphere-geometry.ts | 2 +- .../src/geometries/truncated-cone-geometry.ts | 3 +- modules/engine/src/geometry/geometry-table.ts | 10 +- modules/engine/src/geometry/geometry-utils.ts | 2 +- modules/engine/src/geometry/geometry.ts | 10 +- modules/engine/src/geometry/gpu-geometry.ts | 20 +- modules/engine/src/lib/clip-space.ts | 32 +- modules/engine/src/model/model.ts | 19 +- modules/engine/src/scenegraph/group-node.ts | 24 +- modules/engine/src/scenegraph/model-node.ts | 4 +- .../engine/src/scenegraph/scenegraph-node.ts | 4 +- modules/engine/src/shader-inputs.ts | 26 +- .../engine/src/transform/texture-transform.ts | 24 +- .../engine/test/animation/key-frames.spec.ts | 2 +- .../engine/test/animation/timeline.spec.ts | 2 +- ...get-debug-table-from-shader-layout.spec.ts | 2 +- .../engine/test/geometry/geometries.spec.ts | 4 +- .../test/geometry/geometry-utils.spec.ts | 2 +- modules/engine/test/geometry/geometry.spec.ts | 2 +- modules/engine/test/index.ts | 1 - .../engine/test/lib/animation-loop.spec.ts | 14 +- modules/engine/test/lib/model.spec.ts | 2 - .../engine/test/lib/pipeline-factory.spec.ts | 7 +- .../engine/test/scenegraph/group-node.spec.ts | 14 +- .../engine/test/scenegraph/model-node.spec.ts | 2 +- .../test/scenegraph/scenegraph-node.spec.ts | 16 +- modules/engine/test/shader-inputs.spec.ts | 14 +- .../test/transform/buffer-transform.spec.ts | 15 +- .../test/transform/texture-transform.spec.ts | 20 +- modules/gltf/src/gltf/create-gltf-model.ts | 6 +- modules/gltf/src/gltf/gltf-animator.ts | 6 +- modules/gltf/src/gltf/gltf-instantiator.ts | 66 ++-- modules/gltf/src/index.ts | 1 - modules/gltf/src/pbr/parse-pbr-material.ts | 22 +- modules/gltf/src/pbr/pbr-environment.ts | 29 +- modules/gltf/test/gltf/gltf.spec.ts | 14 +- modules/gltf/test/index.ts | 1 - modules/shadertools/src/index.ts | 1 - .../shadertools/src/lib/filters/prop-types.ts | 57 ++-- .../src/lib/glsl-utils/shader-utils.ts | 11 +- .../shadertools/src/lib/shader-assembler.ts | 36 ++- .../lib/shader-assembly/assemble-shaders.ts | 40 ++- .../src/lib/shader-assembly/platform-info.ts | 4 +- .../lib/shader-assembly/resolve-modules.ts | 14 +- .../src/lib/shader-assembly/select-shaders.ts | 14 +- .../src/lib/shader-assembly/shader-hooks.ts | 4 +- .../lib/shader-assembly/shader-injections.ts | 22 +- .../lib/shader-generator/generate-shader.ts | 5 +- .../shader-generator/glsl/generate-glsl.ts | 25 +- .../shader-generator/wgsl/generate-wgsl.ts | 5 +- .../shader-module/shader-module-instance.ts | 10 +- .../src/lib/shader-module/shader-module.ts | 14 +- .../src/lib/shader-module/shader-pass.ts | 9 +- .../transpile-glsl-shader.ts | 5 +- .../src/lib/wgsl/get-shader-layout-wgsl.ts | 3 +- .../lighting/dirlight/dirlight.ts | 4 +- .../modules-webgl1/lighting/lights/lights.ts | 6 +- .../lighting/phong-lighting/phong-lighting.ts | 9 +- .../src/modules-webgl1/math/fp64/fp64.ts | 4 +- .../src/modules-webgl1/project/project.ts | 8 +- .../src/modules/engine/picking/picking.ts | 22 +- .../src/modules/engine/project/project.ts | 5 +- .../gouraud-material/gouraud-material.ts | 14 +- .../lighting/lights/lighting-uniforms.ts | 25 +- .../modules/lighting/no-material/dirlight.ts | 8 +- .../lighting/pbr-material/pbr-material.ts | 25 +- .../image-adjust-filters/denoise.ts | 4 +- .../image-adjust-filters/huesaturation.ts | 6 +- .../image-blur-filters/zoomblur.ts | 4 +- .../image-fun-filters/hexagonalpixelate.ts | 2 +- .../postprocessing/image-fun-filters/ink.ts | 6 +- .../image-fun-filters/magnify.ts | 6 +- modules/shadertools/src/types.ts | 53 ++-- .../lib/generator/generate-shader.spec.ts | 22 +- .../lib/glsl-utils/get-shader-info.spec.ts | 26 +- .../test/lib/glsl-utils/shader-utils.spec.ts | 20 +- .../test/lib/shader-assembler.spec.ts | 18 +- .../shader-assembly/assemble-shaders.spec.ts | 33 +- .../lib/shader-module/shader-module.spec.ts | 8 +- .../transpile-shader.spec.ts | 2 +- .../fp64/fp64-arithmetic-transform.spec.ts | 62 +++- .../fp64/fp64-test-utils-transform.ts | 16 +- .../modules-webgl1/fp64/fp64-utils.spec.ts | 6 +- .../test/modules-webgl1/lights/lights.spec.ts | 2 +- .../test/modules/engine/picking.spec.ts | 68 ++-- .../modules/lighting/gouraud-material.spec.ts | 9 +- .../modules/lighting/pbr-material.spec.ts | 2 +- .../modules/lighting/phong-material.spec.ts | 9 +- .../shadertools/test/modules/modules.spec.ts | 2 +- .../brightnesscontrast.spec.ts | 2 +- .../image-adjust-filters/denoise.spec.ts | 2 +- .../huesaturation.spec.ts | 2 +- .../image-adjust-filters/noise.spec.ts | 2 +- .../image-adjust-filters/sepia.spec.ts | 2 +- .../image-adjust-filters/vibrance.spec.ts | 2 +- .../image-adjust-filters/vignette.spec.ts | 2 +- .../image-blur-filters/tiltshift.spec.ts | 2 +- .../image-blur-filters/triangleblur.spec.ts | 2 +- .../image-blur-filters/zoomblur.spec.ts | 2 +- .../image-fun-filters/colorhalftone.spec.ts | 2 +- .../image-fun-filters/dotscreen.spec.ts | 2 +- .../image-fun-filters/edgework.spec.ts | 2 +- .../hexagonalpixelate.spec.ts | 2 +- .../image-fun-filters/ink.spec.ts | 2 +- .../image-warp-filters/bulgepinch.spec.ts | 2 +- .../image-warp-filters/swirl.spec.ts | 2 +- .../image-warp-filters/warp.spec.ts | 2 +- .../test/modules/utils/random.spec.ts | 2 +- modules/test-utils/src/create-test-device.ts | 9 +- .../src/engine/classic-animation-loop.ts | 22 +- .../test-utils/src/snapshot-test-runner.ts | 4 +- modules/test-utils/src/test-runner.ts | 18 +- modules/test-utils/src/utils/check-type.ts | 1 - modules/test-utils/src/utils/deep-copy.ts | 2 +- .../test-utils/src/utils/get-bounding-box.ts | 7 +- .../test-utils/src/utils/resource-tracker.ts | 5 +- .../adapter/converters/device-parameters.ts | 3 +- .../adapter/converters/sampler-parameters.ts | 12 +- .../src/adapter/converters/shader-formats.ts | 66 ++-- .../src/adapter/converters/vertex-formats.ts | 3 +- .../device-helpers/webgl-device-limits.ts | 2 +- .../src/adapter/helpers/decode-webgl-types.ts | 17 +- .../src/adapter/helpers/get-shader-layout.ts | 4 +- .../helpers/parse-shader-compiler-log.ts | 13 +- .../adapter/helpers/webgl-topology-utils.ts | 10 +- .../src/adapter/objects/webgl-renderbuffer.ts | 43 ++- .../src/adapter/objects/webgl-resource.ts | 6 +- .../src/adapter/resources/webgl-buffer.ts | 4 +- .../adapter/resources/webgl-command-buffer.ts | 5 +- .../resources/webgl-external-texture.ts | 2 +- .../adapter/resources/webgl-framebuffer.ts | 7 +- .../adapter/resources/webgl-render-pass.ts | 7 +- .../resources/webgl-render-pipeline.ts | 18 +- .../src/adapter/resources/webgl-shader.ts | 4 +- .../adapter/resources/webgl-texture-view.ts | 2 +- .../resources/webgl-transform-feedback.ts | 7 +- .../webgl/src/adapter/webgl-canvas-context.ts | 7 +- modules/webgl/src/classic/accessor.ts | 6 +- modules/webgl/src/classic/clear.ts | 15 +- modules/webgl/src/classic/copy-and-blit.ts | 8 +- .../webgl/src/classic/typed-array-utils.ts | 7 +- modules/webgl/src/context/debug/spector.ts | 12 +- .../context/debug/webgl-developer-tools.ts | 32 +- .../context/helpers/create-browser-context.ts | 2 +- .../parameters/webgl-parameter-tables.ts | 53 ++-- .../state-tracker/track-context-state.ts | 14 +- .../context/state-tracker/with-parameters.ts | 6 +- .../set-device-parameters.spec.ts | 28 +- .../helpers/parse-shader-compiler-log.spec.ts | 42 +-- .../helpers/webgl-topology-utils.spec.ts | 18 +- .../objects/webgl-renderbuffer.spec.ts | 21 +- .../adapter/resources/webgl-buffer.spec.ts | 6 +- .../test/adapter/webgl-canvas-context.spec.ts | 24 +- .../webgl/test/adapter/webgl-device.spec.ts | 6 +- .../state-tracker/context-state.spec.ts | 6 +- .../data/sample-enum-settings.ts | 58 ++-- .../state-tracker/deep-array-equal.spec.ts | 2 +- .../state-tracker/set-parameters.spec.ts | 46 +-- .../state-tracker/track-context-state.spec.ts | 12 +- .../src/adapter/helpers/accessor-to-format.ts | 2 +- .../src/adapter/helpers/generate-mipmaps.ts | 58 ++-- .../src/adapter/helpers/get-bind-group.ts | 5 +- .../helpers/get-vertex-buffer-layout.ts | 11 +- .../src/adapter/helpers/webgpu-parameters.ts | 90 +++++- .../src/adapter/resources/webgpu-buffer.ts | 26 +- .../adapter/resources/webgpu-compute-pass.ts | 10 +- .../resources/webgpu-compute-pipeline.ts | 20 +- .../resources/webgpu-external-texture.ts | 13 +- .../src/adapter/resources/webgpu-query.ts | 2 +- .../adapter/resources/webgpu-render-pass.ts | 8 +- .../resources/webgpu-render-pipeline.ts | 21 +- .../src/adapter/resources/webgpu-sampler.ts | 2 +- .../src/adapter/resources/webgpu-shader.ts | 6 +- .../adapter/resources/webgpu-texture-view.ts | 24 +- .../src/adapter/resources/webgpu-texture.ts | 28 +- .../adapter/resources/webgpu-vertex-array.ts | 24 +- .../src/adapter/webgpu-canvas-context.ts | 4 +- modules/webgpu/src/adapter/webgpu-device.ts | 18 +- modules/webgpu/src/glsl/glsllang.ts | 4 +- .../helpers/get-vertex-buffer-layout.spec.ts | 77 ++--- test/apps/pbr/controls.js | 8 +- test/apps/pbr/main.js | 12 +- test/apps/pbr/scene.js | 2 +- ...abel-plugin-inline-webgl-constants.spec.js | 4 +- .../babel-plugin-remove-glsl-comments.spec.js | 4 +- ...eslint-plugin-luma-gl-custom-rules.spec.js | 2 +- test/perf/index.js | 4 +- test/perf/performance-test-cases.js | 2 +- test/render/example-test-cases.ts | 8 +- test/render/render.spec.ts | 4 +- 311 files changed, 2485 insertions(+), 1873 deletions(-) diff --git a/.ocularrc.js b/.ocularrc.js index f2716e0916..71e4834505 100644 --- a/.ocularrc.js +++ b/.ocularrc.js @@ -51,4 +51,4 @@ const config = { } }; -export default config; \ No newline at end of file +export default config; diff --git a/.prettierignore b/.prettierignore index 97b835a1cf..6fa2f45e4c 100644 --- a/.prettierignore +++ b/.prettierignore @@ -2,9 +2,4 @@ workers/ *.min.js wip/ -encoding.js -encoding-indexes.js -examples -modules -test -.ocularrc.js +libs/ diff --git a/examples/api/animation/app.ts b/examples/api/animation/app.ts index c44ca523ec..ceaa121bbf 100644 --- a/examples/api/animation/app.ts +++ b/examples/api/animation/app.ts @@ -170,7 +170,6 @@ export default class AppAnimationLoopTemplate extends AnimationLoopTemplate { new KeyFrames(this.keyFrameData), new KeyFrames(this.keyFrameData) ]; - for (let i = 0; i < 4; ++i) { this.timeline.attachAnimation(keyFrames[i], channels[i]); @@ -205,10 +204,7 @@ export default class AppAnimationLoopTemplate extends AnimationLoopTemplate { }, bindings: { app: cubeUniformStore.getManagedUniformBuffer(device, 'app'), - dirlight: this.globalUniformStore.getManagedUniformBuffer( - device, - 'dirlight' - ) + dirlight: this.globalUniformStore.getManagedUniformBuffer(device, 'dirlight') } }) }; @@ -252,7 +248,7 @@ export default class AppAnimationLoopTemplate extends AnimationLoopTemplate { // Draw the cubes const renderPass = device.beginRenderPass({ - clearColor: [0, 0, 0, 1], + clearColor: [0, 0, 0, 1] // clearDepth: true }); for (const cube of this.cubes) { diff --git a/examples/api/animation/vite.config.ts b/examples/api/animation/vite.config.ts index cf1b3f316d..0eb48cdb0e 100644 --- a/examples/api/animation/vite.config.ts +++ b/examples/api/animation/vite.config.ts @@ -1,4 +1,4 @@ -import { defineConfig } from 'vite' +import {defineConfig} from 'vite'; const alias = { '@luma.gl/constants': `${__dirname}/../../../modules/constants/src`, @@ -9,10 +9,10 @@ const alias = { '@luma.gl/shadertools': `${__dirname}/../../../modules/shadertools/src`, '@luma.gl/test-utils': `${__dirname}/../../../modules/test-utils/src`, '@luma.gl/webgl': `${__dirname}/../../../modules/webgl/src` -} +}; // https://vitejs.dev/config/ export default defineConfig({ resolve: {alias}, server: {open: true} -}) +}); diff --git a/examples/api/cubemap/app.ts b/examples/api/cubemap/app.ts index 5f40361328..47c1c842a5 100644 --- a/examples/api/cubemap/app.ts +++ b/examples/api/cubemap/app.ts @@ -1,5 +1,11 @@ import {Device, loadImage, glsl} from '@luma.gl/core'; -import {AnimationLoopTemplate, AnimationProps, CubeGeometry, Model, ModelProps} from '@luma.gl/engine'; +import { + AnimationLoopTemplate, + AnimationProps, + CubeGeometry, + Model, + ModelProps +} from '@luma.gl/engine'; import {Matrix4, radians} from '@math.gl/core'; const INFO_HTML = ` @@ -131,14 +137,14 @@ export default class AppAnimationLoopTemplate extends AnimationLoopTemplate { }, parameters: { depthWriteEnabled: true, - depthCompare: 'less-equal' + depthCompare: 'less-equal' } }); this.prism = new Prism(device, { bindings: { uTexture: texture, - uTextureCube: cubemap, + uTextureCube: cubemap }, parameters: { depthWriteEnabled: true, @@ -149,7 +155,7 @@ export default class AppAnimationLoopTemplate extends AnimationLoopTemplate { onFinalize(): void { this.prism.destroy(); - this.cube.destroy(); + this.cube.destroy(); } onRender({device, aspect, tick}: AnimationProps): void { diff --git a/examples/api/cubemap/vite.config.ts b/examples/api/cubemap/vite.config.ts index 74b76edb7f..43053081f0 100644 --- a/examples/api/cubemap/vite.config.ts +++ b/examples/api/cubemap/vite.config.ts @@ -1,4 +1,4 @@ -import { defineConfig } from 'vite' +import {defineConfig} from 'vite'; const alias = { '@luma.gl/constants': `${__dirname}/../../../modules/constants/src`, @@ -9,10 +9,10 @@ const alias = { '@luma.gl/shadertools': `${__dirname}/../../../modules/shadertools/src`, '@luma.gl/test-utils': `${__dirname}/../../../modules/test-utils/src`, '@luma.gl/webgl': `${__dirname}/../../../modules/webgl/src` -} +}; // https://vitejs.dev/config/ export default defineConfig({ resolve: {alias}, server: {open: true} -}) +}); diff --git a/examples/api/texture-3d/app.ts b/examples/api/texture-3d/app.ts index 04d6874fe0..d4a512ef81 100644 --- a/examples/api/texture-3d/app.ts +++ b/examples/api/texture-3d/app.ts @@ -53,7 +53,7 @@ export default class AppAnimationLoopTemplate extends AnimationLoopTemplate { constructor({device}: AnimationProps) { super(); - + const noise = perlin({ interpolation: lerp, permutation: shuffle(range(0, 255), random) @@ -148,11 +148,13 @@ export default class AppAnimationLoopTemplate extends AnimationLoopTemplate { } onRender({device, tick, aspect}: AnimationProps) { - this.mvpMat.perspective({fovy: radians(75), aspect, near: NEAR, far: FAR}).multiplyRight(this.viewMat); + this.mvpMat + .perspective({fovy: radians(75), aspect, near: NEAR, far: FAR}) + .multiplyRight(this.viewMat); // Draw the cubes const renderPass = device.beginRenderPass({ - clearColor: [0, 0, 0, 1], + clearColor: [0, 0, 0, 1] // clearDepth: true }); this.cloud.setUniforms({ diff --git a/examples/api/texture-3d/vite.config.ts b/examples/api/texture-3d/vite.config.ts index 74b76edb7f..43053081f0 100644 --- a/examples/api/texture-3d/vite.config.ts +++ b/examples/api/texture-3d/vite.config.ts @@ -1,4 +1,4 @@ -import { defineConfig } from 'vite' +import {defineConfig} from 'vite'; const alias = { '@luma.gl/constants': `${__dirname}/../../../modules/constants/src`, @@ -9,10 +9,10 @@ const alias = { '@luma.gl/shadertools': `${__dirname}/../../../modules/shadertools/src`, '@luma.gl/test-utils': `${__dirname}/../../../modules/test-utils/src`, '@luma.gl/webgl': `${__dirname}/../../../modules/webgl/src` -} +}; // https://vitejs.dev/config/ export default defineConfig({ resolve: {alias}, server: {open: true} -}) +}); diff --git a/examples/glfx/app.js b/examples/glfx/app.js index d08765e6e0..17d369eb51 100644 --- a/examples/glfx/app.js +++ b/examples/glfx/app.js @@ -41,29 +41,35 @@ function loadImage(src) { function showDialog() { $('#fade').fadeIn(); - $('#dialog').show().css({ - top: -$('#dialog').outerHeight() - }).animate({ - top: 0 - }); + $('#dialog') + .show() + .css({ + top: -$('#dialog').outerHeight() + }) + .animate({ + top: 0 + }); } function hideDialog() { $('#fade').fadeOut(); - $('#dialog').animate({ - top: -$('#dialog').outerHeight() - }, function() { - $('#dialog').hide(); - }); + $('#dialog').animate( + { + top: -$('#dialog').outerHeight() + }, + function () { + $('#dialog').hide(); + } + ); } function contractItem(item) { - $(item).removeClass('active').animate({ paddingTop: 0 }); + $(item).removeClass('active').animate({paddingTop: 0}); $(item).children('.contents').slideUp(); } function expandItem(item) { - $(item).addClass('active').animate({ paddingTop: 10 }); + $(item).addClass('active').animate({paddingTop: 10}); $(item).children('.contents').slideDown(); } @@ -85,7 +91,10 @@ function setSelectedFilter(filter) { // Reset all curves for (let i = 0; i < filter.curves.length; i++) { var curves = filter.curves[i]; - filter.values[curves.name] = [[0, 0], [1, 1]]; + filter.values[curves.name] = [ + [0, 0], + [1, 1] + ]; curves.draw(); } @@ -101,20 +110,24 @@ function setSelectedFilter(filter) { var x = nub.x * canvas.width; var y = nub.y * canvas.height; $('
').appendTo('#nubs'); - var ondrag = (function(nub) { return function(event, ui) { - var offset = $(event.target.parentNode).offset(); - var height = event.target.parentNode.clientHeight; - filter.values[nub.name] = [ - ui.offset.left - offset.left, - height - (ui.offset.top - offset.top) - ]; - filter.update(); - }; })(nub); - $('#nub' + i).draggable({ - drag: ondrag, - containment: 'parent', - scroll: false - }).css({ left: x, top: y }); + var ondrag = (function (nub) { + return function (event, ui) { + var offset = $(event.target.parentNode).offset(); + var height = event.target.parentNode.clientHeight; + filter.values[nub.name] = [ + ui.offset.left - offset.left, + height - (ui.offset.top - offset.top) + ]; + filter.update(); + }; + })(nub); + $('#nub' + i) + .draggable({ + drag: ondrag, + containment: 'parent', + scroll: false + }) + .css({left: x, top: y}); filter.values[nub.name] = [x, y]; } @@ -150,7 +163,7 @@ function init(image) { $('#loading').hide(); } -$(window).load(function() { +$(window).load(function () { // Try to get a WebGL canvas if (!window.luma) { $('#loading') @@ -167,9 +180,7 @@ $(window).load(function() { Getting a WebGL implementation .

${error}`; - $('#loading') - .css('visibility', 'visible') - .html(message); + $('#loading').css('visibility', 'visible').html(message); return; } canvas2d = $('#canvas2d')[0]; @@ -182,18 +193,35 @@ $(window).load(function() { var filter = filters[category][i]; // Generate the HTML for the controls - var html = '
' + filter.name + '
'; + var html = + '
' + + filter.name + + '
'; for (var j = 0; j < filter.sliders.length; j++) { var slider = filter.sliders[j]; slider.id = 'control' + nextID++; - html += ''; + html += + ''; } for (var j = 0; j < filter.segmented.length; j++) { var segmented = filter.segmented[j]; segmented.id = 'control' + nextID++; html += ''; } @@ -208,10 +236,12 @@ $(window).load(function() { item.filter = filter; // Add reset button - (function(filter) { - $(item).find('.reset').click(function() { - setSelectedFilter(filter); - }); + (function (filter) { + $(item) + .find('.reset') + .click(function () { + setSelectedFilter(filter); + }); })(filter); // Make segmented controls @@ -219,13 +249,19 @@ $(window).load(function() { var segmented = filter.segmented[j]; filter[segmented.name] = segmented.initial; for (var k = 0; k < segmented.labels.length; k++) { - $('#' + segmented.id + '-' + k).mousedown((function(filter, segmented, index) { return function() { - filter[segmented.name] = index; - for (var k = 0; k < segmented.labels.length; k++) { - $('#' + segmented.id + '-' + k)[index == k ? 'addClass' : 'removeClass']('selected'); - } - filter.update(); - }; })(filter, segmented, k)); + $('#' + segmented.id + '-' + k).mousedown( + (function (filter, segmented, index) { + return function () { + filter[segmented.name] = index; + for (var k = 0; k < segmented.labels.length; k++) { + $('#' + segmented.id + '-' + k)[index == k ? 'addClass' : 'removeClass']( + 'selected' + ); + } + filter.update(); + }; + })(filter, segmented, k) + ); } } @@ -240,11 +276,11 @@ $(window).load(function() { // Set up curves for (var j = 0; j < filter.curves.length; j++) { var curves = filter.curves[j]; - (function(curves, filter) { + (function (curves, filter) { var canvas = $('#' + curves.id)[0]; var c = canvas.getContext('2d'); - var w = canvas.width = $(canvas).width(); - var h = canvas.height = $(canvas).height(); + var w = (canvas.width = $(canvas).width()); + var h = (canvas.height = $(canvas).height()); var start = 0; var end = 1; @@ -267,17 +303,17 @@ $(window).load(function() { } if (!foundStart) points.push([0, start]); if (!foundEnd) points.push([1, end]); - }; + } // Render the curves to the canvas - curves.draw = function() { + curves.draw = function () { var points = filter.values[curves.name]; var map = luma.filters.splineInterpolate(points); c.clearRect(0, 0, w, h); c.strokeStyle = '#4B4947'; c.beginPath(); for (let i = 0; i < map.length; i++) { - c.lineTo(i / map.length * w, (1 - map[i] / 255) * h); + c.lineTo((i / map.length) * w, (1 - map[i] / 255) * h); } c.stroke(); c.fillStyle = 'white'; @@ -299,7 +335,7 @@ $(window).load(function() { return [x, y]; } - $(canvas).mousedown(function(e) { + $(canvas).mousedown(function (e) { var points = filter.values[curves.name]; point = getMouse(e); for (let i = 0; i < points.length; i++) { @@ -320,7 +356,7 @@ $(window).load(function() { filter.update(); }); - $(document).mousemove(function(e) { + $(document).mousemove(function (e) { if (dragging) { var p = getMouse(e); point[0] = p[0]; @@ -330,12 +366,15 @@ $(window).load(function() { filter.update(); } }); - $(document).mouseup(function() { + $(document).mouseup(function () { dragging = false; }); // Set the initial curves - filter.values[curves.name] = [[0, 0], [1, 1]]; + filter.values[curves.name] = [ + [0, 0], + [1, 1] + ]; curves.draw(); })(curves, filter); } @@ -344,10 +383,12 @@ $(window).load(function() { for (var j = 0; j < filter.sliders.length; j++) { var slider = filter.sliders[j]; filter.values[slider.name] = slider.value; - var onchange = (function(filter, slider) { return function(event, ui) { - filter.values[slider.name] = ui.value; - if (selectedFilter == filter) filter.update(); - }; })(filter, slider); + var onchange = (function (filter, slider) { + return function (event, ui) { + filter.values[slider.name] = ui.value; + if (selectedFilter == filter) filter.update(); + }; + })(filter, slider); $('#' + slider.id).slider({ slide: onchange, change: onchange, @@ -361,7 +402,7 @@ $(window).load(function() { } // Change the filter when a sidebar item is clicked - $('#sidebar .item .title').live('mousedown', function(e) { + $('#sidebar .item .title').live('mousedown', function (e) { var item = e.target.parentNode; if (selectedItem) contractItem(selectedItem); if (selectedItem != item) { @@ -375,7 +416,7 @@ $(window).load(function() { }); // Update texture with canvas contents when a filter is accepted - $('.accept').live('click', function() { + $('.accept').live('click', function () { contractItem(selectedItem); texture.destroy(); texture = canvas.contents(); @@ -384,57 +425,63 @@ $(window).load(function() { }); // Hook up toolbar buttons - $('#load').click(function() { - $('#dialog').html('
Pick one of the sample images below or upload an image of your own:
' + - '' + - '' + - '' + - '' + - '' + - '' + - '' + - '' + - '
Flickr image credits in order: ' + - 'matthigh, ' + - 'delosj, ' + - 'stuckincustoms, ' + - 'pasma, ' + - 'delosj, ' + - 'seriousbri, ' + - 'melisande-origami, and ' + - 'stuckincustoms' + - '
' + - '
Upload File...
' + - '
Cancel
'); + $('#load').click(function () { + $('#dialog').html( + '
Pick one of the sample images below or upload an image of your own:
' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '
Flickr image credits in order: ' + + 'matthigh, ' + + 'delosj, ' + + 'stuckincustoms, ' + + 'pasma, ' + + 'delosj, ' + + 'seriousbri, ' + + 'melisande-origami, and ' + + 'stuckincustoms' + + '
' + + '
Upload File...
' + + '
Cancel
' + ); showDialog(); }); - $('#dialog input.upload').live('change', function(e) { + $('#dialog input.upload').live('change', function (e) { var reader = new FileReader(); - reader.onload = function(e) { + reader.onload = function (e) { loadImage(e.target.result); }; reader.readAsDataURL(e.target.files[0]); }); - $('#dialog img.loader').live('mousedown', function(e) { + $('#dialog img.loader').live('mousedown', function (e) { loadImage(e.target.src); }); - $('#save').click(function() { + $('#save').click(function () { window.open(canvas.toDataURL('image/png')); }); - $('#about').click(function() { - $('#dialog').html('
Copyright 2011 Evan Wallace' + - '

This application is powered by glfx.js, an ' + - 'open-source image effect library that uses WebGL.  The source code for this application is ' + - 'also available on GitHub.
Close
'); + $('#about').click(function () { + $('#dialog').html( + '
Copyright 2011 Evan Wallace' + + '

This application is powered by glfx.js, an ' + + 'open-source image effect library that uses WebGL.  The source code for this application is ' + + 'also available on GitHub.
Close
' + ); showDialog(); }); - $('.closedialog').live('click', function() { + $('.closedialog').live('click', function () { hideDialog(); }); // Start loading the first image - loadImage('https://raw.githubusercontent.com/uber-common/deck.gl-data/master/images/samples/glfx/mountain.jpg'); + loadImage( + 'https://raw.githubusercontent.com/uber-common/deck.gl-data/master/images/samples/glfx/mountain.jpg' + ); }); // Filter object @@ -464,21 +511,21 @@ class Filter { } addSlider(name, label, min, max, value, step) { - this.sliders.push({ name: name, label: label, min: min, max: max, value: value, step: step }); + this.sliders.push({name: name, label: label, min: min, max: max, value: value, step: step}); this.values[name] = value; } addNub(name, value) { - this.nubs.push({ name: name, x: value[0], y: value[1] }); + this.nubs.push({name: name, x: value[0], y: value[1]}); this.values[name] = value; } addCurves(name) { - this.curves.push({ name: name }); + this.curves.push({name: name}); } addSegmented(name, label, labels, initial) { - this.segmented.push({ name: name, label: label, labels: labels, initial: initial }); + this.segmented.push({name: name, label: label, labels: labels, initial: initial}); } _initShaderModule(module) { @@ -488,32 +535,32 @@ class Filter { if (!uniform.private) { switch (uniform.type) { - case 'number': - const min = uniform.softMin || uniform.min || 0; - const max = uniform.softMax || uniform.max || 1; - const step = (max - min) / 100; - this.addSlider(uniformName, uniformName, min, max, uniform.value, step); - break; - default: - if (Array.isArray(uniform.value)) { - // Assume texCoords - this.addNub(uniformName, uniform.value); - } else { - console.log(uniform); - } + case 'number': + const min = uniform.softMin || uniform.min || 0; + const max = uniform.softMax || uniform.max || 1; + const step = (max - min) / 100; + this.addSlider(uniformName, uniformName, min, max, uniform.value, step); + break; + default: + if (Array.isArray(uniform.value)) { + // Assume texCoords + this.addNub(uniformName, uniform.value); + } else { + console.log(uniform); + } } } } } this._update = values => { - canvas.filter(module, values) - } + canvas.filter(module, values); + }; } } const filters = { - 'Adjust': [ + Adjust: [ new Filter('Brightness / Contrast', filterModules.brightnessContrast), new Filter('Hue / Saturation', filterModules.hueSaturation), new Filter('Sepia', filterModules.sepia), @@ -526,7 +573,9 @@ const filters = { // this.addSlider('strength', 'Strength', 0, 5, 2, 0.01); new Filter('Vibrance', filterModules.vibrance), new Filter('Vignette', filterModules.vignette), - new Filter('Curves', filterModules.curves, + new Filter( + 'Curves', + filterModules.curves, filter => { filter.addCurves('points'); }, @@ -540,9 +589,9 @@ const filters = { }) ) ], - 'Blur': [ + Blur: [ new Filter('Triangle Blur', filterModules.triangleBlur), - new Filter('Zoom Blur', filterModules.zoomBlur), + new Filter('Zoom Blur', filterModules.zoomBlur) // new Filter('Lens Blur', filterModules.lensBlur), // this.addSlider('radius', 'Radius', 0, 50, 10, 1); // this.addSlider('brightness', 'Brightness', -1, 1, 0.75, 0.01); @@ -556,16 +605,16 @@ const filters = { // canvas.filter('tiltShift', this.values) // }) ], - 'Fun': [ + Fun: [ new Filter('Ink', filterModules.ink), new Filter('Edge Work', filterModules.edgeWork), new Filter('Hexagonal Pixelate', filterModules.hexagonalPixelate), new Filter('Dot Screen', filterModules.dotScreen), - new Filter('Color Halftone', filterModules.colorHalftone), + new Filter('Color Halftone', filterModules.colorHalftone) ], - 'Warp': [ + Warp: [ new Filter('Swirl', filterModules.swirl), - new Filter('Bulge / Pinch', filterModules.bulgePinch), + new Filter('Bulge / Pinch', filterModules.bulgePinch) /* new Filter('Perspective', function() { this.addSegmented('showAfter', 'Edit point set', ['Before', 'After'], 1); diff --git a/examples/portable/instanced-cubes/app.ts b/examples/portable/instanced-cubes/app.ts index 9860c295e5..2266633aca 100644 --- a/examples/portable/instanced-cubes/app.ts +++ b/examples/portable/instanced-cubes/app.ts @@ -36,7 +36,7 @@ fn main( } `; -const FS_WGSL = /* WGSL */`\ +const FS_WGSL = /* WGSL */ `\ @fragment fn main( @location(0) fragUV: vec2, @@ -100,7 +100,7 @@ export default class AppAnimationLoopTemplate extends AnimationLoopTemplate { this.uniformBuffer = device.createBuffer({ id: 'uniforms', usage: Buffer.UNIFORM | Buffer.COPY_DST, - byteLength: UNIFORM_BUFFER_SIZE, + byteLength: UNIFORM_BUFFER_SIZE }); this.cubeModel = new Model(device, { @@ -111,13 +111,13 @@ export default class AppAnimationLoopTemplate extends AnimationLoopTemplate { instanceCount: NUMBER_OF_INSTANCES, parameters: { depthWriteEnabled: true, // Fragment closest to the camera is rendered in front. - depthCompare: 'less', - depthFormat: 'depth24plus', + depthCompare: 'less', + depthFormat: 'depth24plus', cullMode: 'back' // Faces pointing away will be occluded by faces pointing toward the camera. }, bindings: { app: this.uniformBuffer - }, + } }); } @@ -148,7 +148,9 @@ const STEP = 4.0; for (let x = 0; x < X_COUNT; x++) { for (let y = 0; y < Y_COUNT; y++) { - modelMatrices.push(new Matrix4().translate([STEP * (x - X_COUNT / 2 + 0.5), STEP * (y - Y_COUNT / 2 + 0.5), 0])); + modelMatrices.push( + new Matrix4().translate([STEP * (x - X_COUNT / 2 + 0.5), STEP * (y - Y_COUNT / 2 + 0.5), 0]) + ); } } @@ -164,8 +166,11 @@ function getMVPMatrixArray(projectionMatrix: Matrix4, now: number): Float32Array let offset = 0; for (let x = 0; x < X_COUNT; x++) { for (let y = 0; y < Y_COUNT; y++) { - tmpMat4.copy(modelMatrices[i]).rotateAxis(1, [Math.sin((x + 0.5) * now), Math.cos((y + 0.5) * now), 0]) - .multiplyLeft(viewMatrix).multiplyLeft(projectionMatrix); + tmpMat4 + .copy(modelMatrices[i]) + .rotateAxis(1, [Math.sin((x + 0.5) * now), Math.cos((y + 0.5) * now), 0]) + .multiplyLeft(viewMatrix) + .multiplyLeft(projectionMatrix); mvpMatricesData.set(tmpMat4, offset); @@ -175,4 +180,3 @@ function getMVPMatrixArray(projectionMatrix: Matrix4, now: number): Float32Array } return mvpMatricesData; } - diff --git a/examples/portable/instanced-cubes/vite.config.ts b/examples/portable/instanced-cubes/vite.config.ts index 46bb698c1a..ad387e431f 100644 --- a/examples/portable/instanced-cubes/vite.config.ts +++ b/examples/portable/instanced-cubes/vite.config.ts @@ -1,5 +1,5 @@ import fs from 'fs/promises'; -import { defineConfig } from 'vite' +import {defineConfig} from 'vite'; /** @see https://vitejs.dev/config/ */ export default defineConfig(async () => ({ @@ -9,10 +9,10 @@ export default defineConfig(async () => ({ /** Run against local source */ const getAliases = async (frameworkName, frameworkRootDir) => { - const modules = await fs.readdir(`${frameworkRootDir}/modules`) - const aliases = {} + const modules = await fs.readdir(`${frameworkRootDir}/modules`); + const aliases = {}; for (const module of modules) { - aliases[`${frameworkName}/${module}`] = `${frameworkRootDir}/modules/${module}/src` + aliases[`${frameworkName}/${module}`] = `${frameworkRootDir}/modules/${module}/src`; } - return aliases -} + return aliases; +}; diff --git a/examples/portable/rotating-cube/app.ts b/examples/portable/rotating-cube/app.ts index 76b97ba99f..c0d85b6d68 100644 --- a/examples/portable/rotating-cube/app.ts +++ b/examples/portable/rotating-cube/app.ts @@ -5,7 +5,7 @@ import {Matrix4} from '@math.gl/core'; export const title = 'Rotating Cube'; export const description = 'Shows rendering a basic triangle.'; -const VS_WGSL = /* WGSL */`\ +const VS_WGSL = /* WGSL */ `\ struct Uniforms { modelViewProjectionMatrix : mat4x4, }; @@ -31,7 +31,7 @@ fn main( } `; -const FS_WGSL = /* WGSL */`\ +const FS_WGSL = /* WGSL */ `\ @fragment fn main( @location(0) fragUV: vec2, @@ -95,7 +95,7 @@ export default class AppAnimationLoopTemplate extends AnimationLoopTemplate { this.uniformBuffer = device.createBuffer({ id: 'uniforms', byteLength: UNIFORM_BUFFER_SIZE, - usage: Buffer.UNIFORM | Buffer.COPY_DST, + usage: Buffer.UNIFORM | Buffer.COPY_DST }); this.model = new Model(device, { @@ -105,13 +105,13 @@ export default class AppAnimationLoopTemplate extends AnimationLoopTemplate { geometry: new CubeGeometry({indices: false}), parameters: { depthWriteEnabled: true, // Fragment closest to the camera is rendered in front. - depthCompare: 'less', - depthFormat: 'depth24plus', + depthCompare: 'less', + depthFormat: 'depth24plus', cullMode: 'back' // Faces pointing away will be occluded by faces pointing toward the camera. }, bindings: { app: this.uniformBuffer - }, + } }); } @@ -128,11 +128,14 @@ export default class AppAnimationLoopTemplate extends AnimationLoopTemplate { const aspect = device.canvasContext?.getAspect(); const now = Date.now() / 1000; - viewMatrix.identity().translate([0, 0, -4]).rotateAxis(1, [Math.sin(now), Math.cos(now), 0]); + viewMatrix + .identity() + .translate([0, 0, -4]) + .rotateAxis(1, [Math.sin(now), Math.cos(now), 0]); projectionMatrix.perspective({fovy: (2 * Math.PI) / 5, aspect, near: 1, far: 100.0}); modelViewProjectionMatrix.copy(viewMatrix).multiplyLeft(projectionMatrix); this.uniformBuffer.write(new Float32Array(modelViewProjectionMatrix)); - + const renderPass = device.beginRenderPass({clearColor: [0, 0, 0, 1]}); this.model.setBindings({app: this.uniformBuffer}); this.model.draw(renderPass); diff --git a/examples/portable/rotating-cube/vite.config.ts b/examples/portable/rotating-cube/vite.config.ts index 46bb698c1a..ad387e431f 100644 --- a/examples/portable/rotating-cube/vite.config.ts +++ b/examples/portable/rotating-cube/vite.config.ts @@ -1,5 +1,5 @@ import fs from 'fs/promises'; -import { defineConfig } from 'vite' +import {defineConfig} from 'vite'; /** @see https://vitejs.dev/config/ */ export default defineConfig(async () => ({ @@ -9,10 +9,10 @@ export default defineConfig(async () => ({ /** Run against local source */ const getAliases = async (frameworkName, frameworkRootDir) => { - const modules = await fs.readdir(`${frameworkRootDir}/modules`) - const aliases = {} + const modules = await fs.readdir(`${frameworkRootDir}/modules`); + const aliases = {}; for (const module of modules) { - aliases[`${frameworkName}/${module}`] = `${frameworkRootDir}/modules/${module}/src` + aliases[`${frameworkName}/${module}`] = `${frameworkRootDir}/modules/${module}/src`; } - return aliases -} + return aliases; +}; diff --git a/examples/portable/triangle/app.ts b/examples/portable/triangle/app.ts index d3e2d9a3ad..6666632dd7 100644 --- a/examples/portable/triangle/app.ts +++ b/examples/portable/triangle/app.ts @@ -15,7 +15,7 @@ void main() { gl_Position = vec4(pos[gl_VertexID], 0.0, 1.0); } `, - wgsl: /* WGSL */`\ + wgsl: /* WGSL */ `\ @vertex fn main(@builtin(vertex_index) VertexIndex : u32) -> @builtin(position) vec4 { var pos = array, 3>( @@ -37,7 +37,7 @@ void main() { outColor = vec4(1.0, 0.0, 0.0, 1.0); } `, - wgsl: /* WGSL */`\ + wgsl: /* WGSL */ `\ @fragment fn main() -> @location(0) vec4 { return vec4(1.0, 0.0, 0.0, 1.0); @@ -61,7 +61,7 @@ export default class AppAnimationLoopTemplate extends AnimationLoopTemplate { bindings: [] }, parameters: { - depthFormat: 'depth24plus', + depthFormat: 'depth24plus' } }); } @@ -71,7 +71,7 @@ export default class AppAnimationLoopTemplate extends AnimationLoopTemplate { } onRender({device}: AnimationProps) { - const renderPass = device.beginRenderPass({clearColor: [1,1,1,1]}); + const renderPass = device.beginRenderPass({clearColor: [1, 1, 1, 1]}); this.model.draw(renderPass); renderPass.end(); } diff --git a/examples/portable/triangle/vite.config.ts b/examples/portable/triangle/vite.config.ts index 46bb698c1a..ad387e431f 100644 --- a/examples/portable/triangle/vite.config.ts +++ b/examples/portable/triangle/vite.config.ts @@ -1,5 +1,5 @@ import fs from 'fs/promises'; -import { defineConfig } from 'vite' +import {defineConfig} from 'vite'; /** @see https://vitejs.dev/config/ */ export default defineConfig(async () => ({ @@ -9,10 +9,10 @@ export default defineConfig(async () => ({ /** Run against local source */ const getAliases = async (frameworkName, frameworkRootDir) => { - const modules = await fs.readdir(`${frameworkRootDir}/modules`) - const aliases = {} + const modules = await fs.readdir(`${frameworkRootDir}/modules`); + const aliases = {}; for (const module of modules) { - aliases[`${frameworkName}/${module}`] = `${frameworkRootDir}/modules/${module}/src` + aliases[`${frameworkName}/${module}`] = `${frameworkRootDir}/modules/${module}/src`; } - return aliases -} + return aliases; +}; diff --git a/examples/portable/two-cubes/app.ts b/examples/portable/two-cubes/app.ts index c5a46136c7..4af9d1a322 100644 --- a/examples/portable/two-cubes/app.ts +++ b/examples/portable/two-cubes/app.ts @@ -120,8 +120,8 @@ export default class AppAnimationLoopTemplate extends AnimationLoopTemplate { geometry: new CubeGeometry({indices: false}), parameters: { depthWriteEnabled: true, // Fragment closest to the camera is rendered in front. - depthCompare: 'less', - depthFormat: 'depth24plus', + depthCompare: 'less', + depthFormat: 'depth24plus', cullMode: 'back' // Faces pointing away will be occluded by faces pointing toward the camera. }, // TODO - bindings should not be needed here, as they are set later diff --git a/examples/portable/two-cubes/vite.config.ts b/examples/portable/two-cubes/vite.config.ts index 46bb698c1a..ad387e431f 100644 --- a/examples/portable/two-cubes/vite.config.ts +++ b/examples/portable/two-cubes/vite.config.ts @@ -1,5 +1,5 @@ import fs from 'fs/promises'; -import { defineConfig } from 'vite' +import {defineConfig} from 'vite'; /** @see https://vitejs.dev/config/ */ export default defineConfig(async () => ({ @@ -9,10 +9,10 @@ export default defineConfig(async () => ({ /** Run against local source */ const getAliases = async (frameworkName, frameworkRootDir) => { - const modules = await fs.readdir(`${frameworkRootDir}/modules`) - const aliases = {} + const modules = await fs.readdir(`${frameworkRootDir}/modules`); + const aliases = {}; for (const module of modules) { - aliases[`${frameworkName}/${module}`] = `${frameworkRootDir}/modules/${module}/src` + aliases[`${frameworkName}/${module}`] = `${frameworkRootDir}/modules/${module}/src`; } - return aliases -} + return aliases; +}; diff --git a/examples/script/webgl/transform-feedback/app.ts b/examples/script/webgl/transform-feedback/app.ts index 32460e5dd7..707c407bf1 100644 --- a/examples/script/webgl/transform-feedback/app.ts +++ b/examples/script/webgl/transform-feedback/app.ts @@ -6,7 +6,7 @@ const INFO_HTML = ` Animation via transform feedback. `; -const ALT_TEXT = 'THIS DEMO REQUIRES WEBGL 2, BUT YOUR BROWSER DOESN\'T SUPPORT IT'; +const ALT_TEXT = "THIS DEMO REQUIRES WEBGL 2, BUT YOUR BROWSER DOESN'T SUPPORT IT"; const transformVs = glsl`\ #version 300 es @@ -67,9 +67,13 @@ export default class AppAnimationLoopTemplate extends AnimationLoopTemplate { throw new Error(ALT_TEXT); } - this.prevPositionBuffer = device.createBuffer(new Float32Array([-0.5, -0.5, 0.5, -0.5, 0.0, 0.5])); + this.prevPositionBuffer = device.createBuffer( + new Float32Array([-0.5, -0.5, 0.5, -0.5, 0.0, 0.5]) + ); this.nextPositionBuffer = device.createBuffer(new Float32Array(6)); - this.colorBuffer = device.createBuffer(new Float32Array([1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0])); + this.colorBuffer = device.createBuffer( + new Float32Array([1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0]) + ); this.transform = new BufferTransform(device, { vs: transformVs, diff --git a/examples/script/webgl/transform-feedback/vite.config.ts b/examples/script/webgl/transform-feedback/vite.config.ts index 11488583fe..b873884922 100644 --- a/examples/script/webgl/transform-feedback/vite.config.ts +++ b/examples/script/webgl/transform-feedback/vite.config.ts @@ -1,4 +1,4 @@ -import { defineConfig } from 'vite' +import {defineConfig} from 'vite'; const alias = { '@luma.gl/constants': `${__dirname}/../../../modules/constants/src`, @@ -8,10 +8,10 @@ const alias = { '@luma.gl/shadertools': `${__dirname}/../../../modules/shadertools/src`, '@luma.gl/test-utils': `${__dirname}/../../../modules/test-utils/src`, '@luma.gl/webgl': `${__dirname}/../../../modules/webgl/src` -} +}; // https://vitejs.dev/config/ export default defineConfig({ resolve: {alias}, server: {open: true} -}) +}); diff --git a/examples/showcase/instancing/app.ts b/examples/showcase/instancing/app.ts index 418b402c88..5554934929 100644 --- a/examples/showcase/instancing/app.ts +++ b/examples/showcase/instancing/app.ts @@ -20,7 +20,7 @@ const random = makeRandomNumberGenerator(); // WGSL -// const VS_WGSL = /* WGSL */`\ +// const VS_WGSL = /* WGSL */`\ // void dirlight_setNormal(normal: vec3) { // dirlight_vNormal = normalize(normal); // } @@ -82,7 +82,7 @@ fn main(inputs: VertexInputs) -> FragmentInputs { } `; -const FS_WGSL = /* WGSL */`\ +const FS_WGSL = /* WGSL */ `\ struct DirlightUniforms { lightDirection: vec3, @@ -345,7 +345,7 @@ export default class AppAnimationLoopTemplate extends AnimationLoopTemplate { this.shaderInputs.setProps({picking: {highlightedObjectColor: null}}); return; } - + // use the center pixel location in device pixel range const devicePixels = device.canvasContext.cssToDevicePixels(mousePosition); const pickX = devicePixels.x + Math.floor(devicePixels.width / 2); @@ -373,8 +373,9 @@ export default class AppAnimationLoopTemplate extends AnimationLoopTemplate { }); // console.log(color255); - let highlightedObjectColor = new Float32Array(color255).map((x) => x / 255); - const isHighlightActive = highlightedObjectColor[0] + highlightedObjectColor[1] + highlightedObjectColor[2] > 0; + let highlightedObjectColor = new Float32Array(color255).map(x => x / 255); + const isHighlightActive = + highlightedObjectColor[0] + highlightedObjectColor[1] + highlightedObjectColor[2] > 0; if (!isHighlightActive) { highlightedObjectColor = null; } diff --git a/examples/showcase/instancing/vite.config.ts b/examples/showcase/instancing/vite.config.ts index 580567270b..fd348f1d89 100644 --- a/examples/showcase/instancing/vite.config.ts +++ b/examples/showcase/instancing/vite.config.ts @@ -1,4 +1,4 @@ -import { defineConfig } from 'vite' +import {defineConfig} from 'vite'; const alias = { '@luma.gl/constants': `${__dirname}/../../../modules/constants/src`, @@ -9,10 +9,10 @@ const alias = { '@luma.gl/test-utils': `${__dirname}/../../../modules/test-utils/src`, '@luma.gl/webgl': `${__dirname}/../../../modules/webgl/src`, '@luma.gl/webgpu': `${__dirname}/../../../modules/webgpu/src` -} +}; // https://vitejs.dev/config/ export default defineConfig({ resolve: {alias}, server: {open: true} -}) +}); diff --git a/examples/showcase/persistence/app.ts b/examples/showcase/persistence/app.ts index 09f65bcb08..bccd037509 100644 --- a/examples/showcase/persistence/app.ts +++ b/examples/showcase/persistence/app.ts @@ -278,10 +278,7 @@ export default class AppAnimationLoopTemplate extends AnimationLoopTemplate { fs: PERSISTENCE_FS, geometry: quadGeometry, bindings: { - persistenceQuad: this.uniformStore.getManagedUniformBuffer( - device, - 'persistenceQuad' - ) + persistenceQuad: this.uniformStore.getManagedUniformBuffer(device, 'persistenceQuad') }, parameters: { depthWriteEnabled: true, @@ -397,7 +394,6 @@ export default class AppAnimationLoopTemplate extends AnimationLoopTemplate { const currentFramebuffer = this.pingpongFramebuffers[ppi]; const nextFramebuffer = this.pingpongFramebuffers[1 - ppi]; - // Accumulate in persistence buffer const persistenceRenderPass = device.beginRenderPass({ framebuffer: currentFramebuffer, diff --git a/examples/showcase/persistence/vite.config.ts b/examples/showcase/persistence/vite.config.ts index 11488583fe..b873884922 100644 --- a/examples/showcase/persistence/vite.config.ts +++ b/examples/showcase/persistence/vite.config.ts @@ -1,4 +1,4 @@ -import { defineConfig } from 'vite' +import {defineConfig} from 'vite'; const alias = { '@luma.gl/constants': `${__dirname}/../../../modules/constants/src`, @@ -8,10 +8,10 @@ const alias = { '@luma.gl/shadertools': `${__dirname}/../../../modules/shadertools/src`, '@luma.gl/test-utils': `${__dirname}/../../../modules/test-utils/src`, '@luma.gl/webgl': `${__dirname}/../../../modules/webgl/src` -} +}; // https://vitejs.dev/config/ export default defineConfig({ resolve: {alias}, server: {open: true} -}) +}); diff --git a/examples/tutorials/hello-cube/vite.config.ts b/examples/tutorials/hello-cube/vite.config.ts index 74b76edb7f..43053081f0 100644 --- a/examples/tutorials/hello-cube/vite.config.ts +++ b/examples/tutorials/hello-cube/vite.config.ts @@ -1,4 +1,4 @@ -import { defineConfig } from 'vite' +import {defineConfig} from 'vite'; const alias = { '@luma.gl/constants': `${__dirname}/../../../modules/constants/src`, @@ -9,10 +9,10 @@ const alias = { '@luma.gl/shadertools': `${__dirname}/../../../modules/shadertools/src`, '@luma.gl/test-utils': `${__dirname}/../../../modules/test-utils/src`, '@luma.gl/webgl': `${__dirname}/../../../modules/webgl/src` -} +}; // https://vitejs.dev/config/ export default defineConfig({ resolve: {alias}, server: {open: true} -}) +}); diff --git a/examples/tutorials/hello-gltf/app.ts b/examples/tutorials/hello-gltf/app.ts index 8f8ac19465..345b67a4e8 100644 --- a/examples/tutorials/hello-gltf/app.ts +++ b/examples/tutorials/hello-gltf/app.ts @@ -84,7 +84,7 @@ export default class AppAnimationLoopTemplate extends AnimationLoopTemplate { const options = {pbrDebug: false, imageBasedLightingEnvironment: null, lights: true}; const {scenes} = createScenegraphsFromGLTF(this.device, processedGLTF, options); - this.scenes = scenes ; + this.scenes = scenes; // Calculate nice camera view // TODO move to utility in gltf module diff --git a/examples/tutorials/hello-instancing/app.ts b/examples/tutorials/hello-instancing/app.ts index 6a5dd47115..c81d8ade57 100644 --- a/examples/tutorials/hello-instancing/app.ts +++ b/examples/tutorials/hello-instancing/app.ts @@ -35,8 +35,12 @@ export default class AppAnimationLoopTemplate extends AnimationLoopTemplate { super(); this.positionBuffer = device.createBuffer(new Float32Array([-0.2, -0.2, 0.2, -0.2, 0.0, 0.2])); - this.colorBuffer = device.createBuffer(new Float32Array([1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 0.0])); - this.offsetBuffer = device.createBuffer(new Float32Array([0.5, 0.5, -0.5, 0.5, 0.5, -0.5, -0.5, -0.5])); + this.colorBuffer = device.createBuffer( + new Float32Array([1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 0.0]) + ); + this.offsetBuffer = device.createBuffer( + new Float32Array([0.5, 0.5, -0.5, 0.5, 0.5, -0.5, -0.5, -0.5]) + ); this.model = new Model(device, { vs: glsl`\ @@ -61,12 +65,12 @@ void main() { bufferLayout: [ {name: 'position', format: 'float32x2'}, {name: 'instanceColor', format: 'float32x3', stepMode: 'instance'}, - {name: 'instanceOffset', format: 'float32x2', stepMode: 'instance'}, + {name: 'instanceOffset', format: 'float32x2', stepMode: 'instance'} ], attributes: { position: this.positionBuffer, instanceColor: this.colorBuffer, - instanceOffset:this.offsetBuffer + instanceOffset: this.offsetBuffer }, vertexCount: 3, instanceCount: 4 diff --git a/examples/tutorials/hello-instancing/vite.config.ts b/examples/tutorials/hello-instancing/vite.config.ts index 74b76edb7f..43053081f0 100644 --- a/examples/tutorials/hello-instancing/vite.config.ts +++ b/examples/tutorials/hello-instancing/vite.config.ts @@ -1,4 +1,4 @@ -import { defineConfig } from 'vite' +import {defineConfig} from 'vite'; const alias = { '@luma.gl/constants': `${__dirname}/../../../modules/constants/src`, @@ -9,10 +9,10 @@ const alias = { '@luma.gl/shadertools': `${__dirname}/../../../modules/shadertools/src`, '@luma.gl/test-utils': `${__dirname}/../../../modules/test-utils/src`, '@luma.gl/webgl': `${__dirname}/../../../modules/webgl/src` -} +}; // https://vitejs.dev/config/ export default defineConfig({ resolve: {alias}, server: {open: true} -}) +}); diff --git a/examples/tutorials/hello-triangle/app.ts b/examples/tutorials/hello-triangle/app.ts index fb9820b889..d253d0e74c 100644 --- a/examples/tutorials/hello-triangle/app.ts +++ b/examples/tutorials/hello-triangle/app.ts @@ -72,19 +72,23 @@ export default class AppAnimationLoopTemplate extends AnimationLoopTemplate { 0.0, 0.5, 0, 0, 1 ]) this.interleavedBuffer = device.createBuffer(interleavedData); - + this.model = new Model(device, { id: 'triangle', vs, fs, bufferLayout: [ - {name: 'vertexData', byteStride: 20, attributes: [ - {attribute: 'position', format: 'float32x2', byteOffset: 8 + 0}, - {attribute: 'color', format: 'float32x3', byteOffset: 8 + 8}, - ]} + { + name: 'vertexData', + byteStride: 20, + attributes: [ + {attribute: 'position', format: 'float32x2', byteOffset: 8 + 0}, + {attribute: 'color', format: 'float32x3', byteOffset: 8 + 8} + ] + } ], attributes: { - vertexData: this.interleavedBuffer, + vertexData: this.interleavedBuffer }, vertexCount: 3 }); diff --git a/examples/tutorials/hello-triangle/vite.config.ts b/examples/tutorials/hello-triangle/vite.config.ts index 580567270b..fd348f1d89 100644 --- a/examples/tutorials/hello-triangle/vite.config.ts +++ b/examples/tutorials/hello-triangle/vite.config.ts @@ -1,4 +1,4 @@ -import { defineConfig } from 'vite' +import {defineConfig} from 'vite'; const alias = { '@luma.gl/constants': `${__dirname}/../../../modules/constants/src`, @@ -9,10 +9,10 @@ const alias = { '@luma.gl/test-utils': `${__dirname}/../../../modules/test-utils/src`, '@luma.gl/webgl': `${__dirname}/../../../modules/webgl/src`, '@luma.gl/webgpu': `${__dirname}/../../../modules/webgpu/src` -} +}; // https://vitejs.dev/config/ export default defineConfig({ resolve: {alias}, server: {open: true} -}) +}); diff --git a/examples/tutorials/lighting/app-old.ts b/examples/tutorials/lighting/app-old.ts index b3bfb33791..46c9237026 100644 --- a/examples/tutorials/lighting/app-old.ts +++ b/examples/tutorials/lighting/app-old.ts @@ -179,7 +179,7 @@ export default class AppAnimationLoopTemplate extends AnimationLoopTemplate { // This updates the "app" uniform buffer, which is already bound this.uniformStore.setUniforms({ app: { - mvpMatrix: this.mvpMatrix, + mvpMatrix: this.mvpMatrix, modelMatrix: this.modelMatrix } }); diff --git a/examples/tutorials/lighting/app.ts b/examples/tutorials/lighting/app.ts index c077f9b53d..1f62ee8eea 100644 --- a/examples/tutorials/lighting/app.ts +++ b/examples/tutorials/lighting/app.ts @@ -1,5 +1,11 @@ import {glsl, NumberArray, loadImage} from '@luma.gl/core'; -import {AnimationLoopTemplate, AnimationProps, Model, CubeGeometry, _ShaderInputs} from '@luma.gl/engine'; +import { + AnimationLoopTemplate, + AnimationProps, + Model, + CubeGeometry, + _ShaderInputs +} from '@luma.gl/engine'; import {phongMaterial, lighting, ShaderModule} from '@luma.gl/shadertools'; import {Matrix4} from '@math.gl/core'; @@ -90,7 +96,6 @@ export default class AppAnimationLoopTemplate extends AnimationLoopTemplate { phongMaterial: typeof phongMaterial.props; }>({app, lighting, phongMaterial}); - modelMatrix = new Matrix4(); viewMatrix = new Matrix4().lookAt({eye: eyePosition}); mvpMatrix = new Matrix4(); @@ -146,7 +151,7 @@ export default class AppAnimationLoopTemplate extends AnimationLoopTemplate { // This updates the "app" uniform buffer, which is already bound this.shaderInputs.setProps({ app: { - mvpMatrix: this.mvpMatrix, + mvpMatrix: this.mvpMatrix, modelMatrix: this.modelMatrix } }); diff --git a/examples/tutorials/lighting/vite.config.ts b/examples/tutorials/lighting/vite.config.ts index 7230a5d0fd..08964dc4d2 100644 --- a/examples/tutorials/lighting/vite.config.ts +++ b/examples/tutorials/lighting/vite.config.ts @@ -1,4 +1,4 @@ -import { defineConfig } from 'vite'; +import {defineConfig} from 'vite'; import fs from 'fs'; // https://vitejs.dev/config/ @@ -9,10 +9,10 @@ export default defineConfig(async () => ({ /** Run against local source */ const getAliases = async (frameworkName, frameworkRootDir) => { - const modules = await fs.promises.readdir(`${frameworkRootDir}/modules`) - const aliases = {} + const modules = await fs.promises.readdir(`${frameworkRootDir}/modules`); + const aliases = {}; modules.forEach(module => { aliases[`${frameworkName}/${module}`] = `${frameworkRootDir}/modules/${module}/src`; - }) - return aliases -} + }); + return aliases; +}; diff --git a/examples/tutorials/shader-hooks/app.ts b/examples/tutorials/shader-hooks/app.ts index c96cd13294..54af02e3e9 100644 --- a/examples/tutorials/shader-hooks/app.ts +++ b/examples/tutorials/shader-hooks/app.ts @@ -78,7 +78,6 @@ export default class AppAnimationLoopTemplate extends AnimationLoopTemplate { this.positionBuffer = device.createBuffer(new Float32Array([-0.3, -0.5, 0.3, -0.5, 0.0, 0.5])); - this.uniformBuffer1 = this.uniformStore.createUniformBuffer(device, 'app', { app: { color: [1, 0, 0] @@ -99,9 +98,7 @@ export default class AppAnimationLoopTemplate extends AnimationLoopTemplate { fs, shaderAssembler, // Not needed, if not specified uses the default ShaderAssembler modules: [offsetLeftModule], - bufferLayout: [ - {name: 'position', format: 'float32x2'}, - ], + bufferLayout: [{name: 'position', format: 'float32x2'}], attributes: { position: this.positionBuffer }, @@ -116,9 +113,7 @@ export default class AppAnimationLoopTemplate extends AnimationLoopTemplate { fs, shaderAssembler, // Not needed, if not specified uses the default ShaderAssembler modules: [offsetRightModule], - bufferLayout: [ - {name: 'position', format: 'float32x2'}, - ], + bufferLayout: [{name: 'position', format: 'float32x2'}], vertexCount: 3, attributes: { position: this.positionBuffer diff --git a/examples/tutorials/shader-hooks/vite.config.ts b/examples/tutorials/shader-hooks/vite.config.ts index 74b76edb7f..43053081f0 100644 --- a/examples/tutorials/shader-hooks/vite.config.ts +++ b/examples/tutorials/shader-hooks/vite.config.ts @@ -1,4 +1,4 @@ -import { defineConfig } from 'vite' +import {defineConfig} from 'vite'; const alias = { '@luma.gl/constants': `${__dirname}/../../../modules/constants/src`, @@ -9,10 +9,10 @@ const alias = { '@luma.gl/shadertools': `${__dirname}/../../../modules/shadertools/src`, '@luma.gl/test-utils': `${__dirname}/../../../modules/test-utils/src`, '@luma.gl/webgl': `${__dirname}/../../../modules/webgl/src` -} +}; // https://vitejs.dev/config/ export default defineConfig({ resolve: {alias}, server: {open: true} -}) +}); diff --git a/examples/tutorials/shader-modules/app.ts b/examples/tutorials/shader-modules/app.ts index b702cf6357..5cf97cc576 100644 --- a/examples/tutorials/shader-modules/app.ts +++ b/examples/tutorials/shader-modules/app.ts @@ -88,7 +88,6 @@ export default class AppAnimationLoopTemplate extends AnimationLoopTemplate { positionBuffer: Buffer; - constructor({device}: AnimationProps) { super(); diff --git a/examples/tutorials/shader-modules/vite.config.ts b/examples/tutorials/shader-modules/vite.config.ts index 11488583fe..b873884922 100644 --- a/examples/tutorials/shader-modules/vite.config.ts +++ b/examples/tutorials/shader-modules/vite.config.ts @@ -1,4 +1,4 @@ -import { defineConfig } from 'vite' +import {defineConfig} from 'vite'; const alias = { '@luma.gl/constants': `${__dirname}/../../../modules/constants/src`, @@ -8,10 +8,10 @@ const alias = { '@luma.gl/shadertools': `${__dirname}/../../../modules/shadertools/src`, '@luma.gl/test-utils': `${__dirname}/../../../modules/test-utils/src`, '@luma.gl/webgl': `${__dirname}/../../../modules/webgl/src` -} +}; // https://vitejs.dev/config/ export default defineConfig({ resolve: {alias}, server: {open: true} -}) +}); diff --git a/examples/webgpu/compute/app.ts b/examples/webgpu/compute/app.ts index a179525609..6134b6f1e1 100644 --- a/examples/webgpu/compute/app.ts +++ b/examples/webgpu/compute/app.ts @@ -54,34 +54,23 @@ async function init(canvas: HTMLCanvasElement) { // First Matrix - const firstMatrix = new Float32Array([ - 2 /* rows */, 4 /* columns */, - 1, 2, 3, 4, - 5, 6, 7, 8 - ]); + const firstMatrix = new Float32Array([2 /* rows */, 4 /* columns */, 1, 2, 3, 4, 5, 6, 7, 8]); // Second Matrix - const secondMatrix = new Float32Array([ - 4 /* rows */, 2 /* columns */, - 1, 2, - 3, 4, - 5, 6, - 7, 8 - ]); + const secondMatrix = new Float32Array([4 /* rows */, 2 /* columns */, 1, 2, 3, 4, 5, 6, 7, 8]); const gpuBufferFirstMatrix = device.createBuffer({usage: Buffer.STORAGE, data: firstMatrix}); const gpuBufferSecondMatrix = device.createBuffer({usage: Buffer.STORAGE, data: secondMatrix}); - // Result Matrix - const resultMatrixBufferSize = Float32Array.BYTES_PER_ELEMENT * (2 + firstMatrix[0] * secondMatrix[1]); + const resultMatrixBufferSize = + Float32Array.BYTES_PER_ELEMENT * (2 + firstMatrix[0] * secondMatrix[1]); const resultMatrixBuffer = device.createBuffer({ size: resultMatrixBufferSize, usage: Buffer.STORAGE | Buffer.COPY_SRC }); - // Compute shader code const computeShader = device.createShader({ @@ -97,7 +86,7 @@ async function init(canvas: HTMLCanvasElement) { firstMatrix, secondMatrix, resultMatrix - }, + } }); // Commands submission @@ -131,7 +120,6 @@ async function init(canvas: HTMLCanvasElement) { const gpuCommands = commandEncoder.finish(); device.queue.submit([gpuCommands]); - // Read buffer. await gpuReadBuffer.mapAsync(GPUMapMode.READ); const arrayBuffer = gpuReadBuffer.getMappedRange(); diff --git a/examples/webgpu/computeboids/app.ts b/examples/webgpu/computeboids/app.ts index 8215db5fe9..2ca2a7e023 100644 --- a/examples/webgpu/computeboids/app.ts +++ b/examples/webgpu/computeboids/app.ts @@ -12,7 +12,7 @@ import {Model, WebGPUDevice} from '@luma.gl/webgpu'; export const name = 'Compute Boids'; export const description = - 'A GPU compute particle simulation that mimics \ + 'A GPU compute particle simulation that mimics \ the flocking behavior of birds. A compute shader updates \ two ping-pong buffers which store particle data. The data \ is used to draw instanced particles.'; @@ -47,10 +47,7 @@ export async function init(canvas: HTMLCanvasElement, language: 'glsl' | 'wgsl') bindings: [] }, bufferLayout: [ - {name: 'particles', attributes: [ - {name: 'instancePositions'}, - {name: 'instanceVelocities'} - ]} + {name: 'particles', attributes: [{name: 'instancePositions'}, {name: 'instanceVelocities'}]} ], // targets: [ // { @@ -67,15 +64,23 @@ export async function init(canvas: HTMLCanvasElement, language: 'glsl' | 'wgsl') // Backface culling since the cube is solid piece of geometry. // Faces pointing away from the camera will be occluded by faces // pointing toward the camera. - cullMode: 'back', + cullMode: 'back' }, topology: 'triangle-list', vertexCount: 6, instanceCount: NUM_PARTICLES }); - const cs = device.createShader({id: 'sprites', stage: 'compute', source: SHADERS.wgsl.updateSprites}); - const computePipeline = device.createComputePipeline({id: 'updateSprites', cs, csEntryPoint: 'main'}); + const cs = device.createShader({ + id: 'sprites', + stage: 'compute', + source: SHADERS.wgsl.updateSprites + }); + const computePipeline = device.createComputePipeline({ + id: 'updateSprites', + cs, + csEntryPoint: 'main' + }); const vertexBufferData = new Float32Array([-0.01, -0.02, 0.01, -0.02, 0.0, 0.02]); const spriteVertexBuffer = device.createBuffer({id: 'boid-geometry', data: vertexBufferData}); @@ -87,26 +92,28 @@ export async function init(canvas: HTMLCanvasElement, language: 'glsl' | 'wgsl') rule3Distance: 0.025, rule1Scale: 0.02, rule2Scale: 0.05, - rule3Scale: 0.005, + rule3Scale: 0.005 }; const simParamBufferSize = 7 * Float32Array.BYTES_PER_ELEMENT; const simParamBuffer = device.createBuffer({ id: 'simParams', byteLength: simParamBufferSize, - usage: GPUBufferUsage.UNIFORM | GPUBufferUsage.COPY_DST, + usage: GPUBufferUsage.UNIFORM | GPUBufferUsage.COPY_DST }); function updateSimParams() { - simParamBuffer.write(new Float32Array([ - simParams.deltaT, - simParams.rule1Distance, - simParams.rule2Distance, - simParams.rule3Distance, - simParams.rule1Scale, - simParams.rule2Scale, - simParams.rule3Scale, - ])); + simParamBuffer.write( + new Float32Array([ + simParams.deltaT, + simParams.rule1Distance, + simParams.rule2Distance, + simParams.rule3Distance, + simParams.rule1Scale, + simParams.rule2Scale, + simParams.rule3Scale + ]) + ); } updateSimParams(); @@ -124,8 +131,16 @@ export async function init(canvas: HTMLCanvasElement, language: 'glsl' | 'wgsl') } const particleBuffers = [ - device.createBuffer({id: 'particles1', data: initialParticleData, usage: Buffer.VERTEX | Buffer.STORAGE | Buffer.COPY_SRC}), - device.createBuffer({id: 'particles2', data: initialParticleData, usage: Buffer.VERTEX | Buffer.STORAGE}) + device.createBuffer({ + id: 'particles1', + data: initialParticleData, + usage: Buffer.VERTEX | Buffer.STORAGE | Buffer.COPY_SRC + }), + device.createBuffer({ + id: 'particles2', + data: initialParticleData, + usage: Buffer.VERTEX | Buffer.STORAGE + }) ]; const particleBindings = [ @@ -149,7 +164,6 @@ export async function init(canvas: HTMLCanvasElement, language: 'glsl' | 'wgsl') const arrayBuffer = await particleBuffers[0].readAsync(); console.log(new Float32Array(arrayBuffer)); - const renderPass = device.beginRenderPass({clearColor: [0, 0, 0, 1]}); model.setAttributes({ particles: particleBuffers[(t + 1) % 2], diff --git a/examples/webgpu/computeboids/vite.config.ts b/examples/webgpu/computeboids/vite.config.ts index dbd53a0974..0ff0fa78fd 100644 --- a/examples/webgpu/computeboids/vite.config.ts +++ b/examples/webgpu/computeboids/vite.config.ts @@ -1,6 +1,6 @@ import fs from 'fs/promises'; // import string from 'vite-plugin-string'; -import { defineConfig } from 'vite' +import {defineConfig} from 'vite'; /** @see https://vitejs.dev/config/ */ export default defineConfig(async () => ({ @@ -11,10 +11,10 @@ export default defineConfig(async () => ({ /** Run against local source */ const getAliases = async (frameworkName, frameworkRootDir) => { - const modules = await fs.readdir(`${frameworkRootDir}/modules`) - const aliases = {} + const modules = await fs.readdir(`${frameworkRootDir}/modules`); + const aliases = {}; for (const module of modules) { - aliases[`${frameworkName}/${module}`] = `${frameworkRootDir}/modules/${module}/src` + aliases[`${frameworkName}/${module}`] = `${frameworkRootDir}/modules/${module}/src`; } - return aliases -} + return aliases; +}; diff --git a/examples/webgpu/textured-cube/app.ts b/examples/webgpu/textured-cube/app.ts index df1e8bd3fb..f19e8ff71e 100644 --- a/examples/webgpu/textured-cube/app.ts +++ b/examples/webgpu/textured-cube/app.ts @@ -111,7 +111,7 @@ export default class AppAnimationLoopTemplate extends AnimationLoopTemplate { minFilter: 'linear', addressModeU: 'clamp-to-edge', addressModeV: 'clamp-to-edge' - }, + } }); this.uniformBuffer = device.createBuffer({ @@ -132,10 +132,10 @@ export default class AppAnimationLoopTemplate extends AnimationLoopTemplate { }, parameters: { depthWriteEnabled: true, // Fragment closest to the camera is rendered in front. - depthCompare: 'less', - // depthFormat: 'depth24plus', + depthCompare: 'less' + // depthFormat: 'depth24plus', // cullMode: 'back' // Faces pointing away will be occluded by faces pointing toward the camera. - }, + } }); } diff --git a/examples/webgpu/textured-cube/vite.config.ts b/examples/webgpu/textured-cube/vite.config.ts index 46bb698c1a..ad387e431f 100644 --- a/examples/webgpu/textured-cube/vite.config.ts +++ b/examples/webgpu/textured-cube/vite.config.ts @@ -1,5 +1,5 @@ import fs from 'fs/promises'; -import { defineConfig } from 'vite' +import {defineConfig} from 'vite'; /** @see https://vitejs.dev/config/ */ export default defineConfig(async () => ({ @@ -9,10 +9,10 @@ export default defineConfig(async () => ({ /** Run against local source */ const getAliases = async (frameworkName, frameworkRootDir) => { - const modules = await fs.readdir(`${frameworkRootDir}/modules`) - const aliases = {} + const modules = await fs.readdir(`${frameworkRootDir}/modules`); + const aliases = {}; for (const module of modules) { - aliases[`${frameworkName}/${module}`] = `${frameworkRootDir}/modules/${module}/src` + aliases[`${frameworkName}/${module}`] = `${frameworkRootDir}/modules/${module}/src`; } - return aliases -} + return aliases; +}; diff --git a/modules/constants/src/index.ts b/modules/constants/src/index.ts index fd4d6c6a79..c3118e0fad 100644 --- a/modules/constants/src/index.ts +++ b/modules/constants/src/index.ts @@ -26,4 +26,4 @@ export type { GLParameters, GLLimits, GLExtensions -} from './webgl-types'; \ No newline at end of file +} from './webgl-types'; diff --git a/modules/constants/src/webgl-types.ts b/modules/constants/src/webgl-types.ts index 8035a63e21..71e4c02f1c 100644 --- a/modules/constants/src/webgl-types.ts +++ b/modules/constants/src/webgl-types.ts @@ -569,32 +569,32 @@ type EXT_conservative_depth = {}; /** EXT_polygon_offset_clamp https://registry.khronos.org/webgl/extensions/EXT_polygon_offset_clamp/ */ type EXT_polygon_offset_clamp = { - POLYGON_OFFSET_CLAMP_EXT: 0x8E1B; + POLYGON_OFFSET_CLAMP_EXT: 0x8e1b; polygonOffsetClampEXT(factor: number, units: number, clamp: number): void; }; /** EXT_clip_control https://registry.khronos.org/webgl/extensions/EXT_clip_control/ */ type EXT_clip_control = { - LOWER_LEFT_EXT: 0x8CA1; - UPPER_LEFT_EXT: 0x8CA2; + LOWER_LEFT_EXT: 0x8ca1; + UPPER_LEFT_EXT: 0x8ca2; - NEGATIVE_ONE_TO_ONE_EXT: 0x935E; - ZERO_TO_ONE_EXT: 0x935F; + NEGATIVE_ONE_TO_ONE_EXT: 0x935e; + ZERO_TO_ONE_EXT: 0x935f; - CLIP_ORIGIN_EXT: 0x935C; - CLIP_DEPTH_MODE_EXT: 0x935D; + CLIP_ORIGIN_EXT: 0x935c; + CLIP_DEPTH_MODE_EXT: 0x935d; clipControlEXT(origin: GL, depth: GL): void; }; /** WEBGL_blend_func_extended https://registry.khronos.org/webgl/extensions/WEBGL_blend_func_extended/ */ type WEBGL_blend_func_extended = { - SRC1_COLOR_WEBGL: 0x88F9; + SRC1_COLOR_WEBGL: 0x88f9; SRC1_ALPHA_WEBGL: 0x8589; - ONE_MINUS_SRC1_COLOR_WEBGL: 0x88FA; - ONE_MINUS_SRC1_ALPHA_WEBGL: 0x88FB; - MAX_DUAL_SOURCE_DRAW_BUFFERS_WEBGL: 0x88FC; + ONE_MINUS_SRC1_COLOR_WEBGL: 0x88fa; + ONE_MINUS_SRC1_ALPHA_WEBGL: 0x88fb; + MAX_DUAL_SOURCE_DRAW_BUFFERS_WEBGL: 0x88fc; }; /** OES_draw_buffers_indexed https://registry.khronos.org/webgl/extensions/OES_draw_buffers_indexed/ */ @@ -613,4 +613,4 @@ type OES_draw_buffers_indexed = { blendFuncSeparateiOES(buf: number, srcRGB: GL, dstRGB: GL, srcAlpha: GL, dstAlpha: GL): void; /** Modifies color mask for an individual draw buffer */ colorMaskiOES(buf: number, r: boolean, g: boolean, b: boolean, a: boolean): void; -}; \ No newline at end of file +}; diff --git a/modules/constants/test/webgl-constants.spec.ts b/modules/constants/test/webgl-constants.spec.ts index d01cb74d8d..f1e9e5eabd 100644 --- a/modules/constants/test/webgl-constants.spec.ts +++ b/modules/constants/test/webgl-constants.spec.ts @@ -7,12 +7,12 @@ import {webglDevice} from '@luma.gl/test-utils'; import {GL} from '@luma.gl/constants'; -test('@luma.gl/constants', (t) => { +test('@luma.gl/constants', t => { t.equal(typeof GL, 'object', '@luma.gl/constants is an object'); t.end(); }); -test('@luma.gl/constants#WebGL2 context', (t) => { +test('@luma.gl/constants#WebGL2 context', t => { const count = checkConstants(webglDevice.gl, t); t.comment(`Checked ${count} GL constants against platform WebGL2 context`); t.end(); diff --git a/modules/core-tests/src/index.ts b/modules/core-tests/src/index.ts index 8f161dafcb..d11c69f812 100644 --- a/modules/core-tests/src/index.ts +++ b/modules/core-tests/src/index.ts @@ -1 +1 @@ -// intentionally empty \ No newline at end of file +// intentionally empty diff --git a/modules/core-tests/test/adapter/canvas-context.spec.ts b/modules/core-tests/test/adapter/canvas-context.spec.ts index 00bed7bf04..fbe6ce32c3 100644 --- a/modules/core-tests/test/adapter/canvas-context.spec.ts +++ b/modules/core-tests/test/adapter/canvas-context.spec.ts @@ -1,17 +1,16 @@ // luma.gl, MIT license import test from 'tape-promise/tape'; -import {getWebGLTestDevices} from '@luma.gl/test-utils' +import {getWebGLTestDevices} from '@luma.gl/test-utils'; import {CanvasContext} from '@luma.gl/core'; -test('CanvasContext#defined', (t) => { +test('CanvasContext#defined', t => { t.ok(CanvasContext, 'CanvasContext defined'); // t.ok(new WEBGLCanvasContext()), 'Context creation ok'); t.end(); }); - -test('CanvasContext#getDevicePixelRatio', (t) => { +test('CanvasContext#getDevicePixelRatio', t => { const windowPixelRatio = (typeof window !== 'undefined' && window.devicePixelRatio) || 1; const TEST_CASES = [ { @@ -47,7 +46,7 @@ test('CanvasContext#getDevicePixelRatio', (t) => { ]; for (const device of getWebGLTestDevices()) { - TEST_CASES.forEach((tc) => { + TEST_CASES.forEach(tc => { const result = device.canvasContext?.getDevicePixelRatio(tc.useDevicePixels); t.equal(result, tc.expected, tc.name); }); diff --git a/modules/core-tests/test/adapter/device-helpers/device-info.spec.ts b/modules/core-tests/test/adapter/device-helpers/device-info.spec.ts index 45cc382b2e..f9d44f8b72 100644 --- a/modules/core-tests/test/adapter/device-helpers/device-info.spec.ts +++ b/modules/core-tests/test/adapter/device-helpers/device-info.spec.ts @@ -1,7 +1,7 @@ import test from 'tape-promise/tape'; import {getTestDevices} from '@luma.gl/test-utils'; -test('WebGLDevice#info (unknown)', async (t) => { +test('WebGLDevice#info (unknown)', async t => { for (const testDevice of await getTestDevices()) { t.ok(testDevice.info.type); // TODO check all info fields diff --git a/modules/core-tests/test/adapter/device-helpers/device-limits.spec.ts b/modules/core-tests/test/adapter/device-helpers/device-limits.spec.ts index 73b7db70fe..2b29f0c0c2 100644 --- a/modules/core-tests/test/adapter/device-helpers/device-limits.spec.ts +++ b/modules/core-tests/test/adapter/device-helpers/device-limits.spec.ts @@ -82,7 +82,7 @@ export const WEBGL_LIMITS = { [GL.UNIFORM_BUFFER_OFFSET_ALIGNMENT]: true }; -test('WebGLDevice#limits (WebGPU style limits)', async (t) => { +test('WebGLDevice#limits (WebGPU style limits)', async t => { for (const testDevice of await getTestDevices()) { for (const [limit, numeric] of Object.entries(DEVICE_LIMITS)) { const actual = testDevice.limits[limit]; diff --git a/modules/core-tests/test/adapter/device-helpers/set-device-parameters.spec.ts b/modules/core-tests/test/adapter/device-helpers/set-device-parameters.spec.ts index 04bc3ba885..7c5fda8ef4 100644 --- a/modules/core-tests/test/adapter/device-helpers/set-device-parameters.spec.ts +++ b/modules/core-tests/test/adapter/device-helpers/set-device-parameters.spec.ts @@ -17,9 +17,9 @@ const {gl} = webglDevice; const getGLParameter = (parameter: keyof GLParameters): any => { const parameters = getGLParameters(gl, [parameter]); return parameters[parameter]; -} +}; -test('setDeviceParameters#cullMode', (t) => { +test('setDeviceParameters#cullMode', t => { resetGLParameters(gl); t.deepEqual(getGLParameter(GL.CULL_FACE), false, 'got expected value'); @@ -38,7 +38,7 @@ test('setDeviceParameters#cullMode', (t) => { t.end(); }); -test('setDeviceParameters#frontFace', (t) => { +test('setDeviceParameters#frontFace', t => { resetGLParameters(gl); t.deepEqual(getGLParameter(GL.FRONT_FACE), GL.CCW, 'got expected value'); @@ -52,7 +52,7 @@ test('setDeviceParameters#frontFace', (t) => { t.end(); }); -test('setDeviceParameters#depthWriteEnabled', (t) => { +test('setDeviceParameters#depthWriteEnabled', t => { resetGLParameters(gl); t.deepEqual(getGLParameter(GL.DEPTH_WRITEMASK), true, 'got expected value'); @@ -66,20 +66,19 @@ test('setDeviceParameters#depthWriteEnabled', (t) => { t.end(); }); -test('setDeviceParameters#depthWriteEnabled', (t) => { +test('setDeviceParameters#depthWriteEnabled', t => { testClauses(t, 'depthWriteEnabled', [ {check: {[GL.DEPTH_WRITEMASK]: true}}, {set: {depthWriteEnabled: false}}, {check: {[GL.DEPTH_WRITEMASK]: false}}, {set: {depthWriteEnabled: true}}, - {check: {[GL.DEPTH_WRITEMASK]: true}}, + {check: {[GL.DEPTH_WRITEMASK]: true}} ]); t.end(); }); - -test.skip('setDeviceParameters#depthClearValue', (t) => { +test.skip('setDeviceParameters#depthClearValue', t => { // let value = getGLParameters(gl, [GL.DEPTH_CLEAR_VALUE])[GL.DEPTH_CLEAR_VALUE]; // t.is(value, 1, `got expected value ${stringify(value)}`); @@ -96,7 +95,7 @@ test.skip('setDeviceParameters#depthClearValue', (t) => { // HELPERS // type TestClause = {check: GLParameters} | {set: Parameters}; -type TestClause = {check?: GLParameters, set?: Parameters}; +type TestClause = {check?: GLParameters; set?: Parameters}; function testClauses(t: Test, name: string, clauses: TestClause[]): void { resetGLParameters(gl); diff --git a/modules/core-tests/test/adapter/device.spec.ts b/modules/core-tests/test/adapter/device.spec.ts index 3954b053ed..0e2f6050f9 100644 --- a/modules/core-tests/test/adapter/device.spec.ts +++ b/modules/core-tests/test/adapter/device.spec.ts @@ -4,7 +4,7 @@ import {getWebGLTestDevices, getTestDevices} from '@luma.gl/test-utils'; // import {luma} from '@luma.gl/core'; -test('WebGLDevice#info', (t) => { +test('WebGLDevice#info', t => { for (const device of getWebGLTestDevices()) { // TODO t.ok(typeof device.info.vendor === 'string', 'info.vendor ok'); @@ -14,16 +14,16 @@ test('WebGLDevice#info', (t) => { }); // Minimal test, extensive test in texture-formats.spec -test('WebGLDevice#isTextureFormatCompressed', async (t) => { +test('WebGLDevice#isTextureFormatCompressed', async t => { for (const device of await getTestDevices()) { // Just sanity check two types t.equal(device.isTextureFormatCompressed('rgba8unorm'), false); - t.equal(device.isTextureFormatCompressed('bc3-rgba-unorm'), true) + t.equal(device.isTextureFormatCompressed('bc3-rgba-unorm'), true); } t.end(); }); -test('WebGLDevice#lost (Promise)', async (t) => { +test('WebGLDevice#lost (Promise)', async t => { // const device = await luma.createDevice({webgl2: false}); // // Wrap in a promise to make sure tape waits for us @@ -41,7 +41,7 @@ test('WebGLDevice#lost (Promise)', async (t) => { t.end(); }); -test.skip('WebGLDevice#resize', (t) => { +test.skip('WebGLDevice#resize', t => { // Using default pixel ratio of 1 // update drawing buffer size to simulate webglDevice context // webglDevice.canvasContext.resize({width: 10, height: 20, useDevicePixels: 1}); diff --git a/modules/core-tests/test/adapter/helpers/parse-shader-compiler-log.spec.ts b/modules/core-tests/test/adapter/helpers/parse-shader-compiler-log.spec.ts index add4934988..d8178b7a5a 100644 --- a/modules/core-tests/test/adapter/helpers/parse-shader-compiler-log.spec.ts +++ b/modules/core-tests/test/adapter/helpers/parse-shader-compiler-log.spec.ts @@ -1,7 +1,7 @@ import test from 'tape-promise/tape'; import {parseShaderCompilerLog} from '@luma.gl/webgl/adapter/helpers/parse-shader-compiler-log'; -test('parseShaderCompilerLog', (t) => { +test('parseShaderCompilerLog', t => { const {ERROR_LOG, EXPECTED_MESSAGES} = getFixtures(); const messages = parseShaderCompilerLog(ERROR_LOG); // SHADER_SOURCE, SHADER_TYPE; t.deepEqual(messages, EXPECTED_MESSAGES, 'parseShaderCompilerLog generated correct messages'); @@ -33,121 +33,121 @@ ERROR: 0:994: 'project_scale' : no matching overloaded function found const EXPECTED_MESSAGES = [ { - message: '\'/\' : Zero divided by zero during constant folding generated NaN', + message: "'/' : Zero divided by zero during constant folding generated NaN", type: 'warning', lineNum: 264, linePos: 0 }, { - message: '\'/\' : Zero divided by zero during constant folding generated NaN', + message: "'/' : Zero divided by zero during constant folding generated NaN", type: 'warning', lineNum: 264, linePos: 0 }, { - message: '\'/\' : Divide by zero during constant folding', + message: "'/' : Divide by zero during constant folding", type: 'warning', lineNum: 294, linePos: 0 }, { - message: '\'/\' : Divide by zero during constant folding', + message: "'/' : Divide by zero during constant folding", type: 'warning', lineNum: 294, linePos: 0 }, { - message: '\'/\' : Zero divided by zero during constant folding generated NaN', + message: "'/' : Zero divided by zero during constant folding generated NaN", type: 'warning', lineNum: 344, linePos: 0 }, { - message: '\'/\' : Zero divided by zero during constant folding generated NaN', + message: "'/' : Zero divided by zero during constant folding generated NaN", type: 'warning', lineNum: 344, linePos: 0 }, { - message: '\'/\' : Zero divided by zero during constant folding generated NaN', + message: "'/' : Zero divided by zero during constant folding generated NaN", type: 'warning', lineNum: 447, linePos: 0 }, { - message: '\'/\' : Zero divided by zero during constant folding generated NaN', + message: "'/' : Zero divided by zero during constant folding generated NaN", type: 'warning', lineNum: 447, linePos: 0 }, { - message: '\'/\' : Zero divided by zero during constant folding generated NaN', + message: "'/' : Zero divided by zero during constant folding generated NaN", type: 'warning', lineNum: 470, linePos: 0 }, { - message: '\'/\' : Zero divided by zero during constant folding generated NaN', + message: "'/' : Zero divided by zero during constant folding generated NaN", type: 'warning', lineNum: 470, linePos: 0 }, { - message: '\'/\' : Zero divided by zero during constant folding generated NaN', + message: "'/' : Zero divided by zero during constant folding generated NaN", type: 'warning', lineNum: 557, linePos: 0 }, { - message: '\'/\' : Zero divided by zero during constant folding generated NaN', + message: "'/' : Zero divided by zero during constant folding generated NaN", type: 'warning', lineNum: 557, linePos: 0 }, { - message: '\'/\' : Zero divided by zero during constant folding generated NaN', + message: "'/' : Zero divided by zero during constant folding generated NaN", type: 'warning', lineNum: 580, linePos: 0 }, { - message: '\'/\' : Zero divided by zero during constant folding generated NaN', + message: "'/' : Zero divided by zero during constant folding generated NaN", type: 'warning', lineNum: 580, linePos: 0 }, { - message: '\'/\' : Zero divided by zero during constant folding generated NaN', + message: "'/' : Zero divided by zero during constant folding generated NaN", type: 'warning', lineNum: 669, linePos: 0 }, { - message: '\'/\' : Zero divided by zero during constant folding generated NaN', + message: "'/' : Zero divided by zero during constant folding generated NaN", type: 'warning', lineNum: 669, linePos: 0 }, { - message: '\'/\' : Zero divided by zero during constant folding generated NaN', + message: "'/' : Zero divided by zero during constant folding generated NaN", type: 'warning', lineNum: 681, linePos: 0 }, { - message: '\'/\' : Zero divided by zero during constant folding generated NaN', + message: "'/' : Zero divided by zero during constant folding generated NaN", type: 'warning', lineNum: 681, linePos: 0 }, { - message: '\'project_scale\' : no matching overloaded function found', + message: "'project_scale' : no matching overloaded function found", type: 'error', lineNum: 967, linePos: 0 }, { - message: '\'project_scale\' : no matching overloaded function found', + message: "'project_scale' : no matching overloaded function found", type: 'error', lineNum: 994, linePos: 0 diff --git a/modules/core-tests/test/adapter/resources/buffer.spec.ts b/modules/core-tests/test/adapter/resources/buffer.spec.ts index 84d6ee1f03..56786b49e0 100644 --- a/modules/core-tests/test/adapter/resources/buffer.spec.ts +++ b/modules/core-tests/test/adapter/resources/buffer.spec.ts @@ -21,7 +21,7 @@ test('Buffer#constructor/delete', t => { t.end(); }); -test('Buffer#constructor offset and size', async (t) => { +test('Buffer#constructor offset and size', async t => { const data = new Float32Array([1, 2, 3]); for (const device of getWebGLTestDevices()) { @@ -108,7 +108,7 @@ test('Buffer#construction', t => { t.end(); }); -test('Buffer#write', async (t) => { +test('Buffer#write', async t => { const expectedData = new Float32Array([1, 2, 3]); for (const device of getWebGLTestDevices()) { const buffer = device.createBuffer({usage: Buffer.VERTEX, byteLength: 12}); @@ -137,7 +137,7 @@ test('Buffer#write', async (t) => { t.end(); }); -test('Buffer#readAsync', async (t) => { +test('Buffer#readAsync', async t => { for (const device of getWebGLTestDevices()) { let data: TypedArray = new Float32Array([1, 2, 3]); let buffer = device.createBuffer({data}); @@ -150,7 +150,7 @@ test('Buffer#readAsync', async (t) => { receivedData = await buffer.readAsync(Float32Array.BYTES_PER_ELEMENT); f32Data = new Float32Array(receivedData.buffer); expectedData = new Float32Array([2, 3]); - t.deepEqual(f32Data, expectedData, 'Buffer.readAsync: with \'dstData\' parameter successful'); + t.deepEqual(f32Data, expectedData, "Buffer.readAsync: with 'dstData' parameter successful"); // receivedData = await buffer.readAsync({ // Float32Array.BYTES_PER_ELEMENT, @@ -182,7 +182,7 @@ test('Buffer#readAsync', async (t) => { t.end(); }); -test('Buffer#debugData', async (t) => { +test('Buffer#debugData', async t => { for (const device of getWebGLTestDevices()) { const buffer = device.createBuffer({usage: Buffer.VERTEX, byteLength: 24}); t.equal(buffer.debugData.byteLength, 24, 'Buffer.debugData is not null before write'); @@ -201,4 +201,3 @@ test('Buffer#debugData', async (t) => { t.end(); }); - diff --git a/modules/core-tests/test/adapter/resources/command-buffer.spec.ts b/modules/core-tests/test/adapter/resources/command-buffer.spec.ts index d0afac7f88..ab0dcf62bd 100644 --- a/modules/core-tests/test/adapter/resources/command-buffer.spec.ts +++ b/modules/core-tests/test/adapter/resources/command-buffer.spec.ts @@ -70,7 +70,7 @@ const COPY_TEXTURE_TO_BUFFER_FIXTURES: CopyTextureToBufferFixture[] = [ format: 'rgba8unorm', srcPixel: new Uint8Array([255, 128, 64, 32]), dstPixel: new Uint8Array([255, 128, 64, 32]), - dstOffset: 4, + dstOffset: 4 }, // { // // TODO: Framebuffer creation fails under Node (browser WebGL1 is fine) @@ -82,7 +82,7 @@ const COPY_TEXTURE_TO_BUFFER_FIXTURES: CopyTextureToBufferFixture[] = [ title: 'rgba32', format: 'rgba32float', srcPixel: new Float32Array([0.214, -32.23, 1242, -123.847]), - dstPixel: new Float32Array([0.214, -32.23, 1242, -123.847]), + dstPixel: new Float32Array([0.214, -32.23, 1242, -123.847]) }, { title: 'rgba32 + offset', @@ -102,21 +102,25 @@ const COPY_TEXTURE_TO_BUFFER_FIXTURES: CopyTextureToBufferFixture[] = [ title: 'rg32', format: 'rg32float', srcPixel: new Float32Array([-0.214, 32.23]), - dstPixel: new Float32Array([-0.214, 32.23, 0, 0]), + dstPixel: new Float32Array([-0.214, 32.23, 0, 0]) }, { title: 'r32', format: 'r32float', srcPixel: new Float32Array([0.124]), - dstPixel: new Float32Array([0.124, 0, 0, 0]), - }, + dstPixel: new Float32Array([0.124, 0, 0, 0]) + } ]; test('CommandBuffer#copyTextureToBuffer', async t => { for (const device of getWebGLTestDevices()) { for (const fixture of COPY_TEXTURE_TO_BUFFER_FIXTURES) { await testCopyTextureToBuffer(t, device, {...fixture}); - await testCopyTextureToBuffer(t, device, {...fixture, useFramebuffer: true, title: `${fixture.title} + framebuffer`}); + await testCopyTextureToBuffer(t, device, { + ...fixture, + useFramebuffer: true, + title: `${fixture.title} + framebuffer` + }); } } t.end(); @@ -163,9 +167,10 @@ async function testCopyTextureToBuffer( commandEncoder.finish(); commandEncoder.destroy(); - const color = srcPixel instanceof Uint8Array - ? await readAsyncU8(destination) - : await readAsyncF32(destination); + const color = + srcPixel instanceof Uint8Array + ? await readAsyncU8(destination) + : await readAsyncF32(destination); t.ok(abs(dstPixel[0] - color[0 + dstOffset]) < EPSILON, `reads "R" channel (${title})`); t.ok(abs(dstPixel[1] - color[1 + dstOffset]) < EPSILON, `reads "G" channel (${title})`); diff --git a/modules/core-tests/test/adapter/resources/framebuffer.spec.ts b/modules/core-tests/test/adapter/resources/framebuffer.spec.ts index 7c49079104..5c231c63b5 100644 --- a/modules/core-tests/test/adapter/resources/framebuffer.spec.ts +++ b/modules/core-tests/test/adapter/resources/framebuffer.spec.ts @@ -6,17 +6,17 @@ import {webglDevice, getWebGLTestDevices} from '@luma.gl/test-utils'; const TEST_CASES = [ { title: 'Default attachments', - getOpts: (device) => ({}), + getOpts: device => ({}), pass: false }, { title: 'No attachments', - getOpts: (device) => ({attachments: {}}), + getOpts: device => ({attachments: {}}), pass: false }, { title: 'Autocreated Depth Renderbuffer + Color Texture', - getOpts: (device) => ({ + getOpts: device => ({ colorAttachments: ['rgba8unorm-unsized'], depthStencilAttachment: 'depth16unorm' }), @@ -65,7 +65,7 @@ const TEST_CASES = [ // } ]; -test('WebGLDevice.createFramebuffer()', async (t) => { +test('WebGLDevice.createFramebuffer()', async t => { for (const testDevice of getWebGLTestDevices()) { t.throws(() => testDevice.createFramebuffer({}), 'Framebuffer without attachment fails'); @@ -84,7 +84,7 @@ test('WebGLDevice.createFramebuffer()', async (t) => { t.end(); }); -test('WebGLFramebuffer create and resize attachments', async (t) => { +test('WebGLFramebuffer create and resize attachments', async t => { for (const testDevice of getWebGLTestDevices()) { for (const tc of TEST_CASES) { let props; @@ -123,7 +123,7 @@ test('WebGLFramebuffer create and resize attachments', async (t) => { t.end(); }); -test.skip('WebGLFramebuffer resize', (t) => { +test.skip('WebGLFramebuffer resize', t => { const frameBufferOptions = { colorAttachments: [webglDevice.createTexture({})] // depthStencilAttachment: webglDevice.createRenderbuffer({format: GL.DEPTH_STENCIL}) @@ -131,7 +131,7 @@ test.skip('WebGLFramebuffer resize', (t) => { const framebuffer = webglDevice.createFramebuffer(frameBufferOptions); - framebuffer.resize({width: 1000,height: 1000}); + framebuffer.resize({width: 1000, height: 1000}); t.equals(framebuffer.width, 1000, 'Framebuffer width updated correctly on resize'); t.equals(framebuffer.height, 1000, 'Framebuffer height updated correctly on resize'); diff --git a/modules/core-tests/test/adapter/resources/sampler.spec.ts b/modules/core-tests/test/adapter/resources/sampler.spec.ts index eafed09ca6..200c83f0b3 100644 --- a/modules/core-tests/test/adapter/resources/sampler.spec.ts +++ b/modules/core-tests/test/adapter/resources/sampler.spec.ts @@ -8,7 +8,7 @@ import {Device, Sampler} from '@luma.gl/core'; export const SAMPLER_PARAMETERS = { minFilter: { linear: 'interpolated texel', - nearest: 'nearest texel', + nearest: 'nearest texel' }, magFilter: { @@ -22,21 +22,24 @@ export const SAMPLER_PARAMETERS = { }, addressModeU: { - 'repeat': 'use fractional part of texture coordinates', + repeat: 'use fractional part of texture coordinates', 'clamp-to-edge': 'clamp texture coordinates', - 'mirrored-repeat': 'use fractional part of texture coordinate if integer part is odd, otherwise `1 - frac' + 'mirrored-repeat': + 'use fractional part of texture coordinate if integer part is odd, otherwise `1 - frac' }, addressModeV: { - 'repeat': 'use fractional part of texture coordinates', + repeat: 'use fractional part of texture coordinates', 'clamp-to-edge': 'clamp texture coordinates', - 'mirrored-repeat': 'use fractional part of texture coordinate if integer part is odd, otherwise `1 - frac' + 'mirrored-repeat': + 'use fractional part of texture coordinate if integer part is odd, otherwise `1 - frac' }, addressModeW: { - 'repeat': 'use fractional part of texture coordinates', + repeat: 'use fractional part of texture coordinates', 'clamp-to-edge': 'clamp texture coordinates', - 'mirrored-repeat': 'use fractional part of texture coordinate if integer part is odd, otherwise `1 - frac' + 'mirrored-repeat': + 'use fractional part of texture coordinate if integer part is odd, otherwise `1 - frac' } /* @@ -68,13 +71,15 @@ test('WebGL#Sampler setParameters', t => { function testSampler(t: Test, device: Device): void { for (const pname in SAMPLER_PARAMETERS) { - const parameter = Number(pname); const values = SAMPLER_PARAMETERS[parameter]; for (const valueString in values) { const value = Number(valueString); const sampler = device.createSampler({[parameter]: value}); - t.ok(sampler instanceof Sampler, `${device.info.type} new Sampler({${pname}: ${valueString}}) constructed.`); + t.ok( + sampler instanceof Sampler, + `${device.info.type} new Sampler({${pname}: ${valueString}}) constructed.` + ); sampler.destroy(); } } diff --git a/modules/core-tests/test/adapter/resources/shader.spec.ts b/modules/core-tests/test/adapter/resources/shader.spec.ts index 88d18b1494..5fb63b9336 100644 --- a/modules/core-tests/test/adapter/resources/shader.spec.ts +++ b/modules/core-tests/test/adapter/resources/shader.spec.ts @@ -21,4 +21,4 @@ test.skip('Shader', async t => { `${device.info.type} device.createShader throws on bad shader source` ); } -}); \ No newline at end of file +}); diff --git a/modules/core-tests/test/adapter/resources/texture.spec.ts b/modules/core-tests/test/adapter/resources/texture.spec.ts index bd7a7ea08d..a6a1d3acb6 100644 --- a/modules/core-tests/test/adapter/resources/texture.spec.ts +++ b/modules/core-tests/test/adapter/resources/texture.spec.ts @@ -132,21 +132,21 @@ function testFormatDeduction(t, device: Device) { } } -test.skip('WebGL#Texture format deduction', async (t) => { +test.skip('WebGL#Texture format deduction', async t => { for (const device of await getTestDevices()) { testFormatDeduction(t, device); } t.end(); }); -test.skip('WebGL#Texture format creation', async (t) => { +test.skip('WebGL#Texture format creation', async t => { for (const device of await getTestDevices()) { testFormatCreation(t, device); } t.end(); }); -test.skip('WebGL#Texture format creation with data', async (t) => { +test.skip('WebGL#Texture format creation with data', async t => { for (const device of await getTestDevices()) { testFormatCreation(t, device, true); } diff --git a/modules/core-tests/test/adapter/texture-formats.spec.ts b/modules/core-tests/test/adapter/texture-formats.spec.ts index 069e7387ca..b398f7fe0a 100644 --- a/modules/core-tests/test/adapter/texture-formats.spec.ts +++ b/modules/core-tests/test/adapter/texture-formats.spec.ts @@ -4,10 +4,10 @@ import {getTestDevices} from '@luma.gl/test-utils'; // import {luma} from '@luma.gl/core'; // TODO - add full reference table, more exhaustive test -test('WebGLDevice#isTextureFormatCompressed', async (t) => { +test('WebGLDevice#isTextureFormatCompressed', async t => { for (const device of await getTestDevices()) { t.equal(device.isTextureFormatCompressed('rgba8unorm'), false); - t.equal(device.isTextureFormatCompressed('bc3-rgba-unorm'), true) + t.equal(device.isTextureFormatCompressed('bc3-rgba-unorm'), true); } t.end(); }); diff --git a/modules/core/src/adapter/attribute-utils/get-attribute-from-layouts.ts b/modules/core/src/adapter/attribute-utils/get-attribute-from-layouts.ts index e91a52c717..d26f3f32e9 100644 --- a/modules/core/src/adapter/attribute-utils/get-attribute-from-layouts.ts +++ b/modules/core/src/adapter/attribute-utils/get-attribute-from-layouts.ts @@ -53,8 +53,8 @@ type BufferAttributeInfo = { byteStride: number; }; -/** - * Map from "attribute names" to "resolved attribute infos" +/** + * Map from "attribute names" to "resolved attribute infos" * containing information about both buffer layouts and shader attribute declarations */ export function getAttributeInfosFromLayouts( @@ -72,8 +72,8 @@ export function getAttributeInfosFromLayouts( return attributeInfos; } -/** - * Array indexed by "location" holding "resolved attribute infos" +/** + * Array indexed by "location" holding "resolved attribute infos" */ export function getAttributeInfosByLocation( shaderLayout: ShaderLayout, diff --git a/modules/core/src/adapter/canvas-context.ts b/modules/core/src/adapter/canvas-context.ts index 9f110d27e2..026eb63138 100644 --- a/modules/core/src/adapter/canvas-context.ts +++ b/modules/core/src/adapter/canvas-context.ts @@ -120,7 +120,7 @@ export abstract class CanvasContext { // React to size changes if (this.canvas instanceof HTMLCanvasElement && props.autoResize) { - this.resizeObserver = new ResizeObserver((entries) => { + this.resizeObserver = new ResizeObserver(entries => { for (const entry of entries) { if (entry.target === this.canvas) { this.update(); @@ -145,7 +145,7 @@ export abstract class CanvasContext { useDevicePixels = useDevicePixels === undefined ? this.props.useDevicePixels : useDevicePixels; - if (!useDevicePixels || useDevicePixels as number <= 0) { + if (!useDevicePixels || (useDevicePixels as number) <= 0) { return 1; } @@ -320,7 +320,7 @@ function getPageLoadPromise(): Promise { if (isPageLoaded() || typeof window === 'undefined') { return Promise.resolve(); } - return new Promise((resolve) => { + return new Promise(resolve => { window.addEventListener('load', () => resolve()); }); } @@ -387,7 +387,7 @@ function scalePixels( height: number; } { const point = pixel as [number, number]; - + const x = scaleX(point[0], ratio, width); let y = scaleY(point[1], ratio, height, yInvert); diff --git a/modules/core/src/adapter/resources/buffer.ts b/modules/core/src/adapter/resources/buffer.ts index 8f57427625..2e2563380a 100644 --- a/modules/core/src/adapter/resources/buffer.ts +++ b/modules/core/src/adapter/resources/buffer.ts @@ -19,7 +19,7 @@ export type BufferProps = ResourceProps & { // TBD mappedAtCreation?: boolean; -} +}; /** Abstract GPU buffer */ export abstract class Buffer extends Resource { @@ -49,7 +49,9 @@ export abstract class Buffer extends Resource { static INDIRECT = 0x0100; static QUERY_RESOLVE = 0x0200; - override get [Symbol.toStringTag](): string { return 'Buffer'; } + override get [Symbol.toStringTag](): string { + return 'Buffer'; + } /** The usage with which this buffer was created */ readonly usage: number; @@ -82,7 +84,9 @@ export abstract class Buffer extends Resource { abstract readAsync(byteOffset?: number, byteLength?: number): Promise; /** Read data synchronously. @note WebGL2 only */ - readSyncWebGL(byteOffset?: number, byteLength?: number): Uint8Array { throw new Error('not implemented'); } + readSyncWebGL(byteOffset?: number, byteLength?: number): Uint8Array { + throw new Error('not implemented'); + } // PROTECTED METHODS (INTENDED FOR USE BY OTHER FRAMEWORK CODE ONLY) @@ -92,9 +96,16 @@ export abstract class Buffer extends Resource { debugData: ArrayBuffer = new ArrayBuffer(0); /** This doesn't handle partial non-zero offset updates correctly */ - protected _setDebugData(data: ArrayBufferView | ArrayBuffer | null, byteOffset: number, byteLength: number): void { + protected _setDebugData( + data: ArrayBufferView | ArrayBuffer | null, + byteOffset: number, + byteLength: number + ): void { const buffer: ArrayBuffer | null = ArrayBuffer.isView(data) ? data.buffer : data; - const debugDataLength = Math.min(data ? data.byteLength : byteLength, Buffer.DEBUG_DATA_MAX_LENGTH); + const debugDataLength = Math.min( + data ? data.byteLength : byteLength, + Buffer.DEBUG_DATA_MAX_LENGTH + ); if (data === null) { this.debugData = new ArrayBuffer(debugDataLength); } else if (byteOffset === 0 && byteLength === data.byteLength) { diff --git a/modules/core/src/adapter/resources/command-buffer.ts b/modules/core/src/adapter/resources/command-buffer.ts index a999b91de8..eff9a8e2c9 100644 --- a/modules/core/src/adapter/resources/command-buffer.ts +++ b/modules/core/src/adapter/resources/command-buffer.ts @@ -1,5 +1,5 @@ // luma.gl, MIT license -import { Device } from '../device'; +import {Device} from '../device'; import {Resource, ResourceProps} from './resource'; // interface Queue { @@ -17,8 +17,7 @@ import {Resource, ResourceProps} from './resource'; // // ): void; // } -export type CommandBufferProps = ResourceProps & { -}; +export type CommandBufferProps = ResourceProps & {}; /** * Encodes commands to queue that can be executed later @@ -27,7 +26,7 @@ export abstract class CommandBuffer extends Resource { static override defaultProps: Required = { ...Resource.defaultProps }; - + override get [Symbol.toStringTag](): string { return 'CommandBuffer'; } diff --git a/modules/core/src/adapter/resources/command-encoder.ts b/modules/core/src/adapter/resources/command-encoder.ts index eae4c4a6cc..0b92091f56 100644 --- a/modules/core/src/adapter/resources/command-encoder.ts +++ b/modules/core/src/adapter/resources/command-encoder.ts @@ -5,11 +5,11 @@ import {Buffer} from './buffer'; import {Texture} from './texture'; export type WriteBufferOptions = { - buffer: Buffer, - bufferOffset?: number, - data: BufferSource, - dataOffset?: number, - size?: number + buffer: Buffer; + bufferOffset?: number; + data: BufferSource; + dataOffset?: number; + size?: number; }; export type WriteTextureOptions = { @@ -23,7 +23,7 @@ export type WriteTextureOptions = { bytesPerRow: number; rowsPerImage: number; size: [number, number, number] | number[]; -} +}; export type CopyBufferToBufferOptions = { source: Buffer; @@ -37,7 +37,7 @@ export type CopyBufferToTextureOptions = { source: Buffer; byteOffset?: number; destination: Texture; - mipLevel?: number // = 0; + mipLevel?: number; // = 0; origin?: [number, number, number] | number[]; aspect?: 'all' | 'stencil-only' | 'depth-only'; bytesPerRow: number; @@ -131,7 +131,7 @@ export abstract class CommandEncoder extends Resource { ...Resource.defaultProps, measureExecutionTime: undefined }; - + override get [Symbol.toStringTag](): string { return 'CommandEncoder'; } @@ -139,7 +139,7 @@ export abstract class CommandEncoder extends Resource { constructor(device: Device, props: CommandEncoderProps) { super(device, props, CommandEncoder.defaultProps); } - + abstract finish(): void; // TODO - return the CommandBuffer? // beginRenderPass(GPURenderPassDescriptor descriptor): GPURenderPassEncoder; diff --git a/modules/core/src/adapter/resources/compute-pass.ts b/modules/core/src/adapter/resources/compute-pass.ts index 5d369fa157..78295578d7 100644 --- a/modules/core/src/adapter/resources/compute-pass.ts +++ b/modules/core/src/adapter/resources/compute-pass.ts @@ -8,7 +8,7 @@ export type ComputePassProps = ResourceProps & {}; export abstract class ComputePass extends Resource { static override defaultProps: Required = { ...Resource.defaultProps - } + }; override get [Symbol.toStringTag](): string { return 'ComputePass'; diff --git a/modules/core/src/adapter/resources/compute-pipeline.ts b/modules/core/src/adapter/resources/compute-pipeline.ts index 4d0f4a23e3..0463b51511 100644 --- a/modules/core/src/adapter/resources/compute-pipeline.ts +++ b/modules/core/src/adapter/resources/compute-pipeline.ts @@ -25,7 +25,7 @@ export abstract class ComputePipeline extends Resource { csEntryPoint: undefined, csConstants: {}, shaderLayout: [] - }; + }; override get [Symbol.toStringTag](): string { return 'ComputePipeline'; diff --git a/modules/core/src/adapter/resources/external-texture.ts b/modules/core/src/adapter/resources/external-texture.ts index 40cff71c66..22b584fab6 100644 --- a/modules/core/src/adapter/resources/external-texture.ts +++ b/modules/core/src/adapter/resources/external-texture.ts @@ -4,7 +4,7 @@ import {Resource, ResourceProps} from './resource'; export type ExternalTextureProps = ResourceProps & { source: HTMLVideoElement | null; colorSpace?: 'srgb'; -} +}; export abstract class ExternalTexture extends Resource { static override defaultProps: Required = { ...Resource.defaultProps, @@ -12,7 +12,9 @@ export abstract class ExternalTexture extends Resource { colorSpace: 'srgb' }; - override get [Symbol.toStringTag](): string { return 'ExternalTexture'; } + override get [Symbol.toStringTag](): string { + return 'ExternalTexture'; + } constructor(device: Device, props: ExternalTextureProps) { super(device, props, ExternalTexture.defaultProps); diff --git a/modules/core/src/adapter/resources/framebuffer.ts b/modules/core/src/adapter/resources/framebuffer.ts index 803b68eb3a..6b9a633f6f 100644 --- a/modules/core/src/adapter/resources/framebuffer.ts +++ b/modules/core/src/adapter/resources/framebuffer.ts @@ -1,7 +1,11 @@ // luma.gl, MIT license // Copyright (c) vis.gl contributors -import type {ColorTextureFormat, DepthStencilTextureFormat, TextureFormat} from '../types/texture-formats'; +import type { + ColorTextureFormat, + DepthStencilTextureFormat, + TextureFormat +} from '../types/texture-formats'; import type {Device} from '../device'; import {Resource, ResourceProps} from './resource'; import {Texture} from './texture'; @@ -26,7 +30,7 @@ export abstract class Framebuffer extends Resource { height: 1, colorAttachments: [], // ['rgba8unorm-unsized'], depthStencilAttachment: null // 'depth24plus-stencil8' - }; + }; override get [Symbol.toStringTag](): string { return 'Framebuffer'; @@ -54,7 +58,7 @@ export abstract class Framebuffer extends Resource { * Resizes all attachments * @note resize() destroys existing textures (if size has changed). */ - resize(size: {width: number; height: number;}): void; + resize(size: {width: number; height: number}): void; resize(size: [width: number, height: number]): void; resize(): void; resize(size?: {width: number; height: number} | [width: number, height: number]): void { @@ -106,7 +110,7 @@ export abstract class Framebuffer extends Resource { usage: Texture.RENDER_ATTACHMENT, format, width: this.width, - height: this.height, + height: this.height }); } diff --git a/modules/core/src/adapter/resources/render-pass.ts b/modules/core/src/adapter/resources/render-pass.ts index 6e3683ccba..f173379f56 100644 --- a/modules/core/src/adapter/resources/render-pass.ts +++ b/modules/core/src/adapter/resources/render-pass.ts @@ -1,6 +1,6 @@ // luma.gl, MIT license -import type {Device} from '../device' -import type { RenderPassParameters } from '../types/parameters'; +import type {Device} from '../device'; +import type {RenderPassParameters} from '../types/parameters'; // import {Binding} from '../types/shader-layout'; import {Resource, ResourceProps} from './resource'; // import {Buffer} from './buffer'; @@ -28,19 +28,18 @@ export type RenderPassProps = ResourceProps & { /** Indicates that the stencil component is read only. */ stencilReadOnly?: boolean; /** Whether to disable / discard the output of the rasterizer */ - discard?: boolean; + discard?: boolean; }; /** * A RenderPass instance is a required parameter to all draw calls. - * - * It holds a combination of + * + * It holds a combination of * - render targets (specified via a framebuffer) * - clear colors, read/write, discard information for the framebuffer attachments * - a couple of mutable parameters () */ export abstract class RenderPass extends Resource { - /** Default properties for RenderPass */ static override defaultProps: Required = { ...Resource.defaultProps, @@ -65,9 +64,9 @@ export abstract class RenderPass extends Resource { /** Call when rendering is done in this pass. */ abstract end(): void; - /** - * A small set of parameters can be changed between every draw call - * (viewport, scissorRect, blendColor, stencilReference) + /** + * A small set of parameters can be changed between every draw call + * (viewport, scissorRect, blendColor, stencilReference) */ abstract setParameters(parameters: RenderPassParameters): void; diff --git a/modules/core/src/adapter/resources/resource.ts b/modules/core/src/adapter/resources/resource.ts index 6cf0dd1253..b888a8b1df 100644 --- a/modules/core/src/adapter/resources/resource.ts +++ b/modules/core/src/adapter/resources/resource.ts @@ -9,7 +9,7 @@ export type ResourceProps = { handle?: any; /** User provided data stored on this resource */ userData?: {[key: string]: any}; -} +}; /** * Base class for GPU (WebGPU/WebGL) Resources @@ -19,9 +19,9 @@ export abstract class Resource { static defaultProps: Required = { id: 'undefined', handle: undefined, - userData: undefined, + userData: undefined }; - + abstract get [Symbol.toStringTag](): string; /** props.id, for debugging. */ @@ -38,7 +38,6 @@ export abstract class Resource { /** Attached resources will be destroyed when this resource is destroyed. Tracks auto-created "sub" resources. */ private _attachedResources = new Set>(); - /** * Create a new Resource. Called from Subclass */ @@ -49,7 +48,8 @@ export abstract class Resource { this._device = device; this.props = selectivelyMerge(props, defaultProps); - const id = this.props.id !== 'undefined' ? this.props.id as string : uid(this[Symbol.toStringTag]); + const id = + this.props.id !== 'undefined' ? (this.props.id as string) : uid(this[Symbol.toStringTag]); this.props.id = id; this.id = id; this.userData = this.props.userData || {}; @@ -84,7 +84,7 @@ export abstract class Resource { // ATTACHED RESOURCES - /** + /** * Attaches a resource. Attached resources are auto destroyed when this resource is destroyed * Called automatically when sub resources are auto created but can be called by application */ @@ -92,14 +92,14 @@ export abstract class Resource { this._attachedResources.add(resource); } - /** + /** * Detach an attached resource. The resource will no longer be auto-destroyed when this resource is destroyed. */ detachResource(resource: Resource): void { this._attachedResources.delete(resource); } - - /** + + /** * Destroys a resource (only if owned), and removes from the owned (auto-destroy) list for this resource. */ destroyAttachedResource(resource: Resource): void { diff --git a/modules/core/src/adapter/resources/sampler.ts b/modules/core/src/adapter/resources/sampler.ts index 3b8af3e305..dd5aab5b28 100644 --- a/modules/core/src/adapter/resources/sampler.ts +++ b/modules/core/src/adapter/resources/sampler.ts @@ -35,7 +35,7 @@ export type SamplerProps = ResourceProps & { /** Affects the mipmap image selection */ lodMaxClamp?: number; /** Maximum number of samples that can be taken of the texture during any one texture fetch */ - maxAnisotropy?: number; + maxAnisotropy?: number; /** How to compare reference values provided in shader shadow sampler calls with those pulled from the texture */ compare?: CompareFunction; }; @@ -58,7 +58,7 @@ export abstract class Sampler extends Resource { compare: 'less-equal', maxAnisotropy: 1 }; - + override get [Symbol.toStringTag](): string { return 'Sampler'; } diff --git a/modules/core/src/adapter/resources/texture-view.ts b/modules/core/src/adapter/resources/texture-view.ts index e0570e0954..2b2182cd75 100644 --- a/modules/core/src/adapter/resources/texture-view.ts +++ b/modules/core/src/adapter/resources/texture-view.ts @@ -19,7 +19,7 @@ export type TextureViewProps = ResourceProps & { /** How many mipmap levels, starting with baseMipLevel, are accessible to the texture view. */ mipLevelCount: number; /** The index of the first array layer accessible to the texture view. default 0 */ - baseArrayLayer?: number; + baseArrayLayer?: number; /** How many array layers, starting with baseArrayLayer, are accessible to the texture view. */ arrayLayerCount: number; }; diff --git a/modules/core/src/adapter/resources/texture.ts b/modules/core/src/adapter/resources/texture.ts index c913701705..fadbaaf150 100644 --- a/modules/core/src/adapter/resources/texture.ts +++ b/modules/core/src/adapter/resources/texture.ts @@ -14,14 +14,9 @@ import {TextureView, TextureViewProps} from './texture-view'; // required GPUTextureUsageFlags usage; /** Data types that can be used to initialize textures */ -export type TextureData = - TypedArray | ArrayBuffer | Buffer | ImageBitmap | HTMLImageElement - ; +export type TextureData = TypedArray | ArrayBuffer | Buffer | ImageBitmap | HTMLImageElement; -export type CubeTextureData = - Record | - Record> - ; +export type CubeTextureData = Record | Record>; export type ExternalTextureData = HTMLVideoElement; @@ -54,7 +49,7 @@ export type WebGPUTextureProps = ResourceProps & { format?: string; }; -/** +/** * @deprecated * @todo remove, are these even used anymore? */ @@ -101,14 +96,16 @@ export abstract class Texture extends sampler: {}, view: undefined! }; - + static COPY_SRC = 0x01; static COPY_DST = 0x02; static TEXTURE_BINDING = 0x04; static STORAGE_BINDING = 0x08; static RENDER_ATTACHMENT = 0x10; - override get [Symbol.toStringTag](): string { return 'Texture'; } + override get [Symbol.toStringTag](): string { + return 'Texture'; + } /** dimension of this texture */ readonly dimension: '1d' | '2d' | '2d-array' | 'cube' | 'cube-array' | '3d'; @@ -127,10 +124,14 @@ export abstract class Texture extends /** Default view for this texture */ abstract view: TextureView; - constructor(device: Device, props: Props, defaultProps = Texture.defaultProps as Required) { + constructor( + device: Device, + props: Props, + defaultProps = Texture.defaultProps as Required + ) { super(device, props, defaultProps); this.dimension = this.props.dimension; - this.format = this.props.format ; + this.format = this.props.format; this.width = this.props.width; this.height = this.props.height; this.depth = this.props.depth; diff --git a/modules/core/src/adapter/resources/vertex-array.ts b/modules/core/src/adapter/resources/vertex-array.ts index c79f3450dc..c9f310ba7f 100644 --- a/modules/core/src/adapter/resources/vertex-array.ts +++ b/modules/core/src/adapter/resources/vertex-array.ts @@ -62,7 +62,7 @@ export abstract class VertexArray extends Resource { abstract unbindAfterRender(renderPass: RenderPass): void; // DEPRECATED METHODS - + /** @deprecated Set constant attributes (WebGL only) */ setConstantWebGL(location: number, value: TypedArray | null): void { throw new Error('constant attributes not supported'); diff --git a/modules/core/src/adapter/type-utils/decode-attribute-type.ts b/modules/core/src/adapter/type-utils/decode-attribute-type.ts index 36ccf10e17..d4d0f7256f 100644 --- a/modules/core/src/adapter/type-utils/decode-attribute-type.ts +++ b/modules/core/src/adapter/type-utils/decode-attribute-type.ts @@ -5,7 +5,7 @@ import {VertexFormat, VertexType} from '../types/vertex-formats'; /** Information extracted from a ShaderAttributeInfo constant */ export type ShaderAttributeTypeInfo = { /** WGSL-style primitive data type, f32, i32, u32 */ - dataType: ShaderDataType, + dataType: ShaderDataType; /** Whether this is a normalized integer (that must be used as float) */ components: 1 | 2 | 3 | 4; /** Length in bytes of the data for one vertex */ @@ -19,7 +19,9 @@ export type ShaderAttributeTypeInfo = { }; /** Decodes a vertex type, returning byte length and flags (integer, signed, normalized) */ -export function decodeShaderAttributeType(attributeType: ShaderAttributeType): ShaderAttributeTypeInfo { +export function decodeShaderAttributeType( + attributeType: ShaderAttributeType +): ShaderAttributeTypeInfo { const [dataType, components] = TYPE_INFO[attributeType]; const integer: boolean = dataType === 'i32' || dataType === 'u32'; const signed: boolean = dataType !== 'u32'; @@ -37,13 +39,22 @@ export function decodeShaderAttributeType(attributeType: ShaderAttributeType): S } /** Get the "default" vertex format for a certain shader data type */ -function getCompatibleVertexFormat(dataType: ShaderDataType, components: 1 | 2 | 3 | 4): VertexFormat { +function getCompatibleVertexFormat( + dataType: ShaderDataType, + components: 1 | 2 | 3 | 4 +): VertexFormat { let vertexType: VertexType; switch (dataType) { - case 'f32': vertexType = 'float32'; break; - case 'i32': vertexType = 'sint32'; break; - case 'u32': vertexType = 'uint32'; break; - case 'f16': + case 'f32': + vertexType = 'float32'; + break; + case 'i32': + vertexType = 'sint32'; + break; + case 'u32': + vertexType = 'uint32'; + break; + case 'f16': return components <= 2 ? 'float16x2' : 'float16x4'; } // TODO logic does not work for float16 @@ -77,6 +88,6 @@ const TYPE_SIZES: Record = { f32: 4, f16: 2, i32: 4, - u32: 4, - // 'bool-webgl': 4, + u32: 4 + // 'bool-webgl': 4, }; diff --git a/modules/core/src/adapter/type-utils/decode-data-type.ts b/modules/core/src/adapter/type-utils/decode-data-type.ts index 1ea7eacf40..c804186e7e 100644 --- a/modules/core/src/adapter/type-utils/decode-data-type.ts +++ b/modules/core/src/adapter/type-utils/decode-data-type.ts @@ -2,7 +2,7 @@ import {DataType, NormalizedDataType} from '../types/vertex-formats'; export type DecodedVertexType = { /** WebGPU data type */ - dataType: DataType, + dataType: DataType; /** Length in bytes of the data for one vertex */ byteLength: number; /** Whether this is for integer or float vert */ diff --git a/modules/core/src/adapter/type-utils/decode-shader-types.ts b/modules/core/src/adapter/type-utils/decode-shader-types.ts index ebf8d0017b..bfd147c96b 100644 --- a/modules/core/src/adapter/type-utils/decode-shader-types.ts +++ b/modules/core/src/adapter/type-utils/decode-shader-types.ts @@ -4,10 +4,10 @@ import {assert} from '../../utils/assert'; import {ShaderUniformType, ShaderDataType} from '../types/shader-types'; -const UNIFORM_FORMATS: Record = { - 'f32': {type: 'f32', components: 1}, - 'i32': {type: 'i32', components: 1}, - 'u32': {type: 'u32', components: 1}, +const UNIFORM_FORMATS: Record = { + f32: {type: 'f32', components: 1}, + i32: {type: 'i32', components: 1}, + u32: {type: 'u32', components: 1}, // 'bool-webgl': {type: 'bool-webgl', components: 1}, 'vec2': {type: 'f32', components: 2}, 'vec3': {type: 'f32', components: 3}, @@ -26,15 +26,18 @@ const UNIFORM_FORMATS: Record': {type: 'f32', components: 12}, 'mat4x2': {type: 'f32', components: 8}, 'mat4x3': {type: 'f32', components: 12}, - 'mat4x4': {type: 'f32', components: 16}, + 'mat4x4': {type: 'f32', components: 16} }; /** Split a uniform type string into type and components */ -export function decodeShaderUniformType(format: ShaderUniformType): {type: ShaderDataType, components: number} { +export function decodeShaderUniformType(format: ShaderUniformType): { + type: ShaderDataType; + components: number; +} { const decoded = UNIFORM_FORMATS[format]; assert(format); return decoded; -} +} /** Align offset to 1, 2 or 4 elements (4, 8 or 16 bytes) */ export function alignTo(size: number, count: number): number { @@ -45,4 +48,3 @@ export function alignTo(size: number, count: number): number { default: return size + ((4 - (size % 4)) % 4); // Pad upwards to even multiple of 4 } } - diff --git a/modules/core/src/adapter/type-utils/decode-texture-format.ts b/modules/core/src/adapter/type-utils/decode-texture-format.ts index 4416d3850b..e6067ed991 100644 --- a/modules/core/src/adapter/type-utils/decode-texture-format.ts +++ b/modules/core/src/adapter/type-utils/decode-texture-format.ts @@ -2,7 +2,6 @@ import {TextureFormat} from '../types/texture-formats'; import {VertexType} from '../types/vertex-formats'; import {decodeVertexType} from './decode-data-type'; - // prettier-ignore const COMPRESSED_TEXTURE_FORMAT_PREFIXES = [ 'bc1', 'bc2', 'bc3', 'bc4', 'bc5', 'bc6', 'bc7', 'etc1', 'etc2', 'eac', 'atc', 'astc', 'pvrtc' @@ -21,10 +20,10 @@ export type DecodedTextureFormat = { integer: boolean; signed: boolean; normalized: boolean; -} +}; -/** - * Returns true if a texture format is GPU compressed +/** + * Returns true if a texture format is GPU compressed */ export function isTextureFormatCompressed(textureFormat: TextureFormat): boolean { return COMPRESSED_TEXTURE_FORMAT_PREFIXES.some(prefix => textureFormat.startsWith(prefix)); @@ -34,7 +33,7 @@ export function isTextureFormatCompressed(textureFormat: TextureFormat): boolean * Decodes a vertex format, returning type, components, byte length and flags (integer, signed, normalized) */ export function decodeTextureFormat(format: TextureFormat): DecodedTextureFormat { - const matches = REGEX.exec((format as string)); + const matches = REGEX.exec(format as string); if (matches) { const [, format, length, type, srgb, suffix] = matches; if (format) { @@ -59,19 +58,19 @@ export function decodeTextureFormat(format: TextureFormat): DecodedTextureFormat const EXCEPTIONS: Partial> = { // Packed 16 bit formats - 'rgba4unorm-webgl': {format: 'rgba', bpp: 2}, + 'rgba4unorm-webgl': {format: 'rgba', bpp: 2}, 'rgb565unorm-webgl': {format: 'rgb', bpp: 2}, - 'rgb5a1unorm-webgl': {format: 'rgba', bbp: 2}, + 'rgb5a1unorm-webgl': {format: 'rgba', bbp: 2}, // Packed 32 bit formats - 'rgb9e5ufloat': {format: 'rgb', bbp: 4}, - 'rg11b10ufloat': {format: 'rgb', bbp: 4}, - 'rgb10a2unorm': {format: 'rgba', bbp: 4}, + rgb9e5ufloat: {format: 'rgb', bbp: 4}, + rg11b10ufloat: {format: 'rgb', bbp: 4}, + rgb10a2unorm: {format: 'rgba', bbp: 4}, 'rgb10a2unorm-webgl': {format: 'rgba', bbp: 4}, // Depth/stencil - 'stencil8': {components: 1, bpp: 1, a: 'stencil'}, - 'depth16unorm': {components: 1, bpp: 2, a: 'depth'}, - 'depth24plus': {components: 1, bpp: 3, a: 'depth'}, - 'depth32float': {components: 1, bpp: 4, a: 'depth'}, + stencil8: {components: 1, bpp: 1, a: 'stencil'}, + depth16unorm: {components: 1, bpp: 2, a: 'depth'}, + depth24plus: {components: 1, bpp: 3, a: 'depth'}, + depth32float: {components: 1, bpp: 4, a: 'depth'}, 'depth24plus-stencil8': {components: 2, bpp: 4, a: 'depth-stencil'}, // "depth24unorm-stencil8" feature 'depth24unorm-stencil8': {components: 2, bpp: 4, a: 'depth-stencil'}, @@ -89,7 +88,7 @@ function decodeNonStandardFormat(format: TextureFormat): DecodedTextureFormat { components: data.components || data.format?.length || 1, byteLength: data.bpp || 1, srgb: false, - unsized: false + unsized: false } as DecodedTextureFormat; } diff --git a/modules/core/src/adapter/type-utils/wgsl-utils.ts b/modules/core/src/adapter/type-utils/wgsl-utils.ts index de2e86db28..2b027d263e 100644 --- a/modules/core/src/adapter/type-utils/wgsl-utils.ts +++ b/modules/core/src/adapter/type-utils/wgsl-utils.ts @@ -1,4 +1,4 @@ -import { ShaderAttributeType } from '../types/shader-types'; +import {ShaderAttributeType} from '../types/shader-types'; /** Predeclared aliases @see https://www.w3.org/TR/WGSL/#vector-types */ export const WGSL_TYPE_ALIAS_MAP: Record = { @@ -14,5 +14,5 @@ export const WGSL_TYPE_ALIAS_MAP: Record = { // Requires the f16 extension. vec2h: 'vec2', vec3h: 'vec3', - vec4h: 'vec4', + vec4h: 'vec4' }; diff --git a/modules/core/src/adapter/types/accessor.ts b/modules/core/src/adapter/types/accessor.ts index 370b35d019..e01e59a509 100644 --- a/modules/core/src/adapter/types/accessor.ts +++ b/modules/core/src/adapter/types/accessor.ts @@ -14,7 +14,7 @@ export interface AccessorObject { offset?: number; // can now be described with single WebGPU-style `format` string - // + // stride?: number; /** @deprecated - Use accessor.stepMode */ diff --git a/modules/core/src/adapter/types/buffer-layout.ts b/modules/core/src/adapter/types/buffer-layout.ts index 2533f1818a..48aa32b399 100644 --- a/modules/core/src/adapter/types/buffer-layout.ts +++ b/modules/core/src/adapter/types/buffer-layout.ts @@ -1,15 +1,15 @@ import type {VertexFormat} from './vertex-formats'; -/** - * Provides specific details about the memory layout of the actual buffers +/** + * Provides specific details about the memory layout of the actual buffers * that will be provided to a `RenderPipeline`. - * + * * BufferLayout lets the application describe whether - * - A single buffer can be used for multiple attributes (using interleaving or offsets), + * - A single buffer can be used for multiple attributes (using interleaving or offsets), * - The data format of the memory being supplied to a specific shader attribute. - * - * `BufferLayout` complements the "static" attribute declarations in a ShaderLayout - * with information about the "dynamic" memory layout of each buffer that will be bound + * + * `BufferLayout` complements the "static" attribute declarations in a ShaderLayout + * with information about the "dynamic" memory layout of each buffer that will be bound * to the render pipeline. */ @@ -59,4 +59,3 @@ export type BufferAttributeLayout = { /** Sum up any the "global" offset (or 0) and the offset each stride (for interleaved data). */ byteOffset: number; }; - diff --git a/modules/core/src/adapter/types/shader-layout.ts b/modules/core/src/adapter/types/shader-layout.ts index 053b533dca..4b53cd50f4 100644 --- a/modules/core/src/adapter/types/shader-layout.ts +++ b/modules/core/src/adapter/types/shader-layout.ts @@ -149,7 +149,12 @@ type StorageTextureBindingLayout = { // BINDINGS /** Binding value */ -export type Binding = TextureView | Texture | Sampler | Buffer | {buffer: Buffer; offset?: number; size?: number}; +export type Binding = + | TextureView + | Texture + | Sampler + | Buffer + | {buffer: Buffer; offset?: number; size?: number}; // SHADER LAYOUTS diff --git a/modules/core/src/adapter/types/texture-formats.ts b/modules/core/src/adapter/types/texture-formats.ts index 8d1a6206d2..dd2a9b6970 100644 --- a/modules/core/src/adapter/types/texture-formats.ts +++ b/modules/core/src/adapter/types/texture-formats.ts @@ -6,163 +6,163 @@ export type TextureFormat = ColorTextureFormat | DepthStencilTextureFormat; /** Depth and stencil texture formats */ export type DepthStencilTextureFormat = - 'stencil8' | - 'depth16unorm' | - 'depth24plus' | - 'depth24plus-stencil8' | - 'depth32float' | + | 'stencil8' + | 'depth16unorm' + | 'depth24plus' + | 'depth24plus-stencil8' + | 'depth32float' // device.features.has('depth24unorm-stencil8') - 'depth24unorm-stencil8' | + | 'depth24unorm-stencil8' // device.features.has('depth32float-stencil8') - 'depth32float-stencil8'; + | 'depth32float-stencil8'; /** Texture formats for color attachments */ -export type ColorTextureFormat = WebGPUColorTextureFormat | WebGL2ColorTextureFormat | UnsizedColorTextureFormat; +export type ColorTextureFormat = + | WebGPUColorTextureFormat + | WebGL2ColorTextureFormat + | UnsizedColorTextureFormat; export type WebGPUColorTextureFormat = // 8-bit formats - 'r8unorm' | - 'r8snorm' | - 'r8uint' | - 'r8sint' | + | 'r8unorm' + | 'r8snorm' + | 'r8uint' + | 'r8sint' // 16-bit formats - 'r16uint' | - 'r16sint' | - 'r16float' | - 'rg8unorm' | - 'rg8snorm' | - 'rg8uint' | - 'rg8sint' | + | 'r16uint' + | 'r16sint' + | 'r16float' + | 'rg8unorm' + | 'rg8snorm' + | 'rg8uint' + | 'rg8sint' // 32-bit formats - 'r32uint' | - 'r32sint' | - 'r32float' | - 'rg16uint' | - 'rg16sint' | - 'rg16float' | - 'rgba8unorm' | - 'rgba8unorm-srgb' | - 'rgba8snorm' | - 'rgba8uint' | - 'rgba8sint' | - 'bgra8unorm' | - 'bgra8unorm-srgb' | + | 'r32uint' + | 'r32sint' + | 'r32float' + | 'rg16uint' + | 'rg16sint' + | 'rg16float' + | 'rgba8unorm' + | 'rgba8unorm-srgb' + | 'rgba8snorm' + | 'rgba8uint' + | 'rgba8sint' + | 'bgra8unorm' + | 'bgra8unorm-srgb' // Packed 32-bit formats - 'rgb9e5ufloat' | - 'rgb10a2unorm' | - 'rg11b10ufloat' | + | 'rgb9e5ufloat' + | 'rgb10a2unorm' + | 'rg11b10ufloat' // 64-bit formats - 'rg32uint' | - 'rg32sint' | - 'rg32float' | - 'rgba16uint' | - 'rgba16sint' | - 'rgba16float' | + | 'rg32uint' + | 'rg32sint' + | 'rg32float' + | 'rgba16uint' + | 'rgba16sint' + | 'rgba16float' // 128-bit formats - 'rgba32uint' | - 'rgba32sint' | - 'rgba32float' | + | 'rgba32uint' + | 'rgba32sint' + | 'rgba32float' // BC compressed formats usable if 'texture-compression-bc' is both // supported by the device/user agent and enabled in requestDevice. - 'bc1-rgba-unorm' | - 'bc1-rgba-unorm-srgb' | - 'bc2-rgba-unorm' | - 'bc2-rgba-unorm-srgb' | - 'bc3-rgba-unorm' | - 'bc3-rgba-unorm-srgb' | - 'bc4-r-unorm' | - 'bc4-r-snorm' | - 'bc5-rg-unorm' | - 'bc5-rg-snorm' | - 'bc6h-rgb-ufloat' | - 'bc6h-rgb-float' | - 'bc7-rgba-unorm' | - 'bc7-rgba-unorm-srgb' | + | 'bc1-rgba-unorm' + | 'bc1-rgba-unorm-srgb' + | 'bc2-rgba-unorm' + | 'bc2-rgba-unorm-srgb' + | 'bc3-rgba-unorm' + | 'bc3-rgba-unorm-srgb' + | 'bc4-r-unorm' + | 'bc4-r-snorm' + | 'bc5-rg-unorm' + | 'bc5-rg-snorm' + | 'bc6h-rgb-ufloat' + | 'bc6h-rgb-float' + | 'bc7-rgba-unorm' + | 'bc7-rgba-unorm-srgb' // ETC2 compressed formats usable if "texture-compression-etc2" is both // supported by the device/user agent and enabled in requestDevice. - 'etc2-rgb8unorm' | - 'etc2-rgb8unorm-srgb' | - 'etc2-rgb8a1unorm' | - 'etc2-rgb8a1unorm-srgb' | - 'etc2-rgba8unorm' | - 'etc2-rgba8unorm-srgb' | - 'eac-r11unorm' | - 'eac-r11snorm' | - 'eac-rg11unorm' | - 'eac-rg11snorm' | + | 'etc2-rgb8unorm' + | 'etc2-rgb8unorm-srgb' + | 'etc2-rgb8a1unorm' + | 'etc2-rgb8a1unorm-srgb' + | 'etc2-rgba8unorm' + | 'etc2-rgba8unorm-srgb' + | 'eac-r11unorm' + | 'eac-r11snorm' + | 'eac-rg11unorm' + | 'eac-rg11snorm' // ASTC compressed formats usable if "texture-compression-astc" is both // supported by the device/user agent and enabled in requestDevice. - 'astc-4x4-unorm' | - 'astc-4x4-unorm-srgb' | - 'astc-5x4-unorm' | - 'astc-5x4-unorm-srgb' | - 'astc-5x5-unorm' | - 'astc-5x5-unorm-srgb' | - 'astc-6x5-unorm' | - 'astc-6x5-unorm-srgb' | - 'astc-6x6-unorm' | - 'astc-6x6-unorm-srgb' | - 'astc-8x5-unorm' | - 'astc-8x5-unorm-srgb' | - 'astc-8x6-unorm' | - 'astc-8x6-unorm-srgb' | - 'astc-8x8-unorm' | - 'astc-8x8-unorm-srgb' | - 'astc-10x5-unorm' | - 'astc-10x5-unorm-srgb' | - 'astc-10x6-unorm' | - 'astc-10x6-unorm-srgb' | - 'astc-10x8-unorm' | - 'astc-10x8-unorm-srgb' | - 'astc-10x10-unorm' | - 'astc-10x10-unorm-srgb' | - 'astc-12x10-unorm' | - 'astc-12x10-unorm-srgb' | - 'astc-12x12-unorm' | - 'astc-12x12-unorm-srgb' - ; + | 'astc-4x4-unorm' + | 'astc-4x4-unorm-srgb' + | 'astc-5x4-unorm' + | 'astc-5x4-unorm-srgb' + | 'astc-5x5-unorm' + | 'astc-5x5-unorm-srgb' + | 'astc-6x5-unorm' + | 'astc-6x5-unorm-srgb' + | 'astc-6x6-unorm' + | 'astc-6x6-unorm-srgb' + | 'astc-8x5-unorm' + | 'astc-8x5-unorm-srgb' + | 'astc-8x6-unorm' + | 'astc-8x6-unorm-srgb' + | 'astc-8x8-unorm' + | 'astc-8x8-unorm-srgb' + | 'astc-10x5-unorm' + | 'astc-10x5-unorm-srgb' + | 'astc-10x6-unorm' + | 'astc-10x6-unorm-srgb' + | 'astc-10x8-unorm' + | 'astc-10x8-unorm-srgb' + | 'astc-10x10-unorm' + | 'astc-10x10-unorm-srgb' + | 'astc-12x10-unorm' + | 'astc-12x10-unorm-srgb' + | 'astc-12x12-unorm' + | 'astc-12x12-unorm-srgb'; /** Unsized texture formats (the only formats supported by WebGL1) */ export type UnsizedColorTextureFormat = // 'r8unorm-unsized' | // 'ra8unorm-unsized' | - 'rgb8unorm-unsized' | - 'rgba8unorm-unsized' + 'rgb8unorm-unsized' | 'rgba8unorm-unsized'; // 'rgb8unorm-srgb-unsized' | // 'rgba8unorm-srgb-unsized' - ; /** Sized formats unique to WebGL 2. Some will perhaps be added to WebGPU standard? */ export type WebGL2ColorTextureFormat = - 'r16unorm-webgl' | - 'r16snorm-webgl' | - 'rgba4unorm-webgl' | - 'rgb565unorm-webgl' | - 'rgb5a1unorm-webgl' | - 'rgb8unorm-webgl' | - 'rgb8snorm-webgl' | - 'rg16unorm-webgl' | - 'rg16snorm-webgl' | - 'rgb10a2unorm-webgl' | - 'rgb16unorm-webgl' | - 'rgb16snorm-webgl' | - 'rgba16unorm-webgl' | - 'rgba16snorm-webgl' | - 'rgb32float-webgl' | - 'bc1-rgb-unorm-webgl' | - 'bc1-rgb-unorm-srgb-webgl' | - 'pvrtc-rgb4unorm-webgl' | - 'pvrtc-rgba4unorm-webgl' | - 'pvrtc-rbg2unorm-webgl' | - 'pvrtc-rgba2unorm-webgl' | - 'etc1-rbg-unorm-webgl' | - 'atc-rgb-unorm-webgl' | - 'atc-rgba-unorm-webgl' | - 'atc-rgbai-unorm-webgl'; + | 'r16unorm-webgl' + | 'r16snorm-webgl' + | 'rgba4unorm-webgl' + | 'rgb565unorm-webgl' + | 'rgb5a1unorm-webgl' + | 'rgb8unorm-webgl' + | 'rgb8snorm-webgl' + | 'rg16unorm-webgl' + | 'rg16snorm-webgl' + | 'rgb10a2unorm-webgl' + | 'rgb16unorm-webgl' + | 'rgb16snorm-webgl' + | 'rgba16unorm-webgl' + | 'rgba16snorm-webgl' + | 'rgb32float-webgl' + | 'bc1-rgb-unorm-webgl' + | 'bc1-rgb-unorm-srgb-webgl' + | 'pvrtc-rgb4unorm-webgl' + | 'pvrtc-rgba4unorm-webgl' + | 'pvrtc-rbg2unorm-webgl' + | 'pvrtc-rgba2unorm-webgl' + | 'etc1-rbg-unorm-webgl' + | 'atc-rgb-unorm-webgl' + | 'atc-rgba-unorm-webgl' + | 'atc-rgbai-unorm-webgl'; diff --git a/modules/core/src/adapter/types/types.ts b/modules/core/src/adapter/types/types.ts index ff5a19121c..de9d93a7e8 100644 --- a/modules/core/src/adapter/types/types.ts +++ b/modules/core/src/adapter/types/types.ts @@ -12,7 +12,7 @@ export type UniformValue = number | boolean | Readonly; // Float32A // BINDINGS /** Buffer bindings */ -export type Binding = Texture | Buffer | {buffer: Buffer, offset?: number, size?: number}; +export type Binding = Texture | Buffer | {buffer: Buffer; offset?: number; size?: number}; // BINDING LAYOUTS @@ -25,7 +25,7 @@ type BufferBindingLayout = { type: 'uniform' | 'storage' | 'read-only-storage'; hasDynamicOffset?: boolean; minBindingSize?: number; -} +}; /** Describes a texture binding */ type TextureBindingLayout = { @@ -47,7 +47,10 @@ type StorageTextureBindingLayout = { viewDimension?: '1d' | '2d' | '2d-array' | 'cube' | 'cube-array' | '3d'; }; -export type BindingDeclaration = BufferBindingLayout | TextureBindingLayout | StorageTextureBindingLayout; +export type BindingDeclaration = + | BufferBindingLayout + | TextureBindingLayout + | StorageTextureBindingLayout; // TEXTURE VIEWS @@ -60,7 +63,7 @@ export type TextureView = { // ATTACHMENTS (See Framebuffer) /** - * Framebuffer attachments lets the user specify the textures that will be used for a RenderPass, + * Framebuffer attachments lets the user specify the textures that will be used for a RenderPass, * together with some additional options for how to clear. */ export type ColorAttachment = { @@ -80,7 +83,7 @@ export type ColorAttachment = { }; /** - * Framebuffer attachments lets the user specify the depth stencil texture that will be used for a RenderPass, + * Framebuffer attachments lets the user specify the depth stencil texture that will be used for a RenderPass, * together with some additional options for how to clear. */ export type DepthStencilAttachment = { diff --git a/modules/core/src/adapter/types/vertex-formats.ts b/modules/core/src/adapter/types/vertex-formats.ts index 4165f6fc3f..6a3314b8ca 100644 --- a/modules/core/src/adapter/types/vertex-formats.ts +++ b/modules/core/src/adapter/types/vertex-formats.ts @@ -28,8 +28,7 @@ export type NormalizedDataType = // | 'unorm32' // | 'snorm32' | 'float32' - | 'float16' - ; + | 'float16'; /** Describes the type (without number of components) of a vertex format */ export type VertexType = NormalizedDataType; @@ -87,5 +86,4 @@ export type VertexFormat = | 'float32' | 'float32x2' | 'float32x3' - | 'float32x4' - ; + | 'float32x4'; diff --git a/modules/core/src/index.ts b/modules/core/src/index.ts index 205e8251ba..62b5d569c0 100644 --- a/modules/core/src/index.ts +++ b/modules/core/src/index.ts @@ -115,7 +115,11 @@ export {UniformStore} from './lib/uniforms/uniform-store'; // TYPE UTILS export {decodeVertexFormat} from './adapter/type-utils/decode-vertex-format'; export {decodeTextureFormat} from './adapter/type-utils/decode-texture-format'; -export {getDataTypeFromTypedArray, getTypedArrayFromDataType, getVertexFormatFromAttribute} from './adapter/type-utils/vertex-format-from-attribute'; +export { + getDataTypeFromTypedArray, + getTypedArrayFromDataType, + getVertexFormatFromAttribute +} from './adapter/type-utils/vertex-format-from-attribute'; // SHADER TYPE UTILS export {decodeShaderUniformType} from './adapter/type-utils/decode-shader-types'; @@ -143,13 +147,7 @@ export {isUniformValue, splitUniformsAndBindings} from './lib/uniforms/uniform'; export {formatValue} from './utils/format-value'; export {stubRemovedMethods} from './utils/stub-methods'; export {checkProps} from './utils/check-props'; -export { - setPathPrefix, - loadFile, - loadImage, - loadImageBitmap, - loadScript -} from './utils/load-file'; +export {setPathPrefix, loadFile, loadImage, loadImageBitmap, loadScript} from './utils/load-file'; export {getScratchArrayBuffer, getScratchArray, fillArray} from './utils/array-utils-flat'; export {makeRandomNumberGenerator, random} from './utils/random'; export {deepEqual} from './utils/deep-equal'; diff --git a/modules/core/src/init.ts b/modules/core/src/init.ts index 34febf3fbf..0e212db397 100644 --- a/modules/core/src/init.ts +++ b/modules/core/src/init.ts @@ -4,10 +4,10 @@ import {lumaStats} from './utils/stats-manager'; declare global { // eslint-disable-next-line no-var - var luma: any + var luma: any; } -/** +/** * By adding the result of init() to Device.VERSION we guarantee it will be called * @returns version */ @@ -22,7 +22,9 @@ function initializeLuma(): string { // luma.log.break[], set to gl funcs, luma.log.profile[] set to model names`; if (globalThis.luma && globalThis.luma.VERSION !== VERSION) { - throw new Error(`luma.gl - multiple VERSIONs detected: ${globalThis.luma.VERSION} vs ${VERSION}`); + throw new Error( + `luma.gl - multiple VERSIONs detected: ${globalThis.luma.VERSION} vs ${VERSION}` + ); } if (!globalThis.luma) { @@ -37,7 +39,7 @@ function initializeLuma(): string { // A global stats object that various components can add information to // E.g. see webgl/resource.js - stats: lumaStats, + stats: lumaStats }; } diff --git a/modules/core/src/lib/compiler-log/compiler-message.ts b/modules/core/src/lib/compiler-log/compiler-message.ts index c0d7a4cac6..afca7fcb38 100644 --- a/modules/core/src/lib/compiler-log/compiler-message.ts +++ b/modules/core/src/lib/compiler-log/compiler-message.ts @@ -7,4 +7,4 @@ export type CompilerMessage = { message: string; lineNum: number; linePos: number; -} +}; diff --git a/modules/core/src/lib/compiler-log/format-compiler-log.ts b/modules/core/src/lib/compiler-log/format-compiler-log.ts index 8d602d1e27..10ac900945 100644 --- a/modules/core/src/lib/compiler-log/format-compiler-log.ts +++ b/modules/core/src/lib/compiler-log/format-compiler-log.ts @@ -65,7 +65,9 @@ ${numberedLines}${positionIndicator}${message.type.toUpperCase()}: ${message.mes `; } return options?.html - ? `
${message.type.toUpperCase()}: ${message.message}
` + ? `
${message.type.toUpperCase()}: ${ + message.message + }
` : `${message.type.toUpperCase()}: ${message.message}`; } @@ -109,5 +111,5 @@ function escapeHTML(unsafe: string): string { .replaceAll('<', '<') .replaceAll('>', '>') .replaceAll('"', '"') - .replaceAll('\'', '''); + .replaceAll("'", '''); } diff --git a/modules/core/src/lib/luma.ts b/modules/core/src/lib/luma.ts index efca13521e..3d30f5a0f9 100644 --- a/modules/core/src/lib/luma.ts +++ b/modules/core/src/lib/luma.ts @@ -9,7 +9,6 @@ import {lumaStats} from '../utils/stats-manager'; import {log} from '../utils/log'; import {assert} from '../utils/assert'; - const deviceList = new Map(); /** @@ -38,7 +37,9 @@ export class luma { static getSupportedDevices(): string[] { // @ts-expect-error - return Array.from(deviceList).filter(Device => Device.isSupported()).map(Device => Device.type); + return Array.from(deviceList) + .filter(Device => Device.isSupported()) + .map(Device => Device.type); } static setDefaultDeviceProps(props: DeviceProps): void { @@ -47,7 +48,7 @@ export class luma { /** Creates a device. Asynchronously. */ static async createDevice(props: DeviceProps = {}): Promise { - props = {...Device.defaultProps, ...props} + props = {...Device.defaultProps, ...props}; if (props.gl) { props.type = 'webgl'; } @@ -77,6 +78,8 @@ export class luma { } break; } - throw new Error('No matching device found. Ensure `@luma.gl/webgl` and/or `@luma.gl/webgpu` modules are imported.'); + throw new Error( + 'No matching device found. Ensure `@luma.gl/webgl` and/or `@luma.gl/webgpu` modules are imported.' + ); } } diff --git a/modules/core/src/lib/uniforms/uniform-block.ts b/modules/core/src/lib/uniforms/uniform-block.ts index 3d976891f2..63b11a79cb 100644 --- a/modules/core/src/lib/uniforms/uniform-block.ts +++ b/modules/core/src/lib/uniforms/uniform-block.ts @@ -12,7 +12,9 @@ import {arrayEqual, arrayCopy} from '../../utils/array-equal'; * A uniform block holds values of the of uniform values for one uniform block / buffer. * It also does some book keeping on what has changed, to minimize unnecessary writes to uniform buffers. */ -export class UniformBlock = Record> { +export class UniformBlock< + TUniforms extends Record = Record +> { name: string; uniforms: Record = {} as Record; diff --git a/modules/core/src/lib/uniforms/uniform-buffer-layout.ts b/modules/core/src/lib/uniforms/uniform-buffer-layout.ts index 75e6398a71..af39839e2e 100644 --- a/modules/core/src/lib/uniforms/uniform-buffer-layout.ts +++ b/modules/core/src/lib/uniforms/uniform-buffer-layout.ts @@ -4,9 +4,9 @@ import type {UniformValue} from '../../adapter/types/types'; import {decodeShaderUniformType, alignTo} from '../../adapter/type-utils/decode-shader-types'; import {getScratchArrayBuffer} from '../../utils/array-utils-flat'; import {isNumberArray} from '../../utils/is-array'; -import { log } from '../../utils/log'; +import {log} from '../../utils/log'; -/** +/** * Smallest buffer size that can be used for uniform buffers. * TODO - does this depend on device? */ @@ -17,12 +17,11 @@ const minBufferSize: number = 1024; * Supports manual listing of uniforms */ export class UniformBufferLayout { - readonly layout: Record = {}; + readonly layout: Record = {}; /** number of bytes needed for buffer allocation */ readonly byteLength: number; - /** Create a new UniformBufferLayout given a map of attributes. */ constructor(uniformTypes: Record) { /** number of 4 byte slots taken */ @@ -61,7 +60,7 @@ export class UniformBufferLayout { }; // TODO is this needed? // typedArrays.i32.fill(0); - + for (const [name, value] of Object.entries(uniformValues)) { const uniformLayout = this.layout[name]; if (!uniformLayout) { @@ -74,7 +73,9 @@ export class UniformBufferLayout { const typedArray = typedArrays[type]; if (size === 1) { if (typeof value !== 'number' && typeof value !== 'boolean') { - log.warn(`Supplied value for single component uniform ${name} is not a number: ${value}`)(); + log.warn( + `Supplied value for single component uniform ${name} is not a number: ${value}` + )(); // eslint-disable-next-line no-continue continue; } @@ -83,7 +84,9 @@ export class UniformBufferLayout { } else { const numericArray = isNumberArray(value); if (!numericArray) { - log.warn(`Supplied value for multi component / array uniform ${name} is not a numeric array: ${value}`)(); + log.warn( + `Supplied value for multi component / array uniform ${name} is not a numeric array: ${value}` + )(); // eslint-disable-next-line no-continue continue; } @@ -94,7 +97,7 @@ export class UniformBufferLayout { } return new Uint8Array(arrayBuffer); - } + } /** Does this layout have a field with specified name */ has(name: string) { @@ -102,7 +105,7 @@ export class UniformBufferLayout { } /** Get offset and size for a field with specified name */ - get(name: string): {offset: number, size: number} | undefined { + get(name: string): {offset: number; size: number} | undefined { const layout = this.layout[name]; return layout; } diff --git a/modules/core/src/lib/uniforms/uniform.ts b/modules/core/src/lib/uniforms/uniform.ts index 91be2f00ce..5dd48d039d 100644 --- a/modules/core/src/lib/uniforms/uniform.ts +++ b/modules/core/src/lib/uniforms/uniform.ts @@ -3,18 +3,20 @@ import type {Binding} from '../../adapter/types/shader-layout'; import {isNumberArray} from '../../utils/is-array'; export function isUniformValue(value: unknown): boolean { - return isNumberArray(value) !== null || (typeof value === 'number') || (typeof value === 'boolean'); + return isNumberArray(value) !== null || typeof value === 'number' || typeof value === 'boolean'; } type UniformsAndBindings = { - bindings: Record, - uniforms: Record + bindings: Record; + uniforms: Record; }; -export function splitUniformsAndBindings(uniforms: Record): UniformsAndBindings { - const result: UniformsAndBindings = { bindings: {}, uniforms: {} } +export function splitUniformsAndBindings( + uniforms: Record +): UniformsAndBindings { + const result: UniformsAndBindings = {bindings: {}, uniforms: {}}; Object.keys(uniforms).forEach(name => { const uniform = uniforms[name]; - if(isUniformValue(uniform)) { + if (isUniformValue(uniform)) { result.uniforms[name] = uniform as UniformValue; } else { result.bindings[name] = uniform as Binding; diff --git a/modules/core/src/types.ts b/modules/core/src/types.ts index e24f60ccea..a40757f82a 100644 --- a/modules/core/src/types.ts +++ b/modules/core/src/types.ts @@ -25,9 +25,9 @@ export interface ConstructorOf { new (...args: unknown[]): T; } -/** - * Make specific fields in a type optional. Granular version of `Partial` - * @example +/** + * Make specific fields in a type optional. Granular version of `Partial` + * @example * type PartialProps = PartialBy, 'device' | 'canvas'> */ export type PartialBy = Omit & Partial>; diff --git a/modules/core/src/utils/array-utils-flat.ts b/modules/core/src/utils/array-utils-flat.ts index a663efafd6..4a10edd062 100644 --- a/modules/core/src/utils/array-utils-flat.ts +++ b/modules/core/src/utils/array-utils-flat.ts @@ -18,13 +18,18 @@ export function getScratchArray(Type: any, length: number): TypedArray { } // Uses copyWithin to significantly speed up typed array value filling -export function fillArray(options: {target: NumberArray, source: NumberArray, start?: number, count?: number}): NumberArray { +export function fillArray(options: { + target: NumberArray; + source: NumberArray; + start?: number; + count?: number; +}): NumberArray { const {target, source, start = 0, count = 1} = options; const length = source.length; const total = count * length; let copied = 0; for (let i = start; copied < length; copied++) { - target[i++] = source[copied] ; + target[i++] = source[copied]; } while (copied < total) { diff --git a/modules/core/src/utils/check-props.ts b/modules/core/src/utils/check-props.ts index 7443fb55e1..392e337551 100644 --- a/modules/core/src/utils/check-props.ts +++ b/modules/core/src/utils/check-props.ts @@ -36,7 +36,11 @@ export type PropChecks = { deprecatedProps?: Record; }; -export function checkProps(className: string, props: Record, propChecks: PropChecks): Record { +export function checkProps( + className: string, + props: Record, + propChecks: PropChecks +): Record { const {removedProps = {}, deprecatedProps = {}, replacedProps = {}} = propChecks; // removedProps: Removed props no longer supported diff --git a/modules/core/src/utils/format-value.ts b/modules/core/src/utils/format-value.ts index f7864aaf20..f6813bbf6e 100644 --- a/modules/core/src/utils/format-value.ts +++ b/modules/core/src/utils/format-value.ts @@ -2,7 +2,7 @@ import type {NumberArray} from '../types'; /** TODO @deprecated - delete when confident that probe.gl logging implements all opts */ -function formatArrayValue(v: NumberArray, opts: {maxElts?: number, size?: number} = {}): string { +function formatArrayValue(v: NumberArray, opts: {maxElts?: number; size?: number} = {}): string { const {maxElts = 16, size = 1} = opts; let string = '['; for (let i = 0; i < v.length && i < maxElts; ++i) { @@ -16,7 +16,10 @@ function formatArrayValue(v: NumberArray, opts: {maxElts?: number, size?: number } /** TODO @deprecated - delete when confident that probe.gl logging implements all opts */ -export function formatValue(v: number | NumberArray | unknown, opts: {isInteger?: boolean, size?: number} = {}): string { +export function formatValue( + v: number | NumberArray | unknown, + opts: {isInteger?: boolean; size?: number} = {} +): string { const EPSILON = 1e-16; const {isInteger = false} = opts; if (Array.isArray(v) || ArrayBuffer.isView(v)) { diff --git a/modules/core/src/utils/load-file.ts b/modules/core/src/utils/load-file.ts index 66eeac8ce1..a4e7fc3c4e 100644 --- a/modules/core/src/utils/load-file.ts +++ b/modules/core/src/utils/load-file.ts @@ -83,7 +83,8 @@ export async function loadScript(scriptUrl: string, scriptId?: string): Promise< return new Promise((resolve, reject) => { script.onload = resolve; - script.onerror = (error) => reject(new Error(`Unable to load script '${scriptUrl}': ${error as string}`)); + script.onerror = error => + reject(new Error(`Unable to load script '${scriptUrl}': ${error as string}`)); head.appendChild(script); }); } diff --git a/modules/core/src/utils/stats-manager.ts b/modules/core/src/utils/stats-manager.ts index 5e09d3ce75..acf9d6c36c 100644 --- a/modules/core/src/utils/stats-manager.ts +++ b/modules/core/src/utils/stats-manager.ts @@ -1,7 +1,7 @@ import {Stats} from '@probe.gl/stats'; -/** - * Helper class managing a collection of probe.gl stats objects +/** + * Helper class managing a collection of probe.gl stats objects */ export class StatsManager { stats = new Map(); diff --git a/modules/core/src/utils/stub-methods.ts b/modules/core/src/utils/stub-methods.ts index aefdc3a151..67e36c1684 100644 --- a/modules/core/src/utils/stub-methods.ts +++ b/modules/core/src/utils/stub-methods.ts @@ -1,7 +1,12 @@ import {log} from './log'; // Install stubs for removed methods -export function stubRemovedMethods(instance: any, className: string, version: string, methodNames: string[]) { +export function stubRemovedMethods( + instance: any, + className: string, + version: string, + methodNames: string[] +) { const upgradeMessage = `See luma.gl ${version} Upgrade Guide at \ https://luma.gl/docs/upgrade-guide`; diff --git a/modules/core/test/adapter/attribute-utils/get-attribute-from-layout.spec.ts b/modules/core/test/adapter/attribute-utils/get-attribute-from-layout.spec.ts index 085950f6dd..c994bf86de 100644 --- a/modules/core/test/adapter/attribute-utils/get-attribute-from-layout.spec.ts +++ b/modules/core/test/adapter/attribute-utils/get-attribute-from-layout.spec.ts @@ -185,7 +185,11 @@ const resolvedLayout = { test('getAttributeInfosFromLayouts', t => { const result = getAttributeInfosFromLayouts(shaderLayout, bufferLayout); for (const key of Object.keys(resolvedLayout)) { - t.deepEqual(result[key], resolvedLayout[key], `Interleaved attribute info for ${key} are correct`); + t.deepEqual( + result[key], + resolvedLayout[key], + `Interleaved attribute info for ${key} are correct` + ); // t.comment(JSON.stringify(result[key], null, 2)); } t.end(); diff --git a/modules/core/test/adapter/canvas-context.spec.ts b/modules/core/test/adapter/canvas-context.spec.ts index a8be50c516..d4c2b4e344 100644 --- a/modules/core/test/adapter/canvas-context.spec.ts +++ b/modules/core/test/adapter/canvas-context.spec.ts @@ -9,11 +9,13 @@ import {isBrowser} from '@probe.gl/env'; class TestCanvasContext extends CanvasContext { // @ts-expect-error readonly device = {}; - getCurrentFramebuffer(): Framebuffer { throw new Error('test'); } + getCurrentFramebuffer(): Framebuffer { + throw new Error('test'); + } update() {} } -test('CanvasContext', (t) => { +test('CanvasContext', t => { if (isBrowser()) { let canvasContext = new TestCanvasContext(); t.ok(canvasContext); diff --git a/modules/core/test/adapter/type-utils/decode-texture-format.spec.ts b/modules/core/test/adapter/type-utils/decode-texture-format.spec.ts index 9ec9a6075c..3654ff7a1d 100644 --- a/modules/core/test/adapter/type-utils/decode-texture-format.spec.ts +++ b/modules/core/test/adapter/type-utils/decode-texture-format.spec.ts @@ -16,7 +16,7 @@ const TEST_CASES: {format: TextureFormat, result: any}[] = [ {format: 'r16float', result: { format: 'r', components: 1, dataType: 'float16', byteLength: 2, integer: false, signed: false, normalized: false, srgb: false, webgl: false, unsized: false }} ]; -test('api#decodeTextureFormat', (t) => { +test('api#decodeTextureFormat', t => { for (const tc of TEST_CASES) { const decoded = decodeTextureFormat(tc.format); t.deepEqual( diff --git a/modules/core/test/adapter/type-utils/decode-vertex-format.spec.ts b/modules/core/test/adapter/type-utils/decode-vertex-format.spec.ts index c5a4ef95ae..05479c7d32 100644 --- a/modules/core/test/adapter/type-utils/decode-vertex-format.spec.ts +++ b/modules/core/test/adapter/type-utils/decode-vertex-format.spec.ts @@ -22,7 +22,7 @@ const TEST_CASES: {format: VertexFormat, result: any}[] = [ {format: 'sint32x2', result: {type: 'sint32', components: 2, byteLength: 8, integer: true, signed: true, normalized: false}}, ]; -test('api#decodeVertexFormat', (t) => { +test('api#decodeVertexFormat', t => { for (const tc of TEST_CASES) { const decoded = decodeVertexFormat(tc.format); t.deepEqual( diff --git a/modules/core/test/adapter/type-utils/vertex-format-from-attribute.spec.ts b/modules/core/test/adapter/type-utils/vertex-format-from-attribute.spec.ts index 46a8aafd51..9a508d48b1 100644 --- a/modules/core/test/adapter/type-utils/vertex-format-from-attribute.spec.ts +++ b/modules/core/test/adapter/type-utils/vertex-format-from-attribute.spec.ts @@ -1,9 +1,20 @@ // luma.gl, MIT license import test from 'tape-promise/tape'; -import {VertexFormat, getDataTypeFromTypedArray, getTypedArrayFromDataType, getVertexFormatFromAttribute} from '@luma.gl/core'; +import { + VertexFormat, + getDataTypeFromTypedArray, + getTypedArrayFromDataType, + getVertexFormatFromAttribute +} from '@luma.gl/core'; import type {TypedArray, TypedArrayConstructor} from '@luma.gl/core'; -const TEST_CASES: {typedArray: TypedArray, size?: number, normalized?: boolean, result?: VertexFormat, error?: string}[] = [ +const TEST_CASES: { + typedArray: TypedArray; + size?: number; + normalized?: boolean; + result?: VertexFormat; + error?: string; +}[] = [ {typedArray: new Uint8Array(), size: 4, result: 'uint8x4'}, {typedArray: new Uint8ClampedArray(), size: 2, result: 'uint8x2'}, {typedArray: new Int8Array(), size: 4, result: 'sint8x4'}, @@ -25,7 +36,7 @@ const TEST_CASES: {typedArray: TypedArray, size?: number, normalized?: boolean, {typedArray: new Int32Array(), error: 'Missing attribute size'}, {typedArray: new Uint8Array(), size: 1, error: 'Bad 16 bit alignment'}, {typedArray: new Int16Array(), size: 3, error: 'Bad 32 bit alignment'}, - {typedArray: new Float64Array(), size: 2, error: 'Unknown array format'}, + {typedArray: new Float64Array(), size: 2, error: 'Unknown array format'} ]; test('api#getVertexFormatFromAttribute', t => { @@ -54,7 +65,7 @@ const ARRAY_TEST_CASES: {typedArray: TypedArrayConstructor}[] = [ {typedArray: Uint32Array}, {typedArray: Int32Array}, {typedArray: Float32Array} -] +]; test('api#getDataTypeFromTypedArray', t => { for (const {typedArray} of ARRAY_TEST_CASES) { diff --git a/modules/core/test/lib/compiler-log/format-compiler-log.spec.ts b/modules/core/test/lib/compiler-log/format-compiler-log.spec.ts index c50fd60b32..aee1a557c7 100644 --- a/modules/core/test/lib/compiler-log/format-compiler-log.spec.ts +++ b/modules/core/test/lib/compiler-log/format-compiler-log.spec.ts @@ -7,121 +7,121 @@ const ERROR_LOG: CompilerMessage[] = [ type: 'warning', linePos: 0, lineNum: 264, - message: '\'/\' : Zero divided by zero during constant folding generated NaN' + message: "'/' : Zero divided by zero during constant folding generated NaN" }, { type: 'warning', linePos: 0, lineNum: 264, - message: '\'/\' : Zero divided by zero during constant folding generated NaN' + message: "'/' : Zero divided by zero during constant folding generated NaN" }, { type: 'warning', linePos: 0, lineNum: 294, - message: '\'/\' : Divide by zero during constant folding' + message: "'/' : Divide by zero during constant folding" }, { type: 'warning', linePos: 0, lineNum: 294, - message: '\'/\' : Divide by zero during constant folding' + message: "'/' : Divide by zero during constant folding" }, { type: 'warning', linePos: 0, lineNum: 344, - message: '\'/\' : Zero divided by zero during constant folding generated NaN' + message: "'/' : Zero divided by zero during constant folding generated NaN" }, { type: 'warning', linePos: 0, lineNum: 344, - message: '\'/\' : Zero divided by zero during constant folding generated NaN' + message: "'/' : Zero divided by zero during constant folding generated NaN" }, { type: 'warning', linePos: 0, lineNum: 447, - message: '\'/\' : Zero divided by zero during constant folding generated NaN' + message: "'/' : Zero divided by zero during constant folding generated NaN" }, { type: 'warning', linePos: 0, lineNum: 447, - message: '\'/\' : Zero divided by zero during constant folding generated NaN' + message: "'/' : Zero divided by zero during constant folding generated NaN" }, { type: 'warning', linePos: 0, lineNum: 470, - message: '\'/\' : Zero divided by zero during constant folding generated NaN' + message: "'/' : Zero divided by zero during constant folding generated NaN" }, { type: 'warning', linePos: 0, lineNum: 470, - message: '\'/\' : Zero divided by zero during constant folding generated NaN' + message: "'/' : Zero divided by zero during constant folding generated NaN" }, { type: 'warning', linePos: 0, lineNum: 557, - message: '\'/\' : Zero divided by zero during constant folding generated NaN' + message: "'/' : Zero divided by zero during constant folding generated NaN" }, { type: 'warning', linePos: 0, lineNum: 557, - message: '\'/\' : Zero divided by zero during constant folding generated NaN' + message: "'/' : Zero divided by zero during constant folding generated NaN" }, { type: 'warning', linePos: 0, lineNum: 580, - message: '\'/\' : Zero divided by zero during constant folding generated NaN' + message: "'/' : Zero divided by zero during constant folding generated NaN" }, { type: 'warning', linePos: 0, lineNum: 580, - message: '\'/\' : Zero divided by zero during constant folding generated NaN' + message: "'/' : Zero divided by zero during constant folding generated NaN" }, { type: 'warning', linePos: 0, lineNum: 669, - message: '\'/\' : Zero divided by zero during constant folding generated NaN' + message: "'/' : Zero divided by zero during constant folding generated NaN" }, { type: 'warning', linePos: 0, lineNum: 669, - message: '\'/\' : Zero divided by zero during constant folding generated NaN' + message: "'/' : Zero divided by zero during constant folding generated NaN" }, { type: 'warning', linePos: 0, lineNum: 681, - message: '\'/\' : Zero divided by zero during constant folding generated NaN' + message: "'/' : Zero divided by zero during constant folding generated NaN" }, { type: 'warning', linePos: 0, lineNum: 681, - message: '\'/\' : Zero divided by zero during constant folding generated NaN' + message: "'/' : Zero divided by zero during constant folding generated NaN" }, { type: 'error', linePos: 0, lineNum: 967, - message: '\'project_scale\' : no matching overloaded function found' + message: "'project_scale' : no matching overloaded function found" }, { type: 'error', linePos: 0, lineNum: 994, - message: '\'project_scale\' : no matching overloaded function found' + message: "'project_scale' : no matching overloaded function found" } ]; @@ -1255,7 +1255,7 @@ ERROR: \'project_scale\' : no matching overloaded function found `; -test('formatGLSLError', (t) => { +test('formatGLSLError', t => { let formattedLog = formatCompilerLog(ERROR_LOG, SHADER_SOURCE, {showSourceCode: 'issues'}); compareStrings(t, formattedLog, EXPECTED, 'formatGLSLError generated correct error'); t.equal(formattedLog, EXPECTED, 'formatGLSLError generated correct error'); @@ -1263,7 +1263,10 @@ test('formatGLSLError', (t) => { // Run with various options to ensure we don't crash // TODO - add output checks formattedLog = formatCompilerLog(ERROR_LOG, SHADER_SOURCE, {showSourceCode: 'all'}); - formattedLog = formatCompilerLog(ERROR_LOG, SHADER_SOURCE, {showSourceCode: 'issues', html: true}); + formattedLog = formatCompilerLog(ERROR_LOG, SHADER_SOURCE, { + showSourceCode: 'issues', + html: true + }); formattedLog = formatCompilerLog(ERROR_LOG, SHADER_SOURCE, {showSourceCode: 'all', html: true}); t.end(); @@ -1278,6 +1281,6 @@ function compareStrings(t: Test, string1: string, string2: string, message?: str if (lines1[i] !== lines2[i]) { t.comment(`line ${i + 1}: '${lines1[i]}' --> '${lines2[i]}'`); return; - } + } } } diff --git a/modules/core/test/lib/utils/array-utils-flat.spec.ts b/modules/core/test/lib/utils/array-utils-flat.spec.ts index 29a06eb68d..d80c71b77b 100644 --- a/modules/core/test/lib/utils/array-utils-flat.spec.ts +++ b/modules/core/test/lib/utils/array-utils-flat.spec.ts @@ -12,12 +12,12 @@ const FILL_ARRAY_TEST_CASES = [ } ]; -test('flatten#import', (t) => { +test('flatten#import', t => { t.ok(typeof fillArray === 'function', 'fillArray imported OK'); t.end(); }); -test('fillArray#tests', (t) => { +test('fillArray#tests', t => { for (const tc of FILL_ARRAY_TEST_CASES) { const result = fillArray(tc.arguments); t.deepEqual(result, tc.result, `fillArray ${tc.title} returned expected result`); diff --git a/modules/core/test/lib/utils/format-value.spec.ts b/modules/core/test/lib/utils/format-value.spec.ts index 366ff59285..32a4c89066 100644 --- a/modules/core/test/lib/utils/format-value.spec.ts +++ b/modules/core/test/lib/utils/format-value.spec.ts @@ -57,8 +57,8 @@ const FORMAT_VALUE_TEST_CASES = [ } ]; -test('formatValue', (t) => { - FORMAT_VALUE_TEST_CASES.forEach((tc) => { +test('formatValue', t => { + FORMAT_VALUE_TEST_CASES.forEach(tc => { t.equal(formatValue(tc.value, tc.opts), tc.result); }); t.end(); diff --git a/modules/core/test/lib/utils/uniform.spec.ts b/modules/core/test/lib/utils/uniform.spec.ts index c5a7c41cc9..cd80372e61 100644 --- a/modules/core/test/lib/utils/uniform.spec.ts +++ b/modules/core/test/lib/utils/uniform.spec.ts @@ -3,14 +3,14 @@ import {WEBGLSampler, WEBGLTexture} from '@luma.gl/webgl'; import {getWebGLTestDevices} from '@luma.gl/test-utils'; import test from 'tape-promise/tape'; -test('isUniformValue', (t) => { +test('isUniformValue', t => { t.ok(isUniformValue(3), 'Number is uniform value'); t.ok(isUniformValue(3.412), 'Number is uniform value'); t.ok(isUniformValue(0), 'Number is uniform value'); t.ok(isUniformValue(false), 'Boolean is uniform value'); t.ok(isUniformValue(true), 'Boolean is uniform value'); - t.ok(isUniformValue([1,2,3,4]), 'Number array is uniform value'); - t.ok(isUniformValue(new Float32Array([1,2,3,4])), 'Number array is uniform value'); + t.ok(isUniformValue([1, 2, 3, 4]), 'Number array is uniform value'); + t.ok(isUniformValue(new Float32Array([1, 2, 3, 4])), 'Number array is uniform value'); const device = getWebGLTestDevices()[0]; t.notOk(isUniformValue(new WEBGLTexture(device, {})), 'WEBGLTexture is not a uniform value'); @@ -18,18 +18,22 @@ test('isUniformValue', (t) => { t.end(); }); -test('splitUniformsAndBindings', (t) => { +test('splitUniformsAndBindings', t => { const device = getWebGLTestDevices()[0]; const mixed: Parameters[0] = { - 'array': [1,2,3,4], - 'boolean': true, - 'float32array': new Float32Array([1,2,3,4]), - 'number': 123, - 'sampler': new WEBGLSampler(device, {}), - 'texture': new WEBGLTexture(device, {}) - } + array: [1, 2, 3, 4], + boolean: true, + float32array: new Float32Array([1, 2, 3, 4]), + number: 123, + sampler: new WEBGLSampler(device, {}), + texture: new WEBGLTexture(device, {}) + }; const {bindings, uniforms} = splitUniformsAndBindings(mixed); t.deepEquals(Object.keys(bindings), ['sampler', 'texture'], 'bindings correctly extracted'); - t.deepEquals(Object.keys(uniforms), ['array', 'boolean', 'float32array', 'number'], 'bindings correctly extracted'); + t.deepEquals( + Object.keys(uniforms), + ['array', 'boolean', 'float32array', 'number'], + 'bindings correctly extracted' + ); t.end(); }); diff --git a/modules/core/test/lib/utils/utils.spec.ts b/modules/core/test/lib/utils/utils.spec.ts index 2187226610..21b5fb7aba 100644 --- a/modules/core/test/lib/utils/utils.spec.ts +++ b/modules/core/test/lib/utils/utils.spec.ts @@ -1,7 +1,7 @@ import {uid} from '@luma.gl/core'; import test from 'tape-promise/tape'; -test('Utils#uid', (t) => { +test('Utils#uid', t => { t.ok(typeof uid() === 'string', 'Type of uid() is correct'); t.equal(uid('prefix').indexOf('prefix'), 0, 'uid("prefix") starts with prefix'); t.end(); diff --git a/modules/engine/src/animation-loop/animation-loop-template.ts b/modules/engine/src/animation-loop/animation-loop-template.ts index 49fd93217a..4a77bd597b 100644 --- a/modules/engine/src/animation-loop/animation-loop-template.ts +++ b/modules/engine/src/animation-loop/animation-loop-template.ts @@ -3,21 +3,23 @@ import type {AnimationProps} from './animation-props'; /** * Minimal class that represents a "componentized" rendering life cycle * (resource construction, repeated rendering, resource destruction) - * - * @note A motivation for this class compared to the raw animation loop is - * that it simplifies TypeScript code by allowing resources to be typed unconditionally + * + * @note A motivation for this class compared to the raw animation loop is + * that it simplifies TypeScript code by allowing resources to be typed unconditionally * since they are allocated in the constructor rather than in onInitialized - * + * * @note Introduced in luma.gl v9 - * - * @example AnimationLoopTemplate is intended to be subclassed, + * + * @example AnimationLoopTemplate is intended to be subclassed, * but the subclass should not be instantiated directly. Instead the subclass - * (i.e. the constructor of the subclass) should be used + * (i.e. the constructor of the subclass) should be used * as an argument to create an AnimationLoop. */ export abstract class AnimationLoopTemplate { constructor(animationProps?: AnimationProps) {} - async onInitialize(animationProps: AnimationProps): Promise { return null; } + async onInitialize(animationProps: AnimationProps): Promise { + return null; + } abstract onRender(animationProps: AnimationProps): unknown; abstract onFinalize(animationProps: AnimationProps): void; } diff --git a/modules/engine/src/animation-loop/animation-loop.ts b/modules/engine/src/animation-loop/animation-loop.ts index 057e8fa43b..69516f3b98 100644 --- a/modules/engine/src/animation-loop/animation-loop.ts +++ b/modules/engine/src/animation-loop/animation-loop.ts @@ -32,23 +32,25 @@ export type MutableAnimationLoopProps = { autoResizeViewport?: boolean; autoResizeDrawingBuffer?: boolean; useDevicePixels?: number | boolean; -} +}; const DEFAULT_ANIMATION_LOOP_PROPS: Required = { device: null!, onAddHTML: () => '', - onInitialize: async () => { return null; }, + onInitialize: async () => { + return null; + }, onRender: () => {}, onFinalize: () => {}, - onError: (error) => console.error(error), // eslint-disable-line no-console + onError: error => console.error(error), // eslint-disable-line no-console stats: luma.stats.get(`animation-loop-${statIdCounter++}`), // view parameters useDevicePixels: true, autoResizeViewport: false, - autoResizeDrawingBuffer: false, + autoResizeDrawingBuffer: false }; /** Convenient animation loop */ @@ -148,7 +150,6 @@ export class AnimationLoop { this._running = true; try { - let appContext; if (!this._initialized) { this._initialized = true; @@ -174,7 +175,7 @@ export class AnimationLoop { return this; } catch (err: unknown) { - const error = err instanceof Error ? err : new Error('Unknown error') + const error = err instanceof Error ? err : new Error('Unknown error'); this.props.onError(error); // this._running = false; // TODO throw error; @@ -242,7 +243,7 @@ export class AnimationLoop { this.setNeedsRedraw('waitForRender'); if (!this._nextFramePromise) { - this._nextFramePromise = new Promise((resolve) => { + this._nextFramePromise = new Promise(resolve => { this._resolveNextFrame = resolve; }); } @@ -461,7 +462,7 @@ export class AnimationLoop { } } - _getSizeAndAspect(): {width: number; height: number; aspect: number} { + _getSizeAndAspect(): {width: number; height: number; aspect: number} { if (!this.device) { return {width: 1, height: 1, aspect: 1}; } @@ -488,7 +489,12 @@ export class AnimationLoop { // @ts-expect-error Expose on canvasContext if (this.props.autoResizeViewport && this.device.gl) { // @ts-expect-error Expose canvasContext - this.device.gl.viewport(0, 0, this.device.gl.drawingBufferWidth, this.device.gl.drawingBufferHeight); + this.device.gl.viewport( + 0, + 0, + this.device.gl.drawingBufferWidth, + this.device.gl.drawingBufferHeight + ); } } diff --git a/modules/engine/src/animation-loop/animation-props.ts b/modules/engine/src/animation-loop/animation-props.ts index cb718f75ce..d5cb787ff3 100644 --- a/modules/engine/src/animation-loop/animation-props.ts +++ b/modules/engine/src/animation-loop/animation-props.ts @@ -1,5 +1,5 @@ import {Device} from '@luma.gl/core'; -import {Timeline} from '../animation/timeline' +import {Timeline} from '../animation/timeline'; import type {AnimationLoop} from './animation-loop'; /** Properties passed to every render frame */ diff --git a/modules/engine/src/animation-loop/make-animation-loop.ts b/modules/engine/src/animation-loop/make-animation-loop.ts index 05778b4794..ac754b3006 100644 --- a/modules/engine/src/animation-loop/make-animation-loop.ts +++ b/modules/engine/src/animation-loop/make-animation-loop.ts @@ -1,20 +1,26 @@ // luma.gl, MIT license import {luma} from '@luma.gl/core'; -import {AnimationLoopTemplate} from './animation-loop-template' -import {AnimationLoop, AnimationLoopProps} from './animation-loop' +import {AnimationLoopTemplate} from './animation-loop-template'; +import {AnimationLoop, AnimationLoopProps} from './animation-loop'; import type {AnimationProps} from './animation-props'; -export type MakeAnimationLoopProps = Omit; +export type MakeAnimationLoopProps = Omit< + AnimationLoopProps, + 'onCreateDevice' | 'onInitialize' | 'onRedraw' | 'onFinalize' +>; /** Instantiates and runs the render loop */ -export function makeAnimationLoop(AnimationLoopTemplateCtor: typeof AnimationLoopTemplate, props?: MakeAnimationLoopProps): AnimationLoop { +export function makeAnimationLoop( + AnimationLoopTemplateCtor: typeof AnimationLoopTemplate, + props?: MakeAnimationLoopProps +): AnimationLoop { let renderLoop: AnimationLoopTemplate | null = null; const device = props?.device || luma.createDevice(); // Create an animation loop; const animationLoop = new AnimationLoop({ - ... props, + ...props, device, @@ -26,7 +32,7 @@ export function makeAnimationLoop(AnimationLoopTemplateCtor: typeof AnimationLoo }, onRender: (animationProps: AnimationProps) => renderLoop?.onRender(animationProps), - + onFinalize: (animationProps: AnimationProps) => renderLoop?.onFinalize(animationProps) }); @@ -35,7 +41,7 @@ export function makeAnimationLoop(AnimationLoopTemplateCtor: typeof AnimationLoo // @ts-ignore // eslint-disable-next-line no-invalid-this return this.AnimationLoopTemplateCtor.info; - } + }; // Start the loop automatically // animationLoop.start(); diff --git a/modules/engine/src/animation/timeline.ts b/modules/engine/src/animation/timeline.ts index 89986e9adc..26fb457046 100644 --- a/modules/engine/src/animation/timeline.ts +++ b/modules/engine/src/animation/timeline.ts @@ -9,30 +9,30 @@ * @param repeat = 1 */ export type ChannelOptions = { - delay?: number - duration?: number - rate?: number - repeat?: number -} + delay?: number; + duration?: number; + rate?: number; + repeat?: number; +}; export type AnimationOptions = { - setTime: (time: number) => void -} + setTime: (time: number) => void; +}; - type Channel = { - time: number - delay: number - duration: number - rate: number - repeat: number -} +type Channel = { + time: number; + delay: number; + duration: number; + rate: number; + repeat: number; +}; type Animation = { channel?: number; animation: { - setTime: (time: number) => void - } -} + setTime: (time: number) => void; + }; +}; let channelHandles = 1; let animationHandles = 1; @@ -44,8 +44,7 @@ export class Timeline { playing: boolean = false; lastEngineTime: number = -1; - constructor() { - } + constructor() {} addChannel(props: ChannelOptions): number { const {delay = 0, duration = Number.POSITIVE_INFINITY, rate = 1, repeat = 1} = props; diff --git a/modules/engine/src/debug/copy-texture-to-image.ts b/modules/engine/src/debug/copy-texture-to-image.ts index 40da81de42..65144dcb44 100644 --- a/modules/engine/src/debug/copy-texture-to-image.ts +++ b/modules/engine/src/debug/copy-texture-to-image.ts @@ -8,7 +8,7 @@ import {flipRows, scalePixels} from './pixel-data-utils'; * @todo - support gl.readBuffer */ export type CopyTextureToImageOptions = { - sourceAttachment?: number; + sourceAttachment?: number; targetMaxHeight?: number; targetImage?: HTMLImageElement; }; @@ -16,15 +16,14 @@ export type CopyTextureToImageOptions = { /** * Reads pixels from a Framebuffer or Texture object into an HTML Image * @todo - can we move this to @luma.gl/core? - * @param source + * @param source * @param options options passed to copyToDataUrl - * @returns + * @returns */ export function copyTextureToImage( source: Texture | Framebuffer, options?: CopyTextureToImageOptions ): HTMLImageElement { - const dataUrl = copyTextureToDataUrl(source, options); const targetImage: HTMLImageElement = options?.targetImage || new Image(); targetImage.src = dataUrl; @@ -36,7 +35,7 @@ export function copyTextureToImage( * Reads pixels from a Framebuffer or Texture object to a dataUrl * @todo - can we move this to @luma.gl/core? * @param source texture or framebuffer to read from - * @param options + * @param options */ export function copyTextureToDataUrl( source: Texture | Framebuffer, diff --git a/modules/engine/src/debug/debug-framebuffer.ts b/modules/engine/src/debug/debug-framebuffer.ts index f1e4e328ae..6068417bfb 100644 --- a/modules/engine/src/debug/debug-framebuffer.ts +++ b/modules/engine/src/debug/debug-framebuffer.ts @@ -10,7 +10,21 @@ let ctx: CanvasRenderingContext2D | null = null; // eslint-disable-next-line export function debugFramebuffer( fbo: Framebuffer | Texture, - {id, minimap, opaque, top = '0', left = '0', rgbaScale = 1}: {id: string, minimap?: boolean; opaque?: boolean, top?: string, left?: string, rgbaScale?: number} + { + id, + minimap, + opaque, + top = '0', + left = '0', + rgbaScale = 1 + }: { + id: string; + minimap?: boolean; + opaque?: boolean; + top?: string; + left?: string; + rgbaScale?: number; + } ) { if (!canvas) { canvas = document.createElement('canvas'); @@ -34,7 +48,6 @@ export function debugFramebuffer( canvas.height = fbo.height / 2; canvas.style.width = '400px'; canvas.style.height = '400px'; - } // const image = copyTextureToImage(fbo, {targetMaxHeight: 100, targetImage}); @@ -54,4 +67,4 @@ export function debugFramebuffer( imageData.data[offset + i + 3] = opaque ? 255 : color[i + 3] * rgbaScale; } ctx.putImageData(imageData, 0, 0); -}; \ No newline at end of file +} diff --git a/modules/engine/src/debug/debug-shader-layout.ts b/modules/engine/src/debug/debug-shader-layout.ts index c128dbb531..8115106f46 100644 --- a/modules/engine/src/debug/debug-shader-layout.ts +++ b/modules/engine/src/debug/debug-shader-layout.ts @@ -8,7 +8,7 @@ import type {ShaderLayout} from '@luma.gl/core'; * Extracts a table suitable for `console.table()` from a shader layout to assist in debugging. * @param layout shader layout * @param name app should provide the most meaningful name, usually the model or pipeline name / id. - * @returns + * @returns */ export function getDebugTableForShaderLayout( layout: ShaderLayout, diff --git a/modules/engine/src/debug/pixel-data-utils.ts b/modules/engine/src/debug/pixel-data-utils.ts index 4446b54651..fb6b28e947 100644 --- a/modules/engine/src/debug/pixel-data-utils.ts +++ b/modules/engine/src/debug/pixel-data-utils.ts @@ -33,11 +33,7 @@ export function flipRows(options: { } } -export function scalePixels(options: { - data: TypedArray; - width: number; - height: number; -}): { +export function scalePixels(options: {data: TypedArray; width: number; height: number}): { data: Uint8Array; width: number; height: number; diff --git a/modules/engine/src/geometries/cube-geometry.ts b/modules/engine/src/geometries/cube-geometry.ts index aa8fef24dc..7a5badd42c 100644 --- a/modules/engine/src/geometries/cube-geometry.ts +++ b/modules/engine/src/geometries/cube-geometry.ts @@ -11,19 +11,23 @@ export type CubeGeometryProps = { export class CubeGeometry extends Geometry { constructor(props: CubeGeometryProps = {}) { const {id = uid('cube-geometry'), indices = true} = props; - super(indices ? { - ...props, - id, - topology: 'triangle-list', - indices: {size: 1, value: CUBE_INDICES}, - attributes: {...ATTRIBUTES, ...props.attributes} - } : { - ...props, - id, - topology: 'triangle-list', - indices: undefined, - attributes: {...NON_INDEXED_ATTRIBUTES, ...props.attributes} - }); + super( + indices + ? { + ...props, + id, + topology: 'triangle-list', + indices: {size: 1, value: CUBE_INDICES}, + attributes: {...ATTRIBUTES, ...props.attributes} + } + : { + ...props, + id, + topology: 'triangle-list', + indices: undefined, + attributes: {...NON_INDEXED_ATTRIBUTES, ...props.attributes} + } + ); } } diff --git a/modules/engine/src/geometries/ico-sphere-geometry.ts b/modules/engine/src/geometries/ico-sphere-geometry.ts index bf04558af4..f0c3c83353 100644 --- a/modules/engine/src/geometries/ico-sphere-geometry.ts +++ b/modules/engine/src/geometries/ico-sphere-geometry.ts @@ -11,7 +11,7 @@ export type IcoSphereGeometryProps = { id?: string; radius?: number; iterations?: number; - attributes?: any + attributes?: any; }; export class IcoSphereGeometry extends Geometry { diff --git a/modules/engine/src/geometries/plane-geometry.ts b/modules/engine/src/geometries/plane-geometry.ts index 84379af34b..492733372c 100644 --- a/modules/engine/src/geometries/plane-geometry.ts +++ b/modules/engine/src/geometries/plane-geometry.ts @@ -5,7 +5,7 @@ import {unpackIndexedGeometry} from '../geometry/geometry-utils'; export type PlaneGeometryProps = { id?: string; radius?: number; - attributes?: any + attributes?: any; }; // Primitives inspired by TDL http://code.google.com/p/webglsamples/, diff --git a/modules/engine/src/geometries/sphere-geometry.ts b/modules/engine/src/geometries/sphere-geometry.ts index d69e2ccde2..0d4ca51953 100644 --- a/modules/engine/src/geometries/sphere-geometry.ts +++ b/modules/engine/src/geometries/sphere-geometry.ts @@ -6,7 +6,7 @@ export type SphereGeometryProps = { radius?: number; nlat?: number; nlong?: number; - attributes?: any + attributes?: any; }; // Primitives inspired by TDL http://code.google.com/p/webglsamples/, diff --git a/modules/engine/src/geometries/truncated-cone-geometry.ts b/modules/engine/src/geometries/truncated-cone-geometry.ts index 111aab499a..576b2661f7 100644 --- a/modules/engine/src/geometries/truncated-cone-geometry.ts +++ b/modules/engine/src/geometries/truncated-cone-geometry.ts @@ -36,7 +36,8 @@ export class TruncatedConeGeometry extends Geometry { POSITION: {size: 3, value: attributes.POSITION}, NORMAL: {size: 3, value: attributes.NORMAL}, TEXCOORD_0: {size: 2, value: attributes.TEXCOORD_0}, - ...props.attributes} + ...props.attributes + } }); } } diff --git a/modules/engine/src/geometry/geometry-table.ts b/modules/engine/src/geometry/geometry-table.ts index c3d303cc05..5718dbb826 100644 --- a/modules/engine/src/geometry/geometry-table.ts +++ b/modules/engine/src/geometry/geometry-table.ts @@ -6,11 +6,11 @@ export type GeometryTable = { length: number; schema?: Record; attributes: { - POSITION: TypedArray, - NORMAL: TypedArray, - TEXCOORD_0: TypedArray, - [key: string]: TypedArray, + POSITION: TypedArray; + NORMAL: TypedArray; + TEXCOORD_0: TypedArray; + [key: string]: TypedArray; }; indices?: Uint16Array | Uint32Array; topology?: 'point-list' | 'line-list' | 'line-strip' | 'triangle-list' | 'triangle-strip'; -} +}; diff --git a/modules/engine/src/geometry/geometry-utils.ts b/modules/engine/src/geometry/geometry-utils.ts index 9a4aafab04..d7424a4cd5 100644 --- a/modules/engine/src/geometry/geometry-utils.ts +++ b/modules/engine/src/geometry/geometry-utils.ts @@ -44,4 +44,4 @@ export function unpackIndexedGeometry(geometry: any) { // normals.set(normal[2], i + 2); // } // const normal = new Vector3(vec1).cross(vec2).normalize(); -// } \ No newline at end of file +// } diff --git a/modules/engine/src/geometry/geometry.ts b/modules/engine/src/geometry/geometry.ts index d29b59958b..fffb68d3e2 100644 --- a/modules/engine/src/geometry/geometry.ts +++ b/modules/engine/src/geometry/geometry.ts @@ -98,7 +98,7 @@ export class Geometry { return this.vertexCount; } - /** + /** * Return an object with all attributes plus indices added as a field. * TODO Geometry types are a mess */ @@ -118,10 +118,10 @@ export class Geometry { * type: indices, vertices, uvs * size: elements per vertex * target: WebGL buffer type (string or constant) - * - * @param attributes - * @param indices - * @returns + * + * @param attributes + * @param indices + * @returns */ _setAttributes(attributes: Record, indices: any): this { return this; diff --git a/modules/engine/src/geometry/gpu-geometry.ts b/modules/engine/src/geometry/gpu-geometry.ts index 3d530a5ed5..497617d9e9 100644 --- a/modules/engine/src/geometry/gpu-geometry.ts +++ b/modules/engine/src/geometry/gpu-geometry.ts @@ -101,7 +101,7 @@ export function getIndexBufferFromGeometry(device: Device, geometry: Geometry): export function getAttributeBuffersFromGeometry( device: Device, geometry: Geometry -): {attributes: Record, bufferLayout: BufferLayout[], vertexCount: number} { +): {attributes: Record; bufferLayout: BufferLayout[]; vertexCount: number} { const bufferLayout: BufferLayout[] = []; const attributes: Record = {}; @@ -109,17 +109,25 @@ export function getAttributeBuffersFromGeometry( let name: string = attributeName; // TODO Map some GLTF attribute names (is this still needed?) switch (attributeName) { - case 'POSITION': name = 'positions'; break; - case 'NORMAL': name = 'normals'; break; - case 'TEXCOORD_0': name = 'texCoords'; break; - case 'COLOR_0': name = 'colors'; break; + case 'POSITION': + name = 'positions'; + break; + case 'NORMAL': + name = 'normals'; + break; + case 'TEXCOORD_0': + name = 'texCoords'; + break; + case 'COLOR_0': + name = 'colors'; + break; } attributes[name] = device.createBuffer({data: attribute.value, id: `${attributeName}-buffer`}); const {value, size, normalized} = attribute; bufferLayout.push({name, format: getVertexFormatFromAttribute(value, size, normalized)}); } - const vertexCount = geometry._calculateVertexCount(geometry.attributes, geometry.indices) + const vertexCount = geometry._calculateVertexCount(geometry.attributes, geometry.indices); return {attributes, bufferLayout, vertexCount}; } diff --git a/modules/engine/src/lib/clip-space.ts b/modules/engine/src/lib/clip-space.ts index c1c1aeab32..dd212792da 100644 --- a/modules/engine/src/lib/clip-space.ts +++ b/modules/engine/src/lib/clip-space.ts @@ -1,4 +1,3 @@ - // ClipSpace import {Device, glsl} from '@luma.gl/core'; import {Model, ModelProps} from '../model/model'; @@ -30,24 +29,21 @@ const POSITIONS = [-1, -1, 1, -1, -1, 1, 1, 1]; */ export class ClipSpace extends Model { constructor(device: Device, opts: Omit) { - const TEX_COORDS = POSITIONS.map((coord) => (coord === -1 ? 0 : coord)); + const TEX_COORDS = POSITIONS.map(coord => (coord === -1 ? 0 : coord)); - super( - device, - { - ...opts, - vs: CLIPSPACE_VERTEX_SHADER, + super(device, { + ...opts, + vs: CLIPSPACE_VERTEX_SHADER, + vertexCount: 4, + geometry: new Geometry({ + topology: 'triangle-strip', vertexCount: 4, - geometry: new Geometry({ - topology: 'triangle-strip', - vertexCount: 4, - attributes: { - aClipSpacePosition: {size: 2, value: new Float32Array(POSITIONS)}, - aTexCoord: {size: 2, value: new Float32Array(TEX_COORDS)}, - aCoordinate: {size: 2, value: new Float32Array(TEX_COORDS)} - } - }) - } - ); + attributes: { + aClipSpacePosition: {size: 2, value: new Float32Array(POSITIONS)}, + aTexCoord: {size: 2, value: new Float32Array(TEX_COORDS)}, + aCoordinate: {size: 2, value: new Float32Array(TEX_COORDS)} + } + }) + }); } } diff --git a/modules/engine/src/model/model.ts b/modules/engine/src/model/model.ts index 7921f41f41..823e517edf 100644 --- a/modules/engine/src/model/model.ts +++ b/modules/engine/src/model/model.ts @@ -259,7 +259,9 @@ export class Model { this.setIndexBuffer(props.indexBuffer); } if (props.attributes) { - this.setAttributes(props.attributes, {ignoreUnknownAttributes: props.ignoreUnknownAttributes}); + this.setAttributes(props.attributes, { + ignoreUnknownAttributes: props.ignoreUnknownAttributes + }); } if (props.constantAttributes) { this.setConstantAttributes(props.constantAttributes); @@ -517,7 +519,10 @@ export class Model { * Sets attributes (buffers) * @note Overrides any attributes previously set with the same name */ - setAttributes(buffers: Record, options?: {ignoreUnknownAttributes?: boolean}): void { + setAttributes( + buffers: Record, + options?: {ignoreUnknownAttributes?: boolean} + ): void { if (buffers.indices) { log.warn( `Model:${this.id} setAttributes() - indexBuffer should be set using setIndexBuffer()` @@ -599,11 +604,11 @@ export class Model { const fs = this.fs ? this.shaderFactory.createShader({ - id: `${this.id}-fragment`, - stage: 'fragment', - source: this.fs, - debug: this.props.debugShaders - }) + id: `${this.id}-fragment`, + stage: 'fragment', + source: this.fs, + debug: this.props.debugShaders + }) : null; this.pipeline = this.pipelineFactory.createRenderPipeline({ diff --git a/modules/engine/src/scenegraph/group-node.ts b/modules/engine/src/scenegraph/group-node.ts index 63dde2907f..b3d7462176 100644 --- a/modules/engine/src/scenegraph/group-node.ts +++ b/modules/engine/src/scenegraph/group-node.ts @@ -4,7 +4,7 @@ import {ScenegraphNode, ScenegraphNodeProps} from './scenegraph-node'; export type GroupNodeProps = ScenegraphNodeProps & { children?: ScenegraphNode[]; -} +}; export class GroupNode extends ScenegraphNode { children: ScenegraphNode[]; @@ -16,7 +16,7 @@ export class GroupNode extends ScenegraphNode { props = Array.isArray(props) ? {children: props} : props; const {children = []} = props; log.assert( - children.every((child) => child instanceof ScenegraphNode), + children.every(child => child instanceof ScenegraphNode), 'every child must an instance of ScenegraphNode' ); super(props); @@ -24,7 +24,10 @@ export class GroupNode extends ScenegraphNode { } override getBounds(): [number[], number[]] | null { - const result: [number[], number[]] = [[Infinity, Infinity, Infinity], [-Infinity, -Infinity, -Infinity]]; + const result: [number[], number[]] = [ + [Infinity, Infinity, Infinity], + [-Infinity, -Infinity, -Infinity] + ]; this.traverse((node, {worldMatrix}) => { const bounds = node.getBounds(); @@ -39,11 +42,9 @@ export class GroupNode extends ScenegraphNode { for (let v = 0; v < 8; v++) { // Test all 8 corners of the box - const position = new Vector3( - v & 0b001 ? -1 : 1, - v & 0b010 ? -1 : 1, - v & 0b100 ? -1 : 1 - ).multiply(halfSize).add(center); + const position = new Vector3(v & 0b001 ? -1 : 1, v & 0b010 ? -1 : 1, v & 0b100 ? -1 : 1) + .multiply(halfSize) + .add(center); for (let i = 0; i < 3; i++) { result[0][i] = Math.min(result[0][i], position[i]); @@ -58,7 +59,7 @@ export class GroupNode extends ScenegraphNode { } override destroy(): void { - this.children.forEach((child) => child.destroy()); + this.children.forEach(child => child.destroy()); this.removeAll(); super.destroy(); } @@ -89,7 +90,10 @@ export class GroupNode extends ScenegraphNode { return this; } - traverse(visitor: (node: ScenegraphNode, context: {worldMatrix: Matrix4}) => void, {worldMatrix = new Matrix4()} = {}) { + traverse( + visitor: (node: ScenegraphNode, context: {worldMatrix: Matrix4}) => void, + {worldMatrix = new Matrix4()} = {} + ) { const modelMatrix = new Matrix4(worldMatrix).multiplyRight(this.matrix); for (const child of this.children) { diff --git a/modules/engine/src/scenegraph/model-node.ts b/modules/engine/src/scenegraph/model-node.ts index 08ac993c01..1c27d53757 100644 --- a/modules/engine/src/scenegraph/model-node.ts +++ b/modules/engine/src/scenegraph/model-node.ts @@ -6,7 +6,7 @@ export type ModelNodeProps = ScenegraphNodeProps & { model: Model; managedResources?: any[]; bounds?: [number[], number[]]; -} +}; export class ModelNode extends ScenegraphNode { readonly model: Model; @@ -38,7 +38,7 @@ export class ModelNode extends ScenegraphNode { // @ts-expect-error this.model = null; } - this.managedResources.forEach((resource) => resource.destroy()); + this.managedResources.forEach(resource => resource.destroy()); this.managedResources = []; } diff --git a/modules/engine/src/scenegraph/scenegraph-node.ts b/modules/engine/src/scenegraph/scenegraph-node.ts index 2b4597e4eb..986ef11580 100644 --- a/modules/engine/src/scenegraph/scenegraph-node.ts +++ b/modules/engine/src/scenegraph/scenegraph-node.ts @@ -10,14 +10,14 @@ export type ScenegraphNodeProps = { position?: NumberArray; rotation?: NumberArray; scale?: NumberArray; - update?: boolean + update?: boolean; }; export class ScenegraphNode { readonly id: string; matrix: Matrix4 = new Matrix4(); - display = true; + display = true; position = new Vector3(); rotation = new Vector3(); scale = new Vector3(1, 1, 1); diff --git a/modules/engine/src/shader-inputs.ts b/modules/engine/src/shader-inputs.ts index f20e31a681..7d0dd7ed49 100644 --- a/modules/engine/src/shader-inputs.ts +++ b/modules/engine/src/shader-inputs.ts @@ -2,8 +2,7 @@ import type {UniformValue, Texture, Sampler} from '@luma.gl/core'; import {log} from '@luma.gl/core'; // import type {ShaderUniformType, UniformValue, UniformFormat, UniformInfoDevice, Texture, Sampler} from '@luma.gl/core'; -import {_resolveModules, ShaderModuleInstance} from '@luma.gl/shadertools' - +import {_resolveModules, ShaderModuleInstance} from '@luma.gl/shadertools'; /** Minimal ShaderModule subset, we don't need shader code etc */ export type ShaderModuleInputs< @@ -40,8 +39,8 @@ export class ShaderInputs< Record> > > { - /** - * The map of modules + /** + * The map of modules * @todo should should this include the resolved dependencies? */ modules: Readonly<{[P in keyof ShaderPropsT]: ShaderModuleInputs}>; @@ -59,8 +58,12 @@ export class ShaderInputs< */ constructor(modules: {[P in keyof ShaderPropsT]: ShaderModuleInputs}) { // TODO - get all dependencies from modules - const allModules =_resolveModules(Object.values(modules)); - log.log(1, 'Creating ShaderInputs with modules', allModules.map(m => m.name))(); + const allModules = _resolveModules(Object.values(modules)); + log.log( + 1, + 'Creating ShaderInputs with modules', + allModules.map(m => m.name) + )(); // Store the module definitions and create storage for uniform values and binding values, per module this.modules = modules; @@ -94,8 +97,9 @@ export class ShaderInputs< continue; // eslint-disable-line no-continue } - const oldUniforms = this.moduleUniforms[moduleName]; - const uniforms = module.getUniforms?.(moduleProps, this.moduleUniforms[moduleName]) || moduleProps as any; + const oldUniforms = this.moduleUniforms[moduleName]; + const uniforms = + module.getUniforms?.(moduleProps, this.moduleUniforms[moduleName]) || (moduleProps as any); // console.error(uniforms) this.moduleUniforms[moduleName] = {...oldUniforms, ...uniforms}; // this.moduleUniformsChanged ||= moduleName; @@ -113,8 +117,8 @@ export class ShaderInputs< // return this.moduleUniforms; // } - /** - * Return the map of modules + /** + * Return the map of modules * @todo should should this include the resolved dependencies? */ getModules(): ShaderModuleInstance[] { @@ -136,7 +140,7 @@ export class ShaderInputs< } getDebugTable(): Record> { - const table: Record> = {}; + const table: Record> = {}; for (const [moduleName, module] of Object.entries(this.moduleUniforms)) { for (const [key, value] of Object.entries(module)) { table[`${moduleName}.${key}`] = { diff --git a/modules/engine/src/transform/texture-transform.ts b/modules/engine/src/transform/texture-transform.ts index 0ec7f15553..eadbf84561 100644 --- a/modules/engine/src/transform/texture-transform.ts +++ b/modules/engine/src/transform/texture-transform.ts @@ -1,9 +1,9 @@ // luma.gl, MIT license // Copyright (c) vis.gl contributors -import { Buffer, Device, Framebuffer, RenderPassProps, Sampler, Texture } from '@luma.gl/core'; -import { Model, ModelProps } from '../model/model'; -import { getPassthroughFS } from '@luma.gl/shadertools'; +import {Buffer, Device, Framebuffer, RenderPassProps, Sampler, Texture} from '@luma.gl/core'; +import {Model, ModelProps} from '../model/model'; +import {getPassthroughFS} from '@luma.gl/shadertools'; /** * Properties for creating a {@link TextureTransform} @@ -24,7 +24,6 @@ export type TextureTransformProps = Omit & { targetTextureVarying: string; }; - type TextureBinding = { sourceBuffers: Record; sourceTextures: Record; @@ -42,7 +41,7 @@ export class TextureTransform { readonly device: Device; readonly model: Model; readonly sampler: Sampler; - + currentIndex = 0; samplerTextureMap: Record | null = null; bindings: TextureBinding[] = []; // each element is an object : {sourceTextures, targetTexture, framebuffer} @@ -57,16 +56,18 @@ export class TextureTransform { addressModeV: 'clamp-to-edge', minFilter: 'nearest', magFilter: 'nearest', - mipmapFilter: 'nearest', + mipmapFilter: 'nearest' }); this.model = new Model(this.device, { id: props.id || 'texture-transform-model', - fs: props.fs || getPassthroughFS({ - input: props.targetTextureVarying, - inputChannels: props.targetTextureChannels, - output: FS_OUTPUT_VARIABLE - }), + fs: + props.fs || + getPassthroughFS({ + input: props.targetTextureVarying, + inputChannels: props.targetTextureChannels, + output: FS_OUTPUT_VARIABLE + }), vertexCount: props.vertexCount, // TODO(donmccurdy): Naming? ...props }); @@ -109,7 +110,6 @@ export class TextureTransform { return targetTexture; } - getFramebuffer(): Framebuffer { const currentResources = this.bindings[this.currentIndex]; return currentResources.framebuffer; diff --git a/modules/engine/test/animation/key-frames.spec.ts b/modules/engine/test/animation/key-frames.spec.ts index 6c2ba8a858..a66836a57f 100644 --- a/modules/engine/test/animation/key-frames.spec.ts +++ b/modules/engine/test/animation/key-frames.spec.ts @@ -1,7 +1,7 @@ import {KeyFrames} from '@luma.gl/engine'; import test from 'tape-promise/tape'; -test('Animation#KeyFrames', (t) => { +test('Animation#KeyFrames', t => { const keyFrames = new KeyFrames([ [0, {val1: [1, 0, 1], val2: 0}], [500, {val1: [1, 1, 1], val2: 2}], diff --git a/modules/engine/test/animation/timeline.spec.ts b/modules/engine/test/animation/timeline.spec.ts index fb7b59bf4e..c6bebe9b98 100644 --- a/modules/engine/test/animation/timeline.spec.ts +++ b/modules/engine/test/animation/timeline.spec.ts @@ -4,7 +4,7 @@ import test from 'tape-promise/tape'; // NOTE(Tarek): This is for the x * CHANNEL1_RATE // lines, which are important for clarity. /* eslint-disable no-implicit-coercion */ -test('Animation#Timeline', (t) => { +test('Animation#Timeline', t => { const timeline = new Timeline(); timeline.pause(); timeline.reset(); diff --git a/modules/engine/test/debug/get-debug-table-from-shader-layout.spec.ts b/modules/engine/test/debug/get-debug-table-from-shader-layout.spec.ts index 39af777b14..1a73b8be44 100644 --- a/modules/engine/test/debug/get-debug-table-from-shader-layout.spec.ts +++ b/modules/engine/test/debug/get-debug-table-from-shader-layout.spec.ts @@ -16,7 +16,7 @@ const SHADER_LAYOUT: ShaderLayout = { bindings: [] }; -test('getDebugTableForShaderLayout#tests', (t) => { +test('getDebugTableForShaderLayout#tests', t => { const table = getDebugTableForShaderLayout(SHADER_LAYOUT, 'test'); t.ok(table); t.end(); diff --git a/modules/engine/test/geometry/geometries.spec.ts b/modules/engine/test/geometry/geometries.spec.ts index d8146b9afc..14820285e8 100644 --- a/modules/engine/test/geometry/geometries.spec.ts +++ b/modules/engine/test/geometry/geometries.spec.ts @@ -43,13 +43,13 @@ function checkAttribute(attribute, type: TypedArrayConstructor[] = [Float32Array return ( attribute && attribute.value && - type.some((t) => attribute.value instanceof t) && + type.some(t => attribute.value instanceof t) && attribute.value.length > 0 && attribute.value.every(Number.isFinite) ); } -test('Object#Geometries', (t) => { +test('Object#Geometries', t => { for (const geometryTest of GEOMETRY_TESTS) { const {name, Geometry} = geometryTest; // `undefined` tests the default props diff --git a/modules/engine/test/geometry/geometry-utils.spec.ts b/modules/engine/test/geometry/geometry-utils.spec.ts index 6f3e2f8a51..15469d875e 100644 --- a/modules/engine/test/geometry/geometry-utils.spec.ts +++ b/modules/engine/test/geometry/geometry-utils.spec.ts @@ -41,7 +41,7 @@ const TEST_CASES = [ } ]; -test('unpackIndexedGeometry', (t) => { +test('unpackIndexedGeometry', t => { for (const testCase of TEST_CASES) { const {attributes} = unpackIndexedGeometry(testCase.input); for (const name in testCase.output.attributes) { diff --git a/modules/engine/test/geometry/geometry.spec.ts b/modules/engine/test/geometry/geometry.spec.ts index 5f88c2aee9..0b49ed509a 100644 --- a/modules/engine/test/geometry/geometry.spec.ts +++ b/modules/engine/test/geometry/geometry.spec.ts @@ -63,7 +63,7 @@ const TEST_CASES: {title: string; props: GeometryProps; [key: string]: any}[] = } ]; -test('Geometry#constructor', (t) => { +test('Geometry#constructor', t => { for (const testCase of TEST_CASES) { if (testCase.shouldThrow) { t.throws(() => new Geometry(testCase.props), `${testCase.title}: should throw`); diff --git a/modules/engine/test/index.ts b/modules/engine/test/index.ts index ab92e0b019..678590c5df 100644 --- a/modules/engine/test/index.ts +++ b/modules/engine/test/index.ts @@ -22,6 +22,5 @@ import './shader-inputs.spec'; import './transform/buffer-transform.spec'; import './transform/texture-transform.spec'; - // debug import './debug/get-debug-table-from-shader-layout.spec'; diff --git a/modules/engine/test/lib/animation-loop.spec.ts b/modules/engine/test/lib/animation-loop.spec.ts index 1b2046bd58..50a081064b 100644 --- a/modules/engine/test/lib/animation-loop.spec.ts +++ b/modules/engine/test/lib/animation-loop.spec.ts @@ -3,14 +3,14 @@ import {webglDevice as device} from '@luma.gl/test-utils'; import {AnimationLoop} from '@luma.gl/engine'; -test('engine#AnimationLoop constructor', (t) => { +test('engine#AnimationLoop constructor', t => { t.ok(AnimationLoop, 'AnimationLoop imported'); const animationLoop = new AnimationLoop({device}); t.ok(animationLoop, 'AnimationLoop constructor should not throw'); t.end(); }); -test('engine#AnimationLoop start,stop', (t) => { +test('engine#AnimationLoop start,stop', t => { let initializeCalled = 0; let renderCalled = 0; let finalizeCalled = 0; @@ -39,7 +39,7 @@ test('engine#AnimationLoop start,stop', (t) => { }).start(); }); -test('engine#AnimationLoop redraw', (t) => { +test('engine#AnimationLoop redraw', t => { let renderCalled = 0; new AnimationLoop({ @@ -58,7 +58,7 @@ test('engine#AnimationLoop redraw', (t) => { }).start(); }); -test('engine#AnimationLoop should not call initialize more than once', async (t) => { +test('engine#AnimationLoop should not call initialize more than once', async t => { let initializeCalled = 0; const animationLoop = new AnimationLoop({ @@ -75,7 +75,7 @@ test('engine#AnimationLoop should not call initialize more than once', async (t) t.end(); }); -test('engine#AnimationLoop two start()s should only run one loop', async (t) => { +test('engine#AnimationLoop two start()s should only run one loop', async t => { let renderCalled = 0; const animationLoop = new AnimationLoop({ @@ -94,7 +94,7 @@ test('engine#AnimationLoop two start()s should only run one loop', async (t) => t.end(); }); -test.skip('engine#AnimationLoop start followed immediately by stop() should stop', (t) => { +test.skip('engine#AnimationLoop start followed immediately by stop() should stop', t => { let initializeCalled = 0; const animationLoop = new AnimationLoop({ @@ -111,7 +111,7 @@ test.skip('engine#AnimationLoop start followed immediately by stop() should stop }, 100); }); -test('engine#AnimationLoop a start/stop/start should not call initialize again', (t) => { +test('engine#AnimationLoop a start/stop/start should not call initialize again', t => { let initializeCalled = 0; const animationLoop = new AnimationLoop({ diff --git a/modules/engine/test/lib/model.spec.ts b/modules/engine/test/lib/model.spec.ts index 11874c7e93..37eb0259cc 100644 --- a/modules/engine/test/lib/model.spec.ts +++ b/modules/engine/test/lib/model.spec.ts @@ -353,8 +353,6 @@ test('Model#getBuffersFromGeometry', (t) => { }); */ - - /* test.skip('PipelineFactory#basic', (t) => { const pipelineFactory = new PipelineFactory(webglDevice); diff --git a/modules/engine/test/lib/pipeline-factory.spec.ts b/modules/engine/test/lib/pipeline-factory.spec.ts index 7e3133b9bb..5eb59de5be 100644 --- a/modules/engine/test/lib/pipeline-factory.spec.ts +++ b/modules/engine/test/lib/pipeline-factory.spec.ts @@ -4,7 +4,6 @@ import {webglDevice} from '@luma.gl/test-utils'; import {glsl} from '@luma.gl/core'; import {PipelineFactory} from '@luma.gl/engine'; - // TODO - this doesn't test that parameters etc are properly cached const vsSource = glsl`\ @@ -22,12 +21,12 @@ void main(void) { } `; -test('PipelineFactory#import', (t) => { +test('PipelineFactory#import', t => { t.ok(PipelineFactory !== undefined, 'PipelineFactory import successful'); t.end(); }); -test('PipelineFactory#getDefaultPipelineFactory', (t) => { +test('PipelineFactory#getDefaultPipelineFactory', t => { const pm1 = PipelineFactory.getDefaultPipelineFactory(webglDevice); const pm2 = PipelineFactory.getDefaultPipelineFactory(webglDevice); @@ -37,7 +36,7 @@ test('PipelineFactory#getDefaultPipelineFactory', (t) => { t.end(); }); -test('PipelineFactory#release', (t) => { +test('PipelineFactory#release', t => { const pipelineFactory = new PipelineFactory(webglDevice); const vs = webglDevice.createShader({stage: 'vertex', source: vsSource}); diff --git a/modules/engine/test/scenegraph/group-node.spec.ts b/modules/engine/test/scenegraph/group-node.spec.ts index 6466523857..661ae70bd3 100644 --- a/modules/engine/test/scenegraph/group-node.spec.ts +++ b/modules/engine/test/scenegraph/group-node.spec.ts @@ -7,7 +7,7 @@ import {GroupNode, ScenegraphNode, ModelNode, Model} from '@luma.gl/engine'; import {Matrix4} from '@math.gl/core'; import {DUMMY_VS, DUMMY_FS} from './model-node.spec'; -test('GroupNode#construction', (t) => { +test('GroupNode#construction', t => { const grandChild = new ScenegraphNode(); const child1 = new GroupNode([grandChild]); const child2 = new GroupNode(); @@ -26,7 +26,7 @@ test('GroupNode#construction', (t) => { t.end(); }); -test('GroupNode#add', (t) => { +test('GroupNode#add', t => { const child1 = new GroupNode(); const child2 = new GroupNode(); const child3 = new GroupNode(); @@ -39,7 +39,7 @@ test('GroupNode#add', (t) => { t.end(); }); -test('GroupNode#remove', (t) => { +test('GroupNode#remove', t => { const child1 = new GroupNode(); const child2 = new GroupNode(); const child3 = new GroupNode(); @@ -55,7 +55,7 @@ test('GroupNode#remove', (t) => { t.end(); }); -test('GroupNode#removeAll', (t) => { +test('GroupNode#removeAll', t => { const child1 = new GroupNode(); const child2 = new GroupNode(); const child3 = new GroupNode(); @@ -68,7 +68,7 @@ test('GroupNode#removeAll', (t) => { t.end(); }); -test('GroupNode#destroy', (t) => { +test('GroupNode#destroy', t => { const grandChild = new GroupNode(); const child1 = new GroupNode([grandChild]); const child2 = new GroupNode(); @@ -81,7 +81,7 @@ test('GroupNode#destroy', (t) => { t.end(); }); -test('GroupNode#traverse', (t) => { +test('GroupNode#traverse', t => { const modelMatrices = {}; const matrix = new Matrix4().identity().scale(2); @@ -106,7 +106,7 @@ test('GroupNode#traverse', (t) => { t.end(); }); -test('GroupNode#getBounds', (t) => { +test('GroupNode#getBounds', t => { for (const device of getWebGLTestDevices()) { const matrix = new Matrix4().translate([0, 0, 1]).scale(2); diff --git a/modules/engine/test/scenegraph/model-node.spec.ts b/modules/engine/test/scenegraph/model-node.spec.ts index dc44e5116d..eeb925393b 100644 --- a/modules/engine/test/scenegraph/model-node.spec.ts +++ b/modules/engine/test/scenegraph/model-node.spec.ts @@ -18,7 +18,7 @@ out vec4 fragmentColor; void main() { fragmentColor = vec4(1.0); } `; -test('ModelNode#constructor', (t) => { +test('ModelNode#constructor', t => { for (const device of getWebGLTestDevices()) { const model = new Model(device, {vs: DUMMY_VS, fs: DUMMY_FS}); diff --git a/modules/engine/test/scenegraph/scenegraph-node.spec.ts b/modules/engine/test/scenegraph/scenegraph-node.spec.ts index 7c61fe540b..5658b120f7 100644 --- a/modules/engine/test/scenegraph/scenegraph-node.spec.ts +++ b/modules/engine/test/scenegraph/scenegraph-node.spec.ts @@ -13,7 +13,7 @@ const PROPS = { matrix: new Matrix4().scale(4) }; -test('ScenegraphNode#constructor', (t) => { +test('ScenegraphNode#constructor', t => { const sgNode = new ScenegraphNode(PROPS); t.ok(sgNode instanceof ScenegraphNode, 'should construct the object'); for (const key in PROPS) { @@ -23,14 +23,14 @@ test('ScenegraphNode#constructor', (t) => { t.end(); }); -test('ScenegraphNode#delete', (t) => { +test('ScenegraphNode#delete', t => { const sgNode = new ScenegraphNode(); t.doesNotThrow(() => sgNode.destroy(), 'delete should work'); t.end(); }); -test('ScenegraphNode#setProps', (t) => { +test('ScenegraphNode#setProps', t => { const sgNode = new ScenegraphNode(); sgNode.setProps(PROPS); for (const key in PROPS) { @@ -40,14 +40,14 @@ test('ScenegraphNode#setProps', (t) => { t.end(); }); -test('ScenegraphNode#toString', (t) => { +test('ScenegraphNode#toString', t => { const sgNode = new ScenegraphNode(); t.doesNotThrow(() => sgNode.toString(), 'delete should work'); t.end(); }); -test('ScenegraphNode#setMatrix', (t) => { +test('ScenegraphNode#setMatrix', t => { const sgNode = new ScenegraphNode(); const matrix = new Matrix4().scale(1.5); @@ -60,7 +60,7 @@ test('ScenegraphNode#setMatrix', (t) => { t.end(); }); -test('ScenegraphNode#setMatrixComponents', (t) => { +test('ScenegraphNode#setMatrixComponents', t => { const sgNode = new ScenegraphNode(); const position = new Vector3(1, 1, 1); const rotation = new Vector3(2, 2, 2); @@ -79,7 +79,7 @@ test('ScenegraphNode#setMatrixComponents', (t) => { t.end(); }); -test('ScenegraphNode#update', (t) => { +test('ScenegraphNode#update', t => { const sgNode = new ScenegraphNode(); const position = new Vector3(1, 1, 1); const rotation = new Vector3(2, 2, 2); @@ -98,7 +98,7 @@ test('ScenegraphNode#update', (t) => { t.end(); }); -test('ScenegraphNode#getCoordinateUniforms', (t) => { +test('ScenegraphNode#getCoordinateUniforms', t => { const sgNode = new ScenegraphNode(); const uniforms = sgNode.getCoordinateUniforms(new Matrix4()); diff --git a/modules/engine/test/shader-inputs.spec.ts b/modules/engine/test/shader-inputs.spec.ts index 1b9a12e97d..f0c7bee670 100644 --- a/modules/engine/test/shader-inputs.spec.ts +++ b/modules/engine/test/shader-inputs.spec.ts @@ -6,9 +6,9 @@ import {picking} from '../../shadertools/src/index'; // import {_ShaderInputs as ShaderInputs} from '@luma.gl/engine'; import {ShaderInputs} from '../src/shader-inputs'; -test('ShaderInputs#picking', (t) => { +test('ShaderInputs#picking', t => { const shaderInputsUntyped = new ShaderInputs({picking}); - // Add + // Add shaderInputsUntyped.setProps({picking: {highlightedObjectColor: [255, 255, 255]}}); t.ok(shaderInputsUntyped, 'untyped'); @@ -22,7 +22,7 @@ test('ShaderInputs#picking', (t) => { t.end(); }); -test('ShaderInputs#picking', (t) => { +test('ShaderInputs#picking', t => { const shaderInputsUntyped = new ShaderInputs({picking}); shaderInputsUntyped.setProps({picking: {highlightedObjectColor: [255, 255, 255]}}); t.ok(shaderInputsUntyped, 'untyped'); @@ -40,7 +40,7 @@ test('ShaderInputs#picking', (t) => { t.end(); }); -test('ShaderInputs#picking prop merge', (t) => { +test('ShaderInputs#picking prop merge', t => { const shaderInputs = new ShaderInputs<{picking: typeof picking.props}>({picking}); const expected = {...picking.defaultUniforms}; t.deepEqual(shaderInputs.moduleUniforms.picking, expected, 'defaults set'); @@ -53,7 +53,11 @@ test('ShaderInputs#picking prop merge', (t) => { shaderInputs.setProps({picking: {highlightedObjectColor: [255, 255, 255]}}); expected.highlightedObjectColor = [255, 255, 255]; expected.isHighlightActive = true; - t.deepEqual(shaderInputs.moduleUniforms.picking, expected, 'Only highlight object and highlight active updated'); + t.deepEqual( + shaderInputs.moduleUniforms.picking, + expected, + 'Only highlight object and highlight active updated' + ); t.end(); }); diff --git a/modules/engine/test/transform/buffer-transform.spec.ts b/modules/engine/test/transform/buffer-transform.spec.ts index 202eb9a43d..a1a178f324 100644 --- a/modules/engine/test/transform/buffer-transform.spec.ts +++ b/modules/engine/test/transform/buffer-transform.spec.ts @@ -20,14 +20,14 @@ out vec4 fragColor; void main() { fragColor.x = dst; } `; -test('BufferTransform#constructor', async (t) => { +test('BufferTransform#constructor', async t => { for (const device of getWebGLTestDevices()) { t.ok(createBufferTransform(device), 'WebGL succeeds'); } t.end(); }); -test('BufferTransform#run', async (t) => { +test('BufferTransform#run', async t => { const SRC_ARRAY = new Float32Array([0, 1, 2, 3, 4, 5]); const DST_ARRAY = new Float32Array([0, 1, 4, 9, 16, 25]); @@ -46,7 +46,12 @@ test('BufferTransform#run', async (t) => { t.end(); }); -function createBufferTransform(device: Device, src?: Buffer, dst?: Buffer, vertexCount?: number): BufferTransform { +function createBufferTransform( + device: Device, + src?: Buffer, + dst?: Buffer, + vertexCount?: number +): BufferTransform { return new BufferTransform(device, { vs: VS, fs: FS, @@ -55,6 +60,6 @@ function createBufferTransform(device: Device, src?: Buffer, dst?: Buffer, verte bufferLayout: [{name: 'src', format: 'float32'}], feedbackBuffers: dst ? {dst} : undefined, varyings: ['dst'], - topology: 'point-list', + topology: 'point-list' }); -} \ No newline at end of file +} diff --git a/modules/engine/test/transform/texture-transform.spec.ts b/modules/engine/test/transform/texture-transform.spec.ts index 81e6723074..3e04f9893c 100644 --- a/modules/engine/test/transform/texture-transform.spec.ts +++ b/modules/engine/test/transform/texture-transform.spec.ts @@ -13,7 +13,7 @@ test('TextureTransform#constructor', async t => { data: new Float32Array([201, 202, 203, 1.0]), width: 1, height: 1, - format: 'rgba32float', + format: 'rgba32float' }); const transform = new TextureTransform(device, { vs: BASIC_VS, @@ -21,7 +21,7 @@ test('TextureTransform#constructor', async t => { targetTexture, targetTextureChannels: 1, targetTextureVarying: 'vSrc', - vertexCount: 1, + vertexCount: 1 }); t.ok(transform, 'creates transform'); } @@ -36,7 +36,7 @@ test('TextureTransform#attribute', async t => { data: new Float32Array([201, 202, 203, 1.0]), width: 1, height: 1, - format: 'rgba32float', + format: 'rgba32float' }); const transform = new TextureTransform(device, { vs: SUM_VS, @@ -51,11 +51,11 @@ test('TextureTransform#attribute', async t => { depthCompare: 'always', blendColorOperation: 'add', blendColorSrcFactor: 'one', - blendColorDstFactor: 'one', - }, + blendColorDstFactor: 'one' + } }); const source = transform.getTargetTexture(); - + // TODO(donmccurdy): Consider having Transform inherit from Model, or at // least mimic its API by accepting a RenderPass in .run(). transform.run({clearColor: [0, 0, 0, 0]}); @@ -79,13 +79,13 @@ test('TextureTransform#texture', async t => { data: srcData, width: 1, height: 1, - format: 'rgba8unorm', + format: 'rgba8unorm' }); const targetTexture = device.createTexture({ data: new Uint8Array([0, 0, 0, 1]), width: 1, height: 1, - format: 'rgba8unorm', + format: 'rgba8unorm' }); const transform = new TextureTransform(device, { vs: BLEND_VS, @@ -100,8 +100,8 @@ test('TextureTransform#texture', async t => { depthCompare: 'always', blendColorOperation: 'add', blendColorSrcFactor: 'one', - blendColorDstFactor: 'one', - }, + blendColorDstFactor: 'one' + } }); // TODO(donmccurdy): Consider having Transform inherit from Model, or at diff --git a/modules/gltf/src/gltf/create-gltf-model.ts b/modules/gltf/src/gltf/create-gltf-model.ts index 10c6ab2a1f..3e581f249a 100644 --- a/modules/gltf/src/gltf/create-gltf-model.ts +++ b/modules/gltf/src/gltf/create-gltf-model.ts @@ -93,7 +93,7 @@ export function createGLTFModel(device: Device, options: CreateGLTFModelOptions) depthCompare: 'less', depthFormat: 'depth24plus', cullMode: 'back' - } + }; const modelProps: ModelProps = { id, @@ -109,10 +109,10 @@ export function createGLTFModel(device: Device, options: CreateGLTFModelOptions) defines: {...parsedMaterial.defines, ...modelOptions.defines}, parameters: {...parameters, ...parsedMaterial.parameters, ...modelOptions.parameters}, uniforms: {...parsedMaterial.uniforms, ...modelOptions.uniforms} - } + }; const model = new Model(device, modelProps); - return new ModelNode({ managedResources, model}); + return new ModelNode({managedResources, model}); } function addVersionToShader(device: Device, source: string): string { diff --git a/modules/gltf/src/gltf/gltf-animator.ts b/modules/gltf/src/gltf/gltf-animator.ts index c5c0488e71..5b83bc634c 100644 --- a/modules/gltf/src/gltf/gltf-animator.ts +++ b/modules/gltf/src/gltf/gltf-animator.ts @@ -27,7 +27,7 @@ type GLTFAnimationProps = { playing?: boolean; speed?: number; channels?: any; -} +}; class GLTFAnimation { name: string; @@ -81,7 +81,7 @@ export class GLTFAnimator { } setTime(time: number): void { - this.animations.forEach((animation) => animation.animate(time)); + this.animations.forEach(animation => animation.animate(time)); } getAnimations() { @@ -173,7 +173,7 @@ function interpolate(time, {input, interpolation, output}, target, path) { const maxTime = input[input.length - 1]; const animationTime = time % maxTime; - const nextIndex = input.findIndex((t) => t >= animationTime); + const nextIndex = input.findIndex(t => t >= animationTime); const previousIndex = Math.max(0, nextIndex - 1); if (!Array.isArray(target[path])) { diff --git a/modules/gltf/src/gltf/gltf-instantiator.ts b/modules/gltf/src/gltf/gltf-instantiator.ts index 88637a15a6..88a798882e 100644 --- a/modules/gltf/src/gltf/gltf-instantiator.ts +++ b/modules/gltf/src/gltf/gltf-instantiator.ts @@ -9,12 +9,12 @@ import {createGLTFModel} from './create-gltf-model'; import type {PBREnvironment} from '../pbr/pbr-environment'; export type GLTFInstantiatorOptions = { - modelOptions?: Partial, - pbrDebug?: boolean, - imageBasedLightingEnvironment?: PBREnvironment, - lights?: boolean, - useTangents?: boolean -} + modelOptions?: Partial; + pbrDebug?: boolean; + imageBasedLightingEnvironment?: PBREnvironment; + lights?: boolean; + useTangents?: boolean; +}; const DEFAULT_OPTIONS: GLTFInstantiatorOptions = { modelOptions: {}, @@ -41,7 +41,7 @@ export class GLTFInstantiator { instantiate(gltf: any): GroupNode[] { this.gltf = gltf; - const scenes = (gltf.scenes || []).map((scene) => this.createScene(scene)); + const scenes = (gltf.scenes || []).map(scene => this.createScene(scene)); return scenes; } @@ -55,7 +55,7 @@ export class GLTFInstantiator { createScene(gltfScene: any): GroupNode { const gltfNodes = gltfScene.nodes || []; - const nodes = gltfNodes.map((node) => this.createNode(node)); + const nodes = gltfNodes.map(node => this.createNode(node)); const scene = new GroupNode({ id: gltfScene.name || gltfScene.id, children: nodes @@ -66,7 +66,7 @@ export class GLTFInstantiator { createNode(gltfNode) { if (!gltfNode._node) { const gltfChildren = gltfNode.children || []; - const children = gltfChildren.map((child) => this.createNode(child)); + const children = gltfChildren.map(child => this.createNode(child)); // Node can have children nodes and meshes at the same time if (gltfNode.mesh) { @@ -128,14 +128,17 @@ export class GLTFInstantiator { const modelNode = createGLTFModel(this.device, { id, - geometry: this.createGeometry(id, gltfPrimitive, topology), + geometry: this.createGeometry(id, gltfPrimitive, topology), material: gltfPrimitive.material, materialOptions: this.options, modelOptions: this.options.modelOptions, vertexCount }); - modelNode.bounds = [gltfPrimitive.attributes.POSITION.min, gltfPrimitive.attributes.POSITION.max]; + modelNode.bounds = [ + gltfPrimitive.attributes.POSITION.min, + gltfPrimitive.attributes.POSITION.max + ]; // TODO this holds on to all the CPU side texture and attribute data // modelNode.material = gltfPrimitive.material; @@ -147,12 +150,12 @@ export class GLTFInstantiator { } createGeometry(id: string, gltfPrimitive: any, topology: PrimitiveTopology): Geometry { - const attributes = {} + const attributes = {}; for (const [attributeName, attribute] of Object.entries(gltfPrimitive.attributes)) { const {components, size, value} = attribute as GeometryAttribute; attributes[attributeName] = {size: size ?? components, value}; - }; + } return new Geometry({ id, @@ -177,7 +180,7 @@ export class GLTFInstantiator { bufferView.lumaBuffers[usage] = this.device.createBuffer({ id: `from-${bufferView.id}`, // Draco decoded files have attribute.value - data: bufferView.data || attribute.value, + data: bufferView.data || attribute.value }); } @@ -214,16 +217,31 @@ enum GLEnum { } export function convertGLDrawModeToTopology( - drawMode: GLEnum.POINTS | GLEnum.LINES | GLEnum.LINE_STRIP | GLEnum.LINE_LOOP | GLEnum.TRIANGLES | GLEnum.TRIANGLE_STRIP | GLEnum.TRIANGLE_FAN, -): PrimitiveTopology { + drawMode: + | GLEnum.POINTS + | GLEnum.LINES + | GLEnum.LINE_STRIP + | GLEnum.LINE_LOOP + | GLEnum.TRIANGLES + | GLEnum.TRIANGLE_STRIP + | GLEnum.TRIANGLE_FAN +): PrimitiveTopology { switch (drawMode) { - case GLEnum.POINTS: return 'point-list'; - case GLEnum.LINES: return 'line-list'; - case GLEnum.LINE_STRIP: return 'line-strip'; - case GLEnum.LINE_LOOP: return 'line-loop-webgl'; - case GLEnum.TRIANGLES: return 'triangle-list'; - case GLEnum.TRIANGLE_STRIP: return 'triangle-strip'; - case GLEnum.TRIANGLE_FAN: return 'triangle-fan-webgl'; - default: throw new Error(drawMode); + case GLEnum.POINTS: + return 'point-list'; + case GLEnum.LINES: + return 'line-list'; + case GLEnum.LINE_STRIP: + return 'line-strip'; + case GLEnum.LINE_LOOP: + return 'line-loop-webgl'; + case GLEnum.TRIANGLES: + return 'triangle-list'; + case GLEnum.TRIANGLE_STRIP: + return 'triangle-strip'; + case GLEnum.TRIANGLE_FAN: + return 'triangle-fan-webgl'; + default: + throw new Error(drawMode); } } diff --git a/modules/gltf/src/index.ts b/modules/gltf/src/index.ts index 6edac01443..484f0d5441 100644 --- a/modules/gltf/src/index.ts +++ b/modules/gltf/src/index.ts @@ -8,4 +8,3 @@ export {loadPBREnvironment} from './pbr/pbr-environment'; // glTF Scenegraph Instantiator export {createScenegraphsFromGLTF} from './gltf/create-gltf-objects'; export {GLTFAnimator} from './gltf/gltf-animator'; - diff --git a/modules/gltf/src/pbr/parse-pbr-material.ts b/modules/gltf/src/pbr/parse-pbr-material.ts index 422ce2f56e..172911b733 100644 --- a/modules/gltf/src/pbr/parse-pbr-material.ts +++ b/modules/gltf/src/pbr/parse-pbr-material.ts @@ -36,7 +36,7 @@ enum GLEnum { TEXTURE_MIN_FILTER = 0x2801, LINEAR = 0x2601, LINEAR_MIPMAP_NEAREST = 0x2701, - UNPACK_FLIP_Y_WEBGL = 0x9240, + UNPACK_FLIP_Y_WEBGL = 0x9240 } /** @@ -62,7 +62,7 @@ export function parsePBRMaterial( u_MetallicRoughnessValues: [1, 1] // Default is 1 and 1 }, parameters: {}, - glParameters: {}, + glParameters: {}, generatedTextures: [] }; @@ -71,10 +71,8 @@ export function parsePBRMaterial( const {imageBasedLightingEnvironment} = options; if (imageBasedLightingEnvironment) { - parsedMaterial.bindings.u_DiffuseEnvSampler = - imageBasedLightingEnvironment.diffuseEnvSampler; - parsedMaterial.bindings.u_SpecularEnvSampler = - imageBasedLightingEnvironment.specularEnvSampler; + parsedMaterial.bindings.u_DiffuseEnvSampler = imageBasedLightingEnvironment.diffuseEnvSampler; + parsedMaterial.bindings.u_SpecularEnvSampler = imageBasedLightingEnvironment.specularEnvSampler; parsedMaterial.bindings.u_brdfLUT = imageBasedLightingEnvironment.brdfLutTexture; parsedMaterial.uniforms.u_ScaleIBLAmbient = [1, 1]; } @@ -149,7 +147,7 @@ function parseMaterial(device: Device, material, parsedMaterial: ParsedPBRMateri parsedMaterial.parameters.blendColorOperation = 'add'; parsedMaterial.parameters.blendColorSrcFactor = 'src-alpha'; parsedMaterial.parameters.blendColorDstFactor = 'one-minus-src-alpha'; - + parsedMaterial.parameters.blendAlphaOperation = 'add'; parsedMaterial.parameters.blendAlphaSrcFactor = 'one'; parsedMaterial.parameters.blendAlphaDstFactor = 'one-minus-src-alpha'; @@ -157,7 +155,12 @@ function parseMaterial(device: Device, material, parsedMaterial: ParsedPBRMateri // GL parameters parsedMaterial.glParameters.blend = true; parsedMaterial.glParameters.blendEquation = GLEnum.FUNC_ADD; - parsedMaterial.glParameters.blendFunc = [GLEnum.SRC_ALPHA, GLEnum.ONE_MINUS_SRC_ALPHA, GLEnum.ONE, GLEnum.ONE_MINUS_SRC_ALPHA]; + parsedMaterial.glParameters.blendFunc = [ + GLEnum.SRC_ALPHA, + GLEnum.ONE_MINUS_SRC_ALPHA, + GLEnum.ONE, + GLEnum.ONE_MINUS_SRC_ALPHA + ]; break; } @@ -209,7 +212,8 @@ function addTexture( if (image.compressed) { textureOptions = image; specialTextureParameters = { - [GLEnum.TEXTURE_MIN_FILTER]: image.data.length > 1 ? GLEnum.LINEAR_MIPMAP_NEAREST : GLEnum.LINEAR + [GLEnum.TEXTURE_MIN_FILTER]: + image.data.length > 1 ? GLEnum.LINEAR_MIPMAP_NEAREST : GLEnum.LINEAR }; } else { // Texture2D accepts a promise that returns an image as data (Async Textures) diff --git a/modules/gltf/src/pbr/pbr-environment.ts b/modules/gltf/src/pbr/pbr-environment.ts index 26a3d7e113..3fe3129daa 100644 --- a/modules/gltf/src/pbr/pbr-environment.ts +++ b/modules/gltf/src/pbr/pbr-environment.ts @@ -15,7 +15,7 @@ export type PBREnvironmentProps = { brdfLutUrl: string; getTexUrl: (name: string, dir: number, level: number) => string; specularMipLevels?: number; -} +}; /** Loads textures for PBR environment */ export function loadPBREnvironment(device: Device, props: PBREnvironmentProps): PBREnvironment { @@ -33,13 +33,13 @@ export function loadPBREnvironment(device: Device, props: PBREnvironmentProps): const diffuseEnvSampler = makeCube(device, { id: 'DiffuseEnvSampler', - getTextureForFace: (dir) => loadImageTexture(props.getTexUrl('diffuse', dir, 0)), + getTextureForFace: dir => loadImageTexture(props.getTexUrl('diffuse', dir, 0)), sampler: { wrapS: 'clamp-to-edge', wrapT: 'clamp-to-edge', minFilter: 'linear', maxFilter: 'linear' - } as SamplerProps, + } as SamplerProps }); const specularEnvSampler = makeCube(device, { @@ -56,26 +56,33 @@ export function loadPBREnvironment(device: Device, props: PBREnvironmentProps): wrapT: 'clamp-to-edge', minFilter: 'linear', // [GL.TEXTURE_MIN_FILTER]: GL.LINEAR_MIPMAP_LINEAR, maxFilter: 'linear' - } as SamplerProps, + } as SamplerProps }); return { brdfLutTexture, diffuseEnvSampler, specularEnvSampler - } + }; } // TODO put somewhere common const FACES = [0, 1, 2, 3, 4, 5]; -function makeCube(device: Device, {id, getTextureForFace, sampler}: { - id: string, - getTextureForFace: (dir: number) => Promise | Promise[], - sampler: SamplerProps -}): TextureCube { +function makeCube( + device: Device, + { + id, + getTextureForFace, + sampler + }: { + id: string; + getTextureForFace: (dir: number) => Promise | Promise[]; + sampler: SamplerProps; + } +): TextureCube { const data = {}; - FACES.forEach((face) => { + FACES.forEach(face => { data[String(face)] = getTextureForFace(face); }); return device.createTexture({ diff --git a/modules/gltf/test/gltf/gltf.spec.ts b/modules/gltf/test/gltf/gltf.spec.ts index 4cbf9565db..913fc58ddd 100644 --- a/modules/gltf/test/gltf/gltf.spec.ts +++ b/modules/gltf/test/gltf/gltf.spec.ts @@ -8,7 +8,7 @@ import {GLTFLoader} from '@loaders.gl/gltf'; import {Texture} from '@luma.gl/core'; import {createScenegraphsFromGLTF, loadPBREnvironment} from '@luma.gl/gltf'; -test('gltf#loading', async (t) => { +test('gltf#loading', async t => { // TODO - is gl argument used? const gltf = await load('test/data/box.glb', GLTFLoader); @@ -20,7 +20,7 @@ test('gltf#loading', async (t) => { t.end(); }); -test.skip('gltf#environment', (t) => { +test.skip('gltf#environment', t => { const environment = loadPBREnvironment(webglDevice, { brdfLutUrl: 'test/data/webgl-logo-0.png', getTexUrl: (type, dir, mipLevel) => `test/data/webgl-logo-${mipLevel}.png`, @@ -28,14 +28,8 @@ test.skip('gltf#environment', (t) => { }); t.ok(environment.brdfLutTexture instanceof Texture, 'BRDF lookup texture created'); - t.ok( - environment.diffuseEnvSampler instanceof Texture, - 'Diffuse environment map created' - ); - t.ok( - environment.specularEnvSampler instanceof Texture, - 'Specular environment map created' - ); + t.ok(environment.diffuseEnvSampler instanceof Texture, 'Diffuse environment map created'); + t.ok(environment.specularEnvSampler instanceof Texture, 'Specular environment map created'); t.end(); }); diff --git a/modules/gltf/test/index.ts b/modules/gltf/test/index.ts index d19d160de7..7786b12f6c 100644 --- a/modules/gltf/test/index.ts +++ b/modules/gltf/test/index.ts @@ -1,3 +1,2 @@ - // GLTF import './gltf/gltf.spec'; diff --git a/modules/shadertools/src/index.ts b/modules/shadertools/src/index.ts index 40383f0223..e8f021836e 100644 --- a/modules/shadertools/src/index.ts +++ b/modules/shadertools/src/index.ts @@ -129,7 +129,6 @@ export {fxaa} from './modules/postprocessing/fxaa/fxaa'; export type {WarpProps} from './modules/postprocessing/image-warp-filters/warp'; export {warp as _warp} from './modules/postprocessing/image-warp-filters/warp'; - // DEPRECATED - v8 legacy shader modules (non-uniform buffer) // math libraries diff --git a/modules/shadertools/src/lib/filters/prop-types.ts b/modules/shadertools/src/lib/filters/prop-types.ts index 73983b84ff..e96a5be081 100644 --- a/modules/shadertools/src/lib/filters/prop-types.ts +++ b/modules/shadertools/src/lib/filters/prop-types.ts @@ -3,24 +3,26 @@ import {assert} from '../utils/assert'; -/** - * For use by shader module and shader pass writers to describe the types of the +/** + * For use by shader module and shader pass writers to describe the types of the * properties they expose (properties ultimately map to uniforms). */ -export type PropType = { - type?: string; - value?: unknown; - max?: number; - min?: number; - softMax?: number; - softMin?: number; - hint?: string; - /** @deprecated internal uniform */ - private?: boolean; -} | number; +export type PropType = + | { + type?: string; + value?: unknown; + max?: number; + min?: number; + softMax?: number; + softMin?: number; + hint?: string; + /** @deprecated internal uniform */ + private?: boolean; + } + | number; /** - * Internal property validators generated by processing the prop types , + * Internal property validators generated by processing the prop types , * The `validate()` method can be used to validate the type of properties passed in to * shader module or shader pass */ @@ -41,8 +43,8 @@ const DEFAULT_PROP_VALIDATORS: Record = { return ( Number.isFinite(value) && typeof propType === 'object' && - (propType.max === undefined || value as number <= propType.max) && - (propType.min === undefined || value as number >= propType.min) + (propType.max === undefined || (value as number) <= propType.max) && + (propType.min === undefined || (value as number) >= propType.min) ); } }, @@ -57,10 +59,12 @@ const DEFAULT_PROP_VALIDATORS: Record = { /** * Parse a list of property types into property definitions that can be used to validate * values passed in by applications. - * @param propTypes - * @returns + * @param propTypes + * @returns */ -export function makePropValidators(propTypes: Record): Record { +export function makePropValidators( + propTypes: Record +): Record { const propValidators: Record = {}; for (const [name, propType] of Object.entries(propTypes)) { propValidators[name] = makePropValidator(propType); @@ -71,22 +75,24 @@ export function makePropValidators(propTypes: Record): Record< /** * Validate a map of user supplied properties against a map of validators * Inject default values when user doesn't supply a property - * @param properties - * @param propValidators - * @returns + * @param properties + * @param propValidators + * @returns */ export function getValidatedProperties( properties: Record, propValidators: Record, errorMessage: string ): Record { - const validated: Record = {}; for (const [key, propsValidator] of Object.entries(propValidators)) { if (properties && key in properties && !propsValidator.private) { if (propsValidator.validate) { - assert(propsValidator.validate(properties[key], propsValidator), `${errorMessage}: invalid ${key}`); + assert( + propsValidator.validate(properties[key], propsValidator), + `${errorMessage}: invalid ${key}` + ); } validated[key] = properties[key]; } else { @@ -100,7 +106,6 @@ export function getValidatedProperties( return validated; } - /** * Creates a property validator for a prop type. Either contains: * - a valid prop type object ({type, ...}) @@ -133,7 +138,7 @@ function makePropValidator(propType: PropType): PropValidator { throw new Error('props'); } -/** +/** * "improved" version of javascript typeof that can distinguish arrays and null values */ function getTypeOf(value: unknown): string { diff --git a/modules/shadertools/src/lib/glsl-utils/shader-utils.ts b/modules/shadertools/src/lib/glsl-utils/shader-utils.ts index 369c4fd61d..81d5a68dc0 100644 --- a/modules/shadertools/src/lib/glsl-utils/shader-utils.ts +++ b/modules/shadertools/src/lib/glsl-utils/shader-utils.ts @@ -14,10 +14,13 @@ type QualifierInfo = { qualifier: string; type: string; name: string; -} +}; // Prase given glsl line and return qualifier details or null -export function getQualifierDetails(line: string, qualifiers: string | string[]): QualifierInfo | null { +export function getQualifierDetails( + line: string, + qualifiers: string | string[] +): QualifierInfo | null { qualifiers = Array.isArray(qualifiers) ? qualifiers : [qualifiers]; const words = line.replace(/^\s+/, '').split(/\s+/); // TODO add support for precession qualifiers (highp, mediump and lowp) @@ -58,7 +61,7 @@ void main() { } /** convert glsl type to suffix */ -export function typeToChannelSuffix(type: string): 'x' | 'xy' | 'xyz' | 'xyzw' { +export function typeToChannelSuffix(type: string): 'x' | 'xy' | 'xyz' | 'xyzw' { // prettier-ignore switch (type) { case 'float': return 'x'; @@ -82,7 +85,7 @@ export function typeToChannelCount(type: string): 1 | 2 | 3 | 4 { throw new Error(type); } } -function channelCountToType(channels: 1 | 2 | 3 |4): 'float' | 'vec2' | 'vec3' | 'vec4' { +function channelCountToType(channels: 1 | 2 | 3 | 4): 'float' | 'vec2' | 'vec3' | 'vec4' { // prettier-ignore switch (channels) { case 1: return 'float'; diff --git a/modules/shadertools/src/lib/shader-assembler.ts b/modules/shadertools/src/lib/shader-assembler.ts index e76af73e97..f78ab01757 100644 --- a/modules/shadertools/src/lib/shader-assembler.ts +++ b/modules/shadertools/src/lib/shader-assembler.ts @@ -20,15 +20,16 @@ export class ShaderAssembler { /** * A default shader assembler instance - the natural place to register default modules and hooks - * @returns + * @returns */ static getDefaultShaderAssembler(): ShaderAssembler { - ShaderAssembler.defaultShaderAssembler = ShaderAssembler.defaultShaderAssembler || new ShaderAssembler(); + ShaderAssembler.defaultShaderAssembler = + ShaderAssembler.defaultShaderAssembler || new ShaderAssembler(); return ShaderAssembler.defaultShaderAssembler; } - /** - * Add a default module that does not have to be provided with every call to assembleShaders() + /** + * Add a default module that does not have to be provided with every call to assembleShaders() */ addDefaultModule(module: ShaderModule): void { if ( @@ -40,7 +41,7 @@ export class ShaderAssembler { } } - /** + /** * Remove a default module */ removeDefaultModule(module: ShaderModule): void { @@ -50,8 +51,8 @@ export class ShaderAssembler { /** * Register a shader hook - * @param hook - * @param opts + * @param hook + * @param opts */ addShaderHook(hook: string, opts?: any): void { if (opts) { @@ -62,28 +63,35 @@ export class ShaderAssembler { /** * Assemble a pair of shaders into a single shader program - * @param platformInfo - * @param props - * @returns + * @param platformInfo + * @param props + * @returns */ assembleShaders(props: AssembleShaderProps): { vs: string; fs: string; getUniforms: GetUniformsFunc; - modules:ShaderModuleInstance[]; + modules: ShaderModuleInstance[]; } { const modules = this._getModuleList(props.modules); // Combine with default modules const hookFunctions = this._hookFunctions; // TODO - combine with default hook functions const options = selectShaders(props); - const assembled = assembleShaders({platformInfo: props.platformInfo, ...options, modules, hookFunctions}); + const assembled = assembleShaders({ + platformInfo: props.platformInfo, + ...options, + modules, + hookFunctions + }); return {...assembled, modules}; } - /** + /** * Dedupe and combine with default modules */ _getModuleList(appModules: (ShaderModule | ShaderModuleInstance)[] = []): ShaderModuleInstance[] { - const modules = new Array(this._defaultModules.length + appModules.length); + const modules = new Array( + this._defaultModules.length + appModules.length + ); const seen: Record = {}; let count = 0; diff --git a/modules/shadertools/src/lib/shader-assembly/assemble-shaders.ts b/modules/shadertools/src/lib/shader-assembly/assemble-shaders.ts index 54629c088a..fd6a685e1d 100644 --- a/modules/shadertools/src/lib/shader-assembly/assemble-shaders.ts +++ b/modules/shadertools/src/lib/shader-assembly/assemble-shaders.ts @@ -12,7 +12,7 @@ import type {ShaderInjection} from './shader-injections'; import type {ShaderModule} from '../shader-module/shader-module'; import {ShaderHook, normalizeShaderHooks, getShaderHooks} from './shader-hooks'; import {assert} from '../utils/assert'; -import { getShaderInfo } from '../glsl-utils/get-shader-info'; +import {getShaderInfo} from '../glsl-utils/get-shader-info'; /** Define map */ export type ShaderDefine = string | number | boolean; @@ -31,7 +31,7 @@ export type HookFunction = {hook: string; header: string; footer: string; signat export type AssembleShaderOptions = { /** information about the platform (which shader language & version, extensions etc.) */ - platformInfo: PlatformInfo, + platformInfo: PlatformInfo; /** Inject shader id #defines */ id?: string; /** Vertex shader */ @@ -82,9 +82,7 @@ export type GetUniformsFunc = (opts: Record) => Record /** * Inject a list of shader modules into shader sources */ -export function assembleShaders( - options: AssembleShaderOptions -): { +export function assembleShaders(options: AssembleShaderOptions): { vs: string; fs: string; getUniforms: GetUniformsFunc; @@ -95,15 +93,35 @@ export function assembleShaders( switch (options.platformInfo.shaderLanguage) { case 'glsl': return { - vs: assembleGLSLShader(options.platformInfo, {...options, source: vs, stage: 'vertex', modules}), - fs: assembleGLSLShader(options.platformInfo, {...options, source: fs, stage: 'fragment', modules}), + vs: assembleGLSLShader(options.platformInfo, { + ...options, + source: vs, + stage: 'vertex', + modules + }), + fs: assembleGLSLShader(options.platformInfo, { + ...options, + source: fs, + stage: 'fragment', + modules + }), getUniforms: assembleGetUniforms(modules) }; case 'wgsl': return { - vs: assembleWGSLShader(options.platformInfo, {...options, source: vs, stage: 'vertex', modules}), - fs: assembleWGSLShader(options.platformInfo, {...options, source: fs, stage: 'fragment', modules}), + vs: assembleWGSLShader(options.platformInfo, { + ...options, + source: vs, + stage: 'vertex', + modules + }), + fs: assembleWGSLShader(options.platformInfo, { + ...options, + source: fs, + stage: 'fragment', + modules + }), getUniforms: assembleGetUniforms(modules) }; } @@ -265,7 +283,7 @@ function assembleGLSLShader( assert(typeof source === 'string', 'shader source must be a string'); - const sourceVersion = language === 'glsl' ? getShaderInfo(source).version : -1; + const sourceVersion = language === 'glsl' ? getShaderInfo(source).version : -1; const targetVersion = platformInfo.shaderLanguageVersion; const sourceVersionDirective = sourceVersion === 100 ? '#version 100' : '#version 300 es'; @@ -377,7 +395,7 @@ ${getApplicationDefines(allDefines)} // Apply any requested shader injections assembledSource = injectShader(assembledSource, stage, mainInjections); - + if (language === 'glsl' && sourceVersion !== targetVersion) { assembledSource = transpileGLSLShader(assembledSource, stage); } diff --git a/modules/shadertools/src/lib/shader-assembly/platform-info.ts b/modules/shadertools/src/lib/shader-assembly/platform-info.ts index 616715be0b..6b2b065e18 100644 --- a/modules/shadertools/src/lib/shader-assembly/platform-info.ts +++ b/modules/shadertools/src/lib/shader-assembly/platform-info.ts @@ -1,8 +1,8 @@ // luma.gl, MIT license // Copyright (c) vis.gl contributors -/** - * PlatformInfo +/** + * PlatformInfo * @note Designed so that it can be easily created from a luma.gl Device instance * Without having any actual dependency on `@luma.gl/core` */ diff --git a/modules/shadertools/src/lib/shader-assembly/resolve-modules.ts b/modules/shadertools/src/lib/shader-assembly/resolve-modules.ts index ad90ebc734..bfcb43bdf5 100644 --- a/modules/shadertools/src/lib/shader-assembly/resolve-modules.ts +++ b/modules/shadertools/src/lib/shader-assembly/resolve-modules.ts @@ -4,10 +4,12 @@ import type {ShaderModule} from '../shader-module/shader-module'; import {ShaderModuleInstance} from '../shader-module/shader-module-instance'; -/** +/** * Instantiate shader modules and esolve any dependencies - */ -export function resolveModules(modules: (ShaderModule | ShaderModuleInstance)[]): ShaderModuleInstance[] { + */ +export function resolveModules( + modules: (ShaderModule | ShaderModuleInstance)[] +): ShaderModuleInstance[] { const instances = ShaderModuleInstance.instantiateModules(modules); return getShaderDependencies(instances); } @@ -32,7 +34,7 @@ function getShaderDependencies(modules: ShaderModuleInstance[]): ShaderModuleIns // Return a reverse sort so that dependencies come before the modules that use them return Object.keys(moduleDepth) .sort((a, b) => moduleDepth[b] - moduleDepth[a]) - .map((name) => moduleMap[name]); + .map(name => moduleMap[name]); } /** @@ -46,8 +48,8 @@ function getShaderDependencies(modules: ShaderModuleInstance[]): ShaderModuleIns */ // Adds another level of dependencies to the result map export function getDependencyGraph(options: { - modules: ShaderModuleInstance[], - level: number, + modules: ShaderModuleInstance[]; + level: number; moduleMap: Record; moduleDepth: Record; }) { diff --git a/modules/shadertools/src/lib/shader-assembly/select-shaders.ts b/modules/shadertools/src/lib/shader-assembly/select-shaders.ts index 5b295d2020..d8f53edb28 100644 --- a/modules/shadertools/src/lib/shader-assembly/select-shaders.ts +++ b/modules/shadertools/src/lib/shader-assembly/select-shaders.ts @@ -1,7 +1,6 @@ // luma.gl, MIT license // Copyright (c) vis.gl contributors - import type {PlatformInfo} from './platform-info'; import type {AssembleShaderOptions} from './assemble-shaders'; @@ -13,18 +12,16 @@ export type AssembleShaderProps = Omit & { /** Vertex shader source. Can be GLSL or WGSL or both */ vs?: {glsl?: string; wgsl?: string} | string | null; /** Fragment shader source. Can be GLSL or WGSL or both */ - fs?: {glsl?: string; wgsl?: string} | string | null; + fs?: {glsl?: string; wgsl?: string} | string | null; }; /** - * Shader selection + * Shader selection * @param device * @param props * @returns */ -export function selectShaders( - props: AssembleShaderProps -): AssembleShaderOptions { +export function selectShaders(props: AssembleShaderProps): AssembleShaderOptions { if (!props.vs) { throw new Error('no vertex shader'); } @@ -40,7 +37,10 @@ export function selectShaders( } /** Create a shader from the different overloads */ -function getShaderSource(platformInfo: PlatformInfo, shader: string | {glsl?: string; wgsl?: string}): string { +function getShaderSource( + platformInfo: PlatformInfo, + shader: string | {glsl?: string; wgsl?: string} +): string { // TODO - detect WGSL/GLSL and throw an error if not supported if (typeof shader === 'string') { return shader; diff --git a/modules/shadertools/src/lib/shader-assembly/shader-hooks.ts b/modules/shadertools/src/lib/shader-assembly/shader-hooks.ts index d02c691e85..af9c6daa43 100644 --- a/modules/shadertools/src/lib/shader-assembly/shader-hooks.ts +++ b/modules/shadertools/src/lib/shader-assembly/shader-hooks.ts @@ -63,8 +63,8 @@ export function getShaderHooks( return result; } -/** - * Parse string based hook functions +/** + * Parse string based hook functions * And split per shader */ export function normalizeShaderHooks(hookFunctions: (string | ShaderHook)[]): ShaderHooks { diff --git a/modules/shadertools/src/lib/shader-assembly/shader-injections.ts b/modules/shadertools/src/lib/shader-assembly/shader-injections.ts index 8ba20e15a1..06299986b1 100644 --- a/modules/shadertools/src/lib/shader-assembly/shader-injections.ts +++ b/modules/shadertools/src/lib/shader-assembly/shader-injections.ts @@ -17,7 +17,7 @@ const fragments: string[] = []; export const DECLARATION_INJECT_MARKER = '__LUMA_INJECT_DECLARATIONS__'; /** - * + * */ export type ShaderInjection = { injection: string; @@ -33,9 +33,11 @@ export type ShaderInjections = { }; /** - * + * */ -export function normalizeInjections(injections: Record): ShaderInjections { +export function normalizeInjections( + injections: Record +): ShaderInjections { const result: ShaderInjections = {vertex: {}, fragment: {}}; for (const hook in injections) { @@ -57,8 +59,10 @@ export function normalizeInjections(injections: Record, + source: string, + stage: 'vertex' | 'fragment', + inject: Record, injectStandardStubs = false ): string { const isVertex = stage === 'vertex'; @@ -151,7 +155,7 @@ export function injectShader( export function combineInjects(injects: any[]): Record { const result: Record = {}; assert(Array.isArray(injects) && injects.length > 1); - injects.forEach((inject) => { + injects.forEach(inject => { for (const key in inject) { result[key] = result[key] ? `${result[key]}\n${inject[key]}` : inject[key]; } diff --git a/modules/shadertools/src/lib/shader-generator/generate-shader.ts b/modules/shadertools/src/lib/shader-generator/generate-shader.ts index 85a25a370b..f878498012 100644 --- a/modules/shadertools/src/lib/shader-generator/generate-shader.ts +++ b/modules/shadertools/src/lib/shader-generator/generate-shader.ts @@ -13,7 +13,10 @@ import {generateWGSLForModule} from './wgsl/generate-wgsl'; export type ShaderGenerationOptions = GLSLGenerationOptions | WGSLGenerationOptions; /** Generates shader code for a module */ -export function generateShaderForModule(module: ShaderModule>, options: ShaderGenerationOptions): string { +export function generateShaderForModule( + module: ShaderModule>, + options: ShaderGenerationOptions +): string { switch (options.shaderLanguage) { case 'glsl': return generateGLSLForModule(module, options); diff --git a/modules/shadertools/src/lib/shader-generator/glsl/generate-glsl.ts b/modules/shadertools/src/lib/shader-generator/glsl/generate-glsl.ts index 9b2bba0402..1f11aeb020 100644 --- a/modules/shadertools/src/lib/shader-generator/glsl/generate-glsl.ts +++ b/modules/shadertools/src/lib/shader-generator/glsl/generate-glsl.ts @@ -14,7 +14,10 @@ export function generateGLSLForModule(module: ShaderModule, options: GLSLGenerat return generateGLSLUniformDeclarations(module, options); } -function generateGLSLUniformDeclarations(module: ShaderModule, options: GLSLGenerationOptions): string { +function generateGLSLUniformDeclarations( + module: ShaderModule, + options: GLSLGenerationOptions +): string { const glsl: string[] = []; // => uniform UniformBlockName { @@ -24,18 +27,18 @@ function generateGLSLUniformDeclarations(module: ShaderModule, options: GLSLGene glsl.push(`uniform ${capitalize(module.name)} {`); break; case 'uniforms': - // ignore + // ignore } for (const [uniformName, uniformFormat] of Object.entries(module.uniformTypes || {})) { const glslUniformType = getGLSLUniformType(uniformFormat); switch (options.uniforms) { case 'scoped-interface-blocks': - // => uniform UniformBlockName { + // => uniform UniformBlockName { glsl.push(` ${glslUniformType} ${uniformName};`); break; case 'unscoped-interface-blocks': - // => uniform UniformBlockName { + // => uniform UniformBlockName { glsl.push(` ${glslUniformType} ${module.name}_${uniformName};`); break; case 'uniforms': @@ -51,7 +54,7 @@ function generateGLSLUniformDeclarations(module: ShaderModule, options: GLSLGene glsl.push('};'); break; case 'uniforms': - // ignore + // ignore } // final new line @@ -60,13 +63,12 @@ function generateGLSLUniformDeclarations(module: ShaderModule, options: GLSLGene return glsl.join('\n'); } - /** Map a luma.gl WebGPU style uniform type to GLSL */ function getGLSLUniformType(uniformFormat: UniformFormat): string { const UNIFORM_TYPE_TO_GLSL: Record = { - 'f32': 'float', - 'i32': 'int', - 'u32': 'uint', + f32: 'float', + i32: 'int', + u32: 'uint', 'vec2': 'vec2', 'vec3': 'vec3', 'vec4': 'vec4', @@ -84,10 +86,9 @@ function getGLSLUniformType(uniformFormat: UniformFormat): string { 'mat3x4': 'mat3x4', 'mat4x2': 'mat4x2', 'mat4x3': 'mat4x3', - 'mat4x4': 'mat4', + 'mat4x4': 'mat4' }; - + const glsl = UNIFORM_TYPE_TO_GLSL[uniformFormat]; return glsl; } - diff --git a/modules/shadertools/src/lib/shader-generator/wgsl/generate-wgsl.ts b/modules/shadertools/src/lib/shader-generator/wgsl/generate-wgsl.ts index 0d3be1f794..7348663a1a 100644 --- a/modules/shadertools/src/lib/shader-generator/wgsl/generate-wgsl.ts +++ b/modules/shadertools/src/lib/shader-generator/wgsl/generate-wgsl.ts @@ -12,7 +12,10 @@ export function generateWGSLForModule(module: ShaderModule, options: WGSLGenerat return generateWGSLUniformDeclarations(module, options); } -export function generateWGSLUniformDeclarations(module: ShaderModule, options: WGSLGenerationOptions) { +export function generateWGSLUniformDeclarations( + module: ShaderModule, + options: WGSLGenerationOptions +) { const wgsl: string[] = []; // => uniform UniformBlockName { diff --git a/modules/shadertools/src/lib/shader-module/shader-module-instance.ts b/modules/shadertools/src/lib/shader-module/shader-module-instance.ts index 9edc02daa5..be32a70932 100644 --- a/modules/shadertools/src/lib/shader-module/shader-module-instance.ts +++ b/modules/shadertools/src/lib/shader-module/shader-module-instance.ts @@ -4,7 +4,7 @@ import {assert} from '../utils/assert'; import {makePropValidators, getValidatedProperties, PropValidator} from '../filters/prop-types'; import {ShaderModule, ShaderModuleDeprecation} from './shader-module'; -import { ShaderInjection, normalizeInjections } from '../shader-assembly/shader-injections'; +import {ShaderInjection, normalizeInjections} from '../shader-assembly/shader-injections'; let index = 1; @@ -34,7 +34,9 @@ export class ShaderModuleInstance { assert( typeof module !== 'string', - `Shader module use by name is deprecated. Import shader module '${JSON.stringify(module)}' and use it directly.` + `Shader module use by name is deprecated. Import shader module '${JSON.stringify( + module + )}' and use it directly.` ); if (!module.name) { // eslint-disable-next-line no-console @@ -43,7 +45,9 @@ export class ShaderModuleInstance { } const moduleObject = new ShaderModuleInstance(module); - moduleObject.dependencies = ShaderModuleInstance.instantiateModules(module.dependencies || []); + moduleObject.dependencies = ShaderModuleInstance.instantiateModules( + module.dependencies || [] + ); return moduleObject; }); diff --git a/modules/shadertools/src/lib/shader-module/shader-module.ts b/modules/shadertools/src/lib/shader-module/shader-module.ts index e0ad6e29fb..768ca02da8 100644 --- a/modules/shadertools/src/lib/shader-module/shader-module.ts +++ b/modules/shadertools/src/lib/shader-module/shader-module.ts @@ -8,16 +8,18 @@ import {PropType} from '../filters/prop-types'; export type UniformValue = number | boolean | Readonly; // Float32Array> | Readonly | Readonly | Readonly; export type UniformInfo = { - format?: UniformFormat; + format?: UniformFormat; } & PropType; - - -/** +/** * A shader module definition object * @note Can be viewed as the ShaderModuleProps for a ShaderModuleInstance */ -export type ShaderModule = Record, UniformsT extends Record = Record, BindingsT extends Record = {}> = { +export type ShaderModule< + PropsT extends Record = Record, + UniformsT extends Record = Record, + BindingsT extends Record = {} +> = { /** Used for type inference not for values */ props?: Required; /** Used for type inference, not currently used for values */ @@ -43,7 +45,7 @@ export type ShaderModule = Record; /** Injections */ - inject?: Record; + inject?: Record; dependencies?: ShaderModule[]; /** Information on deprecated properties */ deprecations?: ShaderModuleDeprecation[]; diff --git a/modules/shadertools/src/lib/shader-module/shader-pass.ts b/modules/shadertools/src/lib/shader-module/shader-pass.ts index ef18abc1e4..fb39b5340a 100644 --- a/modules/shadertools/src/lib/shader-module/shader-pass.ts +++ b/modules/shadertools/src/lib/shader-module/shader-pass.ts @@ -5,9 +5,12 @@ import type {ShaderModule, UniformValue} from './shader-module'; /** * A shaderpass is a shader module with additional information - * on how to run + * on how to run */ -export type ShaderPass = Record, UniformsT extends Record = Record> = ShaderModule & { +export type ShaderPass< + PropsT extends Record = Record, + UniformsT extends Record = Record +> = ShaderModule & { passes: ShaderPassData[]; }; @@ -15,4 +18,4 @@ type ShaderPassData = { sampler?: boolean; filter?: boolean; uniforms?: Record; -} +}; diff --git a/modules/shadertools/src/lib/shader-transpiler/transpile-glsl-shader.ts b/modules/shadertools/src/lib/shader-transpiler/transpile-glsl-shader.ts index e01adfe84d..1a77a4bcd0 100644 --- a/modules/shadertools/src/lib/shader-transpiler/transpile-glsl-shader.ts +++ b/modules/shadertools/src/lib/shader-transpiler/transpile-glsl-shader.ts @@ -10,10 +10,7 @@ * @note For texture sampling transpilation, apps need to use non-standard texture* calls in GLSL 3.00 source * RFC: https://github.com/visgl/luma.gl/blob/7.0-release/dev-docs/RFCs/v6.0/portable-glsl-300-rfc.md */ -export function transpileGLSLShader( - source: string, - stage: 'vertex' | 'fragment' -): string { +export function transpileGLSLShader(source: string, stage: 'vertex' | 'fragment'): string { const sourceGLSLVersion = Number(source.match(/^#version[ \t]+(\d+)/m)?.[1] || 100); if (sourceGLSLVersion !== 300) { // TODO - we splurge on a longer error message to help deck.gl custom layer developers diff --git a/modules/shadertools/src/lib/wgsl/get-shader-layout-wgsl.ts b/modules/shadertools/src/lib/wgsl/get-shader-layout-wgsl.ts index 50f7708cc3..53df072e4f 100644 --- a/modules/shadertools/src/lib/wgsl/get-shader-layout-wgsl.ts +++ b/modules/shadertools/src/lib/wgsl/get-shader-layout-wgsl.ts @@ -7,10 +7,9 @@ import {WgslReflect} from '../../libs/wgsl-reflect/wgsl_reflect.module.js'; /** * Parse a ShaderLayout from WGSL shader source code. * @param source WGSL source code (can contain both @vertex and @fragment entry points) - * @returns + * @returns */ export function getShaderLayoutFromWGSL(source: string): ShaderLayout { - const shaderLayout: ShaderLayout = {attributes: [], bindings: []}; const parsedWGSL = parseWGSL(source); diff --git a/modules/shadertools/src/modules-webgl1/lighting/dirlight/dirlight.ts b/modules/shadertools/src/modules-webgl1/lighting/dirlight/dirlight.ts index 04e5bc85af..0e7fe75962 100644 --- a/modules/shadertools/src/modules-webgl1/lighting/dirlight/dirlight.ts +++ b/modules/shadertools/src/modules-webgl1/lighting/dirlight/dirlight.ts @@ -7,8 +7,8 @@ import {project} from '../../project/project'; /* eslint-disable camelcase */ export type DirlightOptions = { - lightDirection?: NumberArray -} + lightDirection?: NumberArray; +}; const DEFAULT_MODULE_OPTIONS: Required = { lightDirection: new Float32Array([1, 1, 2]) diff --git a/modules/shadertools/src/modules-webgl1/lighting/lights/lights.ts b/modules/shadertools/src/modules-webgl1/lighting/lights/lights.ts index 37a9ebb6ee..3e55a69751 100644 --- a/modules/shadertools/src/modules-webgl1/lighting/lights/lights.ts +++ b/modules/shadertools/src/modules-webgl1/lighting/lights/lights.ts @@ -31,9 +31,11 @@ const INITIAL_MODULE_OPTIONS: Required = { }; // Take color 0-255 and intensity as input and output 0.0-1.0 range -function convertColor(colorDef: {color?: Readonly, intensity?: number} = {}): NumberArray { +function convertColor( + colorDef: {color?: Readonly; intensity?: number} = {} +): NumberArray { const {color = [0, 0, 0], intensity = 1.0} = colorDef; - return color.map((component) => (component * intensity) / 255.0); + return color.map(component => (component * intensity) / 255.0); } function getLightSourceUniforms({ diff --git a/modules/shadertools/src/modules-webgl1/lighting/phong-lighting/phong-lighting.ts b/modules/shadertools/src/modules-webgl1/lighting/phong-lighting/phong-lighting.ts index 171f2ac745..e52be5f35d 100644 --- a/modules/shadertools/src/modules-webgl1/lighting/phong-lighting/phong-lighting.ts +++ b/modules/shadertools/src/modules-webgl1/lighting/phong-lighting/phong-lighting.ts @@ -8,11 +8,10 @@ export type PhongLightingProps = { diffuse?: number; shininess?: number; specularColor?: [number, number, number]; -} +}; const INITIAL_MODULE_OPTIONS: {material?: PhongLightingProps} = {}; - function getMaterialUniforms(material: PhongLightingProps) { const {ambient = 0.35, diffuse = 0.6, shininess = 32, specularColor = [30, 30, 30]} = material; @@ -20,11 +19,13 @@ function getMaterialUniforms(material: PhongLightingProps) { lighting_uAmbient: ambient, lighting_uDiffuse: diffuse, lighting_uShininess: shininess, - lighting_uSpecularColor: specularColor.map((x) => x / 255) + lighting_uSpecularColor: specularColor.map(x => x / 255) }; } -function getUniforms(opts: {material?: PhongLightingProps} = INITIAL_MODULE_OPTIONS): Record { +function getUniforms( + opts: {material?: PhongLightingProps} = INITIAL_MODULE_OPTIONS +): Record { if (!('material' in opts)) { return {}; } diff --git a/modules/shadertools/src/modules-webgl1/math/fp64/fp64.ts b/modules/shadertools/src/modules-webgl1/math/fp64/fp64.ts index 1ee3602b4d..2ffd274066 100644 --- a/modules/shadertools/src/modules-webgl1/math/fp64/fp64.ts +++ b/modules/shadertools/src/modules-webgl1/math/fp64/fp64.ts @@ -26,8 +26,8 @@ export const fp64arithmetic = { }; /** -* Full 64 bit math library -*/ + * Full 64 bit math library + */ export const fp64 = { name: 'fp64', vs: fp64functionShader, diff --git a/modules/shadertools/src/modules-webgl1/project/project.ts b/modules/shadertools/src/modules-webgl1/project/project.ts index 2f9aed3af8..012d682f0d 100644 --- a/modules/shadertools/src/modules-webgl1/project/project.ts +++ b/modules/shadertools/src/modules-webgl1/project/project.ts @@ -3,10 +3,10 @@ import {glsl} from '../../lib/glsl-utils/highlight'; import {ShaderModule} from '../..'; type ProjectionProps = { - modelMatrix?: readonly number[], - viewMatrix?: readonly number[], - projectionMatrix?: readonly number[], - cameraPositionWorld?: readonly number[] + modelMatrix?: readonly number[]; + viewMatrix?: readonly number[]; + projectionMatrix?: readonly number[]; + cameraPositionWorld?: readonly number[]; }; const IDENTITY_MATRIX = [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]; diff --git a/modules/shadertools/src/modules/engine/picking/picking.ts b/modules/shadertools/src/modules/engine/picking/picking.ts index 950a9c6dda..1221dd613e 100644 --- a/modules/shadertools/src/modules/engine/picking/picking.ts +++ b/modules/shadertools/src/modules/engine/picking/picking.ts @@ -8,10 +8,10 @@ import {ShaderModule} from '../../../lib/shader-module/shader-module'; // cyan color const DEFAULT_HIGHLIGHT_COLOR = new Float32Array([0, 1, 1, 1]); -/** +/** * Props for the picking module, which depending on mode renders picking colors or highlighted item. - * When active, renders picking colors, assumed to be rendered to off-screen "picking" buffer. - * When inactive, renders normal colors, with the exception of selected object which is rendered with highlight + * When active, renders picking colors, assumed to be rendered to off-screen "picking" buffer. + * When inactive, renders normal colors, with the exception of selected object which is rendered with highlight */ export type PickingProps = { /** Are we picking? I.e. rendering picking colors? */ @@ -26,15 +26,15 @@ export type PickingProps = { useFloatColors?: boolean; }; -/** - * Uniforms for the picking module, which renders picking colors and highlighted item. - * When active, renders picking colors, assumed to be rendered to off-screen "picking" buffer. - * When inactive, renders normal colors, with the exception of selected object which is rendered with highlight +/** + * Uniforms for the picking module, which renders picking colors and highlighted item. + * When active, renders picking colors, assumed to be rendered to off-screen "picking" buffer. + * When inactive, renders normal colors, with the exception of selected object which is rendered with highlight */ export type PickingUniforms = { - /** - * When true, renders picking colors. Set when rendering to off-screen "picking" buffer. - * When false, renders normal colors, with the exception of selected object which is rendered with highlight + /** + * When true, renders picking colors. Set when rendering to off-screen "picking" buffer. + * When false, renders normal colors, with the exception of selected object which is rendered with highlight */ isActive?: boolean; /** Set to true when picking an attribute value instead of object index */ @@ -226,7 +226,7 @@ function getUniforms(opts: PickingProps = {}, prevUniforms?: PickingUniforms): P } if (opts.highlightColor) { - const color = Array.from(opts.highlightColor, (x) => x / 255); + const color = Array.from(opts.highlightColor, x => x / 255); if (!Number.isFinite(color[3])) { color[3] = 1; } diff --git a/modules/shadertools/src/modules/engine/project/project.ts b/modules/shadertools/src/modules/engine/project/project.ts index 254c906d5c..ae4d209ff4 100644 --- a/modules/shadertools/src/modules/engine/project/project.ts +++ b/modules/shadertools/src/modules/engine/project/project.ts @@ -35,7 +35,10 @@ const DEFAULT_MODULE_OPTIONS: Required = { cameraPositionWorld: [0, 0, 0] }; -function getUniforms(opts: ProjectionProps = DEFAULT_MODULE_OPTIONS, prevUniforms: ProjectionUniforms = {}): ProjectionUniforms { +function getUniforms( + opts: ProjectionProps = DEFAULT_MODULE_OPTIONS, + prevUniforms: ProjectionUniforms = {} +): ProjectionUniforms { // const viewProjectionInverse = viewProjection.invert(); // viewInverseMatrix: view.invert(), // viewProjectionInverseMatrix: viewProjectionInverse diff --git a/modules/shadertools/src/modules/lighting/gouraud-material/gouraud-material.ts b/modules/shadertools/src/modules/lighting/gouraud-material/gouraud-material.ts index a039fdb2d5..51836bb32b 100644 --- a/modules/shadertools/src/modules/lighting/gouraud-material/gouraud-material.ts +++ b/modules/shadertools/src/modules/lighting/gouraud-material/gouraud-material.ts @@ -13,7 +13,7 @@ export type GouraudMaterialUniforms = { /** Specularity exponent */ shininess?: number; specularColor?: [number, number, number]; -} +}; /** In Gouraud shading, color is calculated for each triangle vertex normal, and then color is interpolated colors across the triangle */ export const gouraudMaterial: ShaderModule = { @@ -26,15 +26,15 @@ export const gouraudMaterial: ShaderModule' }, defaultUniforms: { - ambient: 0.35, - diffuse: 0.6, - shininess: 32, + ambient: 0.35, + diffuse: 0.6, + shininess: 32, specularColor: [0.15, 0.15, 0.15] }, getUniforms(props: GouraudMaterialProps): GouraudMaterialUniforms { diff --git a/modules/shadertools/src/modules/lighting/lights/lighting-uniforms.ts b/modules/shadertools/src/modules/lighting/lights/lighting-uniforms.ts index d8afc76982..71d09b1930 100644 --- a/modules/shadertools/src/modules/lighting/lights/lighting-uniforms.ts +++ b/modules/shadertools/src/modules/lighting/lights/lighting-uniforms.ts @@ -25,7 +25,7 @@ export type AmbientLight = { type: 'ambient'; color?: Readonly; intensity?: number; -} +}; export type PointLight = { type: 'point'; @@ -33,7 +33,7 @@ export type PointLight = { color?: Readonly; intensity?: number; attenuation?: number; -} +}; export type DirectionalLight = { type: 'directional'; @@ -41,7 +41,7 @@ export type DirectionalLight = { direction: Readonly; color?: Readonly; intensity?: number; -} +}; export type LightingProps = { enabled?: boolean; @@ -91,7 +91,7 @@ export const lighting: ShaderModule = { lightAttenuation: 'vec3' // , array: MAX_LIGHTS}, }, - defaultUniforms: { + defaultUniforms: { enabled: 1, ambientLightColor: [0.1, 0.1, 0.1], numberOfLights: 0, @@ -100,12 +100,15 @@ export const lighting: ShaderModule = { lightPosition: [1, 1, 2], // TODO - could combine direction and attenuation lightDirection: [1, 1, 1], - lightAttenuation: [1, 1, 1], + lightAttenuation: [1, 1, 1] } }; -function getUniforms(props?: LightingProps, prevUniforms: Partial = {}): LightingUniforms { - // Copy props so we can modify +function getUniforms( + props?: LightingProps, + prevUniforms: Partial = {} +): LightingUniforms { + // Copy props so we can modify props = props ? {...props} : props; // TODO legacy @@ -132,7 +135,7 @@ function getUniforms(props?: LightingProps, prevUniforms: Partial, intensity?: number} = {}): NumberArray { +function convertColor( + colorDef: {color?: Readonly; intensity?: number} = {} +): NumberArray { const {color = [0, 0, 0], intensity = 1.0} = colorDef; - return color.map((component) => (component * intensity) / COLOR_FACTOR); + return color.map(component => (component * intensity) / COLOR_FACTOR); } diff --git a/modules/shadertools/src/modules/lighting/no-material/dirlight.ts b/modules/shadertools/src/modules/lighting/no-material/dirlight.ts index 15b7d4776d..1393e4f4c8 100644 --- a/modules/shadertools/src/modules/lighting/no-material/dirlight.ts +++ b/modules/shadertools/src/modules/lighting/no-material/dirlight.ts @@ -6,20 +6,20 @@ import {glsl} from '../../../lib/glsl-utils/highlight'; import {ShaderModule} from '../../../lib/shader-module/shader-module'; export type DirlightProps = { - lightDirection?: NumberArray | [number, number, number] -} + lightDirection?: NumberArray | [number, number, number]; +}; export type DirlightUniforms = DirlightProps; // TODO -export const VS_WGSL = /* WGSL */`\ +export const VS_WGSL = /* WGSL */ `\ void dirlight_setNormal(normal: vec3) { dirlight_vNormal = normalize(normal); } `; // TODO -export const FS_WGSL = /* WGSL */`\ +export const FS_WGSL = /* WGSL */ `\ uniform dirlightUniforms { vec3 lightDirection; } dirlight; diff --git a/modules/shadertools/src/modules/lighting/pbr-material/pbr-material.ts b/modules/shadertools/src/modules/lighting/pbr-material/pbr-material.ts index 88dbacf082..b3517833a7 100644 --- a/modules/shadertools/src/modules/lighting/pbr-material/pbr-material.ts +++ b/modules/shadertools/src/modules/lighting/pbr-material/pbr-material.ts @@ -10,7 +10,6 @@ import {lighting} from '../lights/lighting-uniforms'; import {vs} from './pbr-vertex-glsl'; import {fs} from './pbr-fragment-glsl'; - export type PBRMaterialProps = PBRMaterialBindings & { unlit: boolean; @@ -18,7 +17,7 @@ export type PBRMaterialProps = PBRMaterialBindings & { baseColorMapEnabled: boolean; baseColorFactor: Readonly; - normalMapEnabled: boolean; + normalMapEnabled: boolean; normalScale: number; // #ifdef HAS_NORMALMAP emissiveMapEnabled: boolean; @@ -56,7 +55,7 @@ type PBRMaterialBindings = { diffuseEnvSampler: Texture | null; // #ifdef USE_IBL (samplerCube) specularEnvSampler: Texture | null; // #ifdef USE_IBL (samplerCube) brdfLUT?: Texture | null; // #ifdef USE_IBL -} +}; export type PBRMaterialUniforms = { unlit: boolean; @@ -65,7 +64,7 @@ export type PBRMaterialUniforms = { baseColorMapEnabled: boolean; baseColorFactor: Readonly; - normalMapEnabled: boolean; + normalMapEnabled: boolean; normalScale: number; // #ifdef HAS_NORMALMAP emissiveMapEnabled: boolean; @@ -88,7 +87,7 @@ export type PBRMaterialUniforms = { // #ifdef PBR_DEBUG scaleDiffBaseMR: Readonly; scaleFGDSpec: Readonly; -} +}; /** * An implementation of PBR (Physically-Based Rendering). @@ -117,7 +116,7 @@ export const pbrMaterial: ShaderModule = baseColorMapEnabled: 'i32', baseColorFactor: 'vec4', - normalMapEnabled: 'i32', + normalMapEnabled: 'i32', normalScale: 'f32', // #ifdef HAS_NORMALMAP emissiveMapEnabled: 'i32', @@ -128,29 +127,29 @@ export const pbrMaterial: ShaderModule = occlusionMapEnabled: 'i32', occlusionStrength: 'f32', // #ifdef HAS_OCCLUSIONMAP - + alphaCutoffEnabled: 'i32', alphaCutoff: 'f32', // #ifdef ALPHA_CUTOFF - + // IBL IBLenabled: 'i32', scaleIBLAmbient: 'vec2', // #ifdef USE_IBL - + // debugging flags used for shader output of intermediate PBR variables // #ifdef PBR_DEBUG scaleDiffBaseMR: 'vec4', - scaleFGDSpec: 'vec4', + scaleFGDSpec: 'vec4' }, bindings: { baseColorSampler: {type: 'texture', location: 8}, // #ifdef HAS_BASECOLORMAP normalSampler: {type: 'texture', location: 9}, // #ifdef HAS_NORMALMAP emissiveSampler: {type: 'texture', location: 10}, // #ifdef HAS_EMISSIVEMAP metallicRoughnessSampler: {type: 'texture', location: 11}, // #ifdef HAS_METALROUGHNESSMAP - occlusionSampler: {type: 'texture', location: 12}, // #ifdef HAS_OCCLUSIONMAP + occlusionSampler: {type: 'texture', location: 12}, // #ifdef HAS_OCCLUSIONMAP // IBL Samplers diffuseEnvSampler: {type: 'texture', location: 13}, // #ifdef USE_IBL (samplerCube) - specularEnvSampler: {type: 'texture', location: 14 }, // #ifdef USE_IBL (samplerCube) - brdfLUT: {type: 'texture', location: 15}, // #ifdef USE_IBL + specularEnvSampler: {type: 'texture', location: 14}, // #ifdef USE_IBL (samplerCube) + brdfLUT: {type: 'texture', location: 15} // #ifdef USE_IBL }, dependencies: [lighting] }; diff --git a/modules/shadertools/src/modules/postprocessing/image-adjust-filters/denoise.ts b/modules/shadertools/src/modules/postprocessing/image-adjust-filters/denoise.ts index dfc21c0c5d..5c595c58c9 100644 --- a/modules/shadertools/src/modules/postprocessing/image-adjust-filters/denoise.ts +++ b/modules/shadertools/src/modules/postprocessing/image-adjust-filters/denoise.ts @@ -36,10 +36,10 @@ vec4 denoise_sampleColor(sampler2D source, vec2 texSize, vec2 texCoord) { * weighted by color intensity, similar to a bilateral filter. */ export type DenoiseProps = { - /** + /** * The exponent of the color intensity difference, should be greater * than zero. A value of zero just gives an 9x9 box blur and high values - * give the original image, but ideal values are usually around 10-20. + * give the original image, but ideal values are usually around 10-20. */ strength?: number; }; diff --git a/modules/shadertools/src/modules/postprocessing/image-adjust-filters/huesaturation.ts b/modules/shadertools/src/modules/postprocessing/image-adjust-filters/huesaturation.ts index 02801098ad..0ae6ceb9f0 100644 --- a/modules/shadertools/src/modules/postprocessing/image-adjust-filters/huesaturation.ts +++ b/modules/shadertools/src/modules/postprocessing/image-adjust-filters/huesaturation.ts @@ -44,9 +44,9 @@ vec4 hueSaturation_filterColor(vec4 color, vec2 texSize, vec2 texCoord) { export type HueSaturationProps = { /** -1 to 1 (-1 is 180 degree rotation in the negative direction, 0 is no change, * and 1 is 180 degree rotation in the positive direction) */ - hue?: number; - /** @param saturation -1 to 1 (-1 is solid gray, 0 is no change, and 1 is maximum contrast) */ - saturation?: number; + hue?: number; + /** @param saturation -1 to 1 (-1 is solid gray, 0 is no change, and 1 is maximum contrast) */ + saturation?: number; }; /** diff --git a/modules/shadertools/src/modules/postprocessing/image-blur-filters/zoomblur.ts b/modules/shadertools/src/modules/postprocessing/image-blur-filters/zoomblur.ts index 702917e663..46140f5436 100644 --- a/modules/shadertools/src/modules/postprocessing/image-blur-filters/zoomblur.ts +++ b/modules/shadertools/src/modules/postprocessing/image-blur-filters/zoomblur.ts @@ -44,9 +44,9 @@ vec4 zoomBlur_sampleColor(sampler2D source, vec2 texSize, vec2 texCoord) { */ export type ZoomBlurProps = { /** - The x, y coordinate of the blur origin. */ - center?: number[], + center?: number[]; /** - The strength of the blur. Values in the range 0 to 1 are usually sufficient, where 0 doesn't change the image and 1 creates a highly blurred image. */ - strength?: number + strength?: number; }; /** diff --git a/modules/shadertools/src/modules/postprocessing/image-fun-filters/hexagonalpixelate.ts b/modules/shadertools/src/modules/postprocessing/image-fun-filters/hexagonalpixelate.ts index 8fa217e0a4..07bdfce97a 100644 --- a/modules/shadertools/src/modules/postprocessing/image-fun-filters/hexagonalpixelate.ts +++ b/modules/shadertools/src/modules/postprocessing/image-fun-filters/hexagonalpixelate.ts @@ -51,7 +51,7 @@ vec4 hexagonalPixelate_sampleColor(sampler2D source, vec2 texSize, vec2 texCoord /** * Hexagonal Pixelate - * Renders the image using a pattern of hexagonal tiles. + * Renders the image using a pattern of hexagonal tiles. * Tile colors are nearest-neighbor sampled from the centers of the tiles. */ export type HexagonalPixelateProps = { diff --git a/modules/shadertools/src/modules/postprocessing/image-fun-filters/ink.ts b/modules/shadertools/src/modules/postprocessing/image-fun-filters/ink.ts index 0c0899fb74..d77fc3bd13 100644 --- a/modules/shadertools/src/modules/postprocessing/image-fun-filters/ink.ts +++ b/modules/shadertools/src/modules/postprocessing/image-fun-filters/ink.ts @@ -41,11 +41,11 @@ vec4 ink_sampleColor(sampler2D source, vec2 texSize, vec2 texCoord) { * copies of the image, each blurred using a blur of a different radius. */ export type InkProps = { - /** The multiplicative scale of the ink edges. - * Values in the range 0 to 1 are usually sufficient, where 0 doesn't change the image and 1 adds lots of black edges. + /** The multiplicative scale of the ink edges. + * Values in the range 0 to 1 are usually sufficient, where 0 doesn't change the image and 1 adds lots of black edges. * Negative strength values will create white ink edges instead of black ones. */ - strength?: number; + strength?: number; }; /** diff --git a/modules/shadertools/src/modules/postprocessing/image-fun-filters/magnify.ts b/modules/shadertools/src/modules/postprocessing/image-fun-filters/magnify.ts index 1dab2d860f..c621235948 100644 --- a/modules/shadertools/src/modules/postprocessing/image-fun-filters/magnify.ts +++ b/modules/shadertools/src/modules/postprocessing/image-fun-filters/magnify.ts @@ -27,8 +27,8 @@ vec4 magnify_sampleColor(sampler2D source, vec2 texSize, vec2 texCoord) { } `; -/** - * Magnify - display a circle with magnify effect applied to surrounding the pixels given position +/** + * Magnify - display a circle with magnify effect applied to surrounding the pixels given position */ export type MagnifyProps = { /** x, y position in screen coords, both x and y is normalized and in range `[0, 1]`. `[0, 0]` is the up left corner, `[1, 1]` is the bottom right corner. Default value is `[0, 0]`. */ @@ -53,7 +53,7 @@ export const magnify: ShaderPass = { radiusPixels: 'f32', zoom: 'f32', borderWidthPixels: 'f32', - borderColor: 'vec4', + borderColor: 'vec4' }, uniformPropTypes: { // range 0 to 1 diff --git a/modules/shadertools/src/types.ts b/modules/shadertools/src/types.ts index 3274b979d9..bb6115a7c0 100644 --- a/modules/shadertools/src/types.ts +++ b/modules/shadertools/src/types.ts @@ -6,35 +6,30 @@ export {TypedArray, NumberArray, NumericArray} from '@math.gl/types'; // export type BigIntOrNumberArray = NumberArray | BigIntTypedArray; -// UNIFORM TYPES +// UNIFORM TYPES // These are "duplicated" from core module to avoid cross-dependencies -export type UniformDataType = - 'uint32' | - 'sint32' | - 'float32' - ; +export type UniformDataType = 'uint32' | 'sint32' | 'float32'; -export type UniformFormat = - 'f32' | - 'i32' | - 'u32' | - 'vec2' | - 'vec3' | - 'vec4' | - 'vec2' | - 'vec3' | - 'vec4' | - 'vec2' | - 'vec3' | - 'vec4' | - 'mat2x2' | - 'mat2x3' | - 'mat2x4' | - 'mat3x2' | - 'mat3x3' | - 'mat3x4' | - 'mat4x2' | - 'mat4x3' | - 'mat4x4' - ; +export type UniformFormat = + | 'f32' + | 'i32' + | 'u32' + | 'vec2' + | 'vec3' + | 'vec4' + | 'vec2' + | 'vec3' + | 'vec4' + | 'vec2' + | 'vec3' + | 'vec4' + | 'mat2x2' + | 'mat2x3' + | 'mat2x4' + | 'mat3x2' + | 'mat3x3' + | 'mat3x4' + | 'mat4x2' + | 'mat4x3' + | 'mat4x4'; diff --git a/modules/shadertools/test/lib/generator/generate-shader.spec.ts b/modules/shadertools/test/lib/generator/generate-shader.spec.ts index 2edab2506f..3f9380d029 100644 --- a/modules/shadertools/test/lib/generator/generate-shader.spec.ts +++ b/modules/shadertools/test/lib/generator/generate-shader.spec.ts @@ -9,14 +9,14 @@ const module: ShaderModule = { uniformTypes: { uProjectMatrix: 'mat4x4', uViewMatrix: 'mat4x4', - uClipped: 'f32', - }, + uClipped: 'f32' + } }; -const TEST_CASES: {module: ShaderModule; options: ShaderGenerationOptions, result: string}[] = [ +const TEST_CASES: {module: ShaderModule; options: ShaderGenerationOptions; result: string}[] = [ { - module, - options: {shaderLanguage: 'glsl', uniforms: 'uniforms'}, + module, + options: {shaderLanguage: 'glsl', uniforms: 'uniforms'}, result: `\ uniform mat4 test_uProjectMatrix; uniform mat4 test_uViewMatrix; @@ -24,8 +24,8 @@ uniform float test_uClipped; ` }, { - module, - options: {shaderLanguage: 'glsl', uniforms: 'unscoped-interface-blocks'}, + module, + options: {shaderLanguage: 'glsl', uniforms: 'unscoped-interface-blocks'}, result: `\ uniform Test { mat4 test_uProjectMatrix; @@ -35,8 +35,8 @@ uniform Test { ` }, { - module, - options: {shaderLanguage: 'glsl', uniforms: 'scoped-interface-blocks'}, + module, + options: {shaderLanguage: 'glsl', uniforms: 'scoped-interface-blocks'}, result: `\ uniform Test { mat4 uProjectMatrix; @@ -44,10 +44,10 @@ uniform Test { float uClipped; } test; ` - }, + } ]; -test('shadertools#generateGLSLForModule', (t) => { +test('shadertools#generateGLSLForModule', t => { for (const tc of TEST_CASES) { const glsl = generateShaderForModule(tc.module, tc.options); t.equal(glsl, tc.result, JSON.stringify(tc.options)); diff --git a/modules/shadertools/test/lib/glsl-utils/get-shader-info.spec.ts b/modules/shadertools/test/lib/glsl-utils/get-shader-info.spec.ts index 5723ae169d..d675e58e03 100644 --- a/modules/shadertools/test/lib/glsl-utils/get-shader-info.spec.ts +++ b/modules/shadertools/test/lib/glsl-utils/get-shader-info.spec.ts @@ -92,7 +92,7 @@ const versionTests = { [SHADER7]: 300 }; -test('WebGL#getShaderInfo()', (t) => { +test('WebGL#getShaderInfo()', t => { t.equal( getShaderInfo(SHADER_1).name, 'name-of-shader', @@ -113,29 +113,13 @@ test('WebGL#getShaderInfo()', (t) => { 'getShaderInfo().name extracted correct name' ); - t.equal( - getShaderInfo(SHADER_5).name, - 'unnamed', - 'getShaderInfo().name extracted default name' - ); + t.equal(getShaderInfo(SHADER_5).name, 'unnamed', 'getShaderInfo().name extracted default name'); - t.equal( - getShaderInfo(SHADER_6).name, - 'unnamed', - 'getShaderInfo().name extracted default name' - ); + t.equal(getShaderInfo(SHADER_6).name, 'unnamed', 'getShaderInfo().name extracted default name'); - t.equal( - getShaderInfo(SHADER_7).name, - 'unnamed', - 'getShaderInfo().name extracted default name' - ); + t.equal(getShaderInfo(SHADER_7).name, 'unnamed', 'getShaderInfo().name extracted default name'); - t.equal( - getShaderInfo(SHADER_8).name, - 'unnamed', - 'getShaderInfo().name extracted default name' - ); + t.equal(getShaderInfo(SHADER_8).name, 'unnamed', 'getShaderInfo().name extracted default name'); for (const string in versionTests) { t.equal(getShaderInfo(string).version, versionTests[string], 'Version should match'); diff --git a/modules/shadertools/test/lib/glsl-utils/shader-utils.spec.ts b/modules/shadertools/test/lib/glsl-utils/shader-utils.spec.ts index dde5ae8f79..0b2a060d11 100644 --- a/modules/shadertools/test/lib/glsl-utils/shader-utils.spec.ts +++ b/modules/shadertools/test/lib/glsl-utils/shader-utils.spec.ts @@ -10,7 +10,7 @@ import { type channelCount = 1 | 2 | 3 | 4; -test('shader-utils#getQualifierDetails', (t) => { +test('shader-utils#getQualifierDetails', t => { const QUALIFIER_TEST_CASES = [ { line: 'uniform vec2 size;', @@ -42,7 +42,7 @@ test('shader-utils#getQualifierDetails', (t) => { } ]; - QUALIFIER_TEST_CASES.forEach((testCase) => { + QUALIFIER_TEST_CASES.forEach(testCase => { const {line, qualifiers, expected} = testCase; const result = getQualifierDetails(line, qualifiers); t.deepEqual( @@ -54,7 +54,7 @@ test('shader-utils#getQualifierDetails', (t) => { t.end(); }); -test('shader-utils#getPassthroughFS', (t) => { +test('shader-utils#getPassthroughFS', t => { const PASSTHROUGH_TEST_CASES = [ { input: 'myInput', @@ -70,19 +70,15 @@ void main() { } ]; - PASSTHROUGH_TEST_CASES.forEach((testCase) => { + PASSTHROUGH_TEST_CASES.forEach(testCase => { const {input, inputChannels, output, expected} = testCase; const result = getPassthroughFS({input, inputChannels, output}); - t.equal( - result, - expected, - `Passthrough shader should match when channels=${inputChannels}` - ); + t.equal(result, expected, `Passthrough shader should match when channels=${inputChannels}`); }); t.end(); }); -test('shader-utils#typeToChannelSuffix', (t) => { +test('shader-utils#typeToChannelSuffix', t => { t.equal(typeToChannelSuffix('float'), 'x', 'typeToChannelSuffix should return x for float'); t.equal(typeToChannelSuffix('vec2'), 'xy', 'typeToChannelSuffix should return xy for vec2'); t.equal(typeToChannelSuffix('vec3'), 'xyz', 'typeToChannelSuffix should return xyz for vec3'); @@ -90,7 +86,7 @@ test('shader-utils#typeToChannelSuffix', (t) => { t.end(); }); -test('shader-utils#typeToChannelCount', (t) => { +test('shader-utils#typeToChannelCount', t => { t.equal(typeToChannelCount('float'), 1, 'typeToChannelCount should return 1 for float'); t.equal(typeToChannelCount('vec2'), 2, 'typeToChannelCount should return 2 for vec2'); t.equal(typeToChannelCount('vec3'), 3, 'typeToChannelCount should return 3 for vec3'); @@ -98,7 +94,7 @@ test('shader-utils#typeToChannelCount', (t) => { t.end(); }); -test('shader-utils#convertToVec4', (t) => { +test('shader-utils#convertToVec4', t => { t.equal( convertToVec4('one', 1), 'vec4(one, 0.0, 0.0, 1.0)', diff --git a/modules/shadertools/test/lib/shader-assembler.spec.ts b/modules/shadertools/test/lib/shader-assembler.spec.ts index c4c19d0f9d..ac12fb2c4c 100644 --- a/modules/shadertools/test/lib/shader-assembler.spec.ts +++ b/modules/shadertools/test/lib/shader-assembler.spec.ts @@ -106,7 +106,8 @@ test('ShaderAssembler#hooks', t => { 'injection code not included in fragment shader without module' ); - const modulesProgram = shaderAssembler.assembleShaders({platformInfo, + const modulesProgram = shaderAssembler.assembleShaders({ + platformInfo, vs, fs, modules: [pickingInjection] @@ -137,7 +138,8 @@ test('ShaderAssembler#hooks', t => { 'hook footer injected after injection code' ); - const injectedShaders = shaderAssembler.assembleShaders({platformInfo, + const injectedShaders = shaderAssembler.assembleShaders({ + platformInfo, vs, fs, inject: { @@ -151,7 +153,8 @@ test('ShaderAssembler#hooks', t => { t.ok(injectVs.indexOf('color *= 0.1') > -1, 'argument injection code included in shader hook'); t.ok(injectFs.indexOf('color += 0.1') > -1, 'argument injection code included in shader hook'); - const injectDefineProgram1 = shaderAssembler.assembleShaders({platformInfo, + const injectDefineProgram1 = shaderAssembler.assembleShaders({ + platformInfo, vs, fs, inject: { @@ -159,7 +162,8 @@ test('ShaderAssembler#hooks', t => { } }); - const injectDefineProgram2 = shaderAssembler.assembleShaders({platformInfo, + const injectDefineProgram2 = shaderAssembler.assembleShaders({ + platformInfo, vs, fs, defines: { @@ -177,7 +181,8 @@ test('ShaderAssembler#defaultModules', t => { const program = shaderAssembler.assembleShaders({platformInfo, vs, fs}); - const preDefaultModuleProgram = shaderAssembler.assembleShaders({platformInfo, + const preDefaultModuleProgram = shaderAssembler.assembleShaders({ + platformInfo, vs, fs, modules: [dirlight] @@ -188,7 +193,8 @@ test('ShaderAssembler#defaultModules', t => { shaderAssembler.addDefaultModule(dirlight); const defaultModuleProgram = shaderAssembler.assembleShaders({platformInfo, vs, fs}); - const moduleProgram = shaderAssembler.assembleShaders({platformInfo, + const moduleProgram = shaderAssembler.assembleShaders({ + platformInfo, vs, fs, modules: [dirlight] diff --git a/modules/shadertools/test/lib/shader-assembly/assemble-shaders.spec.ts b/modules/shadertools/test/lib/shader-assembly/assemble-shaders.spec.ts index ac0efe4e45..0589ea64da 100644 --- a/modules/shadertools/test/lib/shader-assembly/assemble-shaders.spec.ts +++ b/modules/shadertools/test/lib/shader-assembly/assemble-shaders.spec.ts @@ -259,12 +259,12 @@ void main(void) { } `; -test('assembleShaders#import', (t) => { +test('assembleShaders#import', t => { t.ok(assembleShaders !== undefined, 'assembleShaders import successful'); t.end(); }); -test('assembleShaders#version_directive', (t) => { +test('assembleShaders#version_directive', t => { const assembleResult = assembleShaders({ platformInfo: getInfo(webglDevice), vs: VS_GLSL_300, @@ -285,7 +285,7 @@ test('assembleShaders#version_directive', (t) => { t.end(); }); -test('assembleShaders#getUniforms', (t) => { +test('assembleShaders#getUniforms', t => { // inject spy into the picking module's getUniforms // const module = getShaderModule(picking); // const getUniformsSpy = makeSpy(module, 'getUniforms'); @@ -327,7 +327,7 @@ test('assembleShaders#getUniforms', (t) => { t.end(); }); -test('assembleShaders#defines', (t) => { +test('assembleShaders#defines', t => { const assembleResult = assembleShaders({ platformInfo: getInfo(webglDevice), vs: VS_GLSL_300, @@ -341,7 +341,7 @@ test('assembleShaders#defines', (t) => { t.end(); }); -test('assembleShaders#shaderhooks', (t) => { +test('assembleShaders#shaderhooks', t => { const hookFunctions = [ 'vs:LUMAGL_pickColor(inout vec4 color)', { @@ -502,7 +502,7 @@ test('assembleShaders#shaderhooks', (t) => { t.end(); }); -test('assembleShaders#injection order', (t) => { +test('assembleShaders#injection order', t => { let assembleResult = assembleShaders({ platformInfo: getInfo(webglDevice), vs: VS_GLSL_300_MODULES, @@ -541,7 +541,7 @@ test('assembleShaders#injection order', (t) => { }); // TODO - restore if we ever support transpilation of uniform blocks -test.skip('assembleShaders#transpilation', (t) => { +test.skip('assembleShaders#transpilation', t => { let assembleResult = assembleShaders({ platformInfo: getInfo(webglDevice), vs: VS_GLSL_300, @@ -550,12 +550,15 @@ test.skip('assembleShaders#transpilation', (t) => { }); t.ok(assembleResult.vs.indexOf('#version 300 es') === -1, 'es 3.0 version directive removed'); - t.ok(!(/\bin vec4\b/.exec(assembleResult.vs)), '"in" keyword removed'); + t.ok(!/\bin vec4\b/.exec(assembleResult.vs), '"in" keyword removed'); t.ok(assembleResult.fs.indexOf('#version 300 es') === -1, 'es 3.0 version directive removed'); - t.ok(!(/\bout vec4\b/.exec(assembleResult.fs)), '"out" keyword removed'); + t.ok(!/\bout vec4\b/.exec(assembleResult.fs), '"out" keyword removed'); - t.ok(compileAndLinkShaders(t, webglDevice, assembleResult), 'assemble GLSL300 + picking and transpile to GLSL100'); + t.ok( + compileAndLinkShaders(t, webglDevice, assembleResult), + 'assemble GLSL300 + picking and transpile to GLSL100' + ); assembleResult = assembleShaders({ platformInfo: getInfo(webglDevice), @@ -564,7 +567,10 @@ test.skip('assembleShaders#transpilation', (t) => { modules: [picking] }); - t.ok(compileAndLinkShaders(t, webglDevice, assembleResult), 'assemble GLSL300 + picking and transpile to GLSL100'); + t.ok( + compileAndLinkShaders(t, webglDevice, assembleResult), + 'assemble GLSL300 + picking and transpile to GLSL100' + ); const extension = webglDevice.gl.getExtension('OES_standard_derivatives'); // TODO - this doesn't work in headless gl @@ -580,7 +586,6 @@ test.skip('assembleShaders#transpilation', (t) => { compileAndLinkShaders(t, webglDevice, assembleResult), 'Deck shaders transpile 300 to 100 valid program' ); - } assembleResult = assembleShaders({ @@ -613,7 +618,7 @@ function compileAndLinkShaders(t, device: WebGLDevice, assembleResult) { return false; } - const fShader = gl.createShader(gl.FRAGMENT_SHADER) ; + const fShader = gl.createShader(gl.FRAGMENT_SHADER); gl.shaderSource(fShader, assembleResult.fs); gl.compileShader(fShader); compileStatus = gl.getShaderParameter(fShader, gl.COMPILE_STATUS); @@ -623,7 +628,7 @@ function compileAndLinkShaders(t, device: WebGLDevice, assembleResult) { return false; } - const program = gl.createProgram() ; + const program = gl.createProgram(); gl.attachShader(program, vShader); gl.attachShader(program, fShader); gl.linkProgram(program); diff --git a/modules/shadertools/test/lib/shader-module/shader-module.spec.ts b/modules/shadertools/test/lib/shader-module/shader-module.spec.ts index 224134e451..95959887c6 100644 --- a/modules/shadertools/test/lib/shader-module/shader-module.spec.ts +++ b/modules/shadertools/test/lib/shader-module/shader-module.spec.ts @@ -4,7 +4,7 @@ import test from 'tape-promise/tape'; import {normalizeShaderModule, ShaderModuleInstance} from '@luma.gl/shadertools'; // import {} from '@luma.gl/shadertools/lib/shader-module/shader-module-instance'; -test('ShaderModuleInstance', (t) => { +test('ShaderModuleInstance', t => { let shaderModule = new ShaderModuleInstance({name: 'empty-shader-module', uniformTypes: {}}); t.ok(shaderModule.getModuleSource('vertex'), 'returns vertex shader'); @@ -31,7 +31,7 @@ varying float vClipped; t.end(); }); -test('ShaderModuleInstance#checkDeprecations', (t) => { +test('ShaderModuleInstance#checkDeprecations', t => { const shaderModule = new ShaderModuleInstance({ name: 'test-shader-module', uniformTypes: {}, @@ -75,7 +75,7 @@ void main() { t.end(); }); -test('normalizeShaderModule', (t) => { +test('normalizeShaderModule', t => { const moduleDef = { name: 'test-shader-module', uniformPropTypes: { @@ -86,7 +86,7 @@ test('normalizeShaderModule', (t) => { range: {value: new Float32Array([0, 1]), private: true} } }; - + // @ts-expect-error const module = normalizeShaderModule(moduleDef); diff --git a/modules/shadertools/test/lib/shader-transpiler/transpile-shader.spec.ts b/modules/shadertools/test/lib/shader-transpiler/transpile-shader.spec.ts index b9d6301e3a..acfbee51ff 100644 --- a/modules/shadertools/test/lib/shader-transpiler/transpile-shader.spec.ts +++ b/modules/shadertools/test/lib/shader-transpiler/transpile-shader.spec.ts @@ -17,7 +17,7 @@ function compareStrings(t: Test, string1: string, string2: string, message?: str if (lines1[i] !== lines2[i]) { t.comment(`line ${i + 1}: '${lines1[i]}' --> '${lines2[i]}'`); return; - } + } } t.equal(string1, string2, message); diff --git a/modules/shadertools/test/modules-webgl1/fp64/fp64-arithmetic-transform.spec.ts b/modules/shadertools/test/modules-webgl1/fp64/fp64-arithmetic-transform.spec.ts index 09d4c043a1..34c4676f05 100644 --- a/modules/shadertools/test/modules-webgl1/fp64/fp64-arithmetic-transform.spec.ts +++ b/modules/shadertools/test/modules-webgl1/fp64/fp64-arithmetic-transform.spec.ts @@ -19,11 +19,19 @@ const commonTestCases = [ // mul_fp64: Large numbers once multipled, can't be represented by 32 bit precision and Math.fround() returns NAN // sqrt_fp64: Fail on INTEL with margin 3.906051071870294e-12 - {a: 2.4e3, b: 5.9e31, ignoreFor: {all: ['mul_fp64'], intel: ['sqrt_fp64'], apple: ['sum_fp64', 'sub_fp64']}}, + { + a: 2.4e3, + b: 5.9e31, + ignoreFor: {all: ['mul_fp64'], intel: ['sqrt_fp64'], apple: ['sum_fp64', 'sub_fp64']} + }, // div_fp64 fails on INTEL with margin 1.7318642528355118e-12 // sqrt_fp64 fails on INTEL with margin 1.5518878351528786e-12 - {a: 1.4e9, b: 6.3e5, ignoreFor: {intel: ['div_fp64', 'sqrt_fp64'], apple: ['mul_fp64', 'div_fp64']}}, + { + a: 1.4e9, + b: 6.3e5, + ignoreFor: {intel: ['div_fp64', 'sqrt_fp64'], apple: ['mul_fp64', 'div_fp64']} + }, // div fails on INTEL with margin 1.7886288892678105e-14 // sqrt fails on INTEL with margin 2.5362810256331708e-12 @@ -39,16 +47,28 @@ const commonTestCases = [ // mul_fp64 : fails since result can't be represented by 32 bit floats // div_fp64 : fails on INTEL with margin 1.9999999999999994e-15 // sqrt_fp64 : fails on INTEL with margin 1.832115697751484e-12 - {a: 4.1e30, b: 8.2e15, ignoreFor: {all: ['mul_fp64'], intel: ['div_fp64', 'sqrt_fp64'], apple: ['div_fp64']}}, + { + a: 4.1e30, + b: 8.2e15, + ignoreFor: {all: ['mul_fp64'], intel: ['div_fp64', 'sqrt_fp64'], apple: ['div_fp64']} + }, // Fails on INTEL, margin 3.752606081210107e-12 - {a: 6.2e3, b: 6.3e10, ignoreFor: {intel: ['sqrt_fp64'], apple: ['sum_fp64', 'mul_fp64', 'sub_fp64']}}, + { + a: 6.2e3, + b: 6.3e10, + ignoreFor: {intel: ['sqrt_fp64'], apple: ['sum_fp64', 'mul_fp64', 'sub_fp64']} + }, // Fails on INTEL, margin 3.872578286363912e-13 {a: 2.5e2, b: 5.1e-21, ignoreFor: {intel: ['sqrt_fp64'], apple: ['div_fp64']}}, // Fails on INTEL, margin 1.5332142001740705e-12 {a: 96, b: 1.7e4, ignoreFor: {intel: ['sqrt_fp64'], apple: ['div_fp64']}}, // // Fail on INTEL, margin 1.593162047558726e-12 - {a: 0.27, b: 2.3e16, ignoreFor: {intel: ['sqrt_fp64'], apple: ['sum_fp64', 'mul_fp64', 'sub_fp64']}}, + { + a: 0.27, + b: 2.3e16, + ignoreFor: {intel: ['sqrt_fp64'], apple: ['sum_fp64', 'mul_fp64', 'sub_fp64']} + }, // Fails on INTEL, margin 1.014956357028767e-12 {a: 18, b: 9.1e-9, ignoreFor: {intel: ['sqrt_fp64'], apple: ['div_fp64']}} ]; @@ -56,7 +76,7 @@ const commonTestCases = [ // Filter all tests cases based on current gpu and glsFunc function getTestCasesFor(glslFunc) { const debugInfo = webglDevice.info; - const testCases = commonTestCases.filter((testCase) => { + const testCases = commonTestCases.filter(testCase => { if (testCase.ignoreFor) { for (const gpu in testCase.ignoreFor) { if ( @@ -72,37 +92,51 @@ function getTestCasesFor(glslFunc) { return testCases; } -test('fp64#sum_fp64', async (t) => { +test('fp64#sum_fp64', async t => { const glslFunc = 'sum_fp64'; const testCases = getTestCasesFor(glslFunc); await runTests(webglDevice, {glslFunc, binary: true, op: (a, b) => a + b, testCases, t}); t.end(); }); -test('fp64#sub_fp64', async (t) => { +test('fp64#sub_fp64', async t => { const glslFunc = 'sub_fp64'; const testCases = getTestCasesFor(glslFunc); await runTests(webglDevice, {glslFunc, binary: true, op: (a, b) => a - b, testCases, t}); t.end(); }); -test('fp64#mul_fp64', async (t) => { +test('fp64#mul_fp64', async t => { const glslFunc = 'mul_fp64'; const testCases = getTestCasesFor(glslFunc); - await runTests(webglDevice, {glslFunc, binary: true, op: (a, b) => a * b, limit: 128, testCases, t}); + await runTests(webglDevice, { + glslFunc, + binary: true, + op: (a, b) => a * b, + limit: 128, + testCases, + t + }); t.end(); }); -test('fp64#div_fp64', async (t) => { +test('fp64#div_fp64', async t => { const glslFunc = 'div_fp64'; const testCases = getTestCasesFor(glslFunc); - await runTests(webglDevice, {glslFunc, binary: true, op: (a, b) => a / b, limit: 128, testCases, t}); + await runTests(webglDevice, { + glslFunc, + binary: true, + op: (a, b) => a / b, + limit: 128, + testCases, + t + }); t.end(); }); -test('fp64#sqrt_fp64', async (t) => { +test('fp64#sqrt_fp64', async t => { const glslFunc = 'sqrt_fp64'; const testCases = getTestCasesFor(glslFunc); - await runTests(webglDevice, {glslFunc, op: (a) => Math.sqrt(a), limit: 128, testCases, t}); + await runTests(webglDevice, {glslFunc, op: a => Math.sqrt(a), limit: 128, testCases, t}); t.end(); }); diff --git a/modules/shadertools/test/modules-webgl1/fp64/fp64-test-utils-transform.ts b/modules/shadertools/test/modules-webgl1/fp64/fp64-test-utils-transform.ts index 78ab458c6d..c6dd5fba0c 100644 --- a/modules/shadertools/test/modules-webgl1/fp64/fp64-test-utils-transform.ts +++ b/modules/shadertools/test/modules-webgl1/fp64/fp64-test-utils-transform.ts @@ -74,7 +74,10 @@ function setupFloatTest(device: Device, {glslFunc, binary = false, limit = 256, vs, modules: [fp64], attributes: {a: bufferA, b: bufferB}, - bufferLayout: [{name: 'a', format: 'float32x2'}, {name: 'b', format: 'float32x2'}], + bufferLayout: [ + {name: 'a', format: 'float32x2'}, + {name: 'b', format: 'float32x2'} + ], feedbackBuffers: {result: bufferResult}, varyings: ['result'], vertexCount: testCases.length @@ -82,7 +85,10 @@ function setupFloatTest(device: Device, {glslFunc, binary = false, limit = 256, return {a, b, expected, a_fp64, b_fp64, expected_fp64, transform}; } -export async function runTests(device: Device, {glslFunc, binary = false, op, limit = 256, testCases, t}) { +export async function runTests( + device: Device, + {glslFunc, binary = false, op, limit = 256, testCases, t} +) { if (!BufferTransform.isSupported(device)) { t.comment('Transform not supported, skipping tests'); t.end(); @@ -101,7 +107,11 @@ export async function runTests(device: Device, {glslFunc, binary = false, op, li transform.run(); const {buffer, byteOffset, byteLength} = await transform.readAsync('result'); - const gpuResult = new Float32Array(buffer, byteOffset, byteLength / Float32Array.BYTES_PER_ELEMENT); + const gpuResult = new Float32Array( + buffer, + byteOffset, + byteLength / Float32Array.BYTES_PER_ELEMENT + ); for (let idx = 0; idx < testCases.length; idx++) { const reference64 = expected_fp64[2 * idx] + expected_fp64[2 * idx + 1]; const result64 = gpuResult[2 * idx] + gpuResult[2 * idx + 1]; diff --git a/modules/shadertools/test/modules-webgl1/fp64/fp64-utils.spec.ts b/modules/shadertools/test/modules-webgl1/fp64/fp64-utils.spec.ts index fdd4b9dbcc..0655b7ac1a 100644 --- a/modules/shadertools/test/modules-webgl1/fp64/fp64-utils.spec.ts +++ b/modules/shadertools/test/modules-webgl1/fp64/fp64-utils.spec.ts @@ -5,7 +5,7 @@ import test from 'tape-promise/tape'; import {fp64} from '@luma.gl/shadertools'; import {_Pose as Pose} from '@math.gl/core'; -test('fp64#fp64LowPart', (t) => { +test('fp64#fp64LowPart', t => { const x = Math.PI; const x32 = new Float32Array([x])[0]; @@ -14,7 +14,7 @@ test('fp64#fp64LowPart', (t) => { t.end(); }); -test('fp64#fp64ify', (t) => { +test('fp64#fp64ify', t => { const x = Math.PI; const xHi = Math.fround(x); @@ -30,7 +30,7 @@ test('fp64#fp64ify', (t) => { t.end(); }); -test('fp64#fp64ifyMatrix4', (t) => { +test('fp64#fp64ifyMatrix4', t => { const matrix = new Pose({ yaw: -0.00032679972032649654, pitch: 0.0017499351314303354, diff --git a/modules/shadertools/test/modules-webgl1/lights/lights.spec.ts b/modules/shadertools/test/modules-webgl1/lights/lights.spec.ts index b7439d95cc..1c59f8aacd 100644 --- a/modules/shadertools/test/modules-webgl1/lights/lights.spec.ts +++ b/modules/shadertools/test/modules-webgl1/lights/lights.spec.ts @@ -5,7 +5,7 @@ import {lighting, ShaderModule} from '@luma.gl/shadertools'; checkType(lighting); -test('shadertools#lighting', (t) => { +test('shadertools#lighting', t => { let uniforms = lighting.getUniforms({}); t.ok(uniforms, 'Generated default uniforms'); diff --git a/modules/shadertools/test/modules/engine/picking.spec.ts b/modules/shadertools/test/modules/engine/picking.spec.ts index 2cf62d560a..34f62d1aa0 100644 --- a/modules/shadertools/test/modules/engine/picking.spec.ts +++ b/modules/shadertools/test/modules/engine/picking.spec.ts @@ -56,7 +56,7 @@ const TEST_CASES = [ } ]; -test('picking#getUniforms', (t) => { +test('picking#getUniforms', t => { t.deepEqual(picking.getUniforms({}), {}, 'Empty input'); t.deepEqual( @@ -69,7 +69,9 @@ test('picking#getUniforms', (t) => { isActive: true, isAttribute: false, highlightColor: [1, 0, 0, 1] - }, 'Undefined input (no change to highlighted object)'); + }, + 'Undefined input (no change to highlighted object)' + ); t.deepEqual( picking.getUniforms({ @@ -82,7 +84,9 @@ test('picking#getUniforms', (t) => { isAttribute: false, isHighlightActive: false, highlightColor: [1, 0, 0, 1] - }, 'Null input (clear highlighted object)'); + }, + 'Null input (clear highlighted object)' + ); t.deepEqual( picking.getUniforms({ @@ -93,7 +97,8 @@ test('picking#getUniforms', (t) => { isHighlightActive: true, highlightedObjectColor: [0, 0, 1], highlightColor: [0.4, 0, 0, 0.2] - }, 'Picked input (set highlighted object)' + }, + 'Picked input (set highlighted object)' ); t.deepEqual( @@ -106,15 +111,16 @@ test('picking#getUniforms', (t) => { useFloatColors: false, isHighlightActive: true, highlightedObjectColor: [0, 0, 1], - highlightColor: [0.4, 0, 0, 0.2], - }, 'Override useFloatColors' + highlightColor: [0.4, 0, 0, 0.2] + }, + 'Override useFloatColors' ); t.end(); }); // TODO(v9): Restore picking tests. -test.skip('picking#isVertexPicked(highlightedObjectColor invalid)', async (t) => { +test.skip('picking#isVertexPicked(highlightedObjectColor invalid)', async t => { if (!BufferTransform.isSupported(webglDevice)) { t.comment('Transform not available, skipping tests'); t.end(); @@ -150,26 +156,28 @@ test.skip('picking#isVertexPicked(highlightedObjectColor invalid)', async (t) => vertexCount }); - await Promise.all(TEST_CASES.map(async (testCase) => { - const uniforms = picking.getUniforms({ - highlightedObjectColor: testCase.highlightedObjectColor - }); + await Promise.all( + TEST_CASES.map(async testCase => { + const uniforms = picking.getUniforms({ + highlightedObjectColor: testCase.highlightedObjectColor + }); - transform.model.setUniforms(uniforms); - transform.run(); + transform.model.setUniforms(uniforms); + transform.run(); - const expectedData = testCase.isPicked; - const outData = await transform.readAsync('isPicked'); + const expectedData = testCase.isPicked; + const outData = await transform.readAsync('isPicked'); - t.deepEqual(outData, expectedData, 'Vertex should correctly get picked'); - })); + t.deepEqual(outData, expectedData, 'Vertex should correctly get picked'); + }) + ); t.end(); }); // TODO(v9): Restore picking tests. /* eslint-disable max-nested-callbacks */ -test.skip('picking#picking_setPickingColor', async (t) => { +test.skip('picking#picking_setPickingColor', async t => { if (!BufferTransform.isSupported(webglDevice)) { t.comment('Transform not available, skipping tests'); t.end(); @@ -202,20 +210,22 @@ test.skip('picking#picking_setPickingColor', async (t) => { vertexCount }); - await Promise.all(TEST_CASES.map(async (testCase) => { - const uniforms = picking.getUniforms({ - highlightedObjectColor: testCase.highlightedObjectColor, - // @ts-expect-error - pickingThreshold: testCase.pickingThreshold - }); + await Promise.all( + TEST_CASES.map(async testCase => { + const uniforms = picking.getUniforms({ + highlightedObjectColor: testCase.highlightedObjectColor, + // @ts-expect-error + pickingThreshold: testCase.pickingThreshold + }); - transform.model.setUniforms(uniforms); - transform.run(); + transform.model.setUniforms(uniforms); + transform.run(); - const outData = await transform.readAsync('rgbColorASelected'); + const outData = await transform.readAsync('rgbColorASelected'); - t.deepEqual(outData, testCase.isPicked, 'Vertex should correctly get picked'); - })); + t.deepEqual(outData, testCase.isPicked, 'Vertex should correctly get picked'); + }) + ); t.ok(true, 'picking_setPickingColor successful'); t.end(); diff --git a/modules/shadertools/test/modules/lighting/gouraud-material.spec.ts b/modules/shadertools/test/modules/lighting/gouraud-material.spec.ts index 3debfc9315..41143bee3e 100644 --- a/modules/shadertools/test/modules/lighting/gouraud-material.spec.ts +++ b/modules/shadertools/test/modules/lighting/gouraud-material.spec.ts @@ -5,13 +5,18 @@ import test from 'tape-promise/tape'; import type {UniformValue} from '@luma.gl/core'; import {gouraudMaterial} from '@luma.gl/shadertools'; -test('shadertools#gouraudMaterial', (t) => { +test('shadertools#gouraudMaterial', t => { // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion let uniforms: Record = gouraudMaterial.getUniforms?.({})!; t.deepEqual(uniforms, gouraudMaterial.defaultUniforms, 'Default phong lighting uniforms ok'); // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion - uniforms = gouraudMaterial.getUniforms?.({ambient: 0.0, diffuse: 0.0, shininess: 0.0, specularColor: [255, 0, 0]})!; + uniforms = gouraudMaterial.getUniforms?.({ + ambient: 0.0, + diffuse: 0.0, + shininess: 0.0, + specularColor: [255, 0, 0] + })!; // t.equal( // uniforms.enabled, // undefined, diff --git a/modules/shadertools/test/modules/lighting/pbr-material.spec.ts b/modules/shadertools/test/modules/lighting/pbr-material.spec.ts index 59f78e9ef0..465cfb5417 100644 --- a/modules/shadertools/test/modules/lighting/pbr-material.spec.ts +++ b/modules/shadertools/test/modules/lighting/pbr-material.spec.ts @@ -4,7 +4,7 @@ import test from 'tape-promise/tape'; import {pbrMaterial} from '@luma.gl/shadertools'; -test('shadertools#pbrMaterial', (t) => { +test('shadertools#pbrMaterial', t => { const uniforms = pbrMaterial.getUniforms({}); t.ok(uniforms, 'Default pbr lighting uniforms ok'); t.end(); diff --git a/modules/shadertools/test/modules/lighting/phong-material.spec.ts b/modules/shadertools/test/modules/lighting/phong-material.spec.ts index 864cd0c931..a6d99657ca 100644 --- a/modules/shadertools/test/modules/lighting/phong-material.spec.ts +++ b/modules/shadertools/test/modules/lighting/phong-material.spec.ts @@ -4,11 +4,16 @@ import test from 'tape-promise/tape'; import {phongMaterial} from '@luma.gl/shadertools'; -test('shadertools#phongMaterial', (t) => { +test('shadertools#phongMaterial', t => { let uniforms = phongMaterial.getUniforms({}); t.deepEqual(uniforms, phongMaterial.defaultUniforms, 'Default phong lighting uniforms ok'); - uniforms = phongMaterial.getUniforms({ambient: 0.0, diffuse: 0.0, shininess: 0.0, specularColor: [255, 0, 0]}); + uniforms = phongMaterial.getUniforms({ + ambient: 0.0, + diffuse: 0.0, + shininess: 0.0, + specularColor: [255, 0, 0] + }); // t.equal( // uniforms.enabled, // undefined, diff --git a/modules/shadertools/test/modules/modules.spec.ts b/modules/shadertools/test/modules/modules.spec.ts index 0e5a9f3172..abf3a4f452 100644 --- a/modules/shadertools/test/modules/modules.spec.ts +++ b/modules/shadertools/test/modules/modules.spec.ts @@ -13,7 +13,7 @@ for (const [name, value] of Object.entries(imports)) { } } -test('shadertools#module imports are defined', (t) => { +test('shadertools#module imports are defined', t => { for (const name in shaderModules) { verifyShaderModule(t, shaderModules[name]); } diff --git a/modules/shadertools/test/modules/postprocessing/image-adjust-filters/brightnesscontrast.spec.ts b/modules/shadertools/test/modules/postprocessing/image-adjust-filters/brightnesscontrast.spec.ts index aeb5ee9290..cf44f973c4 100644 --- a/modules/shadertools/test/modules/postprocessing/image-adjust-filters/brightnesscontrast.spec.ts +++ b/modules/shadertools/test/modules/postprocessing/image-adjust-filters/brightnesscontrast.spec.ts @@ -1,7 +1,7 @@ import {brightnessContrast, normalizeShaderModule} from '@luma.gl/shadertools'; import test from 'tape-promise/tape'; -test('brightnessContrast#build/uniform', (t) => { +test('brightnessContrast#build/uniform', t => { normalizeShaderModule(brightnessContrast); const uniforms = brightnessContrast.getUniforms(); diff --git a/modules/shadertools/test/modules/postprocessing/image-adjust-filters/denoise.spec.ts b/modules/shadertools/test/modules/postprocessing/image-adjust-filters/denoise.spec.ts index fff0b9527e..4237697e0f 100644 --- a/modules/shadertools/test/modules/postprocessing/image-adjust-filters/denoise.spec.ts +++ b/modules/shadertools/test/modules/postprocessing/image-adjust-filters/denoise.spec.ts @@ -1,7 +1,7 @@ import {denoise, normalizeShaderModule} from '@luma.gl/shadertools'; import test from 'tape-promise/tape'; -test('denoise#build/uniform', (t) => { +test('denoise#build/uniform', t => { normalizeShaderModule(denoise); const uniforms = denoise.getUniforms(); diff --git a/modules/shadertools/test/modules/postprocessing/image-adjust-filters/huesaturation.spec.ts b/modules/shadertools/test/modules/postprocessing/image-adjust-filters/huesaturation.spec.ts index 256ce58484..5ac44bb312 100644 --- a/modules/shadertools/test/modules/postprocessing/image-adjust-filters/huesaturation.spec.ts +++ b/modules/shadertools/test/modules/postprocessing/image-adjust-filters/huesaturation.spec.ts @@ -1,7 +1,7 @@ import {hueSaturation, normalizeShaderModule} from '@luma.gl/shadertools'; import test from 'tape-promise/tape'; -test('hueSaturation#build/uniform', (t) => { +test('hueSaturation#build/uniform', t => { normalizeShaderModule(hueSaturation); const uniforms = hueSaturation.getUniforms(); diff --git a/modules/shadertools/test/modules/postprocessing/image-adjust-filters/noise.spec.ts b/modules/shadertools/test/modules/postprocessing/image-adjust-filters/noise.spec.ts index 8db67624df..4e6da71414 100644 --- a/modules/shadertools/test/modules/postprocessing/image-adjust-filters/noise.spec.ts +++ b/modules/shadertools/test/modules/postprocessing/image-adjust-filters/noise.spec.ts @@ -1,7 +1,7 @@ import {noise, normalizeShaderModule} from '@luma.gl/shadertools'; import test from 'tape-promise/tape'; -test('noise#build/uniform', (t) => { +test('noise#build/uniform', t => { normalizeShaderModule(noise); const uniforms = noise.getUniforms(); diff --git a/modules/shadertools/test/modules/postprocessing/image-adjust-filters/sepia.spec.ts b/modules/shadertools/test/modules/postprocessing/image-adjust-filters/sepia.spec.ts index 1544a5f8ae..97af42bba7 100644 --- a/modules/shadertools/test/modules/postprocessing/image-adjust-filters/sepia.spec.ts +++ b/modules/shadertools/test/modules/postprocessing/image-adjust-filters/sepia.spec.ts @@ -1,7 +1,7 @@ import {sepia, normalizeShaderModule} from '@luma.gl/shadertools'; import test from 'tape-promise/tape'; -test('sepia#build/uniform', (t) => { +test('sepia#build/uniform', t => { normalizeShaderModule(sepia); const uniforms = sepia.getUniforms(); diff --git a/modules/shadertools/test/modules/postprocessing/image-adjust-filters/vibrance.spec.ts b/modules/shadertools/test/modules/postprocessing/image-adjust-filters/vibrance.spec.ts index 91e0d50f77..ad5952a7e8 100644 --- a/modules/shadertools/test/modules/postprocessing/image-adjust-filters/vibrance.spec.ts +++ b/modules/shadertools/test/modules/postprocessing/image-adjust-filters/vibrance.spec.ts @@ -1,7 +1,7 @@ import {vibrance, normalizeShaderModule} from '@luma.gl/shadertools'; import test from 'tape-promise/tape'; -test('vibrance#build/uniform', (t) => { +test('vibrance#build/uniform', t => { normalizeShaderModule(vibrance); const uniforms = vibrance.getUniforms(); diff --git a/modules/shadertools/test/modules/postprocessing/image-adjust-filters/vignette.spec.ts b/modules/shadertools/test/modules/postprocessing/image-adjust-filters/vignette.spec.ts index 88b81409cf..09e242cc62 100644 --- a/modules/shadertools/test/modules/postprocessing/image-adjust-filters/vignette.spec.ts +++ b/modules/shadertools/test/modules/postprocessing/image-adjust-filters/vignette.spec.ts @@ -1,7 +1,7 @@ import {vignette, normalizeShaderModule} from '@luma.gl/shadertools'; import test from 'tape-promise/tape'; -test('vignette#build/uniform', (t) => { +test('vignette#build/uniform', t => { normalizeShaderModule(vignette); const uniforms = vignette.getUniforms(); diff --git a/modules/shadertools/test/modules/postprocessing/image-blur-filters/tiltshift.spec.ts b/modules/shadertools/test/modules/postprocessing/image-blur-filters/tiltshift.spec.ts index 1445c87c72..654c166ef0 100644 --- a/modules/shadertools/test/modules/postprocessing/image-blur-filters/tiltshift.spec.ts +++ b/modules/shadertools/test/modules/postprocessing/image-blur-filters/tiltshift.spec.ts @@ -1,7 +1,7 @@ import {tiltShift, normalizeShaderModule} from '@luma.gl/shadertools'; import test from 'tape-promise/tape'; -test('tiltShift#build/uniform', (t) => { +test('tiltShift#build/uniform', t => { normalizeShaderModule(tiltShift); const uniforms = tiltShift.getUniforms(); diff --git a/modules/shadertools/test/modules/postprocessing/image-blur-filters/triangleblur.spec.ts b/modules/shadertools/test/modules/postprocessing/image-blur-filters/triangleblur.spec.ts index f4c17567c1..bf167a69a5 100644 --- a/modules/shadertools/test/modules/postprocessing/image-blur-filters/triangleblur.spec.ts +++ b/modules/shadertools/test/modules/postprocessing/image-blur-filters/triangleblur.spec.ts @@ -1,7 +1,7 @@ import {triangleBlur, normalizeShaderModule} from '@luma.gl/shadertools'; import test from 'tape-promise/tape'; -test('triangleBlur#build/uniform', (t) => { +test('triangleBlur#build/uniform', t => { normalizeShaderModule(triangleBlur); const uniforms = triangleBlur.getUniforms(); diff --git a/modules/shadertools/test/modules/postprocessing/image-blur-filters/zoomblur.spec.ts b/modules/shadertools/test/modules/postprocessing/image-blur-filters/zoomblur.spec.ts index 3ee4731df0..b17d313caa 100644 --- a/modules/shadertools/test/modules/postprocessing/image-blur-filters/zoomblur.spec.ts +++ b/modules/shadertools/test/modules/postprocessing/image-blur-filters/zoomblur.spec.ts @@ -1,7 +1,7 @@ import {zoomBlur, normalizeShaderModule} from '@luma.gl/shadertools'; import test from 'tape-promise/tape'; -test('zoomBlur#build/uniform', (t) => { +test('zoomBlur#build/uniform', t => { normalizeShaderModule(zoomBlur); const uniforms = zoomBlur.getUniforms(); diff --git a/modules/shadertools/test/modules/postprocessing/image-fun-filters/colorhalftone.spec.ts b/modules/shadertools/test/modules/postprocessing/image-fun-filters/colorhalftone.spec.ts index ca4fd1ca90..0c63df5c84 100644 --- a/modules/shadertools/test/modules/postprocessing/image-fun-filters/colorhalftone.spec.ts +++ b/modules/shadertools/test/modules/postprocessing/image-fun-filters/colorhalftone.spec.ts @@ -1,7 +1,7 @@ import {colorHalftone, normalizeShaderModule} from '@luma.gl/shadertools'; import test from 'tape-promise/tape'; -test('colorHalftone#build/uniform', (t) => { +test('colorHalftone#build/uniform', t => { normalizeShaderModule(colorHalftone); const uniforms = colorHalftone.getUniforms(); diff --git a/modules/shadertools/test/modules/postprocessing/image-fun-filters/dotscreen.spec.ts b/modules/shadertools/test/modules/postprocessing/image-fun-filters/dotscreen.spec.ts index 876910af99..5f55254255 100644 --- a/modules/shadertools/test/modules/postprocessing/image-fun-filters/dotscreen.spec.ts +++ b/modules/shadertools/test/modules/postprocessing/image-fun-filters/dotscreen.spec.ts @@ -1,7 +1,7 @@ import {dotScreen, normalizeShaderModule} from '@luma.gl/shadertools'; import test from 'tape-promise/tape'; -test('dotScreen#build/uniform', (t) => { +test('dotScreen#build/uniform', t => { normalizeShaderModule(dotScreen); const uniforms = dotScreen.getUniforms(); diff --git a/modules/shadertools/test/modules/postprocessing/image-fun-filters/edgework.spec.ts b/modules/shadertools/test/modules/postprocessing/image-fun-filters/edgework.spec.ts index 62efeadd6b..974153c12d 100644 --- a/modules/shadertools/test/modules/postprocessing/image-fun-filters/edgework.spec.ts +++ b/modules/shadertools/test/modules/postprocessing/image-fun-filters/edgework.spec.ts @@ -1,7 +1,7 @@ import {edgeWork, normalizeShaderModule} from '@luma.gl/shadertools'; import test from 'tape-promise/tape'; -test('edgeWork#build/uniform', (t) => { +test('edgeWork#build/uniform', t => { normalizeShaderModule(edgeWork); const uniforms = edgeWork.getUniforms(); diff --git a/modules/shadertools/test/modules/postprocessing/image-fun-filters/hexagonalpixelate.spec.ts b/modules/shadertools/test/modules/postprocessing/image-fun-filters/hexagonalpixelate.spec.ts index 261a4fccbb..c6870e1b53 100644 --- a/modules/shadertools/test/modules/postprocessing/image-fun-filters/hexagonalpixelate.spec.ts +++ b/modules/shadertools/test/modules/postprocessing/image-fun-filters/hexagonalpixelate.spec.ts @@ -1,7 +1,7 @@ import {normalizeShaderModule, hexagonalPixelate} from '@luma.gl/shadertools'; import test from 'tape-promise/tape'; -test('hexagonalPixelate#build/uniform', (t) => { +test('hexagonalPixelate#build/uniform', t => { normalizeShaderModule(hexagonalPixelate); const uniforms = hexagonalPixelate.getUniforms(); diff --git a/modules/shadertools/test/modules/postprocessing/image-fun-filters/ink.spec.ts b/modules/shadertools/test/modules/postprocessing/image-fun-filters/ink.spec.ts index d05c341818..91f5016a2e 100644 --- a/modules/shadertools/test/modules/postprocessing/image-fun-filters/ink.spec.ts +++ b/modules/shadertools/test/modules/postprocessing/image-fun-filters/ink.spec.ts @@ -1,7 +1,7 @@ import {ink, normalizeShaderModule} from '@luma.gl/shadertools'; import test from 'tape-promise/tape'; -test('ink#build/uniform', (t) => { +test('ink#build/uniform', t => { normalizeShaderModule(ink); const uniforms = ink.getUniforms(); diff --git a/modules/shadertools/test/modules/postprocessing/image-warp-filters/bulgepinch.spec.ts b/modules/shadertools/test/modules/postprocessing/image-warp-filters/bulgepinch.spec.ts index bdb94dc1c1..7ed723213a 100644 --- a/modules/shadertools/test/modules/postprocessing/image-warp-filters/bulgepinch.spec.ts +++ b/modules/shadertools/test/modules/postprocessing/image-warp-filters/bulgepinch.spec.ts @@ -1,7 +1,7 @@ import {bulgePinch, normalizeShaderModule} from '@luma.gl/shadertools'; import test from 'tape-promise/tape'; -test('bulgePinch#build/uniform', (t) => { +test('bulgePinch#build/uniform', t => { normalizeShaderModule(bulgePinch); const uniforms = bulgePinch.getUniforms(); diff --git a/modules/shadertools/test/modules/postprocessing/image-warp-filters/swirl.spec.ts b/modules/shadertools/test/modules/postprocessing/image-warp-filters/swirl.spec.ts index 73834538a6..7224dc6c07 100644 --- a/modules/shadertools/test/modules/postprocessing/image-warp-filters/swirl.spec.ts +++ b/modules/shadertools/test/modules/postprocessing/image-warp-filters/swirl.spec.ts @@ -1,7 +1,7 @@ import {swirl, normalizeShaderModule} from '@luma.gl/shadertools'; import test from 'tape-promise/tape'; -test('swirl#build/uniform', (t) => { +test('swirl#build/uniform', t => { normalizeShaderModule(swirl); const uniforms = swirl.getUniforms(); diff --git a/modules/shadertools/test/modules/postprocessing/image-warp-filters/warp.spec.ts b/modules/shadertools/test/modules/postprocessing/image-warp-filters/warp.spec.ts index 868b3f4140..23ed48dec5 100644 --- a/modules/shadertools/test/modules/postprocessing/image-warp-filters/warp.spec.ts +++ b/modules/shadertools/test/modules/postprocessing/image-warp-filters/warp.spec.ts @@ -3,7 +3,7 @@ import {_warp as warp} from '@luma.gl/shadertools'; import {normalizeShaderModule} from '@luma.gl/shadertools'; import test from 'tape-promise/tape'; -test('warp#build', (t) => { +test('warp#build', t => { normalizeShaderModule(warp); t.ok(warp.fs, 'warp module fs is ok'); diff --git a/modules/shadertools/test/modules/utils/random.spec.ts b/modules/shadertools/test/modules/utils/random.spec.ts index 1a2ff62867..a30ac9e35d 100644 --- a/modules/shadertools/test/modules/utils/random.spec.ts +++ b/modules/shadertools/test/modules/utils/random.spec.ts @@ -3,7 +3,7 @@ import {random} from '@luma.gl/shadertools'; import {normalizeShaderModule} from '@luma.gl/shadertools'; import test from 'tape-promise/tape'; -test('random#build', (t) => { +test('random#build', t => { normalizeShaderModule(random); t.ok(random.fs, 'random module fs is ok'); diff --git a/modules/test-utils/src/create-test-device.ts b/modules/test-utils/src/create-test-device.ts index 7bd1146721..824d743137 100644 --- a/modules/test-utils/src/create-test-device.ts +++ b/modules/test-utils/src/create-test-device.ts @@ -32,7 +32,7 @@ export function createTestDevice(props: DeviceProps = {}): WebGLDevice | null { } /** A WebGL 2 Device intended for testing */ -export const webglDevice: WebGLDevice = createTestDevice({id: 'webgl2-test-device'}) ; +export const webglDevice: WebGLDevice = createTestDevice({id: 'webgl2-test-device'}); /** Only available after getTestDevices() has completed */ export let webgpuDevice: WebGPUDevice; @@ -47,11 +47,14 @@ export function getWebGLTestDevices(): WebGLDevice[] { } /** Includes WebGPU device if available */ -export async function getTestDevices() : Promise { +export async function getTestDevices(): Promise { if (!webgpuCreated) { webgpuCreated = true; try { - webgpuDevice = await luma.createDevice({id: 'webgpu-test-device', type: 'webgpu'}) as WebGPUDevice; + webgpuDevice = (await luma.createDevice({ + id: 'webgpu-test-device', + type: 'webgpu' + })) as WebGPUDevice; } catch { // ignore (assume WebGPU was not available) } diff --git a/modules/test-utils/src/engine/classic-animation-loop.ts b/modules/test-utils/src/engine/classic-animation-loop.ts index 1e879179d7..8bb5e10005 100644 --- a/modules/test-utils/src/engine/classic-animation-loop.ts +++ b/modules/test-utils/src/engine/classic-animation-loop.ts @@ -87,7 +87,7 @@ const DEFAULT_CLASSIC_ANIMATION_LOOP_PROPS: Required onInitialize: () => ({}), onRender: () => {}, onFinalize: () => {}, - onError: (error) => console.error(error), // eslint-disable-line no-console + onError: error => console.error(error), // eslint-disable-line no-console device: null, // debug: true, @@ -313,7 +313,7 @@ export class ClassicAnimationLoop { this.setNeedsRedraw('waitForRender'); if (!this._nextFramePromise) { - this._nextFramePromise = new Promise((resolve) => { + this._nextFramePromise = new Promise(resolve => { this._resolveNextFrame = resolve; }); } @@ -388,14 +388,14 @@ export class ClassicAnimationLoop { if (!this._pageLoadPromise) { this._pageLoadPromise = isPage ? new Promise((resolve, reject) => { - if (isPage && document.readyState === 'complete') { - resolve(document); - return; - } - window.addEventListener('load', () => { - resolve(document); - }); - }) + if (isPage && document.readyState === 'complete') { + resolve(document); + return; + } + window.addEventListener('load', () => { + resolve(document); + }); + }) : Promise.resolve({}); } return this._pageLoadPromise; @@ -582,7 +582,7 @@ export class ClassicAnimationLoop { } _createInfoDiv() { - const canvas = getHTMLCanvasElement(this.gl.canvas) + const canvas = getHTMLCanvasElement(this.gl.canvas); if (canvas && this.props.onAddHTML) { const wrapperDiv = document.createElement('div'); document.body.appendChild(wrapperDiv); diff --git a/modules/test-utils/src/snapshot-test-runner.ts b/modules/test-utils/src/snapshot-test-runner.ts index 3f42a5d348..ad46b1e842 100644 --- a/modules/test-utils/src/snapshot-test-runner.ts +++ b/modules/test-utils/src/snapshot-test-runner.ts @@ -6,8 +6,8 @@ export type SnapshotTestRunnerTestCase = TestRunnerTestCase & { /** URL to golden image */ goldenImage: string; /** Diff options */ - imageDiffOptions?: {[key: string]: any}; -} + imageDiffOptions?: {[key: string]: any}; +}; export type SnapshotTestRunnerProps = TestRunnerProps; diff --git a/modules/test-utils/src/test-runner.ts b/modules/test-utils/src/test-runner.ts index 33fdce7541..bc4d86e69c 100644 --- a/modules/test-utils/src/test-runner.ts +++ b/modules/test-utils/src/test-runner.ts @@ -48,8 +48,10 @@ const DEFAULT_TEST_PROPS: Required = { // test lifecycle callback onTestStart: (testCase: TestRunnerTestCase) => console.log(`# ${testCase.name}`), - onTestPass: (testCase: TestRunnerTestCase, result?: unknown) => console.log(`ok ${testCase.name} passed`), - onTestFail: (testCase: TestRunnerTestCase, error?: unknown) => console.log(`not ok ${testCase.name} failed`), + onTestPass: (testCase: TestRunnerTestCase, result?: unknown) => + console.log(`ok ${testCase.name} passed`), + onTestFail: (testCase: TestRunnerTestCase, error?: unknown) => + console.log(`not ok ${testCase.name} failed`), // milliseconds to wait for each test case before aborting timeout: 2000, @@ -99,9 +101,9 @@ export class TestRunner { } /** - * Returns a promise that resolves when all the test cases are done - */ - run(options: object = {}): Promise { + * Returns a promise that resolves when all the test cases are done + */ + run(options: object = {}): Promise { this.testOptions = {...this.testOptions, ...options}; return new Promise((resolve, reject) => { @@ -119,7 +121,7 @@ export class TestRunner { this.isRunning = true; this.isDiffing = false; this._currentTestCase = null; - }).catch (error => { + }).catch(error => { this._fail({error: error.message}); // reject(error); }); @@ -178,7 +180,7 @@ export class TestRunner { let isDone = false; const testCaseAnimationProps: AnimationProps = { - ...animationProps, + ...animationProps, ...this._testCaseData, // tick/time starts from 0 for each test case startTime: this._currentTestCaseStartTime, @@ -255,7 +257,7 @@ export class TestRunner { // aligned with the behavior of AnimationLoop.onInitialized // onInitialized could return a plain object or a promise - Promise.resolve(testCase.onInitialize(initProps)).then((userData) => { + Promise.resolve(testCase.onInitialize(initProps)).then(userData => { this._testCaseData = userData || {}; }); diff --git a/modules/test-utils/src/utils/check-type.ts b/modules/test-utils/src/utils/check-type.ts index dcff84c4dc..8b8f7ae307 100644 --- a/modules/test-utils/src/utils/check-type.ts +++ b/modules/test-utils/src/utils/check-type.ts @@ -1,4 +1,3 @@ - /** * Tests that an argument matches the type. * @note fails during typescript type check, not during runtime. diff --git a/modules/test-utils/src/utils/deep-copy.ts b/modules/test-utils/src/utils/deep-copy.ts index 4b947a05d2..8b32fa7024 100644 --- a/modules/test-utils/src/utils/deep-copy.ts +++ b/modules/test-utils/src/utils/deep-copy.ts @@ -1,7 +1,7 @@ /** Recursively copies objects */ export function deepCopy(object: Record) { if (Array.isArray(object)) { - return object.map((element) => deepCopy(element)); + return object.map(element => deepCopy(element)); } if (object !== null && typeof object === 'object') { diff --git a/modules/test-utils/src/utils/get-bounding-box.ts b/modules/test-utils/src/utils/get-bounding-box.ts index 2fbba83226..47b4b114eb 100644 --- a/modules/test-utils/src/utils/get-bounding-box.ts +++ b/modules/test-utils/src/utils/get-bounding-box.ts @@ -1,5 +1,10 @@ // Get the bounding box of a DOMElement relative to the page -export function getBoundingBoxInPage(domElement: HTMLElement): {x: number; y: number; width: number; height: number;} { +export function getBoundingBoxInPage(domElement: HTMLElement): { + x: number; + y: number; + width: number; + height: number; +} { const bbox = domElement.getBoundingClientRect(); return { x: window.scrollX + bbox.x, diff --git a/modules/test-utils/src/utils/resource-tracker.ts b/modules/test-utils/src/utils/resource-tracker.ts index cba36437ef..f73e454f3f 100644 --- a/modules/test-utils/src/utils/resource-tracker.ts +++ b/modules/test-utils/src/utils/resource-tracker.ts @@ -8,7 +8,10 @@ export function getResourceCounts() { }; } -export function getLeakedResources(startCounts: Record, endCounts: Record): number | null { +export function getLeakedResources( + startCounts: Record, + endCounts: Record +): number | null { let leakedResources = null; const info = 'leaking: '; for (const resourceName in endCounts) { diff --git a/modules/webgl/src/adapter/converters/device-parameters.ts b/modules/webgl/src/adapter/converters/device-parameters.ts index 09b5f6f3c3..f19dd83b82 100644 --- a/modules/webgl/src/adapter/converters/device-parameters.ts +++ b/modules/webgl/src/adapter/converters/device-parameters.ts @@ -144,7 +144,8 @@ export function setDeviceParameters(device: Device, parameters: Parameters) { } if (parameters.unclippedDepth) { - if (device.features.has('depth-clip-control')) { // EXT_depth_clamp + if (device.features.has('depth-clip-control')) { + // EXT_depth_clamp gl.enable(GL.DEPTH_CLAMP_EXT); } } diff --git a/modules/webgl/src/adapter/converters/sampler-parameters.ts b/modules/webgl/src/adapter/converters/sampler-parameters.ts index 81c0ab5ff3..41e88c3831 100644 --- a/modules/webgl/src/adapter/converters/sampler-parameters.ts +++ b/modules/webgl/src/adapter/converters/sampler-parameters.ts @@ -55,7 +55,9 @@ export function convertSamplerParametersToWebGL(props: SamplerProps): GLSamplerP // HELPERS /** Convert address more */ -function convertAddressMode(addressMode: 'clamp-to-edge' | 'repeat' | 'mirror-repeat'): GL.CLAMP_TO_EDGE | GL.REPEAT | GL.MIRRORED_REPEAT { +function convertAddressMode( + addressMode: 'clamp-to-edge' | 'repeat' | 'mirror-repeat' +): GL.CLAMP_TO_EDGE | GL.REPEAT | GL.MIRRORED_REPEAT { switch (addressMode) { case 'clamp-to-edge': return GL.CLAMP_TO_EDGE; @@ -82,7 +84,13 @@ function convertMaxFilterMode(maxFilter: 'nearest' | 'linear'): GL.NEAREST | GL. function convertMinFilterMode( minFilter: 'nearest' | 'linear', mipmapFilter?: 'nearest' | 'linear' -): GL.NEAREST | GL.LINEAR | GL.NEAREST_MIPMAP_NEAREST | GL.LINEAR_MIPMAP_NEAREST | GL.NEAREST_MIPMAP_LINEAR | GL.LINEAR_MIPMAP_LINEAR { +): + | GL.NEAREST + | GL.LINEAR + | GL.NEAREST_MIPMAP_NEAREST + | GL.LINEAR_MIPMAP_NEAREST + | GL.NEAREST_MIPMAP_LINEAR + | GL.LINEAR_MIPMAP_LINEAR { if (!mipmapFilter) { return convertMaxFilterMode(minFilter); } diff --git a/modules/webgl/src/adapter/converters/shader-formats.ts b/modules/webgl/src/adapter/converters/shader-formats.ts index 8a0898226e..67f362e88e 100644 --- a/modules/webgl/src/adapter/converters/shader-formats.ts +++ b/modules/webgl/src/adapter/converters/shader-formats.ts @@ -5,40 +5,64 @@ import {GL} from '@luma.gl/constants'; import {ShaderAttributeType, ShaderDataType} from '@luma.gl/core'; /** Get shader attribute type from GL constants */ -export function getShaderAttributeTypeFromGL(type: GL, components: 1 | 2 | 3 | 4): ShaderAttributeType { +export function getShaderAttributeTypeFromGL( + type: GL, + components: 1 | 2 | 3 | 4 +): ShaderAttributeType { const dataType = getShaderDataTypeFromGL(type); switch (components) { - case 1: return dataType; - case 2: return `vec2<${dataType}>`; - case 3: return `vec2<${dataType}>`; - case 4: return `vec2<${dataType}>`; - default: throw new Error(String(components)); + case 1: + return dataType; + case 2: + return `vec2<${dataType}>`; + case 3: + return `vec2<${dataType}>`; + case 4: + return `vec2<${dataType}>`; + default: + throw new Error(String(components)); } } /** Get shader data type from GL constants */ export function getShaderDataTypeFromGL(type: GL): ShaderDataType { switch (type) { - case GL.INT: return 'i32'; - case GL.UNSIGNED_INT: return 'u32'; - case GL.SHORT: return 'i32'; - case GL.UNSIGNED_SHORT: return 'u32'; - case GL.BYTE: return 'i32'; - case GL.UNSIGNED_BYTE: return 'u32'; - case GL.FLOAT: return 'f32'; - case GL.HALF_FLOAT: return 'f16'; - default: throw new Error(String(type)); + case GL.INT: + return 'i32'; + case GL.UNSIGNED_INT: + return 'u32'; + case GL.SHORT: + return 'i32'; + case GL.UNSIGNED_SHORT: + return 'u32'; + case GL.BYTE: + return 'i32'; + case GL.UNSIGNED_BYTE: + return 'u32'; + case GL.FLOAT: + return 'f32'; + case GL.HALF_FLOAT: + return 'f16'; + default: + throw new Error(String(type)); } } /** GetGL constant from shader data type */ -export function getGLFromShaderDataType(type: ShaderDataType): GL.INT | GL.UNSIGNED_INT | GL.FLOAT | GL.HALF_FLOAT { +export function getGLFromShaderDataType( + type: ShaderDataType +): GL.INT | GL.UNSIGNED_INT | GL.FLOAT | GL.HALF_FLOAT { switch (type) { // TODO - case 'i32': return GL.INT; - case 'u32': return GL.UNSIGNED_INT; - case 'f32': return GL.FLOAT; - case 'f16': return GL.HALF_FLOAT; - default: throw new Error(String(type)); + case 'i32': + return GL.INT; + case 'u32': + return GL.UNSIGNED_INT; + case 'f32': + return GL.FLOAT; + case 'f16': + return GL.HALF_FLOAT; + default: + throw new Error(String(type)); } } diff --git a/modules/webgl/src/adapter/converters/vertex-formats.ts b/modules/webgl/src/adapter/converters/vertex-formats.ts index d4926b3b38..be6fcccc44 100644 --- a/modules/webgl/src/adapter/converters/vertex-formats.ts +++ b/modules/webgl/src/adapter/converters/vertex-formats.ts @@ -4,7 +4,7 @@ import {GL} from '@luma.gl/constants'; import {VertexFormat, VertexType} from '@luma.gl/core'; -type GLDataType = +type GLDataType = | GL.UNSIGNED_BYTE | GL.BYTE | GL.UNSIGNED_SHORT @@ -14,7 +14,6 @@ type GLDataType = | GL.HALF_FLOAT | GL.FLOAT; - /** Get vertex format from GL constants */ export function getVertexFormatFromGL(type: GLDataType, components: 1 | 2 | 3 | 4): VertexFormat { const base = getVertexTypeFromGL(type); diff --git a/modules/webgl/src/adapter/device-helpers/webgl-device-limits.ts b/modules/webgl/src/adapter/device-helpers/webgl-device-limits.ts index 3c2c8e240e..e2774eb71a 100644 --- a/modules/webgl/src/adapter/device-helpers/webgl-device-limits.ts +++ b/modules/webgl/src/adapter/device-helpers/webgl-device-limits.ts @@ -49,4 +49,4 @@ export class WebGLDeviceLimits extends DeviceLimits { } return this.limits[parameter]; } -}; +} diff --git a/modules/webgl/src/adapter/helpers/decode-webgl-types.ts b/modules/webgl/src/adapter/helpers/decode-webgl-types.ts index 7a65c7296c..7ec7b41a84 100644 --- a/modules/webgl/src/adapter/helpers/decode-webgl-types.ts +++ b/modules/webgl/src/adapter/helpers/decode-webgl-types.ts @@ -67,9 +67,11 @@ const COMPOSITE_GL_TYPES: Record< }; /** Decomposes a composite type (GL.VEC3) into a basic type (GL.FLOAT) and components (3) */ -export function decodeGLUniformType( - glUniformType: GL -): {format: ShaderUniformType; components: number; glType: GLDataType} { +export function decodeGLUniformType(glUniformType: GL): { + format: ShaderUniformType; + components: number; + glType: GLDataType; +} { const typeAndSize = COMPOSITE_GL_TYPES[glUniformType]; if (!typeAndSize) { throw new Error('uniform'); @@ -87,11 +89,11 @@ export function decodeGLAttributeType(glAttributeType: GL): { } { const typeAndSize = COMPOSITE_GL_TYPES[glAttributeType]; if (!typeAndSize) { - throw new Error('attribute') + throw new Error('attribute'); } const [, components, , shaderType, vertexFormat] = typeAndSize; // TODO sanity - if (shaderType.startsWith('mat' ...)) - const attributeType = shaderType as unknown as ShaderAttributeType + const attributeType = shaderType as unknown as ShaderAttributeType; return {attributeType, vertexFormat, components}; // , glType}; } @@ -107,7 +109,10 @@ export function decomposeCompositeGLDataType( return {type, components}; } -export function getCompositeGLDataType(type: GL, components): {glType: GLDataType; name: string} | null { +export function getCompositeGLDataType( + type: GL, + components +): {glType: GLDataType; name: string} | null { switch (type) { case GL.BYTE: case GL.UNSIGNED_BYTE: diff --git a/modules/webgl/src/adapter/helpers/get-shader-layout.ts b/modules/webgl/src/adapter/helpers/get-shader-layout.ts index 862c82266d..07535f026d 100644 --- a/modules/webgl/src/adapter/helpers/get-shader-layout.ts +++ b/modules/webgl/src/adapter/helpers/get-shader-layout.ts @@ -105,7 +105,7 @@ function readAttributeDeclarations( if (location >= 0) { const {attributeType} = decodeGLAttributeType(compositeType); - // Whether an attribute is instanced is essentially fixed by the structure of the shader code, + // Whether an attribute is instanced is essentially fixed by the structure of the shader code, // so it is arguably a static property of the shader. // There is no hint in the shader declarations // Heuristic: Any attribute name containing the word "instance" will be assumed to be instanced @@ -115,7 +115,7 @@ function readAttributeDeclarations( name, location, stepMode, - type: attributeType, + type: attributeType // size - for arrays, size is the number of elements in the array }); } diff --git a/modules/webgl/src/adapter/helpers/parse-shader-compiler-log.ts b/modules/webgl/src/adapter/helpers/parse-shader-compiler-log.ts index 9bc92ccc2e..f9235dc240 100644 --- a/modules/webgl/src/adapter/helpers/parse-shader-compiler-log.ts +++ b/modules/webgl/src/adapter/helpers/parse-shader-compiler-log.ts @@ -8,7 +8,7 @@ import type {CompilerMessage} from '@luma.gl/core'; * This follows documented WebGL conventions for compilation logs. * Based on https://github.com/wwwtyro/gl-format-compiler-error (public domain) */ -export function parseShaderCompilerLog(errLog: string) : readonly CompilerMessage[] { +export function parseShaderCompilerLog(errLog: string): readonly CompilerMessage[] { // Parse the error - note: browser and driver dependent const lines = errLog.split(/\r?\n/); @@ -30,7 +30,7 @@ export function parseShaderCompilerLog(errLog: string) : readonly CompilerMessag lineNum: 0, linePos: 0 }); - continue; // eslint-disable-line no-continue + continue; // eslint-disable-line no-continue } const [messageType, linePosition, lineNumber, ...rest] = segments; @@ -50,15 +50,18 @@ export function parseShaderCompilerLog(errLog: string) : readonly CompilerMessag type: getMessageType(messageType), lineNum, linePos // TODO - }) + }); } return messages; } /** Ensure supported type */ -function getMessageType(messageType: string): 'warning' | 'error' | 'info' { +function getMessageType(messageType: string): 'warning' | 'error' | 'info' { const MESSAGE_TYPES = ['warning', 'error', 'info']; const lowerCaseType = messageType.toLowerCase(); - return (MESSAGE_TYPES.includes(lowerCaseType) ? lowerCaseType : 'info') as 'warning' | 'error' | 'info'; + return (MESSAGE_TYPES.includes(lowerCaseType) ? lowerCaseType : 'info') as + | 'warning' + | 'error' + | 'info'; } diff --git a/modules/webgl/src/adapter/helpers/webgl-topology-utils.ts b/modules/webgl/src/adapter/helpers/webgl-topology-utils.ts index c1fe312574..edba6257e4 100644 --- a/modules/webgl/src/adapter/helpers/webgl-topology-utils.ts +++ b/modules/webgl/src/adapter/helpers/webgl-topology-utils.ts @@ -27,7 +27,10 @@ export function getPrimitiveDrawMode(drawMode: GLPrimitiveTopology): GLPrimitive } // Counts the number of complete "primitives" given a number of vertices and a drawMode -export function getPrimitiveCount(options: {drawMode: GLPrimitiveTopology, vertexCount: number}): number { +export function getPrimitiveCount(options: { + drawMode: GLPrimitiveTopology; + vertexCount: number; +}): number { const {drawMode, vertexCount} = options; switch (drawMode) { case GL.POINTS: @@ -48,7 +51,10 @@ export function getPrimitiveCount(options: {drawMode: GLPrimitiveTopology, verte } // Counts the number of vertices after splitting the vertex stream into separate "primitives" -export function getVertexCount(options: {drawMode: GLPrimitiveTopology, vertexCount: number}): number { +export function getVertexCount(options: { + drawMode: GLPrimitiveTopology; + vertexCount: number; +}): number { const {drawMode, vertexCount} = options; const primitiveCount = getPrimitiveCount({drawMode, vertexCount}); switch (getPrimitiveDrawMode(drawMode)) { diff --git a/modules/webgl/src/adapter/objects/webgl-renderbuffer.ts b/modules/webgl/src/adapter/objects/webgl-renderbuffer.ts index ad9b492c47..9a4de3485a 100644 --- a/modules/webgl/src/adapter/objects/webgl-renderbuffer.ts +++ b/modules/webgl/src/adapter/objects/webgl-renderbuffer.ts @@ -6,7 +6,10 @@ import {GL} from '@luma.gl/constants'; import {WebGLDevice} from '../webgl-device'; import {WebGLResource} from './webgl-resource'; import {isRenderbufferFormatSupported} from '../converters/texture-formats'; -import {convertTextureFormatToGL, getTextureFormatBytesPerPixel} from '../converters/texture-formats'; +import { + convertTextureFormatToGL, + getTextureFormatBytesPerPixel +} from '../converters/texture-formats'; export type RenderbufferProps = ResourceProps & { format: TextureFormat; @@ -32,17 +35,29 @@ export class WEBGLRenderbuffer extends WebGLResource { userData: undefined, format: undefined, // 'depth16unorm' width: 1, - height: 1, + height: 1, samples: 0 - }; + }; - override get [Symbol.toStringTag](): string { return 'Renderbuffer'; } + override get [Symbol.toStringTag](): string { + return 'Renderbuffer'; + } - get width(): number { return this.props.width; } - get height(): number { return this.props.height; } - get format(): TextureFormat { return this.props.format; } - get samples(): number { return this.props.samples; } - get attachment() { return } + get width(): number { + return this.props.width; + } + get height(): number { + return this.props.height; + } + get format(): TextureFormat { + return this.props.format; + } + get samples(): number { + return this.props.samples; + } + get attachment() { + return; + } /** WebGL format constant */ glFormat: GL; @@ -61,7 +76,7 @@ export class WEBGLRenderbuffer extends WebGLResource { this._initialize(this.props); } - resize(size: {width: number, height: number}): void { + resize(size: {width: number; height: number}): void { // Don't resize if width/height haven't changed if (size.width !== this.width || size.height !== this.height) { Object.assign(this.props, {...size, format: this.format, samples: this.samples}); @@ -81,7 +96,13 @@ export class WEBGLRenderbuffer extends WebGLResource { this.gl.bindRenderbuffer(GL.RENDERBUFFER, this.handle); if (samples !== 0) { - this.gl.renderbufferStorageMultisample(GL.RENDERBUFFER, samples, this.glFormat, width, height); + this.gl.renderbufferStorageMultisample( + GL.RENDERBUFFER, + samples, + this.glFormat, + width, + height + ); } else { this.gl.renderbufferStorage(GL.RENDERBUFFER, this.glFormat, width, height); } diff --git a/modules/webgl/src/adapter/objects/webgl-resource.ts b/modules/webgl/src/adapter/objects/webgl-resource.ts index 23c33ae4b3..eea21a2178 100644 --- a/modules/webgl/src/adapter/objects/webgl-resource.ts +++ b/modules/webgl/src/adapter/objects/webgl-resource.ts @@ -27,10 +27,10 @@ export abstract class WebGLResource extends Resourc this.device = WebGLDevice.attach(device); const gl = this.device.gl; - // extends + // extends const {id} = props || {}; this.gl = gl; - this.gl2 = gl ; + this.gl2 = gl; this.id = id || uid(this.constructor.name); // Set the handle @@ -78,7 +78,7 @@ export abstract class WebGLResource extends Resourc // @ts-expect-error if (children && deleteChildren) { // @ts-expect-error - children.filter(Boolean).forEach((child) => child.destroy()); + children.filter(Boolean).forEach(child => child.destroy()); } return this; diff --git a/modules/webgl/src/adapter/resources/webgl-buffer.ts b/modules/webgl/src/adapter/resources/webgl-buffer.ts index 2b12deb986..0966bdae90 100644 --- a/modules/webgl/src/adapter/resources/webgl-buffer.ts +++ b/modules/webgl/src/adapter/resources/webgl-buffer.ts @@ -166,9 +166,9 @@ export class WEBGLBuffer extends Buffer { * static STORAGE = 0x0080; * static INDIRECT = 0x0100; * static QUERY_RESOLVE = 0x0200; - * + * * @returns WebGL buffer targe - * + * * Buffer bind points in WebGL2 * gl.COPY_READ_BUFFER: Buffer for copying from one buffer object to another. * gl.COPY_WRITE_BUFFER: Buffer for copying from one buffer object to another. diff --git a/modules/webgl/src/adapter/resources/webgl-command-buffer.ts b/modules/webgl/src/adapter/resources/webgl-command-buffer.ts index 882953cde2..1e7481610f 100644 --- a/modules/webgl/src/adapter/resources/webgl-command-buffer.ts +++ b/modules/webgl/src/adapter/resources/webgl-command-buffer.ts @@ -225,19 +225,18 @@ function _copyTextureToTexture(device: WebGLDevice, options: CopyTextureToTextur origin = [0, 0], /** Texture to copy to/from. */ - destination, + destination /** Mip-map level of the texture to copy to/from. (Default 0) */ // destinationMipLevel = options.mipLevel, /** Defines the origin of the copy - the minimum corner of the texture sub-region to copy to/from. */ // destinationOrigin = [0, 0], /** Defines which aspects of the texture to copy to/from. */ // destinationAspect = options.aspect, - } = options; let { width = options.destination.width, - height = options.destination.width, + height = options.destination.width // depthOrArrayLayers = 0 } = options; diff --git a/modules/webgl/src/adapter/resources/webgl-external-texture.ts b/modules/webgl/src/adapter/resources/webgl-external-texture.ts index 4e83c7cf8f..c44d5bdce0 100644 --- a/modules/webgl/src/adapter/resources/webgl-external-texture.ts +++ b/modules/webgl/src/adapter/resources/webgl-external-texture.ts @@ -91,4 +91,4 @@ export class WEBGLExternalTexture extends WEBGLTexture { } -*/ \ No newline at end of file +*/ diff --git a/modules/webgl/src/adapter/resources/webgl-framebuffer.ts b/modules/webgl/src/adapter/resources/webgl-framebuffer.ts index cb6d30dd86..60c98777e8 100644 --- a/modules/webgl/src/adapter/resources/webgl-framebuffer.ts +++ b/modules/webgl/src/adapter/resources/webgl-framebuffer.ts @@ -142,7 +142,12 @@ export class WEBGLFramebuffer extends Framebuffer { return attachment; } else if (attachment instanceof WEBGLTextureView) { const textureView = attachment; - this._attachTexture(attachmentPoint, textureView.texture, textureView.props.baseMipLevel, textureView.props.baseArrayLayer); + this._attachTexture( + attachmentPoint, + textureView.texture, + textureView.props.baseMipLevel, + textureView.props.baseArrayLayer + ); return attachment.texture; } throw new Error('attach'); diff --git a/modules/webgl/src/adapter/resources/webgl-render-pass.ts b/modules/webgl/src/adapter/resources/webgl-render-pass.ts index cb9b78697b..3a7002c231 100644 --- a/modules/webgl/src/adapter/resources/webgl-render-pass.ts +++ b/modules/webgl/src/adapter/resources/webgl-render-pass.ts @@ -133,13 +133,13 @@ export class WEBGLRenderPass extends RenderPass { // TODO - clear multiple color attachments // for (attachment of this.framebuffer.colorAttachments) { - // this.clearColorBuffer + // this.clearColorBuffer // } } } - /** - * WebGL2 - clear a specific color buffer + /** + * WebGL2 - clear a specific color buffer */ protected clearColorBuffer(drawBuffer: number = 0, value: NumberArray = [0, 0, 0, 0]) { withGLParameters(this.device.gl, {framebuffer: this.props.framebuffer}, () => { @@ -182,4 +182,3 @@ export class WEBGLRenderPass extends RenderPass { // } // }); } - diff --git a/modules/webgl/src/adapter/resources/webgl-render-pipeline.ts b/modules/webgl/src/adapter/resources/webgl-render-pipeline.ts index 772ac52bbd..6bcb7b6693 100644 --- a/modules/webgl/src/adapter/resources/webgl-render-pipeline.ts +++ b/modules/webgl/src/adapter/resources/webgl-render-pipeline.ts @@ -136,7 +136,13 @@ export class WEBGLRenderPipeline extends RenderPipeline { } break; case 'texture': - if (!(value instanceof WEBGLTextureView || value instanceof WEBGLTexture || value instanceof WEBGLFramebuffer)) { + if ( + !( + value instanceof WEBGLTextureView || + value instanceof WEBGLTexture || + value instanceof WEBGLFramebuffer + ) + ) { throw new Error('texture value'); } break; @@ -267,7 +273,7 @@ export class WEBGLRenderPipeline extends RenderPipeline { }); // TODO - check against layout Object.assign(this.uniforms, uniforms); - } + } // PRIVATE METHODS @@ -431,7 +437,13 @@ export class WEBGLRenderPipeline extends RenderPipeline { break; case 'texture': - if (!(value instanceof WEBGLTextureView || value instanceof WEBGLTexture || value instanceof WEBGLFramebuffer)) { + if ( + !( + value instanceof WEBGLTextureView || + value instanceof WEBGLTexture || + value instanceof WEBGLFramebuffer + ) + ) { throw new Error('texture'); } let texture: WEBGLTexture; diff --git a/modules/webgl/src/adapter/resources/webgl-shader.ts b/modules/webgl/src/adapter/resources/webgl-shader.ts index 158fe2361f..10fa851b65 100644 --- a/modules/webgl/src/adapter/resources/webgl-shader.ts +++ b/modules/webgl/src/adapter/resources/webgl-shader.ts @@ -51,7 +51,7 @@ export class WEBGLShader extends Shader { override getTranslatedSource(): string | null { const extensions = this.device.getExtension('WEBGL_debug_shaders'); const ext = extensions.WEBGL_debug_shaders; - return ext?.getTranslatedShaderSource(this.handle); + return ext?.getTranslatedShaderSource(this.handle); } // PRIVATE METHODS @@ -118,7 +118,7 @@ export class WEBGLShader extends Shader { * Get the shader compilation status * TODO - Load log even when no error reported, to catch warnings? * https://gamedev.stackexchange.com/questions/30429/how-to-detect-glsl-warnings - */ + */ protected _getCompilationStatus() { this.compilationStatus = this.device.gl.getShaderParameter(this.handle, GL.COMPILE_STATUS) ? 'success' diff --git a/modules/webgl/src/adapter/resources/webgl-texture-view.ts b/modules/webgl/src/adapter/resources/webgl-texture-view.ts index 77dc851b61..70c6ec5839 100644 --- a/modules/webgl/src/adapter/resources/webgl-texture-view.ts +++ b/modules/webgl/src/adapter/resources/webgl-texture-view.ts @@ -15,7 +15,7 @@ export class WEBGLTextureView extends TextureView { readonly texture: WEBGLTexture; - constructor(device: Device, props: TextureViewProps & {texture: WEBGLTexture}) { + constructor(device: Device, props: TextureViewProps & {texture: WEBGLTexture}) { super(device, {...Texture.defaultProps, ...props}); this.device = device as WebGLDevice; diff --git a/modules/webgl/src/adapter/resources/webgl-transform-feedback.ts b/modules/webgl/src/adapter/resources/webgl-transform-feedback.ts index 12e032d7c5..73102e779d 100644 --- a/modules/webgl/src/adapter/resources/webgl-transform-feedback.ts +++ b/modules/webgl/src/adapter/resources/webgl-transform-feedback.ts @@ -174,12 +174,7 @@ export class WEBGLTransformFeedback extends TransformFeedback { } } - protected _bindBuffer( - index: number, - buffer: Buffer, - byteOffset = 0, - byteLength?: number - ): void { + protected _bindBuffer(index: number, buffer: Buffer, byteOffset = 0, byteLength?: number): void { const handle = buffer && (buffer as WEBGLBuffer).handle; if (!handle || byteLength === undefined) { this.gl.bindBufferBase(GL.TRANSFORM_FEEDBACK_BUFFER, index, handle); diff --git a/modules/webgl/src/adapter/webgl-canvas-context.ts b/modules/webgl/src/adapter/webgl-canvas-context.ts index c1d9041b8c..94b6fb2b67 100644 --- a/modules/webgl/src/adapter/webgl-canvas-context.ts +++ b/modules/webgl/src/adapter/webgl-canvas-context.ts @@ -6,8 +6,8 @@ import {CanvasContext} from '@luma.gl/core'; import {WebGLDevice} from './webgl-device'; import {WEBGLFramebuffer} from './resources/webgl-framebuffer'; -/** - * A WebGL Canvas Context which manages the canvas and handles drawing buffer resizing etc +/** + * A WebGL Canvas Context which manages the canvas and handles drawing buffer resizing etc */ export class WebGLCanvasContext extends CanvasContext { readonly device: WebGLDevice; @@ -33,7 +33,8 @@ export class WebGLCanvasContext extends CanvasContext { /** Resizes and updates render targets if necessary */ update() { const size = this.getPixelSize(); - const sizeChanged = size[0] !== this.presentationSize[0] || size[1] !== this.presentationSize[1]; + const sizeChanged = + size[0] !== this.presentationSize[0] || size[1] !== this.presentationSize[1]; if (sizeChanged) { this.presentationSize = size; this.resize(); diff --git a/modules/webgl/src/classic/accessor.ts b/modules/webgl/src/classic/accessor.ts index bdee925c0a..f93690a188 100644 --- a/modules/webgl/src/classic/accessor.ts +++ b/modules/webgl/src/classic/accessor.ts @@ -58,7 +58,7 @@ export class Accessor implements AccessorObject { } constructor(...accessors: AccessorObject[]) { - accessors.forEach((accessor) => this._assign(accessor)); // Merge in sequence + accessors.forEach(accessor => this._assign(accessor)); // Merge in sequence Object.freeze(this); } @@ -151,10 +151,10 @@ export class Accessor implements AccessorObject { if (this.divisor === undefined) delete this.divisor; if (this.normalized === undefined) delete this.normalized; if (this.integer === undefined) delete this.integer; - + if (this.buffer === undefined) delete this.buffer; if (this.index === undefined) delete this.index; - + return this; } } diff --git a/modules/webgl/src/classic/clear.ts b/modules/webgl/src/classic/clear.ts index 084238f158..fc8c8de562 100644 --- a/modules/webgl/src/classic/clear.ts +++ b/modules/webgl/src/classic/clear.ts @@ -18,8 +18,8 @@ const GL_DEPTH_STENCIL = 0x84f9; // Should disappear if asserts are removed const ERR_ARGUMENTS = 'clear: bad arguments'; -/** - * Optionally clears depth, color and stencil buffers +/** + * Optionally clears depth, color and stencil buffers * @deprecated Set clear color when creating a RenderPass. */ export function clear( @@ -65,15 +65,20 @@ export function clear( }); } -/** - * WebGL2 - clear a specific drawing buffer +/** + * WebGL2 - clear a specific drawing buffer * @deprecated Set clear color when creating a RenderPass */ export function clearBuffer( device: Device, options?: {framebuffer?: Framebuffer; buffer?: any; drawBuffer?: any; value?: any} ) { - const {framebuffer = null, buffer = GL_COLOR, drawBuffer = 0, value = [0, 0, 0, 0]} = options || {}; + const { + framebuffer = null, + buffer = GL_COLOR, + drawBuffer = 0, + value = [0, 0, 0, 0] + } = options || {}; const gl = (device as WebGLDevice).gl; withGLParameters(gl, {framebuffer}, () => { // Method selection per OpenGL ES 3 docs diff --git a/modules/webgl/src/classic/copy-and-blit.ts b/modules/webgl/src/classic/copy-and-blit.ts index 4fe391685d..932ddbb8ad 100644 --- a/modules/webgl/src/classic/copy-and-blit.ts +++ b/modules/webgl/src/classic/copy-and-blit.ts @@ -106,7 +106,13 @@ export function readPixelsToBuffer( sourceType?: number; } ): WEBGLBuffer { - const {target, sourceX = 0, sourceY = 0, sourceFormat = GL.RGBA, targetByteOffset = 0} = options || {}; + const { + target, + sourceX = 0, + sourceY = 0, + sourceFormat = GL.RGBA, + targetByteOffset = 0 + } = options || {}; // following parameters are auto deduced if not provided let {sourceWidth, sourceHeight, sourceType} = options || {}; const {framebuffer, deleteFramebuffer} = getFramebuffer(source); diff --git a/modules/webgl/src/classic/typed-array-utils.ts b/modules/webgl/src/classic/typed-array-utils.ts index 1e03cc9eff..3f9812e367 100644 --- a/modules/webgl/src/classic/typed-array-utils.ts +++ b/modules/webgl/src/classic/typed-array-utils.ts @@ -108,12 +108,7 @@ export function flipRows(options: { } } - -export function scalePixels(options: { - data: TypedArray; - width: number; - height: number; -}): { +export function scalePixels(options: {data: TypedArray; width: number; height: number}): { data: Uint8Array; width: number; height: number; diff --git a/modules/webgl/src/context/debug/spector.ts b/modules/webgl/src/context/debug/spector.ts index bc30fa093c..ac2bddfc83 100644 --- a/modules/webgl/src/context/debug/spector.ts +++ b/modules/webgl/src/context/debug/spector.ts @@ -34,8 +34,8 @@ export async function loadSpectorJS(props?: SpectorProps) { if (!globalThis.SPECTOR) { try { await loadScript(SPECTOR_CDN_URL); - } catch(error) { - log.warn(String(error)) + } catch (error) { + log.warn(String(error)); } } } @@ -64,14 +64,16 @@ export function initializeSpectorJS(props?: SpectorProps) { // enables recording some extra information merged in the capture like texture memory sizes and formats spector.spyCanvases(); // A callback when results are ready - spector?.onCaptureStarted.add((capture: unknown) => log.info('Spector capture started:', capture)()); + spector?.onCaptureStarted.add((capture: unknown) => + log.info('Spector capture started:', capture)() + ); spector?.onCapture.add((capture: unknown) => { log.info('Spector capture complete:', capture)(); // Use undocumented Spector API to open the UI with our capture // See https://github.com/BabylonJS/Spector.js/blob/767ad1195a25b85a85c381f400eb50a979239eca/src/spector.ts#L124 - spector?.getResultUI() + spector?.getResultUI(); spector?.resultView.display(); - spector?.resultView.addCapture(capture) + spector?.resultView.addCapture(capture); }); } diff --git a/modules/webgl/src/context/debug/webgl-developer-tools.ts b/modules/webgl/src/context/debug/webgl-developer-tools.ts index 61f5d638e3..e2f026665f 100644 --- a/modules/webgl/src/context/debug/webgl-developer-tools.ts +++ b/modules/webgl/src/context/debug/webgl-developer-tools.ts @@ -4,7 +4,7 @@ import {log, loadScript} from '@luma.gl/core'; // Rename constant to prevent inlining. We need the full set of constants for generating debug strings. import {GL as GLEnum} from '@luma.gl/constants'; -import {isBrowser} from '@probe.gl/env' +import {isBrowser} from '@probe.gl/env'; const WEBGL_DEBUG_CDN_URL = 'https://unpkg.com/webgl-debug@2.0.1/index.js'; @@ -24,7 +24,7 @@ type DebugContextProps = { type ContextData = { realContext?: WebGL2RenderingContext; debugContext?: WebGL2RenderingContext; -} +}; // Helper to get shared context data function getWebGLContextData(gl: any): ContextData { @@ -38,7 +38,7 @@ declare global { } /** - * Loads Khronos WebGLDeveloperTools from CDN if not already installed + * Loads Khronos WebGLDeveloperTools from CDN if not already installed * const WebGLDebugUtils = require('webgl-debug'); * @see https://github.com/KhronosGroup/WebGLDeveloperTools * @see https://github.com/vorg/webgl-debug @@ -54,7 +54,10 @@ export async function loadWebGLDeveloperTools(): Promise { // Returns (a potentially new) context with debug instrumentation turned off or on. // Note that this actually returns a new context -export function makeDebugContext(gl: WebGL2RenderingContext, props: DebugContextProps = {}): WebGL2RenderingContext | null { +export function makeDebugContext( + gl: WebGL2RenderingContext, + props: DebugContextProps = {} +): WebGL2RenderingContext | null { // Return null to ensure we don't try to create a context in this case (TODO what case is that?) if (!gl) { return null; @@ -71,7 +74,10 @@ function getRealContext(gl: WebGL2RenderingContext): WebGL2RenderingContext { } // Returns the debug context from either of the real/debug contexts -function getDebugContext(gl: WebGL2RenderingContext, props: DebugContextProps): WebGL2RenderingContext { +function getDebugContext( + gl: WebGL2RenderingContext, + props: DebugContextProps +): WebGL2RenderingContext { if (!globalThis.WebGLDebugUtils) { log.warn('webgl-debug not loaded')(); return gl; @@ -98,7 +104,7 @@ function getDebugContext(gl: WebGL2RenderingContext, props: DebugContextProps): glDebug[key] = GLEnum[key]; } } - + // Ensure we have a clean prototype on the instrumented object // Note: setPrototypeOf does come with perf warnings, but we already take a bigger perf reduction // by synchronizing the WebGL errors after each WebGL call. @@ -119,7 +125,7 @@ function getDebugContext(gl: WebGL2RenderingContext, props: DebugContextProps): function getFunctionString(functionName: string, functionArgs): string { // Cover bug in webgl-debug-tools - functionArgs = Array.from(functionArgs).map(arg => arg === undefined ? 'undefined' : arg); + functionArgs = Array.from(functionArgs).map(arg => (arg === undefined ? 'undefined' : arg)); let args = globalThis.WebGLDebugUtils.glFunctionArgsToString(functionName, functionArgs); args = `${args.slice(0, 100)}${args.length > 100 ? '...' : ''}`; return `gl.${functionName}(${args})`; @@ -127,7 +133,7 @@ function getFunctionString(functionName: string, functionArgs): string { function onGLError(props: DebugContextProps, err, functionName: string, args: any[]): void { // Cover bug in webgl-debug-tools - args = Array.from(args).map(arg => arg === undefined ? 'undefined' : arg); + args = Array.from(args).map(arg => (arg === undefined ? 'undefined' : arg)); const errorMessage = globalThis.WebGLDebugUtils.glEnumToString(err); const functionArgs = globalThis.WebGLDebugUtils.glFunctionArgsToString(functionName, args); const message = `${errorMessage} in gl.${functionName}(${functionArgs})`; @@ -139,7 +145,11 @@ function onGLError(props: DebugContextProps, err, functionName: string, args: an } // Don't generate function string until it is needed -function onValidateGLFunc(props: DebugContextProps, functionName: string, functionArgs: any[]): void { +function onValidateGLFunc( + props: DebugContextProps, + functionName: string, + functionArgs: any[] +): void { let functionString: string = ''; if (log.level >= 1) { functionString = getFunctionString(functionName, functionArgs); @@ -149,7 +159,9 @@ function onValidateGLFunc(props: DebugContextProps, functionName: string, functi // If array of breakpoint strings supplied, check if any of them is contained in current GLEnum function if (props.break && props.break.length > 0) { functionString = functionString || getFunctionString(functionName, functionArgs); - const isBreakpoint = props.break.every((breakOn: string) => functionString.indexOf(breakOn) !== -1); + const isBreakpoint = props.break.every( + (breakOn: string) => functionString.indexOf(breakOn) !== -1 + ); if (isBreakpoint) { debugger; // eslint-disable-line } diff --git a/modules/webgl/src/context/helpers/create-browser-context.ts b/modules/webgl/src/context/helpers/create-browser-context.ts index e56c5e6d1a..5e7f240cdd 100644 --- a/modules/webgl/src/context/helpers/create-browser-context.ts +++ b/modules/webgl/src/context/helpers/create-browser-context.ts @@ -64,7 +64,7 @@ export function createBrowserContext( // Software GPU // props.failIfMajorPerformanceCaveat = false; - + // if (!gl && props.webgl1) { // gl = canvas.getContext('webgl', props); // } diff --git a/modules/webgl/src/context/parameters/webgl-parameter-tables.ts b/modules/webgl/src/context/parameters/webgl-parameter-tables.ts index f4f94049bf..0a0ea2d1d8 100644 --- a/modules/webgl/src/context/parameters/webgl-parameter-tables.ts +++ b/modules/webgl/src/context/parameters/webgl-parameter-tables.ts @@ -98,7 +98,7 @@ const pixelStorei = (gl: WebGL2RenderingContext, value: number | boolean, key: G gl.pixelStorei(key, value); const bindFramebuffer = (gl: WebGL2RenderingContext, value: unknown, key: GL) => { - const target = (key === GL.FRAMEBUFFER_BINDING) ? GL.DRAW_FRAMEBUFFER : GL.READ_FRAMEBUFFER; + const target = key === GL.FRAMEBUFFER_BINDING ? GL.DRAW_FRAMEBUFFER : GL.READ_FRAMEBUFFER; return gl.bindFramebuffer(target, value); }; @@ -135,13 +135,15 @@ export const GL_PARAMETER_SETTERS = { [GL.BLEND_DST_ALPHA]: 'blendFunc', [GL.COLOR_CLEAR_VALUE]: (gl: WebGL2RenderingContext, value: [number, number, number, number]) => gl.clearColor(...value), - [GL.COLOR_WRITEMASK]: (gl: WebGL2RenderingContext, value: [boolean, boolean, boolean, boolean]) => gl.colorMask(...value), + [GL.COLOR_WRITEMASK]: (gl: WebGL2RenderingContext, value: [boolean, boolean, boolean, boolean]) => + gl.colorMask(...value), [GL.CULL_FACE]: enable, [GL.CULL_FACE_MODE]: (gl: WebGL2RenderingContext, value) => gl.cullFace(value), [GL.DEPTH_TEST]: enable, [GL.DEPTH_CLEAR_VALUE]: (gl: WebGL2RenderingContext, value) => gl.clearDepth(value), [GL.DEPTH_FUNC]: (gl: WebGL2RenderingContext, value) => gl.depthFunc(value), - [GL.DEPTH_RANGE]: (gl: WebGL2RenderingContext, value: [number, number]) => gl.depthRange(...value), + [GL.DEPTH_RANGE]: (gl: WebGL2RenderingContext, value: [number, number]) => + gl.depthRange(...value), [GL.DEPTH_WRITEMASK]: (gl: WebGL2RenderingContext, value) => gl.depthMask(value), [GL.DITHER]: enable, [GL.FRAGMENT_SHADER_DERIVATIVE_HINT]: hint, @@ -150,9 +152,8 @@ export const GL_PARAMETER_SETTERS = { [GL.RENDERBUFFER_BINDING]: (gl: WebGL2RenderingContext, value) => gl.bindRenderbuffer(GL.RENDERBUFFER, value), [GL.TRANSFORM_FEEDBACK_BINDING]: (gl: WebGL2RenderingContext, value) => - (gl ).bindTransformFeedback?.(GL.TRANSFORM_FEEDBACK, value), - [GL.VERTEX_ARRAY_BINDING]: (gl: WebGL2RenderingContext, value) => - (gl ).bindVertexArray(value), + gl.bindTransformFeedback?.(GL.TRANSFORM_FEEDBACK, value), + [GL.VERTEX_ARRAY_BINDING]: (gl: WebGL2RenderingContext, value) => gl.bindVertexArray(value), // NOTE: FRAMEBUFFER_BINDING and DRAW_FRAMEBUFFER_BINDING(WebGL2) refer same state. [GL.FRAMEBUFFER_BINDING]: bindFramebuffer, [GL.READ_FRAMEBUFFER_BINDING]: bindFramebuffer, @@ -176,7 +177,8 @@ export const GL_PARAMETER_SETTERS = { [GL.SAMPLE_COVERAGE_VALUE]: 'sampleCoverage', [GL.SAMPLE_COVERAGE_INVERT]: 'sampleCoverage', [GL.SCISSOR_TEST]: enable, - [GL.SCISSOR_BOX]: (gl: WebGL2RenderingContext, value: [number, number, number, number]) => gl.scissor(...value), + [GL.SCISSOR_BOX]: (gl: WebGL2RenderingContext, value: [number, number, number, number]) => + gl.scissor(...value), [GL.STENCIL_TEST]: enable, [GL.STENCIL_CLEAR_VALUE]: (gl: WebGL2RenderingContext, value) => gl.clearStencil(value), [GL.STENCIL_WRITEMASK]: (gl: WebGL2RenderingContext, value) => @@ -195,7 +197,8 @@ export const GL_PARAMETER_SETTERS = { [GL.STENCIL_BACK_FAIL]: 'stencilOpBack', [GL.STENCIL_BACK_PASS_DEPTH_FAIL]: 'stencilOpBack', [GL.STENCIL_BACK_PASS_DEPTH_PASS]: 'stencilOpBack', - [GL.VIEWPORT]: (gl: WebGL2RenderingContext, value: [number, number, number, number]) => gl.viewport(...value), + [GL.VIEWPORT]: (gl: WebGL2RenderingContext, value: [number, number, number, number]) => + gl.viewport(...value), // WEBGL2 EXTENSIONS @@ -245,22 +248,30 @@ export const GL_PARAMETER_SETTERS = { const handle = framebuffer && 'handle' in framebuffer ? framebuffer.handle : framebuffer; return gl.bindFramebuffer(GL.FRAMEBUFFER, handle); }, - blend: (gl: WebGL2RenderingContext, value) => (value ? gl.enable(GL.BLEND) : gl.disable(GL.BLEND)), - blendColor: (gl: WebGL2RenderingContext, value: [number, number, number, number]) => gl.blendColor(...value), + blend: (gl: WebGL2RenderingContext, value) => + value ? gl.enable(GL.BLEND) : gl.disable(GL.BLEND), + blendColor: (gl: WebGL2RenderingContext, value: [number, number, number, number]) => + gl.blendColor(...value), blendEquation: (gl: WebGL2RenderingContext, args: number | [number, number]) => { - const separateModes = typeof args === 'number' ? [args, args] as [number, number]: args; + const separateModes = typeof args === 'number' ? ([args, args] as [number, number]) : args; gl.blendEquationSeparate(...separateModes); }, - blendFunc: (gl: WebGL2RenderingContext, args: [number, number] | [number, number, number, number]) => { - const separateFuncs = args?.length === 2 ? [...args, ...args] as [number, number, number, number] : args; + blendFunc: ( + gl: WebGL2RenderingContext, + args: [number, number] | [number, number, number, number] + ) => { + const separateFuncs = + args?.length === 2 ? ([...args, ...args] as [number, number, number, number]) : args; gl.blendFuncSeparate(...separateFuncs); }, - clearColor: (gl: WebGL2RenderingContext, value: [number, number, number, number]) => gl.clearColor(...value), + clearColor: (gl: WebGL2RenderingContext, value: [number, number, number, number]) => + gl.clearColor(...value), clearDepth: (gl: WebGL2RenderingContext, value) => gl.clearDepth(value), clearStencil: (gl: WebGL2RenderingContext, value) => gl.clearStencil(value), - colorMask: (gl: WebGL2RenderingContext, value: [boolean, boolean, boolean, boolean]) => gl.colorMask(...value), + colorMask: (gl: WebGL2RenderingContext, value: [boolean, boolean, boolean, boolean]) => + gl.colorMask(...value), cull: (gl: WebGL2RenderingContext, value) => value ? gl.enable(GL.CULL_FACE) : gl.disable(GL.CULL_FACE), @@ -288,13 +299,16 @@ export const GL_PARAMETER_SETTERS = { polygonOffsetFill: (gl: WebGL2RenderingContext, value) => value ? gl.enable(GL.POLYGON_OFFSET_FILL) : gl.disable(GL.POLYGON_OFFSET_FILL), - polygonOffset: (gl: WebGL2RenderingContext, value: [number, number]) => gl.polygonOffset(...value), + polygonOffset: (gl: WebGL2RenderingContext, value: [number, number]) => + gl.polygonOffset(...value), - sampleCoverage: (gl: WebGL2RenderingContext, value: [number, boolean?]) => gl.sampleCoverage(...value), + sampleCoverage: (gl: WebGL2RenderingContext, value: [number, boolean?]) => + gl.sampleCoverage(...value), scissorTest: (gl: WebGL2RenderingContext, value) => value ? gl.enable(GL.SCISSOR_TEST) : gl.disable(GL.SCISSOR_TEST), - scissor: (gl: WebGL2RenderingContext, value: [number, number, number, number]) => gl.scissor(...value), + scissor: (gl: WebGL2RenderingContext, value: [number, number, number, number]) => + gl.scissor(...value), stencilTest: (gl: WebGL2RenderingContext, value) => value ? gl.enable(GL.STENCIL_TEST) : gl.disable(GL.STENCIL_TEST), @@ -317,7 +331,8 @@ export const GL_PARAMETER_SETTERS = { gl.stencilOpSeparate(GL.BACK, backSfail, backDpfail, backDppass); }, - viewport: (gl: WebGL2RenderingContext, value: [number, number, number, number]) => gl.viewport(...value) + viewport: (gl: WebGL2RenderingContext, value: [number, number, number, number]) => + gl.viewport(...value) }; function getValue(glEnum, values, cache) { diff --git a/modules/webgl/src/context/state-tracker/track-context-state.ts b/modules/webgl/src/context/state-tracker/track-context-state.ts index 159a60de60..0bb3322285 100644 --- a/modules/webgl/src/context/state-tracker/track-context-state.ts +++ b/modules/webgl/src/context/state-tracker/track-context-state.ts @@ -4,7 +4,11 @@ // Support for listening to context state changes and intercepting state queries // NOTE: this system does not handle buffer bindings import {assert} from '@luma.gl/core'; -import {GL_PARAMETER_DEFAULTS, GL_HOOKED_SETTERS, NON_CACHE_PARAMETERS} from '../parameters/webgl-parameter-tables'; +import { + GL_PARAMETER_DEFAULTS, + GL_HOOKED_SETTERS, + NON_CACHE_PARAMETERS +} from '../parameters/webgl-parameter-tables'; import {setGLParameters, getGLParameters} from '../parameters/unified-parameter-api'; import {deepArrayEqual} from './deep-array-equal'; @@ -57,7 +61,8 @@ class GLState { let valueChanged = false; let oldValue; // = undefined - const oldValues: {[key: number | string]: any} | null = this.stateStack.length > 0 ? this.stateStack[this.stateStack.length - 1] : null; + const oldValues: {[key: number | string]: any} | null = + this.stateStack.length > 0 ? this.stateStack[this.stateStack.length - 1] : null; for (const key in values) { assert(key !== undefined); @@ -152,7 +157,6 @@ export function pushContextState(gl: WebGL2RenderingContext): void { glState.push(); } - /** * Restores previously saved WebGL context state */ @@ -190,9 +194,9 @@ function installGetterOverride(gl: WebGL2RenderingContext, functionName: string) // Optionally call the original function to do a "hard" query from the WebGL2RenderingContext return glState.enable ? // Call the getter the params so that it can e.g. serve from a cache - glState.cache[pname] + glState.cache[pname] : // Optionally call the original function to do a "hard" query from the WebGL2RenderingContext - originalGetterFunc(pname); + originalGetterFunc(pname); }; // Set the name of this anonymous function to help in debugging and profiling diff --git a/modules/webgl/src/context/state-tracker/with-parameters.ts b/modules/webgl/src/context/state-tracker/with-parameters.ts index 4ac810ac58..011db2d711 100644 --- a/modules/webgl/src/context/state-tracker/with-parameters.ts +++ b/modules/webgl/src/context/state-tracker/with-parameters.ts @@ -14,7 +14,11 @@ import {pushContextState, popContextState} from './track-context-state'; * - Restores parameters * - Returns the return value of the supplied function */ -export function withGLParameters(device: Device | WebGL2RenderingContext, parameters: GLParameters & {nocatch?: boolean}, func: any): any { +export function withGLParameters( + device: Device | WebGL2RenderingContext, + parameters: GLParameters & {nocatch?: boolean}, + func: any +): any { const webglDevice = WebGLDevice.attach(device); const gl = webglDevice.gl; diff --git a/modules/webgl/test/adapter/device-helpers/set-device-parameters.spec.ts b/modules/webgl/test/adapter/device-helpers/set-device-parameters.spec.ts index d734394b26..072ee92ca0 100644 --- a/modules/webgl/test/adapter/device-helpers/set-device-parameters.spec.ts +++ b/modules/webgl/test/adapter/device-helpers/set-device-parameters.spec.ts @@ -14,9 +14,9 @@ import {setDeviceParameters, getGLParameters, resetGLParameters} from '@luma.gl/ const getGLParameter = (parameter: keyof GLParameters): any => { const parameters = getGLParameters(webglDevice, [parameter]); return parameters[parameter]; -} +}; -test('setDeviceParameters#cullMode', (t) => { +test('setDeviceParameters#cullMode', t => { resetGLParameters(webglDevice); t.deepEqual(getGLParameter(GL.CULL_FACE), false, 'got expected value'); @@ -35,7 +35,7 @@ test('setDeviceParameters#cullMode', (t) => { t.end(); }); -test('setDeviceParameters#frontFace', (t) => { +test('setDeviceParameters#frontFace', t => { resetGLParameters(webglDevice); t.deepEqual(getGLParameter(GL.FRONT_FACE), GL.CCW, 'got expected value'); @@ -49,7 +49,7 @@ test('setDeviceParameters#frontFace', (t) => { t.end(); }); -test('setDeviceParameters#depthWriteEnabled', (t) => { +test('setDeviceParameters#depthWriteEnabled', t => { resetGLParameters(webglDevice); t.deepEqual(getGLParameter(GL.DEPTH_WRITEMASK), true, 'got expected value'); @@ -63,7 +63,7 @@ test('setDeviceParameters#depthWriteEnabled', (t) => { t.end(); }); -test('setDeviceParameters#blending', (t) => { +test('setDeviceParameters#blending', t => { resetGLParameters(webglDevice); t.equal(getGLParameter(GL.BLEND), false, 'blending disabled'); @@ -71,8 +71,16 @@ test('setDeviceParameters#blending', (t) => { setDeviceParameters(webglDevice, {blendColorOperation: 'add', blendAlphaOperation: 'subtract'}); t.equal(getGLParameter(GL.BLEND), true, 'GL.BLEND = true'); - t.equal(getGLParameter(GL.BLEND_EQUATION_RGB), GL.FUNC_ADD, 'GL.BLEND_EQUATION_RGB = GL.FUNC_ADD'); - t.equal(getGLParameter(GL.BLEND_EQUATION_ALPHA), GL.FUNC_SUBTRACT, 'GL.BLEND_EQUATION_ALPHA = GL.FUNC_SUBTRACT'); + t.equal( + getGLParameter(GL.BLEND_EQUATION_RGB), + GL.FUNC_ADD, + 'GL.BLEND_EQUATION_RGB = GL.FUNC_ADD' + ); + t.equal( + getGLParameter(GL.BLEND_EQUATION_ALPHA), + GL.FUNC_SUBTRACT, + 'GL.BLEND_EQUATION_ALPHA = GL.FUNC_SUBTRACT' + ); t.equal(getGLParameter(GL.BLEND_SRC_RGB), GL.ONE, 'GL.BLEND_SRC_RGB = GL.ONE'); t.equal(getGLParameter(GL.BLEND_DST_RGB), GL.ZERO, 'GL.BLEND_DST_RGB = GL.ZERO'); t.equal(getGLParameter(GL.BLEND_SRC_ALPHA), GL.ONE, 'GL.BLEND_SRC_ALPHA = GL.ONE'); @@ -84,7 +92,7 @@ test('setDeviceParameters#blending', (t) => { blendColorSrcFactor: 'src-alpha', blendColorDstFactor: 'dst-alpha', blendAlphaSrcFactor: 'zero', - blendAlphaDstFactor: 'one', + blendAlphaDstFactor: 'one' }); t.equal(getGLParameter(GL.BLEND), true, 'GL.BLEND = true'); @@ -98,7 +106,7 @@ test('setDeviceParameters#blending', (t) => { t.end(); }); -test('setDeviceParameters#depthCompare', (t) => { +test('setDeviceParameters#depthCompare', t => { resetGLParameters(webglDevice); t.equal(getGLParameter(GL.DEPTH_TEST), false, 'GL.DEPTH_TEST = false'); @@ -114,7 +122,7 @@ test('setDeviceParameters#depthCompare', (t) => { t.end(); }); -test.skip('setDeviceParameters#depthClearValue', (t) => { +test.skip('setDeviceParameters#depthClearValue', t => { // let value = getGLParameters(gl, [GL.DEPTH_CLEAR_VALUE])[GL.DEPTH_CLEAR_VALUE]; // t.is(value, 1, `got expected value ${stringify(value)}`); diff --git a/modules/webgl/test/adapter/helpers/parse-shader-compiler-log.spec.ts b/modules/webgl/test/adapter/helpers/parse-shader-compiler-log.spec.ts index 2df64e2c54..ea01e4b0fb 100644 --- a/modules/webgl/test/adapter/helpers/parse-shader-compiler-log.spec.ts +++ b/modules/webgl/test/adapter/helpers/parse-shader-compiler-log.spec.ts @@ -4,7 +4,7 @@ import test from 'tape-promise/tape'; import {parseShaderCompilerLog} from '@luma.gl/webgl/adapter/helpers/parse-shader-compiler-log'; -test('parseShaderCompilerLog', (t) => { +test('parseShaderCompilerLog', t => { const {ERROR_LOG, EXPECTED_MESSAGES} = getFixtures(); const messages = parseShaderCompilerLog(ERROR_LOG); // SHADER_SOURCE, SHADER_TYPE; t.deepEqual(messages, EXPECTED_MESSAGES, 'parseShaderCompilerLog generated correct messages'); @@ -36,121 +36,121 @@ ERROR: 0:994: 'project_scale' : no matching overloaded function found const EXPECTED_MESSAGES = [ { - message: '\'/\' : Zero divided by zero during constant folding generated NaN', + message: "'/' : Zero divided by zero during constant folding generated NaN", type: 'warning', lineNum: 264, linePos: 0 }, { - message: '\'/\' : Zero divided by zero during constant folding generated NaN', + message: "'/' : Zero divided by zero during constant folding generated NaN", type: 'warning', lineNum: 264, linePos: 0 }, { - message: '\'/\' : Divide by zero during constant folding', + message: "'/' : Divide by zero during constant folding", type: 'warning', lineNum: 294, linePos: 0 }, { - message: '\'/\' : Divide by zero during constant folding', + message: "'/' : Divide by zero during constant folding", type: 'warning', lineNum: 294, linePos: 0 }, { - message: '\'/\' : Zero divided by zero during constant folding generated NaN', + message: "'/' : Zero divided by zero during constant folding generated NaN", type: 'warning', lineNum: 344, linePos: 0 }, { - message: '\'/\' : Zero divided by zero during constant folding generated NaN', + message: "'/' : Zero divided by zero during constant folding generated NaN", type: 'warning', lineNum: 344, linePos: 0 }, { - message: '\'/\' : Zero divided by zero during constant folding generated NaN', + message: "'/' : Zero divided by zero during constant folding generated NaN", type: 'warning', lineNum: 447, linePos: 0 }, { - message: '\'/\' : Zero divided by zero during constant folding generated NaN', + message: "'/' : Zero divided by zero during constant folding generated NaN", type: 'warning', lineNum: 447, linePos: 0 }, { - message: '\'/\' : Zero divided by zero during constant folding generated NaN', + message: "'/' : Zero divided by zero during constant folding generated NaN", type: 'warning', lineNum: 470, linePos: 0 }, { - message: '\'/\' : Zero divided by zero during constant folding generated NaN', + message: "'/' : Zero divided by zero during constant folding generated NaN", type: 'warning', lineNum: 470, linePos: 0 }, { - message: '\'/\' : Zero divided by zero during constant folding generated NaN', + message: "'/' : Zero divided by zero during constant folding generated NaN", type: 'warning', lineNum: 557, linePos: 0 }, { - message: '\'/\' : Zero divided by zero during constant folding generated NaN', + message: "'/' : Zero divided by zero during constant folding generated NaN", type: 'warning', lineNum: 557, linePos: 0 }, { - message: '\'/\' : Zero divided by zero during constant folding generated NaN', + message: "'/' : Zero divided by zero during constant folding generated NaN", type: 'warning', lineNum: 580, linePos: 0 }, { - message: '\'/\' : Zero divided by zero during constant folding generated NaN', + message: "'/' : Zero divided by zero during constant folding generated NaN", type: 'warning', lineNum: 580, linePos: 0 }, { - message: '\'/\' : Zero divided by zero during constant folding generated NaN', + message: "'/' : Zero divided by zero during constant folding generated NaN", type: 'warning', lineNum: 669, linePos: 0 }, { - message: '\'/\' : Zero divided by zero during constant folding generated NaN', + message: "'/' : Zero divided by zero during constant folding generated NaN", type: 'warning', lineNum: 669, linePos: 0 }, { - message: '\'/\' : Zero divided by zero during constant folding generated NaN', + message: "'/' : Zero divided by zero during constant folding generated NaN", type: 'warning', lineNum: 681, linePos: 0 }, { - message: '\'/\' : Zero divided by zero during constant folding generated NaN', + message: "'/' : Zero divided by zero during constant folding generated NaN", type: 'warning', lineNum: 681, linePos: 0 }, { - message: '\'project_scale\' : no matching overloaded function found', + message: "'project_scale' : no matching overloaded function found", type: 'error', lineNum: 967, linePos: 0 }, { - message: '\'project_scale\' : no matching overloaded function found', + message: "'project_scale' : no matching overloaded function found", type: 'error', lineNum: 994, linePos: 0 diff --git a/modules/webgl/test/adapter/helpers/webgl-topology-utils.spec.ts b/modules/webgl/test/adapter/helpers/webgl-topology-utils.spec.ts index 21d474c15d..db21ac7a90 100644 --- a/modules/webgl/test/adapter/helpers/webgl-topology-utils.spec.ts +++ b/modules/webgl/test/adapter/helpers/webgl-topology-utils.spec.ts @@ -3,9 +3,15 @@ import test from 'tape-promise/tape'; import {GL} from '@luma.gl/constants'; -import {getGLDrawMode, getGLPrimitive, getPrimitiveCount, getPrimitiveDrawMode, getVertexCount} from '@luma.gl/webgl/adapter/helpers/webgl-topology-utils'; +import { + getGLDrawMode, + getGLPrimitive, + getPrimitiveCount, + getPrimitiveDrawMode, + getVertexCount +} from '@luma.gl/webgl/adapter/helpers/webgl-topology-utils'; -test('getPrimitiveDrawMode', (t) => { +test('getPrimitiveDrawMode', t => { t.equals(getPrimitiveDrawMode(GL.POINTS), GL.POINTS, 'point-list'); t.equals(getPrimitiveDrawMode(GL.LINES), GL.LINES, 'line-list'); t.equals(getPrimitiveDrawMode(GL.LINE_STRIP), GL.LINES, 'line-strip'); @@ -15,7 +21,7 @@ test('getPrimitiveDrawMode', (t) => { t.end(); }); -test('getPrimitiveCount', (t) => { +test('getPrimitiveCount', t => { t.equals(getPrimitiveCount({drawMode: GL.POINTS, vertexCount: 12}), 12, 'point-list'); t.equals(getPrimitiveCount({drawMode: GL.LINES, vertexCount: 12}), 6, 'line-list'); t.equals(getPrimitiveCount({drawMode: GL.TRIANGLES, vertexCount: 12}), 4, 'triangle-list'); @@ -23,7 +29,7 @@ test('getPrimitiveCount', (t) => { t.end(); }); -test('getVertexCount', (t) => { +test('getVertexCount', t => { t.equals(getVertexCount({drawMode: GL.POINTS, vertexCount: 12}), 12, 'point-list'); t.equals(getVertexCount({drawMode: GL.LINE_STRIP, vertexCount: 12}), 22, 'line-strip'); t.equals(getVertexCount({drawMode: GL.TRIANGLE_STRIP, vertexCount: 12}), 30, 'triangle-strip'); @@ -31,7 +37,7 @@ test('getVertexCount', (t) => { t.end(); }); -test('getGLDrawMode', (t) => { +test('getGLDrawMode', t => { t.equals(getGLDrawMode('point-list'), GL.POINTS, 'point-list'); t.equals(getGLDrawMode('line-list'), GL.LINES, 'line-list'); t.equals(getGLDrawMode('line-strip'), GL.LINE_STRIP, 'line-strip'); @@ -41,7 +47,7 @@ test('getGLDrawMode', (t) => { t.end(); }); -test('getGLPrimitive', (t) => { +test('getGLPrimitive', t => { t.equals(getGLPrimitive('point-list'), GL.POINTS, 'point-list'); t.equals(getGLPrimitive('line-list'), GL.LINES, 'line-list'); t.equals(getGLPrimitive('line-strip'), GL.LINES, 'line-strip'); diff --git a/modules/webgl/test/adapter/objects/webgl-renderbuffer.spec.ts b/modules/webgl/test/adapter/objects/webgl-renderbuffer.spec.ts index 6268855f1d..8c9ca3560c 100644 --- a/modules/webgl/test/adapter/objects/webgl-renderbuffer.spec.ts +++ b/modules/webgl/test/adapter/objects/webgl-renderbuffer.spec.ts @@ -7,31 +7,34 @@ import {getWebGLTestDevices} from '@luma.gl/test-utils'; import {TextureFormat} from '@luma.gl/core'; import {WEBGLRenderbuffer, _TEXTURE_FORMATS} from '@luma.gl/webgl'; -test('WebGL#WEBGLRenderbuffer construct/delete', (t) => { +test('WebGL#WEBGLRenderbuffer construct/delete', t => { for (const device of getWebGLTestDevices()) { t.throws( // @ts-ignore () => new WEBGLRenderbuffer(), 'WEBGLRenderbuffer throws on missing gl context' ); - - const renderbuffer = new WEBGLRenderbuffer(device, {format: 'depth16unorm', width: 1, height: 1}); + + const renderbuffer = new WEBGLRenderbuffer(device, { + format: 'depth16unorm', + width: 1, + height: 1 + }); t.ok(renderbuffer instanceof WEBGLRenderbuffer, 'WEBGLRenderbuffer construction successful'); - + renderbuffer.destroy(); t.ok(renderbuffer instanceof WEBGLRenderbuffer, 'WEBGLRenderbuffer delete successful'); - + renderbuffer.destroy(); - t.ok(renderbuffer instanceof WEBGLRenderbuffer, 'WEBGLRenderbuffer repeated delete successful'); + t.ok(renderbuffer instanceof WEBGLRenderbuffer, 'WEBGLRenderbuffer repeated delete successful'); } t.end(); }); -test('WebGL#WEBGLRenderbuffer format creation', (t) => { +test('WebGL#WEBGLRenderbuffer format creation', t => { for (const device of getWebGLTestDevices()) { - - for (const formatName of Object.keys(_TEXTURE_FORMATS) ) { + for (const formatName of Object.keys(_TEXTURE_FORMATS)) { const format = formatName as TextureFormat; if (WEBGLRenderbuffer.isTextureFormatSupported(device, format)) { t.comment(format); diff --git a/modules/webgl/test/adapter/resources/webgl-buffer.spec.ts b/modules/webgl/test/adapter/resources/webgl-buffer.spec.ts index c5ff615cc4..14d3adb951 100644 --- a/modules/webgl/test/adapter/resources/webgl-buffer.spec.ts +++ b/modules/webgl/test/adapter/resources/webgl-buffer.spec.ts @@ -67,9 +67,5 @@ test('WEBGLBuffer#write', async t => { async function readAsyncF32(source: Buffer): Promise { const {buffer, byteOffset, byteLength} = await source.readAsync(); - return new Float32Array( - buffer, - byteOffset, - byteLength / Float32Array.BYTES_PER_ELEMENT - ); + return new Float32Array(buffer, byteOffset, byteLength / Float32Array.BYTES_PER_ELEMENT); } diff --git a/modules/webgl/test/adapter/webgl-canvas-context.spec.ts b/modules/webgl/test/adapter/webgl-canvas-context.spec.ts index 4fcf5ed30d..2304ee9872 100644 --- a/modules/webgl/test/adapter/webgl-canvas-context.spec.ts +++ b/modules/webgl/test/adapter/webgl-canvas-context.spec.ts @@ -2,7 +2,7 @@ // Copyright (c) vis.gl contributors import test from 'tape-promise/tape'; -import {createTestDevice} from '@luma.gl/test-utils' +import {createTestDevice} from '@luma.gl/test-utils'; import {WebGLCanvasContext} from '@luma.gl/webgl'; import {CanvasContext} from '@luma.gl/core'; @@ -10,7 +10,7 @@ import {CanvasContext} from '@luma.gl/core'; const canvasContextDevice = createTestDevice(); const canvasContext = canvasContextDevice?.canvasContext; -test('WebGLDevice#headless context creation', (t) => { +test('WebGLDevice#headless context creation', t => { t.ok(WebGLCanvasContext, 'WebGLCanvasContext defined'); // t.ok(new WEBGLCanvasContext()), 'Context creation ok'); t.end(); @@ -296,17 +296,19 @@ const MAP_TEST_CASES = [ } ]; -test('WebGLCanvasContext#cssToDevicePixels', (t) => { - MAP_TEST_CASES.forEach((tc) => { +test('WebGLCanvasContext#cssToDevicePixels', t => { + MAP_TEST_CASES.forEach(tc => { if (canvasContext) { configureCanvasContext(canvasContext, tc); } tc.windowPositions.forEach((wPos, i) => { // by default yInvert is true t.deepEqual( - canvasContext?.cssToDevicePixels( tc.windowPositions[i]), + canvasContext?.cssToDevicePixels(tc.windowPositions[i]), tc.devicePositionsInverted[i], - `${tc.name}(yInvert=true): device pixel should be ${JSON.stringify(tc.devicePositionsInverted[i])} for window position ${tc.windowPositions[i]}` + `${tc.name}(yInvert=true): device pixel should be ${JSON.stringify( + tc.devicePositionsInverted[i] + )} for window position ${tc.windowPositions[i]}` ); t.deepEqual( canvasContext?.cssToDevicePixels(tc.windowPositions[i], false), @@ -318,12 +320,16 @@ test('WebGLCanvasContext#cssToDevicePixels', (t) => { t.end(); }); -test('WebGLCanvasContext#cssToDeviceRatio', (t) => { - MAP_TEST_CASES.forEach((tc) => { +test('WebGLCanvasContext#cssToDeviceRatio', t => { + MAP_TEST_CASES.forEach(tc => { if (canvasContext) { configureCanvasContext(canvasContext, tc); } - t.equal(canvasContext?.cssToDeviceRatio(), tc.ratio, 'cssToDeviceRatio should return correct value'); + t.equal( + canvasContext?.cssToDeviceRatio(), + tc.ratio, + 'cssToDeviceRatio should return correct value' + ); }); // TODO - this is no longer how we emulate node contexts... diff --git a/modules/webgl/test/adapter/webgl-device.spec.ts b/modules/webgl/test/adapter/webgl-device.spec.ts index 23be1c282f..aa37cde3c7 100644 --- a/modules/webgl/test/adapter/webgl-device.spec.ts +++ b/modules/webgl/test/adapter/webgl-device.spec.ts @@ -5,11 +5,11 @@ import test from 'tape-promise/tape'; import {webglDevice} from '@luma.gl/test-utils'; import {WebGLDevice} from '@luma.gl/webgl'; -test('WebGLDevice#lost (Promise)', async (t) => { +test('WebGLDevice#lost (Promise)', async t => { const device = await WebGLDevice.create(); // Wrap in a promise to make sure tape waits for us - await new Promise(async (resolve) => { + await new Promise(async resolve => { setTimeout(async () => { const cause = await device.lost; t.equal(cause.reason, 'destroyed', `Context lost: ${cause.message}`); @@ -22,7 +22,7 @@ test('WebGLDevice#lost (Promise)', async (t) => { device.destroy(); }); -test.skip('WebGLDevice#resize', (t) => { +test.skip('WebGLDevice#resize', t => { // Using default pixel ratio of 1 // update drawing buffer size to simulate webglDevice context webglDevice.canvasContext.resize({width: 10, height: 20, useDevicePixels: 1}); diff --git a/modules/webgl/test/context/state-tracker/context-state.spec.ts b/modules/webgl/test/context/state-tracker/context-state.spec.ts index 719310aab6..38b8c637e1 100644 --- a/modules/webgl/test/context/state-tracker/context-state.spec.ts +++ b/modules/webgl/test/context/state-tracker/context-state.spec.ts @@ -353,9 +353,9 @@ test('WebGLState#BlendEquationMinMax', t => { t.equal( value, expected[state], - `WebGL : expected value, ${webglDevice.getGLKey( - value - )} received for ${webglDevice.getGLKey(state)}` + `WebGL : expected value, ${webglDevice.getGLKey(value)} received for ${webglDevice.getGLKey( + state + )}` ); } } diff --git a/modules/webgl/test/context/state-tracker/data/sample-enum-settings.ts b/modules/webgl/test/context/state-tracker/data/sample-enum-settings.ts index fc0b4a0830..d185082791 100644 --- a/modules/webgl/test/context/state-tracker/data/sample-enum-settings.ts +++ b/modules/webgl/test/context/state-tracker/data/sample-enum-settings.ts @@ -52,33 +52,37 @@ export const ENUM_STYLE_SETTINGS_SET1_PRIMITIVE: GLParameters = { // [GL.UNPACK_SKIP_IMAGES]: 512 }; -export const ENUM_STYLE_SETTINGS_SET1: GLParameters = Object.assign({}, ENUM_STYLE_SETTINGS_SET1_PRIMITIVE, { - [GL.BLEND_EQUATION_RGB]: GL.FUNC_SUBTRACT, - [GL.BLEND_EQUATION_ALPHA]: GL.MIN, - [GL.BLEND_SRC_RGB]: GL.SRC_COLOR, - [GL.BLEND_DST_RGB]: GL.DST_COLOR, - [GL.BLEND_SRC_ALPHA]: GL.SRC_ALPHA, - [GL.BLEND_DST_ALPHA]: GL.DST_ALPHA, - [GL.POLYGON_OFFSET_FILL]: true, - [GL.POLYGON_OFFSET_FACTOR]: 1, - [GL.POLYGON_OFFSET_UNITS]: 1, - [GL.SAMPLE_COVERAGE_VALUE]: 0, - [GL.SAMPLE_COVERAGE_INVERT]: true, - [GL.STENCIL_WRITEMASK]: 0xcccccccc, - [GL.STENCIL_BACK_WRITEMASK]: 0xdddddddd, - [GL.STENCIL_FUNC]: GL.NEVER, - [GL.STENCIL_REF]: 0.5, - [GL.STENCIL_VALUE_MASK]: 0xbbbbbbbb, - [GL.STENCIL_BACK_FUNC]: GL.LEQUAL, - [GL.STENCIL_BACK_REF]: 0.5, - [GL.STENCIL_BACK_VALUE_MASK]: 0x11111111, - [GL.STENCIL_FAIL]: GL.REPLACE, - [GL.STENCIL_PASS_DEPTH_FAIL]: GL.INCR, - [GL.STENCIL_PASS_DEPTH_PASS]: GL.DECR, - [GL.STENCIL_BACK_FAIL]: GL.REPLACE, - [GL.STENCIL_BACK_PASS_DEPTH_FAIL]: GL.INCR, - [GL.STENCIL_BACK_PASS_DEPTH_PASS]: GL.DECR -}); +export const ENUM_STYLE_SETTINGS_SET1: GLParameters = Object.assign( + {}, + ENUM_STYLE_SETTINGS_SET1_PRIMITIVE, + { + [GL.BLEND_EQUATION_RGB]: GL.FUNC_SUBTRACT, + [GL.BLEND_EQUATION_ALPHA]: GL.MIN, + [GL.BLEND_SRC_RGB]: GL.SRC_COLOR, + [GL.BLEND_DST_RGB]: GL.DST_COLOR, + [GL.BLEND_SRC_ALPHA]: GL.SRC_ALPHA, + [GL.BLEND_DST_ALPHA]: GL.DST_ALPHA, + [GL.POLYGON_OFFSET_FILL]: true, + [GL.POLYGON_OFFSET_FACTOR]: 1, + [GL.POLYGON_OFFSET_UNITS]: 1, + [GL.SAMPLE_COVERAGE_VALUE]: 0, + [GL.SAMPLE_COVERAGE_INVERT]: true, + [GL.STENCIL_WRITEMASK]: 0xcccccccc, + [GL.STENCIL_BACK_WRITEMASK]: 0xdddddddd, + [GL.STENCIL_FUNC]: GL.NEVER, + [GL.STENCIL_REF]: 0.5, + [GL.STENCIL_VALUE_MASK]: 0xbbbbbbbb, + [GL.STENCIL_BACK_FUNC]: GL.LEQUAL, + [GL.STENCIL_BACK_REF]: 0.5, + [GL.STENCIL_BACK_VALUE_MASK]: 0x11111111, + [GL.STENCIL_FAIL]: GL.REPLACE, + [GL.STENCIL_PASS_DEPTH_FAIL]: GL.INCR, + [GL.STENCIL_PASS_DEPTH_PASS]: GL.DECR, + [GL.STENCIL_BACK_FAIL]: GL.REPLACE, + [GL.STENCIL_BACK_PASS_DEPTH_FAIL]: GL.INCR, + [GL.STENCIL_BACK_PASS_DEPTH_PASS]: GL.DECR + } +); export const ENUM_STYLE_SETTINGS_SET2: GLParameters = { [GL.BLEND]: true, diff --git a/modules/webgl/test/context/state-tracker/deep-array-equal.spec.ts b/modules/webgl/test/context/state-tracker/deep-array-equal.spec.ts index d5f42aa3b6..fa471a8a09 100644 --- a/modules/webgl/test/context/state-tracker/deep-array-equal.spec.ts +++ b/modules/webgl/test/context/state-tracker/deep-array-equal.spec.ts @@ -4,7 +4,7 @@ import test from 'tape-promise/tape'; import {deepArrayEqual} from '@luma.gl/webgl/context/state-tracker/deep-array-equal'; -test('WebGLState#deepArrayEqual', (t) => { +test('WebGLState#deepArrayEqual', t => { const ARRAY = [0, 1, 2]; const TEST_CASES = [ diff --git a/modules/webgl/test/context/state-tracker/set-parameters.spec.ts b/modules/webgl/test/context/state-tracker/set-parameters.spec.ts index 0140bce404..b5b5bfa582 100644 --- a/modules/webgl/test/context/state-tracker/set-parameters.spec.ts +++ b/modules/webgl/test/context/state-tracker/set-parameters.spec.ts @@ -12,7 +12,7 @@ import {GL_PARAMETER_DEFAULTS} from '@luma.gl/webgl/context/parameters/webgl-par import {ENUM_STYLE_SETTINGS_SET1_PRIMITIVE} from './data/sample-enum-settings'; // Settings test, don't reuse a context -test('WebGL#set and get', (t) => { +test('WebGL#set and get', t => { resetGLParameters(webglDevice); let cullFace = getGLParameters(webglDevice, [GL.CULL_FACE])[GL.CULL_FACE]; @@ -35,7 +35,7 @@ test('WebGL#set and get', (t) => { t.end(); }); -test('WebGL#composite setter', (t) => { +test('WebGL#composite setter', t => { const compositeStateKeys = [GL.STENCIL_FUNC, GL.STENCIL_REF, GL.STENCIL_VALUE_MASK]; resetGLParameters(webglDevice); @@ -71,8 +71,7 @@ test('WebGL#composite setter', (t) => { t.end(); }); -test('WebGLState#get all parameters', (t) => { - +test('WebGLState#get all parameters', t => { resetGLParameters(webglDevice); // Set custom values. @@ -83,7 +82,9 @@ test('WebGLState#get all parameters', (t) => { t.deepEqual( value, ENUM_STYLE_SETTINGS_SET1_PRIMITIVE[key], - `got expected value ${stringifyTypedArray(value)} after setGLParameters for ${webglDevice.getGLKey(key)}` + `got expected value ${stringifyTypedArray( + value + )} after setGLParameters for ${webglDevice.getGLKey(key)}` ); } @@ -93,15 +94,16 @@ test('WebGLState#get all parameters', (t) => { t.deepEqual( value, ENUM_STYLE_SETTINGS_SET1_PRIMITIVE[key], - `got expected value ${stringifyTypedArray(value)} after getGLParameters for ${webglDevice.getGLKey(key)}` + `got expected value ${stringifyTypedArray( + value + )} after getGLParameters for ${webglDevice.getGLKey(key)}` ); } t.end(); }); -test('WebGL#reset', (t) => { - +test('WebGL#reset', t => { // Set custom values and verify. setGLParameters(webglDevice, ENUM_STYLE_SETTINGS_SET1_PRIMITIVE); for (const key in ENUM_STYLE_SETTINGS_SET1_PRIMITIVE) { @@ -110,7 +112,9 @@ test('WebGL#reset', (t) => { t.deepEqual( value, ENUM_STYLE_SETTINGS_SET1_PRIMITIVE[key], - `got expected value ${stringifyTypedArray(value)} after setGLParameters for ${webglDevice.getGLKey(key)}` + `got expected value ${stringifyTypedArray( + value + )} after setGLParameters for ${webglDevice.getGLKey(key)}` ); } @@ -124,17 +128,16 @@ test('WebGL#reset', (t) => { t.deepEqual( value, GL_PARAMETER_DEFAULTS[key], - `got expected value ${stringifyTypedArray(value)} after resetGLParameters for ${webglDevice.getGLKey( - key - )}` + `got expected value ${stringifyTypedArray( + value + )} after resetGLParameters for ${webglDevice.getGLKey(key)}` ); } t.end(); }); -test('WebGLState#setGLParameters framebuffer', (t) => { - +test('WebGLState#setGLParameters framebuffer', t => { resetGLParameters(webglDevice); let fbHandle = getGLParameters(webglDevice, [GL.FRAMEBUFFER_BINDING])[GL.FRAMEBUFFER_BINDING]; @@ -157,12 +160,13 @@ test('WebGLState#setGLParameters framebuffer', (t) => { t.end(); }); -test('WebGLState#setGLParameters read-framebuffer (WebGL2 only)', (t) => { +test('WebGLState#setGLParameters read-framebuffer (WebGL2 only)', t => { // const webglDevice = createTestContext({webgl2: true, webgl1: false}); resetGLParameters(webglDevice); - - let fbHandle = getGLParameters(webglDevice, [GL.READ_FRAMEBUFFER_BINDING])[GL.READ_FRAMEBUFFER_BINDING]; + let fbHandle = getGLParameters(webglDevice, [GL.READ_FRAMEBUFFER_BINDING])[ + GL.READ_FRAMEBUFFER_BINDING + ]; // t.equal(fbHandle, null, 'Initial read-frambuffer binding should be null'); const framebuffer = webglDevice.createFramebuffer({colorAttachments: ['rgba8unorm']}); @@ -170,7 +174,9 @@ test('WebGLState#setGLParameters read-framebuffer (WebGL2 only)', (t) => { [GL.READ_FRAMEBUFFER_BINDING]: framebuffer.handle }); - fbHandle = getGLParameters(webglDevice, [GL.READ_FRAMEBUFFER_BINDING])[GL.READ_FRAMEBUFFER_BINDING]; + fbHandle = getGLParameters(webglDevice, [GL.READ_FRAMEBUFFER_BINDING])[ + GL.READ_FRAMEBUFFER_BINDING + ]; t.equal(fbHandle, framebuffer.handle, 'setGLParameters should set read-framebuffer binding'); // verify setting null value @@ -178,7 +184,9 @@ test('WebGLState#setGLParameters read-framebuffer (WebGL2 only)', (t) => { [GL.READ_FRAMEBUFFER_BINDING]: null }); - fbHandle = getGLParameters(webglDevice, [GL.READ_FRAMEBUFFER_BINDING])[GL.READ_FRAMEBUFFER_BINDING]; + fbHandle = getGLParameters(webglDevice, [GL.READ_FRAMEBUFFER_BINDING])[ + GL.READ_FRAMEBUFFER_BINDING + ]; t.equal(fbHandle, null, 'setGLParameters should set read-framebuffer binding'); t.end(); }); diff --git a/modules/webgl/test/context/state-tracker/track-context-state.spec.ts b/modules/webgl/test/context/state-tracker/track-context-state.spec.ts index efcb09c6aa..3752e0f5c6 100644 --- a/modules/webgl/test/context/state-tracker/track-context-state.spec.ts +++ b/modules/webgl/test/context/state-tracker/track-context-state.spec.ts @@ -29,14 +29,14 @@ import {ENUM_STYLE_SETTINGS_SET1, ENUM_STYLE_SETTINGS_SET2} from './data/sample- // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion const device = createTestDevice({debug: true}) as WebGLDevice; -test('WebGLState#imports', (t) => { +test('WebGLState#imports', t => { t.ok(typeof trackContextState === 'function', 'trackContextState imported OK'); t.ok(typeof pushContextState === 'function', 'trackContextState imported OK'); t.ok(typeof popContextState === 'function', 'trackContextState imported OK'); t.end(); }); -test('WebGLState#trackContextState', (t) => { +test('WebGLState#trackContextState', t => { const {gl} = device; t.doesNotThrow( () => trackContextState(gl, {copyState: false}), @@ -45,7 +45,7 @@ test('WebGLState#trackContextState', (t) => { t.end(); }); -test('WebGLState#push & pop', (t) => { +test('WebGLState#push & pop', t => { const {gl} = device; resetGLParameters(gl); @@ -116,7 +116,7 @@ test('WebGLState#push & pop', (t) => { t.end(); }); -test('WebGLState#gl API', (t) => { +test('WebGLState#gl API', t => { const {gl} = device; resetGLParameters(gl); @@ -172,7 +172,7 @@ test('WebGLState#gl API', (t) => { t.end(); }); -test('WebGLState#intercept gl calls', (t) => { +test('WebGLState#intercept gl calls', t => { const {gl} = device; resetGLParameters(gl); @@ -215,7 +215,7 @@ test('WebGLState#intercept gl calls', (t) => { t.end(); }); -test('WebGLState#not cached parameters', (t) => { +test('WebGLState#not cached parameters', t => { const {gl} = device; resetGLParameters(gl); diff --git a/modules/webgpu/src/adapter/helpers/accessor-to-format.ts b/modules/webgpu/src/adapter/helpers/accessor-to-format.ts index b9698b7837..d664dbf8aa 100644 --- a/modules/webgpu/src/adapter/helpers/accessor-to-format.ts +++ b/modules/webgpu/src/adapter/helpers/accessor-to-format.ts @@ -97,4 +97,4 @@ export function mapAccessorToWebGPUFormat(accessor) { } throw new Error('illegal accessor'); } -*/ \ No newline at end of file +*/ diff --git a/modules/webgpu/src/adapter/helpers/generate-mipmaps.ts b/modules/webgpu/src/adapter/helpers/generate-mipmaps.ts index 23563e439f..e9f88b9ee9 100644 --- a/modules/webgpu/src/adapter/helpers/generate-mipmaps.ts +++ b/modules/webgpu/src/adapter/helpers/generate-mipmaps.ts @@ -30,7 +30,7 @@ export class WebGPUMipmapGenerator { constructor(device: GPUDevice, glslang) { this.device = device; - this.mipmapSampler = device.createSampler({ minFilter: 'linear' }); + this.mipmapSampler = device.createSampler({minFilter: 'linear'}); this.mipmapPipeline = device.createRenderPipeline({ vertexStage: { @@ -46,9 +46,11 @@ export class WebGPUMipmapGenerator { entryPoint: 'main' }, primitiveTopology: 'triangle-strip', - colorStates: [{ - format: 'rgba8unorm', - }] + colorStates: [ + { + format: 'rgba8unorm' + } + ] }); } @@ -56,9 +58,10 @@ export class WebGPUMipmapGenerator { const textureSize = { width: imageBitmap.width, height: imageBitmap.height, - depth: 1, - } - const mipLevelCount = Math.floor(Math.log2(Math.max(imageBitmap.width, imageBitmap.height))) + 1; + depth: 1 + }; + const mipLevelCount = + Math.floor(Math.log2(Math.max(imageBitmap.width, imageBitmap.height))) + 1; // Populate the top level of the srcTexture with the imageBitmap. const texture = this.device.createTexture({ @@ -67,32 +70,37 @@ export class WebGPUMipmapGenerator { usage: GPUTextureUsage.COPY_DST | GPUTextureUsage.SAMPLED | GPUTextureUsage.OUTPUT_ATTACHMENT, mipLevelCount }); - this.device.queue.copyImageBitmapToTexture({ imageBitmap }, { texture }, textureSize); + this.device.queue.copyImageBitmapToTexture({imageBitmap}, {texture}, textureSize); const commandEncoder = this.device.createCommandEncoder({}); for (let i = 1; i < mipLevelCount; ++i) { const passEncoder = commandEncoder.beginRenderPass({ - colorAttachments: [{ - attachment: texture.createView({ - baseMipLevel: i, - mipLevelCount: 1 - }), - loadValue: { r: 1.0, g: 0.0, b: 0.0, a: 0.0 }, - }], + colorAttachments: [ + { + attachment: texture.createView({ + baseMipLevel: i, + mipLevelCount: 1 + }), + loadValue: {r: 1.0, g: 0.0, b: 0.0, a: 0.0} + } + ] }); const bindGroup = this.device.createBindGroup({ layout: this.mipmapPipeline.getBindGroupLayout(0), - bindings: [{ - binding: 0, - resource: this.mipmapSampler, - }, { - binding: 1, - resource: texture.createView({ - baseMipLevel: i - 1, - mipLevelCount: 1 - }), - }], + bindings: [ + { + binding: 0, + resource: this.mipmapSampler + }, + { + binding: 1, + resource: texture.createView({ + baseMipLevel: i - 1, + mipLevelCount: 1 + }) + } + ] }); passEncoder.setPipeline(this.mipmapPipeline); diff --git a/modules/webgpu/src/adapter/helpers/get-bind-group.ts b/modules/webgpu/src/adapter/helpers/get-bind-group.ts index bb7499ab75..a6f0e9afa1 100644 --- a/modules/webgpu/src/adapter/helpers/get-bind-group.ts +++ b/modules/webgpu/src/adapter/helpers/get-bind-group.ts @@ -41,7 +41,10 @@ export function getShaderLayoutBinding( shaderLayout: ShaderLayout, bindingName: string ): BindingDeclaration { - const bindingLayout = shaderLayout.bindings.find(binding => binding.name === bindingName || `${binding.name}uniforms` === bindingName.toLocaleLowerCase()); + const bindingLayout = shaderLayout.bindings.find( + binding => + binding.name === bindingName || `${binding.name}uniforms` === bindingName.toLocaleLowerCase() + ); if (!bindingLayout) { log.warn(`Binding ${bindingName} not set: Not found in shader layout.`)(); } diff --git a/modules/webgpu/src/adapter/helpers/get-vertex-buffer-layout.ts b/modules/webgpu/src/adapter/helpers/get-vertex-buffer-layout.ts index 177cd4e94b..84d2eef544 100644 --- a/modules/webgpu/src/adapter/helpers/get-vertex-buffer-layout.ts +++ b/modules/webgpu/src/adapter/helpers/get-vertex-buffer-layout.ts @@ -40,7 +40,9 @@ export function getVertexBufferLayout( const attributeName = attributeMapping.attribute; const attributeLayout = findAttributeLayout(shaderLayout, attributeName, usedAttributes); - stepMode = attributeLayout.stepMode || (attributeLayout.name.startsWith('instance') ? 'instance' : 'vertex'); + stepMode = + attributeLayout.stepMode || + (attributeLayout.name.startsWith('instance') ? 'instance' : 'vertex'); vertexAttributes.push({ format: getWebGPUVertexFormat(attributeMapping.format || mapping.format), offset: attributeMapping.byteOffset, @@ -57,7 +59,9 @@ export function getVertexBufferLayout( } byteStride = decodeVertexFormat(mapping.format).byteLength; - stepMode = attributeLayout.stepMode || (attributeLayout.name.startsWith('instance') ? 'instance' : 'vertex'); + stepMode = + attributeLayout.stepMode || + (attributeLayout.name.startsWith('instance') ? 'instance' : 'vertex'); vertexAttributes.push({ format: getWebGPUVertexFormat(mapping.format), // We only support 0 offset for non-interleaved buffer layouts @@ -79,7 +83,8 @@ export function getVertexBufferLayout( if (!usedAttributes.has(attribute.name)) { vertexBufferLayouts.push({ arrayStride: decodeVertexFormat('float32x3').byteLength, - stepMode: attribute.stepMode || (attribute.name.startsWith('instance') ? 'instance' : 'vertex'), + stepMode: + attribute.stepMode || (attribute.name.startsWith('instance') ? 'instance' : 'vertex'), attributes: [ { format: getWebGPUVertexFormat('float32x3'), diff --git a/modules/webgpu/src/adapter/helpers/webgpu-parameters.ts b/modules/webgpu/src/adapter/helpers/webgpu-parameters.ts index ecea345608..bc011f7481 100644 --- a/modules/webgpu/src/adapter/helpers/webgpu-parameters.ts +++ b/modules/webgpu/src/adapter/helpers/webgpu-parameters.ts @@ -33,17 +33,29 @@ export const PARAMETER_TABLE: Record = { // DEPTH - depthWriteEnabled: (parameter: keyof Parameters, value: any, descriptor: GPURenderPipelineDescriptor) => { + depthWriteEnabled: ( + parameter: keyof Parameters, + value: any, + descriptor: GPURenderPipelineDescriptor + ) => { const depthStencil = addDepthStencil(descriptor); depthStencil.depthWriteEnabled = value; }, - depthCompare: (parameter: keyof Parameters, value: any, descriptor: GPURenderPipelineDescriptor) => { + depthCompare: ( + parameter: keyof Parameters, + value: any, + descriptor: GPURenderPipelineDescriptor + ) => { const depthStencil = addDepthStencil(descriptor); depthStencil.depthCompare = value; }, - depthFormat: (parameter: keyof Parameters, value: any, descriptor: GPURenderPipelineDescriptor) => { + depthFormat: ( + parameter: keyof Parameters, + value: any, + descriptor: GPURenderPipelineDescriptor + ) => { const depthStencil = addDepthStencil(descriptor); depthStencil.format = value; }, @@ -53,47 +65,79 @@ export const PARAMETER_TABLE: Record = { depthStencil.depthBias = value; }, - depthBiasSlopeScale: (parameter: keyof Parameters, value: any, descriptor: GPURenderPipelineDescriptor) => { + depthBiasSlopeScale: ( + parameter: keyof Parameters, + value: any, + descriptor: GPURenderPipelineDescriptor + ) => { const depthStencil = addDepthStencil(descriptor); depthStencil.depthBiasSlopeScale = value; }, - depthBiasClamp: (parameter: keyof Parameters, value: any, descriptor: GPURenderPipelineDescriptor) => { + depthBiasClamp: ( + parameter: keyof Parameters, + value: any, + descriptor: GPURenderPipelineDescriptor + ) => { const depthStencil = addDepthStencil(descriptor); depthStencil.depthBiasClamp = value; }, // STENCIL - stencilReadMask: (parameter: keyof Parameters, value: any, descriptor: GPURenderPipelineDescriptor) => { + stencilReadMask: ( + parameter: keyof Parameters, + value: any, + descriptor: GPURenderPipelineDescriptor + ) => { const depthStencil = addDepthStencil(descriptor); depthStencil.stencilReadMask = value; }, - stencilWriteMask: (parameter: keyof Parameters, value: any, descriptor: GPURenderPipelineDescriptor) => { + stencilWriteMask: ( + parameter: keyof Parameters, + value: any, + descriptor: GPURenderPipelineDescriptor + ) => { const depthStencil = addDepthStencil(descriptor); depthStencil.stencilWriteMask = value; }, - stencilCompare: (parameter: keyof Parameters, value: any, descriptor: GPURenderPipelineDescriptor) => { + stencilCompare: ( + parameter: keyof Parameters, + value: any, + descriptor: GPURenderPipelineDescriptor + ) => { const depthStencil = addDepthStencil(descriptor); depthStencil.stencilFront.compare = value; depthStencil.stencilBack.compare = value; }, - stencilPassOperation: (parameter: keyof Parameters, value: any, descriptor: GPURenderPipelineDescriptor) => { + stencilPassOperation: ( + parameter: keyof Parameters, + value: any, + descriptor: GPURenderPipelineDescriptor + ) => { const depthStencil = addDepthStencil(descriptor); depthStencil.stencilFront.passOp = value; depthStencil.stencilBack.passOp = value; }, - stencilFailOperation: (parameter: keyof Parameters, value: any, descriptor: GPURenderPipelineDescriptor) => { + stencilFailOperation: ( + parameter: keyof Parameters, + value: any, + descriptor: GPURenderPipelineDescriptor + ) => { const depthStencil = addDepthStencil(descriptor); depthStencil.stencilFront.failOp = value; depthStencil.stencilBack.failOp = value; }, - stencilDepthFailOperation: (parameter: keyof Parameters, value: any, descriptor: GPURenderPipelineDescriptor) => { + stencilDepthFailOperation: ( + parameter: keyof Parameters, + value: any, + descriptor: GPURenderPipelineDescriptor + ) => { const depthStencil = addDepthStencil(descriptor); depthStencil.stencilFront.depthFailOp = value; depthStencil.stencilBack.depthFailOp = value; @@ -101,17 +145,29 @@ export const PARAMETER_TABLE: Record = { // MULTISAMPLE - sampleCount: (parameter: keyof Parameters, value: any, descriptor: GPURenderPipelineDescriptor) => { + sampleCount: ( + parameter: keyof Parameters, + value: any, + descriptor: GPURenderPipelineDescriptor + ) => { descriptor.multisample = descriptor.multisample || {}; descriptor.multisample.count = value; }, - sampleMask: (parameter: keyof Parameters, value: any, descriptor: GPURenderPipelineDescriptor) => { + sampleMask: ( + parameter: keyof Parameters, + value: any, + descriptor: GPURenderPipelineDescriptor + ) => { descriptor.multisample = descriptor.multisample || {}; descriptor.multisample.mask = value; }, - sampleAlphaToCoverageEnabled: (parameter: keyof Parameters, value: any, descriptor: GPURenderPipelineDescriptor) => { + sampleAlphaToCoverageEnabled: ( + parameter: keyof Parameters, + value: any, + descriptor: GPURenderPipelineDescriptor + ) => { descriptor.multisample = descriptor.multisample || {}; descriptor.multisample.alphaToCoverageEnabled = value; }, @@ -123,7 +179,11 @@ export const PARAMETER_TABLE: Record = { targets[0].writeMask = value; }, - blendColorOperation: (parameter: keyof Parameters, value: any, descriptor: GPURenderPipelineDescriptor) => { + blendColorOperation: ( + parameter: keyof Parameters, + value: any, + descriptor: GPURenderPipelineDescriptor + ) => { addColorState(descriptor); // const targets = addColorState(descriptor); // const target = targets[0]; diff --git a/modules/webgpu/src/adapter/resources/webgpu-buffer.ts b/modules/webgpu/src/adapter/resources/webgpu-buffer.ts index 8ce5f0c043..0dd483db2f 100644 --- a/modules/webgpu/src/adapter/resources/webgpu-buffer.ts +++ b/modules/webgpu/src/adapter/resources/webgpu-buffer.ts @@ -21,13 +21,15 @@ export class WebGPUBuffer extends Buffer { // WebGPU buffers must be aligned to 4 bytes const size = Math.ceil(this.byteLength / 4) * 4; - this.handle = this.props.handle || this.device.handle.createBuffer({ - size, - // usage defaults to vertex - usage: this.props.usage || (GPUBufferUsage.VERTEX | GPUBufferUsage.COPY_DST), - mappedAtCreation: this.props.mappedAtCreation || mapBuffer, - label: this.props.id - }); + this.handle = + this.props.handle || + this.device.handle.createBuffer({ + size, + // usage defaults to vertex + usage: this.props.usage || GPUBufferUsage.VERTEX | GPUBufferUsage.COPY_DST, + mappedAtCreation: this.props.mappedAtCreation || mapBuffer, + label: this.props.id + }); if (props.data) { this._writeMapped(props.data); @@ -54,9 +56,15 @@ export class WebGPUBuffer extends Buffer { ); } - override async readAsync(byteOffset: number = 0, byteLength: number = this.byteLength): Promise { + override async readAsync( + byteOffset: number = 0, + byteLength: number = this.byteLength + ): Promise { // We need MAP_READ flag, but only COPY_DST buffers can have MAP_READ flag, so we need to create a temp buffer - const tempBuffer = new WebGPUBuffer(this.device, {usage: Buffer.MAP_READ | Buffer.COPY_DST, byteLength}); + const tempBuffer = new WebGPUBuffer(this.device, { + usage: Buffer.MAP_READ | Buffer.COPY_DST, + byteLength + }); // Now do a GPU-side copy into the temp buffer we can actually read. // TODO - we are spinning up an independent command queue here, what does this mean diff --git a/modules/webgpu/src/adapter/resources/webgpu-compute-pass.ts b/modules/webgpu/src/adapter/resources/webgpu-compute-pass.ts index 3573b05b12..5bacb55d79 100644 --- a/modules/webgpu/src/adapter/resources/webgpu-compute-pass.ts +++ b/modules/webgpu/src/adapter/resources/webgpu-compute-pass.ts @@ -13,10 +13,12 @@ export class WebGPUComputePass extends ComputePass { super(device, props); this.device = device; - this.handle = this.props.handle || device.commandEncoder?.beginComputePass({ - label: this.props.id, - // timestampWrites?: GPUComputePassTimestampWrites; - }); + this.handle = + this.props.handle || + device.commandEncoder?.beginComputePass({ + label: this.props.id + // timestampWrites?: GPUComputePassTimestampWrites; + }); } /** @note no WebGPU destroy method, just gc */ diff --git a/modules/webgpu/src/adapter/resources/webgpu-compute-pipeline.ts b/modules/webgpu/src/adapter/resources/webgpu-compute-pipeline.ts index 1f7a8c66d1..bac1e5d060 100644 --- a/modules/webgpu/src/adapter/resources/webgpu-compute-pipeline.ts +++ b/modules/webgpu/src/adapter/resources/webgpu-compute-pipeline.ts @@ -16,15 +16,17 @@ export class WebGPUComputePipeline extends ComputePipeline { this.device = device; const webgpuShader = this.props.cs as WebGPUShader; - this.handle = this.props.handle || this.device.handle.createComputePipeline({ - label: this.props.id, - compute: { - module: webgpuShader.handle, - entryPoint: this.props.csEntryPoint, - // constants: this.props.csConstants - }, - layout: 'auto' - }); + this.handle = + this.props.handle || + this.device.handle.createComputePipeline({ + label: this.props.id, + compute: { + module: webgpuShader.handle, + entryPoint: this.props.csEntryPoint + // constants: this.props.csConstants + }, + layout: 'auto' + }); } /** For internal use in render passes */ diff --git a/modules/webgpu/src/adapter/resources/webgpu-external-texture.ts b/modules/webgpu/src/adapter/resources/webgpu-external-texture.ts index 4c56524321..d7b1e983df 100644 --- a/modules/webgpu/src/adapter/resources/webgpu-external-texture.ts +++ b/modules/webgpu/src/adapter/resources/webgpu-external-texture.ts @@ -15,10 +15,12 @@ export class WebGPUExternalTexture extends ExternalTexture { constructor(device: WebGPUDevice, props: ExternalTextureProps) { super(device, props); this.device = device; - this.handle = this.props.handle || this.device.handle.importExternalTexture({ - source: props.source, - colorSpace: props.colorSpace - }); + this.handle = + this.props.handle || + this.device.handle.importExternalTexture({ + source: props.source, + colorSpace: props.colorSpace + }); this.sampler = null; } @@ -31,7 +33,8 @@ export class WebGPUExternalTexture extends ExternalTexture { /** Set default sampler */ setSampler(sampler: Sampler | SamplerProps): this { // We can accept a sampler instance or set of props; - this.sampler = sampler instanceof WebGPUSampler ? sampler : new WebGPUSampler(this.device, sampler); + this.sampler = + sampler instanceof WebGPUSampler ? sampler : new WebGPUSampler(this.device, sampler); return this; } } diff --git a/modules/webgpu/src/adapter/resources/webgpu-query.ts b/modules/webgpu/src/adapter/resources/webgpu-query.ts index 658ca3adf9..f4a00f4589 100644 --- a/modules/webgpu/src/adapter/resources/webgpu-query.ts +++ b/modules/webgpu/src/adapter/resources/webgpu-query.ts @@ -40,4 +40,4 @@ class WebGPUQuery extends Resource implements Query { this.handle.destroy(); } } -*/ \ No newline at end of file +*/ diff --git a/modules/webgpu/src/adapter/resources/webgpu-render-pass.ts b/modules/webgpu/src/adapter/resources/webgpu-render-pass.ts index 8f7ea67d88..1541b17a58 100644 --- a/modules/webgpu/src/adapter/resources/webgpu-render-pass.ts +++ b/modules/webgpu/src/adapter/resources/webgpu-render-pass.ts @@ -16,7 +16,7 @@ export class WebGPURenderPass extends RenderPass { constructor(device: WebGPUDevice, props: RenderPassProps = {}) { super(device, props); this.device = device; - const framebuffer = props.framebuffer || device.canvasContext.getCurrentFramebuffer() ; + const framebuffer = props.framebuffer || device.canvasContext.getCurrentFramebuffer(); const renderPassDescriptor = this.getRenderPassDescriptor(framebuffer); log.groupCollapsed(3, `new WebGPURenderPass(${this.id})`)(); log.probe(3, JSON.stringify(renderPassDescriptor, null, 2))(); @@ -134,9 +134,9 @@ export class WebGPURenderPass extends RenderPass { // INTERNAL - /** + /** * Partial render pass descriptor. Used by WebGPURenderPass. - * @returns attachments fields of a renderpass descriptor. + * @returns attachments fields of a renderpass descriptor. */ protected getRenderPassDescriptor(framebuffer: Framebuffer): GPURenderPassDescriptor { const renderPassDescriptor: GPURenderPassDescriptor = { @@ -147,7 +147,7 @@ export class WebGPURenderPass extends RenderPass { // clear values loadOp: this.props.clearColor !== false ? 'clear' : 'load', colorClearValue: this.props.clearColor || [0, 0, 0, 0], - storeOp: this.props.discard? 'discard': 'store', + storeOp: this.props.discard ? 'discard' : 'store', // ...colorAttachment, view: (colorAttachment as WebGPUTextureView).handle })); diff --git a/modules/webgpu/src/adapter/resources/webgpu-render-pipeline.ts b/modules/webgpu/src/adapter/resources/webgpu-render-pipeline.ts index ead30db806..a490eeb892 100644 --- a/modules/webgpu/src/adapter/resources/webgpu-render-pipeline.ts +++ b/modules/webgpu/src/adapter/resources/webgpu-render-pipeline.ts @@ -43,7 +43,7 @@ export class WebGPURenderPipeline extends RenderPipeline { log.groupCollapsed(1, `new WebGPURenderPipeline(${this.id})`)(); log.probe(1, JSON.stringify(descriptor, null, 2))(); log.groupEnd(1)(); - this.handle = this.device.handle.createRenderPipeline(descriptor); + this.handle = this.device.handle.createRenderPipeline(descriptor); } this.handle.label = this.props.id; @@ -113,7 +113,6 @@ export class WebGPURenderPipeline extends RenderPipeline { webgpuRenderPass.handle.setBindGroup(0, bindGroup); } - // Set attributes // Note: Rebinds constant attributes before each draw call options.vertexArray.bindBeforeRender(options.renderPass); @@ -149,18 +148,20 @@ export class WebGPURenderPipeline extends RenderPipeline { this._bindGroupLayout = this._bindGroupLayout || this.handle.getBindGroupLayout(0); // Set up the bindings - this._bindGroup = this._bindGroup || getBindGroup( - this.device.handle, - this._bindGroupLayout, - this.props.shaderLayout, - this.props.bindings - ); + this._bindGroup = + this._bindGroup || + getBindGroup( + this.device.handle, + this._bindGroupLayout, + this.props.shaderLayout, + this.props.bindings + ); return this._bindGroup; } - /** - * Populate the complex WebGPU GPURenderPipelineDescriptor + /** + * Populate the complex WebGPU GPURenderPipelineDescriptor */ protected _getRenderPipelineDescriptor() { // Set up the vertex stage diff --git a/modules/webgpu/src/adapter/resources/webgpu-sampler.ts b/modules/webgpu/src/adapter/resources/webgpu-sampler.ts index fcd90c2421..444d72a1cd 100644 --- a/modules/webgpu/src/adapter/resources/webgpu-sampler.ts +++ b/modules/webgpu/src/adapter/resources/webgpu-sampler.ts @@ -3,7 +3,7 @@ import type {WebGPUDevice} from '../webgpu-device'; export type WebGPUSamplerProps = SamplerProps & { handle?: GPUSampler; -} +}; /** * diff --git a/modules/webgpu/src/adapter/resources/webgpu-shader.ts b/modules/webgpu/src/adapter/resources/webgpu-shader.ts index ecfecdd2dd..413958d6fa 100644 --- a/modules/webgpu/src/adapter/resources/webgpu-shader.ts +++ b/modules/webgpu/src/adapter/resources/webgpu-shader.ts @@ -29,7 +29,7 @@ export class WebGPUShader extends Shader { } async _checkCompilationError(errorScope: Promise): Promise { - const error = await errorScope as GPUValidationError; + const error = (await errorScope) as GPUValidationError; if (error) { // The `Shader` base class will determine if debug window should be opened based on props this.debugShader(); @@ -65,14 +65,14 @@ export class WebGPUShader extends Shader { language = source.includes('->') ? 'wgsl' : 'glsl'; } - switch(language) { + switch (language) { case 'wgsl': return this.device.handle.createShaderModule({code: source}); case 'glsl': return this.device.handle.createShaderModule({ code: source, // @ts-expect-error - transform: (glsl) => this.device.glslang.compileGLSL(glsl, stage) + transform: glsl => this.device.glslang.compileGLSL(glsl, stage) }); default: throw new Error(language); diff --git a/modules/webgpu/src/adapter/resources/webgpu-texture-view.ts b/modules/webgpu/src/adapter/resources/webgpu-texture-view.ts index c870714d06..b68e1e639f 100644 --- a/modules/webgpu/src/adapter/resources/webgpu-texture-view.ts +++ b/modules/webgpu/src/adapter/resources/webgpu-texture-view.ts @@ -7,10 +7,10 @@ import type {WebGPUTexture} from './webgpu-texture'; export type WebGPUTextureViewProps = TextureViewProps & { handle?: GPUTextureView; -} +}; /** - * + * */ export class WebGPUTextureView extends TextureView { readonly device: WebGPUDevice; @@ -22,15 +22,17 @@ export class WebGPUTextureView extends TextureView { this.device = device; this.texture = props.texture; - this.handle = this.handle || this.texture.handle.createView({ - format: (props.format || this.texture.format) as GPUTextureFormat, - dimension: props.dimension || this.texture.dimension, - aspect: props.aspect, - baseMipLevel: props.baseMipLevel, - mipLevelCount: props.mipLevelCount, // GPUIntegerCoordinate; - baseArrayLayer: props.baseArrayLayer, // GPUIntegerCoordinate; - arrayLayerCount: props.arrayLayerCount, // GPUIntegerCoordinate; - }); + this.handle = + this.handle || + this.texture.handle.createView({ + format: (props.format || this.texture.format) as GPUTextureFormat, + dimension: props.dimension || this.texture.dimension, + aspect: props.aspect, + baseMipLevel: props.baseMipLevel, + mipLevelCount: props.mipLevelCount, // GPUIntegerCoordinate; + baseArrayLayer: props.baseArrayLayer, // GPUIntegerCoordinate; + arrayLayerCount: props.arrayLayerCount // GPUIntegerCoordinate; + }); this.handle.label = this.props.id; } diff --git a/modules/webgpu/src/adapter/resources/webgpu-texture.ts b/modules/webgpu/src/adapter/resources/webgpu-texture.ts index 292b6ff7b4..7f442da612 100644 --- a/modules/webgpu/src/adapter/resources/webgpu-texture.ts +++ b/modules/webgpu/src/adapter/resources/webgpu-texture.ts @@ -9,7 +9,7 @@ const BASE_DIMENSIONS: Record = { '1d': '1d', '2d': '2d', '2d-array': '2d', - 'cube': '2d', + cube: '2d', 'cube-array': '2d', '3d': '3d' }; @@ -69,7 +69,10 @@ export class WebGPUTexture extends Texture { // Create a default sampler. This mimics the WebGL1 API where sampler props are stored on the texture // this.setSampler(props.sampler); - this.sampler = props.sampler instanceof WebGPUSampler ? props.sampler : new WebGPUSampler(this.device, props.sampler); + this.sampler = + props.sampler instanceof WebGPUSampler + ? props.sampler + : new WebGPUSampler(this.device, props.sampler); // TODO - To support texture arrays we need to create custom views... // But we are not ready to expose TextureViews to the public API. @@ -116,13 +119,12 @@ export class WebGPUTexture extends Texture { * Accept a sampler instance or set of props; */ setSampler(sampler: Sampler | SamplerProps): this { - this.sampler = sampler instanceof WebGPUSampler ? sampler : new WebGPUSampler(this.device, sampler); + this.sampler = + sampler instanceof WebGPUSampler ? sampler : new WebGPUSampler(this.device, sampler); return this; } - setData(options: { - data: any; - }) { + setData(options: {data: any}) { return this.setImage({source: options.data}); } @@ -141,7 +143,7 @@ export class WebGPUTexture extends Texture { aspect?: 'all' | 'stencil-only' | 'depth-only'; colorSpace?: 'srgb'; premultipliedAlpha?: boolean; - }): {width: number, height: number} { + }): {width: number; height: number} { const { source, width = options.source.width, @@ -176,22 +178,18 @@ export class WebGPUTexture extends Texture { premultipliedAlpha }, // copySize: GPUExtent3D - [ - width, - height, - depth - ] + [width, height, depth] ); return {width, height}; } - // WebGPU specific - + // WebGPU specific + /** TODO - intention is to expose TextureViews in the public API */ createView(): GPUTextureView { return this.handle.createView({label: this.id}); } - + /* async readPixels() { const readbackBuffer = device.createBuffer({ diff --git a/modules/webgpu/src/adapter/resources/webgpu-vertex-array.ts b/modules/webgpu/src/adapter/resources/webgpu-vertex-array.ts index 3897bbcd8c..5d3155d023 100644 --- a/modules/webgpu/src/adapter/resources/webgpu-vertex-array.ts +++ b/modules/webgpu/src/adapter/resources/webgpu-vertex-array.ts @@ -30,7 +30,7 @@ export class WebGPUVertexArray extends VertexArray { /** * Set an elements buffer, for indexed rendering. - * Must be a Buffer bound to buffer with usage bit Buffer.INDEX set. + * Must be a Buffer bound to buffer with usage bit Buffer.INDEX set. */ setIndexBuffer(buffer: Buffer | null): void { // assert(!elementBuffer || elementBuffer.glTarget === GL.ELEMENT_ARRAY_BUFFER, ERR_ELEMENTS); @@ -47,18 +47,25 @@ export class WebGPUVertexArray extends VertexArray { this.attributes[bufferSlot] = buffer; } - override bindBeforeRender(renderPass: RenderPass, firstIndex?: number, indexCount?: number): void { + override bindBeforeRender( + renderPass: RenderPass, + firstIndex?: number, + indexCount?: number + ): void { const webgpuRenderPass = renderPass as WebGPURenderPass; const webgpuIndexBuffer = this.indexBuffer as WebGPUBuffer; if (webgpuIndexBuffer?.handle) { // Note we can't unset an index buffer log.warn('setting index buffer', webgpuIndexBuffer?.handle, webgpuIndexBuffer?.indexType)(); - webgpuRenderPass.handle.setIndexBuffer(webgpuIndexBuffer?.handle, webgpuIndexBuffer?.indexType); + webgpuRenderPass.handle.setIndexBuffer( + webgpuIndexBuffer?.handle, + webgpuIndexBuffer?.indexType + ); } for (let location = 0; location < this.maxVertexAttributes; location++) { const webgpuBuffer = this.attributes[location] as WebGPUBuffer; if (webgpuBuffer?.handle) { - log.warn(`setting vertex buffer ${location}`,webgpuBuffer?.handle)(); + log.warn(`setting vertex buffer ${location}`, webgpuBuffer?.handle)(); webgpuRenderPass.handle.setVertexBuffer(location, webgpuBuffer?.handle); } } @@ -66,19 +73,18 @@ export class WebGPUVertexArray extends VertexArray { } override unbindAfterRender(renderPass: RenderPass): void { - // On WebGPU we don't need to unbind. + // On WebGPU we don't need to unbind. // In fact we can't easily do it. setIndexBuffer/setVertexBuffer don't accept null. // Unbinding presumably happens automatically when the render pass is ended. } // DEPRECATED METHODS - /** - * @deprecated is this even an issue for WebGPU? - * Attribute 0 can not be disable on most desktop OpenGL based browsers + /** + * @deprecated is this even an issue for WebGPU? + * Attribute 0 can not be disable on most desktop OpenGL based browsers */ static isConstantAttributeZeroSupported(device: Device): boolean { return getBrowser() === 'Chrome'; } - } diff --git a/modules/webgpu/src/adapter/webgpu-canvas-context.ts b/modules/webgpu/src/adapter/webgpu-canvas-context.ts index ab550516ea..bd40d175c3 100644 --- a/modules/webgpu/src/adapter/webgpu-canvas-context.ts +++ b/modules/webgpu/src/adapter/webgpu-canvas-context.ts @@ -6,7 +6,7 @@ import {WebGPUDevice} from './webgpu-device'; import {WebGPUFramebuffer} from './resources/webgpu-framebuffer'; import {WebGPUTexture} from './resources/webgpu-texture'; -/** +/** * Holds a WebGPU Canvas Context * The primary job of the CanvasContext is to generate textures for rendering into the current canvas * It also manages canvas sizing calculations and resizing. @@ -55,7 +55,7 @@ export class WebGPUCanvasContext extends CanvasContext { // height: this.height // }); - // Wrap the current canvas context texture in a luma.gl texture + // Wrap the current canvas context texture in a luma.gl texture const currentColorAttachment = this.getCurrentTexture(); this.width = currentColorAttachment.width; this.height = currentColorAttachment.height; diff --git a/modules/webgpu/src/adapter/webgpu-device.ts b/modules/webgpu/src/adapter/webgpu-device.ts index aee9f011ce..6df27a1bfb 100644 --- a/modules/webgpu/src/adapter/webgpu-device.ts +++ b/modules/webgpu/src/adapter/webgpu-device.ts @@ -50,7 +50,7 @@ export class WebGPUDevice extends Device { /* The underlying WebGPU adapter */ readonly adapter: GPUAdapter; /* The underlying WebGPU adapter's info */ - readonly adapterInfo: GPUAdapterInfo + readonly adapterInfo: GPUAdapterInfo; readonly features: DeviceFeatures; readonly info: DeviceInfo; @@ -100,13 +100,21 @@ export class WebGPUDevice extends Device { const device = new WebGPUDevice(gpuDevice, adapter, adapterInfo, props); - log.probe(1, 'Device created. For more info, set chrome://flags/#enable-webgpu-developer-features')(); + log.probe( + 1, + 'Device created. For more info, set chrome://flags/#enable-webgpu-developer-features' + )(); log.table(1, device.info)(); log.groupEnd(1)(); return device; } - constructor(device: GPUDevice, adapter: GPUAdapter, adapterInfo: GPUAdapterInfo, props: DeviceProps) { + constructor( + device: GPUDevice, + adapter: GPUAdapter, + adapterInfo: GPUAdapterInfo, + props: DeviceProps + ) { super({...props, id: props.id || uid('webgpu-device')}); this.handle = device; this.adapter = adapter; @@ -265,14 +273,14 @@ export class WebGPUDevice extends Device { const gpu = vendor === 'apple' ? 'apple' : 'unknown'; // 'nvidia' | 'amd' | 'intel' | 'apple' | 'unknown', const gpuArchitecture = this.adapterInfo.architecture || 'unknown'; const gpuBackend = (this.adapterInfo as any).backend || 'unknown'; - const gpuType = ((this.adapterInfo as any).type || '').split(' ')[0].toLowerCase() || 'unknown' + const gpuType = ((this.adapterInfo as any).type || '').split(' ')[0].toLowerCase() || 'unknown'; return { type: 'webgpu', vendor, renderer, version, - gpu, + gpu, gpuType, gpuBackend, gpuArchitecture, diff --git a/modules/webgpu/src/glsl/glsllang.ts b/modules/webgpu/src/glsl/glsllang.ts index d5594ddcc1..09ed2caf5d 100644 --- a/modules/webgpu/src/glsl/glsllang.ts +++ b/modules/webgpu/src/glsl/glsllang.ts @@ -7,7 +7,9 @@ let glslang: unknown; export async function loadGlslangModule() { if (!glslang) { // @ts-ignore - const glslangModule = await import(/* webpackIgnore: true */ 'https://unpkg.com/@webgpu/glslang@0.0.15/dist/web-devel/glslang.js'); + const glslangModule = await import( + /* webpackIgnore: true */ 'https://unpkg.com/@webgpu/glslang@0.0.15/dist/web-devel/glslang.js' + ); glslang = await glslangModule.default(); } return glslang; diff --git a/modules/webgpu/test/adapter/helpers/get-vertex-buffer-layout.spec.ts b/modules/webgpu/test/adapter/helpers/get-vertex-buffer-layout.spec.ts index 476c0a1569..32ba7f36a3 100644 --- a/modules/webgpu/test/adapter/helpers/get-vertex-buffer-layout.spec.ts +++ b/modules/webgpu/test/adapter/helpers/get-vertex-buffer-layout.spec.ts @@ -13,48 +13,49 @@ const shaderLayout: ShaderLayout = { // We want to use "non-standard" buffers: two attributes interleaved in same buffer const bufferLayout = [ - {name: 'particles', attributes: [ - {name: 'instancePositions'}, - {name: 'instanceVelocities'} - ]} + {name: 'particles', attributes: [{name: 'instancePositions'}, {name: 'instanceVelocities'}]} ]; -const TEST_CASES: {shaderLayout: ShaderLayout, bufferLayout, vertexBufferLayout: GPUVertexBufferLayout[]}[] = [ +const TEST_CASES: { + shaderLayout: ShaderLayout; + bufferLayout; + vertexBufferLayout: GPUVertexBufferLayout[]; +}[] = [ { shaderLayout, bufferLayout: [], vertexBufferLayout: [ { - 'stepMode': 'instance', - 'arrayStride': 8, - 'attributes': [ + stepMode: 'instance', + arrayStride: 8, + attributes: [ { - 'format': 'float32x2', - 'offset': 0, - 'shaderLocation': 0 + format: 'float32x2', + offset: 0, + shaderLocation: 0 } ] }, { - 'stepMode': 'instance', - 'arrayStride': 8, - 'attributes': [ + stepMode: 'instance', + arrayStride: 8, + attributes: [ { - 'format': 'float32x2', - 'offset': 0, - 'shaderLocation': 1 + format: 'float32x2', + offset: 0, + shaderLocation: 1 } ] }, { - 'stepMode': 'vertex', - 'arrayStride': 8, - 'attributes': [ + stepMode: 'vertex', + arrayStride: 8, + attributes: [ { - 'format': 'float32x2', - 'offset': 0, - 'shaderLocation': 2 + format: 'float32x2', + offset: 0, + shaderLocation: 2 } ] } @@ -66,29 +67,29 @@ const TEST_CASES: {shaderLayout: ShaderLayout, bufferLayout, vertexBufferLayout: vertexBufferLayout: [ { - 'stepMode': 'instance', - 'arrayStride': 16, - 'attributes': [ + stepMode: 'instance', + arrayStride: 16, + attributes: [ { - 'format': 'float32x2', - 'offset': 0, - 'shaderLocation': 0 + format: 'float32x2', + offset: 0, + shaderLocation: 0 }, { - 'format': 'float32x2', - 'offset': 8, - 'shaderLocation': 1 + format: 'float32x2', + offset: 8, + shaderLocation: 1 } ] }, { - 'stepMode': 'vertex', - 'arrayStride': 8, - 'attributes': [ + stepMode: 'vertex', + arrayStride: 8, + attributes: [ { - 'format': 'float32x2', - 'offset': 0, - 'shaderLocation': 2 + format: 'float32x2', + offset: 0, + shaderLocation: 2 } ] } diff --git a/test/apps/pbr/controls.js b/test/apps/pbr/controls.js index 0a97c1a57b..6cd15468cd 100644 --- a/test/apps/pbr/controls.js +++ b/test/apps/pbr/controls.js @@ -3,10 +3,10 @@ class Controls { constructor(canvas, redraw) { // Set control callbacks - canvas.onmousedown = (ev) => this._handleMouseDown(ev); - document.onmouseup = (ev) => this._handleMouseUp(ev); - document.onmousemove = (ev) => this._handleMouseMove(ev, redraw); - document.onwheel = (ev) => this._handleWheel(ev, redraw); + canvas.onmousedown = ev => this._handleMouseDown(ev); + document.onmouseup = ev => this._handleMouseUp(ev); + document.onmousemove = ev => this._handleMouseMove(ev, redraw); + document.onwheel = ev => this._handleWheel(ev, redraw); this.lastMouseX = null; this.lastMouseY = null; diff --git a/test/apps/pbr/main.js b/test/apps/pbr/main.js index 9e852a43cb..88a63d4562 100644 --- a/test/apps/pbr/main.js +++ b/test/apps/pbr/main.js @@ -182,7 +182,7 @@ function updateModel(value, gl, glState, viewMatrix, projectionMatrix, backBuffe error: (jqXhr, textStatus, errorThrown) => { error.innerHTML += `Failed to load model: ${errorThrown}
`; }, - success: (gltf) => { + success: gltf => { const scene = new Scene(gl, glState, `${BASE_URL}/models/${value}/glTF/`, gltf); scene.projectionMatrix = projectionMatrix; scene.viewMatrix = viewMatrix; @@ -262,7 +262,7 @@ function setupGUI(gl, viewMatrix, canvas, ctx2d) { const folder = gui.addFolder('Metallic-Roughness Material'); const text = {Model: DEFAULT_MODEL_NAME}; - folder.add(text, 'Model', MODELS).onChange((value) => { + folder.add(text, 'Model', MODELS).onChange(value => { updateModel(value, gl, glState, viewMatrix, projectionMatrix, canvas, ctx2d); }); folder.open(); @@ -299,7 +299,7 @@ function setupGUI(gl, viewMatrix, canvas, ctx2d) { updateMathScales(); - $(glState.canvas2d).mousemove((e) => pickPixel(e.pageX, e.pageY)); + $(glState.canvas2d).mousemove(e => pickPixel(e.pageX, e.pageY)); } // picker @@ -378,11 +378,11 @@ function createMouseOverScale() { const localArgs = arguments; const el = $(localArgs[0]); el.hover( - (ev) => setActiveComponent(el), - (ev) => setActiveComponent(null) + ev => setActiveComponent(el), + ev => setActiveComponent(null) ); - el.click((ev) => { + el.click(ev => { if (scaleVals.pinnedElement) { setPinnedComponent(null); } else { diff --git a/test/apps/pbr/scene.js b/test/apps/pbr/scene.js index f5d33e2837..64359a792a 100644 --- a/test/apps/pbr/scene.js +++ b/test/apps/pbr/scene.js @@ -60,7 +60,7 @@ class Scene { loadImage(imageInfo, gl) { this.pendingTextures++; - loadImage(imageInfo.uri).then((image) => { + loadImage(imageInfo.uri).then(image => { const lumatexture = new Texture2D(gl, { // gl.TEXTUREn enums are in numeric order. textureUnit: imageInfo.samplerIndex, // gl.TEXTURE0 + diff --git a/test/dev-modules/babel-plugin-inline-webgl-constants.spec.js b/test/dev-modules/babel-plugin-inline-webgl-constants.spec.js index de738bac90..762f6e350e 100644 --- a/test/dev-modules/babel-plugin-inline-webgl-constants.spec.js +++ b/test/dev-modules/babel-plugin-inline-webgl-constants.spec.js @@ -62,8 +62,8 @@ function clean(code) { return code.replace('"use strict";', '').replace(/\n\s+/g, '\n').trim(); } -test('InlineGLSLConstants Babel Plugin', (t) => { - TEST_CASES.forEach((testCase) => { +test('InlineGLSLConstants Babel Plugin', t => { + TEST_CASES.forEach(testCase => { const transform = () => babel.transform(testCase.input, { presets: [['@babel/env', ES6_ENV]], diff --git a/test/dev-modules/babel-plugin-remove-glsl-comments.spec.js b/test/dev-modules/babel-plugin-remove-glsl-comments.spec.js index 9de3f5c364..b162082d01 100644 --- a/test/dev-modules/babel-plugin-remove-glsl-comments.spec.js +++ b/test/dev-modules/babel-plugin-remove-glsl-comments.spec.js @@ -110,8 +110,8 @@ function clean(code) { } // TODO - RESTORE -test.skip('RemoveGLSLComments Babel Plugin', (t) => { - TEST_CASES.forEach((testCase) => { +test.skip('RemoveGLSLComments Babel Plugin', t => { + TEST_CASES.forEach(testCase => { const {code} = babel.transform(testCase.input, { comments: true, presets: [['@babel/env', testCase.env]], diff --git a/test/dev-modules/eslint-plugin-luma-gl-custom-rules.spec.js b/test/dev-modules/eslint-plugin-luma-gl-custom-rules.spec.js index 9e6d2459d9..702ff4701f 100644 --- a/test/dev-modules/eslint-plugin-luma-gl-custom-rules.spec.js +++ b/test/dev-modules/eslint-plugin-luma-gl-custom-rules.spec.js @@ -6,7 +6,7 @@ const ruleTester = new RuleTester(); const {rules} = customRulesPlugin; // TODO - RESTORE -test.skip('EslintCustomRules#check-log-call', (t) => { +test.skip('EslintCustomRules#check-log-call', t => { ruleTester.run('check-log-call', rules['check-log-call'], { valid: ['log.log(1, "initialized")();', 'log.assert(gl, "error");', 'someObject.method();'], invalid: [ diff --git a/test/perf/index.js b/test/perf/index.js index b647daecd3..9959212d8b 100644 --- a/test/perf/index.js +++ b/test/perf/index.js @@ -7,7 +7,7 @@ const {_enableDOMLogging} = require('@probe.gl/test-utils'); const PERF_TEST_CASES = require('./performance-test-cases').default; _enableDOMLogging({ - getStyle: (message) => ({ + getStyle: message => ({ background: '#fff', position: 'absolute', top: 0 @@ -25,7 +25,7 @@ new PerformanceTestRunner({ .run({ timeout: 5000, maxFramesToRender: 120, - onTestStart: (testCase) => console.log(testCase.name), + onTestStart: testCase => console.log(testCase.name), onTestPass: (testCase, result) => console.log(`perf: ${result.framesRendered} frames at ${result.fps} fps`), onTestFail: (testCase, result) => diff --git a/test/perf/performance-test-cases.js b/test/perf/performance-test-cases.js index d357797c0b..226339af95 100644 --- a/test/perf/performance-test-cases.js +++ b/test/perf/performance-test-cases.js @@ -12,7 +12,7 @@ export default examples.map(({name, animationLoop, targetFPS}) => { return { name, onInitialize: animationLoop.onInitialize.bind(animationLoop), - onRender: (params) => { + onRender: params => { // disable picking in the example params._mousePosition = 0; animationLoop.onRender(params); diff --git a/test/render/example-test-cases.ts b/test/render/example-test-cases.ts index 0d70794bc4..5a74066601 100644 --- a/test/render/example-test-cases.ts +++ b/test/render/example-test-cases.ts @@ -1,4 +1,4 @@ -// luma.gl, MIT license +// luma.gl, MIT license import type {SnapshotTestRunnerTestCase} from '@luma.gl/test-utils'; import {AnimationLoopTemplate, AnimationProps} from '@luma.gl/engine'; @@ -35,7 +35,7 @@ const examples = { helloTriangle, helloInstancing, shaderModules, - shaderHooks, + shaderHooks // transformFeedback, // API @@ -56,14 +56,14 @@ const examples = { /** * Wraps the imported AnimationLoopTemplates from the examples into SnapshotTestRunner test cases * We don't start the loops but manually trigger their lifecycle methods - * + * * @returns a list of test cases for the SnapshotTestRunner */ function getTestCases(): SnapshotTestRunnerTestCase[] { const testCases: SnapshotTestRunnerTestCase[] = []; for (const [name, ExampleAnimationLoopTemplate] of Object.entries(examples)) { - let animationLoopTemplate: AnimationLoopTemplate | null = null; + let animationLoopTemplate: AnimationLoopTemplate | null = null; testCases.push({ name, diff --git a/test/render/render.spec.ts b/test/render/render.spec.ts index 0806836354..2f00013979 100644 --- a/test/render/render.spec.ts +++ b/test/render/render.spec.ts @@ -9,7 +9,7 @@ import EXAMPLE_TEST_CASES from './example-test-cases'; const renderTestCaseCount = EXAMPLE_TEST_CASES.length; // + GLTF_TEST_CASES.length; -test('RenderTest', (t) => { +test('RenderTest', t => { // tape's default timeout is 500ms t.timeoutAfter(renderTestCaseCount * 4000); @@ -17,7 +17,7 @@ test('RenderTest', (t) => { .add(EXAMPLE_TEST_CASES) // .add(GLTF_TEST_CASES) .run({ - onTestStart: (testCase) => t.comment(testCase.name), + onTestStart: testCase => t.comment(testCase.name), onTestPass: (testCase, result) => t.pass(`match: ${result.matchPercentage}`), onTestFail: (testCase, result) => t.fail(result.error || `match: ${result.matchPercentage}`), From 9255ec432df5780ff131d766a32cb4958e86caf3 Mon Sep 17 00:00:00 2001 From: Ib Green Date: Mon, 26 Feb 2024 11:40:05 -0500 Subject: [PATCH 3/6] prettier --- modules/core/src/adapter/types/texture-formats.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/core/src/adapter/types/texture-formats.ts b/modules/core/src/adapter/types/texture-formats.ts index dd2a9b6970..aa0b0418b0 100644 --- a/modules/core/src/adapter/types/texture-formats.ts +++ b/modules/core/src/adapter/types/texture-formats.ts @@ -136,8 +136,8 @@ export type UnsizedColorTextureFormat = // 'r8unorm-unsized' | // 'ra8unorm-unsized' | 'rgb8unorm-unsized' | 'rgba8unorm-unsized'; - // 'rgb8unorm-srgb-unsized' | - // 'rgba8unorm-srgb-unsized' +// 'rgb8unorm-srgb-unsized' | +// 'rgba8unorm-srgb-unsized' /** Sized formats unique to WebGL 2. Some will perhaps be added to WebGPU standard? */ export type WebGL2ColorTextureFormat = From abbf3a07452cc59b275209476d582865b3f52356 Mon Sep 17 00:00:00 2001 From: Ib Green Date: Mon, 26 Feb 2024 11:43:27 -0500 Subject: [PATCH 4/6] fix --- modules/core/src/lib/luma.ts | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/modules/core/src/lib/luma.ts b/modules/core/src/lib/luma.ts index 3d30f5a0f9..5cd008b787 100644 --- a/modules/core/src/lib/luma.ts +++ b/modules/core/src/lib/luma.ts @@ -36,10 +36,13 @@ export class luma { } static getSupportedDevices(): string[] { - // @ts-expect-error - return Array.from(deviceList) - .filter(Device => Device.isSupported()) - .map(Device => Device.type); + return ( + Array.from(deviceList) + // @ts-expect-error + .filter(Device => Device.isSupported()) + // @ts-expect-error + .map(Device => Device.type) + ); } static setDefaultDeviceProps(props: DeviceProps): void { From 367a1c74a60dbbc39e3e1ca4bac07df2d5806a47 Mon Sep 17 00:00:00 2001 From: Ib Green Date: Mon, 26 Feb 2024 11:48:24 -0500 Subject: [PATCH 5/6] wip --- modules/engine/src/animation-loop/animation-loop.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/modules/engine/src/animation-loop/animation-loop.ts b/modules/engine/src/animation-loop/animation-loop.ts index 69516f3b98..c9760d986c 100644 --- a/modules/engine/src/animation-loop/animation-loop.ts +++ b/modules/engine/src/animation-loop/animation-loop.ts @@ -486,13 +486,16 @@ export class AnimationLoop { /** Default viewport setup */ _resizeViewport(): void { + // TODO can we use canvas context to code this in a portable way? // @ts-expect-error Expose on canvasContext if (this.props.autoResizeViewport && this.device.gl) { // @ts-expect-error Expose canvasContext this.device.gl.viewport( 0, 0, + // @ts-expect-error Expose canvasContext this.device.gl.drawingBufferWidth, + // @ts-expect-error Expose canvasContext this.device.gl.drawingBufferHeight ); } From 742be99d15011d9f5be50820b63101ec6a3f0a5e Mon Sep 17 00:00:00 2001 From: Ib Green Date: Mon, 26 Feb 2024 11:51:12 -0500 Subject: [PATCH 6/6] wip --- modules/webgpu/src/glsl/glsllang.ts | 16 ---------------- 1 file changed, 16 deletions(-) delete mode 100644 modules/webgpu/src/glsl/glsllang.ts diff --git a/modules/webgpu/src/glsl/glsllang.ts b/modules/webgpu/src/glsl/glsllang.ts deleted file mode 100644 index 09ed2caf5d..0000000000 --- a/modules/webgpu/src/glsl/glsllang.ts +++ /dev/null @@ -1,16 +0,0 @@ -// Inspired by webgpu samples at https://github.com/austinEng/webgpu-samples/blob/master/src/glslang.ts -// under BSD 3-clause license - -let glslang: unknown; - -/** Dynamically load the GLSL compiler */ -export async function loadGlslangModule() { - if (!glslang) { - // @ts-ignore - const glslangModule = await import( - /* webpackIgnore: true */ 'https://unpkg.com/@webgpu/glslang@0.0.15/dist/web-devel/glslang.js' - ); - glslang = await glslangModule.default(); - } - return glslang; -}
' + slider.label + ':
' + + slider.label + + ':
' + segmented.label + ':
'; for (var k = 0; k < segmented.labels.length; k++) { - html += '
' + segmented.labels[k] + '
'; + html += + '
' + + segmented.labels[k] + + '
'; } html += '