GPUImage源码解读(三)
GPUImageContext类,提供OpenGL ES基本上下文,GPUImage相关处理线程,GLProgram缓存、帧缓存。由于是上下文对象,因此该模块提供的更多是存取、设置相关的方法。
属性列表
// GPUImage处理OpenGL绘制的相关队列,串行队列
@property(readonly, nonatomic) dispatch_queue_t contextQueue;
// 当前使用的着色器程序
@property(readwrite, retain, nonatomic) GLProgram *currentShaderProgram;
// OpenGLES上下文对象
@property(readonly, retain, nonatomic) EAGLContext *context;
// CoreVideo中的纹理缓存
@property(readonly) CVOpenGLESTextureCacheRef coreVideoTextureCache;
// 帧缓存
@property(readonly) GPUImageFramebufferCache *framebufferCache;初始化过程。在初始化的过程中通过dispatch_queue_set_specific设置队列标识是为了防止死锁
- (id)init;
{
if (!(self = [super init]))
{
return nil;
}
// 创建OpenGL渲染队列
openGLESContextQueueKey = &openGLESContextQueueKey;
_contextQueue = dispatch_queue_create("com.sunsetlakesoftware.GPUImage.openGLESContextQueue", NULL);
#if (!defined(__IPHONE_6_0) || (__IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_6_0))
#else
//设置队列标识 防止死锁 @see http://www.jianshu.com/p/a9066dde1f2b
dispatch_queue_set_specific(_contextQueue, openGLESContextQueueKey, (__bridge void *)self, NULL);
#endif
// 初始化着色器缓存相关数组
shaderProgramCache = [[NSMutableDictionary alloc] init];
shaderProgramUsageHistory = [[NSMutableArray alloc] init];
return self;
}方法列表
调整纹理大小,保证纹理不超过OpenGLES支持最大的尺寸:
获取OpenGLES支持的最大纹理尺寸。,最在尺寸是多少?
创建GLProgram,首先在缓存中查找,如果没有则创建
创建EAGLContext上下文对象,使用的是kEAGLRenderingAPIOpenGLES2的API也就是OpenGL ES 2.0
设置当前的上下文对象,以及当前的着色器程序。
Last updated