#include "hecl/Backend/Metal.hpp" #include #include #include static logvisor::Module Log("hecl::Backend::Metal"); namespace hecl::Backend { std::string Metal::EmitTexGenSource2(TexGenSrc src, int uvIdx) const { switch (src) { case TexGenSrc::Position: return "vtf.mvPos.xy\n"; case TexGenSrc::Normal: return "vtf.mvNorm.xy\n"; case TexGenSrc::UV: return hecl::Format("v.uvIn%u", uvIdx); default: break; } return std::string(); } std::string Metal::EmitTexGenSource4(TexGenSrc src, int uvIdx) const { switch (src) { case TexGenSrc::Position: return "float4(vtf.mvPos.xyz, 1.0)\n"; case TexGenSrc::Normal: return "float4(vtf.mvNorm.xyz, 1.0)\n"; case TexGenSrc::UV: return hecl::Format("float4(v.uvIn%u, 0.0, 1.0)", uvIdx); default: break; } return std::string(); } std::string Metal::GenerateVertInStruct(unsigned col, unsigned uv, unsigned w) const { std::string retval = "struct VertData\n" "{\n" " float3 posIn [[ attribute(0) ]];\n" " float3 normIn [[ attribute(1) ]];\n"; unsigned idx = 2; if (col) { for (unsigned i=0 ; i tex%u [[ texture(%u) ]]", i, i); if (reflectionType == ReflectionType::Indirect) texMapDecl += hecl::Format(",\ntexture2d reflectionIndTex [[ texture(%u) ]]\n" ",\ntexture2d reflectionTex [[ texture(%u) ]]\n", m_texMapEnd, m_texMapEnd+1); else if (reflectionType == ReflectionType::Simple) texMapDecl += hecl::Format(",\ntexture2d reflectionTex [[ texture(%u) ]]\n", m_texMapEnd); std::string blockCall; for (size_t i=0 ; i tex%u [[ texture(%u) ]]", i, i); if (reflectionType == ReflectionType::Indirect) texMapDecl += hecl::Format(",\ntexture2d reflectionIndTex [[ texture(%u) ]]\n" ",\ntexture2d reflectionTex [[ texture(%u) ]]\n", m_texMapEnd, m_texMapEnd+1); else if (reflectionType == ReflectionType::Simple) texMapDecl += hecl::Format(",\ntexture2d reflectionTex [[ texture(%u) ]]\n", m_texMapEnd); std::string extTexCall; for (int i=0 ; i tex%u [[ texture(%u) ]]", extTex.mapIdx, extTex.mapIdx); extTexBits |= 1 << extTex.mapIdx; } std::string blockCall; for (size_t i=0 ; i