I got a strange behavior since Xcode 4.5 and the iOS 6 SDK when using textures on my 3D objects. The problem also appears on my mac application when building against OS X 10.8 SDK.
I am using OpenGL ES 2.0 on iOS and OpenGL legacy profile ( < 3.0 ) on OS X 10.8.
The textures are not placed at there correct coordinates anymore and i have lots of artifacts. The VAOs are correctly uploaded and they look good without texturing. When using XCode 4.4.1 and iOS 5.1 SDK everything is fine.
The VAO is exactly the same (checked with OpenGL ES frame capture) and also the texture uniforms are binded correct.
Xcode 4.4 VAO Overview
Xcode 4.5 VAO Overview
XCode 4.4.1 (iOS 5.1 SDK)
XCode 4.5 (iOS 6 SDK)
Code / Shader Snippet
Relevant parts for uploading and processing the texture. I had to strip the shaders to the minium.
Vertex shader
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;
....
}
Fragment Shader
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;
....
}
Texture loading
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];
Render loop (Only sending the uniform of the active texture)
....
[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];
}
Had anyone a close problem to mine since iOS 6?
You should report the bug to bugreport.apple.com as already mentioned. As an aside, if you are suggesting that GLKTextureLoader is maybe the problem (seems like a good theory) then you might narrow things down in one of two ways off the top of my head...
1) I would render the texture shown to a trivial quad and see if the render results are what you expect., i.e., is it rendering vertically flipped from what you expect? Is the source texture partially garbled in some way that you weren't expecting?
2) You could try converting your image to a different size/color depth/image type and see if the problem still exists. What I'm thinking is, and it seems unlikely, but maybe it's not being reported because you are hitting an unusual edge case due to something with the image format. Knowing this would be of huge help to anyone trying to fix this at apple.
Probably not much help but without having access to all your source and assets, pretty hard to know what to suggest. FWIW, I have some samples that do similar things to what you are doing and haven't noticed anything under GLKit v. 10.8.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With