textmode.js 0.1.9 → 0.2.0-beta.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.
Files changed (63) hide show
  1. package/README.md +4 -4
  2. package/dist/textmode.esm.js +1418 -1481
  3. package/dist/textmode.esm.min.js +1500 -1563
  4. package/dist/textmode.umd.js +19 -56
  5. package/dist/textmode.umd.min.js +20 -57
  6. package/dist/types/Textmode.d.ts +10 -38
  7. package/dist/types/export/base/DataExtractor.d.ts +3 -3
  8. package/dist/types/export/image/ImageExporter.d.ts +4 -11
  9. package/dist/types/export/image/types.d.ts +2 -3
  10. package/dist/types/export/svg/SVGExporter.d.ts +1 -1
  11. package/dist/types/export/svg/types.d.ts +1 -0
  12. package/dist/types/export/txt/TXTExporter.d.ts +1 -1
  13. package/dist/types/export/txt/types.d.ts +2 -2
  14. package/dist/types/index.d.ts +1 -7
  15. package/dist/types/rendering/index.d.ts +0 -1
  16. package/dist/types/rendering/webgl/DrawQueue.d.ts +26 -0
  17. package/dist/types/rendering/webgl/Framebuffer.d.ts +41 -40
  18. package/dist/types/rendering/webgl/InstanceBatch.d.ts +91 -0
  19. package/dist/types/rendering/webgl/InstanceData.d.ts +65 -0
  20. package/dist/types/rendering/webgl/RenderPipeline.d.ts +15 -0
  21. package/dist/types/rendering/webgl/RenderState.d.ts +71 -0
  22. package/dist/types/rendering/webgl/Renderer.d.ts +54 -81
  23. package/dist/types/rendering/webgl/Shader.d.ts +11 -16
  24. package/dist/types/rendering/webgl/VAOManager.d.ts +15 -0
  25. package/dist/types/rendering/webgl/geometries/Arc.d.ts +16 -0
  26. package/dist/types/rendering/webgl/geometries/BaseGeometry.d.ts +35 -29
  27. package/dist/types/rendering/webgl/geometries/BezierCurve.d.ts +22 -0
  28. package/dist/types/rendering/webgl/geometries/Ellipse.d.ts +20 -0
  29. package/dist/types/rendering/webgl/geometries/Line.d.ts +13 -4
  30. package/dist/types/rendering/webgl/geometries/Rectangle.d.ts +13 -8
  31. package/dist/types/rendering/webgl/geometries/Triangle.d.ts +20 -0
  32. package/dist/types/rendering/webgl/geometries/index.d.ts +4 -1
  33. package/dist/types/rendering/webgl/index.d.ts +17 -1
  34. package/dist/types/rendering/webgl/types/DrawCommand.d.ts +9 -0
  35. package/dist/types/rendering/webgl/types/GeometryTypes.d.ts +144 -0
  36. package/dist/types/rendering/webgl/types/RenderTypes.d.ts +12 -0
  37. package/dist/types/textmode/AnimationController.d.ts +81 -0
  38. package/dist/types/textmode/Canvas.d.ts +18 -19
  39. package/dist/types/textmode/Grid.d.ts +1 -34
  40. package/dist/types/textmode/Textmodifier.d.ts +36 -277
  41. package/dist/types/textmode/font/CharacterColorMapper.d.ts +3 -3
  42. package/dist/types/textmode/font/TextmodeFont.d.ts +6 -11
  43. package/dist/types/textmode/font/types.d.ts +1 -1
  44. package/dist/types/textmode/font/typr/types.d.ts +1 -1
  45. package/dist/types/textmode/font/utils/index.d.ts +0 -1
  46. package/dist/types/textmode/mixins/AnimationMixin.d.ts +120 -0
  47. package/dist/types/textmode/mixins/ExportMixin.d.ts +4 -6
  48. package/dist/types/textmode/mixins/FontMixin.d.ts +4 -10
  49. package/dist/types/textmode/mixins/RenderingMixin.d.ts +224 -246
  50. package/dist/types/textmode/mixins/TextmodifierMixin.d.ts +13 -4
  51. package/dist/types/textmode/mixins/index.d.ts +2 -2
  52. package/package.json +1 -1
  53. package/dist/types/ColorPalette.d.ts +0 -35
  54. package/dist/types/rendering/core/Framebuffer.d.ts +0 -140
  55. package/dist/types/rendering/core/Shader.d.ts +0 -59
  56. package/dist/types/rendering/core/index.d.ts +0 -2
  57. package/dist/types/textmode/ConversionPipeline.d.ts +0 -110
  58. package/dist/types/textmode/converters/BrightnessConverter.d.ts +0 -58
  59. package/dist/types/textmode/converters/Converter.d.ts +0 -69
  60. package/dist/types/textmode/converters/FeatureConverter.d.ts +0 -128
  61. package/dist/types/textmode/converters/index.d.ts +0 -3
  62. package/dist/types/textmode/font/utils/FontConstants.d.ts +0 -60
  63. package/dist/types/textmode/mixins/ConversionMixin.d.ts +0 -62
@@ -2,7 +2,6 @@
2
2
  * TXT-specific type definitions for the textmode.js library.
3
3
  */
4
4
  import type { TextmodeFont, TextmodeGrid } from '../..';
5
- import type { TextmodeConversionPipeline } from '../../textmode/ConversionPipeline';
6
5
  /**
7
6
  * Options for exporting the textmode content to TXT format.
8
7
  */
@@ -40,12 +39,13 @@ export interface TXTGenerationOptions {
40
39
  preserveTrailingSpaces: boolean;
41
40
  lineEnding: 'lf' | 'crlf';
42
41
  emptyCharacter: string;
42
+ filename: string;
43
43
  }
44
44
  /**
45
45
  * Data required for textmode rendering export
46
46
  */
47
47
  export interface TextmodeRenderingData {
48
- pipeline: TextmodeConversionPipeline;
48
+ pipeline: any;
49
49
  grid: TextmodeGrid;
50
50
  font: TextmodeFont;
51
51
  }
@@ -3,18 +3,12 @@ export { Textmodifier } from './textmode/Textmodifier';
3
3
  export { TextmodeFont } from './textmode/font';
4
4
  export { TextmodeCanvas } from './textmode/Canvas';
5
5
  export { TextmodeGrid } from './textmode/Grid';
6
- export type { TextmodeOptions, TextmodeCaptureSource } from './textmode/Textmodifier';
6
+ export type { TextmodeOptions } from './textmode/Textmodifier';
7
7
  export type { TextmodeCharacter } from './textmode/font';
8
8
  /** All types related to export options for different formats. */
9
9
  export * as export from './export';
10
- export { TextmodeConversionPipeline } from './textmode/ConversionPipeline';
11
- export { TextmodeColorPalette } from './ColorPalette';
12
10
  export { TextmodeErrorLevel } from './errors/ErrorHandler';
13
- /** Contains all converters that can be added to a rendering pipeline to shape the textmode output. */
14
- export * as converters from './textmode/converters';
15
11
  export { Textmode as textmode } from './Textmode';
16
- /** Contains all rendering-related utilities and components. */
17
- export * as rendering from './rendering/core';
18
12
  /**
19
13
  * Exports the create, setErrorLevel, and version functions from the Textmode class for UMD compatibility,
20
14
  * so calls like `textmode.create()` can be used.
@@ -1,4 +1,3 @@
1
- export * from './core';
2
1
  export { GLShader as Shader } from './webgl/Shader';
3
2
  export { GLRenderer } from './webgl/Renderer';
4
3
  export { GLFramebuffer } from './webgl/Framebuffer';
@@ -0,0 +1,26 @@
1
+ import type { DrawCommand } from './types/DrawCommand';
2
+ /**
3
+ * Global draw queue preserving user-issued draw order across geometry types.
4
+ */
5
+ export declare class DrawQueue implements Iterable<DrawCommand> {
6
+ private _commands;
7
+ private _nextId;
8
+ private _size;
9
+ /** Reserve or reuse a pooled slot */
10
+ private _acquireSlot;
11
+ /** Specialized enqueues (zero-alloc on steady state) */
12
+ $enqueueRectangle(x: number, y: number, width: number, height: number, renderState: any): number;
13
+ $enqueueLine(x1: number, y1: number, x2: number, y2: number, thickness: number | undefined, renderState: any): number;
14
+ $enqueueEllipse(x: number, y: number, width: number, height: number, renderState: any): number;
15
+ $enqueueArc(x: number, y: number, width: number, height: number, start: number, stop: number, renderState: any): number;
16
+ $enqueueTriangle(x1: number, y1: number, x2: number, y2: number, x3: number, y3: number, renderState: any): number;
17
+ $enqueueBezierCurve(x1: number, y1: number, cp1x: number, cp1y: number, cp2x: number, cp2y: number, x2: number, y2: number, thickness: number | undefined, renderState: any): number;
18
+ /** Number of queued commands */
19
+ get length(): number;
20
+ /** True if no commands queued */
21
+ get isEmpty(): boolean;
22
+ /** Clear all queued commands */
23
+ $clear(): void;
24
+ /** Iterate in the exact order of insertion */
25
+ [Symbol.iterator](): Iterator<DrawCommand>;
26
+ }
@@ -1,69 +1,70 @@
1
- import { Framebuffer, type FramebufferOptions } from '../core/Framebuffer';
1
+ export type FramebufferOptions = {
2
+ /** Texture filtering mode */
3
+ filter?: 'nearest' | 'linear';
4
+ /** Texture wrapping mode */
5
+ wrap?: 'clamp' | 'repeat';
6
+ /** Texture format */
7
+ format?: 'rgba' | 'rgb';
8
+ /** Data type for texture data */
9
+ type?: 'unsigned_byte' | 'float';
10
+ };
2
11
  /**
3
- * WebGL implementation of the framebuffer abstraction.
12
+ * WebGL2 implementation of the framebuffer abstraction.
4
13
  * Provides GPU-accelerated render targets with automatic texture creation.
14
+ * Supports both single-texture and Multiple Render Targets (MRT) functionality.
5
15
  * Can also be used as a standalone texture (without render target functionality).
6
16
  */
7
- export declare class GLFramebuffer extends Framebuffer {
17
+ export declare class GLFramebuffer {
18
+ protected _width: number;
19
+ protected _height: number;
20
+ protected _options: FramebufferOptions;
21
+ protected _pixels: Uint8Array | null;
8
22
  private _gl;
9
23
  private _framebuffer;
10
- private _texture;
24
+ private _textures;
25
+ private _attachmentCount;
11
26
  private _previousState;
12
- constructor(gl: WebGLRenderingContext, width: number, height?: number, options?: FramebufferOptions);
13
- /**
14
- * Execute a function with this framebuffer bound, then restore previous binding
15
- */
16
- private _withFramebufferBound;
17
- private _createTexture;
18
- private _updateTextureSize;
19
- private _attachTexture;
27
+ private _attachmentPixels;
28
+ constructor(gl: WebGL2RenderingContext, width: number, height?: number, attachmentCount?: number, options?: FramebufferOptions);
29
+ private _createTextures;
30
+ private _attachTextures;
20
31
  /**
21
32
  * Update the framebuffer texture with canvas or video content
33
+ * Note: Only updates the first attachment in multi-attachment mode
22
34
  */
23
35
  $update(source: HTMLCanvasElement | HTMLVideoElement): void;
24
36
  /**
25
- * Update the framebuffer texture with pixel data
37
+ * Resize the framebuffer
26
38
  */
27
- updatePixels(pixelData: Uint8Array, width: number, height: number): void;
39
+ $resize(width: number, height: number): void;
28
40
  /**
29
- * Resize the framebuffer
41
+ * Read pixels from a specific color attachment into an RGBA Uint8Array.
42
+ * Rows are flipped to top-left origin to match row-major iteration in exporters.
30
43
  */
31
- resize(width: number, height: number): void;
44
+ $readAttachment(attachmentIndex: number): Uint8Array;
45
+ /** Read and cache all attachments. */
46
+ $readAll(): void;
32
47
  /**
33
48
  * Begin rendering to this framebuffer
34
49
  */
35
- begin(): void;
50
+ $begin(): void;
36
51
  /**
37
52
  * End rendering to this framebuffer and restore previous state
38
53
  */
39
- end(): void;
40
- /**
41
- * Load pixel data from the framebuffer into the pixels array
42
- */
43
- loadPixels(): void;
44
- /**
45
- * Gets a pixel or a region of pixels from the framebuffer.
46
- *
47
- * The version of `get()` with no parameters returns pixel data for the entire framebuffer.
48
- * The version of `get()` with two parameters interprets them as coordinates and returns
49
- * an array with the `[R, G, B, A]` values of the pixel at the given point.
50
- * The version of `get()` with four parameters interprets them as coordinates and dimensions
51
- * and returns pixel data for the specified region.
52
- *
53
- * @param x x-coordinate of the pixel (optional)
54
- * @param y y-coordinate of the pixel (optional)
55
- * @param w width of the region (optional)
56
- * @param h height of the region (optional)
57
- * @returns Uint8Array for regions or number array for single pixel
58
- */
59
- get(): Uint8Array;
60
- get(x: number, y: number): [number, number, number, number];
61
- get(x: number, y: number, w: number, h: number): Uint8Array;
54
+ $end(): void;
62
55
  /**
63
56
  * Dispose of WebGL resources used by this framebuffer.
64
57
  * This method is idempotent and safe to call multiple times.
65
58
  */
66
59
  $dispose(): void;
60
+ get width(): number;
61
+ get height(): number;
62
+ get pixels(): Uint8Array | null;
63
+ get options(): FramebufferOptions;
67
64
  get framebuffer(): WebGLFramebuffer | null;
68
65
  get texture(): WebGLTexture;
66
+ get textures(): WebGLTexture[];
67
+ get attachmentCount(): number;
68
+ /** Return a cached copy of pixels for an attachment if previously read, else null. */
69
+ getAttachmentPixels(attachmentIndex: number): Uint8Array | null;
69
70
  }
@@ -0,0 +1,91 @@
1
+ import type { InstanceData } from './InstanceData';
2
+ import { GLShader } from './Shader';
3
+ /**
4
+ * High-performance instance batch manager for WebGL instanced rendering.
5
+ * Handles efficient buffer management, automatic capacity growth, and WebGL attribute setup.
6
+ *
7
+ * Features:
8
+ * - Automatic buffer growth with configurable growth factor
9
+ * - Double buffering for smooth updates
10
+ * - Efficient sub-buffer updates for animated content
11
+ * - Optimized WebGL attribute binding
12
+ * - Memory pooling to reduce garbage collection
13
+ */
14
+ export declare class InstanceBatch {
15
+ private _gl;
16
+ private _instances;
17
+ private _capacity;
18
+ private _growthFactor;
19
+ private _instanceBuffer;
20
+ private _needsUpload;
21
+ private _lastUploadedCount;
22
+ private _attributeLocationCache;
23
+ private _packedDataCache;
24
+ /**
25
+ * Creates a new instance batch.
26
+ * @param gl WebGL2 rendering context
27
+ * @param initialCapacity Initial buffer capacity (number of instances)
28
+ * @param growthFactor Buffer growth factor when capacity is exceeded
29
+ */
30
+ constructor(gl: WebGL2RenderingContext, initialCapacity?: number, growthFactor?: number);
31
+ /**
32
+ * Add a new instance to the batch.
33
+ * @param instance Instance data to add
34
+ * @returns Index of the added instance
35
+ */
36
+ $addInstance(instance: InstanceData): number;
37
+ /**
38
+ * Get the current number of instances in the batch.
39
+ */
40
+ get count(): number;
41
+ /**
42
+ * Check if the batch is empty.
43
+ */
44
+ get isEmpty(): boolean;
45
+ /**
46
+ * Clear all instances from the batch.
47
+ */
48
+ clear(): void;
49
+ /**
50
+ * Ensure buffer capacity can handle the specified number of instances.
51
+ * Automatically grows buffer if needed.
52
+ * @param requiredInstances Number of instances that need to fit
53
+ */
54
+ private _ensureCapacity;
55
+ /**
56
+ * Create or recreate the WebGL instance buffer.
57
+ */
58
+ private _createBuffer;
59
+ /**
60
+ * Upload instance data to GPU buffer.
61
+ * Uses efficient sub-buffer updates when possible.
62
+ */
63
+ $upload(): void;
64
+ /**
65
+ * Get cached attribute locations for a shader program.
66
+ * @param program WebGL shader program
67
+ * @returns Map of attribute name to location
68
+ */
69
+ private _getAttributeLocations;
70
+ /**
71
+ * Bind instance buffer and configure vertex attributes for instanced rendering.
72
+ * @param shader The shader program to bind attributes for
73
+ */
74
+ $bindAttributes(shader: GLShader): void;
75
+ /**
76
+ * Unbind instance attributes to clean up WebGL state.
77
+ * @param shader The shader program to unbind attributes for
78
+ */
79
+ $unbindAttributes(shader: GLShader): void;
80
+ /**
81
+ * Execute instanced draw call for all instances in the batch.
82
+ * @param primitiveType WebGL primitive type (e.g., gl.TRIANGLES)
83
+ * @param vertexCount Number of vertices in the base geometry
84
+ */
85
+ $draw(primitiveType: number, vertexCount: number): void;
86
+ /**
87
+ * Dispose of WebGL resources.
88
+ * Call this when the batch is no longer needed.
89
+ */
90
+ $dispose(): void;
91
+ }
@@ -0,0 +1,65 @@
1
+ /**
2
+ * Core data structure representing a single instance in batched rendering.
3
+ * Contains all necessary data for ASCII character rendering via MRT.
4
+ */
5
+ export interface InstanceData {
6
+ position: [number, number];
7
+ size: [number, number];
8
+ character: [number, number, number];
9
+ primaryColor: [number, number, number, number];
10
+ secondaryColor: [number, number, number, number];
11
+ rotation: [number, number];
12
+ transform: [number, number, number];
13
+ globalRotation: number;
14
+ rotationCenter: [number, number];
15
+ arcAngles?: [number, number];
16
+ bezierControlPoint1?: [number, number];
17
+ bezierControlPoint2?: [number, number];
18
+ bezierStartPoint?: [number, number];
19
+ bezierEndPoint?: [number, number];
20
+ }
21
+ /**
22
+ * Optimized packed instance data layout for GPU upload.
23
+ * Designed for efficient WebGL attribute binding and minimal memory usage.
24
+ *
25
+ * Total size: 132 bytes per instance (with Arc + Bezier support)
26
+ * Layout designed to minimize GPU bandwidth and maximize cache efficiency.
27
+ */
28
+ export declare class PackedInstanceData {
29
+ static readonly BYTES_PER_INSTANCE = 132;
30
+ static readonly FLOATS_PER_INSTANCE = 33;
31
+ /**
32
+ * Pack instance data into a Float32Array for efficient GPU upload.
33
+ * @param instance The instance data to pack
34
+ * @param target Optional target array to write into (for reuse)
35
+ * @param offset Offset in the target array to start writing
36
+ * @returns Float32Array containing packed instance data
37
+ */
38
+ static $pack(instance: InstanceData, target?: Float32Array, offset?: number): Float32Array;
39
+ /**
40
+ * Pack multiple instances into a single Float32Array for batch upload.
41
+ * @param instances Array of instance data to pack
42
+ * @returns Float32Array containing all packed instance data
43
+ */
44
+ static $packBatch(instances: InstanceData[]): Float32Array;
45
+ }
46
+ /**
47
+ * WebGL attribute configuration for instance data.
48
+ * Defines how packed instance data maps to vertex shader attributes.
49
+ */
50
+ export interface InstanceAttributeConfig {
51
+ location: number;
52
+ size: number;
53
+ type: number;
54
+ normalized: boolean;
55
+ stride: number;
56
+ offset: number;
57
+ divisor: number;
58
+ }
59
+ /**
60
+ * Pre-configured attribute layouts for efficient WebGL setup.
61
+ */
62
+ export declare class InstanceAttributeLayout {
63
+ static readonly STRIDE = 132;
64
+ static readonly ATTRIBUTES: Record<string, InstanceAttributeConfig>;
65
+ }
@@ -0,0 +1,15 @@
1
+ import type { IGeometry } from './types/GeometryTypes';
2
+ import { GeometryType } from './types/GeometryTypes';
3
+ import type { RenderContext } from './types/RenderTypes';
4
+ import type { DrawCommand } from './types/DrawCommand';
5
+ /**
6
+ * Execute draw commands exactly in the order they were enqueued while
7
+ * still batching consecutive commands of the same geometry type to minimize
8
+ * state changes and buffer uploads.
9
+ */
10
+ export declare class RenderPipeline {
11
+ private readonly _vaoMgr;
12
+ private readonly _gl;
13
+ constructor(gl: WebGL2RenderingContext);
14
+ $execute(context: RenderContext, commands: Iterable<DrawCommand>, geometries: Map<GeometryType, IGeometry>): void;
15
+ }
@@ -0,0 +1,71 @@
1
+ /**
2
+ * Represents a snapshot of the current rendering state
3
+ */
4
+ export interface IRenderState {
5
+ lineWeight: number;
6
+ rotation: number;
7
+ character: [number, number, number];
8
+ charColor: [number, number, number, number];
9
+ cellColor: [number, number, number, number];
10
+ flipHorizontally: boolean;
11
+ flipVertically: boolean;
12
+ invert: boolean;
13
+ charRotation: [number, number];
14
+ }
15
+ /**
16
+ * Manages rendering state and provides push/pop functionality for state management
17
+ */
18
+ export declare class RenderState {
19
+ private _currentLineWeight;
20
+ private _currentRotation;
21
+ private _currentCharacter;
22
+ private _currentCharColor;
23
+ private _currentCellColor;
24
+ private _flipHorizontally;
25
+ private _flipVertically;
26
+ private _invert;
27
+ private _charRotation;
28
+ private _canvasBackgroundColor;
29
+ private _stateStack;
30
+ /**
31
+ * Save the current rendering state to the state stack
32
+ */
33
+ $push(): void;
34
+ /**
35
+ * Restore the most recently saved rendering state from the state stack
36
+ */
37
+ $pop(): void;
38
+ /**
39
+ * Reset frame-specific state - called automatically after each frame.
40
+ * Note: This does not reset fill/stroke state as that should persist
41
+ * across frames and be managed by push/pop or explicit calls.
42
+ */
43
+ $reset(): void;
44
+ /**
45
+ * Write current state into an existing target object/struct to avoid allocations.
46
+ * The target is expected to have the same shape as RenderStateSnapshot, with mutable arrays.
47
+ */
48
+ $writeSnapshotTo(target: {
49
+ lineWeight: number;
50
+ rotation: number;
51
+ character: number[];
52
+ charColor: number[];
53
+ bgColor: number[];
54
+ flipHorizontally: boolean;
55
+ flipVertically: boolean;
56
+ invert: boolean;
57
+ charRotation: number[];
58
+ }): void;
59
+ get lineWeight(): number;
60
+ get canvasBackgroundColor(): [number, number, number, number];
61
+ $setLineWeight(weight: number): void;
62
+ $setRotation(degrees: number): void;
63
+ $setCharacter(character: [number, number, number]): void;
64
+ $setCharColor(r: number, g?: number, b?: number, a?: number): void;
65
+ $setCellColor(r: number, g?: number, b?: number, a?: number): void;
66
+ $setFlipHorizontally(flip: boolean): void;
67
+ $setFlipVertically(flip: boolean): void;
68
+ $setInvert(invert: boolean): void;
69
+ $setCharRotation(rotation: number): void;
70
+ $setCanvasBackground(r: number, g: number, b: number, a: number): void;
71
+ }
@@ -1,96 +1,39 @@
1
1
  import { GLFramebuffer } from "./Framebuffer";
2
- import type { Framebuffer, FramebufferOptions } from '../core/Framebuffer';
2
+ import type { FramebufferOptions } from '../webgl/Framebuffer';
3
3
  import { GLShader } from "./Shader";
4
- import type { UniformValue } from "../core";
4
+ import { RenderState } from "./RenderState";
5
5
  /**
6
6
  * Core WebGL renderer that manages the WebGL context and provides high-level rendering operations
7
7
  */
8
8
  export declare class GLRenderer {
9
9
  private _gl;
10
- private _imageShader;
11
- private _solidColorShader;
12
10
  private _currentShader;
13
- private _rectangleGeometry;
14
- private _lineGeometry;
15
- private _currentFillColor;
16
- private _fillMode;
17
- private _currentStrokeColor;
18
- private _currentStrokeWeight;
19
- private _strokeMode;
20
- private _currentRotation;
21
- private _stateStack;
22
- constructor(gl: WebGLRenderingContext | WebGL2RenderingContext);
11
+ private _fullscreenQuadBuffer;
12
+ private _ndcQuadBuffer;
13
+ private readonly _geometries;
14
+ private readonly _renderPipeline;
15
+ private readonly _drawQueue;
16
+ private _renderState;
17
+ constructor(gl: WebGL2RenderingContext);
18
+ /** Get or create a geometry instance */
19
+ private _getGeometry;
23
20
  /**
24
21
  * Set the current shader
25
22
  */
26
23
  $shader(shader: GLShader): void;
27
- /**
28
- * Sets the fill color for subsequent rendering operations
29
- * @param r Red component *(0-255)*
30
- * @param g Green component *(0-255, optional)*
31
- * @param b Blue component *(0-255, optional)*
32
- * @param a Alpha component *(0-255, optional)*
33
- */
34
- $fill(r: number, g?: number, b?: number, a?: number): void;
35
- /**
36
- * Sets the stroke color for subsequent rendering operations
37
- * @param r Red component *(0-255)*
38
- * @param g Green component *(0-255, optional)*
39
- * @param b Blue component *(0-255, optional)*
40
- * @param a Alpha component *(0-255, optional)*
41
- */
42
- $stroke(r: number, g?: number, b?: number, a?: number): void;
43
- /**
44
- * Sets the stroke weight (thickness) for subsequent stroke operations
45
- * @param weight The stroke thickness in pixels
46
- */
47
- $strokeWeight(weight: number): void;
48
- /**
49
- * Disables stroke rendering for subsequent operations
50
- */
51
- $noStroke(): void;
52
- /**
53
- * Disables fill rendering for subsequent operations
54
- */
55
- $noFill(): void;
56
- /**
57
- * Sets the rotation angle for subsequent rendering operations
58
- * @param degrees The rotation angle in degrees
59
- */
60
- $rotate(degrees: number): void;
61
- /**
62
- * Save the current rendering state (fill, stroke, etc.) to the state stack
63
- */
64
- $push(): void;
65
- /**
66
- * Restore the most recently saved rendering state from the state stack
67
- */
68
- $pop(): void;
69
- /**
70
- * Reset frame-specific state - called automatically after each frame.
71
- * Note: This does not reset fill/stroke state as that should persist
72
- * across frames and be managed by push/pop or explicit calls.
73
- */
74
- $reset(): void;
75
- /**
76
- * Detect if a fragment shader is WebGL2 by checking for version directive
77
- * @param fragmentSource The fragment shader source code
78
- * @returns true if WebGL2, false if WebGL1
79
- */
80
- private _detectShaderVersion;
81
24
  $createShader(vertexSource: string, fragmentSource: string): GLShader;
82
- $createFilterShader(fragmentSource: string): GLShader;
83
25
  /**
84
- * Set a uniform value for the current shader
26
+ * Draw a quad covering the pixel rectangle (x, y, width, height) on the canvas.
27
+ * The quad is converted to NDC and rendered with the current shader using only a_position.
28
+ * Origin: top-left (canvas space)
85
29
  */
86
- $setUniform(name: string, value: UniformValue): void;
30
+ $quadPixels(x: number, y: number, width: number, height: number): void;
87
31
  /**
88
- * Draw a rectangle with the current fill and/or stroke settings
32
+ * Draw a rectangle.
89
33
  */
90
34
  $rect(x: number, y: number, width: number, height: number): void;
91
35
  /**
92
- * Draw a line from (x1, y1) to (x2, y2) with the current stroke settings.
93
- * Lines only support stroke rendering - fill properties are ignored.
36
+ * Draw a line from (x1, y1) to (x2, y2).
94
37
  * @param x1 X-coordinate of the line start point
95
38
  * @param y1 Y-coordinate of the line start point
96
39
  * @param x2 X-coordinate of the line end point
@@ -98,13 +41,40 @@ export declare class GLRenderer {
98
41
  */
99
42
  $line(x1: number, y1: number, x2: number, y2: number): void;
100
43
  /**
101
- * Calculate rotation parameters for built-in shaders (NDC coordinates)
44
+ * Draw an ellipse.
45
+ * @param x X coordinate (center)
46
+ * @param y Y coordinate (center)
47
+ * @param width Ellipse width
48
+ * @param height Ellipse height
49
+ */
50
+ $ellipse(x: number, y: number, width: number, height: number): void;
51
+ /**
52
+ * Draw a triangle.
53
+ * @param x1 First vertex X coordinate
54
+ * @param y1 First vertex Y coordinate
55
+ * @param x2 Second vertex X coordinate
56
+ * @param y2 Second vertex Y coordinate
57
+ * @param x3 Third vertex X coordinate
58
+ * @param y3 Third vertex Y coordinate
59
+ */
60
+ $triangle(x1: number, y1: number, x2: number, y2: number, x3: number, y3: number): void;
61
+ /**
62
+ * Draw a bezier curve.
63
+ * @param x1 Start point X coordinate
64
+ * @param y1 Start point Y coordinate
65
+ * @param cp1x Control point 1 X coordinate
66
+ * @param cp1y Control point 1 Y coordinate
67
+ * @param cp2x Control point 2 X coordinate
68
+ * @param cp2y Control point 2 Y coordinate
69
+ * @param x2 End point X coordinate
70
+ * @param y2 End point Y coordinate
102
71
  */
103
- private _calculateRotationParams;
72
+ $bezierCurve(x1: number, y1: number, cp1x: number, cp1y: number, cp2x: number, cp2y: number, x2: number, y2: number): void;
104
73
  /**
105
74
  * Create a new framebuffer
106
75
  */
107
- $createFramebuffer(width: number, height: number, options?: FramebufferOptions): GLFramebuffer;
76
+ $createFramebuffer(width: number, height: number, attachmentCount?: number, options?: FramebufferOptions): GLFramebuffer;
77
+ $arc(x: number, y: number, width: number, height: number, start: number, stop: number): void;
108
78
  /**
109
79
  * Fill the current framebuffer with a solid color
110
80
  */
@@ -121,13 +91,16 @@ export declare class GLRenderer {
121
91
  * Get the WebGL context
122
92
  */
123
93
  get context(): WebGLRenderingContext;
94
+ get state(): RenderState;
95
+ /**
96
+ * Flush all batched instances for instanced rendering.
97
+ * This must be called at the end of each frame to actually render the batched geometry.
98
+ * @param shader The instanced shader to use for rendering
99
+ */
100
+ $flushInstances(shader: GLShader): void;
124
101
  /**
125
102
  * Dispose of all WebGL resources managed by this renderer.
126
103
  * This method is idempotent and safe to call multiple times.
127
104
  */
128
105
  $dispose(): void;
129
- /**
130
- * Render a framebuffer at a specific position with optional scaling
131
- */
132
- $image(source: Framebuffer, posX: number, posY: number, width?: number, height?: number): void;
133
106
  }
@@ -1,9 +1,13 @@
1
- import { Shader, type UniformValue } from '../core/Shader';
1
+ import { GLFramebuffer } from './Framebuffer';
2
+ /**
3
+ * Supported uniform value types
4
+ */
5
+ type UniformValue = number | boolean | number[] | Float32Array | Int32Array | GLFramebuffer | WebGLTexture;
2
6
  /**
3
7
  * WebGL implementation of the shader abstraction.
4
8
  * Provides GPU shader program management with automatic uniform handling.
5
9
  */
6
- export declare class GLShader extends Shader {
10
+ export declare class GLShader {
7
11
  private _gl;
8
12
  private _program;
9
13
  private _uniformLocations;
@@ -18,13 +22,6 @@ export declare class GLShader extends Shader {
18
22
  * @ignore
19
23
  */
20
24
  constructor(gl: WebGLRenderingContext, vertexSource: string, fragmentSource: string);
21
- /**
22
- * Factory method to create a shader from source object
23
- */
24
- static fromSource(gl: WebGLRenderingContext, source: {
25
- vertex: string;
26
- fragment: string;
27
- }): GLShader;
28
25
  private _cacheLocations;
29
26
  private _createProgram;
30
27
  private _createShader;
@@ -35,23 +32,21 @@ export declare class GLShader extends Shader {
35
32
  /**
36
33
  * Reset texture unit counter and other state
37
34
  */
38
- $resetState(): void;
35
+ private _resetState;
36
+ $setUniforms(uniforms: Record<string, UniformValue>): void;
39
37
  /**
40
38
  * Set a single uniform value with automatic texture unit management
41
39
  */
42
- setUniform(name: string, value: UniformValue): void;
40
+ $setUniform(name: string, value: UniformValue): void;
43
41
  private _getNextTextureUnit;
44
- /**
45
- * Check if a uniform is an integer type
46
- */
47
- private _isUniformInteger;
48
42
  /**
49
43
  * Get the WebGL program
50
44
  */
51
- get glProgram(): WebGLProgram;
45
+ get $glProgram(): WebGLProgram;
52
46
  /**
53
47
  * Dispose of WebGL resources used by this shader.
54
48
  * This method is idempotent and safe to call multiple times.
55
49
  */
56
50
  $dispose(): void;
57
51
  }
52
+ export {};