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.
- package/dist/textmode.esm.js +965 -965
- package/dist/textmode.umd.js +13 -13
- package/dist/types/Textmode.d.ts +133 -0
- package/dist/types/errors/Error.d.ts +24 -0
- package/dist/types/errors/ErrorHandler.d.ts +77 -0
- package/dist/types/errors/index.d.ts +2 -0
- package/dist/types/exports/conversion.d.ts +1 -0
- package/dist/types/exports/filters.d.ts +1 -0
- package/dist/types/exports/input.d.ts +1 -0
- package/dist/types/exports/layering.d.ts +1 -0
- package/dist/types/exports/loadables.d.ts +1 -0
- package/dist/types/exports/loading.d.ts +1 -0
- package/dist/types/exports/plugins.d.ts +1 -0
- package/dist/types/index.d.ts +85 -0
- package/dist/types/rendering/index.d.ts +4 -0
- package/dist/types/rendering/webgl/batching/DrawQueue.d.ts +89 -0
- package/dist/types/rendering/webgl/batching/GeometryAttributeCache.d.ts +18 -0
- package/dist/types/rendering/webgl/batching/InstanceAttributeBinder.d.ts +83 -0
- package/dist/types/rendering/webgl/batching/InstanceBatch.d.ts +87 -0
- package/dist/types/rendering/webgl/batching/InstanceBuffer.d.ts +68 -0
- package/dist/types/rendering/webgl/batching/InstanceData.d.ts +56 -0
- package/dist/types/rendering/webgl/batching/InstanceWriter.d.ts +78 -0
- package/dist/types/rendering/webgl/core/Framebuffer.d.ts +94 -0
- package/dist/types/rendering/webgl/core/Renderer.d.ts +78 -0
- package/dist/types/rendering/webgl/core/Shader.d.ts +62 -0
- package/dist/types/rendering/webgl/core/interfaces/IFramebuffer.d.ts +101 -0
- package/dist/types/rendering/webgl/core/interfaces/IRenderer.d.ts +214 -0
- package/dist/types/rendering/webgl/geometries/2d/Arc.d.ts +17 -0
- package/dist/types/rendering/webgl/geometries/2d/BezierCurve.d.ts +23 -0
- package/dist/types/rendering/webgl/geometries/2d/Ellipse.d.ts +21 -0
- package/dist/types/rendering/webgl/geometries/2d/Line.d.ts +21 -0
- package/dist/types/rendering/webgl/geometries/2d/Rectangle.d.ts +21 -0
- package/dist/types/rendering/webgl/geometries/2d/Triangle.d.ts +21 -0
- package/dist/types/rendering/webgl/geometries/BaseGeometry.d.ts +57 -0
- package/dist/types/rendering/webgl/geometries/immediate/ImmediateQuad.d.ts +33 -0
- package/dist/types/rendering/webgl/geometries/index.d.ts +6 -0
- package/dist/types/rendering/webgl/geometries/utils/GeometryDescriptors.d.ts +31 -0
- package/dist/types/rendering/webgl/geometries/utils/GeometryGenerator.d.ts +16 -0
- package/dist/types/rendering/webgl/index.d.ts +19 -0
- package/dist/types/rendering/webgl/materials/Material.d.ts +23 -0
- package/dist/types/rendering/webgl/materials/MaterialManager.d.ts +56 -0
- package/dist/types/rendering/webgl/materials/index.d.ts +2 -0
- package/dist/types/rendering/webgl/pipeline/MaterialBatchPipeline.d.ts +54 -0
- package/dist/types/rendering/webgl/pipeline/index.d.ts +7 -0
- package/dist/types/rendering/webgl/state/RenderState.d.ts +159 -0
- package/dist/types/rendering/webgl/types/DrawCommand.d.ts +29 -0
- package/dist/types/rendering/webgl/types/GeometryTypes.d.ts +147 -0
- package/dist/types/rendering/webgl/types/RenderTypes.d.ts +18 -0
- package/dist/types/rendering/webgl/types/UniformTypes.d.ts +11 -0
- package/dist/types/rendering/webgl/utils/GLUtils.d.ts +68 -0
- package/dist/types/rendering/webgl/utils/ViewportCache.d.ts +3 -0
- package/dist/types/rendering/webgl/utils/hash.d.ts +102 -0
- package/dist/types/textmode/AnimationController.d.ts +110 -0
- package/dist/types/textmode/Canvas.d.ts +58 -0
- package/dist/types/textmode/Grid.d.ts +563 -0
- package/dist/types/textmode/TextmodeColor.d.ts +405 -0
- package/dist/types/textmode/Textmodifier.d.ts +113 -0
- package/dist/types/textmode/conversion/ConversionManager.d.ts +89 -0
- package/dist/types/textmode/conversion/ConversionRegistry.d.ts +78 -0
- package/dist/types/textmode/conversion/index.d.ts +2 -0
- package/dist/types/textmode/conversion/strategies/brightness.d.ts +2 -0
- package/dist/types/textmode/filters/FilterManager.d.ts +132 -0
- package/dist/types/textmode/filters/index.d.ts +2 -0
- package/dist/types/textmode/filters/types.d.ts +78 -0
- package/dist/types/textmode/interfaces/IDisposable.d.ts +14 -0
- package/dist/types/textmode/interfaces/ITextmodifier.d.ts +753 -0
- package/dist/types/textmode/interfaces/index.d.ts +2 -0
- package/dist/types/textmode/layers/Layer2DCompositor.d.ts +89 -0
- package/dist/types/textmode/layers/LayerManager.d.ts +115 -0
- package/dist/types/textmode/layers/TextmodeLayer.d.ts +105 -0
- package/dist/types/textmode/layers/index.d.ts +4 -0
- package/dist/types/textmode/layers/interfaces/ILayerManager.d.ts +158 -0
- package/dist/types/textmode/layers/interfaces/ITextmodeLayer.d.ts +821 -0
- package/dist/types/textmode/layers/types.d.ts +78 -0
- package/dist/types/textmode/loadables/ITextmodeSource.d.ts +541 -0
- package/dist/types/textmode/loadables/TextmodeImage.d.ts +45 -0
- package/dist/types/textmode/loadables/TextmodeSource.d.ts +65 -0
- package/dist/types/textmode/loadables/TextmodeTexture.d.ts +95 -0
- package/dist/types/textmode/loadables/font/CharacterColorMapper.d.ts +34 -0
- package/dist/types/textmode/loadables/font/CharacterExtractor.d.ts +22 -0
- package/dist/types/textmode/loadables/font/MetricsCalculator.d.ts +23 -0
- package/dist/types/textmode/loadables/font/TextmodeFont.d.ts +176 -0
- package/dist/types/textmode/loadables/font/TextureAtlas.d.ts +66 -0
- package/dist/types/textmode/loadables/font/index.d.ts +8 -0
- package/dist/types/textmode/loadables/font/types.d.ts +28 -0
- package/dist/types/textmode/loadables/font/typr/Typr.d.ts +20 -0
- package/dist/types/textmode/loadables/font/typr/types.d.ts +241 -0
- package/dist/types/textmode/loadables/font/utils/CmapUtils.d.ts +11 -0
- package/dist/types/textmode/loadables/font/utils/FontTableReader.d.ts +40 -0
- package/dist/types/textmode/loadables/font/utils/index.d.ts +7 -0
- package/dist/types/textmode/loadables/index.d.ts +6 -0
- package/dist/types/textmode/loadables/video/ITextmodeVideo.d.ts +339 -0
- package/dist/types/textmode/loadables/video/TextmodeVideo.d.ts +81 -0
- package/dist/types/textmode/loading/LoadingPhase.d.ts +28 -0
- package/dist/types/textmode/loading/LoadingPhaseTracker.d.ts +20 -0
- package/dist/types/textmode/loading/LoadingScreenManager.d.ts +208 -0
- package/dist/types/textmode/loading/LoadingScreenState.d.ts +22 -0
- package/dist/types/textmode/loading/LoadingScreenTheme.d.ts +26 -0
- package/dist/types/textmode/loading/LoadingScreenTransition.d.ts +17 -0
- package/dist/types/textmode/loading/index.d.ts +7 -0
- package/dist/types/textmode/loading/templates/SpinnerTemplate.d.ts +2 -0
- package/dist/types/textmode/loading/templates/index.d.ts +1 -0
- package/dist/types/textmode/loading/types.d.ts +255 -0
- package/dist/types/textmode/managers/KeyboardManager.d.ts +128 -0
- package/dist/types/textmode/managers/MouseManager.d.ts +159 -0
- package/dist/types/textmode/managers/PluginManager.d.ts +220 -0
- package/dist/types/textmode/managers/TouchManager.d.ts +237 -0
- package/dist/types/textmode/managers/index.d.ts +12 -0
- package/dist/types/textmode/mixins/AnimationMixin.d.ts +8 -0
- package/dist/types/textmode/mixins/KeyboardMixin.d.ts +13 -0
- package/dist/types/textmode/mixins/MouseMixin.d.ts +10 -0
- package/dist/types/textmode/mixins/RenderingMixin.d.ts +8 -0
- package/dist/types/textmode/mixins/TextmodifierMixin.d.ts +19 -0
- package/dist/types/textmode/mixins/TouchMixin.d.ts +6 -0
- package/dist/types/textmode/mixins/index.d.ts +9 -0
- package/dist/types/textmode/mixins/interfaces/IAnimationMixin.d.ts +674 -0
- package/dist/types/textmode/mixins/interfaces/IKeyboardMixin.d.ts +234 -0
- package/dist/types/textmode/mixins/interfaces/IMouseMixin.d.ts +425 -0
- package/dist/types/textmode/mixins/interfaces/IRenderingMixin.d.ts +2147 -0
- package/dist/types/textmode/mixins/interfaces/ITouchMixin.d.ts +509 -0
- package/dist/types/textmode/types.d.ts +52 -0
- package/dist/types/utils/Disposable.d.ts +18 -0
- package/dist/types/utils/TextmodeCollection.d.ts +172 -0
- package/dist/types/utils/array.d.ts +34 -0
- package/dist/types/utils/color.d.ts +61 -0
- package/dist/types/utils/input.d.ts +11 -0
- package/dist/types/utils/math.d.ts +118 -0
- package/dist/types/utils/shader.d.ts +12 -0
- package/package.json +2 -2
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
import type { GLFramebuffer, FramebufferOptions } from '../Framebuffer';
|
|
2
|
+
import type { GLShader } from '../Shader';
|
|
3
|
+
import type { UniformValue } from '../../types/UniformTypes';
|
|
4
|
+
import type { RenderState } from '../../state/RenderState';
|
|
5
|
+
/**
|
|
6
|
+
* Interface for the core WebGL renderer that manages the WebGL context and provides high-level rendering operations.
|
|
7
|
+
*
|
|
8
|
+
* This interface defines the contract for all rendering operations including:
|
|
9
|
+
* - Shader management and creation
|
|
10
|
+
* - Framebuffer operations
|
|
11
|
+
* - Primitive rendering (rectangles, lines, ellipses, triangles, arcs, bezier curves)
|
|
12
|
+
* - Image and texture rendering
|
|
13
|
+
* - State management
|
|
14
|
+
* - Viewport and clearing operations
|
|
15
|
+
*/
|
|
16
|
+
export interface IRenderer {
|
|
17
|
+
/**
|
|
18
|
+
* Get the WebGL rendering context.
|
|
19
|
+
* Provides direct access to the underlying WebGL2 context for advanced operations.
|
|
20
|
+
*/
|
|
21
|
+
readonly context: WebGL2RenderingContext;
|
|
22
|
+
/**
|
|
23
|
+
* Get the current render state.
|
|
24
|
+
* The render state tracks the current rendering configuration including blend modes,
|
|
25
|
+
* colors, and other state that affects how primitives are drawn.
|
|
26
|
+
*/
|
|
27
|
+
readonly state: RenderState;
|
|
28
|
+
/**
|
|
29
|
+
* Set the current shader for subsequent rendering operations.
|
|
30
|
+
* This binds the shader program and makes it active for all following draw calls
|
|
31
|
+
* until a different shader is set.
|
|
32
|
+
*
|
|
33
|
+
* @param shader - The shader to activate
|
|
34
|
+
*/
|
|
35
|
+
$shader(shader: GLShader): void;
|
|
36
|
+
/**
|
|
37
|
+
* Create a new shader from vertex and fragment source code.
|
|
38
|
+
* The shader is compiled, linked, and cached by the shader manager.
|
|
39
|
+
*
|
|
40
|
+
* @param vertexSource - GLSL source code for the vertex shader
|
|
41
|
+
* @param fragmentSource - GLSL source code for the fragment shader
|
|
42
|
+
* @returns A compiled and linked shader program
|
|
43
|
+
*/
|
|
44
|
+
$createShader(vertexSource: string, fragmentSource: string): GLShader;
|
|
45
|
+
/**
|
|
46
|
+
* Set a custom user shader for subsequent rendering operations.
|
|
47
|
+
* This shader will be used for primitive rendering instead of the default shader.
|
|
48
|
+
* The shader persists until explicitly reset via $resetShader() or by passing null.
|
|
49
|
+
*
|
|
50
|
+
* @param shader - The custom shader to use, or null to reset to default
|
|
51
|
+
*/
|
|
52
|
+
$setUserShader(shader: GLShader | null): void;
|
|
53
|
+
/**
|
|
54
|
+
* Reset the current user shader to the default solid color shader.
|
|
55
|
+
* This clears both the active shader and any accumulated uniforms.
|
|
56
|
+
* Equivalent to calling $setUserShader(null).
|
|
57
|
+
*/
|
|
58
|
+
$resetShader(): void;
|
|
59
|
+
/**
|
|
60
|
+
* Set a uniform value for the current user shader.
|
|
61
|
+
* The uniform must exist in the shader for this to have any effect.
|
|
62
|
+
*
|
|
63
|
+
* @param name - The name of the uniform variable in the shader
|
|
64
|
+
* @param value - The value to set (type must match the uniform type in the shader)
|
|
65
|
+
*/
|
|
66
|
+
$setUniform(name: string, value: UniformValue): void;
|
|
67
|
+
/**
|
|
68
|
+
* Set multiple uniform values for the current user shader.
|
|
69
|
+
* This is a convenience method for setting multiple uniforms at once.
|
|
70
|
+
*
|
|
71
|
+
* @param uniforms - A record mapping uniform names to their values
|
|
72
|
+
*/
|
|
73
|
+
$setUniforms(uniforms: Record<string, UniformValue>): void;
|
|
74
|
+
/**
|
|
75
|
+
* Create a filter shader using the standard instanced vertex shader.
|
|
76
|
+
* Filter shaders are commonly used for post-processing effects and only require
|
|
77
|
+
* a custom fragment shader since they use a standard quad-rendering vertex shader.
|
|
78
|
+
*
|
|
79
|
+
* @param fragmentSource - GLSL source code for the fragment shader
|
|
80
|
+
* @returns A shader configured for filter operations
|
|
81
|
+
*/
|
|
82
|
+
$createFilterShader(fragmentSource: string): GLShader;
|
|
83
|
+
/**
|
|
84
|
+
* Draw a quad covering the pixel rectangle (x, y, width, height) on the canvas.
|
|
85
|
+
* The quad is converted to NDC (Normalized Device Coordinates) and rendered with the
|
|
86
|
+
* current shader using only the a_position attribute.
|
|
87
|
+
* Origin: top-left (canvas space).
|
|
88
|
+
*
|
|
89
|
+
* @param x - X coordinate of the top-left corner in pixels
|
|
90
|
+
* @param y - Y coordinate of the top-left corner in pixels
|
|
91
|
+
* @param width - Width of the quad in pixels
|
|
92
|
+
* @param height - Height of the quad in pixels
|
|
93
|
+
*/
|
|
94
|
+
$quad(x: number, y: number, width: number, height: number): void;
|
|
95
|
+
/**
|
|
96
|
+
* Draw a rectangle.
|
|
97
|
+
* The rectangle is rendered using the current shader and render state.
|
|
98
|
+
* Positioning is controlled via the render state transform stack.
|
|
99
|
+
*
|
|
100
|
+
* @param width - Width of the rectangle
|
|
101
|
+
* @param height - Height of the rectangle
|
|
102
|
+
*/
|
|
103
|
+
$rect(width: number, height: number): void;
|
|
104
|
+
/**
|
|
105
|
+
* Draw a line from one point to another.
|
|
106
|
+
* The line is rendered with the current stroke settings from the render state.
|
|
107
|
+
*
|
|
108
|
+
* @param x1 - X coordinate of the line start point
|
|
109
|
+
* @param y1 - Y coordinate of the line start point
|
|
110
|
+
* @param x2 - X coordinate of the line end point
|
|
111
|
+
* @param y2 - Y coordinate of the line end point
|
|
112
|
+
*/
|
|
113
|
+
$line(x1: number, y1: number, x2: number, y2: number): void;
|
|
114
|
+
/**
|
|
115
|
+
* Draw an ellipse.
|
|
116
|
+
* The ellipse is centered at (0, 0) in the current local coordinate system.
|
|
117
|
+
* Positioning is controlled via the render state transform stack.
|
|
118
|
+
*
|
|
119
|
+
* @param width - Width of the ellipse
|
|
120
|
+
* @param height - Height of the ellipse
|
|
121
|
+
*/
|
|
122
|
+
$ellipse(width: number, height: number): void;
|
|
123
|
+
/**
|
|
124
|
+
* Draw a triangle.
|
|
125
|
+
* The triangle is defined by three vertices and rendered with the current render state.
|
|
126
|
+
*
|
|
127
|
+
* @param x1 - First vertex X coordinate
|
|
128
|
+
* @param y1 - First vertex Y coordinate
|
|
129
|
+
* @param x2 - Second vertex X coordinate
|
|
130
|
+
* @param y2 - Second vertex Y coordinate
|
|
131
|
+
* @param x3 - Third vertex X coordinate
|
|
132
|
+
* @param y3 - Third vertex Y coordinate
|
|
133
|
+
*/
|
|
134
|
+
$triangle(x1: number, y1: number, x2: number, y2: number, x3: number, y3: number): void;
|
|
135
|
+
/**
|
|
136
|
+
* Draw a cubic Bezier curve.
|
|
137
|
+
* The curve is defined by a start point, two control points, and an end point.
|
|
138
|
+
*
|
|
139
|
+
* @param x1 - Start point X coordinate
|
|
140
|
+
* @param y1 - Start point Y coordinate
|
|
141
|
+
* @param cp1x - First control point X coordinate
|
|
142
|
+
* @param cp1y - First control point Y coordinate
|
|
143
|
+
* @param cp2x - Second control point X coordinate
|
|
144
|
+
* @param cp2y - Second control point Y coordinate
|
|
145
|
+
* @param x2 - End point X coordinate
|
|
146
|
+
* @param y2 - End point Y coordinate
|
|
147
|
+
*/
|
|
148
|
+
$bezierCurve(x1: number, y1: number, cp1x: number, cp1y: number, cp2x: number, cp2y: number, x2: number, y2: number): void;
|
|
149
|
+
/**
|
|
150
|
+
* Draw an arc (a portion of an ellipse).
|
|
151
|
+
* The arc is part of an ellipse centered at (0, 0) in the current local coordinate system,
|
|
152
|
+
* drawn from the start angle to the stop angle.
|
|
153
|
+
* Positioning is controlled via the render state transform stack.
|
|
154
|
+
*
|
|
155
|
+
* @param width - Width of the ellipse
|
|
156
|
+
* @param height - Height of the ellipse
|
|
157
|
+
* @param start - Start angle in radians
|
|
158
|
+
* @param stop - Stop angle in radians
|
|
159
|
+
*/
|
|
160
|
+
$arc(width: number, height: number, start: number, stop: number): void;
|
|
161
|
+
/**
|
|
162
|
+
* Create a new framebuffer for off-screen rendering.
|
|
163
|
+
* Framebuffers can be used for render-to-texture operations, post-processing,
|
|
164
|
+
* and other advanced rendering techniques.
|
|
165
|
+
*
|
|
166
|
+
* @param width - Width of the framebuffer in pixels
|
|
167
|
+
* @param height - Height of the framebuffer in pixels
|
|
168
|
+
* @param attachmentCount - Number of color attachments (default: 1, supports MRT)
|
|
169
|
+
* @param options - Additional framebuffer configuration options
|
|
170
|
+
* @returns A new framebuffer instance
|
|
171
|
+
*/
|
|
172
|
+
$createFramebuffer(width: number, height: number, attachmentCount?: number, options?: FramebufferOptions): GLFramebuffer;
|
|
173
|
+
/**
|
|
174
|
+
* Fill the current framebuffer with a solid color.
|
|
175
|
+
* This sets the canvas background color in the render state and clears the framebuffer.
|
|
176
|
+
* If only one value is provided, it's used for all RGB components.
|
|
177
|
+
*
|
|
178
|
+
* @param r - Red component (0-255)
|
|
179
|
+
* @param g - Green component (0-255), defaults to r if not provided
|
|
180
|
+
* @param b - Blue component (0-255), defaults to r if not provided
|
|
181
|
+
* @param a - Alpha component (0-255), defaults to 255 if not provided
|
|
182
|
+
*/
|
|
183
|
+
$background(r: number, g?: number, b?: number, a?: number): void;
|
|
184
|
+
/**
|
|
185
|
+
* Clear the current framebuffer to a specified color.
|
|
186
|
+
* Color components should be in the range [0, 1].
|
|
187
|
+
*
|
|
188
|
+
* @param r - Red component (0-1), defaults to 0
|
|
189
|
+
* @param g - Green component (0-1), defaults to 0
|
|
190
|
+
* @param b - Blue component (0-1), defaults to 0
|
|
191
|
+
* @param a - Alpha component (0-1), defaults to 0
|
|
192
|
+
*/
|
|
193
|
+
$clear(r?: number, g?: number, b?: number, a?: number): void;
|
|
194
|
+
/**
|
|
195
|
+
* Reset the viewport to match the canvas dimensions.
|
|
196
|
+
* This ensures the viewport is synchronized with the canvas size, which is
|
|
197
|
+
* important after canvas resize operations.
|
|
198
|
+
*/
|
|
199
|
+
$resetViewport(): void;
|
|
200
|
+
/**
|
|
201
|
+
* Flush all batched instances for instanced rendering.
|
|
202
|
+
* This must be called at the end of each frame to actually render all batched geometry.
|
|
203
|
+
* The method processes the entire draw queue and renders all primitives that were
|
|
204
|
+
* queued during the frame.
|
|
205
|
+
*/
|
|
206
|
+
$flushInstances(): void;
|
|
207
|
+
/**
|
|
208
|
+
* Dispose of all WebGL resources managed by this renderer.
|
|
209
|
+
* This releases buffers, shaders, geometries, and other GPU resources.
|
|
210
|
+
* This method is idempotent and safe to call multiple times.
|
|
211
|
+
* After disposal, the renderer should not be used.
|
|
212
|
+
*/
|
|
213
|
+
$dispose(): void;
|
|
214
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Instanced arc (pie segment) geometry implementation
|
|
3
|
+
*/
|
|
4
|
+
import type { InstanceBatch } from '../../batching/InstanceBatch';
|
|
5
|
+
import { type ArcParams } from '../../types/GeometryTypes';
|
|
6
|
+
import { BaseGeometry } from '../BaseGeometry';
|
|
7
|
+
import type { IRenderState } from '../../state/RenderState';
|
|
8
|
+
/**
|
|
9
|
+
* Instanced arc geometry renderer.
|
|
10
|
+
* Batches arc draw calls using a unit triangle fan scaled to width/height.
|
|
11
|
+
* Angles are specified in DEGREES by the API, converted to radians here.
|
|
12
|
+
*/
|
|
13
|
+
export declare class Arc extends BaseGeometry<ArcParams> {
|
|
14
|
+
constructor(gl: WebGL2RenderingContext, batch: InstanceBatch);
|
|
15
|
+
/** Add an arc instance (filled pie segment) */
|
|
16
|
+
$addInstance(params: ArcParams, renderState: IRenderState): number;
|
|
17
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Instanced bezier curve geometry implementation
|
|
3
|
+
*/
|
|
4
|
+
import type { InstanceBatch } from '../../batching/InstanceBatch';
|
|
5
|
+
import { type BezierCurveParams } from '../../types/GeometryTypes';
|
|
6
|
+
import { BaseGeometry } from '../BaseGeometry';
|
|
7
|
+
import type { IRenderState } from '../../state/RenderState';
|
|
8
|
+
/**
|
|
9
|
+
* TRUE INSTANCED bezier curve geometry renderer.
|
|
10
|
+
*
|
|
11
|
+
* APPROACH: Use a fixed multi-segment unit geometry shared by all curves.
|
|
12
|
+
* Each instance provides Bezier control points via instance attributes, and the
|
|
13
|
+
* vertex shader evaluates the curve mathematically to transform each segment.
|
|
14
|
+
*
|
|
15
|
+
* This maintains true instanced rendering: one draw call for all curves.
|
|
16
|
+
*/
|
|
17
|
+
export declare class BezierCurve extends BaseGeometry<BezierCurveParams> {
|
|
18
|
+
constructor(gl: WebGL2RenderingContext, batch: InstanceBatch);
|
|
19
|
+
/**
|
|
20
|
+
* Add a bezier curve instance to the batch - TRUE INSTANCED APPROACH
|
|
21
|
+
*/
|
|
22
|
+
$addInstance(params: BezierCurveParams, renderState: IRenderState): number;
|
|
23
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Instanced ellipse geometry implementation
|
|
3
|
+
*/
|
|
4
|
+
import type { InstanceBatch } from '../../batching/InstanceBatch';
|
|
5
|
+
import { type EllipseParams } from '../../types/GeometryTypes';
|
|
6
|
+
import { BaseGeometry } from '../BaseGeometry';
|
|
7
|
+
import type { IRenderState } from '../../state/RenderState';
|
|
8
|
+
/**
|
|
9
|
+
* Instanced ellipse geometry renderer.
|
|
10
|
+
* Batches all ellipse draw calls for efficient GPU rendering.
|
|
11
|
+
*/
|
|
12
|
+
export declare class Ellipse extends BaseGeometry<EllipseParams> {
|
|
13
|
+
constructor(gl: WebGL2RenderingContext, batch: InstanceBatch);
|
|
14
|
+
/**
|
|
15
|
+
* Add an ellipse instance to the batch
|
|
16
|
+
* @param params Ellipse parameters
|
|
17
|
+
* @param renderState Current render state
|
|
18
|
+
* @returns Index of the added instance
|
|
19
|
+
*/
|
|
20
|
+
$addInstance(params: EllipseParams, renderState: IRenderState): number;
|
|
21
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Instanced line geometry implementation
|
|
3
|
+
*/
|
|
4
|
+
import type { InstanceBatch } from '../../batching/InstanceBatch';
|
|
5
|
+
import { type LineParams } from '../../types/GeometryTypes';
|
|
6
|
+
import { BaseGeometry } from '../BaseGeometry';
|
|
7
|
+
import type { IRenderState } from '../../state/RenderState';
|
|
8
|
+
/**
|
|
9
|
+
* Instanced line geometry renderer.
|
|
10
|
+
* Batches all line draw calls for efficient GPU rendering.
|
|
11
|
+
*/
|
|
12
|
+
export declare class Line extends BaseGeometry<LineParams> {
|
|
13
|
+
constructor(gl: WebGL2RenderingContext, batch: InstanceBatch);
|
|
14
|
+
/**
|
|
15
|
+
* Add a line instance to the batch
|
|
16
|
+
* @param params Line parameters
|
|
17
|
+
* @param renderState Current render state
|
|
18
|
+
* @returns Index of the added instance
|
|
19
|
+
*/
|
|
20
|
+
$addInstance(params: LineParams, renderState: IRenderState): number;
|
|
21
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Instanced rectangle geometry implementation
|
|
3
|
+
*/
|
|
4
|
+
import type { InstanceBatch } from '../../batching/InstanceBatch';
|
|
5
|
+
import { type RectangleParams } from '../../types/GeometryTypes';
|
|
6
|
+
import { BaseGeometry } from '../BaseGeometry';
|
|
7
|
+
import type { IRenderState } from '../../state/RenderState';
|
|
8
|
+
/**
|
|
9
|
+
* Instanced rectangle geometry renderer.
|
|
10
|
+
* Batches all rectangle draw calls for efficient GPU rendering.
|
|
11
|
+
*/
|
|
12
|
+
export declare class Rectangle extends BaseGeometry<RectangleParams> {
|
|
13
|
+
constructor(gl: WebGL2RenderingContext, batch: InstanceBatch);
|
|
14
|
+
/**
|
|
15
|
+
* Add a rectangle instance to the batch
|
|
16
|
+
* @param params Rectangle parameters
|
|
17
|
+
* @param renderState Current render state
|
|
18
|
+
* @returns Index of the added instance
|
|
19
|
+
*/
|
|
20
|
+
$addInstance(params: RectangleParams, renderState: IRenderState): number;
|
|
21
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Instanced triangle geometry implementation
|
|
3
|
+
*/
|
|
4
|
+
import type { InstanceBatch } from '../../batching/InstanceBatch';
|
|
5
|
+
import { type TriangleParams } from '../../types/GeometryTypes';
|
|
6
|
+
import { BaseGeometry } from '../BaseGeometry';
|
|
7
|
+
import type { IRenderState } from '../../state/RenderState';
|
|
8
|
+
/**
|
|
9
|
+
* Instanced triangle geometry renderer.
|
|
10
|
+
* Batches all triangle draw calls for efficient GPU rendering.
|
|
11
|
+
*/
|
|
12
|
+
export declare class Triangle extends BaseGeometry<TriangleParams> {
|
|
13
|
+
constructor(gl: WebGL2RenderingContext, batch: InstanceBatch);
|
|
14
|
+
/**
|
|
15
|
+
* Add a triangle instance to the batch
|
|
16
|
+
* @param params Triangle parameters
|
|
17
|
+
* @param renderState Current render state
|
|
18
|
+
* @returns Index of the added instance
|
|
19
|
+
*/
|
|
20
|
+
$addInstance(params: TriangleParams, renderState: IRenderState): number;
|
|
21
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import type { InstanceBatch } from '../batching/InstanceBatch';
|
|
2
|
+
import { type InstanceData } from '../batching/InstanceData';
|
|
3
|
+
import { type InstanceWriteData } from '../batching/InstanceWriter';
|
|
4
|
+
import type { IGeometry, GeometryType, UnitGeometryData, GeometryParams } from '../types/GeometryTypes';
|
|
5
|
+
import type { IRenderState } from '../state/RenderState';
|
|
6
|
+
/**
|
|
7
|
+
* Abstract base class for all instanced geometries.
|
|
8
|
+
* Provides common functionality for instance data creation and batch management.
|
|
9
|
+
*/
|
|
10
|
+
export declare abstract class BaseGeometry<P = GeometryParams> implements IGeometry<P> {
|
|
11
|
+
protected readonly _gl: WebGL2RenderingContext;
|
|
12
|
+
protected readonly _batch: InstanceBatch;
|
|
13
|
+
protected readonly _type: GeometryType;
|
|
14
|
+
protected readonly _unitGeometry: UnitGeometryData;
|
|
15
|
+
private _unitBuffer;
|
|
16
|
+
protected _tempCurveParams0: [number, number, number, number];
|
|
17
|
+
protected _tempCurveParams1: [number, number, number, number];
|
|
18
|
+
protected _tempWriteData: InstanceWriteData;
|
|
19
|
+
constructor(gl: WebGL2RenderingContext, batch: InstanceBatch, type: GeometryType, unitGeometry: UnitGeometryData);
|
|
20
|
+
get type(): GeometryType;
|
|
21
|
+
get unitGeometry(): UnitGeometryData;
|
|
22
|
+
get unitBuffer(): WebGLBuffer;
|
|
23
|
+
get batch(): InstanceBatch;
|
|
24
|
+
$clearInstances(): void;
|
|
25
|
+
$hasInstances(): boolean;
|
|
26
|
+
$dispose(): void;
|
|
27
|
+
abstract $addInstance(params: P, renderState: IRenderState): number;
|
|
28
|
+
protected _addInstance(instanceData: InstanceData, _rotationCenterX: number, _rotationCenterY: number): number;
|
|
29
|
+
/**
|
|
30
|
+
* Write instance data directly to batch buffer (zero-allocation helper).
|
|
31
|
+
* Handles all common instance data setup to eliminate code duplication.
|
|
32
|
+
*
|
|
33
|
+
* @param x - X position
|
|
34
|
+
* @param y - Y position
|
|
35
|
+
* @param width - Width
|
|
36
|
+
* @param height - Height
|
|
37
|
+
* @param centerX - Rotation center X (in pixels)
|
|
38
|
+
* @param centerY - Rotation center Y (in pixels)
|
|
39
|
+
* @param renderState - Current render state
|
|
40
|
+
* @param geometryData - Optional geometry-specific data (arc angles, bezier points, depth)
|
|
41
|
+
* @returns Index of the written instance
|
|
42
|
+
*/
|
|
43
|
+
protected _writeInstance(x: number, y: number, width: number, height: number, renderState: IRenderState, geometryData?: {
|
|
44
|
+
arcStart?: number;
|
|
45
|
+
arcStop?: number;
|
|
46
|
+
cp1x?: number;
|
|
47
|
+
cp1y?: number;
|
|
48
|
+
cp2x?: number;
|
|
49
|
+
cp2y?: number;
|
|
50
|
+
bezStartX?: number;
|
|
51
|
+
bezStartY?: number;
|
|
52
|
+
bezEndX?: number;
|
|
53
|
+
bezEndY?: number;
|
|
54
|
+
depth?: number;
|
|
55
|
+
baseZ?: number;
|
|
56
|
+
}): number;
|
|
57
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Immediate-mode quad renderer for full-screen passes and framebuffer presentation.
|
|
3
|
+
*
|
|
4
|
+
* This is NOT an instanced geometry - it's a simple, stateless utility for drawing
|
|
5
|
+
* a single textured quad immediately. Used primarily for presenting final framebuffer
|
|
6
|
+
* results to the screen or for filter passes.
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Simple immediate-mode quad renderer.
|
|
10
|
+
* No instancing, no batching, just a single quad drawn with vertex positions in NDC.
|
|
11
|
+
*/
|
|
12
|
+
export declare class ImmediateQuad {
|
|
13
|
+
private _gl;
|
|
14
|
+
private _vbo;
|
|
15
|
+
private _vertexData;
|
|
16
|
+
constructor(gl: WebGL2RenderingContext);
|
|
17
|
+
/**
|
|
18
|
+
* Draw a quad immediately with the given pixel coordinates.
|
|
19
|
+
* Converts pixel coordinates to NDC and renders a textured quad.
|
|
20
|
+
*
|
|
21
|
+
* The current shader must be bound before calling this method.
|
|
22
|
+
*
|
|
23
|
+
* @param x X position in pixels
|
|
24
|
+
* @param y Y position in pixels
|
|
25
|
+
* @param width Width in pixels
|
|
26
|
+
* @param height Height in pixels
|
|
27
|
+
*/
|
|
28
|
+
$draw(x: number, y: number, width: number, height: number): void;
|
|
29
|
+
/**
|
|
30
|
+
* Dispose of WebGL resources.
|
|
31
|
+
*/
|
|
32
|
+
$dispose(): void;
|
|
33
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared geometry attribute descriptors to eliminate redundant definitions.
|
|
3
|
+
* All geometries of the same dimensionality (2D/3D) share identical stride and attribute layouts.
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Unit quad vertex data used by both instanced and immediate quad rendering.
|
|
7
|
+
* Format: [x, y, u, v] for each vertex (position + texCoord interleaved)
|
|
8
|
+
* Layout: Two triangles forming a unit square centered at origin from (-0.5,-0.5) to (0.5,0.5)
|
|
9
|
+
*/
|
|
10
|
+
export declare const UNIT_QUAD: Float32Array<ArrayBuffer>;
|
|
11
|
+
/**
|
|
12
|
+
* Standard 2D geometry attribute descriptor.
|
|
13
|
+
* Used by: Rectangle, Line, Ellipse, Triangle, Arc, BezierCurve
|
|
14
|
+
*
|
|
15
|
+
* Layout: [position.xy, texCoord.uv]
|
|
16
|
+
* Stride: 16 bytes (4 floats)
|
|
17
|
+
*/
|
|
18
|
+
export declare const GEOMETRY_2D_DESCRIPTOR: {
|
|
19
|
+
readonly _stride: 16;
|
|
20
|
+
readonly _primitiveType: 4;
|
|
21
|
+
readonly _attributes: {
|
|
22
|
+
readonly _position: {
|
|
23
|
+
readonly size: 2;
|
|
24
|
+
readonly offset: 0;
|
|
25
|
+
};
|
|
26
|
+
readonly _texCoord: {
|
|
27
|
+
readonly size: 2;
|
|
28
|
+
readonly offset: 8;
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Geometry generation utilities for 2D shapes.
|
|
3
|
+
* 2D geometries use 4 floats per vertex: position.xy + texCoord.uv
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Generate 2D circle/ellipse vertices.
|
|
7
|
+
*/
|
|
8
|
+
export declare function generateCircleVertices(segments?: number): Float32Array;
|
|
9
|
+
/**
|
|
10
|
+
* Generate unit arc vertices for 2D arc rendering.
|
|
11
|
+
*/
|
|
12
|
+
export declare function generateArcVertices(segments: number): Float32Array;
|
|
13
|
+
/**
|
|
14
|
+
* Generate bezier curve geometry (multi-segment for GPU evaluation).
|
|
15
|
+
*/
|
|
16
|
+
export declare function generateBezierVertices(segments?: number): Float32Array;
|
|
@@ -0,0 +1,19 @@
|
|
|
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';
|
|
7
|
+
export { GeometryType } from './types/GeometryTypes';
|
|
8
|
+
export type { IGeometry as IInstancedGeometry, UnitGeometryData, RectangleParams, LineParams, EllipseParams, ArcParams, TriangleParams, BezierCurveParams, GeometryParams, } from './types/GeometryTypes';
|
|
9
|
+
export type { RenderContext } from './types/RenderTypes';
|
|
10
|
+
export type { InstanceData } from './batching/InstanceData';
|
|
11
|
+
export { PackedInstanceData, InstanceAttributeLayout } from './batching/InstanceData';
|
|
12
|
+
export { InstanceBatch } from './batching/InstanceBatch';
|
|
13
|
+
export { BaseGeometry } from './geometries/BaseGeometry';
|
|
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,23 @@
|
|
|
1
|
+
import type { GLShader } from '../core/Shader';
|
|
2
|
+
import type { UniformValue } from '../types/UniformTypes';
|
|
3
|
+
/**
|
|
4
|
+
* Material defines how geometry should be rendered.
|
|
5
|
+
* Combines a shader program with uniform parameters.
|
|
6
|
+
*
|
|
7
|
+
* Materials are immutable once created to enable safe deduplication and caching.
|
|
8
|
+
*/
|
|
9
|
+
export interface Material {
|
|
10
|
+
/** Unique material identifier for fast comparison */
|
|
11
|
+
readonly id: number;
|
|
12
|
+
/** The shader program to use for rendering */
|
|
13
|
+
readonly shader: GLShader;
|
|
14
|
+
/** Uniform values to set when using this material (immutable) */
|
|
15
|
+
readonly uniforms: Readonly<Record<string, UniformValue>>;
|
|
16
|
+
/** Hash for fast material comparison and deduplication */
|
|
17
|
+
readonly hash: number;
|
|
18
|
+
/**
|
|
19
|
+
* Whether this is a built-in system material (solid color, copy, etc.)
|
|
20
|
+
* Built-in materials are never disposed when cleaning up user materials.
|
|
21
|
+
*/
|
|
22
|
+
readonly isBuiltIn: boolean;
|
|
23
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import type { Material } from './Material';
|
|
2
|
+
import { GLShader } from '../core/Shader';
|
|
3
|
+
import type { UniformValue } from '../types/UniformTypes';
|
|
4
|
+
/**
|
|
5
|
+
* Manages material creation, deduplication, and lifecycle.
|
|
6
|
+
*
|
|
7
|
+
* Provides:
|
|
8
|
+
* - Material creation with automatic deduplication
|
|
9
|
+
* - Built-in materials (solid color, copy, image-to-MRT)
|
|
10
|
+
* - Transient materials for dynamic uniforms
|
|
11
|
+
* - Built-in shader management (2D/3D instanced shaders)
|
|
12
|
+
*
|
|
13
|
+
* Performance optimizations:
|
|
14
|
+
* - Material interning: identical materials share the same instance
|
|
15
|
+
* - Hash-based lookup for O(1) deduplication
|
|
16
|
+
* - Separate tracking of user vs built-in materials
|
|
17
|
+
*/
|
|
18
|
+
export declare class MaterialManager {
|
|
19
|
+
private _nextMaterialId;
|
|
20
|
+
private readonly _shader;
|
|
21
|
+
private readonly _copyShader;
|
|
22
|
+
private readonly _solidColorMaterial;
|
|
23
|
+
private _materialCache;
|
|
24
|
+
constructor(gl: WebGL2RenderingContext);
|
|
25
|
+
/**
|
|
26
|
+
* Get the default 2D solid-color material.
|
|
27
|
+
* This material uses the standard instanced MRT shader with per-instance colors.
|
|
28
|
+
*/
|
|
29
|
+
get $solidColorMaterial(): Material;
|
|
30
|
+
/**
|
|
31
|
+
* Get the shared copy shader for MRT framebuffers.
|
|
32
|
+
*/
|
|
33
|
+
get $copyShader(): GLShader;
|
|
34
|
+
/**
|
|
35
|
+
* Create a transient material that won't be cached.
|
|
36
|
+
* Useful for one-off materials with dynamic uniforms that change every frame.
|
|
37
|
+
*
|
|
38
|
+
* @param shader - The shader program to use
|
|
39
|
+
* @param uniforms - Uniform values to set
|
|
40
|
+
* @returns A new material instance (not cached)
|
|
41
|
+
*/
|
|
42
|
+
$createTransientMaterial(shader: GLShader, uniforms?: Record<string, UniformValue>): Material;
|
|
43
|
+
/**
|
|
44
|
+
* Compute a hash for a shader + uniforms combination.
|
|
45
|
+
* Used for material deduplication.
|
|
46
|
+
*/
|
|
47
|
+
private _computeHash;
|
|
48
|
+
/**
|
|
49
|
+
* Hash a single uniform value based on its type.
|
|
50
|
+
*/
|
|
51
|
+
private _hashUniformValue;
|
|
52
|
+
/**
|
|
53
|
+
* Dispose of all shaders and materials managed by this manager.
|
|
54
|
+
*/
|
|
55
|
+
$dispose(): void;
|
|
56
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
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
|
+
* - Optimized to avoid per-frame allocations
|
|
25
|
+
*/
|
|
26
|
+
export declare class MaterialBatchPipeline {
|
|
27
|
+
private _gl;
|
|
28
|
+
private _geometries;
|
|
29
|
+
private _geometryAttributeCache;
|
|
30
|
+
private _currentShader;
|
|
31
|
+
private _shaderViewportState;
|
|
32
|
+
private _lastFlushedMaterial;
|
|
33
|
+
constructor(gl: WebGL2RenderingContext);
|
|
34
|
+
/**
|
|
35
|
+
* Execute all queued draw commands in strict order.
|
|
36
|
+
* Batches consecutive commands with same material+type for efficiency.
|
|
37
|
+
*
|
|
38
|
+
* @param commands - Draw commands in user-specified order
|
|
39
|
+
*/
|
|
40
|
+
$execute(commands: Iterable<DrawCommand>): void;
|
|
41
|
+
/**
|
|
42
|
+
* Flush and render the current batch of instances.
|
|
43
|
+
*
|
|
44
|
+
* @param geometry - The geometry instance containing accumulated instances
|
|
45
|
+
* @param material - The material to use for rendering
|
|
46
|
+
* @param type - The geometry type
|
|
47
|
+
* @param useOrtho - Whether to use orthographic projection
|
|
48
|
+
*/
|
|
49
|
+
private _flushBatch;
|
|
50
|
+
/**
|
|
51
|
+
* Dispose of pipeline resources (including all geometries).
|
|
52
|
+
*/
|
|
53
|
+
$dispose(): void;
|
|
54
|
+
}
|