簡體   English   中英

從更新調用時,GLKTextureLoader失敗

[英]GLKTextureLoader fails when calling from update

從viewDidLoad加載紋理工作正常。 但是,如果我嘗試從GLKViewController更新加載它我得到一個錯誤。 我這樣做是因為我想在不改變視圖的情況下交換新的背景紋理。

這在上次升級之前有效。 也許我對時間很幸運。 我懷疑它是失敗的,因為某些線程正忙或什么?

這是完整的錯誤。

Domain = GLKTextureLoaderErrorDomain Code = 8“無法完成操作。(GLKTextureLoaderErrorDomain error 8.)”UserInfo = 0x10b5b510 {GLKTextureLoaderGLErrorKey = 1282,GLKTextureLoaderErrorKey = OpenGL error}

所以問題是,我可以安全地從GLKViewController更新函數加載紋理嗎? 或者我是否需要重新考慮我的方法並重新加載整個視圖或其他內容?

這是我的功能:

-(void) LoadTexture:(NSString *)texture textureInfo:(GLKTextureInfo**)textureInfo
{
    NSString *path = [[NSBundle mainBundle] pathForResource:texture ofType:@"png"]; 
    NSError *error = nil;

    (*textureInfo) = [GLKTextureLoader textureWithContentsOfFile:path options:nil error:&error];

    NSLog(@"path %@", path);

    if(!(*textureInfo))
    {
        NSLog(@"Failed to load texture %@ %@", texture, error);  
    }
    else
    {
        NSLog(@"LOADED Texture %@ !!! YAY!!! ", texture);
    }
}

謝謝,

大衛

我有這樣的問題,工作arround正在加載沒有glktextureloader的紋理。

這里有一些代碼用於在沒有GLKtextureLoader的情況下加載紋理:

bool lPowerOfTwo  = false;

UIImage *image    = [UIImage imageNamed:@"texture.png"];

GLuint width = CGImageGetWidth(image.CGImage);
GLuint height = CGImageGetHeight(image.CGImage);
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
void *imageData = malloc( height * width * 4 );
CGContextRef context = CGBitmapContextCreate( imageData, width, height, 8, 4 * width, colorSpace, kCGImageAlphaPremultipliedLast | kCGBitmapByteOrder32Big );
CGColorSpaceRelease( colorSpace );

CGContextClearRect( context, CGRectMake( 0, 0, width, height ) );
CGRect bounds=CGRectMake( 0, 0, width, height );
CGContextScaleCTM(context, 1, -1);
bounds.size.height = bounds.size.height*-1;
CGContextDrawImage(context, bounds, image.CGImage);

GLuint lTextId;
glGenTextures(1, &lTextId);
glBindTexture(GL_TEXTURE_2D, lTextId);


glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, imageData);

if(!lPowerOfTwo)
{
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR_MIPMAP_LINEAR);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT );
    glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT );

    glGenerateMipmap(GL_TEXTURE_2D);
}else
{
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);

    glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE );
    glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE );
}

CGContextRelease(context);

free(imageData);

lTextId變量具有opengl紋理ID。

注意:如果紋理尺寸不是2的冪,如果GL_TEXTURE_WRAP_S和_T未設置為GL_GLAMP_TO_EDGE,則紋理將顯示為黑色

我遇到了類似的問題。 我解決這個問題的方法是讓一個擁有我想要用於整個游戲的所有紋理的Class。 viewDidLoad:我初始化了類並加載了所有紋理。 當我需要使用任何紋理時,它們已經加載並且沒有出現問題。

例如。 viewDidLoad

GameTextures *textures = [GameTextures alloc] init];
[textures LoadAll];

LoadAll將加載所有紋理以供以后使用

然后當你需要使用紋理時

[myBackground setTexture: textures.backgroundTexture2];

希望這有助於:)

我看到了同樣的行為,這是由無關的錯誤引起的。 修復錯誤,紋理應正確加載。 看到這個帖子: GLKTextureLoader在第一次加載某個紋理時失敗,但第二次成功

我有幾乎相同的錯誤:

Error Domain = GLKTextureLoaderErrorDomain Code = 8“(null)”UserInfo = {GLKTextureLoaderGLErrorKey = 1282,GLKTextureLoaderErrorKey = OpenGLES Error。}

它是由程序之間的切換引起的。 如果我嘗試使用當前未使用的程序調用glUniform1i,則會遇到Open GL ES錯誤斷點。

通過使用正確的程序修復,避免觸發任何錯誤斷點。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM