From 73891af56a633cf2b4e047b6422f34c80230eb29 Mon Sep 17 00:00:00 2001 From: Jack Andersen Date: Fri, 10 Mar 2017 11:07:29 -1000 Subject: [PATCH] Add frontface culling support to Metal --- lib/graphicsdev/Metal.mm | 17 ++++++++++++++--- test/main.cpp | 2 +- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/lib/graphicsdev/Metal.mm b/lib/graphicsdev/Metal.mm index 0755d68..3e22828 100644 --- a/lib/graphicsdev/Metal.mm +++ b/lib/graphicsdev/Metal.mm @@ -554,12 +554,23 @@ class MetalShaderPipeline : public IShaderPipeline MetalShareableShader::Token&& frag, const MetalVertexFormat* vtxFmt, NSUInteger targetSamples, BlendFactor srcFac, BlendFactor dstFac, Primitive prim, - bool depthTest, bool depthWrite, bool backfaceCulling) + bool depthTest, bool depthWrite, CullMode culling) : m_drawPrim(PRIMITIVE_TABLE[int(prim)]), m_vtxFmt(vtxFmt), m_vert(std::move(vert)), m_frag(std::move(frag)) { - if (backfaceCulling) + switch (culling) + { + case CullMode::None: + default: + m_cullMode = MTLCullModeNone; + break; + case CullMode::Backface: m_cullMode = MTLCullModeBack; + break; + case CullMode::Frontface: + m_cullMode = MTLCullModeFront; + break; + } MTLRenderPipelineDescriptor* desc = [MTLRenderPipelineDescriptor new]; desc.vertexFunction = m_vert.get().m_shader; @@ -1219,7 +1230,7 @@ IShaderPipeline* MetalDataFactory::Context::newShaderPipeline(const char* vertSo MetalShaderPipeline* retval = new MetalShaderPipeline(factory.m_ctx, std::move(vertShader), std::move(fragShader), static_cast(vtxFmt), targetSamples, - srcFac, dstFac, prim, depthTest, depthWrite, backfaceCulling); + srcFac, dstFac, prim, depthTest, depthWrite, culling); MetalDataFactoryImpl::m_deferredData->m_SPs.emplace_back(retval); return retval; } diff --git a/test/main.cpp b/test/main.cpp index e8f0f8c..feec53e 100644 --- a/test/main.cpp +++ b/test/main.cpp @@ -403,7 +403,7 @@ struct TestApplicationCallback : IApplicationCallback pipeline = metalF.newShaderPipeline(VS, FS, vfmt, 1, BlendFactor::One, BlendFactor::Zero, Primitive::TriStrips, - true, true, false); + true, true, boo::CullMode::None); } #endif