6 #include <Metal/Metal.h>
14 MTLRenderPipelineColorAttachmentDescriptor*
17 auto des = [[MTLRenderPipelineColorAttachmentDescriptor alloc] init];
22 des.sourceRGBBlendFactor =
25 des.destinationRGBBlendFactor =
28 des.sourceAlphaBlendFactor =
31 des.destinationAlphaBlendFactor =
40 auto des = [[MTLStencilDescriptor alloc] init];
42 des.stencilFailureOperation =
45 des.depthStencilPassOperation =
55 std::optional<DepthAttachmentDescriptor> depth,
56 std::optional<StencilAttachmentDescriptor> front,
57 std::optional<StencilAttachmentDescriptor> back) {
62 .depth_write_enabled =
false,
66 auto des = [[MTLDepthStencilDescriptor alloc] init];
71 auto depth_write_enabled = depth->depth_write_enabled;
73 des.depthCompareFunction = compare_function;
74 des.depthWriteEnabled = depth_write_enabled;
76 if (front.has_value()) {
79 if (back.has_value()) {
90 auto mtl_desc = [[MTLTextureDescriptor alloc] init];
93 mtl_desc.sampleCount =
static_cast<NSUInteger
>(desc.
sample_count);
96 mtl_desc.mipmapLevelCount = desc.
mip_count;
97 mtl_desc.usage = MTLTextureUsageUnknown;
99 mtl_desc.usage |= MTLTextureUsageUnknown;
102 mtl_desc.usage |= MTLTextureUsageShaderRead;
105 mtl_desc.usage |= MTLTextureUsageShaderWrite;
108 mtl_desc.usage |= MTLTextureUsageRenderTarget;
115 if (@available(macOS 10.11, *)) {
116 return MTLPixelFormatDepth24Unorm_Stencil8;
119 return MTLPixelFormatInvalid;
123 if (@available(iOS 11, macOS 11.0, *)) {
124 return MTLPixelFormatBGR10_XR_sRGB;
126 return MTLPixelFormatInvalid;
131 if (@available(iOS 10, macOS 11.0, *)) {
132 return MTLPixelFormatBGR10_XR;
134 return MTLPixelFormatInvalid;
139 if (@available(iOS 10, macOS 11.0, *)) {
140 return MTLPixelFormatBGRA10_XR;
142 return MTLPixelFormatInvalid;