textmode.js 0.4.0 → 0.6.0-beta.1

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.
Files changed (105) hide show
  1. package/dist/textmode.esm.js +2868 -2164
  2. package/dist/textmode.esm.min.js +2863 -2159
  3. package/dist/textmode.umd.js +11 -8
  4. package/dist/textmode.umd.min.js +11 -8
  5. package/dist/types/Textmode.d.ts +13 -22
  6. package/dist/types/index.d.ts +8 -6
  7. package/dist/types/rendering/index.d.ts +3 -3
  8. package/dist/types/rendering/webgl/batching/DrawQueue.d.ts +89 -0
  9. package/dist/types/rendering/webgl/{VAOManager.d.ts → batching/GeometryAttributeCache.d.ts} +4 -4
  10. package/dist/types/rendering/webgl/batching/InstanceAttributeBinder.d.ts +87 -0
  11. package/dist/types/rendering/webgl/{InstanceBatch.d.ts → batching/InstanceBatch.d.ts} +25 -34
  12. package/dist/types/rendering/webgl/batching/InstanceBuffer.d.ts +78 -0
  13. package/dist/types/rendering/webgl/{InstanceData.d.ts → batching/InstanceData.d.ts} +11 -18
  14. package/dist/types/rendering/webgl/batching/InstanceWriter.d.ts +70 -0
  15. package/dist/types/rendering/webgl/{Framebuffer.d.ts → core/Framebuffer.d.ts} +37 -39
  16. package/dist/types/rendering/webgl/core/Renderer.d.ts +64 -0
  17. package/dist/types/rendering/webgl/{Shader.d.ts → core/Shader.d.ts} +2 -23
  18. package/dist/types/rendering/webgl/core/interfaces/IFramebuffer.d.ts +103 -0
  19. package/dist/types/rendering/webgl/core/interfaces/IRenderer.d.ts +210 -0
  20. package/dist/types/rendering/webgl/geometries/{Arc.d.ts → 2d/Arc.d.ts} +5 -4
  21. package/dist/types/rendering/webgl/geometries/{BezierCurve.d.ts → 2d/BezierCurve.d.ts} +5 -4
  22. package/dist/types/rendering/webgl/geometries/{Ellipse.d.ts → 2d/Ellipse.d.ts} +6 -5
  23. package/dist/types/rendering/webgl/geometries/{Line.d.ts → 2d/Line.d.ts} +5 -4
  24. package/dist/types/rendering/webgl/geometries/{Rectangle.d.ts → 2d/Rectangle.d.ts} +5 -4
  25. package/dist/types/rendering/webgl/geometries/{Triangle.d.ts → 2d/Triangle.d.ts} +5 -4
  26. package/dist/types/rendering/webgl/geometries/BaseGeometry.d.ts +30 -26
  27. package/dist/types/rendering/webgl/geometries/immediate/ImmediateQuad.d.ts +33 -0
  28. package/dist/types/rendering/webgl/geometries/index.d.ts +6 -6
  29. package/dist/types/rendering/webgl/geometries/utils/GeometryDescriptors.d.ts +31 -0
  30. package/dist/types/rendering/webgl/geometries/utils/GeometryGenerator.d.ts +16 -0
  31. package/dist/types/rendering/webgl/index.d.ts +15 -14
  32. package/dist/types/rendering/webgl/materials/Material.d.ts +26 -0
  33. package/dist/types/rendering/webgl/materials/MaterialManager.d.ts +63 -0
  34. package/dist/types/rendering/webgl/materials/index.d.ts +2 -0
  35. package/dist/types/rendering/webgl/pipeline/MaterialBatchPipeline.d.ts +63 -0
  36. package/dist/types/rendering/webgl/pipeline/index.d.ts +7 -0
  37. package/dist/types/rendering/webgl/state/RenderState.d.ts +143 -0
  38. package/dist/types/rendering/webgl/types/DrawCommand.d.ts +5 -3
  39. package/dist/types/rendering/webgl/types/GeometryTypes.d.ts +10 -10
  40. package/dist/types/rendering/webgl/types/RenderTypes.d.ts +1 -1
  41. package/dist/types/rendering/webgl/utils/GLUtils.d.ts +45 -0
  42. package/dist/types/rendering/webgl/utils/hash.d.ts +118 -0
  43. package/dist/types/textmode/AnimationController.d.ts +11 -21
  44. package/dist/types/textmode/Canvas.d.ts +10 -2
  45. package/dist/types/textmode/Grid.d.ts +2 -0
  46. package/dist/types/textmode/TextmodeColor.d.ts +57 -0
  47. package/dist/types/textmode/Textmodifier.d.ts +40 -212
  48. package/dist/types/textmode/interfaces/ITextmodifier.d.ts +272 -0
  49. package/dist/types/textmode/interfaces/index.d.ts +1 -0
  50. package/dist/types/textmode/loadables/TextmodeImage.d.ts +21 -0
  51. package/dist/types/textmode/loadables/TextmodeSource.d.ts +130 -0
  52. package/dist/types/textmode/loadables/TextmodeVideo.d.ts +237 -0
  53. package/dist/types/textmode/{font → loadables/font}/CharacterColorMapper.d.ts +1 -1
  54. package/dist/types/textmode/{font → loadables/font}/CharacterExtractor.d.ts +0 -10
  55. package/dist/types/textmode/{font → loadables/font}/TextmodeFont.d.ts +6 -3
  56. package/dist/types/textmode/{font → loadables/font}/TextureAtlas.d.ts +4 -11
  57. package/dist/types/textmode/{font → loadables/font}/typr/types.d.ts +0 -6
  58. package/dist/types/textmode/loadables/index.d.ts +5 -0
  59. package/dist/types/textmode/loading/LoadingPhaseTracker.d.ts +20 -0
  60. package/dist/types/textmode/loading/LoadingScreenManager.d.ts +170 -0
  61. package/dist/types/textmode/loading/LoadingScreenState.d.ts +22 -0
  62. package/dist/types/textmode/loading/LoadingScreenTheme.d.ts +26 -0
  63. package/dist/types/textmode/loading/LoadingScreenTransition.d.ts +17 -0
  64. package/dist/types/textmode/loading/index.d.ts +6 -0
  65. package/dist/types/textmode/loading/templates/SpinnerTemplate.d.ts +2 -0
  66. package/dist/types/textmode/loading/templates/index.d.ts +1 -0
  67. package/dist/types/textmode/loading/types.d.ts +251 -0
  68. package/dist/types/textmode/managers/KeyboardManager.d.ts +2 -3
  69. package/dist/types/textmode/managers/MouseManager.d.ts +1 -1
  70. package/dist/types/textmode/{plugins → managers}/PluginManager.d.ts +12 -15
  71. package/dist/types/textmode/managers/TouchManager.d.ts +0 -2
  72. package/dist/types/textmode/mixins/AnimationMixin.d.ts +2 -122
  73. package/dist/types/textmode/mixins/FontMixin.d.ts +2 -77
  74. package/dist/types/textmode/mixins/KeyboardMixin.d.ts +3 -85
  75. package/dist/types/textmode/mixins/MouseMixin.d.ts +3 -130
  76. package/dist/types/textmode/mixins/RenderingMixin.d.ts +2 -749
  77. package/dist/types/textmode/mixins/TextmodifierMixin.d.ts +2 -44
  78. package/dist/types/textmode/mixins/TouchMixin.d.ts +2 -187
  79. package/dist/types/textmode/mixins/index.d.ts +8 -8
  80. package/dist/types/textmode/mixins/interfaces/IAnimationMixin.d.ts +167 -0
  81. package/dist/types/textmode/mixins/interfaces/IFontMixin.d.ts +46 -0
  82. package/dist/types/textmode/mixins/interfaces/IKeyboardMixin.d.ts +235 -0
  83. package/dist/types/textmode/mixins/interfaces/IMouseMixin.d.ts +457 -0
  84. package/dist/types/textmode/mixins/interfaces/IRenderingMixin.d.ts +1085 -0
  85. package/dist/types/textmode/mixins/interfaces/ITouchMixin.d.ts +186 -0
  86. package/dist/types/textmode/types.d.ts +49 -0
  87. package/dist/types/textmode/utils/cssColor.d.ts +8 -0
  88. package/dist/types/utils/array.d.ts +34 -0
  89. package/dist/types/utils/math.d.ts +69 -0
  90. package/package.json +1 -1
  91. package/dist/types/rendering/webgl/DrawQueue.d.ts +0 -30
  92. package/dist/types/rendering/webgl/RenderPipeline.d.ts +0 -30
  93. package/dist/types/rendering/webgl/RenderState.d.ts +0 -73
  94. package/dist/types/rendering/webgl/Renderer.d.ts +0 -158
  95. package/dist/types/rendering/webgl/ShaderManager.d.ts +0 -66
  96. package/dist/types/rendering/webgl/geometries/NoiseGrid.d.ts +0 -1
  97. package/dist/types/textmode/TextmodeImage.d.ts +0 -161
  98. package/dist/types/textmode/mixins/ShaderMixin.d.ts +0 -1
  99. /package/dist/types/rendering/webgl/{StateCache.d.ts → utils/ViewportCache.d.ts} +0 -0
  100. /package/dist/types/textmode/{font → loadables/font}/MetricsCalculator.d.ts +0 -0
  101. /package/dist/types/textmode/{font → loadables/font}/index.d.ts +0 -0
  102. /package/dist/types/textmode/{font → loadables/font}/types.d.ts +0 -0
  103. /package/dist/types/textmode/{font → loadables/font}/typr/Typr.d.ts +0 -0
  104. /package/dist/types/textmode/{font → loadables/font}/utils/FontTableReader.d.ts +0 -0
  105. /package/dist/types/textmode/{font → loadables/font}/utils/index.d.ts +0 -0
@@ -1,18 +1,19 @@
1
- export * from './Framebuffer';
2
- export * from './Renderer';
3
- export * from './Shader';
4
- export * from './ShaderManager';
5
- export * from './StateCache';
1
+ export * from './core/Framebuffer';
2
+ export * from './core/Renderer';
3
+ export * from './core/Shader';
4
+ export * from './utils/ViewportCache';
5
+ export * from './geometries/immediate/ImmediateQuad';
6
+ export * from './pipeline';
6
7
  export { GeometryType } from './types/GeometryTypes';
7
8
  export type { IGeometry as IInstancedGeometry, UnitGeometryData, RectangleParams, LineParams, EllipseParams, ArcParams, TriangleParams, BezierCurveParams, GeometryParams } from './types/GeometryTypes';
8
9
  export type { RenderContext, } from './types/RenderTypes';
9
- export type { InstanceData } from './InstanceData';
10
- export { PackedInstanceData, InstanceAttributeLayout } from './InstanceData';
11
- export { InstanceBatch } from './InstanceBatch';
10
+ export type { InstanceData } from './batching/InstanceData';
11
+ export { PackedInstanceData, InstanceAttributeLayout } from './batching/InstanceData';
12
+ export { InstanceBatch } from './batching/InstanceBatch';
12
13
  export { BaseGeometry } from './geometries/BaseGeometry';
13
- export { Rectangle } from './geometries/Rectangle';
14
- export { Line } from './geometries/Line';
15
- export { Ellipse } from './geometries/Ellipse';
16
- export { Arc } from './geometries/Arc';
17
- export { Triangle } from './geometries/Triangle';
18
- export { BezierCurve } from './geometries/BezierCurve';
14
+ export { Rectangle } from './geometries/2d/Rectangle';
15
+ export { Line } from './geometries/2d/Line';
16
+ export { Ellipse } from './geometries/2d/Ellipse';
17
+ export { Arc } from './geometries/2d/Arc';
18
+ export { Triangle } from './geometries/2d/Triangle';
19
+ export { BezierCurve } from './geometries/2d/BezierCurve';
@@ -0,0 +1,26 @@
1
+ import type { GLShader } from '../core/Shader';
2
+ /**
3
+ * Uniform value types supported by materials
4
+ */
5
+ export type UniformValue = number | boolean | number[] | number[][] | Float32Array | Int32Array | WebGLTexture;
6
+ /**
7
+ * Material defines how geometry should be rendered.
8
+ * Combines a shader program with uniform parameters.
9
+ *
10
+ * Materials are immutable once created to enable safe deduplication and caching.
11
+ */
12
+ export interface Material {
13
+ /** Unique material identifier for fast comparison */
14
+ readonly id: number;
15
+ /** The shader program to use for rendering */
16
+ readonly shader: GLShader;
17
+ /** Uniform values to set when using this material (immutable) */
18
+ readonly uniforms: Readonly<Record<string, UniformValue>>;
19
+ /** Hash for fast material comparison and deduplication */
20
+ readonly hash: number;
21
+ /**
22
+ * Whether this is a built-in system material (solid color, copy, etc.)
23
+ * Built-in materials are never disposed when cleaning up user materials.
24
+ */
25
+ readonly isBuiltIn: boolean;
26
+ }
@@ -0,0 +1,63 @@
1
+ import type { Material, UniformValue } from './Material';
2
+ import { GLShader } from '../core/Shader';
3
+ /**
4
+ * Manages material creation, deduplication, and lifecycle.
5
+ *
6
+ * Provides:
7
+ * - Material creation with automatic deduplication
8
+ * - Built-in materials (solid color, copy, image-to-MRT)
9
+ * - Transient materials for dynamic uniforms
10
+ * - Built-in shader management (2D/3D instanced shaders)
11
+ *
12
+ * Performance optimizations:
13
+ * - Material interning: identical materials share the same instance
14
+ * - Hash-based lookup for O(1) deduplication
15
+ * - Separate tracking of user vs built-in materials
16
+ */
17
+ export declare class MaterialManager {
18
+ private _gl;
19
+ private _nextMaterialId;
20
+ private readonly _shader;
21
+ private readonly _solidColorMaterial;
22
+ private _materialCache;
23
+ constructor(gl: WebGL2RenderingContext);
24
+ /**
25
+ * Get the default 2D solid-color material.
26
+ * This material uses the standard instanced MRT shader with per-instance colors.
27
+ */
28
+ get $solidColorMaterial(): Material;
29
+ /**
30
+ * Create a new material or return an existing one with identical properties.
31
+ *
32
+ * Materials are deduplicated based on shader and uniform values.
33
+ * If a material with the same shader and uniforms already exists, it will be reused.
34
+ *
35
+ * @param shader - The shader program to use
36
+ * @param uniforms - Uniform values to set (will be frozen for immutability)
37
+ * @param isBuiltIn - Whether this is a built-in system material
38
+ * @returns A material instance (new or deduplicated)
39
+ */
40
+ $createMaterial(shader: GLShader, uniforms?: Record<string, UniformValue>, isBuiltIn?: boolean): Material;
41
+ /**
42
+ * Create a transient material that won't be cached.
43
+ * Useful for one-off materials with dynamic uniforms that change every frame.
44
+ *
45
+ * @param shader - The shader program to use
46
+ * @param uniforms - Uniform values to set
47
+ * @returns A new material instance (not cached)
48
+ */
49
+ $createTransientMaterial(shader: GLShader, uniforms?: Record<string, UniformValue>): Material;
50
+ /**
51
+ * Compute a hash for a shader + uniforms combination.
52
+ * Used for material deduplication.
53
+ */
54
+ private _computeHash;
55
+ /**
56
+ * Hash a single uniform value based on its type.
57
+ */
58
+ private _hashUniformValue;
59
+ /**
60
+ * Dispose of all shaders and materials managed by this manager.
61
+ */
62
+ $dispose(): void;
63
+ }
@@ -0,0 +1,2 @@
1
+ export type { Material, UniformValue } from './Material';
2
+ export { MaterialManager } from './MaterialManager';
@@ -0,0 +1,63 @@
1
+ import type { DrawCommand } from '../types/DrawCommand';
2
+ /**
3
+ * Material-based rendering pipeline with strict draw order preservation.
4
+ *
5
+ * Responsibilities:
6
+ * - Manages all geometry instances (one per type)
7
+ * - Batches consecutive commands with the same material + geometry type
8
+ * - Executes instanced draw calls
9
+ *
10
+ * Key principles:
11
+ * - Batches consecutive commands with the same material + geometry type
12
+ * - NEVER reorders commands (preserves user draw order)
13
+ * - Single rendering path for all geometry (no special-casing custom shaders)
14
+ *
15
+ * Architecture:
16
+ * 1. Scan commands in insertion order
17
+ * 2. Group consecutive runs of same material+type into batches
18
+ * 3. Render each batch with a single instanced draw call
19
+ *
20
+ * Performance:
21
+ * - Best case: All commands use same material → 1 draw call
22
+ * - Worst case: Alternating materials → same as unbatched
23
+ * - Real-world: 50-70% reduction in draw calls
24
+ */
25
+ export declare class MaterialBatchPipeline {
26
+ private _gl;
27
+ private _geometries;
28
+ private _geometryAttributeCache;
29
+ constructor(gl: WebGL2RenderingContext);
30
+ /**
31
+ * Execute all queued draw commands in strict order.
32
+ * Batches consecutive commands with same material+type for efficiency.
33
+ *
34
+ * @param commands - Draw commands in user-specified order
35
+ */
36
+ $execute(commands: Iterable<DrawCommand>): void;
37
+ /**
38
+ * Group consecutive commands with the same material + geometry type.
39
+ * Preserves draw order by never reordering commands.
40
+ *
41
+ * Algorithm:
42
+ * 1. Start with first command as current batch
43
+ * 2. For each subsequent command:
44
+ * - If material OR type differs: flush current batch, start new one
45
+ * - Otherwise: add to current batch
46
+ * 3. Flush final batch
47
+ *
48
+ * @param commands - Input draw commands in order
49
+ * @returns Array of batches to render sequentially
50
+ */
51
+ private _batchConsecutive;
52
+ /**
53
+ * Render a single batch of commands with the same material and geometry type.
54
+ * Uses instanced rendering for maximum efficiency.
55
+ *
56
+ * @param batch - Batch to render
57
+ */
58
+ private _renderBatch;
59
+ /**
60
+ * Dispose of pipeline resources (including all geometries).
61
+ */
62
+ $dispose(): void;
63
+ }
@@ -0,0 +1,7 @@
1
+ /**
2
+ * WebGL Rendering Pipeline
3
+ *
4
+ * This module contains the rendering pipeline architecture that orchestrates
5
+ * the execution of draw commands through specialized renderers.
6
+ */
7
+ export { MaterialBatchPipeline } from './MaterialBatchPipeline';
@@ -0,0 +1,143 @@
1
+ /**
2
+ * Represents a snapshot of the current rendering state
3
+ */
4
+ export interface IRenderState {
5
+ _lineWeight: number;
6
+ _translationX: number;
7
+ _translationY: number;
8
+ _translationZ: number;
9
+ _rotationX: number;
10
+ _rotationY: number;
11
+ _rotationZ: number;
12
+ _character: [number, number, number];
13
+ _charColor: [number, number, number, number];
14
+ _cellColor: [number, number, number, number];
15
+ _flipX: boolean;
16
+ _flipY: boolean;
17
+ _invert: boolean;
18
+ _charRotation: number;
19
+ _useOrtho: boolean;
20
+ }
21
+ /**
22
+ * Manages rendering state and provides push/pop functionality for state management.
23
+ *
24
+ * Performance optimizations:
25
+ * - Inlined array copies eliminate function call overhead
26
+ * - Object pooling for push/pop operations reduces GC pressure
27
+ * - Direct property assignment maintains V8 hidden classes
28
+ */
29
+ export declare class RenderState {
30
+ private _currentLineWeight;
31
+ private _currentTranslationX;
32
+ private _currentTranslationY;
33
+ private _currentTranslationZ;
34
+ private _rotationX;
35
+ private _rotationY;
36
+ private _rotationZ;
37
+ private _currentCharacter;
38
+ private _currentCharColor;
39
+ private _currentCellColor;
40
+ private _flipHorizontally;
41
+ private _flipVertically;
42
+ private _invert;
43
+ private _charRotation;
44
+ private _canvasBackgroundColor;
45
+ private _useOrtho;
46
+ private _stateStack;
47
+ private _statePool;
48
+ /**
49
+ * Create a new state object with pre-allocated arrays.
50
+ * Used by the object pool to minimize garbage collection.
51
+ * @internal Shared with DrawQueue for command slot initialization
52
+ */
53
+ static $createStateObject(): IRenderState;
54
+ /**
55
+ * Copy current state to target object without allocations.
56
+ *
57
+ * Performance-critical path: This is called every push() operation.
58
+ * Optimizations:
59
+ * - Direct property assignment (no loops, no function calls)
60
+ * - Inlined array element copies (avoids copyArray() overhead)
61
+ * - Sequential memory access pattern for CPU cache efficiency
62
+ *
63
+ * @param target - Target state object to receive values
64
+ * @private
65
+ */
66
+ private _copyCurrentToState;
67
+ /**
68
+ * Copy state object to current state without allocations.
69
+ *
70
+ * Performance-critical path: This is called every pop() operation.
71
+ * Optimizations:
72
+ * - Direct property assignment (no loops, no function calls)
73
+ * - Inlined array element copies (avoids copyArray() overhead)
74
+ * - Sequential memory access pattern for CPU cache efficiency
75
+ *
76
+ * @param source - Source state object to copy from
77
+ * @private
78
+ */
79
+ private _copyStateToCurrents;
80
+ /**
81
+ * Save the current rendering state to the state stack.
82
+ * Uses object pooling to eliminate per-frame allocations and reduce GC pressure.
83
+ */
84
+ $push(): void;
85
+ /**
86
+ * Restore the most recently saved rendering state from the state stack.
87
+ * Returns the state object to the pool for reuse.
88
+ */
89
+ $pop(): void;
90
+ /**
91
+ * Copy current rendering state to a target object without allocations.
92
+ * Mutates the target's properties and arrays in-place for zero-allocation performance.
93
+ *
94
+ * @param target - Pre-allocated state object to copy values into
95
+ */
96
+ $copyTo(target: IRenderState): void;
97
+ $setLineWeight(weight: number): void;
98
+ /**
99
+ * Reset transformation matrix to identity and clear translation counters.
100
+ * Should be called at the start of each frame to prevent accumulation.
101
+ */
102
+ $resetTransform(): void;
103
+ /**
104
+ * Apply a rotation around the X-axis to the current transformation matrix.
105
+ * Follows p5.js convention where order matters.
106
+ * @param degrees Rotation angle in degrees
107
+ */
108
+ $setRotationX(degrees: number): void;
109
+ /**
110
+ * Apply a rotation around the Y-axis to the current transformation matrix.
111
+ * Follows p5.js convention where order matters.
112
+ * @param degrees Rotation angle in degrees
113
+ */
114
+ $setRotationY(degrees: number): void;
115
+ /**
116
+ * Apply a rotation around the Z-axis to the current transformation matrix.
117
+ * Follows p5.js convention where order matters.
118
+ * @param degrees Rotation angle in degrees
119
+ */
120
+ $setRotationZ(degrees: number): void;
121
+ $translate(x?: number, y?: number, z?: number): void;
122
+ $setTranslationX(pixels: number): void;
123
+ $setTranslationY(pixels: number): void;
124
+ $setTranslationZ(pixels: number): void;
125
+ $setCharacter(character: [number, number, number]): void;
126
+ $setCharColor(r: number, g?: number, b?: number, a?: number): void;
127
+ $setCellColor(r: number, g?: number, b?: number, a?: number): void;
128
+ $setFlipHorizontally(flip: boolean): void;
129
+ $setFlipVertically(flip: boolean): void;
130
+ $setInvert(invert: boolean): void;
131
+ $setCharRotation(rotation: number): void;
132
+ $setCanvasBackground(r: number, g: number, b: number, a: number): void;
133
+ $setUseOrtho(useOrtho: boolean): void;
134
+ get canvasBackgroundColor(): [number, number, number, number];
135
+ get useOrtho(): boolean;
136
+ /**
137
+ * Get the current transformation matrix.
138
+ * Returns the underlying Float32Array for efficient GPU upload.
139
+ */
140
+ get rotationX(): number;
141
+ get rotationY(): number;
142
+ get rotationZ(): number;
143
+ }
@@ -1,6 +1,7 @@
1
1
  import type { GeometryParams, GeometryType } from './GeometryTypes';
2
- import type { RenderState } from '../RenderState';
3
- import type { GLShader } from '../Shader';
2
+ import type { IRenderState } from '../state/RenderState';
3
+ import type { GLShader } from '../core/Shader';
4
+ import type { Material } from '../materials/Material';
4
5
  export type CustomRectParams = {
5
6
  x: number;
6
7
  y: number;
@@ -14,5 +15,6 @@ export interface DrawCommand {
14
15
  id: number;
15
16
  type: GeometryType;
16
17
  params: DrawParams;
17
- state: RenderState;
18
+ state: IRenderState;
19
+ material: Material;
18
20
  }
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Core interfaces and types for the instanced geometry system
3
3
  */
4
- import type { InstanceBatch } from '../InstanceBatch';
4
+ import type { InstanceBatch } from '../batching/InstanceBatch';
5
5
  /**
6
6
  * Geometry types supported by the instanced rendering system
7
7
  */
@@ -11,9 +11,16 @@ export declare enum GeometryType {
11
11
  ELLIPSE = "ellipse",
12
12
  ARC = "arc",
13
13
  TRIANGLE = "triangle",
14
- BEZIER_CURVE = "bezier_curve",
15
- CUSTOM = "custom"
14
+ BEZIER_CURVE = "bezier_curve"
16
15
  }
16
+ /**
17
+ * Mapping from GeometryType to numeric shader constant.
18
+ * Must match the constants defined in instanced.vert:
19
+ * - GEOMETRY_TYPE_FLAT = 2 (rectangle, line, ellipse, triangle)
20
+ * - GEOMETRY_TYPE_ARC = 3
21
+ * - GEOMETRY_TYPE_BEZIER = 4
22
+ */
23
+ export declare const GEOMETRY_TYPE_ID: Record<GeometryType, number>;
17
24
  /**
18
25
  * Unit geometry vertex data for a specific geometry type
19
26
  */
@@ -72,8 +79,6 @@ export interface IGeometry {
72
79
  * Parameters for rectangle geometry
73
80
  */
74
81
  export interface RectangleParams {
75
- x: number;
76
- y: number;
77
82
  width: number;
78
83
  height: number;
79
84
  }
@@ -91,8 +96,6 @@ export interface LineParams {
91
96
  * Parameters for ellipse geometry
92
97
  */
93
98
  export interface EllipseParams {
94
- x: number;
95
- y: number;
96
99
  width: number;
97
100
  height: number;
98
101
  startAngle?: number;
@@ -102,11 +105,8 @@ export interface EllipseParams {
102
105
  /**
103
106
  * Parameters for arc geometry (filled pie segment)
104
107
  * Angles are specified in DEGREES and arcs are drawn clockwise from start to stop.
105
- * x, y specify the center of the arc (consistent with current ellipse implementation).
106
108
  */
107
109
  export interface ArcParams {
108
- x: number;
109
- y: number;
110
110
  width: number;
111
111
  height: number;
112
112
  start: number;
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Rendering pipeline interfaces and types
3
3
  */
4
- import type { GLShader } from '../Shader';
4
+ import type { GLShader } from '../core/Shader';
5
5
  /**
6
6
  * Render context containing shader and rendering configuration
7
7
  */
@@ -0,0 +1,45 @@
1
+ /**
2
+ * Update a WebGL texture from a canvas or video source.
3
+ * Handles binding, pixel storage, upload, and unbinding.
4
+ *
5
+ * @param gl WebGL2 rendering context
6
+ * @param texture Target texture to update
7
+ * @param source Canvas or video element to upload
8
+ */
9
+ export declare function updateTextureFromSource(gl: WebGL2RenderingContext, texture: WebGLTexture, source: HTMLCanvasElement | HTMLVideoElement): void;
10
+ /**
11
+ * Configure texture parameters for filtering and wrapping modes.
12
+ * Must be called with texture already bound to gl.TEXTURE_2D.
13
+ *
14
+ * @param gl WebGL2 rendering context
15
+ * @param minFilter Minification filter (gl.NEAREST or gl.LINEAR)
16
+ * @param magFilter Magnification filter (gl.NEAREST or gl.LINEAR)
17
+ * @param wrapS Horizontal wrapping mode (gl.CLAMP_TO_EDGE or gl.REPEAT)
18
+ * @param wrapT Vertical wrapping mode (gl.CLAMP_TO_EDGE or gl.REPEAT)
19
+ */
20
+ export declare function setTextureParameters(gl: WebGL2RenderingContext, minFilter: number, magFilter: number, wrapS: number, wrapT: number): void;
21
+ /**
22
+ * Configure a vertex attribute with pointer and divisor settings.
23
+ * Handles enable, pointer setup, and divisor configuration in one call.
24
+ *
25
+ * @param gl WebGL2 rendering context
26
+ * @param location Attribute location from shader
27
+ * @param size Number of components per vertex attribute (1-4)
28
+ * @param stride Byte offset between consecutive vertex attributes
29
+ * @param offset Byte offset of the first component in the buffer
30
+ * @param divisor Number of instances that will pass between updates (0 = per-vertex, 1 = per-instance)
31
+ * @param type Data type (default: gl.FLOAT)
32
+ * @param normalized Whether integer data should be normalized (default: false)
33
+ */
34
+ export declare function setupVertexAttribute(gl: WebGL2RenderingContext, location: number, size: number, stride: number, offset: number, divisor?: number, type?: number, normalized?: boolean): void;
35
+ /**
36
+ * Allocate or upload data to a buffer (bind → bufferData → unbind pattern).
37
+ * Ensures proper binding/unbinding sequence for safe buffer operations.
38
+ *
39
+ * @param gl WebGL2 rendering context
40
+ * @param target Buffer binding point (gl.ARRAY_BUFFER or gl.ELEMENT_ARRAY_BUFFER)
41
+ * @param buffer Target buffer to bind
42
+ * @param data Data to upload, or size in bytes for allocation
43
+ * @param usage Usage hint (gl.STATIC_DRAW, gl.DYNAMIC_DRAW, etc.)
44
+ */
45
+ export declare function uploadBufferData(gl: WebGL2RenderingContext, target: number, buffer: WebGLBuffer, data: AllowSharedBufferSource | number, usage: number): void;
@@ -0,0 +1,118 @@
1
+ /**
2
+ * Generic hashing utilities for creating stable hash codes from various data types.
3
+ *
4
+ * These functions are useful for:
5
+ * - Object deduplication (e.g., materials, shaders)
6
+ * - Cache keys
7
+ * - Fast equality comparisons
8
+ *
9
+ * Hash algorithm: Simple 32-bit integer hash with good distribution.
10
+ * Not cryptographically secure, but fast and collision-resistant for typical use cases.
11
+ */
12
+ /**
13
+ * Hash a string to a 32-bit integer.
14
+ * Uses the djb2 algorithm variant.
15
+ *
16
+ * @param str - String to hash
17
+ * @returns 32-bit integer hash
18
+ *
19
+ * @example
20
+ * ```typescript
21
+ * hashString("hello") // → 99162322
22
+ * hashString("world") // → 113318802
23
+ * ```
24
+ */
25
+ export declare function hashString(str: string): number;
26
+ /**
27
+ * Hash a number or boolean to an integer.
28
+ * Booleans are converted to 0/1.
29
+ *
30
+ * @param value - Number or boolean to hash
31
+ * @returns Integer hash
32
+ *
33
+ * @example
34
+ * ```typescript
35
+ * hashNumber(42) // → 42
36
+ * hashNumber(3.14) // → 3
37
+ * hashNumber(true) // → 1
38
+ * hashNumber(false) // → 0
39
+ * ```
40
+ */
41
+ export declare function hashNumber(value: number | boolean): number;
42
+ /**
43
+ * Hash an array of numbers.
44
+ * Supports nested arrays (will be flattened).
45
+ *
46
+ * @param arr - Array of numbers or nested arrays
47
+ * @returns Combined hash of all elements
48
+ *
49
+ * @example
50
+ * ```typescript
51
+ * hashArray([1, 2, 3]) // → computed hash
52
+ * hashArray([[1, 2], [3, 4]]) // → computed hash (flattened)
53
+ * ```
54
+ */
55
+ export declare function hashArray(arr: number[] | number[][]): number;
56
+ /**
57
+ * Hash a typed array (Float32Array or Int32Array).
58
+ * For performance, only hashes the first 16 elements for large arrays.
59
+ *
60
+ * @param arr - Typed array to hash
61
+ * @returns Combined hash
62
+ *
63
+ * @example
64
+ * ```typescript
65
+ * const arr = new Float32Array([1.0, 2.0, 3.0]);
66
+ * hashTypedArray(arr) // → computed hash
67
+ * ```
68
+ */
69
+ export declare function hashTypedArray(arr: Float32Array | Int32Array): number;
70
+ /**
71
+ * Hash an object by converting it to a string representation.
72
+ * Uses the object's memory address (toString) as the hash basis.
73
+ *
74
+ * This is useful for WebGL objects like textures, buffers, etc.
75
+ * where identity is more important than value equality.
76
+ *
77
+ * @param obj - Object to hash
78
+ * @returns Hash based on object identity
79
+ *
80
+ * @example
81
+ * ```typescript
82
+ * const texture = gl.createTexture();
83
+ * hashObject(texture) // → hash based on texture identity
84
+ * ```
85
+ */
86
+ export declare function hashObject(obj: any): number;
87
+ /**
88
+ * Combine two hash values into a single hash.
89
+ * Uses a simple but effective combination strategy.
90
+ *
91
+ * @param hash1 - First hash value
92
+ * @param hash2 - Second hash value
93
+ * @returns Combined hash
94
+ *
95
+ * @example
96
+ * ```typescript
97
+ * const h1 = hashString("hello");
98
+ * const h2 = hashString("world");
99
+ * const combined = combineHashes(h1, h2);
100
+ * ```
101
+ */
102
+ export declare function combineHashes(hash1: number, hash2: number): number;
103
+ /**
104
+ * Hash a record/object by hashing its sorted keys and values.
105
+ * Keys are sorted to ensure consistent hashing regardless of property order.
106
+ *
107
+ * @param record - Record to hash
108
+ * @param valueHasher - Function to hash each value
109
+ * @returns Combined hash of all key-value pairs
110
+ *
111
+ * @example
112
+ * ```typescript
113
+ * const obj = { b: 2, a: 1, c: 3 };
114
+ * const hash = hashRecord(obj, hashNumber);
115
+ * // Keys are sorted: a, b, c → consistent hash
116
+ * ```
117
+ */
118
+ export declare function hashRecord<T>(record: Record<string, T>, valueHasher: (value: T) => number): number;
@@ -3,7 +3,6 @@
3
3
  * Provides precise frame rate limiting and smooth animation timing.
4
4
  */
5
5
  export declare class AnimationController {
6
- private _frameRateLimit;
7
6
  private _frameInterval;
8
7
  private _animationFrameId;
9
8
  private _lastFrameTime;
@@ -22,60 +21,51 @@ export declare class AnimationController {
22
21
  * Start the animation loop with the provided render callback.
23
22
  * @param renderCallback Function to call for each frame render
24
23
  */
25
- start(renderCallback: () => void): void;
24
+ $start(renderCallback: () => void): void;
26
25
  /**
27
26
  * Stop the animation loop.
28
27
  */
29
- stop(): void;
28
+ $stop(): void;
30
29
  /**
31
30
  * Pause the animation loop without stopping it completely.
32
31
  */
33
- pause(): void;
32
+ $pause(): void;
34
33
  /**
35
34
  * Resume the animation loop if it was paused.
36
35
  * @param renderCallback Function to call for each frame render
37
36
  */
38
- resume(renderCallback: () => void): void;
37
+ $resume(renderCallback: () => void): void;
39
38
  /**
40
39
  * Set or get the frame rate limit.
41
40
  * @param fps Optional new frame rate limit. If not provided, returns current measured frame rate.
42
41
  * @param renderCallback Required when setting new frame rate and animation is running
43
42
  * @returns Current measured frame rate when getting, void when setting
44
43
  */
45
- frameRate(fps?: number, renderCallback?: () => void): number | void;
44
+ $frameRate(fps?: number, renderCallback?: () => void): number | void;
46
45
  /**
47
46
  * Update frame rate measurement. Should be called on each render.
48
47
  * Uses a rolling average for smoother frame rate reporting.
49
48
  */
50
- measureFrameRate(): void;
49
+ $measureFrameRate(): void;
51
50
  /**
52
51
  * Check if the animation loop is currently active.
53
52
  */
54
- get isLooping(): boolean;
55
- /**
56
- * Get the current frame rate limit.
57
- */
58
- get frameRateLimit(): number;
53
+ get $isLooping(): boolean;
59
54
  /**
60
55
  * Get the current measured frame rate.
61
56
  */
62
- get currentFrameRate(): number;
57
+ get $currentFrameRate(): number;
63
58
  /**
64
59
  * Get the current frame count.
65
60
  */
66
- get frameCount(): number;
61
+ get $frameCount(): number;
67
62
  /**
68
63
  * Set the current frame count.
69
64
  */
70
- set frameCount(value: number);
65
+ set $frameCount(value: number);
71
66
  /**
72
67
  * Increment the frame count by one.
73
68
  * Should be called on each render to track total frames rendered.
74
69
  */
75
- incrementFrame(): void;
76
- /**
77
- * Reset the frame count to zero.
78
- * Useful when restarting animations or resetting state.
79
- */
80
- resetFrameCount(): void;
70
+ $incrementFrame(): void;
81
71
  }