我尝试在 Metal 和我的 swift 项目之间共享我在头文件中定义的枚举:
#ifndef SharedIndizes_h
#define SharedIndizes_h
#import <Foundation/Foundation.h>
#endif /* SharedIndizes_h */
typedef NS_ENUM(NSInteger, VertexAttribute)
{
VertexAttributePosition = 0,
VertexAttributeNormal = 1,
};
Run Code Online (Sandbox Code Playgroud)
#include <metal_stdlib>
#import "ExchangeTypes/SharedIndizes.h"
using namespace metal;
struct VertexIn {
float3 position [[ attribute(VertexAttributePosition) ]];
float3 normal [[ attribute(VertexAttributeNormal) ]];
};
Run Code Online (Sandbox Code Playgroud)
vertexDescriptor.attributes[VertexAttribute.position.rawValue]
vertexDescriptor.attributes[VertexAttribute.normal.rawValue]
Run Code Online (Sandbox Code Playgroud)
但我得到的只是一些意想不到的错误:
不支持的架构
未知类型名称“_int64_t”
未知类型名称“_int32_t”
...
从我的金属文件中删除#import "ExchangeTypes/SharedIndizes.h"
也会消除错误。
替换这个:
#ifndef SharedIndizes_h
#define SharedIndizes_h
#import <Foundation/Foundation.h>
#endif /* SharedIndizes_h */
typedef NS_ENUM(NSInteger, VertexAttribute)
{
VertexAttributePosition = 0,
VertexAttributeNormal = 1,
};
Run Code Online (Sandbox Code Playgroud)
有了这个:
#ifndef SharedIndizes_h
#define SharedIndizes_h
#ifdef __METAL_VERSION__
#define NS_ENUM(_type, _name) enum _name : _type _name; enum _name : _type
#define NSInteger metal::int32_t
#else
#import <Foundation/Foundation.h>
#endif /* __METAL_VERSION__ */
#endif /* SharedIndizes_h */
typedef NS_ENUM(NSInteger, VertexAttribute)
{
VertexAttributePosition = 0,
VertexAttributeNormal = 1,
};
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
438 次 |
最近记录: |