fix(webgl): WebGLAdapter.attach support passing DeviceProps (#2453) (#2454)

This commit is contained in:
felixpalmer 2025-09-30 18:04:21 +02:00 committed by GitHub
parent 4df467b52f
commit eccb6b1ca1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -50,7 +50,7 @@ export class WebGLAdapter extends Adapter {
* @param gl
* @returns
*/
async attach(gl: Device | WebGL2RenderingContext): Promise<WebGLDevice> {
async attach(gl: Device | WebGL2RenderingContext, props: DeviceProps = {}): Promise<WebGLDevice> {
const {WebGLDevice} = await import('./webgl-device');
if (gl instanceof WebGLDevice) {
return gl;
@ -64,11 +64,14 @@ export class WebGLAdapter extends Adapter {
throw new Error('Invalid WebGL2RenderingContext');
}
const createCanvasContext = props.createCanvasContext === true ? {} : props.createCanvasContext;
// We create a new device using the provided WebGL context and its canvas
// Assume that whoever created the external context will be handling resizes.
return new WebGLDevice({
...props,
_handle: gl,
createCanvasContext: {canvas: gl.canvas, autoResize: false}
createCanvasContext: {canvas: gl.canvas, autoResize: false, ...createCanvasContext}
});
}