美文网首页
GPUImageFilter.h源码详解

GPUImageFilter.h源码详解

作者: 孙健会员 | 来源:发表于2016-09-05 10:12 被阅读402次
    #import "GPUImageOutput.h"
    //宏定义
    #define STRINGIZE(x) #x
    #define STRINGIZE2(x) STRINGIZE(x)
    #define SHADER_STRING(text) @ STRINGIZE2(text)
    
    #define GPUImageHashIdentifier #
    #define GPUImageWrappedLabel(x) x
    #define GPUImageEscapedHashIdentifier(a) GPUImageWrappedLabel(GPUImageHashIdentifier)a
    
    extern NSString *const kGPUImageVertexShaderString;//顶点着色器
    extern NSString *const kGPUImagePassthroughFragmentShaderString;//片段着色器
    
    struct GPUVector4 {//4维坐标
        GLfloat one;
        GLfloat two;
        GLfloat three;
        GLfloat four;
    };
    
    typedef struct GPUVector4 GPUVector4;
    
    struct GPUVector3 {//3维坐标系
        GLfloat one;
        GLfloat two;
        GLfloat three;
    };
    typedef struct GPUVector3 GPUVector3;
    
    struct GPUMatrix4x4 {//4x4矩阵
        GPUVector4 one;
        GPUVector4 two;
        GPUVector4 three;
        GPUVector4 four;
    };
    typedef struct GPUMatrix4x4 GPUMatrix4x4;
    
    struct GPUMatrix3x3 {{//3x3矩阵
        GPUVector3 one;
        GPUVector3 two;
        GPUVector3 three;
    };
    typedef struct GPUMatrix3x3 GPUMatrix3x3;
    
    /** GPUImage's base filter class
    GPUImage的滤镜的基类
     
     Filters and other subsequent elements in the chain conform to the GPUImageInput protocol, which lets them take in the supplied or processed texture from the previous link in the chain and do something with it. Objects one step further down the chain are considered targets, and processing can be branched by adding multiple targets to a single output or filter.
    作用:
    1.都遵守GPUImageInput的协议
    2.获得响应链上游的纹理,经过自己的处理,生成新的纹理,向响应链的下一个对象传递
     */
    
    @interface GPUImageFilter : GPUImageOutput <GPUImageInput>
    {
        GPUImageFramebuffer *firstInputFramebuffer;//输入帧缓存
        
        GLProgram *filterProgram;//openGL源程序
        GLint filterPositionAttribute, filterTextureCoordinateAttribute;//顶点属性、纹理属性
        GLint filterInputTextureUniform;//输入纹理常量
        GLfloat backgroundColorRed, backgroundColorGreen, backgroundColorBlue, backgroundColorAlpha;//r  g  b  a
        
        BOOL isEndProcessing;//是否处理完成
    
        CGSize currentFilterSize;//当前滤镜的尺寸
        GPUImageRotationMode inputRotation;//旋转模式
        
        BOOL currentlyReceivingMonochromeInput;//是否接受黑白输入
        
        NSMutableDictionary *uniformStateRestorationBlocks;//
        dispatch_semaphore_t imageCaptureSemaphore;//信号量
    }
    
    @property(readonly) CVPixelBufferRef renderTarget;//像素对象
    @property(readwrite, nonatomic) BOOL preventRendering;//是否方式渲染
    @property(readwrite, nonatomic) BOOL currentlyReceivingMonochromeInput;//是否接受黑白输入
    
    - (id)initWithVertexShaderFromString:(NSString *)vertexShaderString fragmentShaderFromString:(NSString *)fragmentShaderString;// init
    - (id)initWithFragmentShaderFromString:(NSString *)fragmentShaderString;// init
    - (id)initWithFragmentShaderFromFile:(NSString *)fragmentShaderFilename;// init
    - (void)initializeAttributes;// init属性
    - (void)setupFilterForSize:(CGSize)filterFrameSize;//设置滤镜尺寸
    - (CGSize)rotatedSize:(CGSize)sizeToRotate forIndex:(NSInteger)textureIndex;//旋转尺寸
    - (CGPoint)rotatedPoint:(CGPoint)pointToRotate forRotation:(GPUImageRotationMode)rotation;//旋转顶点
    - (CGSize)sizeOfFBO;//帧缓存大小
    + (const GLfloat *)textureCoordinatesForRotation:(GPUImageRotationMode)rotationMode;//纹理旋转
    - (void)renderToTextureWithVertices:(const GLfloat *)vertices textureCoordinates:(const GLfloat *)textureCoordinates;//根据顶点和纹理渲染
    - (void)informTargetsAboutNewFrameAtTime:(CMTime)frameTime;//通知响应链下游的对象
    - (CGSize)outputFrameSize;//输出
    /// 一些列set方法
    - (void)setBackgroundColorRed:(GLfloat)redComponent green:(GLfloat)greenComponent blue:(GLfloat)blueComponent alpha:(GLfloat)alphaComponent;
    - (void)setInteger:(GLint)newInteger forUniformName:(NSString *)uniformName;
    - (void)setFloat:(GLfloat)newFloat forUniformName:(NSString *)uniformName;
    - (void)setSize:(CGSize)newSize forUniformName:(NSString *)uniformName;
    - (void)setPoint:(CGPoint)newPoint forUniformName:(NSString *)uniformName;
    - (void)setFloatVec3:(GPUVector3)newVec3 forUniformName:(NSString *)uniformName;
    - (void)setFloatVec4:(GPUVector4)newVec4 forUniform:(NSString *)uniformName;
    - (void)setFloatArray:(GLfloat *)array length:(GLsizei)count forUniform:(NSString*)uniformName;
    
    - (void)setMatrix3f:(GPUMatrix3x3)matrix forUniform:(GLint)uniform program:(GLProgram *)shaderProgram;
    - (void)setMatrix4f:(GPUMatrix4x4)matrix forUniform:(GLint)uniform program:(GLProgram *)shaderProgram;
    - (void)setFloat:(GLfloat)floatValue forUniform:(GLint)uniform program:(GLProgram *)shaderProgram;
    - (void)setPoint:(CGPoint)pointValue forUniform:(GLint)uniform program:(GLProgram *)shaderProgram;
    - (void)setSize:(CGSize)sizeValue forUniform:(GLint)uniform program:(GLProgram *)shaderProgram;
    - (void)setVec3:(GPUVector3)vectorValue forUniform:(GLint)uniform program:(GLProgram *)shaderProgram;
    - (void)setVec4:(GPUVector4)vectorValue forUniform:(GLint)uniform program:(GLProgram *)shaderProgram;
    - (void)setFloatArray:(GLfloat *)arrayValue length:(GLsizei)arrayLength forUniform:(GLint)uniform program:(GLProgram *)shaderProgram;
    - (void)setInteger:(GLint)intValue forUniform:(GLint)uniform program:(GLProgram *)shaderProgram;
    
    - (void)setAndExecuteUniformStateCallbackAtIndex:(GLint)uniform forProgram:(GLProgram *)shaderProgram toBlock:(dispatch_block_t)uniformStateBlock;
    - (void)setUniformsForProgramAtIndex:(NSUInteger)programIndex;
    
    @end
    

    相关文章

      网友评论

          本文标题:GPUImageFilter.h源码详解

          本文链接:https://www.haomeiwen.com/subject/jmokettx.html