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/dist/render.d.ts CHANGED
@@ -1,255 +1,392 @@
1
- import { ICircleRenderOptions, IGraphicRenderOptions, ILayerRenderOptions, IRapidOptions, IRectRenderOptions, IRenderLineOptions, ISpriteRenderOptions, ShaderType as ShaderType, MaskType, WebGLContext, BlendMode, ILightRenderOptions, IParticleOptions, ICameraOptions, IPolygonGraphicRenderOptions } from "./interface";
2
- import { LightManager } from "./light";
3
- import { Color, MatrixStack, Vec2 } from "./math";
4
- import RenderRegion from "./regions/region";
5
- import { FrameBufferObject, Texture, TextureCache } from "./texture";
6
- import { TileMapRender, TileSet } from "./tilemap";
7
- import GLShader from "./webgl/glshader";
8
- import { ParticleEmitter } from "./particle";
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
- * The `Rapid` class provides a WebGL-based rendering engine.
13
+ * Options for initializing the Rapid application.
11
14
  */
12
- declare class Rapid {
13
- gl: WebGLContext;
15
+ export interface IAppOptions {
16
+ /** The HTML canvas element to render onto. */
14
17
  canvas: HTMLCanvasElement;
15
- projection: Float32Array;
16
- projectionDirty: boolean;
17
- matrixStack: MatrixStack;
18
- textures: TextureCache;
19
- tileMap: TileMapRender;
20
- light: LightManager;
21
- width: number;
22
- height: number;
23
- backgroundColor: Color;
24
- devicePixelRatio: number;
25
- private physicsWidth;
26
- private physicsHeight;
27
- private logicWidth;
28
- private logicHeight;
29
- private scaleEnable;
30
- private scaleRadio;
31
- readonly maxTextureUnits: number;
32
- private readonly defaultColor;
33
- private currentRegion?;
34
- private currentRegionName?;
35
- private regions;
36
- private currentMaskType;
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
- * Sets the current render region by name and optionally a custom shader.
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
- setRegion(regionName: string, customShader?: GLShader): void;
43
+ EQUAL = 0,
79
44
  /**
80
- * Saves the current matrix state to the stack.
45
+ * Draw outside the mask.
81
46
  */
82
- save(): void;
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
- * Restores the matrix state from the stack.
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
- restore(): void;
74
+ CanvasItem = 0,
87
75
  /**
88
- * Executes a callback function within a saved and restored matrix state scope.
89
- * @param cb - The callback function to execute within the saved and restored matrix state scope.
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
- withTransform(cb: () => void): void;
92
- /**
93
- * Starts the rendering process, resetting the matrix stack and clearing the current region.
94
- * @param clear - Whether to clear the matrix stack. Defaults to true.
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
- startRender(clear?: boolean): number;
216
+ private updateProjection;
97
217
  /**
98
- * Ends the rendering process by rendering the current region.
218
+ * Clears the active framebuffer applying the default background color.
99
219
  */
100
- endRender(): void;
220
+ clear(): void;
101
221
  /**
102
- * Render
103
- * @param cb - The function to render.
222
+ * Populates an orthographic projection matrix in place.
223
+ * Avoids continuous Float32Array allocations for performance reasons.
104
224
  */
105
- render(cb: (dt: number) => void): void;
225
+ private updateOrthMatrix;
106
226
  /**
107
- * Render a tile map layer.
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
- renderTileMapLayer(data: (number | string)[][], options: ILayerRenderOptions | TileSet): void;
112
- applyCameraTransform(options: ICameraOptions): void;
229
+ flush(): void;
113
230
  /**
114
- * Renders a sprite with the specified options.
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 options - The rendering options for the sprite, including texture, position, color, and shader.
117
- */
118
- renderSprite(options: ISpriteRenderOptions): void;
119
- renderParticles(particleEmitter: ParticleEmitter): void;
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
- * @param texture - The texture to render at the current transformation position.
240
+ * @example
241
+ * const result = rapid.applyFilters(tex, [blurShader, outlineShader]);
242
+ * rapid.drawSprite({ texture: result });
125
243
  */
126
- renderTexture(texture: Texture): void;
244
+ applyFilters(source: Texture, shaders: CustomGlShader[]): RenderTexture;
245
+ enterRenderTexture(rt: RenderTexture): void;
127
246
  /**
128
- * Renders a line with the specified options.
129
- *
130
- * @param options - The options for rendering the line, including points, color, width, and join/cap types.
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
- renderLine(options: IRenderLineOptions): void;
253
+ clearRenderTexture(color?: Color): void;
133
254
  /**
134
- * Renders graphics based on the provided options.
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
- renderGraphic(options: IPolygonGraphicRenderOptions): void;
257
+ leaveRenderTexture(): void;
139
258
  /**
140
- * Starts the graphic drawing process.
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
- * @param options - The options for the graphic drawing, including shader, texture, and draw type.
143
- */
144
- startGraphicDraw(options: IGraphicRenderOptions): void;
145
- /**
146
- * Adds a vertex to the current graphic being drawn.
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
- * @param offsetX - The X coordinate of the vertex.
149
- * @param offsetY - The Y coordinate of the vertex.
150
- * @param uv - The texture UV coordinates for the vertex.
151
- * @param color - The color of the vertex. Defaults to the renderer's default color.
152
- */
153
- addGraphicVertex(offsetX: number, offsetY: number, uv: Vec2, color?: Color): void;
154
- /**
155
- * Completes the graphic drawing process and renders the result.
156
- */
157
- endGraphicDraw(): void;
158
- private startDraw;
159
- private afterDraw;
160
- /**
161
- * Renders a rectangle with the specified options.
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
- * @param options - The options for rendering the rectangle, including width, height, position, and color.
164
- */
165
- renderRect(options: IRectRenderOptions): void;
166
- /**
167
- * Renders a circle with the specified options.
293
+ * @example
294
+ * // Simple save/restore
295
+ * rapid.withTransform(() => {
296
+ * rapid.matrixStack.translate(100, 100);
297
+ * rapid.drawSprite({ texture: myTexture });
298
+ * });
168
299
  *
169
- * @param options - The options for rendering the circle, including radius, position, color, and segment count.
170
- */
171
- renderCircle(options: ICircleRenderOptions): void;
172
- /**
173
- * Clears the canvas with the background color.
174
- * @param bgColor - The background color to clear the canvas with.
175
- */
176
- clear(bgColor?: Color): void;
177
- /**
178
- * Creates an orthogonal projection matrix.
179
- * @param left - The left bound of the projection.
180
- * @param right - The right bound of the projection.
181
- * @param bottom - The bottom bound of the projection.
182
- * @param top - The top bound of the projection.
183
- * @returns The orthogonal projection matrix as a `Float32Array`.
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
- private createOrthMatrix;
320
+ withScissor(x: number, y: number, width: number, height: number, cb: () => void): void;
186
321
  /**
187
- * Draw a mask. Automatically calls startDrawMask.
188
- * @param type - The type of mask to draw.
189
- * @param cb - The callback function to execute.
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
- drawMask(type: MaskType | undefined, cb: () => void): void;
331
+ withBlendMode(mode: BlendMode, cb: () => void): void;
192
332
  /**
193
- * Start drawing a mask using the stencil buffer.
194
- * This method configures the WebGL context to begin defining a mask area.
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(type?: MaskType): void;
337
+ startDrawMask(ref?: number, mask?: number): void;
197
338
  /**
198
- * End the mask drawing process.
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
- * Set the mask type for rendering
204
- * @param type - The mask type to apply
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
- private setMaskType;
346
+ clearMask(mask?: number): void;
208
347
  /**
209
- * Clear the current mask by clearing the stencil buffer.
210
- * This effectively removes any previously defined mask.
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
- clearMask(): void;
353
+ enterMask(type: MaskType, ref?: number, mask?: number): void;
213
354
  /**
214
- * Creates a custom shader.
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
- createCostumShader(vs: string, fs: string, type: ShaderType, textureUnitNum?: number): GLShader;
357
+ exitMask(): void;
221
358
  /**
222
- * Starts rendering to a Frame Buffer Object (FBO)
223
- * Sets up the FBO for rendering by binding it, adjusting viewport size and projection
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
- * Render light shadow
247
- * @param occlusion - The occlusion polygon
248
- * @param lightSource - The light source position
249
- */
250
- drawLightShadowMask(options: ILightRenderOptions): void;
251
- createParticleEmitter(options: IParticleOptions): ParticleEmitter;
252
- cssToGameCoords(x: number | Vec2, y?: number): Vec2;
253
- gameToCssCoords(x: number | Vec2, y?: number): Vec2;
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;