2011-03-01 2 views
1

iOS에서 나는 항상 이 아니라고 가정하고 있습니다. OpenGL 텍스처 생성 (glTexImage2D)은 NSOperation 하위 클래스를 통해 별도의 스레드에서 수행 할 수 있습니다.이 없습니다. 누군가 확인/거부 할 수 있습니까?iOS의 OpenGL. glTexImage2D를 별도의 스레드에서 호출 할 수 있습니까?

텍스처가 생성되어 GUI가 중단 될 수 있습니다. - 누구나 만족할만한 해결 방법을 찾았습니까?

감사합니다,
더그

답변

2

예, 아이폰적인 Cocos2D에서 CCTextureCache.m를보십시오.

cocos2d-iphone/cocos2d/CCTextureCache.m

NSAutoreleasePool *autoreleasepool = [[NSAutoreleasePool alloc] init]; 

// textures will be created on the main OpenGL context 
// it seems that in SDK 2.2.x there can't be 2 threads creating textures at the same time 
// the lock is used for this purpose: issue #472 
[contextLock_ lock]; 
if(auxGLcontext == nil) { 
    auxGLcontext = [[EAGLContext alloc] 
          initWithAPI:kEAGLRenderingAPIOpenGLES1 
          sharegroup:[[[[CCDirector sharedDirector] openGLView] context] sharegroup]]; 

    if(! auxGLcontext) 
     CCLOG(@"cocos2d: TextureCache: Could not create EAGL context"); 
} 

if([EAGLContext setCurrentContext:auxGLcontext]) { 

    // load/create the texture 
    CCTexture2D *tex = [self addImage:async.data]; 

    /* This method calls glTexImage2D. */ 


    // The callback will be executed on the main thread 
    [async.target performSelectorOnMainThread:async.selector withObject:tex waitUntilDone:NO];   

    [EAGLContext setCurrentContext:nil]; 
} else { 
    CCLOG(@"cocos2d: TetureCache: EAGLContext error"); 
} 
[contextLock_ unlock]; 

[autoreleasepool release]; 
+0

CCCOOOOLLLL! Kazakui에게 감사드립니다. – dugla