@@ -136,6 +136,11 @@ ClipRestoreContents::ClipRestoreContents() = default;
136136
137137ClipRestoreContents::~ClipRestoreContents () = default ;
138138
139+ void ClipRestoreContents::SetRestoreCoverage (
140+ std::optional<Rect> restore_coverage) {
141+ restore_coverage_ = restore_coverage;
142+ }
143+
139144std::optional<Rect> ClipRestoreContents::GetCoverage (
140145 const Entity& entity) const {
141146 return std::nullopt ;
@@ -164,19 +169,20 @@ bool ClipRestoreContents::Render(const ContentContext& renderer,
164169 auto options = OptionsFromPassAndEntity (pass, entity);
165170 options.stencil_compare = CompareFunction::kLess ;
166171 options.stencil_operation = StencilOperation::kSetToReferenceValue ;
172+ options.primitive_type = PrimitiveType::kTriangleStrip ;
167173 cmd.pipeline = renderer.GetClipPipeline (options);
168174 cmd.stencil_reference = entity.GetStencilDepth ();
169175
170- // Create a rect that covers the whole render target.
171- auto size = pass.GetRenderTargetSize ();
176+ // Create a rect that covers either the given restore area, or the whole
177+ // render target texture.
178+ auto ltrb = restore_coverage_.value_or (Rect (Size (pass.GetRenderTargetSize ())))
179+ .GetLTRB ();
172180 VertexBufferBuilder<VS::PerVertexData> vtx_builder;
173181 vtx_builder.AddVertices ({
174- {Point (0.0 , 0.0 )},
175- {Point (size.width , 0.0 )},
176- {Point (size.width , size.height )},
177- {Point (0.0 , 0.0 )},
178- {Point (size.width , size.height )},
179- {Point (0.0 , size.height )},
182+ {Point (ltrb[0 ], ltrb[1 ])},
183+ {Point (ltrb[2 ], ltrb[1 ])},
184+ {Point (ltrb[0 ], ltrb[3 ])},
185+ {Point (ltrb[2 ], ltrb[3 ])},
180186 });
181187 cmd.BindVertices (vtx_builder.CreateVertexBuffer (pass.GetTransientsBuffer ()));
182188
0 commit comments