@@ -187,7 +187,7 @@ void initConfig(wgpu::SurfaceConfiguration& config, wgpu::Device const& device,
187
187
wgpu::SurfaceCapabilities const & capabilities, wgpu::Extent2D const & extent,
188
188
bool useSRGBColorSpace) {
189
189
config.device = device;
190
- config.usage = wgpu::TextureUsage::RenderAttachment;
190
+ config.usage = wgpu::TextureUsage::RenderAttachment | wgpu::TextureUsage::CopySrc ;
191
191
config.width = extent.width ;
192
192
config.height = extent.height ;
193
193
config.format = selectColorFormat (capabilities.formatCount , capabilities.formats , useSRGBColorSpace);
@@ -352,47 +352,45 @@ void WebGPUSwapChain::setExtent(wgpu::Extent2D const& currentSurfaceSize) {
352
352
}
353
353
}
354
354
355
- wgpu::TextureView WebGPUSwapChain::getCurrentTextureView ( wgpu::Extent2D const & extent) {
355
+ wgpu::TextureView WebGPUSwapChain::getNextTextureView () {
356
+ assert_invariant (isHeadless ());
357
+
358
+ mHeadlessBufferIndex = (mHeadlessBufferIndex + 1 ) % mHeadlessBufferCount ;
359
+ return mRenderTargetViews [mHeadlessBufferIndex ];
360
+ }
361
+
362
+ wgpu::TextureView WebGPUSwapChain::getNextTextureView ( wgpu::Extent2D const & extent) {
356
363
setExtent (extent);
357
- wgpu::SurfaceTexture surfaceTexture;
358
- mSurface .GetCurrentTexture (&surfaceTexture );
359
- if (surfaceTexture .status != wgpu::SurfaceGetCurrentTextureStatus::SuccessOptimal) {
364
+
365
+ mSurface .GetCurrentTexture (&mCurrentTexture );
366
+ if (mCurrentTexture .status != wgpu::SurfaceGetCurrentTextureStatus::SuccessOptimal) {
360
367
return nullptr ;
361
368
}
362
369
363
370
// TODO: review these initializations as webgpu pipeline gets mature
364
371
wgpu::TextureViewDescriptor textureViewDescriptor = {
365
372
.label = " surface_texture_view" ,
366
- .format = surfaceTexture .texture .GetFormat (),
373
+ .format = mCurrentTexture .texture .GetFormat (),
367
374
.dimension = wgpu::TextureViewDimension::e2D,
368
375
.baseMipLevel = 0 ,
369
376
.mipLevelCount = 1 ,
370
377
.baseArrayLayer = 0 ,
371
378
.arrayLayerCount = 1
372
379
};
373
- return surfaceTexture .texture .CreateView (&textureViewDescriptor);
380
+ return mCurrentTexture .texture .CreateView (&textureViewDescriptor);
374
381
}
375
382
376
- wgpu::Texture WebGPUSwapChain::getCurrentTexture (wgpu::Extent2D const & extent ) {
383
+ wgpu::Texture WebGPUSwapChain::getCurrentTexture () {
377
384
if (isHeadless ()) {
378
385
return mRenderTargetTextures [mHeadlessBufferIndex ];
379
386
}
380
- // We should return the actual texture that was in use, but we don't keep a direct handle to it.
381
- // The non-headless case for this isn't currently relevant (Since this is only used by headless
382
- // rendering captured by readPixels), but if we need it this can be done in the future
383
- FILAMENT_CHECK_POSTCONDITION (false )
384
- << " getCurrentTexture is not implemented for non-headless mode." ;
385
- return nullptr ;
386
- }
387
+ // We return the texture that was in use
388
+ return mCurrentTexture .texture ;
387
389
388
- wgpu::TextureView WebGPUSwapChain::getCurrentHeadlessTextureView () {
389
- return mRenderTargetViews [mHeadlessBufferIndex ];
390
390
}
391
391
392
392
void WebGPUSwapChain::present () {
393
- if (isHeadless ()) {
394
- mHeadlessBufferIndex = (mHeadlessBufferIndex + 1 ) % mHeadlessBufferCount ;
395
- } else {
393
+ if (!isHeadless ()) {
396
394
mSurface .Present ();
397
395
}
398
396
}
0 commit comments