我正在尝试同时自学 Xcode、Objective-C、iOS 应用程序开发和 GLSL。(我知道,可能不建议这样做。;-) 我一直在修改 GLCameraRipple 示例,到目前为止取得了很大的成功!但是今天当我尝试创建一些新的顶点和片段着色器时,我被难住了。
该示例带有名为“Shader.vsh”和“Shader.fsh”的着色器。我使用 File->Duplicate 来制作它们的副本,我分别称之为“Reflection.vsh”和“Reflection.fsh”。问题是我无法让 Xcode 识别新的着色器。这段代码加载了原始的顶点着色器,工作得很好:
vertShaderPathname = [[NSBundle mainBundle] pathForResource:@"Shader" ofType:@"vsh"];
NSLog(@"Original vertex shader should be here: %@", vertShaderPathname);
if (![self compileShader:&vertShader type:GL_VERTEX_SHADER file:vertShaderPathname]) {
NSLog(@"Failed to compile original vertex shader");
return NO;
}
但是这段试图加载我的新“Reflection.vsh”着色器的代码失败了。具体来说,reflectVertShaderPathname 字符串返回值为 (null)。
reflectVertShaderPathname = [[NSBundle mainBundle] pathForResource:@"Reflection" ofType:@"vsh"];
NSLog(@"Reflection vertex shader should be here: %@", reflectVertShaderPathname);
if (![self compileShader:&reflectVertShader type:GL_VERTEX_SHADER file:reflectVertShaderPathname]) {
NSLog(@"Failed to compile reflection vertex shader");
return NO;
}
我该怎么做才能完成这项工作?我什至不知道从哪里开始:Xcode 在为 iPad 编译它时是否未能将我的新着色器包含在它制作的 NSBundle 中?我必须调用什么魔法来说服 Xcode 加载我的新着色器?(或者我完全在错误的地方寻找答案?)以前有没有其他人遇到过类似的问题?
在文本编辑器中检查“project.pbxproj”文件,我注意到着色器被不同处理的部分:
/* Begin PBXResourcesBuildPhase section */
B66E3E2C13E9E79C00D2ACF0 /* Resources */ = {
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
B66E3E4713E9E79C00D2ACF0 /* Shader.fsh in Resources */,
B66E3E4913E9E79C00D2ACF0 /* Shader.vsh in Resources */,
B66E3E4F13E9E79C00D2ACF0 /* RippleViewController_iPhone.xib in Resources */,
B66E3E5213E9E79C00D2ACF0 /* RippleViewController_iPad.xib in Resources */,
B6388B2C141AB58300DA02FB /* Icon-72.png in Resources */,
B6388B2D141AB58300DA02FB /* Icon-Small-50.png in Resources */,
B6388B2E141AB58300DA02FB /* Icon-Small.png in Resources */,
B6388B2F141AB58300DA02FB /* Icon-Small@2x.png in Resources */,
B6388B30141AB58300DA02FB /* Icon.png in Resources */,
B6388B31141AB58300DA02FB /* Icon@2x.png in Resources */,
C3E55C21175C49F9007C299D /* Default-568h@2x.png in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXResourcesBuildPhase section */
/* Begin PBXSourcesBuildPhase section */
B66E3E2A13E9E79C00D2ACF0 /* Sources */ = {
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
B66E3E4113E9E79C00D2ACF0 /* main.m in Sources */,
B66E3E4513E9E79C00D2ACF0 /* AppDelegate.m in Sources */,
B66E3E4C13E9E79C00D2ACF0 /* RippleViewController.m in Sources */,
B6670DB413E9FD9F00AEF9EC /* RippleModel.m in Sources */,
C359BF4D175EA71C00D801B9 /* Reflection.fsh in Sources */,
C359BF4F175EA72A00D801B9 /* Reflection.vsh in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXSourcesBuildPhase section */
所以看起来“Shader.vsh”在一个叫做“Resources”的东西里,而“Reflection.vsh”在一个叫做“Sources”的东西里。我认为这是问题的一部分。但是(a)这甚至意味着什么,以及(b)我应该如何解决它?在文本编辑器中编辑 project.pbxproj 是否安全???