@@ -30,7 +30,30 @@ export class Window extends NSWindow implements NSWindowDelegate {
30
30
context ! : GPUCanvasContext ;
31
31
renderPipeline ! : GPURenderPipeline ;
32
32
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 ( ) {
34
57
const menu = NSMenu . new ( ) ;
35
58
NSApp . mainMenu = menu ;
36
59
@@ -57,24 +80,7 @@ export class Window extends NSWindow implements NSWindowDelegate {
57
80
58
81
this . isReleasedWhenClosed = false ;
59
82
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 ( ) ;
78
84
79
85
const shaderCode = `
80
86
@vertex
@@ -133,7 +139,7 @@ fn fs_main() -> @___location(0) vec4<f32> {
133
139
view : texture ,
134
140
storeOp : "store" ,
135
141
loadOp : "clear" ,
136
- clearValue : { r : 0 , g : 1 , b : 0 , a : 1.0 } ,
142
+ clearValue : { r : 0 , g : 0 , b : 0 , a : 1.0 } ,
137
143
} ,
138
144
] ,
139
145
} ) ;
@@ -144,6 +150,11 @@ fn fs_main() -> @___location(0) vec4<f32> {
144
150
this . surface . present ( ) ;
145
151
}
146
152
153
+ windowDidResize ( _notification : NSNotification ) : void {
154
+ this . configure ( ) ;
155
+ this . render ( ) ;
156
+ }
157
+
147
158
windowWillClose ( _notification : NSNotification ) {
148
159
NSApp . terminate ( this ) ;
149
160
}
0 commit comments