textmode.js 0.9.0 → 0.9.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 (129) hide show
  1. package/dist/textmode.esm.js +965 -965
  2. package/dist/textmode.umd.js +13 -13
  3. package/dist/types/Textmode.d.ts +133 -0
  4. package/dist/types/errors/Error.d.ts +24 -0
  5. package/dist/types/errors/ErrorHandler.d.ts +77 -0
  6. package/dist/types/errors/index.d.ts +2 -0
  7. package/dist/types/exports/conversion.d.ts +1 -0
  8. package/dist/types/exports/filters.d.ts +1 -0
  9. package/dist/types/exports/input.d.ts +1 -0
  10. package/dist/types/exports/layering.d.ts +1 -0
  11. package/dist/types/exports/loadables.d.ts +1 -0
  12. package/dist/types/exports/loading.d.ts +1 -0
  13. package/dist/types/exports/plugins.d.ts +1 -0
  14. package/dist/types/index.d.ts +85 -0
  15. package/dist/types/rendering/index.d.ts +4 -0
  16. package/dist/types/rendering/webgl/batching/DrawQueue.d.ts +89 -0
  17. package/dist/types/rendering/webgl/batching/GeometryAttributeCache.d.ts +18 -0
  18. package/dist/types/rendering/webgl/batching/InstanceAttributeBinder.d.ts +83 -0
  19. package/dist/types/rendering/webgl/batching/InstanceBatch.d.ts +87 -0
  20. package/dist/types/rendering/webgl/batching/InstanceBuffer.d.ts +68 -0
  21. package/dist/types/rendering/webgl/batching/InstanceData.d.ts +56 -0
  22. package/dist/types/rendering/webgl/batching/InstanceWriter.d.ts +78 -0
  23. package/dist/types/rendering/webgl/core/Framebuffer.d.ts +94 -0
  24. package/dist/types/rendering/webgl/core/Renderer.d.ts +78 -0
  25. package/dist/types/rendering/webgl/core/Shader.d.ts +62 -0
  26. package/dist/types/rendering/webgl/core/interfaces/IFramebuffer.d.ts +101 -0
  27. package/dist/types/rendering/webgl/core/interfaces/IRenderer.d.ts +214 -0
  28. package/dist/types/rendering/webgl/geometries/2d/Arc.d.ts +17 -0
  29. package/dist/types/rendering/webgl/geometries/2d/BezierCurve.d.ts +23 -0
  30. package/dist/types/rendering/webgl/geometries/2d/Ellipse.d.ts +21 -0
  31. package/dist/types/rendering/webgl/geometries/2d/Line.d.ts +21 -0
  32. package/dist/types/rendering/webgl/geometries/2d/Rectangle.d.ts +21 -0
  33. package/dist/types/rendering/webgl/geometries/2d/Triangle.d.ts +21 -0
  34. package/dist/types/rendering/webgl/geometries/BaseGeometry.d.ts +57 -0
  35. package/dist/types/rendering/webgl/geometries/immediate/ImmediateQuad.d.ts +33 -0
  36. package/dist/types/rendering/webgl/geometries/index.d.ts +6 -0
  37. package/dist/types/rendering/webgl/geometries/utils/GeometryDescriptors.d.ts +31 -0
  38. package/dist/types/rendering/webgl/geometries/utils/GeometryGenerator.d.ts +16 -0
  39. package/dist/types/rendering/webgl/index.d.ts +19 -0
  40. package/dist/types/rendering/webgl/materials/Material.d.ts +23 -0
  41. package/dist/types/rendering/webgl/materials/MaterialManager.d.ts +56 -0
  42. package/dist/types/rendering/webgl/materials/index.d.ts +2 -0
  43. package/dist/types/rendering/webgl/pipeline/MaterialBatchPipeline.d.ts +54 -0
  44. package/dist/types/rendering/webgl/pipeline/index.d.ts +7 -0
  45. package/dist/types/rendering/webgl/state/RenderState.d.ts +159 -0
  46. package/dist/types/rendering/webgl/types/DrawCommand.d.ts +29 -0
  47. package/dist/types/rendering/webgl/types/GeometryTypes.d.ts +147 -0
  48. package/dist/types/rendering/webgl/types/RenderTypes.d.ts +18 -0
  49. package/dist/types/rendering/webgl/types/UniformTypes.d.ts +11 -0
  50. package/dist/types/rendering/webgl/utils/GLUtils.d.ts +68 -0
  51. package/dist/types/rendering/webgl/utils/ViewportCache.d.ts +3 -0
  52. package/dist/types/rendering/webgl/utils/hash.d.ts +102 -0
  53. package/dist/types/textmode/AnimationController.d.ts +110 -0
  54. package/dist/types/textmode/Canvas.d.ts +58 -0
  55. package/dist/types/textmode/Grid.d.ts +563 -0
  56. package/dist/types/textmode/TextmodeColor.d.ts +405 -0
  57. package/dist/types/textmode/Textmodifier.d.ts +113 -0
  58. package/dist/types/textmode/conversion/ConversionManager.d.ts +89 -0
  59. package/dist/types/textmode/conversion/ConversionRegistry.d.ts +78 -0
  60. package/dist/types/textmode/conversion/index.d.ts +2 -0
  61. package/dist/types/textmode/conversion/strategies/brightness.d.ts +2 -0
  62. package/dist/types/textmode/filters/FilterManager.d.ts +132 -0
  63. package/dist/types/textmode/filters/index.d.ts +2 -0
  64. package/dist/types/textmode/filters/types.d.ts +78 -0
  65. package/dist/types/textmode/interfaces/IDisposable.d.ts +14 -0
  66. package/dist/types/textmode/interfaces/ITextmodifier.d.ts +753 -0
  67. package/dist/types/textmode/interfaces/index.d.ts +2 -0
  68. package/dist/types/textmode/layers/Layer2DCompositor.d.ts +89 -0
  69. package/dist/types/textmode/layers/LayerManager.d.ts +115 -0
  70. package/dist/types/textmode/layers/TextmodeLayer.d.ts +105 -0
  71. package/dist/types/textmode/layers/index.d.ts +4 -0
  72. package/dist/types/textmode/layers/interfaces/ILayerManager.d.ts +158 -0
  73. package/dist/types/textmode/layers/interfaces/ITextmodeLayer.d.ts +821 -0
  74. package/dist/types/textmode/layers/types.d.ts +78 -0
  75. package/dist/types/textmode/loadables/ITextmodeSource.d.ts +541 -0
  76. package/dist/types/textmode/loadables/TextmodeImage.d.ts +45 -0
  77. package/dist/types/textmode/loadables/TextmodeSource.d.ts +65 -0
  78. package/dist/types/textmode/loadables/TextmodeTexture.d.ts +95 -0
  79. package/dist/types/textmode/loadables/font/CharacterColorMapper.d.ts +34 -0
  80. package/dist/types/textmode/loadables/font/CharacterExtractor.d.ts +22 -0
  81. package/dist/types/textmode/loadables/font/MetricsCalculator.d.ts +23 -0
  82. package/dist/types/textmode/loadables/font/TextmodeFont.d.ts +176 -0
  83. package/dist/types/textmode/loadables/font/TextureAtlas.d.ts +66 -0
  84. package/dist/types/textmode/loadables/font/index.d.ts +8 -0
  85. package/dist/types/textmode/loadables/font/types.d.ts +28 -0
  86. package/dist/types/textmode/loadables/font/typr/Typr.d.ts +20 -0
  87. package/dist/types/textmode/loadables/font/typr/types.d.ts +241 -0
  88. package/dist/types/textmode/loadables/font/utils/CmapUtils.d.ts +11 -0
  89. package/dist/types/textmode/loadables/font/utils/FontTableReader.d.ts +40 -0
  90. package/dist/types/textmode/loadables/font/utils/index.d.ts +7 -0
  91. package/dist/types/textmode/loadables/index.d.ts +6 -0
  92. package/dist/types/textmode/loadables/video/ITextmodeVideo.d.ts +339 -0
  93. package/dist/types/textmode/loadables/video/TextmodeVideo.d.ts +81 -0
  94. package/dist/types/textmode/loading/LoadingPhase.d.ts +28 -0
  95. package/dist/types/textmode/loading/LoadingPhaseTracker.d.ts +20 -0
  96. package/dist/types/textmode/loading/LoadingScreenManager.d.ts +208 -0
  97. package/dist/types/textmode/loading/LoadingScreenState.d.ts +22 -0
  98. package/dist/types/textmode/loading/LoadingScreenTheme.d.ts +26 -0
  99. package/dist/types/textmode/loading/LoadingScreenTransition.d.ts +17 -0
  100. package/dist/types/textmode/loading/index.d.ts +7 -0
  101. package/dist/types/textmode/loading/templates/SpinnerTemplate.d.ts +2 -0
  102. package/dist/types/textmode/loading/templates/index.d.ts +1 -0
  103. package/dist/types/textmode/loading/types.d.ts +255 -0
  104. package/dist/types/textmode/managers/KeyboardManager.d.ts +128 -0
  105. package/dist/types/textmode/managers/MouseManager.d.ts +159 -0
  106. package/dist/types/textmode/managers/PluginManager.d.ts +220 -0
  107. package/dist/types/textmode/managers/TouchManager.d.ts +237 -0
  108. package/dist/types/textmode/managers/index.d.ts +12 -0
  109. package/dist/types/textmode/mixins/AnimationMixin.d.ts +8 -0
  110. package/dist/types/textmode/mixins/KeyboardMixin.d.ts +13 -0
  111. package/dist/types/textmode/mixins/MouseMixin.d.ts +10 -0
  112. package/dist/types/textmode/mixins/RenderingMixin.d.ts +8 -0
  113. package/dist/types/textmode/mixins/TextmodifierMixin.d.ts +19 -0
  114. package/dist/types/textmode/mixins/TouchMixin.d.ts +6 -0
  115. package/dist/types/textmode/mixins/index.d.ts +9 -0
  116. package/dist/types/textmode/mixins/interfaces/IAnimationMixin.d.ts +674 -0
  117. package/dist/types/textmode/mixins/interfaces/IKeyboardMixin.d.ts +234 -0
  118. package/dist/types/textmode/mixins/interfaces/IMouseMixin.d.ts +425 -0
  119. package/dist/types/textmode/mixins/interfaces/IRenderingMixin.d.ts +2147 -0
  120. package/dist/types/textmode/mixins/interfaces/ITouchMixin.d.ts +509 -0
  121. package/dist/types/textmode/types.d.ts +52 -0
  122. package/dist/types/utils/Disposable.d.ts +18 -0
  123. package/dist/types/utils/TextmodeCollection.d.ts +172 -0
  124. package/dist/types/utils/array.d.ts +34 -0
  125. package/dist/types/utils/color.d.ts +61 -0
  126. package/dist/types/utils/input.d.ts +11 -0
  127. package/dist/types/utils/math.d.ts +118 -0
  128. package/dist/types/utils/shader.d.ts +12 -0
  129. package/package.json +2 -2
@@ -0,0 +1,133 @@
1
+ import { type TextmodeErrorLevel } from './errors';
2
+ import { Textmodifier } from './textmode/Textmodifier';
3
+ import type { TextmodeOptions } from './textmode/types';
4
+ /**
5
+ * The main entry point for the `textmode.js` library.
6
+ *
7
+ * Provides static methods for creating {@link Textmodifier} instances and managing global settings.
8
+ *
9
+ * @example
10
+ * ```javascript
11
+ * // Basic usage pattern
12
+ * const t = textmode.create({
13
+ * width: window.innerWidth,
14
+ * height: window.innerHeight
15
+ * });
16
+ *
17
+ * t.draw(() => {
18
+ * t.background(0);
19
+ * t.charColor(255);
20
+ * t.char('T');
21
+ * t.rect(5, 5);
22
+ * });
23
+ *
24
+ * t.windowResized(() => {
25
+ * t.resizeCanvas(window.innerWidth, window.innerHeight);
26
+ * });
27
+ * ```
28
+ */
29
+ export declare class Textmode {
30
+ private constructor();
31
+ /**
32
+ * Create a new {@link Textmodifier} instance with optional configuration.
33
+ * @param opts Configuration options for the Textmodifier instance
34
+ * @returns A new Textmodifier instance
35
+ *
36
+ * @example
37
+ * ```javascript
38
+ * // Initialize with custom font size and responsive canvas
39
+ * const t = textmode.create({
40
+ * width: window.innerWidth,
41
+ * height: window.innerHeight,
42
+ * fontSize: 16
43
+ * });
44
+ *
45
+ * t.draw(() => {
46
+ * t.background(10, 15, 20);
47
+ *
48
+ * // Draw a field of rhythmic characters
49
+ * for (let x = -20; x <= 20; x += 5) {
50
+ * for (let y = -15; y <= 15; y += 5) {
51
+ * const dist = Math.sqrt(x*x + y*y);
52
+ * const offset = Math.sin(t.frameCount * 0.1 - dist * 0.5) * 2;
53
+ *
54
+ * t.push();
55
+ * t.translate(x, y + offset);
56
+ * t.charColor(255 - dist * 10, 150, 200);
57
+ * t.char(dist < 10 ? '█' : '░');
58
+ * t.point();
59
+ * t.pop();
60
+ * }
61
+ * }
62
+ * });
63
+ *
64
+ * t.windowResized(() => {
65
+ * t.resizeCanvas(window.innerWidth, window.innerHeight);
66
+ * });
67
+ * ```
68
+ */
69
+ static create(opts?: TextmodeOptions): Textmodifier;
70
+ /**
71
+ * Set the global error handling level for the library. This applies to all {@link Textmodifier} instances present.
72
+ *
73
+ * @param level The error handling level to set.
74
+ *
75
+ * @example
76
+ * ```javascript
77
+ * // Configuring error behavior
78
+ * import { TextmodeErrorLevel } from 'textmode.js';
79
+ *
80
+ * // Suppress non-critical warnings in production
81
+ * textmode.setErrorLevel(TextmodeErrorLevel.WARNING);
82
+ *
83
+ * const t = textmode.create({ width: window.innerWidth, height: window.innerHeight });
84
+ *
85
+ * t.draw(() => {
86
+ * t.background(0);
87
+ * t.char('!');
88
+ * t.charColor(255, 255, 0);
89
+ * t.rect(10, 10);
90
+ * });
91
+ *
92
+ * t.windowResized(() => {
93
+ * t.resizeCanvas(window.innerWidth, window.innerHeight);
94
+ * });
95
+ * ```
96
+ */
97
+ static setErrorLevel(level: TextmodeErrorLevel): void;
98
+ /**
99
+ * Returns the version of `textmode.js` being used.
100
+ *
101
+ * @returns The version string of the library.
102
+ *
103
+ * @example
104
+ * ```javascript
105
+ * // Display the library version in a retro terminal style
106
+ * const t = textmode.create({ width: window.innerWidth, height: window.innerHeight });
107
+ *
108
+ * const v = `VERSION: ${textmode.version}`;
109
+ *
110
+ * t.draw(() => {
111
+ * t.background(0, 20, 0); // CRT Dark Green
112
+ *
113
+ * t.push();
114
+ * t.translate(-v.length / 2, 0);
115
+ * t.charColor(0, 255, 0);
116
+ *
117
+ * for (let i = 0; i < v.length; i++) {
118
+ * t.push();
119
+ * t.translate(i, 0);
120
+ * t.char(v[i]);
121
+ * t.point();
122
+ * t.pop();
123
+ * }
124
+ * t.pop();
125
+ * });
126
+ *
127
+ * t.windowResized(() => {
128
+ * t.resizeCanvas(window.innerWidth, window.innerHeight);
129
+ * });
130
+ * ```
131
+ */
132
+ static get version(): string;
133
+ }
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Custom error class for textmode.js exceptions.
3
+ *
4
+ * Provides formatted error messages with optional context data to help
5
+ * debug issues.
6
+ *
7
+ */
8
+ export declare class TextmodeError extends Error {
9
+ /**
10
+ * Creates a new TextmodeError instance.
11
+ * @param message The main error message
12
+ * @param context Optional context data to include in the error message
13
+ */
14
+ constructor(message: string, context?: Record<string, unknown>);
15
+ /**
16
+ * Create a formatted error message that includes context
17
+ * @ignore
18
+ */
19
+ static $createFormattedMessage(message: string, context?: Record<string, unknown>): string;
20
+ /**
21
+ * Format values for better display in error messages
22
+ */
23
+ private static _formatValue;
24
+ }
@@ -0,0 +1,77 @@
1
+ /**
2
+ * Error handling levels to control how errors are reported and handled.
3
+ *
4
+ * Determines how validation failures and errors are processed throughout the library.
5
+ * Each level provides different behavior for error reporting and execution flow control.
6
+ *
7
+ * > [!NOTE]
8
+ * > This feature is currently not fully implemented across all modules,
9
+ * > and most `textmode.js` functions will still throw errors if used incorrectly.
10
+ *
11
+ * @example
12
+ * ```js
13
+ * // Set to `WARNING` level to log errors without stopping execution
14
+ * textmode.setErrorLevel(TextmodeErrorLevel.WARNING);
15
+ * ```
16
+ */
17
+ export declare enum TextmodeErrorLevel {
18
+ /**
19
+ * Suppress all error output.
20
+ * Validation failures are handled silently without any console messages.
21
+ */
22
+ SILENT = 0,
23
+ /**
24
+ * Log validation failures as warnings.
25
+ */
26
+ WARNING = 1,
27
+ /**
28
+ * Log validation failures as errors.
29
+ */
30
+ ERROR = 2,
31
+ /**
32
+ * Throw exceptions on validation failures *(default behavior)*.
33
+ */
34
+ THROW = 3
35
+ }
36
+ /**
37
+ * Options for configuring the error handler.
38
+ * @ignore
39
+ */
40
+ export interface ErrorHandlerOptions {
41
+ /** Global error level */
42
+ globalLevel: TextmodeErrorLevel;
43
+ }
44
+ /**
45
+ * Singleton error handler for textmode.js
46
+ * This class handles errors based on the configured error level.
47
+ * It can log warnings, errors, or throw exceptions based on the global error level.
48
+ * @ignore
49
+ */
50
+ export declare class TextmodeErrorHandler {
51
+ private static _instance;
52
+ private _options;
53
+ private constructor();
54
+ static $getInstance(): TextmodeErrorHandler;
55
+ /**
56
+ * Handle an error based on the configured settings
57
+ * @returns true if execution should continue, false if error was handled
58
+ */
59
+ private _handle;
60
+ /**
61
+ * Validate a condition and handle errors if validation fails
62
+ * @param condition The condition to validate
63
+ * @param message Error message if validation fails
64
+ * @param context Additional context for debugging
65
+ * @returns true if validation passed, false if validation failed and was handled
66
+ */
67
+ $validate(condition: boolean, message: string, context?: Record<string, unknown>): boolean;
68
+ /**
69
+ * Set global error level
70
+ */
71
+ $setGlobalLevel(level: TextmodeErrorLevel): void;
72
+ }
73
+ /**
74
+ * Singleton instance of the textmode.js error handler.
75
+ * @ignore
76
+ */
77
+ export declare const errorHandler: TextmodeErrorHandler;
@@ -0,0 +1,2 @@
1
+ export { TextmodeError } from './Error';
2
+ export { TextmodeErrorHandler, errorHandler, TextmodeErrorLevel, type ErrorHandlerOptions } from './ErrorHandler';
@@ -0,0 +1 @@
1
+ export * from '../textmode/conversion';
@@ -0,0 +1 @@
1
+ export * from '../textmode/filters';
@@ -0,0 +1 @@
1
+ export * from '../textmode/managers';
@@ -0,0 +1 @@
1
+ export * from '../textmode/layers';
@@ -0,0 +1 @@
1
+ export * from '../textmode/loadables';
@@ -0,0 +1 @@
1
+ export * from '../textmode/loading';
@@ -0,0 +1 @@
1
+ export type { TextmodePlugin, TextmodePluginAPI, TextmodePluginHook, LayerLifecycleHook, LayerRenderHook, SetupLifecycleHook, } from '../textmode/managers/PluginManager';
@@ -0,0 +1,85 @@
1
+ import { Textmode } from './Textmode';
2
+ export { Textmodifier } from './textmode/Textmodifier';
3
+ export { GLFramebuffer as TextmodeFramebuffer } from './rendering';
4
+ export { TextmodeColor } from './textmode/TextmodeColor';
5
+ export { TextmodeCanvas } from './textmode/Canvas';
6
+ export { TextmodeGrid } from './textmode/Grid';
7
+ export type { TextmodeOptions } from './textmode/types';
8
+ export type { TextmodeFramebufferOptions } from './rendering/webgl';
9
+ /**
10
+ * All media conversion related modules and types.
11
+ *
12
+ * Responsible for converting images and videos into textmode-renderable formats
13
+ * using various conversion strategies, like brightness- or edge-detection-based conversion.
14
+ *
15
+ * `textmode.js` only comes with a built-in `'brightness'`-based conversion strategy,
16
+ * but custom strategies can be registered via {@link TextmodeConversionManager.register}.
17
+ */
18
+ export * as conversion from './textmode/conversion';
19
+ /**
20
+ * Plugin system types for extending textmode.js functionality.
21
+ *
22
+ * Plugins can:
23
+ * - Add methods to TextmodeLayer instances (e.g., `.synth()`)
24
+ * - Hook into the render lifecycle (pre/post draw, per-layer rendering)
25
+ * - React to layer creation and disposal events
26
+ * - Access the WebGL renderer, framebuffers, and other internals
27
+ *
28
+ * @example
29
+ * ```ts
30
+ * import type { TextmodePlugin, TextmodePluginAPI } from 'textmode.js/plugins';
31
+ *
32
+ * const MyPlugin: TextmodePlugin = {
33
+ * name: 'my-plugin',
34
+ * version: '1.0.0',
35
+ * install(textmodifier, api) {
36
+ * // Extend layers with a new method
37
+ * api.extendLayer('setMyState', function(value: number) {
38
+ * // `this` is bound to the TextmodeLayer instance
39
+ * this.setPluginState('my-plugin', { value });
40
+ * });
41
+ *
42
+ * // Hook into layer rendering
43
+ * api.registerLayerPreRenderHook((layer) => {
44
+ * const state = layer.getPluginState<{ value: number }>('my-plugin');
45
+ * if (state && state.value > 0.5) {
46
+ * // Render custom content based on plugin state
47
+ * }
48
+ * });
49
+ * }
50
+ * };
51
+ * ```
52
+ */
53
+ export * as plugins from './textmode/managers/PluginManager';
54
+ /**
55
+ * All filter related modules and types.
56
+ *
57
+ * Provides various image processing filters that can be applied in sequence on a layer's textmode-converted output,
58
+ * such as blur, sharpen, edge detection, and color adjustments. Filters can also be applied globally to all layers as post-processing effects.
59
+ *
60
+ * While `textmode.js` only offers a basic set of filters, additional filters can be implemented and registered via the {@link TextmodeFilterManager},
61
+ * which is accessible through {@link Textmodifier.filters}.
62
+ */
63
+ export * as filters from './textmode/filters';
64
+ export { TextmodeErrorLevel } from './errors/ErrorHandler';
65
+ export { TextmodeError } from './errors/Error';
66
+ export { GLShader as TextmodeShader } from './rendering/webgl/core/Shader';
67
+ export { Textmode as textmode } from './Textmode';
68
+ /** All loading screen related modules and types. */
69
+ export * as loading from './textmode/loading';
70
+ /** All loadable assets related to textmode rendering. */
71
+ export * as loadables from './textmode/loadables';
72
+ /** All types and interfaces related to input event handling. */
73
+ export * as input from './textmode/managers';
74
+ /** All modules and types related to multi-layered textmode rendering. */
75
+ export * as layering from './textmode/layers';
76
+ /**
77
+ * Exports the create, setErrorLevel, and version functions from the Textmode class for UMD compatibility,
78
+ * so calls like `textmode.create()` can be used.
79
+ */
80
+ /** @ignore */
81
+ export declare const create: typeof Textmode.create;
82
+ /** @ignore */
83
+ export declare const setErrorLevel: typeof Textmode.setErrorLevel;
84
+ /** @ignore */
85
+ export declare const version: string;
@@ -0,0 +1,4 @@
1
+ export { GLShader } from './webgl/core/Shader';
2
+ export type { UniformValue } from './webgl/types/UniformTypes';
3
+ export { GLRenderer } from './webgl/core/Renderer';
4
+ export { GLFramebuffer } from './webgl/core/Framebuffer';
@@ -0,0 +1,89 @@
1
+ import { RenderState } from '../state/RenderState';
2
+ import type { DrawCommand } from '../types/DrawCommand';
3
+ import type { Material } from '../materials/Material';
4
+ import type { RectangleParams, LineParams, EllipseParams, ArcParams, TriangleParams, BezierCurveParams } from '../types/GeometryTypes';
5
+ /**
6
+ * Global draw queue preserving user-issued draw order across geometry types.
7
+ *
8
+ * Performance optimizations:
9
+ * - Object pooling: Command slots are reused across frames to eliminate allocations
10
+ * - Direct property assignment: Maintains V8 hidden classes for optimal JIT performance
11
+ * - Type-specific enqueue methods: Eliminates conditional branching
12
+ */
13
+ export declare class DrawQueue implements Iterable<DrawCommand> {
14
+ private _commands;
15
+ private _nextId;
16
+ private _size;
17
+ /** Reserve or reuse a pooled slot */
18
+ private _acquireSlot;
19
+ /**
20
+ * Enqueue a rectangle draw command.
21
+ * Zero-allocation in steady state (reuses pooled slots).
22
+ * Direct property assignment preserves V8 hidden classes for optimal performance.
23
+ *
24
+ * @param params Rectangle parameters
25
+ * @param renderState Current render state
26
+ * @param material Material to use for rendering
27
+ * @returns Command ID
28
+ */
29
+ $enqueueRectangle(params: RectangleParams, renderState: RenderState, material: Material): number;
30
+ /**
31
+ * Enqueue a line draw command.
32
+ * Zero-allocation in steady state (reuses pooled slots).
33
+ * Direct property assignment preserves V8 hidden classes for optimal performance.
34
+ *
35
+ * @param params Line parameters
36
+ * @param renderState Current render state
37
+ * @param material Material to use for rendering
38
+ * @returns Command ID
39
+ */
40
+ $enqueueLine(params: LineParams, renderState: RenderState, material: Material): number;
41
+ /**
42
+ * Enqueue an ellipse draw command.
43
+ * Zero-allocation in steady state (reuses pooled slots).
44
+ * Direct property assignment preserves V8 hidden classes for optimal performance.
45
+ *
46
+ * @param params Ellipse parameters
47
+ * @param renderState Current render state
48
+ * @param material Material to use for rendering
49
+ * @returns Command ID
50
+ */
51
+ $enqueueEllipse(params: EllipseParams, renderState: RenderState, material: Material): number;
52
+ /**
53
+ * Enqueue an arc draw command.
54
+ * Zero-allocation in steady state (reuses pooled slots).
55
+ * Direct property assignment preserves V8 hidden classes for optimal performance.
56
+ *
57
+ * @param params Arc parameters
58
+ * @param renderState Current render state
59
+ * @param material Material to use for rendering
60
+ * @returns Command ID
61
+ */
62
+ $enqueueArc(params: ArcParams, renderState: RenderState, material: Material): number;
63
+ /**
64
+ * Enqueue a triangle draw command.
65
+ * Zero-allocation in steady state (reuses pooled slots).
66
+ * Direct property assignment preserves V8 hidden classes for optimal performance.
67
+ *
68
+ * @param params Triangle parameters
69
+ * @param renderState Current render state
70
+ * @param material Material to use for rendering
71
+ * @returns Command ID
72
+ */
73
+ $enqueueTriangle(params: TriangleParams, renderState: RenderState, material: Material): number;
74
+ /**
75
+ * Enqueue a bezier curve draw command.
76
+ * Zero-allocation in steady state (reuses pooled slots).
77
+ * Direct property assignment preserves V8 hidden classes for optimal performance.
78
+ *
79
+ * @param params Bezier curve parameters
80
+ * @param renderState Current render state
81
+ * @param material Material to use for rendering
82
+ * @returns Command ID
83
+ */
84
+ $enqueueBezierCurve(params: BezierCurveParams, renderState: RenderState, material: Material): number;
85
+ /** Clear all queued commands */
86
+ $clear(): void;
87
+ /** Iterate in the exact order of insertion */
88
+ [Symbol.iterator](): Iterator<DrawCommand>;
89
+ }
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Minimal VAO manager that caches unit-geometry attribute setup per (program, geometry type).
3
+ * It binds only non-instanced attributes (a_position, a_texCoord). Instanced attributes are
4
+ * still configured by InstanceBatch per draw to keep buffers flexible.
5
+ */
6
+ import { GLShader } from '../core/Shader';
7
+ import type { UnitGeometryData } from '../types/GeometryTypes';
8
+ export declare class GeometryAttributeCache {
9
+ private _gl;
10
+ private _cache;
11
+ private _currentVAO;
12
+ constructor(gl: WebGL2RenderingContext);
13
+ /** Bind or create a VAO for the given program and geometry key. */
14
+ $bind(shader: GLShader, geometryKey: string, unit: UnitGeometryData, geometryBuffer: WebGLBuffer): void;
15
+ private _onShaderDisposed;
16
+ $unbind(): void;
17
+ $dispose(): void;
18
+ }
@@ -0,0 +1,83 @@
1
+ import { GLShader } from '../core/Shader';
2
+ /**
3
+ * Manages WebGL attribute binding and GPU buffer synchronization.
4
+ *
5
+ * Responsibilities:
6
+ * - WebGL buffer creation and management
7
+ * - GPU data upload (full buffer or sub-buffer updates)
8
+ * - Attribute location caching per shader program
9
+ * - Vertex attribute binding/unbinding
10
+ *
11
+ * This class is the ONLY one that knows about WebGL state.
12
+ * It has NO knowledge of instance data layout details (delegates to InstanceAttributeLayout).
13
+ */
14
+ export declare class InstanceAttributeBinder {
15
+ private _gl;
16
+ private _glBuffer;
17
+ private _bufferCapacity;
18
+ private _attributeLocationCache;
19
+ private _version;
20
+ private _programSetupCache;
21
+ /**
22
+ * Create a new attribute binder.
23
+ * @param gl WebGL2 rendering context
24
+ * @param initialCapacity Initial GPU buffer capacity in instances
25
+ */
26
+ constructor(gl: WebGL2RenderingContext, initialCapacity?: number);
27
+ /**
28
+ * Create or recreate the WebGL buffer with specified capacity.
29
+ * @param capacity Buffer capacity in number of instances
30
+ */
31
+ private _createBuffer;
32
+ /**
33
+ * Recreate GPU buffer with new capacity.
34
+ * Called when CPU buffer grows beyond current GPU buffer capacity.
35
+ *
36
+ * @param newCapacity New capacity in number of instances
37
+ */
38
+ $recreateBuffer(newCapacity: number): void;
39
+ /**
40
+ * Get the current GPU buffer capacity in instances.
41
+ */
42
+ get $capacity(): number;
43
+ /**
44
+ * Upload instance data to GPU buffer.
45
+ *
46
+ * Performance-critical: This uploads data to the GPU every frame.
47
+ * Optimizations applied:
48
+ * - Only uploads used portion of buffer (not full capacity)
49
+ * - Uses bufferSubData for partial updates (faster than bufferData)
50
+ * - Binds buffer once and keeps it bound for attribute setup
51
+ *
52
+ * Pattern follows modern graphics engines (three.js, babylon.js):
53
+ * - Minimize data transfer size
54
+ * - Avoid redundant buffer bindings
55
+ * - Use streaming pattern for per-frame data
56
+ *
57
+ * @param data Float32Array containing instance data to upload
58
+ * @param instanceCount Number of instances in the data
59
+ */
60
+ $upload(data: Float32Array, instanceCount: number): void;
61
+ /**
62
+ * Get cached attribute locations for a shader program.
63
+ * Queries locations once per program and caches them for performance.
64
+ *
65
+ * @param program WebGL shader program
66
+ * @returns Map of attribute name to location
67
+ */
68
+ private _getAttributeLocations;
69
+ /**
70
+ * Bind instance buffer and configure vertex attributes for instanced rendering.
71
+ *
72
+ * IMPORTANT: Assumes instance buffer is already bound to gl.ARRAY_BUFFER from upload().
73
+ * If upload() was not called immediately before this, the buffer will not be bound correctly.
74
+ * The buffer remains bound after this call for use by the draw command.
75
+ *
76
+ * @param shader The shader program to bind attributes for
77
+ */
78
+ $bindAttributes(shader: GLShader): void;
79
+ /**
80
+ * Dispose of WebGL resources.
81
+ */
82
+ $dispose(): void;
83
+ }
@@ -0,0 +1,87 @@
1
+ import { type InstanceData } from './InstanceData';
2
+ import { GLShader } from '../core/Shader';
3
+ import { InstanceBuffer } from './InstanceBuffer';
4
+ import { InstanceWriter, type InstanceWriteData } from './InstanceWriter';
5
+ export type { InstanceWriteData };
6
+ /**
7
+ * High-performance instance batch manager for WebGL instanced rendering.
8
+ *
9
+ * This is a facade that orchestrates three specialized components:
10
+ * - InstanceBuffer: CPU-side memory management
11
+ * - InstanceWriter: Zero-allocation instance data writing
12
+ * - InstanceAttributeBinder: WebGL state and attribute binding
13
+ *
14
+ * Features:
15
+ * - Direct Float32Array writing (zero allocations per instance)
16
+ * - Automatic buffer growth with configurable growth factor
17
+ * - Efficient sub-buffer updates for animated content
18
+ * - Optimized WebGL attribute binding
19
+ * - Struct-of-arrays layout for maximum GPU efficiency
20
+ *
21
+ * Architecture:
22
+ * This class maintains the same public API as before but delegates work
23
+ * to specialized components. This improves maintainability and testability
24
+ * while preserving performance.
25
+ */
26
+ export declare class InstanceBatch {
27
+ private _gl;
28
+ private readonly _buffer;
29
+ private readonly _writer;
30
+ private readonly _binder;
31
+ /**
32
+ * Creates a new instance batch.
33
+ * @param gl WebGL2 rendering context
34
+ * @param initialCapacity Initial buffer capacity (number of instances)
35
+ * @param growthFactor Buffer growth factor when capacity is exceeded
36
+ */
37
+ constructor(gl: WebGL2RenderingContext, initialCapacity?: number, growthFactor?: number);
38
+ /**
39
+ * Add a new instance to the batch (legacy object-based path).
40
+ * @param instance Instance data to add
41
+ * @returns Index of the added instance
42
+ */
43
+ $addInstance(instance: InstanceData): number;
44
+ /**
45
+ * Synchronize GPU buffer capacity with CPU buffer capacity.
46
+ * Must be called after writing directly to the instance buffer.
47
+ */
48
+ $syncGPUBuffer(): void;
49
+ /**
50
+ * Get the underlying instance buffer for direct write access.
51
+ * @internal Performance optimization for BaseGeometry
52
+ */
53
+ get instanceBuffer(): InstanceBuffer;
54
+ /**
55
+ * Get the underlying instance writer for direct write access.
56
+ * @internal Performance optimization for BaseGeometry
57
+ */
58
+ get writer(): InstanceWriter;
59
+ /**
60
+ * Get the current number of instances in the batch.
61
+ */
62
+ get $count(): number;
63
+ /**
64
+ * Check if the batch is empty.
65
+ */
66
+ get $isEmpty(): boolean;
67
+ /**
68
+ * Clear all instances from the batch.
69
+ */
70
+ $clear(): void;
71
+ /**
72
+ * Bind instance buffer and configure vertex attributes for instanced rendering.
73
+ * @param shader The shader program to bind attributes for
74
+ */
75
+ $bindAttributes(shader: GLShader): void;
76
+ /**
77
+ * Execute instanced draw call for all instances in the batch.
78
+ * @param primitiveType WebGL primitive type (e.g., gl.TRIANGLES)
79
+ * @param vertexCount Number of vertices in the base geometry
80
+ */
81
+ $draw(primitiveType: number, vertexCount: number): void;
82
+ /**
83
+ * Dispose of WebGL resources.
84
+ * Call this when the batch is no longer needed.
85
+ */
86
+ $dispose(): void;
87
+ }