Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit bafdefb

Browse files
committed
[Impeller] Press to toggle wireframe
1 parent f249919 commit bafdefb

File tree

6 files changed

+33
-4
lines changed

6 files changed

+33
-4
lines changed

impeller/aiks/aiks_context.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ std::shared_ptr<Context> AiksContext::GetContext() const {
3232
return context_;
3333
}
3434

35-
const ContentContext& AiksContext::GetContentContext() const {
35+
ContentContext& AiksContext::GetContentContext() const {
3636
return *content_context_;
3737
}
3838

impeller/aiks/aiks_context.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class AiksContext {
2626

2727
std::shared_ptr<Context> GetContext() const;
2828

29-
const ContentContext& GetContentContext() const;
29+
ContentContext& GetContentContext() const;
3030

3131
bool Render(const Picture& picture, RenderTarget& render_target);
3232

impeller/aiks/aiks_playground.cc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
#include "impeller/aiks/aiks_context.h"
88

9+
#include "third_party/imgui/imgui.h"
10+
911
namespace impeller {
1012

1113
AiksPlayground::AiksPlayground() = default;
@@ -32,6 +34,11 @@ bool AiksPlayground::OpenPlaygroundHere(AiksPlaygroundCallback callback) {
3234

3335
return Playground::OpenPlaygroundHere(
3436
[&renderer, &callback](RenderTarget& render_target) -> bool {
37+
static bool wireframe = false;
38+
if (ImGui::IsKeyPressed(ImGuiKey_Z)) {
39+
wireframe = !wireframe;
40+
renderer.GetContentContext().SetWireframe(wireframe);
41+
}
3542
return callback(renderer, render_target);
3643
});
3744
}

impeller/entity/contents/content_context.cc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,8 @@ void ContentContextOptions::ApplyToPipelineDescriptor(
141141
}
142142

143143
desc.SetPrimitiveType(primitive_type);
144+
145+
desc.SetPolygonMode(wireframe ? PolygonMode::kLine : PolygonMode::kFill);
144146
}
145147

146148
template <typename PipelineT>
@@ -377,4 +379,8 @@ const IDeviceCapabilities& ContentContext::GetDeviceCapabilities() const {
377379
return context_->GetDeviceCapabilities();
378380
}
379381

382+
void ContentContext::SetWireframe(bool wireframe) {
383+
wireframe_ = wireframe;
384+
}
385+
380386
} // namespace impeller

impeller/entity/contents/content_context.h

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -269,13 +269,14 @@ struct ContentContextOptions {
269269
PrimitiveType primitive_type = PrimitiveType::kTriangle;
270270
std::optional<PixelFormat> color_attachment_pixel_format;
271271
bool has_stencil_attachment = true;
272+
bool wireframe = false;
272273

273274
struct Hash {
274275
constexpr std::size_t operator()(const ContentContextOptions& o) const {
275276
return fml::HashCombine(o.sample_count, o.blend_mode, o.stencil_compare,
276277
o.stencil_operation, o.primitive_type,
277278
o.color_attachment_pixel_format,
278-
o.has_stencil_attachment);
279+
o.has_stencil_attachment, o.wireframe);
279280
}
280281
};
281282

@@ -289,7 +290,8 @@ struct ContentContextOptions {
289290
lhs.primitive_type == rhs.primitive_type &&
290291
lhs.color_attachment_pixel_format ==
291292
rhs.color_attachment_pixel_format &&
292-
lhs.has_stencil_attachment == rhs.has_stencil_attachment;
293+
lhs.has_stencil_attachment == rhs.has_stencil_attachment &&
294+
lhs.wireframe == rhs.wireframe;
293295
}
294296
};
295297

@@ -598,6 +600,8 @@ class ContentContext {
598600

599601
const IDeviceCapabilities& GetDeviceCapabilities() const;
600602

603+
void SetWireframe(bool wireframe);
604+
601605
using SubpassCallback =
602606
std::function<bool(const ContentContext&, RenderPass&)>;
603607

@@ -705,6 +709,10 @@ class ContentContext {
705709
return nullptr;
706710
}
707711

712+
if (wireframe_) {
713+
opts.wireframe = true;
714+
}
715+
708716
if (auto found = container.find(opts); found != container.end()) {
709717
return found->second->WaitAndGet();
710718
}
@@ -730,6 +738,7 @@ class ContentContext {
730738
std::shared_ptr<Tessellator> tessellator_;
731739
std::shared_ptr<GlyphAtlasContext> glyph_atlas_context_;
732740
std::shared_ptr<scene::SceneContext> scene_context_;
741+
bool wireframe_ = false;
733742

734743
FML_DISALLOW_COPY_AND_ASSIGN(ContentContext);
735744
};

impeller/entity/entity_playground.cc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
#include "impeller/entity/contents/content_context.h"
88

9+
#include "third_party/imgui/imgui.h"
10+
911
namespace impeller {
1012

1113
EntityPlayground::EntityPlayground() = default;
@@ -37,6 +39,11 @@ bool EntityPlayground::OpenPlaygroundHere(EntityPlaygroundCallback callback) {
3739
return false;
3840
}
3941
SinglePassCallback pass_callback = [&](RenderPass& pass) -> bool {
42+
static bool wireframe = false;
43+
if (ImGui::IsKeyPressed(ImGuiKey_Z)) {
44+
wireframe = !wireframe;
45+
content_context.SetWireframe(wireframe);
46+
}
4047
return callback(content_context, pass);
4148
};
4249
return Playground::OpenPlaygroundHere(pass_callback);

0 commit comments

Comments
 (0)