-
Notifications
You must be signed in to change notification settings - Fork 206
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: fix canvas.ready never resolve when switch to webgl, webgpu rend…
…erer (#1737) * fix: fix canvas.ready never resolve when switch to webgl, webgpu renderer * test: add test case
- Loading branch information
Showing
4 changed files
with
44 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { switchRenderer } from './switch-renderer'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { Circle } from '../../../packages/g'; | ||
import { Renderer as CanvasRenderer } from '../../../packages/g-canvas'; | ||
import { Renderer as SVGRenderer } from '../../../packages/g-svg'; | ||
import { Renderer as WebGLRenderer } from '../../../packages/g-webgl'; | ||
|
||
export async function switchRenderer(context) { | ||
const { canvas, gui } = context; | ||
|
||
await canvas.ready; | ||
|
||
const circle = new Circle({ | ||
style: { | ||
cx: 100, | ||
cy: 100, | ||
r: 50, | ||
fill: 'red', | ||
}, | ||
}); | ||
|
||
canvas.appendChild(circle); | ||
|
||
const folder = gui.addFolder('renderer'); | ||
folder | ||
.add({ renderer: 'canvas' }, 'renderer', ['canvas', 'svg', 'webgl']) | ||
.onChange((name) => { | ||
let renderer; | ||
if (name === 'canvas') renderer = new CanvasRenderer(); | ||
else if (name === 'svg') renderer = new SVGRenderer(); | ||
else if (name === 'webgl') renderer = new WebGLRenderer(); | ||
|
||
canvas.setRenderer(renderer); | ||
|
||
canvas.ready.then(() => { | ||
alert(`Switch to ${name} renderer`); | ||
}); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters