diff --git a/impeller/aiks/aiks_context.cc b/impeller/aiks/aiks_context.cc index fd504cbe03ca3..e724ac597af9a 100644 --- a/impeller/aiks/aiks_context.cc +++ b/impeller/aiks/aiks_context.cc @@ -32,7 +32,7 @@ std::shared_ptr AiksContext::GetContext() const { return context_; } -const ContentContext& AiksContext::GetContentContext() const { +ContentContext& AiksContext::GetContentContext() const { return *content_context_; } diff --git a/impeller/aiks/aiks_context.h b/impeller/aiks/aiks_context.h index d748f3156fcba..fe62ebca47b45 100644 --- a/impeller/aiks/aiks_context.h +++ b/impeller/aiks/aiks_context.h @@ -26,7 +26,7 @@ class AiksContext { std::shared_ptr GetContext() const; - const ContentContext& GetContentContext() const; + ContentContext& GetContentContext() const; bool Render(const Picture& picture, RenderTarget& render_target); diff --git a/impeller/aiks/aiks_playground.cc b/impeller/aiks/aiks_playground.cc index dab73f5839615..04d8cdb0627da 100644 --- a/impeller/aiks/aiks_playground.cc +++ b/impeller/aiks/aiks_playground.cc @@ -6,6 +6,8 @@ #include "impeller/aiks/aiks_context.h" +#include "third_party/imgui/imgui.h" + namespace impeller { AiksPlayground::AiksPlayground() = default; @@ -32,6 +34,11 @@ bool AiksPlayground::OpenPlaygroundHere(AiksPlaygroundCallback callback) { return Playground::OpenPlaygroundHere( [&renderer, &callback](RenderTarget& render_target) -> bool { + static bool wireframe = false; + if (ImGui::IsKeyPressed(ImGuiKey_Z)) { + wireframe = !wireframe; + renderer.GetContentContext().SetWireframe(wireframe); + } return callback(renderer, render_target); }); } diff --git a/impeller/entity/contents/content_context.cc b/impeller/entity/contents/content_context.cc index 8ba65593034d5..e15058d5fb330 100644 --- a/impeller/entity/contents/content_context.cc +++ b/impeller/entity/contents/content_context.cc @@ -142,6 +142,8 @@ void ContentContextOptions::ApplyToPipelineDescriptor( } desc.SetPrimitiveType(primitive_type); + + desc.SetPolygonMode(wireframe ? PolygonMode::kLine : PolygonMode::kFill); } template @@ -379,4 +381,8 @@ const IDeviceCapabilities& ContentContext::GetDeviceCapabilities() const { return context_->GetDeviceCapabilities(); } +void ContentContext::SetWireframe(bool wireframe) { + wireframe_ = wireframe; +} + } // namespace impeller diff --git a/impeller/entity/contents/content_context.h b/impeller/entity/contents/content_context.h index d32cc41f9df86..fdad286a4016c 100644 --- a/impeller/entity/contents/content_context.h +++ b/impeller/entity/contents/content_context.h @@ -269,13 +269,14 @@ struct ContentContextOptions { PrimitiveType primitive_type = PrimitiveType::kTriangle; std::optional color_attachment_pixel_format; bool has_stencil_attachment = true; + bool wireframe = false; struct Hash { constexpr std::size_t operator()(const ContentContextOptions& o) const { return fml::HashCombine(o.sample_count, o.blend_mode, o.stencil_compare, o.stencil_operation, o.primitive_type, o.color_attachment_pixel_format, - o.has_stencil_attachment); + o.has_stencil_attachment, o.wireframe); } }; @@ -289,7 +290,8 @@ struct ContentContextOptions { lhs.primitive_type == rhs.primitive_type && lhs.color_attachment_pixel_format == rhs.color_attachment_pixel_format && - lhs.has_stencil_attachment == rhs.has_stencil_attachment; + lhs.has_stencil_attachment == rhs.has_stencil_attachment && + lhs.wireframe == rhs.wireframe; } }; @@ -598,6 +600,8 @@ class ContentContext { const IDeviceCapabilities& GetDeviceCapabilities() const; + void SetWireframe(bool wireframe); + using SubpassCallback = std::function; @@ -706,6 +710,10 @@ class ContentContext { return nullptr; } + if (wireframe_) { + opts.wireframe = true; + } + if (auto found = container.find(opts); found != container.end()) { return found->second->WaitAndGet(); } @@ -731,6 +739,7 @@ class ContentContext { std::shared_ptr tessellator_; std::shared_ptr glyph_atlas_context_; std::shared_ptr scene_context_; + bool wireframe_ = false; FML_DISALLOW_COPY_AND_ASSIGN(ContentContext); }; diff --git a/impeller/entity/entity_playground.cc b/impeller/entity/entity_playground.cc index 297009d90845b..9fb8e92c09e51 100644 --- a/impeller/entity/entity_playground.cc +++ b/impeller/entity/entity_playground.cc @@ -6,6 +6,8 @@ #include "impeller/entity/contents/content_context.h" +#include "third_party/imgui/imgui.h" + namespace impeller { EntityPlayground::EntityPlayground() = default; @@ -37,6 +39,11 @@ bool EntityPlayground::OpenPlaygroundHere(EntityPlaygroundCallback callback) { return false; } SinglePassCallback pass_callback = [&](RenderPass& pass) -> bool { + static bool wireframe = false; + if (ImGui::IsKeyPressed(ImGuiKey_Z)) { + wireframe = !wireframe; + content_context.SetWireframe(wireframe); + } return callback(content_context, pass); }; return Playground::OpenPlaygroundHere(pass_callback);