@@ -122,7 +122,7 @@ function WGPUCore.getContext(gpuCanvas::GLFWWinCanvas)
122122 gpuCanvas. device, # device::Any
123123 WGPUTextureFormat_R8Unorm, # format::WGPUTextureFormat
124124 WGPUCore. getEnum (WGPUTextureUsage, [" RenderAttachment" , " CopySrc" ]), # usage::WGPUTextureUsage
125- WGPUCompositeAlphaMode_PreMultiplied , # compositingAlphaMode::Any
125+ WGPUCompositeAlphaMode_Premultiplied , # compositingAlphaMode::Any
126126 nothing , # size::Any
127127 gpuCanvas. size, # physicalSize::Any
128128 nothing , # pixelRatio::Any
@@ -190,25 +190,30 @@ function WGPUCore.getCurrentTexture(cntxt::GPUCanvasContext)
190190 # if cntxt.device.internal[] == C_NULL
191191 # @error "context must be configured before request for texture"
192192 # end
193+ canvas = cntxt. canvasRef[]
194+ surface = canvas. surfaceRef[]
195+ surfaceTexture = cStruct (WGPUSurfaceTexture;)
193196 if cntxt. currentTexture == nothing
194- createNativeSwapChainMaybe (cntxt)
195- id = wgpuSwapChainGetCurrentTextureView (cntxt . internal[]) |> Ref
197+ configureSurface (cntxt)
198+ wgpuSurfaceGetCurrentTexture (surface, surfaceTexture |> ptr)
196199 size = (cntxt. surfaceSize... , 1 )
200+ currentTexture = wgpuTextureCreateView (surfaceTexture. texture, C_NULL ) |> Ref
197201 cntxt. currentTexture =
198- WGPUCore. GPUTextureView (" swap chain" , id , cntxt. device, nothing , size, nothing |> Ref)
202+ WGPUCore. GPUTextureView (" swap chain" , currentTexture , cntxt. device, nothing , size, nothing |> Ref)
199203 end
200204 return cntxt. currentTexture
201205end
202206
203207function WGPUCore. present (cntxt:: GPUCanvasContext )
208+ canvas = cntxt. canvasRef[]
204209 if cntxt. internal[] != C_NULL && cntxt. currentTexture. internal[] != C_NULL
205- wgpuSwapChainPresent (cntxt . internal [])
210+ wgpuSurfacePresent (canvas . surfaceRef [])
206211 end
207212 WGPUCore. destroy (cntxt. currentTexture)
208213 cntxt. currentTexture = nothing
209214end
210215
211- function createNativeSwapChainMaybe (canvasCntxt:: GPUCanvasContext )
216+ function configureSurface (canvasCntxt:: GPUCanvasContext )
212217 canvas = canvasCntxt. canvasRef[]
213218 pSize = canvasCntxt. physicalSize
214219 if pSize == canvasCntxt. surfaceSize
@@ -217,31 +222,35 @@ function createNativeSwapChainMaybe(canvasCntxt::GPUCanvasContext)
217222 canvasCntxt. surfaceSize = pSize
218223 canvasCntxt. usage = WGPUCore. getEnum (WGPUTextureUsage, [" RenderAttachment" , " CopySrc" ])
219224 presentMode = WGPUPresentMode_Fifo # TODO hardcoded (for other options ref https://docs.rs/wgpu/latest/wgpu/enum.PresentMode.html)
220- swapChainExtras = cStruct (
221- WGPUSwapChainDescriptorExtras;
222- alphaMode= WGPUCompositeAlphaMode_PreMultiplied,
223- viewFormatCount= 1 ,
224- viewFormats = [canvasCntxt. format] |> pointer
225- )
226- swapChain =
225+ surfaceCapabilities = cStruct (WGPUSurfaceCapabilities;)
226+
227+ wgpuSurfaceGetCapabilities (
228+ canvas. surfaceRef[],
229+ canvas. device. internal[],
230+ surfaceCapabilities |> ptr
231+ )
232+
233+ surfaceConfiguration =
227234 cStruct (
228235 WGPUSwapChainDescriptor;
236+ device = canvasCntxt. device. internal[],
229237 usage = canvasCntxt. usage,
230238 format = canvasCntxt. format,
239+ viewFormatCount = 1 ,
240+ viewFormats = [canvasCntxt. format] |> pointer,
241+ alphaMode = WGPUCompositeAlphaMode_Opaque,
231242 width = max (1 , pSize[1 ]),
232243 height = max (1 , pSize[2 ]),
233244 presentMode = presentMode,
234- nextInChain = swapChainExtras |> ptr
245+ nextInChain = C_NULL ,
235246 )
236247 if canvasCntxt. surfaceId == nothing
237248 canvasCntxt. surfaceId = getSurfaceIdFromCanvas (canvas)
238249 end
239- canvasCntxt. internal =
240- wgpuDeviceCreateSwapChain (
241- canvasCntxt. device. internal[],
242- canvasCntxt. surfaceId,
243- swapChain |> ptr,
244- ) |> Ref
250+ wgpuSurfaceConfigure (
251+ canvas. surfaceRef[],,
252+ surfaceConfiguration |> ptr,
253+ )
245254end
246255
247256function WGPUCore. destroyWindow (canvas:: GLFWWinCanvas )
0 commit comments