GPUImageContext 是GPUImage封装的一个的上下文对象,主要是有EAGLContext、GLProgram、GPUImageFramebufferCache等对象。
#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;
//framebuffer缓存
@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; //判断该设备是否支持某种OpenGL ES的字符串扩展
+ (BOOL)deviceSupportsRedTextures;//判断本设备是否支持红色的纹理(估计是以前旧机器有不支持的,然后就把红色去掉)
+ (BOOL)deviceSupportsFramebufferReads;
+ (CGSize)sizeThatFitsWithinATextureForSize:(CGSize)inputSize;
// 将渲染缓存呈现在设备上
- (void)presentBufferForDisplay;
// 创建GLProgram,首先在缓存中查找,如果没有则创建
- (GLProgram *)programForVertexShaderString:(NSString *)vertexShaderString fragmentShaderString:(NSString *)fragmentShaderString;
- (void)useSharegroup:(EAGLSharegroup *)sharegroup;
// Manage fast texture upload
+ (BOOL)supportsFastTextureUpload;
@end
//GPUImageInput协议的定义
@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




在这个方法里可以知道,GPUimageContext其实是一个单例

如果OpenGL ES的上下文不是本单例的上下文,则切换至本单例的上下文

调整纹理大小,保证纹理不超过OpenGLES支持最大的尺寸

获取手机(手机里的OpenGL ES接口)当前支持的最大纹理尺寸

网友评论