Skip to content

Commit

Permalink
Add cull mode to command (flutter#13)
Browse files Browse the repository at this point in the history
  • Loading branch information
bdero authored and dnfield committed Apr 27, 2022
1 parent dde655f commit 4220ef3
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 2 deletions.
12 changes: 12 additions & 0 deletions impeller/renderer/backend/metal/formats_mtl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion impeller/renderer/backend/metal/render_pass_mtl.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
1 change: 1 addition & 0 deletions impeller/renderer/command.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 7 additions & 1 deletion impeller/renderer/formats.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down Expand Up @@ -135,6 +135,12 @@ enum class WindingOrder {
kCounterClockwise,
};

enum class CullMode {
kNone,
kFrontFace,
kBackFace,
};

enum class IndexType {
kUnknown,
k16bit,
Expand Down

0 comments on commit 4220ef3

Please sign in to comment.