@@ -428,6 +428,28 @@ static bool Bind(PassBindingsCache& pass,
428
428
: MTLWindingCounterClockwise ];
429
429
[encoder setCullMode: MTLCullModeNone ];
430
430
[encoder setStencilReferenceValue: command.stencil_reference];
431
+ if (command.viewport .has_value ()) {
432
+ auto v = command.viewport .value ();
433
+ MTLViewport viewport = {
434
+ .originX = v.rect .origin .x ,
435
+ .originY = v.rect .origin .y ,
436
+ .width = v.rect .size .width ,
437
+ .height = v.rect .size .height ,
438
+ .znear = v.znear ,
439
+ .zfar = v.zfar ,
440
+ };
441
+ [encoder setViewport: viewport];
442
+ }
443
+ if (command.scissor .has_value ()) {
444
+ auto s = command.scissor .value ();
445
+ MTLScissorRect scissor = {
446
+ .x = static_cast <NSUInteger >(s.origin .x ),
447
+ .y = static_cast <NSUInteger >(s.origin .y ),
448
+ .width = static_cast <NSUInteger >(s.size .width ),
449
+ .height = static_cast <NSUInteger >(s.size .height ),
450
+ };
451
+ [encoder setScissorRect: scissor];
452
+ }
431
453
if (!bind_stage_resources (command.vertex_bindings , ShaderStage::kVertex )) {
432
454
return false ;
433
455
}
@@ -472,6 +494,15 @@ static bool Bind(PassBindingsCache& pass,
472
494
return false ;
473
495
}
474
496
497
+ if (command.scissor .has_value ()) {
498
+ auto target_rect = IRect ({}, render_target_.GetRenderTargetSize ());
499
+ if (!target_rect.Contains (command.scissor .value ())) {
500
+ VALIDATION_LOG << " Cannot apply a scissor that lies outside the bounds "
501
+ " of the render target." ;
502
+ return false ;
503
+ }
504
+ }
505
+
475
506
commands_.emplace_back (std::move (command));
476
507
return true ;
477
508
}
0 commit comments