GLKTextureLoader fails when loading a certain texture the first time, but succeeds the second time

前端 未结 8 2696
清酒与你
清酒与你 2021-02-20 12:57

I\'m making an iPhone application with OpenGL ES 2.0 using the GLKit. I\'m using GLKTextureLoader to load textures synchronously.

The problem is that for a certain textu

相关标签:
8条回答
  • 2021-02-20 13:49

    Maybe you've resolved this, but are you using multiple contexts? maybe you should be loading your texture asynchronously with sharegroup.

    so instead of using tex = [GLKTextureLoader textureWithContentsOfFile:bundlepath options:options error:&error];

    use something like:

    GLKTextureLoader *textureloader = [[GLKTextureLoader alloc] initWithSharegroup:self.eaglContext.sharegroup];
    GLKTextureInfo *myTexture;
    [textureloader textureWithCGImage:_currentForegroundImage.CGImage options:nil queue:nil completionHandler:^(GLKTextureInfo *textureInfo, NSError *error) {
            myTexture = textureInfo;
            if(error) {
                // log stuff
            }
            // do something
    }];
    
    0 讨论(0)
  • 2021-02-20 13:49

    I had a similar problem. Is was caused by a texture that had width / height not power of 2. GLKTextureLoader failed on loading this and the following images. Checking glGetError() after each texture load revealed the troublemakers :-).

    0 讨论(0)
提交回复
热议问题