Skip to content

Commit

Permalink
Give the default render target a stencil buffer.
Browse files Browse the repository at this point in the history
  • Loading branch information
chinmaygarde authored and dnfield committed Apr 27, 2022
1 parent 0570581 commit 9c88b09
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
18 changes: 18 additions & 0 deletions impeller/playground/playground.mm
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,26 @@ static void PlaygroundKeyCallback(GLFWwindow* window,
color0.load_action = LoadAction::kClear;
color0.store_action = StoreAction::kStore;

TextureDescriptor stencil_texture_descriptor;
stencil_texture_descriptor.format = PixelFormat::kD32FloatS8UNormInt;
stencil_texture_descriptor.size = color0_desc.size;
stencil_texture_descriptor.usage =
static_cast<TextureUsageMask>(TextureUsage::kShaderRead) |
static_cast<TextureUsageMask>(TextureUsage::kShaderWrite);
auto stencil_texture =
renderer_.GetContext()->GetPermanentsAllocator()->CreateTexture(
StorageMode::kDeviceTransient, stencil_texture_descriptor);
stencil_texture->SetLabel("PlaygroundMainStencil");

StencilAttachment stencil0;
stencil0.texture = stencil_texture;
stencil0.clear_stencil = 0;
stencil0.load_action = LoadAction::kClear;
stencil0.store_action = StoreAction::kStore;

RenderTarget desc;
desc.SetColorAttachment(color0, 0u);
desc.SetStencilAttachment(stencil0);

Surface surface(desc);

Expand Down
4 changes: 4 additions & 0 deletions impeller/renderer/pipeline.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ class PipelineT {
context,
Builder::MakeDefaultPipelineDescriptor(context))) {}

explicit PipelineT(const Context& context,
std::optional<PipelineDescriptor> desc)
: pipeline_future_(CreatePipelineFuture(context, desc)) {}

std::shared_ptr<Pipeline> WaitAndGet() {
if (did_wait_) {
return pipeline_;
Expand Down
8 changes: 8 additions & 0 deletions impeller/renderer/pipeline_builder.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,14 @@ struct PipelineBuilder {
desc.SetColorAttachmentDescriptor(0u, std::move(color0));
}

// Setup default stencil buffer descriptions.
{
StencilAttachmentDescriptor stencil0;
stencil0.depth_stencil_pass = StencilOperation::kIncrementClamp;
desc.SetStencilAttachmentDescriptors(stencil0);
desc.SetStencilPixelFormat(PixelFormat::kD32FloatS8UNormInt);
}

return true;
}
};
Expand Down

0 comments on commit 9c88b09

Please sign in to comment.