ADocumentation Index
Fetch the complete documentation index at: https://mintlify.com/Nightre/Rapid.js/llms.txt
Use this file to discover all available pages before exploring further.
RenderTexture wraps a WebGL framebuffer and renderbuffer, letting you redirect draw calls to an offscreen surface and then use that surface as an ordinary texture in subsequent draw calls. This is the foundation for post-processing effects, dynamic compositing, shadow maps, and any technique that needs to capture intermediate rendering results.
Creating a RenderTexture
Userapid.texture.createRenderTexture and supply at minimum a width and height:
IRenderTextureOptions
| Option | Type | Description |
|---|---|---|
width | number | Width of the render texture in pixels (required). |
height | number | Height of the render texture in pixels (required). |
clearColor | Color | Default clear color. Defaults to Color.Black. |
textureFilter | TextureFilterMode | Sampling filter (LINEAR or NEAREST). |
wrap | TextureWrapMode | Texture wrap mode (REPEAT, CLAMP, or MIRRORED_REPEAT). |
premultipliedAlpha | boolean | Whether texture data uses premultiplied alpha. |
Rendering Into a RenderTexture
Convenience Wrapper (Recommended)
drawToRenderTexture handles entering, optionally clearing, and leaving the render target in a single call. The third argument controls the clear color — pass null to skip clearing and composite on top of existing content.
Manual Enter / Leave
When you need finer control — for example to interleave multiple render targets — use the lower-level API:enterRenderTexture flushes any pending draw calls, activates the framebuffer, and resets the viewport and projection matrix to fit the render texture. leaveRenderTexture reverses all of that, restoring the main canvas state.
clearRenderTexture accepts an optional Color argument. If you omit it, it clears to transparent black (0, 0, 0, 0). Pass null to drawToRenderTexture’s third argument to skip clearing entirely and keep existing content.Using the Result as a Texture
Once rendering is complete, aRenderTexture can be passed anywhere a regular Texture is accepted:
flipY = true on every RenderTexture. This means the image will appear the correct way up when drawn with drawSprite — no manual flipping required.
Reading Pixel Data
RenderTexture exposes two methods for reading back pixel data from the GPU:
Resizing a RenderTexture
Callresize to adjust the logical dimensions of an existing render texture:
resize frequently or inside filter loops without causing excessive allocations.
Post-Processing with applyFilters
applyFilters chains an array of CustomGlShader passes over a source texture using an internal ping-pong pair of RenderTexture objects. Each pass receives the output of the previous one as its input, and the final result is returned as a RenderTexture ready to draw.
applyFilters is efficient to call every frame for real-time effects.