rapid-render 0.1.111 → 1.0.2

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