modern-canvas 0.18.0 → 0.18.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -4,8 +4,6 @@ import type { WebGLRenderer } from './WebGLRenderer';
4
4
  import { StencilMode } from './const';
5
5
  import { GlSystem } from './system';
6
6
  export interface StencilState {
7
- stencilWriteMask?: number;
8
- stencilReadMask?: number;
9
7
  stencilFront?: {
10
8
  compare: 'always' | 'equal' | 'not-equal';
11
9
  passOp: 'increment-clamp' | 'decrement-clamp' | 'keep' | 'replace';
@@ -9,6 +9,8 @@ export interface GlUniform {
9
9
  size: number;
10
10
  isArray: boolean;
11
11
  value: any;
12
+ /** cached uniform location, looked up lazily on first upload (undefined = not yet resolved) */
13
+ location?: WebGLUniformLocation | null;
12
14
  }
13
15
  export interface GlProgramOptions {
14
16
  fragment: string;
@@ -1,4 +1,10 @@
1
1
  export declare class GlProgramData {
2
2
  native: WebGLProgram;
3
+ /**
4
+ * Per uniform-group last-synced `_dirtyId`, keyed by the group's uid.
5
+ * If a group's current `_dirtyId` differs from the value stored here, the
6
+ * group's data is (re)uploaded to this program.
7
+ */
8
+ uniformDirtyGroups: Record<number, number>;
3
9
  constructor(native: WebGLProgram);
4
10
  }
@@ -1,22 +1,42 @@
1
1
  import type { ShaderLike } from '../../shared';
2
2
  import type { WebGLRenderer } from '../WebGLRenderer';
3
3
  import type { GlProgram } from './GlProgram';
4
+ import { UniformGroup } from '../../shared/shader';
4
5
  import { GlSystem } from '../system';
5
6
  import { GlProgramData } from './GlProgramData';
6
7
  export declare class GlShaderSystem extends GlSystem {
7
8
  install(renderer: WebGLRenderer): void;
8
9
  readonly glProgramDatas: Map<number, GlProgramData>;
9
10
  currentProgram: GlProgram | null;
10
- uniforms: {
11
+ /**
12
+ * Global uniforms (projection/view) shared by every shader. Held as a
13
+ * UniformGroup so each program only re-uploads them when they actually change
14
+ * (tracked via the group's `_dirtyId`). Call {@link markGlobalUniformsDirty}
15
+ * after mutating `uniforms.projectionMatrix` / `uniforms.viewMatrix`.
16
+ */
17
+ readonly globalUniforms: UniformGroup<{
11
18
  projectionMatrix: Float32Array<ArrayBuffer>;
12
19
  viewMatrix: Float32Array<ArrayBuffer>;
20
+ }>;
21
+ /** Backwards-compatible accessor for the global uniform values. */
22
+ get uniforms(): {
23
+ projectionMatrix: Float32Array;
24
+ viewMatrix: Float32Array;
13
25
  };
26
+ /** Flag the global uniforms as changed so they are re-uploaded on next use. */
27
+ markGlobalUniformsDirty(): void;
14
28
  bind(source: ShaderLike | null): void;
15
29
  useProgram(glProgram: GlProgram | null): void;
16
30
  getGlProgramData(source: GlProgram): GlProgramData;
17
31
  protected _createGlProgramData(glProgram: GlProgram): GlProgramData;
18
32
  protected _createGlShader(source: string, target: number): WebGLShader;
19
33
  updateUniforms(source: ShaderLike): void;
34
+ /**
35
+ * Upload a shared uniform group to a program, skipping the work entirely when
36
+ * the group has not changed since it was last synced to this program.
37
+ */
38
+ updateUniformGroup(group: UniformGroup, glProgram: GlProgram): void;
39
+ protected _uploadUniforms(glProgram: GlProgram, glProgramData: GlProgramData, uniforms: Record<string, any>): void;
20
40
  reset(): void;
21
41
  destroy(): void;
22
42
  }
@@ -0,0 +1,34 @@
1
+ export interface UniformGroupOptions {
2
+ /**
3
+ * If true the group is treated as a Uniform Buffer Object (WebGL2 only). The
4
+ * whole group is uploaded as a single buffer instead of per-uniform calls.
5
+ */
6
+ ubo?: boolean;
7
+ /**
8
+ * If true the group is only re-uploaded to a program when its `_dirtyId`
9
+ * changes (you are responsible for calling `update()`); otherwise it is
10
+ * re-uploaded every time it is used.
11
+ */
12
+ isStatic?: boolean;
13
+ }
14
+ /**
15
+ * A named bag of uniform values shared across shaders, with a version counter
16
+ * (`_dirtyId`) so the renderer can skip re-uploading it when nothing changed.
17
+ *
18
+ * This is the unit the renderer tracks per program (see
19
+ * `GlShaderSystem.updateUniformGroup`): each program records the last `_dirtyId`
20
+ * it synced, and re-uploads only when the group's id moved on.
21
+ */
22
+ export declare class UniformGroup<T extends Record<string, any> = Record<string, any>> {
23
+ readonly isUniformGroup = true;
24
+ /** unique id used as the key for per-program dirty tracking */
25
+ readonly uid: number;
26
+ uniforms: T;
27
+ ubo: boolean;
28
+ isStatic: boolean;
29
+ /** bumped whenever the group's data changes; compared against per-program last-synced id */
30
+ _dirtyId: number;
31
+ constructor(uniforms: T, options?: UniformGroupOptions);
32
+ /** Flag the group's data as changed so it is re-uploaded on next use. */
33
+ update(): void;
34
+ }
@@ -1 +1,2 @@
1
1
  export * from './ShaderLike';
2
+ export * from './UniformGroup';