@@ -21,7 +21,7 @@ import {webgl2Adapter} from '@luma.gl/webgl';
21
21
import { Timeline } from '@luma.gl/engine' ;
22
22
import { AnimationLoop } from '@luma.gl/engine' ;
23
23
import { GL } from '@luma.gl/constants' ;
24
- import type { Device , DeviceProps , Framebuffer , Parameters } from '@luma.gl/core' ;
24
+ import type { CanvasContextProps , Device , DeviceProps , Framebuffer , Parameters } from '@luma.gl/core' ;
25
25
import type { ShaderModule } from '@luma.gl/shadertools' ;
26
26
27
27
import { Stats } from '@probe.gl/stats' ;
@@ -374,34 +374,7 @@ export default class Deck<ViewsT extends ViewOrViews = null> {
374
374
375
375
// Create a new device
376
376
if ( ! deviceOrPromise ) {
377
- const canvasContextUserProps = this . props . deviceProps ?. createCanvasContext ;
378
- const canvasContextProps =
379
- typeof canvasContextUserProps === 'object' ? canvasContextUserProps : undefined ;
380
-
381
- // In deck.gl v9, Deck always bundles and adds a webgl2Adapter.
382
- // This behavior is expected to change in deck.gl v10 to support WebGPU only builds.
383
- const deviceProps = { adapters : [ ] , ...props . deviceProps } ;
384
- if ( ! deviceProps . adapters . includes ( webgl2Adapter ) ) {
385
- deviceProps . adapters . push ( webgl2Adapter ) ;
386
- }
387
-
388
- // Create the "best" device supported from the registered adapters
389
- deviceOrPromise = luma . createDevice ( {
390
- // luma by default throws if a device is already attached
391
- // asynchronous device creation could happen after finalize() is called
392
- // TODO - createDevice should support AbortController?
393
- _reuseDevices : true ,
394
- // tests can't handle WebGPU devices yet so we force WebGL2 unless overridden
395
- type : 'webgl' ,
396
- ...deviceProps ,
397
- // In deck.gl v10 we may emphasize multi canvas support and unwind this prop wrapping
398
- createCanvasContext : {
399
- ...canvasContextProps ,
400
- canvas : this . _createCanvas ( props ) ,
401
- useDevicePixels : this . props . useDevicePixels ,
402
- autoResize : true
403
- }
404
- } ) ;
377
+ deviceOrPromise = this . _createDevice ( props ) ;
405
378
}
406
379
407
380
this . animationLoop = this . _createAnimationLoop ( deviceOrPromise , props ) ;
@@ -874,6 +847,44 @@ export default class Deck<ViewsT extends ViewOrViews = null> {
874
847
} ) ;
875
848
}
876
849
850
+ // Create a device from the deviceProps, assigning required defaults
851
+ private _createDevice ( props : DeckProps < ViewsT > ) : Promise < Device > {
852
+ const canvasContextUserProps = this . props . deviceProps ?. createCanvasContext ;
853
+ const canvasContextProps =
854
+ typeof canvasContextUserProps === 'object' ? canvasContextUserProps : undefined ;
855
+
856
+ // In deck.gl v9, Deck always bundles and adds a webgl2Adapter.
857
+ // This behavior is expected to change in deck.gl v10 to support WebGPU only builds.
858
+ const deviceProps = { adapters : [ ] , ...props . deviceProps } ;
859
+ if ( ! deviceProps . adapters . includes ( webgl2Adapter ) ) {
860
+ deviceProps . adapters . push ( webgl2Adapter ) ;
861
+ }
862
+
863
+ const defaultCanvasProps : CanvasContextProps = {
864
+ // we must use 'premultiplied' canvas for webgpu to enable transparency and match shaders
865
+ alphaMode : this . props . deviceProps ?. type === 'webgpu' ? 'premultiplied' : undefined
866
+ } ;
867
+
868
+ // Create the "best" device supported from the registered adapters
869
+ return luma . createDevice ( {
870
+ // luma by default throws if a device is already attached
871
+ // asynchronous device creation could happen after finalize() is called
872
+ // TODO - createDevice should support AbortController?
873
+ _reuseDevices : true ,
874
+ // tests can't handle WebGPU devices yet so we force WebGL2 unless overridden
875
+ type : 'webgl' ,
876
+ ...deviceProps ,
877
+ // In deck.gl v10 we may emphasize multi canvas support and unwind this prop wrapping
878
+ createCanvasContext : {
879
+ ...defaultCanvasProps ,
880
+ ...canvasContextProps ,
881
+ canvas : this . _createCanvas ( props ) ,
882
+ useDevicePixels : this . props . useDevicePixels ,
883
+ autoResize : true
884
+ }
885
+ } ) ;
886
+ }
887
+
877
888
// Get the most relevant view state: props.viewState, if supplied, shadows internal viewState
878
889
// TODO: For backwards compatibility ensure numeric width and height is added to the viewState
879
890
private _getViewState ( ) : ViewStateObject < ViewsT > | null {
0 commit comments