自從Xcode 4.5和iOS 6 SDK在我的3D對象上使用紋理後,我得到了一個奇怪的行爲。 當針對OS X 10.8 SDK進行構建時,該問題也出現在我的Mac應用程序中。GLKTexture自iOS6以來未正確映射
我在OS X 10.8上的iOS和OpenGL傳統配置文件(< 3.0)上使用OpenGL ES 2.0。
紋理沒有放在那裏正確的座標了,我有很多的文物。 VAOs正確上傳,他們看起來不錯,沒有紋理。當使用XCode 4.4.1和iOS 5.1 SDK時,一切都很好。
VAO是完全一樣的(使用OpenGL ES幀捕獲進行檢查),並且紋理制服的綁定正確。
的Xcode 4.4 VAO概述
的Xcode 4.5 VAO概述
的XCode 4.4.1(5.1的iOS SDK)
的XCode 4.5(iOS 6的SDK)
代碼/着色片段
爲uploadi相關部分並處理紋理。我必須將着色器剝離到最小值。
頂點着色器
precision highp float;
attribute vec2 a_vTextureCoordinate;
uniform mat4 u_mModelViewMatrix;
uniform mat4 u_mModelViewMatrixInverse;
uniform mat4 u_mProjectionMatrix;
uniform mat4 u_mNormalMatrix;
void main()
{
....
// Transform output position
gl_Position = u_mProjectionMatrix * u_mModelViewMatrix * a_vPosition;
// Pass through texture coordinate v_texcoord = a_vTextureCoordinate.xy;
v_vPosition = vec3(u_mModelViewMatrix * a_vPosition);
v_vTextureCoordinate = a_vTextureCoordinate.xy;
....
}
片段着色器
precision highp float;
// location 1
uniform sampler2D u_diffuseTexture;
varying vec2 v_vTextureCoordinate;
varying vec3 v_vPosition;
....
void main() {
....
vec4 base = texture2D(u_diffuseTexture, v_vTextureCoordinate);
gl_FragColor = base;
....
}
紋理加載
NSDictionary *options = @{GLKTextureLoaderOriginBottomLeft: @(YES), [NSNumber numberWithBool:YES] : GLKTextureLoaderGenerateMipmaps};
NSError *error;
path = [path stringByReplacingOccurrencesOfString:@"/" withString:@""];
path = [[NSBundle mainBundle] pathForResource:[path stringByDeletingPathExtension] ofType:[path pathExtension]];
GLKTextureInfo *texture = [GLKTextureLoader textureWithContentsOfFile:path options:options error:&error];
渲染迴路(僅發送所述活性紋理的均勻)
....
[self setShaderTexture:[[materials objectForKey:@"diffuse"] objectForKey:@"glktexture"]
forKey:@"u_diffuseTexture"
withUniform1i:0
andTextureUnit:GL_TEXTURE0+0];
....
#pragma mark - Texture communication
-(void)setShaderTexture:(GLKTextureInfo*)texture forKey:(NSString*)key withUniform1i:(int32_t)uniform andTextureUnit:(int32_t)unit {
glActiveTexture(unit);
glBindTexture(texture.target, texture.name);
[self.shaderManager sendUniform1Int:key parameter:uniform];
}
沒有任何人緊密問題礦因爲iOS 6的?
您是否在https://bugreport.apple.com/上提交了錯誤報告? OpenGL ES工程師可能想看看這個。你說這也出現在你的10.8應用程序中。您是否也在Mac側使用GLKTexture? –
嗨布拉德,是的,我也在OS X 10.8下使用GLKit。我很好奇,沒有人報告過這個問題。在10.8的測試階段,我已經在蘋果公司的測試版論壇上提出了問題,但是知道有一個線索。我也會填寫一個錯誤報告。 – DasFuxx
您可以添加測試紋理的截圖嗎? (例如編號/彩色棋盤) 可能有助於查看偏移中的圖案。 – Andreas