开发者

glGenTextures returns zero in background thread

开发者 https://www.devze.com 2023-01-11 12:16 出处:网络
I need to load textures in background th开发者_运维技巧read in OpenGL ES. But glGenTextures always returns zero when called in background thread.

I need to load textures in background th开发者_运维技巧read in OpenGL ES. But glGenTextures always returns zero when called in background thread.

-(void) someMethodInMainThread {
   [self performSelectorInBackground:@selector(load) withObject:nil];
}

-(void) load {
   GLuint textureID = 0;
   glGenTextures(1, &textureID);        
}

textureID is zero. If i change code to [self performSelector:@selector(tmp) withObject:nil]; it will work correct and return 1. How should i load textures in background thread?


This is a common error, each OpenGL context can be active (current) in one thread only, so when you create a new thread, it doesn't have any OpenGL context, and all GL calls fail.

Solution: Create another OpenGL context, make it current in your background thread. To load textures, you also want to share OpenGL names (texture ids, etc) with the main context.

0

精彩评论

暂无评论...
验证码 换一张
取 消