From 4220ef3727b9d2a14c0776c49726177bc55f49b3 Mon Sep 17 00:00:00 2001 From: Brandon DeRosier Date: Thu, 17 Feb 2022 10:46:55 -0800 Subject: [PATCH] Add cull mode to command (#13) --- impeller/renderer/backend/metal/formats_mtl.h | 12 ++++++++++++ impeller/renderer/backend/metal/render_pass_mtl.mm | 2 +- impeller/renderer/command.h | 1 + impeller/renderer/formats.h | 8 +++++++- 4 files changed, 21 insertions(+), 2 deletions(-) diff --git a/impeller/renderer/backend/metal/formats_mtl.h b/impeller/renderer/backend/metal/formats_mtl.h index 6d1b47e69dae1..9cdb319f1bfca 100644 --- a/impeller/renderer/backend/metal/formats_mtl.h +++ b/impeller/renderer/backend/metal/formats_mtl.h @@ -116,6 +116,18 @@ constexpr MTLIndexType ToMTLIndexType(IndexType type) { } } +constexpr MTLCullMode ToMTLCullMode(CullMode mode) { + switch (mode) { + case CullMode::kNone: + return MTLCullModeNone; + case CullMode::kBackFace: + return MTLCullModeBack; + case CullMode::kFrontFace: + return MTLCullModeFront; + } + return MTLCullModeNone; +} + constexpr MTLBlendOperation ToMTLBlendOperation(BlendOperation type) { switch (type) { case BlendOperation::kAdd: diff --git a/impeller/renderer/backend/metal/render_pass_mtl.mm b/impeller/renderer/backend/metal/render_pass_mtl.mm index 9279d16f2671d..9d7a9e24ffe50 100644 --- a/impeller/renderer/backend/metal/render_pass_mtl.mm +++ b/impeller/renderer/backend/metal/render_pass_mtl.mm @@ -426,7 +426,7 @@ static bool Bind(PassBindingsCache& pass, [encoder setFrontFacingWinding:command.winding == WindingOrder::kClockwise ? MTLWindingClockwise : MTLWindingCounterClockwise]; - [encoder setCullMode:MTLCullModeNone]; + [encoder setCullMode:ToMTLCullMode(command.cull_mode)]; [encoder setStencilReferenceValue:command.stencil_reference]; if (command.viewport.has_value()) { auto v = command.viewport.value(); diff --git a/impeller/renderer/command.h b/impeller/renderer/command.h index 30c2d4cfe662c..fb73d1b16da63 100644 --- a/impeller/renderer/command.h +++ b/impeller/renderer/command.h @@ -70,6 +70,7 @@ struct Command { std::string label; PrimitiveType primitive_type = PrimitiveType::kTriangle; WindingOrder winding = WindingOrder::kClockwise; + CullMode cull_mode = CullMode::kNone; uint32_t stencil_reference = 0u; //---------------------------------------------------------------------------- /// The viewport coordinates that the rasterizer linearly maps normalized diff --git a/impeller/renderer/formats.h b/impeller/renderer/formats.h index 94e7d94012287..092d86283fc53 100644 --- a/impeller/renderer/formats.h +++ b/impeller/renderer/formats.h @@ -11,9 +11,9 @@ #include "flutter/fml/hash_combine.h" #include "flutter/fml/macros.h" +#include "impeller/geometry/color.h" #include "impeller/geometry/rect.h" #include "impeller/geometry/scalar.h" -#include "impeller/geometry/color.h" namespace impeller { @@ -135,6 +135,12 @@ enum class WindingOrder { kCounterClockwise, }; +enum class CullMode { + kNone, + kFrontFace, + kBackFace, +}; + enum class IndexType { kUnknown, k16bit,