GPUImageContext負(fù)責(zé)管理OpenGL context已經(jīng)當(dāng)前context處理任務(wù)用到的資源萨惑,包括GLProgram澳淑、CVOpenGLESTextureCacheRef、GPUImageFramebufferCache。
GPUImageContext的源碼并不是很復(fù)雜,不過.h文件中聲明的屬性和方法有點(diǎn)亂,下面將對.h文件的屬性和方法進(jìn)行分類贷盲,然后對應(yīng)著看.m文件中的相關(guān)實(shí)現(xiàn)就能很快縷清關(guān)系:
// GPUImageContext.h
// 上下文相關(guān)
@property(readonly, retain, nonatomic) EAGLContext *context; // 獲取當(dāng)前上下文
+ (GPUImageContext *)sharedImageProcessingContext; // 創(chuàng)建上下文單例
+ (void)useImageProcessingContext; // 創(chuàng)建上下文單例,并設(shè)置為當(dāng)前上下文
- (void)useAsCurrentContext; // 設(shè)置為當(dāng)前上下文
- (void)useSharegroup:(EAGLSharegroup *)sharegroup; // 使用EAGLSharegroup
@property(readonly, nonatomic) dispatch_queue_t contextQueue; // 上下文隊(duì)列
+ (dispatch_queue_t)sharedContextQueue; // 同上
+ (void *)contextKey; // 上下文的key剥扣,用于獲取當(dāng)前隊(duì)列的
// 著色器程序相關(guān)
@property(readwrite, retain, nonatomic) GLProgram *currentShaderProgram; // 當(dāng)前著色器程序
+ (void)setActiveShaderProgram:(GLProgram *)shaderProgram; // 設(shè)置為當(dāng)前的著色器程序
- (void)setContextShaderProgram:(GLProgram *)shaderProgram; // 設(shè)置為當(dāng)前的著色器程序
- (GLProgram *)programForVertexShaderString:(NSString *)vertexShaderString fragmentShaderString:(NSString *)fragmentShaderString; // 新建或從緩存中獲取著色器程序
// 緩存相關(guān)
@property(readonly) CVOpenGLESTextureCacheRef coreVideoTextureCache;
@property(readonly) GPUImageFramebufferCache *framebufferCache;
+ (GPUImageFramebufferCache *)sharedFramebufferCache;
// 獲取硬件支持信息
+ (GLint)maximumTextureSizeForThisDevice;
+ (GLint)maximumTextureUnitsForThisDevice;
+ (GLint)maximumVaryingVectorsForThisDevice;
+ (BOOL)deviceSupportsOpenGLESExtension:(NSString *)extension;
+ (BOOL)deviceSupportsRedTextures;
+ (BOOL)deviceSupportsFramebufferReads;
+ (BOOL)supportsFastTextureUpload;
// 適應(yīng)設(shè)備支持的最大尺寸
+ (CGSize)sizeThatFitsWithinATextureForSize:(CGSize)inputSize;
// 展示當(dāng)前已渲染的buffer
- (void)presentBufferForDisplay;