Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions docs/essentials/settings.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,40 @@ Example font object:
|----------------|-----------|-------------|
| `renderMode` | `'webgl' \| 'canvas'` | Renderer mode (default: 'webgl') |
| `canvas` | `HTMLCanvasElement` | Custom canvas to render to |
| `platform` | `'web' \| 'next' \| 'chrome50' \| 'legacy' \| Platform` | Platform abstraction layer used by the Lightning renderer (default: `'web'`) |

### Platform

The `platform` setting selects which platform abstraction the underlying Lightning renderer uses to talk to the browser (image loading, canvas creation, etc.). Most Apps should leave this unset and use the default `web` platform; the alternatives exist for environments where the modern browser APIs aren't fully available.

You can pass either a **string alias** (recommended) or a **`Platform` class reference** imported directly from `@lightningjs/renderer/platforms` for full control (including custom subclasses).

| Value | Browser engine |
|------------|-------------|
| `web` | Chrome 70+ |
| `next` | Chrome 70+ |
| `chrome50` | Chrome 50+ |
| `legacy` | Chrome 40+ |

Example using a string alias:
```js
Blits.Launch(App, 'app', {
w: 1920,
h: 1080,
platform: 'legacy',
})
```

Example passing a class reference:
```js
import { WebPlatformChrome50 } from '@lightningjs/renderer/platforms'

Blits.Launch(App, 'app', {
w: 1920,
h: 1080,
platform: WebPlatformChrome50,
})
```

## Effects & Shaders

Expand Down Expand Up @@ -118,5 +152,6 @@ Blits.Launch(App, 'app', {
inspector: false,
announcer: true,
enableMouse: false, // set true for hover + click-to-focus on canvas
platform: 'web', // 'web' (default) | 'next' | 'chrome50' | 'legacy'
})
```
25 changes: 25 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1003,6 +1003,7 @@ declare module '@lightningjs/blits' {

type ReactivityModes = 'Proxy' | 'defineProperty'
type RenderModes = 'webgl' | 'canvas'
type Platforms = 'web' | 'next' | 'chrome50' | 'legacy'

/**
* Settings
Expand Down Expand Up @@ -1222,6 +1223,30 @@ declare module '@lightningjs/blits' {
*/
renderMode?: RenderModes,

/**
* Selects the platform abstraction layer used by the Lightning renderer.
*
* Accepts either:
* - A string alias for one of the bundled implementations:
* - `web` (default) - Modern browsers with full `createImageBitmap` support
* - `next` - PWAs / Service Worker environments using the Fetch API for image loading
* - `chrome50` - Older Chromium / WPEWebKit 2017 with basic `createImageBitmap` support
* - `legacy` - QtWebKit and other legacy engines with limited browser APIs
* - A `Platform` class reference imported from `@lightningjs/renderer/platforms`
* (or a custom subclass) for full control over the platform implementation.
*
* When omitted, the renderer falls back to `WebPlatform`.
*
* @example
* ```js
* import { WebPlatformChrome50 } from '@lightningjs/renderer/platforms'
*
* Blits.Launch(App, 'app', { platform: WebPlatformChrome50 })
* Blits.Launch(App, 'app', { platform: 'chrome50' }) // equivalent
* ```
*/
platform?: Platforms | (new (...args: any[]) => any),

/**
* The time, in milliseconds, after which Blits considers a key press a _hold_ key press
*
Expand Down
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
"tape": "^5.5.0"
},
"dependencies": {
"@lightningjs/renderer": "^3.0.3",
"@lightningjs/renderer": "^3.0.5",
"magic-string": "^0.30.21"
},
"repository": {
Expand Down
18 changes: 17 additions & 1 deletion src/engines/L3/launch.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ import { RendererMain } from '@lightningjs/renderer'
import { WebGlCoreRenderer, SdfTextRenderer } from '@lightningjs/renderer/webgl'
import { CanvasCoreRenderer, CanvasTextRenderer } from '@lightningjs/renderer/canvas'
import { Inspector } from '@lightningjs/renderer/inspector'
import {
WebPlatform,
WebPlatformNext,
WebPlatformChrome50,
WebPlatformLegacy,
} from '@lightningjs/renderer/platforms'

import { Log } from '../../lib/log.js'
import { SCREEN_RESOLUTIONS, RENDER_QUALITIES } from '../../constants.js'
Expand All @@ -43,6 +49,13 @@ const textRenderEngines = (settings) => {
if (renderMode === 'canvas') return [CanvasTextRenderer]
}

const PLATFORMS = {
web: WebPlatform,
next: WebPlatformNext,
chrome50: WebPlatformChrome50,
legacy: WebPlatformLegacy,
}

const textureMemorySettings = (settings) => {
const gpuMemory = {
...{
Expand Down Expand Up @@ -100,7 +113,10 @@ export default (App, target, settings = {}) => {
textureMemory: textureMemorySettings(settings),
createImageBitmapSupport: 'auto',
targetFPS: 'maxFPS' in settings ? settings.maxFPS : 0,
platform: 'platform' in settings ? settings.platform : null,
platform:
typeof settings.platform === 'function'
? settings.platform
: PLATFORMS[settings.platform] || WebPlatform,
},
...(settings.advanced || {}),
},
Expand Down
1 change: 1 addition & 0 deletions src/launch.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ async function rendererVersion() {
* @property {number} [gpuMemoryLimit] - Threshold after which textures are freed (deprecated)
* @property {object} [gpuMemory] - Configures the gpu memory settings
* @property {"webgl"|"canvas"} [renderMode] - Defines which mode the renderer should operate in
* @property {"web"|"next"|"chrome50"|"legacy"|Function} [platform] - Platform abstraction layer used by the renderer. Either a string alias or a `Platform` class from `@lightningjs/renderer/platforms`
* @property {number} [holdTimeout] - Time after which a key press is considered a hold
* @property {HTMLCanvasElement} [canvas] - Custom canvas object used to render the App
* @property {number} [textureProcessingTimeLimit] - Max time renderer can process textures in a frame
Expand Down
Loading