@@ -30,7 +30,30 @@ export class Window extends NSWindow implements NSWindowDelegate {
3030 context ! : GPUCanvasContext ;
3131 renderPipeline ! : GPURenderPipeline ;
3232
33- init ( ) {
33+ configure ( ) {
34+ const { width, height } = this . convertRectToBacking ( this . frame ) . size ;
35+
36+ this . surface = new Deno . UnsafeWindowSurface ( {
37+ system : "cocoa" ,
38+ windowHandle : Deno . UnsafePointer . create (
39+ BigInt ( interop . handleof ( this ) . toNumber ( ) )
40+ ) ,
41+ displayHandle : Deno . UnsafePointer . create (
42+ BigInt ( interop . handleof ( this . contentView ) . toNumber ( ) )
43+ ) ,
44+ width,
45+ height,
46+ } ) ;
47+
48+ this . context = this . surface . getContext ( "webgpu" ) ;
49+
50+ this . context . configure ( {
51+ device,
52+ format : "bgra8unorm" ,
53+ } ) ;
54+ }
55+
56+ override init ( ) {
3457 const menu = NSMenu . new ( ) ;
3558 NSApp . mainMenu = menu ;
3659
@@ -57,24 +80,7 @@ export class Window extends NSWindow implements NSWindowDelegate {
5780
5881 this . isReleasedWhenClosed = false ;
5982
60- this . surface = new Deno . UnsafeWindowSurface (
61- "cocoa" ,
62- Deno . UnsafePointer . create ( BigInt ( interop . handleof ( this ) . toNumber ( ) ) ) ,
63- Deno . UnsafePointer . create (
64- BigInt ( interop . handleof ( this . contentView ) . toNumber ( ) )
65- )
66- ) ;
67-
68- const { width, height } = this . convertRectToBacking ( this . frame ) . size ;
69-
70- this . context = this . surface . getContext ( "webgpu" ) ;
71-
72- this . context . configure ( {
73- device,
74- format : "bgra8unorm" ,
75- width,
76- height,
77- } ) ;
83+ this . configure ( ) ;
7884
7985 const shaderCode = `
8086@vertex
@@ -133,7 +139,7 @@ fn fs_main() -> @location(0) vec4<f32> {
133139 view : texture ,
134140 storeOp : "store" ,
135141 loadOp : "clear" ,
136- clearValue : { r : 0 , g : 1 , b : 0 , a : 1.0 } ,
142+ clearValue : { r : 0 , g : 0 , b : 0 , a : 1.0 } ,
137143 } ,
138144 ] ,
139145 } ) ;
@@ -144,6 +150,11 @@ fn fs_main() -> @location(0) vec4<f32> {
144150 this . surface . present ( ) ;
145151 }
146152
153+ windowDidResize ( _notification : NSNotification ) : void {
154+ this . configure ( ) ;
155+ this . render ( ) ;
156+ }
157+
147158 windowWillClose ( _notification : NSNotification ) {
148159 NSApp . terminate ( this ) ;
149160 }
0 commit comments