Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Impeller] Press z to toggle wireframe #40001

Merged
merged 1 commit into from
Mar 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion impeller/aiks/aiks_context.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ std::shared_ptr<Context> AiksContext::GetContext() const {
return context_;
}

const ContentContext& AiksContext::GetContentContext() const {
ContentContext& AiksContext::GetContentContext() const {
return *content_context_;
}

Expand Down
2 changes: 1 addition & 1 deletion impeller/aiks/aiks_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class AiksContext {

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

const ContentContext& GetContentContext() const;
ContentContext& GetContentContext() const;

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

Expand Down
7 changes: 7 additions & 0 deletions impeller/aiks/aiks_playground.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

#include "impeller/aiks/aiks_context.h"

#include "third_party/imgui/imgui.h"

namespace impeller {

AiksPlayground::AiksPlayground() = default;
Expand All @@ -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);
});
}
Expand Down
6 changes: 6 additions & 0 deletions impeller/entity/contents/content_context.cc
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ void ContentContextOptions::ApplyToPipelineDescriptor(
}

desc.SetPrimitiveType(primitive_type);

desc.SetPolygonMode(wireframe ? PolygonMode::kLine : PolygonMode::kFill);
}

template <typename PipelineT>
Expand Down Expand Up @@ -379,4 +381,8 @@ const IDeviceCapabilities& ContentContext::GetDeviceCapabilities() const {
return context_->GetDeviceCapabilities();
}

void ContentContext::SetWireframe(bool wireframe) {
wireframe_ = wireframe;
}

} // namespace impeller
13 changes: 11 additions & 2 deletions impeller/entity/contents/content_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -269,13 +269,14 @@ struct ContentContextOptions {
PrimitiveType primitive_type = PrimitiveType::kTriangle;
std::optional<PixelFormat> 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);
}
};

Expand All @@ -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;
}
};

Expand Down Expand Up @@ -598,6 +600,8 @@ class ContentContext {

const IDeviceCapabilities& GetDeviceCapabilities() const;

void SetWireframe(bool wireframe);

using SubpassCallback =
std::function<bool(const ContentContext&, RenderPass&)>;

Expand Down Expand Up @@ -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();
}
Expand All @@ -731,6 +739,7 @@ class ContentContext {
std::shared_ptr<Tessellator> tessellator_;
std::shared_ptr<GlyphAtlasContext> glyph_atlas_context_;
std::shared_ptr<scene::SceneContext> scene_context_;
bool wireframe_ = false;

FML_DISALLOW_COPY_AND_ASSIGN(ContentContext);
};
Expand Down
7 changes: 7 additions & 0 deletions impeller/entity/entity_playground.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

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

#include "third_party/imgui/imgui.h"

namespace impeller {

EntityPlayground::EntityPlayground() = default;
Expand Down Expand Up @@ -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);
Expand Down