@@ -14,8 +14,7 @@ quitIfWebGPUNotAvailable(adapter, device);
1414//
1515
1616const kInitConfig = {
17- width : 8 ,
18- height : 8 ,
17+ sizeLog2 : 3 ,
1918 showResolvedColor : true ,
2019 color1 : 0x0000ff ,
2120 alpha1 : 127 ,
@@ -37,8 +36,7 @@ gui.width = 300;
3736
3837 const settings = gui . addFolder ( 'Settings' ) ;
3938 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**' ) ;
4240 settings . add ( config , 'showResolvedColor' , true ) ;
4341
4442 const draw1Panel = gui . addFolder ( 'Draw 1' ) ;
@@ -83,25 +81,36 @@ const bufInstanceColors = device.createBuffer({
8381 size : 8 ,
8482} ) ;
8583
86- let multisampleTexture , multisampleTextureView ;
84+ let multisampleTexture : GPUTexture , multisampleTextureView : GPUTextureView ;
85+ let resolveTexture : GPUTexture , resolveTextureView : GPUTextureView ;
86+ let lastSize = 0 ;
8787function 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 ) {
9390 if ( multisampleTexture ) {
9491 multisampleTexture . destroy ( ) ;
9592 }
96- console . log ( 'recreate' ) ;
9793 multisampleTexture = device . createTexture ( {
9894 format : 'rgba8unorm' ,
9995 usage :
10096 GPUTextureUsage . RENDER_ATTACHMENT | GPUTextureUsage . TEXTURE_BINDING ,
101- size : [ config . width , config . height ] ,
97+ size : [ size , size ] ,
10298 sampleCount : 4 ,
10399 } ) ;
104100 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 ;
105114 }
106115}
107116
@@ -175,13 +184,6 @@ const showMultisampleTextureBGL =
175184function render ( ) {
176185 applyConfig ( ) ;
177186
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-
185187 const showMultisampleTextureBG = device . createBindGroup ( {
186188 layout : showMultisampleTextureBGL ,
187189 entries : [
0 commit comments