@@ -253,8 +253,8 @@ RenderTarget RenderTarget::CreateOffscreen(
253
253
target.SetColorAttachment (color0, 0u );
254
254
255
255
if (stencil_attachment_config.has_value ()) {
256
- target.SetupStencilAttachment (context, allocator, size, false , label,
257
- stencil_attachment_config.value ());
256
+ target.SetupDepthStencilAttachments (context, allocator, size, false , label,
257
+ stencil_attachment_config.value ());
258
258
} else {
259
259
target.SetStencilAttachment (std::nullopt );
260
260
}
@@ -343,43 +343,56 @@ RenderTarget RenderTarget::CreateOffscreenMSAA(
343
343
// Create MSAA stencil texture.
344
344
345
345
if (stencil_attachment_config.has_value ()) {
346
- target.SetupStencilAttachment (context, allocator, size, true , label,
347
- stencil_attachment_config.value ());
346
+ target.SetupDepthStencilAttachments (context, allocator, size, true , label,
347
+ stencil_attachment_config.value ());
348
348
} else {
349
349
target.SetStencilAttachment (std::nullopt );
350
350
}
351
351
352
352
return target;
353
353
}
354
354
355
- void RenderTarget::SetupStencilAttachment (
355
+ void RenderTarget::SetupDepthStencilAttachments (
356
356
const Context& context,
357
357
RenderTargetAllocator& allocator,
358
358
ISize size,
359
359
bool msaa,
360
360
const std::string& label,
361
361
AttachmentConfig stencil_attachment_config) {
362
- TextureDescriptor stencil_tex0;
363
- stencil_tex0.storage_mode = stencil_attachment_config.storage_mode ;
362
+ TextureDescriptor depth_stencil_texture_desc;
363
+ depth_stencil_texture_desc.storage_mode =
364
+ stencil_attachment_config.storage_mode ;
364
365
if (msaa) {
365
- stencil_tex0 .type = TextureType::kTexture2DMultisample ;
366
- stencil_tex0 .sample_count = SampleCount::kCount4 ;
366
+ depth_stencil_texture_desc .type = TextureType::kTexture2DMultisample ;
367
+ depth_stencil_texture_desc .sample_count = SampleCount::kCount4 ;
367
368
}
368
- stencil_tex0.format = context.GetCapabilities ()->GetDefaultStencilFormat ();
369
- stencil_tex0.size = size;
370
- stencil_tex0.usage =
369
+ depth_stencil_texture_desc.format =
370
+ context.GetCapabilities ()->GetDefaultDepthStencilFormat ();
371
+ depth_stencil_texture_desc.size = size;
372
+ depth_stencil_texture_desc.usage =
371
373
static_cast <TextureUsageMask>(TextureUsage::kRenderTarget );
372
374
375
+ auto depth_stencil_texture =
376
+ allocator.CreateTexture (depth_stencil_texture_desc);
377
+ if (!depth_stencil_texture) {
378
+ return ; // Error messages are handled by `Allocator::CreateTexture`.
379
+ }
380
+
381
+ DepthAttachment depth0;
382
+ depth0.load_action = stencil_attachment_config.load_action ;
383
+ depth0.store_action = stencil_attachment_config.store_action ;
384
+ depth0.clear_depth = 0u ;
385
+ depth0.texture = depth_stencil_texture;
386
+
373
387
StencilAttachment stencil0;
374
388
stencil0.load_action = stencil_attachment_config.load_action ;
375
389
stencil0.store_action = stencil_attachment_config.store_action ;
376
390
stencil0.clear_stencil = 0u ;
377
- stencil0.texture = allocator. CreateTexture (stencil_tex0) ;
391
+ stencil0.texture = depth_stencil_texture ;
378
392
379
- if (!stencil0.texture ) {
380
- return ; // Error messages are handled by `Allocator::CreateTexture`.
381
- }
382
- stencil0.texture ->SetLabel (SPrintF (" %s Stencil Texture" , label.c_str ()));
393
+ stencil0.texture ->SetLabel (
394
+ SPrintF (" %s Depth+Stencil Texture" , label.c_str ()));
395
+ SetDepthAttachment (std::move (depth0));
383
396
SetStencilAttachment (std::move (stencil0));
384
397
}
385
398
@@ -399,6 +412,9 @@ size_t RenderTarget::GetTotalAttachmentCount() const {
399
412
if (stencil_.has_value ()) {
400
413
count++;
401
414
}
415
+ if (depth_.has_value ()) {
416
+ count++;
417
+ }
402
418
return count;
403
419
}
404
420
0 commit comments