@@ -14,8 +14,7 @@ quitIfWebGPUNotAvailable(adapter, device);
14
14
//
15
15
16
16
const kInitConfig = {
17
- width : 8 ,
18
- height : 8 ,
17
+ sizeLog2 : 3 ,
19
18
showResolvedColor : true ,
20
19
color1 : 0x0000ff ,
21
20
alpha1 : 127 ,
@@ -37,8 +36,7 @@ gui.width = 300;
37
36
38
37
const settings = gui . addFolder ( 'Settings' ) ;
39
38
settings . open ( ) ;
40
- settings . add ( config , 'width' , 1 , 16 , 1 ) ;
41
- settings . add ( config , 'height' , 1 , 16 , 1 ) ;
39
+ settings . add ( config , 'sizeLog2' , 0 , 8 , 1 ) . name ( 'size = 2**' ) ;
42
40
settings . add ( config , 'showResolvedColor' , true ) ;
43
41
44
42
const draw1Panel = gui . addFolder ( 'Draw 1' ) ;
@@ -83,25 +81,36 @@ const bufInstanceColors = device.createBuffer({
83
81
size : 8 ,
84
82
} ) ;
85
83
86
- let multisampleTexture , multisampleTextureView ;
84
+ let multisampleTexture : GPUTexture , multisampleTextureView : GPUTextureView ;
85
+ let resolveTexture : GPUTexture , resolveTextureView : GPUTextureView ;
86
+ let lastSize = 0 ;
87
87
function resetMultisampleTexture ( ) {
88
- if (
89
- ! multisampleTexture ||
90
- multisampleTexture . width !== config . width ||
91
- multisampleTexture . height !== config . height
92
- ) {
88
+ const size = 2 ** config . sizeLog2 ;
89
+ if ( lastSize !== size ) {
93
90
if ( multisampleTexture ) {
94
91
multisampleTexture . destroy ( ) ;
95
92
}
96
- console . log ( 'recreate' ) ;
97
93
multisampleTexture = device . createTexture ( {
98
94
format : 'rgba8unorm' ,
99
95
usage :
100
96
GPUTextureUsage . RENDER_ATTACHMENT | GPUTextureUsage . TEXTURE_BINDING ,
101
- size : [ config . width , config . height ] ,
97
+ size : [ size , size ] ,
102
98
sampleCount : 4 ,
103
99
} ) ;
104
100
multisampleTextureView = multisampleTexture . createView ( ) ;
101
+
102
+ if ( resolveTexture ) {
103
+ resolveTexture . destroy ( ) ;
104
+ }
105
+ resolveTexture = device . createTexture ( {
106
+ format : 'rgba8unorm' ,
107
+ usage :
108
+ GPUTextureUsage . RENDER_ATTACHMENT | GPUTextureUsage . TEXTURE_BINDING ,
109
+ size : [ size , size ] ,
110
+ } ) ;
111
+ resolveTextureView = resolveTexture . createView ( ) ;
112
+
113
+ lastSize = size ;
105
114
}
106
115
}
107
116
@@ -175,13 +184,6 @@ const showMultisampleTextureBGL =
175
184
function render ( ) {
176
185
applyConfig ( ) ;
177
186
178
- const resolveTexture = device . createTexture ( {
179
- format : 'rgba8unorm' ,
180
- usage : GPUTextureUsage . RENDER_ATTACHMENT | GPUTextureUsage . TEXTURE_BINDING ,
181
- size : [ config . width , config . height ] ,
182
- } ) ;
183
- const resolveTextureView = resolveTexture . createView ( ) ;
184
-
185
187
const showMultisampleTextureBG = device . createBindGroup ( {
186
188
layout : showMultisampleTextureBGL ,
187
189
entries : [
0 commit comments