Skip to content

Commit 9c88b09

Browse files
chinmaygardednfield
authored andcommitted
Give the default render target a stencil buffer.
1 parent 0570581 commit 9c88b09

File tree

3 files changed

+30
-0
lines changed

3 files changed

+30
-0
lines changed

impeller/playground/playground.mm

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,26 @@ static void PlaygroundKeyCallback(GLFWwindow* window,
157157
color0.load_action = LoadAction::kClear;
158158
color0.store_action = StoreAction::kStore;
159159

160+
TextureDescriptor stencil_texture_descriptor;
161+
stencil_texture_descriptor.format = PixelFormat::kD32FloatS8UNormInt;
162+
stencil_texture_descriptor.size = color0_desc.size;
163+
stencil_texture_descriptor.usage =
164+
static_cast<TextureUsageMask>(TextureUsage::kShaderRead) |
165+
static_cast<TextureUsageMask>(TextureUsage::kShaderWrite);
166+
auto stencil_texture =
167+
renderer_.GetContext()->GetPermanentsAllocator()->CreateTexture(
168+
StorageMode::kDeviceTransient, stencil_texture_descriptor);
169+
stencil_texture->SetLabel("PlaygroundMainStencil");
170+
171+
StencilAttachment stencil0;
172+
stencil0.texture = stencil_texture;
173+
stencil0.clear_stencil = 0;
174+
stencil0.load_action = LoadAction::kClear;
175+
stencil0.store_action = StoreAction::kStore;
176+
160177
RenderTarget desc;
161178
desc.SetColorAttachment(color0, 0u);
179+
desc.SetStencilAttachment(stencil0);
162180

163181
Surface surface(desc);
164182

impeller/renderer/pipeline.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@ class PipelineT {
6868
context,
6969
Builder::MakeDefaultPipelineDescriptor(context))) {}
7070

71+
explicit PipelineT(const Context& context,
72+
std::optional<PipelineDescriptor> desc)
73+
: pipeline_future_(CreatePipelineFuture(context, desc)) {}
74+
7175
std::shared_ptr<Pipeline> WaitAndGet() {
7276
if (did_wait_) {
7377
return pipeline_;

impeller/renderer/pipeline_builder.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,14 @@ struct PipelineBuilder {
104104
desc.SetColorAttachmentDescriptor(0u, std::move(color0));
105105
}
106106

107+
// Setup default stencil buffer descriptions.
108+
{
109+
StencilAttachmentDescriptor stencil0;
110+
stencil0.depth_stencil_pass = StencilOperation::kIncrementClamp;
111+
desc.SetStencilAttachmentDescriptors(stencil0);
112+
desc.SetStencilPixelFormat(PixelFormat::kD32FloatS8UNormInt);
113+
}
114+
107115
return true;
108116
}
109117
};

0 commit comments

Comments
 (0)