2011-03-01 34 views

回答

2

是的,看看CCTextureCache.m在cocos2d的iPhone。

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!感谢万卡指针卡萨奎! – dugla 2011-03-02 16:12:04

相关问题