iOSでは、NSOperationサブクラスを介して別のスレッドでOpenGLテクスチャ作成(glTexImage2D)を実行することは不可能であると常に想定しています。誰かが確認/拒否してくれませんか。
テクスチャの作成はGUIをハングさせる可能性があるため、悪いです!-誰かが満足している回避策を思いついたことがありますか?
ありがとう、
ダグ
iOSでは、NSOperationサブクラスを介して別のスレッドでOpenGLテクスチャ作成(glTexImage2D)を実行することは不可能であると常に想定しています。誰かが確認/拒否してくれませんか。
テクスチャの作成はGUIをハングさせる可能性があるため、悪いです!-誰かが満足している回避策を思いついたことがありますか?
ありがとう、
ダグ
はい、iPhone用の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];