diff --git a/internal/graphicsdriver/metal/ca/ca.go b/internal/graphicsdriver/metal/ca/ca.go index 30f44aae5..7aeb06c13 100644 --- a/internal/graphicsdriver/metal/ca/ca.go +++ b/internal/graphicsdriver/metal/ca/ca.go @@ -31,7 +31,8 @@ import ( // Suppress the warnings about availability guard with -Wno-unguarded-availability-new. // It is because old Xcode (8 or older?) does not accept @available syntax. -// #cgo CFLAGS: -mmacosx-version-min=10.11 -Wno-unguarded-availability-new +// #cgo CFLAGS: -Wno-unguarded-availability-new +// #cgo !ios CFLAGS: -mmacosx-version-min=10.11 // #cgo LDFLAGS: -framework QuartzCore -framework Foundation -framework CoreGraphics // // #include "ca.h" diff --git a/internal/graphicsdriver/metal/ca/ca.h b/internal/graphicsdriver/metal/ca/ca.h index 4190a41f2..5ce003069 100644 --- a/internal/graphicsdriver/metal/ca/ca.h +++ b/internal/graphicsdriver/metal/ca/ca.h @@ -14,9 +14,9 @@ // +build darwin -typedef signed char BOOL; +#include + typedef unsigned long uint_t; -typedef unsigned short uint16_t; void *MakeMetalLayer(); @@ -26,7 +26,7 @@ const char *MetalLayer_SetPixelFormat(void *metalLayer, uint16_t pixelFormat); const char *MetalLayer_SetMaximumDrawableCount(void *metalLayer, uint_t maximumDrawableCount); void MetalLayer_SetDisplaySyncEnabled(void *metalLayer, - BOOL displaySyncEnabled); + uint8_t displaySyncEnabled); void MetalLayer_SetDrawableSize(void *metalLayer, double width, double height); void *MetalLayer_NextDrawable(void *metalLayer); diff --git a/internal/graphicsdriver/metal/ca/ca.m b/internal/graphicsdriver/metal/ca/ca.m index b168c8d18..bbc1b79fe 100644 --- a/internal/graphicsdriver/metal/ca/ca.m +++ b/internal/graphicsdriver/metal/ca/ca.m @@ -20,10 +20,13 @@ void *MakeMetalLayer() { CAMetalLayer *layer = [[CAMetalLayer alloc] init]; // TODO: Expose a function to set color space. + // TODO: Enable colorspace on iOS: this will be available as of iOS 13.0. +#if !TARGET_OS_IPHONE CGColorSpaceRef colorspace = - CGColorSpaceCreateWithName(kCGColorSpaceDisplayP3); + CGColorSpaceCreateWithName(kCGColorSpaceDisplayP3); layer.colorspace = colorspace; CGColorSpaceRelease(colorspace); +#endif return layer; } @@ -65,17 +68,19 @@ const char *MetalLayer_SetMaximumDrawableCount(void *metalLayer, } void MetalLayer_SetDisplaySyncEnabled(void *metalLayer, - BOOL displaySyncEnabled) { + uint8_t displaySyncEnabled) { // @available syntax is not available for old Xcode (#781) // // If possible, we'd want to write the guard like: // // if (@available(macOS 10.13, *)) { ... +#if !TARGET_OS_IPHONE if ([(CAMetalLayer *)metalLayer respondsToSelector:@selector(setDisplaySyncEnabled:)]) { [((CAMetalLayer *)metalLayer) setDisplaySyncEnabled:displaySyncEnabled]; } +#endif } void MetalLayer_SetDrawableSize(void *metalLayer, double width, double height) { diff --git a/internal/graphicsdriver/metal/driver.go b/internal/graphicsdriver/metal/driver.go index 3679d4f45..471d768bf 100644 --- a/internal/graphicsdriver/metal/driver.go +++ b/internal/graphicsdriver/metal/driver.go @@ -29,7 +29,8 @@ import ( "github.com/hajimehoshi/ebiten/internal/thread" ) -// #cgo CFLAGS: -x objective-c -mmacosx-version-min=10.11 +// #cgo CFLAGS: -x objective-c +// #cgo !ios CFLAGS: -mmacosx-version-min=10.11 // #cgo LDFLAGS: -framework Foundation // // #import diff --git a/internal/graphicsdriver/metal/mtl/mtl.go b/internal/graphicsdriver/metal/mtl/mtl.go index a0307ddd0..a8e53a7d8 100644 --- a/internal/graphicsdriver/metal/mtl/mtl.go +++ b/internal/graphicsdriver/metal/mtl/mtl.go @@ -30,7 +30,7 @@ import ( "unsafe" ) -// #cgo CFLAGS: -mmacosx-version-min=10.11 +// #cgo !ios CFLAGS: -mmacosx-version-min=10.11 // #cgo LDFLAGS: -framework Metal -framework Foundation // // #include @@ -437,16 +437,16 @@ func (d Device) MakeLibrary(source string, opt CompileOptions) (Library, error) // // Reference: https://developer.apple.com/documentation/metal/mtldevice/1433369-makerenderpipelinestate. func (d Device) MakeRenderPipelineState(rpd RenderPipelineDescriptor) (RenderPipelineState, error) { - blendingEnabled := C.BOOL(0) + blendingEnabled := 0 if rpd.ColorAttachments[0].BlendingEnabled { - blendingEnabled = C.BOOL(1) + blendingEnabled = 1 } c := &rpd.ColorAttachments[0] descriptor := C.struct_RenderPipelineDescriptor{ VertexFunction: rpd.VertexFunction.function, FragmentFunction: rpd.FragmentFunction.function, ColorAttachment0PixelFormat: C.uint16_t(c.PixelFormat), - ColorAttachment0BlendingEnabled: C.BOOL(blendingEnabled), + ColorAttachment0BlendingEnabled: C.uint8_t(blendingEnabled), ColorAttachment0DestinationAlphaBlendFactor: C.uint8_t(c.DestinationAlphaBlendFactor), ColorAttachment0DestinationRGBBlendFactor: C.uint8_t(c.DestinationRGBBlendFactor), ColorAttachment0SourceAlphaBlendFactor: C.uint8_t(c.SourceAlphaBlendFactor), diff --git a/internal/graphicsdriver/metal/mtl/mtl.h b/internal/graphicsdriver/metal/mtl/mtl.h index eb7fccc12..159a0af11 100644 --- a/internal/graphicsdriver/metal/mtl/mtl.h +++ b/internal/graphicsdriver/metal/mtl/mtl.h @@ -15,18 +15,15 @@ // +build darwin #include +#include -typedef signed char BOOL; typedef unsigned long uint_t; -typedef unsigned char uint8_t; -typedef unsigned short uint16_t; -typedef unsigned long long uint64_t; struct Device { void *Device; - BOOL Headless; - BOOL LowPower; - BOOL Removable; + uint8_t Headless; + uint8_t LowPower; + uint8_t Removable; uint64_t RegistryID; const char *Name; }; @@ -45,7 +42,7 @@ struct RenderPipelineDescriptor { void *VertexFunction; void *FragmentFunction; uint16_t ColorAttachment0PixelFormat; - BOOL ColorAttachment0BlendingEnabled; + uint8_t ColorAttachment0BlendingEnabled; uint8_t ColorAttachment0DestinationAlphaBlendFactor; uint8_t ColorAttachment0DestinationRGBBlendFactor; uint8_t ColorAttachment0SourceAlphaBlendFactor; @@ -108,7 +105,7 @@ struct Viewport { struct Device CreateSystemDefaultDevice(); struct Devices CopyAllDevices(); -BOOL Device_SupportsFeatureSet(void *device, uint16_t featureSet); +uint8_t Device_SupportsFeatureSet(void *device, uint16_t featureSet); void *Device_MakeCommandQueue(void *device); struct Library Device_MakeLibrary(void *device, const char *source, size_t sourceLength); diff --git a/internal/graphicsdriver/metal/mtl/mtl.m b/internal/graphicsdriver/metal/mtl/mtl.m index 49b9c3996..4315dede4 100644 --- a/internal/graphicsdriver/metal/mtl/mtl.m +++ b/internal/graphicsdriver/metal/mtl/mtl.m @@ -28,13 +28,18 @@ struct Device CreateSystemDefaultDevice() { struct Device d; d.Device = device; +#if !TARGET_OS_IPHONE d.Headless = device.headless; d.LowPower = device.lowPower; +#else + d.Headless = 0; + d.LowPower = 0; +#endif d.Name = device.name.UTF8String; return d; } -BOOL Device_SupportsFeatureSet(void *device, uint16_t featureSet) { +uint8_t Device_SupportsFeatureSet(void *device, uint16_t featureSet) { return [(id)device supportsFeatureSet:featureSet]; } @@ -257,17 +262,21 @@ void RenderCommandEncoder_DrawIndexedPrimitives( } void BlitCommandEncoder_Synchronize(void *blitCommandEncoder, void *resource) { +#if !TARGET_OS_IPHONE [(id)blitCommandEncoder synchronizeResource:(id)resource]; +#endif } void BlitCommandEncoder_SynchronizeTexture(void *blitCommandEncoder, void *texture, uint_t slice, uint_t level) { +#if !TARGET_OS_IPHONE [(id)blitCommandEncoder synchronizeTexture:(id)texture slice:(NSUInteger)slice level:(NSUInteger)level]; +#endif } void *Library_MakeFunction(void *library, const char *name) { diff --git a/internal/graphicsdriver/metal/ns/ns.go b/internal/graphicsdriver/metal/ns/ns.go index ee044dadb..3e7332000 100644 --- a/internal/graphicsdriver/metal/ns/ns.go +++ b/internal/graphicsdriver/metal/ns/ns.go @@ -27,7 +27,7 @@ import ( "github.com/hajimehoshi/ebiten/internal/graphicsdriver/metal/ca" ) -// #cgo CFLAGS: -mmacosx-version-min=10.11 +// #cgo !ios CFLAGS: -mmacosx-version-min=10.11 // // #include "ns.h" import "C"