I'm trying to replace the opengl api in my static library with the Metal api( for ios). I looked into other answers that provides "ways to provide Metal shaders with a static library". So may I know why .metal files can't be built into the static library? And if that's the case, how should I implement the setup and render api functions in my static library without the .metal file inside the static library project folder?
Asked
Active
Viewed 430 times
2
-
As I understand you want to compile the shader from the string, right? – Hamid Yusifli Feb 12 '19 at 20:07
-
From your [(deleted) comment](https://stackoverflow.com/a/54641622/155187), it sounds like you just want to access the shaders compiled into your main app bundle from a static library that creates your pipeline states, etc. This should "just work," meaning that when you instantiate the default library in your static lib, it should look up the default library in the containing bundle. Is that not what you see? Or is this question more about how to package the shaders and the library together (which would be better done with a framework)? – warrenm Feb 12 '19 at 23:02
-
Pls show us code what you have tried. – GeneCode Feb 13 '19 at 01:14
-
@warrenm Thanks for replying! Yes I hoped to learn " how to package the shaders and the library together". Then I saw the post https://stackoverflow.com/questions/46742403/metal-file-as-part-of-an-ios-framework discussing that we can't do that for static lib so I asked here for further explanation to understand it better. I was trying to do everything in the static lib, including creating pipeline states and rendering, and the main app only provides the pixel buffer. You mentioned that it's better to done in a framework rather than a static lib? – Kathyz Feb 13 '19 at 01:30
-
@0xBFE1A8 Thanks for replying! I saw this solution in other places. Before I try that, I hope to firstly understand why we can't compile .metal and implement the render function inside a static lib? – Kathyz Feb 13 '19 at 01:32
-
@GeneCode Thanks for replying! This is weird but I'm still solving other errors that may not relate to this. I had a small sample metal project to render one picture on screen that works, and now I'm trying to integrate it into a larger app with a static lib. So this is more like a general question, because I thought I should learn the basic knowledge about how metal is compiled and worked in an ios project( and in a static lib in this case). – Kathyz Feb 13 '19 at 01:39
-
@Kathyz Right, because unless you use the tricks in that answer to turn your shader code into either strings or a pre-compiled metallib that you embed in the library as data, you can't get everything into one (.a) file. The reason I suggested a framework is that frameworks have their own directory structure, including a Resources directory, which can contain a .metallib without any special contortions. – warrenm Feb 13 '19 at 18:38
-
@warrenm Thanks for the advice. Since in my case here, the static library is used for this specific application only, I just let the main target compile the .metal file so I can get the defaultLibrary. I think this should be easier. – Kathyz Feb 19 '19 at 22:22
-
Yep, that's the easiest option by far if you don't need to obfuscate the shader code. – warrenm Feb 19 '19 at 23:25