GPUImageContext类,提供OpenGL ES基本环境,我们一般不会用到,所以讲的很简单。
属性
@property(readonly, nonatomic) dispatch_queue_t contextQueue
说明:创建一个context线程
描述:_contextQueue = dispatch_queue_create("com.sunsetlakesoftware.GPUImage.openGLESContextQueue", NULL);
@property(readwrite, retain, nonatomic) GLProgram *currentShaderProgram
说明:当前着色器program
@property(readonly, retain, nonatomic) EAGLContext *context
说明:opengl es绘制环境,管理上下文
方法
+ (void *)contextKey
说明:设置当前context的线程标识符,全局静态变量。
+ (GPUImageContext *)sharedImageProcessingContext
说明:创建一个全局的GPUImageContext对象的单例。
+ (dispatch_queue_t)sharedContextQueue
说明:创建一个context queue单例
+ (GPUImageFramebufferCache *)sharedFramebufferCache
说明:创建一个GPUFramebufferCache单例
- (void)useAsCurrentContext
说明:使用当前context
+ (void)setActiveShaderProgram:(GLProgram *)shaderProgram;
- (void)setContextShaderProgram:(GLProgram *)shaderProgram;
+ (GLint)maximumTextureSizeForThisDevice;
+ (GLint)maximumTextureUnitsForThisDevice;
+ (GLint)maximumVaryingVectorsForThisDevice;
+ (BOOL)deviceSupportsOpenGLESExtension:(NSString *)extension;
+ (BOOL)deviceSupportsRedTextures;
+ (BOOL)deviceSupportsFramebufferReads;
+ (CGSize)sizeThatFitsWithinATextureForSize:(CGSize)inputSize;
- (void)presentBufferForDisplay;
- (GLProgram *)programForVertexShaderString:(NSString *)vertexShaderString fragmentShaderString:(NSString *)fragmentShaderString;
- (void)useSharegroup:(EAGLSharegroup *)sharegroup;
+ (BOOL)supportsFastTextureUpload;
完整代码
#import "GLProgram.h" #import "GPUImageFramebuffer.h" #import "GPUImageFramebufferCache.h" #define GPUImageRotationSwapsWidthAndHeight(rotation) ((rotation) == kGPUImageRotateLeft || (rotation) == kGPUImageRotateRight || (rotation) == kGPUImageRotateRightFlipVertical || (rotation) == kGPUImageRotateRightFlipHorizontal) typedef enum { kGPUImageNoRotation, kGPUImageRotateLeft, kGPUImageRotateRight, kGPUImageFlipVertical, kGPUImageFlipHorizonal, kGPUImageRotateRightFlipVertical, kGPUImageRotateRightFlipHorizontal, kGPUImageRotate180 } GPUImageRotationMode; @interface GPUImageContext : NSObject @property(readonly, nonatomic) dispatch_queue_t contextQueue; @property(readwrite, retain, nonatomic) GLProgram *currentShaderProgram; @property(readonly, retain, nonatomic) EAGLContext *context; @property(readonly) CVOpenGLESTextureCacheRef coreVideoTextureCache; @property(readonly) GPUImageFramebufferCache *framebufferCache; + (void *)contextKey; + (GPUImageContext *)sharedImageProcessingContext; + (dispatch_queue_t)sharedContextQueue; + (GPUImageFramebufferCache *)sharedFramebufferCache; + (void)useImageProcessingContext; - (void)useAsCurrentContext; + (void)setActiveShaderProgram:(GLProgram *)shaderProgram; - (void)setContextShaderProgram:(GLProgram *)shaderProgram; + (GLint)maximumTextureSizeForThisDevice; + (GLint)maximumTextureUnitsForThisDevice; + (GLint)maximumVaryingVectorsForThisDevice; + (BOOL)deviceSupportsOpenGLESExtension:(NSString *)extension; + (BOOL)deviceSupportsRedTextures; + (BOOL)deviceSupportsFramebufferReads; + (CGSize)sizeThatFitsWithinATextureForSize:(CGSize)inputSize; - (void)presentBufferForDisplay; - (GLProgram *)programForVertexShaderString:(NSString *)vertexShaderString fragmentShaderString:(NSString *)fragmentShaderString; - (void)useSharegroup:(EAGLSharegroup *)sharegroup; // Manage fast texture upload + (BOOL)supportsFastTextureUpload; @end @protocol GPUImageInput <NSObject> - (void)newFrameReadyAtTime:(CMTime)frameTime atIndex:(NSInteger)textureIndex; - (void)setInputFramebuffer:(GPUImageFramebuffer *)newInputFramebuffer atIndex:(NSInteger)textureIndex; - (NSInteger)nextAvailableTextureIndex; - (void)setInputSize:(CGSize)newSize atIndex:(NSInteger)textureIndex; - (void)setInputRotation:(GPUImageRotationMode)newInputRotation atIndex:(NSInteger)textureIndex; - (CGSize)maximumOutputSize; - (void)endProcessing; - (BOOL)shouldIgnoreUpdatesToThisTarget; - (BOOL)enabled; - (BOOL)wantsMonochromeInput; - (void)setCurrentlyReceivingMonochromeInput:(BOOL)newValue; @end