mirror of
				https://github.com/GayPizzaSpecifications/voxelotl-engine.git
				synced 2025-11-04 10:59:39 +00:00 
			
		
		
		
	Official iOS/iPadOS/visionOS/tvOS support
This commit is contained in:
		@ -53,7 +53,9 @@ public class Application {
 | 
			
		||||
    view = SDL_Metal_CreateView(window)
 | 
			
		||||
    do {
 | 
			
		||||
      let layer = unsafeBitCast(SDL_Metal_GetLayer(view), to: CAMetalLayer.self)
 | 
			
		||||
#if os(macOS)
 | 
			
		||||
      layer.displaySyncEnabled = cfg.vsyncMode == .off ? false : true
 | 
			
		||||
#endif
 | 
			
		||||
      self.renderer = try Renderer(layer: layer, size: Size<Int>(backBuffer))
 | 
			
		||||
    } catch RendererError.initFailure(let message) {
 | 
			
		||||
      printErr("Renderer init error: \(message)")
 | 
			
		||||
 | 
			
		||||
										
											Binary file not shown.
										
									
								
							| 
		 After Width: | Height: | Size: 672 KiB  | 
										
											Binary file not shown.
										
									
								
							| 
		 After Width: | Height: | Size: 672 KiB  | 
										
											Binary file not shown.
										
									
								
							| 
		 After Width: | Height: | Size: 672 KiB  | 
@ -0,0 +1,38 @@
 | 
			
		||||
{
 | 
			
		||||
  "images" : [
 | 
			
		||||
    {
 | 
			
		||||
      "filename" : "AppIconMobile1024x1024.png",
 | 
			
		||||
      "idiom" : "universal",
 | 
			
		||||
      "platform" : "ios",
 | 
			
		||||
      "size" : "1024x1024"
 | 
			
		||||
    },
 | 
			
		||||
    {
 | 
			
		||||
      "appearances" : [
 | 
			
		||||
        {
 | 
			
		||||
          "appearance" : "luminosity",
 | 
			
		||||
          "value" : "dark"
 | 
			
		||||
        }
 | 
			
		||||
      ],
 | 
			
		||||
      "filename" : "AppIconMobile1024x1024 1.png",
 | 
			
		||||
      "idiom" : "universal",
 | 
			
		||||
      "platform" : "ios",
 | 
			
		||||
      "size" : "1024x1024"
 | 
			
		||||
    },
 | 
			
		||||
    {
 | 
			
		||||
      "appearances" : [
 | 
			
		||||
        {
 | 
			
		||||
          "appearance" : "luminosity",
 | 
			
		||||
          "value" : "tinted"
 | 
			
		||||
        }
 | 
			
		||||
      ],
 | 
			
		||||
      "filename" : "AppIconMobile1024x1024 2.png",
 | 
			
		||||
      "idiom" : "universal",
 | 
			
		||||
      "platform" : "ios",
 | 
			
		||||
      "size" : "1024x1024"
 | 
			
		||||
    }
 | 
			
		||||
  ],
 | 
			
		||||
  "info" : {
 | 
			
		||||
    "author" : "xcode",
 | 
			
		||||
    "version" : 1
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
@ -80,6 +80,15 @@ set_source_files_properties(
 | 
			
		||||
target_include_directories(Voxelotl PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}")
 | 
			
		||||
target_link_libraries(Voxelotl PRIVATE SDLSwift)
 | 
			
		||||
target_compile_definitions(Voxelotl PRIVATE $<$<CONFIG:Debug>:DEBUG>)
 | 
			
		||||
 | 
			
		||||
if(VOXELOTL_MOBILE_ENABLED)
 | 
			
		||||
  set(VOXELOTL_APPICON "AppIconMobile")
 | 
			
		||||
  set(VOXELOTL_RPATH "@loader_path/Frameworks")
 | 
			
		||||
else()
 | 
			
		||||
  set(VOXELOTL_APPICON "AppIcon")
 | 
			
		||||
  set(VOXELOTL_RPATH "@loader_path/../Frameworks")
 | 
			
		||||
endif()
 | 
			
		||||
 | 
			
		||||
set_target_properties(Voxelotl PROPERTIES
 | 
			
		||||
  XCODE_ATTRIBUTE_ENABLE_HARDENED_RUNTIME YES
 | 
			
		||||
  XCODE_ATTRIBUTE_PRODUCT_BUNDLE_IDENTIFIER "gay.pizza.voxelotl"
 | 
			
		||||
@ -91,8 +100,8 @@ set_target_properties(Voxelotl PROPERTIES
 | 
			
		||||
  MACOSX_BUNDLE_SHORT_VERSION_STRING "${PROJECT_VERSION}"
 | 
			
		||||
  MACOSX_BUNDLE_GUI_IDENTIFIER "gay.pizza.voxelotl"
 | 
			
		||||
  MACOSX_BUNDLE_INFO_PLIST "${CMAKE_CURRENT_SOURCE_DIR}/Info.plist.in"
 | 
			
		||||
  XCODE_ATTRIBUTE_ASSETCATALOG_COMPILER_APPICON_NAME "AppIcon"
 | 
			
		||||
  BUILD_RPATH "@loader_path/../Frameworks"
 | 
			
		||||
  XCODE_ATTRIBUTE_ASSETCATALOG_COMPILER_APPICON_NAME "${VOXELOTL_APPICON}"
 | 
			
		||||
  BUILD_RPATH "${VOXELOTL_RPATH}"
 | 
			
		||||
  XCODE_ATTRIBUTE_SKIP_INSTALL "NO"
 | 
			
		||||
  XCODE_ATTRIBUTE_INSTALL_PATH "$(LOCAL_APPS_DIR)"
 | 
			
		||||
  XCODE_GENERATE_SCHEME ON
 | 
			
		||||
@ -100,6 +109,14 @@ set_target_properties(Voxelotl PROPERTIES
 | 
			
		||||
  XCODE_ATTRIBUTE_CODE_SIGN_ENTITLEMENTS "${CMAKE_CURRENT_SOURCE_DIR}/Voxelotl.entitlements"
 | 
			
		||||
  MACOSX_BUNDLE_COPYRIGHT "© 2024 Gay Pizza Specifications")
 | 
			
		||||
 | 
			
		||||
if(VOXELOTL_MOBILE_ENABLED)
 | 
			
		||||
  set_target_properties(Voxelotl PROPERTIES
 | 
			
		||||
    XCODE_ATTRIBUTE_CODE_SIGNING_REQUIRED "YES"
 | 
			
		||||
    XCODE_ATTRIBUTE_CODE_SIGNING_ALLOWED "YES"
 | 
			
		||||
    XCODE_ATTRIBUTE_TARGETED_DEVICE_FAMILY "1,2"
 | 
			
		||||
  )
 | 
			
		||||
endif()
 | 
			
		||||
 | 
			
		||||
set_source_files_properties(Assets.xcassets PROPERTIES MACOSX_PACKAGE_LOCATION Resources)
 | 
			
		||||
set_source_files_properties(module.modulemap PROPERTIES MACOSX_PACKAGE_LOCATION Modules)
 | 
			
		||||
set_source_files_properties(test.png PROPERTIES MACOSX_PACKAGE_LOCATION Resources)
 | 
			
		||||
 | 
			
		||||
@ -52,7 +52,7 @@ public struct AABB {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
public extension AABB {
 | 
			
		||||
  public static func + (lhs: Self, rhs: SIMD3<Float>) -> Self {
 | 
			
		||||
  static func + (lhs: Self, rhs: SIMD3<Float>) -> Self {
 | 
			
		||||
    .init(bounds: lhs._bounds + .init(rhs, rhs))
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -40,12 +40,16 @@ public class Renderer {
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  fileprivate static func createMetalDevice() -> MTLDevice? {
 | 
			
		||||
#if os(macOS)
 | 
			
		||||
    MTLCopyAllDevices().reduce(nil, { best, dev in
 | 
			
		||||
      if best == nil { dev }
 | 
			
		||||
      else if !best!.isLowPower || dev.isLowPower { best }
 | 
			
		||||
      else if best!.supportsRaytracing || !dev.supportsRaytracing { best }
 | 
			
		||||
      else { dev }
 | 
			
		||||
    })
 | 
			
		||||
#else
 | 
			
		||||
    MTLCreateSystemDefaultDevice()
 | 
			
		||||
#endif
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  internal init(layer metalLayer: CAMetalLayer, size: Size<Int>) throws {
 | 
			
		||||
@ -56,6 +60,7 @@ public class Renderer {
 | 
			
		||||
      throw RendererError.initFailure("Failed to create Metal device")
 | 
			
		||||
    }
 | 
			
		||||
    self.device = device
 | 
			
		||||
#if os(macOS)
 | 
			
		||||
    self._defaultStorageMode = if #available(macOS 100.100, iOS 12.0, *) {
 | 
			
		||||
      .storageModeShared
 | 
			
		||||
    } else if #available(macOS 10.15, iOS 13.0, *) {
 | 
			
		||||
@ -64,6 +69,9 @@ public class Renderer {
 | 
			
		||||
      // https://developer.apple.com/documentation/metal/gpu_devices_and_work_submission/multi-gpu_systems/finding_multiple_gpus_on_an_intel-based_mac#3030770
 | 
			
		||||
      (self.device.isLowPower && !self.device.isRemovable) ? .storageModeShared : .storageModeManaged
 | 
			
		||||
    }
 | 
			
		||||
#else
 | 
			
		||||
    self._defaultStorageMode = .storageModeShared
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
    layer.device = device
 | 
			
		||||
    layer.pixelFormat = colorFormat
 | 
			
		||||
 | 
			
		||||
@ -1,4 +1,9 @@
 | 
			
		||||
#if os(macOS)
 | 
			
		||||
import AppKit
 | 
			
		||||
#else
 | 
			
		||||
import UIKit
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
struct NSImageLoader {
 | 
			
		||||
  private static let flipVertically = true
 | 
			
		||||
@ -6,11 +11,19 @@ struct NSImageLoader {
 | 
			
		||||
  static func open(url: URL) throws -> Image2D {
 | 
			
		||||
    try autoreleasepool {
 | 
			
		||||
      // Open as a CoreGraphics image
 | 
			
		||||
#if os(macOS)
 | 
			
		||||
      guard let nsImage = NSImage(contentsOf: url),
 | 
			
		||||
        let cgImage = nsImage.cgImage(forProposedRect: nil, context: nil, hints: nil)
 | 
			
		||||
      else {
 | 
			
		||||
        throw ImageLoaderError.openFailed("Failed to open image \"\(url.absoluteString)\"")
 | 
			
		||||
      }
 | 
			
		||||
#else
 | 
			
		||||
      guard let nsImage = UIImage(contentsOfFile: url.path(percentEncoded: false)),
 | 
			
		||||
        let cgImage = nsImage.cgImage
 | 
			
		||||
      else {
 | 
			
		||||
        throw ImageLoaderError.openFailed("Failed to open image \"\(url.absoluteString)\"")
 | 
			
		||||
      }
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
      // Convert 8-bit ARGB (sRGB) w/ pre-multiplied alpha
 | 
			
		||||
      let alphaInfo = cgImage.alphaInfo == .none
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user