Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/38.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 如何处理多个过滤器?_Iphone_Opengl Es_Filter - Fatal编程技术网

Iphone 如何处理多个过滤器?

Iphone 如何处理多个过滤器?,iphone,opengl-es,filter,Iphone,Opengl Es,Filter,我在这里通读了这个问题:但是,我仍然不理解如何编辑GLImageProcessing的示例代码以支持多个过滤器。下面是我现在在Imaging.c的drawGL中所做的代码 有什么帮助吗 void drawGL(int wide, int high, float val, int mode) { GLuint ResultFBO; GLuint ResultTexture; static int prevmode = -1; typedef void (*procf

我在这里通读了这个问题:但是,我仍然不理解如何编辑GLImageProcessing的示例代码以支持多个过滤器。下面是我现在在Imaging.c的drawGL中所做的代码

有什么帮助吗

void drawGL(int wide, int high, float val, int mode)
{
    GLuint ResultFBO;
    GLuint ResultTexture;
    static int prevmode = -1;
    typedef void (*procfunc)(V2fT2f *, float);

    typedef struct {
        procfunc func;
        procfunc degen;
    } Filter;

    const Filter filter[] = {
        { brightness             },
        { contrast               },
        { extrapolate, greyscale },
        { hue                    },
        { extrapolate, blur      }, // The blur could be exaggerated by downsampling to half size
    };
#define NUM_FILTERS (sizeof(filter)/sizeof(filter[0]))
    rt_assert(mode < NUM_FILTERS);


    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glOrthof(0, wide, 0, high, -1, 1);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    glScalef(wide, high, 1);

    glBindTexture(GL_TEXTURE_2D, Input.texID);

    // Remember the FBO being used for the display framebuffer
    glGetIntegerv(GL_FRAMEBUFFER_BINDING_OES, (GLint *)&SystemFBO);

    // Create the texture and the FBO the will hold the result of applying the first filter
    glGenTextures(1, &ResultTexture);
    glBindTexture(GL_TEXTURE_2D, ResultTexture);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, wide, high, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
    glGenFramebuffersOES(1, &ResultFBO);
    glBindFramebufferOES(GL_FRAMEBUFFER_OES, ResultFBO);
    glFramebufferTexture2DOES(GL_FRAMEBUFFER_OES, GL_COLOR_ATTACHMENT0_OES, GL_TEXTURE_2D, ResultTexture, 0);

    // bind the result FBO
    glBindFramebufferOES(GL_FRAMEBUFFER_OES, ResultFBO);


    // apply 1st filter
    glViewport(0, 0, wide, high);
    filter[mode].func(flipquad, val);

    // restore original frame buffer object
    glBindFramebufferOES(GL_FRAMEBUFFER_OES, SystemFBO);

    // use ResultTexture as input for the 2nd filter
    glBindTexture(GL_TEXTURE_2D, ResultTexture);

    // apply 2nd filter
    glViewport(0, 0, wide, high);
    filter[2].func(flipquad, val);

    glCheckError();
}
void drawGL(整数宽、整数高、浮点值、整数模式)
{
胶合结果;
胶凝材料;
静态模式=-1;
类型定义无效(*PROCFNC)(V2fT2f*,浮动);
类型定义结构{
procfunc-func;
procfunc-degen;
}过滤器;
常量过滤器[]={
{亮度},
{对比},
{外推,灰度},
{hue},
{extraction,blur},//通过将采样减小到一半大小,可以放大模糊
};
#定义NUM_过滤器(sizeof(过滤器)/sizeof(过滤器[0]))
rt_断言(模式
您可以通过交替使用两个缓冲区来扩展此方案:

GLuint stageTextures[2];
glGenTextures(2, stageTextures);

glBindTexture(GL_TEXTURE_2D, stageTexture[0]);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, wide, high, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);

glBindTexture(GL_TEXTURE_2D, stageTexture[1]);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, wide, high, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);

GLuint stageFBO[2];
glGenFramebuffersOES(2, stageFB0);

glBindFramebufferOES(GL_FRAMEBUFFER_OES, stageFBO[0]);
glFramebufferTexture2DOES(GL_FRAMEBUFFER_OES, GL_COLOR_ATTACHMENT0_OES, GL_TEXTURE_2D, stageTexture[0], 0);    

glBindFramebufferOES(GL_FRAMEBUFFER_OES, stageFBO[1]);
glFramebufferTexture2DOES(GL_FRAMEBUFFER_OES, GL_COLOR_ATTACHMENT0_OES, GL_TEXTURE_2D, stageTexture[1], 0);    

// bind stage 1, sourcing stage 0
glBindFramebufferOES(GL_FRAMEBUFFER_OES, stageFBO[1]);
glBindTexture(GL_TEXTURE_2D, stageTexture[0]);

// apply 1st filter
glViewport(0, 0, wide, high);
filter[mode].func(flipquad, val);

glBindTexture(GL_TEXTURE_2D, 0); // must unbind texture before FBO with that texture attached can be bound


// bind stage 0, sourcing stage 1
glBindFramebufferOES(GL_FRAMEBUFFER_OES, stageFBO[0]);
glBindTexture(GL_TEXTURE_2D, stageTexture[1]);

// apply 2nd filter
glViewport(0, 0, wide, high);
filter[mode].func(flipquad, val);

glBindTexture(GL_TEXTURE_2D, 0); // must unbind texture before FBO with that texture attached can be bound

// bind stage 1, sourcing stage 0
glBindFramebufferOES(GL_FRAMEBUFFER_OES, stageFBO[1]);
glBindTexture(GL_TEXTURE_2D, stageTexture[0]);

// apply 3rd filter
glViewport(0, 0, wide, high);
filter[mode].func(flipquad, val);

glBindTexture(GL_TEXTURE_2D, 0); // must unbind texture before FBO with that texture attached can be bound

// and so on. finally

// Bind SystemFBO so the screen is the target, sourcing stage 0/1
// (depending on if a even or odd number of filters involved)
glBindFramebufferOES(GL_FRAMEBUFFER_OES, SystemFBO);
glBindTexture(GL_TEXTURE_2D, stageTexture[...]); // set to follow the scheme above

// apply n-th filter
glViewport(0, 0, wide, high);
filter[mode].func(flipquad, val);

我能够组合多个过滤器,这里是基于这里提出的建议的完整方法

void drawGL(int wide, int high, float val, int mode)
{

    static int prevmode = -1;
    typedef void (*procfunc)(V2fT2f *, float);

    typedef struct {
            procfunc func;
            procfunc degen;
    } Filter;

    const Filter filter[] = {
            { brightness             },
            { contrast               },
            { extrapolate, greyscale },
            { hue                    },
            { extrapolate, blur      },        // The blur could be exaggerated by downsampling to half size
    };
    #define NUM_FILTERS (sizeof(filter)/sizeof(filter[0]))
    rt_assert(mode < NUM_FILTERS);

    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glOrthof(0, wide, 0, high, -1, 1);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    glScalef(wide, high, 1);

glGetIntegerv(GL_FRAMEBUFFER_BINDING_OES, (GLint *)&SystemFBO);
// Create the texture and the FBO the will hold the result of applying the first filter
glGenTextures(1, &ResultTexture.texID);
glBindTexture(GL_TEXTURE_2D, ResultTexture.texID);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, wide, high, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
glGenFramebuffersOES(1, &ResultTextureFBO);
glBindFramebufferOES(GL_FRAMEBUFFER_OES, ResultTextureFBO);
glFramebufferTexture2DOES(GL_FRAMEBUFFER_OES, GL_COLOR_ATTACHMENT0_OES, GL_TEXTURE_2D, ResultTexture.texID, 0);

glBindFramebufferOES(GL_FRAMEBUFFER_OES, ResultTextureFBO);
glBindTexture(GL_TEXTURE_2D, Input.texID);

    glViewport(0, 0, wide, high);
brightness(flipquad, val);
    glCheckError();

glBindFramebufferOES(GL_FRAMEBUFFER_OES, SystemFBO);
glBindTexture(GL_TEXTURE_2D, ResultTexture.texID);

    glViewport(0, 0, wide, high);
hue(fullquad, val);
    glCheckError();    
}
void drawGL(整数宽、整数高、浮点值、整数模式)
{
静态模式=-1;
类型定义无效(*PROCFNC)(V2fT2f*,浮动);
类型定义结构{
procfunc-func;
procfunc-degen;
}过滤器;
常量过滤器[]={
{亮度},
{对比},
{外推,灰度},
{hue},
{extraction,blur},//通过将采样减小到一半大小,可以放大模糊
};
#定义NUM_过滤器(sizeof(过滤器)/sizeof(过滤器[0]))
rt_断言(模式
那么,这究竟会走向何方?我用你的代码替换了从“//记住FBO被用于显示帧缓冲区”开始的所有内容,但仍然不走运。在最后一步中,你必须绘制到屏幕,而不是帧缓冲区。我编辑了那个代码示例。@Flipper:我能想到很多事情。事实上,你可以看到一些东西,这意味着,过滤器链,因为它是,正在工作。现在您可能遇到了一些不幸的过滤器组合和排序。因为我手头既没有iOS设备也没有模拟器,所以很难复制。@Flipper:我真的不知道。这些代码片段也不包含实际的过滤器代码,它们只是引用了一些函数。如果您也添加了这些代码,或者至少提供了一个URL,我可以从中获得您调整后的原始代码,那将是一件好事。然后我可以将其移植到基于PC的OpenGL,并在此基础上进行测试。@Flipper:原始代码使用辅助辅助纹理,而这些纹理在您的代码段中不可见。这改变了要采取的整个方法!给我一些时间把这个程序移植到我的系统中,并修改它。