• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

visgl / luma.gl / 14683349798

26 Apr 2025 05:08PM UTC coverage: 74.055% (-0.9%) from 74.913%
14683349798

push

github

web-flow
feat(core): TextureFormat generics (#2377)

2019 of 2652 branches covered (76.13%)

Branch coverage included in aggregate %.

62 of 262 new or added lines in 15 files covered. (23.66%)

196 existing lines in 9 files now uncovered.

26575 of 35960 relevant lines covered (73.9%)

47.35 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

71.28
/modules/core/src/portable/uniform-block.ts
1
// luma.gl
1✔
2
// SPDX-License-Identifier: MIT
1✔
3
// Copyright (c) vis.gl contributors
1✔
4

1✔
5
import type {VariableShaderType} from '../shadertypes/data-types/shader-types';
1✔
6
import type {UniformValue} from '../adapter/types/uniforms';
1✔
7
import {
1✔
8
  ShaderLayout,
1✔
9
  UniformInfo,
1✔
10
  UniformBufferBindingLayout
1✔
11
} from '../adapter/types/shader-layout';
1✔
12
import {arrayEqual, arrayCopy} from '../utils/array-equal';
1✔
13

1✔
14
/**
1✔
15
 * A uniform block holds values of the of uniform values for one uniform block / buffer.
1✔
16
 * It also does some book keeping on what has changed, to minimize unnecessary writes to uniform buffers.
1✔
17
 */
1✔
18
export class UniformBlock<
1✔
19
  TUniforms extends Record<string, UniformValue> = Record<string, UniformValue>
1✔
20
> {
1✔
21
  name: string;
9✔
22

9✔
23
  uniforms: Record<keyof TUniforms, UniformValue> = {} as Record<keyof TUniforms, UniformValue>;
9✔
24
  modifiedUniforms: Record<keyof TUniforms, boolean> = {} as Record<keyof TUniforms, boolean>;
9✔
25
  modified: boolean = true;
9✔
26

9✔
27
  readonly bindingLayout: Record<string, UniformInfo> = {};
9✔
28
  needsRedraw: string | false = 'initialized';
9✔
29

9✔
30
  constructor(props?: {
9✔
31
    name?: string;
9✔
32
    shaderLayout?: ShaderLayout;
9✔
33
    uniformTypes?: Record<keyof TUniforms, Record<string, VariableShaderType>>;
9✔
34
  }) {
9✔
35
    this.name = props?.name || 'unnamed';
9!
36

9✔
37
    // TODO - Extract uniform layout from the shaderLayout object
9✔
38
    if (props?.name && props?.shaderLayout) {
9!
39
      const binding = props?.shaderLayout.bindings?.find(
×
40
        binding_ => binding_.type === 'uniform' && binding_.name === props?.name
×
41
      );
×
42
      if (!binding) {
×
43
        throw new Error(props?.name);
×
44
      }
×
45

×
46
      const uniformBlock = binding as UniformBufferBindingLayout;
×
47
      for (const uniform of uniformBlock.uniforms || []) {
×
48
        this.bindingLayout[uniform.name] = uniform;
×
49
      }
×
50
    }
×
51
  }
9✔
52

9✔
53
  /** Set a map of uniforms */
9✔
54
  setUniforms(uniforms: Partial<TUniforms>): void {
9✔
55
    for (const [key, value] of Object.entries(uniforms)) {
9✔
56
      this._setUniform(key, value);
51✔
57
      if (!this.needsRedraw) {
51!
58
        this.setNeedsRedraw(`${this.name}.${key}=${value}`);
×
59
      }
×
60
    }
51✔
61
  }
9✔
62

9✔
63
  setNeedsRedraw(reason: string): void {
9✔
64
    this.needsRedraw = this.needsRedraw || reason;
×
65
  }
×
66

9✔
67
  /** Returns all uniforms */
9✔
68
  getAllUniforms(): Record<string, UniformValue> {
9✔
UNCOV
69
    // @ts-expect-error
×
UNCOV
70
    this.modifiedUniforms = {};
×
UNCOV
71
    this.needsRedraw = false;
×
UNCOV
72
    return (this.uniforms || {}) as Record<string, UniformValue>;
×
UNCOV
73
  }
×
74

9✔
75
  /** Set a single uniform */
9✔
76
  private _setUniform(key: keyof TUniforms, value: UniformValue) {
9✔
77
    if (arrayEqual(this.uniforms[key], value)) {
51!
78
      return;
×
79
    }
×
80
    this.uniforms[key] = arrayCopy(value);
51✔
81
    this.modifiedUniforms[key] = true;
51✔
82
    this.modified = true;
51✔
83
  }
51✔
84
}
9✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc