rapid-render 0.1.21 → 1.0.0
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/LICENSE +2 -2
- package/README.md +70 -82
- package/dist/buffer.d.ts +153 -0
- package/dist/color.d.ts +144 -0
- package/dist/draw.d.ts +53 -0
- package/dist/index.d.ts +12 -15
- package/dist/line.d.ts +17 -3
- package/dist/math.d.ts +17 -492
- package/dist/matrix-engine.d.ts +360 -0
- package/dist/particle.d.ts +146 -36
- package/dist/rapid-render.js +3258 -0
- package/dist/rapid-render.umd.cjs +268 -0
- package/dist/region/atlasSpriteRegion.d.ts +9 -0
- package/dist/region/graphicRegion.d.ts +40 -0
- package/dist/region/region.d.ts +42 -0
- package/dist/region/spriteRegion.d.ts +33 -0
- package/dist/render.d.ts +342 -205
- package/dist/texture.d.ts +219 -152
- package/dist/utils.d.ts +28 -25
- package/dist/vite.svg +1 -0
- package/dist/webgl/glshader.d.ts +107 -25
- package/dist/webgl/utils.d.ts +18 -8
- package/package.json +36 -38
- package/dist/depth.d.ts +0 -8
- package/dist/input.d.ts +0 -60
- package/dist/interface.d.ts +0 -334
- package/dist/light.d.ts +0 -7
- package/dist/log.d.ts +0 -2
- package/dist/rapid.global.js +0 -1
- package/dist/rapid.js +0 -1
- package/dist/rapid.umd.cjs +0 -1
- package/dist/regions/attributes.d.ts +0 -44
- package/dist/regions/graphic_region.d.ts +0 -15
- package/dist/regions/region.d.ts +0 -41
- package/dist/regions/sprite_region.d.ts +0 -18
- package/dist/tilemap.d.ts +0 -98
- package/dist/webgl/uniform.d.ts +0 -14
package/dist/render.d.ts
CHANGED
|
@@ -1,255 +1,392 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import
|
|
8
|
-
import {
|
|
1
|
+
import { WebGLContext } from './webgl/utils';
|
|
2
|
+
import { default as GLShader, CustomGlShader } from './webgl/glshader';
|
|
3
|
+
import { Region } from './region/region';
|
|
4
|
+
import { SpriteRegion } from './region/spriteRegion';
|
|
5
|
+
import { MatrixStack, MatrixStore, ITransformOptions } from './matrix-engine';
|
|
6
|
+
import { GraphicRegion } from './region/graphicRegion';
|
|
7
|
+
import { RenderTexture, Texture, TextureManager } from './texture';
|
|
8
|
+
import { Color } from './color';
|
|
9
|
+
import { ICircleOptions, IGraphicOptions, ILineOptions, IMaskImageOptions, IRectOptions, ISpriteOptions } from './draw';
|
|
10
|
+
import { Vec2 } from './math';
|
|
11
|
+
import { AtlasSprtieRegion } from './region/atlasSpriteRegion';
|
|
9
12
|
/**
|
|
10
|
-
*
|
|
13
|
+
* Options for initializing the Rapid application.
|
|
11
14
|
*/
|
|
12
|
-
|
|
13
|
-
|
|
15
|
+
export interface IAppOptions {
|
|
16
|
+
/** The HTML canvas element to render onto. */
|
|
14
17
|
canvas: HTMLCanvasElement;
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
private currentTransform;
|
|
38
|
-
private currentFBO;
|
|
39
|
-
private lastTime;
|
|
40
|
-
/**
|
|
41
|
-
* Constructs a new `Rapid` instance with the given options.
|
|
42
|
-
* @param options - Options for initializing the `Rapid` instance.
|
|
43
|
-
*/
|
|
44
|
-
constructor(options: IRapidOptions);
|
|
45
|
-
/**
|
|
46
|
-
* @param displayWdith css px size
|
|
47
|
-
* @param displayHeight css px size
|
|
48
|
-
*/
|
|
49
|
-
updateDisplaySize(displayWdith: number, displayHeight: number): void;
|
|
50
|
-
private resizeSize;
|
|
51
|
-
private updateProjection;
|
|
52
|
-
/**
|
|
53
|
-
* Initializes WebGL context settings.
|
|
54
|
-
* @param gl - The WebGL context.
|
|
55
|
-
*/
|
|
56
|
-
private initWebgl;
|
|
57
|
-
/**
|
|
58
|
-
* @ignore
|
|
59
|
-
*/
|
|
60
|
-
clearTextureUnit(): void;
|
|
61
|
-
/**
|
|
62
|
-
* Registers built-in regions such as sprite and graphic regions.
|
|
63
|
-
*/
|
|
64
|
-
private registerBuildInRegion;
|
|
65
|
-
/**
|
|
66
|
-
* Registers a custom render region with a specified name.
|
|
67
|
-
* @param name - The name of the region.
|
|
68
|
-
* @param regionClass - The class of the region to register.
|
|
69
|
-
*/
|
|
70
|
-
registerRegion(name: string, regionClass: typeof RenderRegion): void;
|
|
71
|
-
private quitCurrentRegion;
|
|
18
|
+
/** The logical width of the application (CSS pixels). */
|
|
19
|
+
logicWidth?: number;
|
|
20
|
+
/** The logical height of the application (CSS pixels). */
|
|
21
|
+
logicHeight?: number;
|
|
22
|
+
/** The physical width of the application (actual pixels). */
|
|
23
|
+
physicsWidth?: number;
|
|
24
|
+
/** The physical height of the application (actual pixels). */
|
|
25
|
+
physicsHeight?: number;
|
|
26
|
+
/** The default clear color for the application background. */
|
|
27
|
+
backgroundColor?: Color;
|
|
28
|
+
/** Whether to enable MSAA antialiasing on the WebGL canvas. Default: false. */
|
|
29
|
+
antialias?: boolean;
|
|
30
|
+
textureFilter?: TextureFilterMode;
|
|
31
|
+
/** Whether textures are uploaded with premultiplied alpha. Default: true. */
|
|
32
|
+
premultipliedAlpha?: boolean;
|
|
33
|
+
roundPixels?: boolean;
|
|
34
|
+
scaleMode?: CanvasScaleMode;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* The type of mask to apply.
|
|
38
|
+
*/
|
|
39
|
+
export declare enum MaskType {
|
|
72
40
|
/**
|
|
73
|
-
*
|
|
74
|
-
* @param regionName - The name of the region to set as current.
|
|
75
|
-
* @param customShader - An optional custom shader to use with the region.
|
|
76
|
-
* @param hasUnifrom - have costum unifrom
|
|
41
|
+
* Draw inside the mask.
|
|
77
42
|
*/
|
|
78
|
-
|
|
43
|
+
EQUAL = 0,
|
|
79
44
|
/**
|
|
80
|
-
*
|
|
45
|
+
* Draw outside the mask.
|
|
81
46
|
*/
|
|
82
|
-
|
|
47
|
+
NOT_EQUAL = 1
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Supported blend modes for rendering.
|
|
51
|
+
*/
|
|
52
|
+
export declare enum BlendMode {
|
|
53
|
+
/** Normal alpha blending. */
|
|
54
|
+
NORMAL = 0,
|
|
55
|
+
/** Additive blending (useful for glow effects). */
|
|
56
|
+
ADD = 1,
|
|
57
|
+
/** Multiply blending (useful for shadows and darkening). */
|
|
58
|
+
MULTIPLY = 2,
|
|
59
|
+
/** Screen blending (produces a softer additive effect). */
|
|
60
|
+
SCREEN = 3,
|
|
61
|
+
/** Erase blending (removes alpha based on source). */
|
|
62
|
+
ERASE = 4
|
|
63
|
+
}
|
|
64
|
+
export declare enum TextureFilterMode {
|
|
65
|
+
LINEAR = 0,
|
|
66
|
+
NEAREST = 1
|
|
67
|
+
}
|
|
68
|
+
export declare enum CanvasScaleMode {
|
|
83
69
|
/**
|
|
84
|
-
*
|
|
70
|
+
* Scales the canvas by increasing the WebGL backbuffer size.
|
|
71
|
+
* The logical game size stays the same, but rendering happens at the final display resolution,
|
|
72
|
+
* so rotated sprites, lines, and geometry get more rasterized pixels and look smoother.
|
|
85
73
|
*/
|
|
86
|
-
|
|
74
|
+
CanvasItem = 0,
|
|
87
75
|
/**
|
|
88
|
-
*
|
|
89
|
-
*
|
|
76
|
+
* Scales only the final canvas element on the page.
|
|
77
|
+
* The WebGL backbuffer stays at the logical game size, then the browser stretches that bitmap
|
|
78
|
+
* to the CSS display size. This preserves low-resolution/pixel-art rendering and does not add
|
|
79
|
+
* more fragments while scaling up.
|
|
90
80
|
*/
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
81
|
+
Viewport = 1
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* The main application class for the Rapid rendering engine.
|
|
85
|
+
* Manages the WebGL context, rendering regions, state, and matrices.
|
|
86
|
+
*/
|
|
87
|
+
export declare class Rapid {
|
|
88
|
+
/** The active WebGL context. */
|
|
89
|
+
gl: WebGLContext;
|
|
90
|
+
/** The target HTMLCanvasElement. */
|
|
91
|
+
canvas: HTMLCanvasElement;
|
|
92
|
+
/** The current orthographic projection matrix (16 elements). */
|
|
93
|
+
projection: Float32Array;
|
|
94
|
+
/** Indicates if the projection matrix has changed and needs to be uploaded to shaders. */
|
|
95
|
+
projectionDirty: boolean;
|
|
96
|
+
/** The current device pixel ratio. */
|
|
97
|
+
dpr: number;
|
|
98
|
+
/** Background clear color [r, g, b, a], values range from 0 to 255. */
|
|
99
|
+
backgroundColor: Color;
|
|
100
|
+
/** Logical width in CSS pixels, used for coordinate system and projection matrix. */
|
|
101
|
+
logicWidth: number;
|
|
102
|
+
/** Logical height in CSS pixels, used for coordinate system and projection matrix. */
|
|
103
|
+
logicHeight: number;
|
|
104
|
+
/** Physical width (canvas actual pixels = logical width * dpr). */
|
|
105
|
+
physicsWidth: number;
|
|
106
|
+
/** Physical height (canvas actual pixels = logical height * dpr). */
|
|
107
|
+
physicsHeight: number;
|
|
108
|
+
/** The currently active rendering region. */
|
|
109
|
+
currentRegion: Region | null;
|
|
110
|
+
/** Maximum number of texture units supported by the device. */
|
|
111
|
+
maxTextureUnits: number;
|
|
112
|
+
/** Matrix stack for hierarchical transformations. */
|
|
113
|
+
matrixStack: MatrixStack;
|
|
114
|
+
/** Direct access to the underlying matrix store. */
|
|
115
|
+
matrix: MatrixStore;
|
|
116
|
+
/** Region dedicated to fast sprite rendering. */
|
|
117
|
+
spriteRegion: SpriteRegion;
|
|
118
|
+
/** Region dedicated to arbitrary geometry and shapes rendering. */
|
|
119
|
+
graphicRegion: GraphicRegion;
|
|
120
|
+
atlasSpriteRegion: AtlasSprtieRegion;
|
|
121
|
+
/** Counts the number of WebGL draw calls made in the current frame. */
|
|
122
|
+
drawcallCount: number;
|
|
123
|
+
/** Indicates whether we are currently writing to the stencil buffer to create a mask. */
|
|
124
|
+
inCreateMask: boolean;
|
|
125
|
+
/** Manager for creating and organizing textures. */
|
|
126
|
+
texture: TextureManager;
|
|
127
|
+
/** Whether textures use premultiplied alpha. Set once at construction. */
|
|
128
|
+
premultipliedAlpha: boolean;
|
|
129
|
+
/** Default texture filtering preference and requested canvas MSAA setting. */
|
|
130
|
+
antialias: boolean;
|
|
131
|
+
roundPixels: boolean;
|
|
132
|
+
/** Default filtering mode used when sampling textures. */
|
|
133
|
+
textureFilter: TextureFilterMode;
|
|
134
|
+
scaleMode?: CanvasScaleMode;
|
|
135
|
+
/** Internal ping-pong RenderTextures for multi-filter chains. */
|
|
136
|
+
private _filterRT;
|
|
137
|
+
private _filterInput;
|
|
138
|
+
get height(): number;
|
|
139
|
+
get width(): number;
|
|
140
|
+
/**
|
|
141
|
+
* Creates a new Rapid application instance.
|
|
142
|
+
* @param options Initialization options including the target canvas.
|
|
143
|
+
*/
|
|
144
|
+
constructor(options: IAppOptions);
|
|
145
|
+
setTextureFilter(filter: TextureFilterMode): void;
|
|
146
|
+
setAntialias(antialias: boolean): void;
|
|
147
|
+
private getColorUint32;
|
|
148
|
+
/**
|
|
149
|
+
* Enters a specific rendering region, flushing the previous one if necessary.
|
|
150
|
+
* @param region The rendering region to enter.
|
|
151
|
+
* @param customShader An optional custom shader to use for this region.
|
|
152
|
+
*/
|
|
153
|
+
enterRegion(region: Region, customShader?: GLShader | CustomGlShader): void;
|
|
154
|
+
drawSprite(options: ISpriteOptions): void;
|
|
155
|
+
drawLine(options: ILineOptions): void;
|
|
156
|
+
drawGraphic(options: IGraphicOptions): void;
|
|
157
|
+
drawRect(options: IRectOptions): void;
|
|
158
|
+
drawCircle(options: ICircleOptions): void;
|
|
159
|
+
/**
|
|
160
|
+
* Starts rendering arbitrary graphics geometries.
|
|
161
|
+
* @param drawMode The WebGL drawing mode (e.g., gl.TRIANGLES, gl.TRIANGLE_FAN).
|
|
162
|
+
* @param texture An optional texture applied to the graphic vertices.
|
|
163
|
+
* @param customShader An optional custom shader overriding the region's default shader.
|
|
164
|
+
*/
|
|
165
|
+
startGraphic(drawMode?: number, texture?: Texture, customShader?: GLShader | CustomGlShader, customMatrix?: number): void;
|
|
166
|
+
/**
|
|
167
|
+
* Starts rendering graphics explicitly for use as a mask, overriding the shader.
|
|
168
|
+
* @param drawMode The WebGL drawing mode (e.g., gl.TRIANGLES).
|
|
169
|
+
* @param texture An optional texture whose alpha channel may dictate masking rules.
|
|
170
|
+
*/
|
|
171
|
+
startMaskGraphic(drawMode?: number, texture?: Texture, customMatrix?: number): void;
|
|
172
|
+
/**
|
|
173
|
+
* Utility method: Draws an image directly as a mask using a generic rectangle geometry.
|
|
174
|
+
* @param texture The texture to be used as a mask.
|
|
175
|
+
*/
|
|
176
|
+
drawMaskImage(options: IMaskImageOptions): void;
|
|
177
|
+
/**
|
|
178
|
+
* Pushes vertices for a rectangle geometry. Should be enclosed by startGraphic and endGraphic.
|
|
179
|
+
* @param w The width of the rectangle.
|
|
180
|
+
* @param h The height of the rectangle.
|
|
181
|
+
* @param color An optional tint color.
|
|
182
|
+
*/
|
|
183
|
+
addRectVertex(w: number, h: number, color?: Color): void;
|
|
184
|
+
/**
|
|
185
|
+
* Pushes vertices for a circle geometry using TRIANGLES or similar primitives.
|
|
186
|
+
* @param r The radius of the circle.
|
|
187
|
+
* @param color An optional tint color.
|
|
188
|
+
* @param segments The number of segments (polygons) used to approximate the circle.
|
|
189
|
+
*/
|
|
190
|
+
addCircleVertex(r: number, color?: Color, segments?: number): void;
|
|
191
|
+
/**
|
|
192
|
+
* Adds an individual vertex to the current graphics batch.
|
|
193
|
+
* @param x The relative X coordinate of the vertex.
|
|
194
|
+
* @param y The relative Y coordinate of the vertex.
|
|
195
|
+
* @param u The U texture coordinate (0 to 1).
|
|
196
|
+
* @param v The V texture coordinate (0 to 1).
|
|
197
|
+
* @param color The vertex color as a 32-bit unsigned integer.
|
|
198
|
+
*/
|
|
199
|
+
addGraphicVertex(x: number, y: number, u?: number, v?: number, color?: number): void;
|
|
200
|
+
/**
|
|
201
|
+
* Ends the current graphics geometry definition, readying it for rendering.
|
|
202
|
+
*/
|
|
203
|
+
endGraphic(): void;
|
|
204
|
+
/**
|
|
205
|
+
* Resizes the canvas, updates internal viewport values, and recreates projection boundaries.
|
|
206
|
+
* @param logicWidth The new logical display width.
|
|
207
|
+
* @param logicHeight The new logical display height.
|
|
208
|
+
* @param cssWidth Optional CSS display width.
|
|
209
|
+
* @param cssHeight Optional CSS display height.
|
|
210
|
+
*/
|
|
211
|
+
resize(logicWidth: number, logicHeight: number, cssWidth?: number, cssHeight?: number): void;
|
|
212
|
+
/**
|
|
213
|
+
* Updates the projection matrix using an orthographic mapping.
|
|
214
|
+
* Automatically sets local flag projectionDirty.
|
|
95
215
|
*/
|
|
96
|
-
|
|
216
|
+
private updateProjection;
|
|
97
217
|
/**
|
|
98
|
-
*
|
|
218
|
+
* Clears the active framebuffer applying the default background color.
|
|
99
219
|
*/
|
|
100
|
-
|
|
220
|
+
clear(): void;
|
|
101
221
|
/**
|
|
102
|
-
*
|
|
103
|
-
*
|
|
222
|
+
* Populates an orthographic projection matrix in place.
|
|
223
|
+
* Avoids continuous Float32Array allocations for performance reasons.
|
|
104
224
|
*/
|
|
105
|
-
|
|
225
|
+
private updateOrthMatrix;
|
|
106
226
|
/**
|
|
107
|
-
*
|
|
108
|
-
* @param data - The map data to render.
|
|
109
|
-
* @param options - The options for rendering the tile map layer.
|
|
227
|
+
* Flushes currently buffered rendering operations across all active regions.
|
|
110
228
|
*/
|
|
111
|
-
|
|
112
|
-
applyCameraTransform(options: ICameraOptions): void;
|
|
229
|
+
flush(): void;
|
|
113
230
|
/**
|
|
114
|
-
*
|
|
231
|
+
* Applies a chain of shaders to a texture sequentially using ping-pong RenderTextures.
|
|
232
|
+
* Each shader receives the output of the previous one as its input.
|
|
233
|
+
* Two internal RenderTextures are reused across calls (resized as needed).
|
|
115
234
|
*
|
|
116
|
-
* @param
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
/**
|
|
121
|
-
* Renders a texture directly without additional options.
|
|
122
|
-
* This is a convenience method that calls renderSprite with just the texture.
|
|
235
|
+
* @param source The input texture to start the filter chain from.
|
|
236
|
+
* @param shaders An ordered array of CustomGlShader to apply in sequence.
|
|
237
|
+
* @returns The RenderTexture containing the final filtered result.
|
|
238
|
+
* Draw it with `rapid.drawSprite({ texture: result })` to display it on screen.
|
|
123
239
|
*
|
|
124
|
-
* @
|
|
240
|
+
* @example
|
|
241
|
+
* const result = rapid.applyFilters(tex, [blurShader, outlineShader]);
|
|
242
|
+
* rapid.drawSprite({ texture: result });
|
|
125
243
|
*/
|
|
126
|
-
|
|
244
|
+
applyFilters(source: Texture, shaders: CustomGlShader[]): RenderTexture;
|
|
245
|
+
enterRenderTexture(rt: RenderTexture): void;
|
|
127
246
|
/**
|
|
128
|
-
*
|
|
129
|
-
*
|
|
130
|
-
*
|
|
247
|
+
* Clears a RenderTexture to a solid color.
|
|
248
|
+
* Must be called while the RT is the active render target (i.e. inside enterRenderTexture/leaveRenderTexture).
|
|
249
|
+
* Can also be called standalone — it will bind the RT, clear it, but NOT restore the main framebuffer.
|
|
250
|
+
* @param rt The render texture to clear.
|
|
251
|
+
* @param color Clear color. Defaults to transparent black (0, 0, 0, 0).
|
|
131
252
|
*/
|
|
132
|
-
|
|
253
|
+
clearRenderTexture(color?: Color): void;
|
|
133
254
|
/**
|
|
134
|
-
*
|
|
135
|
-
*
|
|
136
|
-
* @param options - The options for rendering the graphic, including points, color, texture, and draw type.
|
|
255
|
+
* Completes rendering to an offscreen render texture and reverts rendering back to the main canvas.
|
|
137
256
|
*/
|
|
138
|
-
|
|
257
|
+
leaveRenderTexture(): void;
|
|
139
258
|
/**
|
|
140
|
-
*
|
|
259
|
+
* Convenience wrapper: enters a RenderTexture, optionally clears it, runs a callback, then leaves.
|
|
260
|
+
* @param rt The RenderTexture to render into.
|
|
261
|
+
* @param cb The callback containing draw calls to execute inside the RT.
|
|
262
|
+
* @param color Clear color before rendering. Pass `null` to skip clearing. Defaults to transparent black.
|
|
141
263
|
*
|
|
142
|
-
* @
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
264
|
+
* @example
|
|
265
|
+
* rapid.drawToRenderTexture(myRT, () => {
|
|
266
|
+
* rapid.drawSprite({ texture: mySprite });
|
|
267
|
+
* });
|
|
268
|
+
*/
|
|
269
|
+
drawToRenderTexture(rt: RenderTexture, cb: () => void, color?: Color | null): void;
|
|
270
|
+
/**
|
|
271
|
+
* Convenience wrapper: writes a mask using the stencil buffer, then renders within it, then exits the mask.
|
|
272
|
+
* @param maskCb Callback that defines the mask geometry (drawn to stencil, not visible).
|
|
273
|
+
* @param drawCb Callback containing the actual draw calls masked by the stencil.
|
|
274
|
+
* @param type Mask type: EQUAL (draw inside) or NOT_EQUAL (draw outside). Defaults to EQUAL.
|
|
275
|
+
* @param ref Stencil reference value. Defaults to 1.
|
|
147
276
|
*
|
|
148
|
-
* @
|
|
149
|
-
*
|
|
150
|
-
*
|
|
151
|
-
*
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
*
|
|
277
|
+
* @example
|
|
278
|
+
* rapid.withMask(
|
|
279
|
+
* () => rapid.drawRect({ width: 200, height: 200 }),
|
|
280
|
+
* () => rapid.drawSprite({ texture: myTexture }),
|
|
281
|
+
* );
|
|
282
|
+
*/
|
|
283
|
+
withMask(maskCb: () => void, drawCb: () => void, type?: MaskType, ref?: number): void;
|
|
284
|
+
/**
|
|
285
|
+
* Convenience wrapper: saves the matrix stack, applies an optional transform, runs a callback, then restores.
|
|
286
|
+
* When `transform` is provided, delegates to `matrixStack.applyTransform()` which handles
|
|
287
|
+
* position, rotation, scale, offset, and origin automatically.
|
|
288
|
+
* @param cb The callback to execute within the saved transform context.
|
|
289
|
+
* @param transform Optional transform options to apply before running the callback.
|
|
290
|
+
* @param width The logical width used to resolve `origin` anchoring. Defaults to 0.
|
|
291
|
+
* @param height The logical height used to resolve `origin` anchoring. Defaults to 0.
|
|
162
292
|
*
|
|
163
|
-
* @
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
*
|
|
293
|
+
* @example
|
|
294
|
+
* // Simple save/restore
|
|
295
|
+
* rapid.withTransform(() => {
|
|
296
|
+
* rapid.matrixStack.translate(100, 100);
|
|
297
|
+
* rapid.drawSprite({ texture: myTexture });
|
|
298
|
+
* });
|
|
168
299
|
*
|
|
169
|
-
* @
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
*
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
*
|
|
179
|
-
* @param
|
|
180
|
-
* @param
|
|
181
|
-
* @param
|
|
182
|
-
* @param
|
|
183
|
-
*
|
|
300
|
+
* @example
|
|
301
|
+
* // With a transform applied
|
|
302
|
+
* rapid.withTransform(() => {
|
|
303
|
+
* rapid.drawSprite({ texture: myTexture });
|
|
304
|
+
* }, { x: 100, y: 50, rotation: Math.PI / 4, origin: 0.5 }, myTexture.width, myTexture.height);
|
|
305
|
+
*/
|
|
306
|
+
withTransform(cb: () => void, transform?: ITransformOptions, width?: number, height?: number): void;
|
|
307
|
+
/**
|
|
308
|
+
* Convenience wrapper: enables scissor clipping for a region, runs a callback, then disables it.
|
|
309
|
+
* @param x Left edge in logical pixels.
|
|
310
|
+
* @param y Top edge in logical pixels.
|
|
311
|
+
* @param width Width in logical pixels.
|
|
312
|
+
* @param height Height in logical pixels.
|
|
313
|
+
* @param cb The callback to execute within the scissor region.
|
|
314
|
+
*
|
|
315
|
+
* @example
|
|
316
|
+
* rapid.withScissor(50, 50, 300, 200, () => {
|
|
317
|
+
* rapid.drawSprite({ texture: myTexture });
|
|
318
|
+
* });
|
|
184
319
|
*/
|
|
185
|
-
|
|
320
|
+
withScissor(x: number, y: number, width: number, height: number, cb: () => void): void;
|
|
186
321
|
/**
|
|
187
|
-
*
|
|
188
|
-
* @param
|
|
189
|
-
* @param cb
|
|
322
|
+
* Convenience wrapper: sets a blend mode, runs a callback, then restores NORMAL blend mode.
|
|
323
|
+
* @param mode The BlendMode to apply for the duration of the callback.
|
|
324
|
+
* @param cb The callback to execute under the given blend mode.
|
|
325
|
+
*
|
|
326
|
+
* @example
|
|
327
|
+
* rapid.withBlendMode(BlendMode.ADD, () => {
|
|
328
|
+
* rapid.drawSprite({ texture: glowTexture });
|
|
329
|
+
* });
|
|
190
330
|
*/
|
|
191
|
-
|
|
331
|
+
withBlendMode(mode: BlendMode, cb: () => void): void;
|
|
192
332
|
/**
|
|
193
|
-
*
|
|
194
|
-
*
|
|
333
|
+
* Starts drawing into the stencil buffer to construct a rendering mask.
|
|
334
|
+
* @param ref The stencil reference value.
|
|
335
|
+
* @param mask The stencil bitmask.
|
|
195
336
|
*/
|
|
196
|
-
startDrawMask(
|
|
337
|
+
startDrawMask(ref?: number, mask?: number): void;
|
|
197
338
|
/**
|
|
198
|
-
*
|
|
199
|
-
* This method configures the WebGL context to use the defined mask for subsequent rendering.
|
|
339
|
+
* Finishes the mask drawing phase and restores color buffer writing.
|
|
200
340
|
*/
|
|
201
341
|
endDrawMask(): void;
|
|
202
342
|
/**
|
|
203
|
-
*
|
|
204
|
-
* @param
|
|
205
|
-
* @param start - Whether this is the start of mask drawing
|
|
343
|
+
* Clears bounds created into the stencil mask.
|
|
344
|
+
* @param mask The bitmask specifying which stencil layer to clear.
|
|
206
345
|
*/
|
|
207
|
-
|
|
346
|
+
clearMask(mask?: number): void;
|
|
208
347
|
/**
|
|
209
|
-
*
|
|
210
|
-
*
|
|
348
|
+
* Enters a constrained rendering phase masked by the existing stencil buffer values.
|
|
349
|
+
* @param type Equality check type. Use "equal" to draw inside the mask, or "notEqual" to draw outside.
|
|
350
|
+
* @param ref The reference value to test against.
|
|
351
|
+
* @param mask The bitmask specifying which stencil bits to consider.
|
|
211
352
|
*/
|
|
212
|
-
|
|
353
|
+
enterMask(type: MaskType, ref?: number, mask?: number): void;
|
|
213
354
|
/**
|
|
214
|
-
*
|
|
215
|
-
* @param vs - Vertex shader code.
|
|
216
|
-
* @param fs - Fragment shader code.
|
|
217
|
-
* @param type - Shader type.
|
|
218
|
-
* @returns The created shader object.
|
|
355
|
+
* Exits the masked rendering phase, restoring default full-screen stencil values tests.
|
|
219
356
|
*/
|
|
220
|
-
|
|
357
|
+
exitMask(): void;
|
|
221
358
|
/**
|
|
222
|
-
*
|
|
223
|
-
*
|
|
224
|
-
* @param fbo - The Frame Buffer Object to render to
|
|
225
|
-
*/
|
|
226
|
-
startFBO(fbo: FrameBufferObject): void;
|
|
227
|
-
/**
|
|
228
|
-
* Ends rendering to a Frame Buffer Object
|
|
229
|
-
* Restores the default framebuffer and original viewport settings
|
|
230
|
-
* @param fbo - The Frame Buffer Object to unbind
|
|
231
|
-
*/
|
|
232
|
-
endFBO(): void;
|
|
233
|
-
/**
|
|
234
|
-
* Convenience method to render to a Frame Buffer Object
|
|
235
|
-
* Handles starting and ending the FBO rendering automatically
|
|
236
|
-
* @param fbo - The Frame Buffer Object to render to
|
|
237
|
-
* @param cb - Callback function containing render commands to execute on the FBO
|
|
238
|
-
*/
|
|
239
|
-
drawToFBO(fbo: FrameBufferObject, cb: () => void): void;
|
|
240
|
-
/**
|
|
241
|
-
* Set the blend mode for rendering
|
|
242
|
-
* @param mode - The blend mode to apply
|
|
359
|
+
* Configures the global WebGL blending behavior.
|
|
360
|
+
* @param mode The targeted BlendMode to switch onto.
|
|
243
361
|
*/
|
|
244
362
|
setBlendMode(mode: BlendMode): void;
|
|
245
363
|
/**
|
|
246
|
-
*
|
|
247
|
-
*
|
|
248
|
-
*
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
364
|
+
* Enables rectangular scissor clipping. Only pixels within the specified
|
|
365
|
+
* rectangle (in logical coordinates) will be rendered.
|
|
366
|
+
* Coordinates use the same system as your drawing calls (top-left origin).
|
|
367
|
+
* @param x Left edge in logical pixels.
|
|
368
|
+
* @param y Top edge in logical pixels.
|
|
369
|
+
* @param width Width in logical pixels.
|
|
370
|
+
* @param height Height in logical pixels.
|
|
371
|
+
*/
|
|
372
|
+
startScissor(x: number, y: number, width: number, height: number): void;
|
|
373
|
+
/**
|
|
374
|
+
* Disables scissor clipping, restoring full-canvas rendering.
|
|
375
|
+
*/
|
|
376
|
+
endScissor(): void;
|
|
377
|
+
renderCamera(transform: ITransformOptions): void;
|
|
378
|
+
logicToPhysics(p: Vec2): Vec2;
|
|
379
|
+
physicsToLogic(p: Vec2): Vec2;
|
|
380
|
+
cssToDevicePixel(p: Vec2): Vec2;
|
|
381
|
+
cssToLogic(p: Vec2): Vec2;
|
|
382
|
+
devicePixelToCss(p: Vec2): Vec2;
|
|
383
|
+
/**
|
|
384
|
+
* Exports a world matrix as a CSS `matrix(...)` string, ready to assign
|
|
385
|
+
* directly to a DOM element's `style.transform`.
|
|
386
|
+
* Unlike `matrixStack.toCSSMatrix()`, this bakes in the logic-pixel → CSS-pixel
|
|
387
|
+
* scale (accounting for dpr and a custom `logicWidth`/`logicHeight`), so the
|
|
388
|
+
* result lines up with the canvas without any extra `scale(...)` on your end.
|
|
389
|
+
* @param index - Matrix index to export. Defaults to the current world matrix.
|
|
390
|
+
*/
|
|
391
|
+
toCSSMatrix(index?: number): string;
|
|
254
392
|
}
|
|
255
|
-
export default Rapid;
|