osy 3 роки тому
батько
коміт
ece15eb5ac
2 змінених файлів з 11 додано та 2 видалено
  1. 3 1
      Package.swift
  2. 8 1
      Sources/CocoaSpiceRenderer/CSRenderer.m

+ 3 - 1
Package.swift

@@ -18,7 +18,9 @@ let package = Package(
     targets: [
         .target(
             name: "CocoaSpiceRenderer",
-            dependencies: []),
+            dependencies: [],
+            resources: [
+                .process("CSShaders.metal")]),
         .target(
             name: "CocoaSpice",
             dependencies: ["CocoaSpiceRenderer"],

+ 8 - 1
Sources/CocoaSpiceRenderer/CSRenderer.m

@@ -59,7 +59,14 @@
         /// Create our render pipeline
 
         // Load all the shader files with a .metal file extension in the project
-        id<MTLLibrary> defaultLibrary = [_device newDefaultLibrary];
+        // FIXME: on Swift we have `Bundle.module` generated by SPM but it doesn't appear to be the case for Obj-C
+        NSURL *modulePath = [NSBundle.mainBundle.resourceURL URLByAppendingPathComponent:@"CocoaSpice_CocoaSpiceRenderer.bundle"];
+        NSBundle *bundle = [NSBundle bundleWithURL:modulePath];
+        NSError *err = nil;
+        id<MTLLibrary> defaultLibrary = [_device newDefaultLibraryWithBundle:bundle error:&err];
+        if (!defaultLibrary || err) {
+            NSLog(@"Failed to get library from bundle: %@", err.localizedDescription);
+        }
 
         // Load the vertex function from the library
         id<MTLFunction> vertexFunction = [defaultLibrary newFunctionWithName:@"vertexShader"];