GLImageProcessing应用多个过滤器

时间:2011-12-28 21:20:18

标签: ios image-processing opengl-es filter

我一直在努力让Apple GLImageProcessing Example同时使用两个过滤器。

注意:我发现此处已被忽略:GLImageProcessing Multiple Filters?并在此处:Can example "GLImageProcessing" work with multi filters

目前我从其中一个问题中坚持这个问题:

// 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, width, height, 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
...

// 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
...

我的问题是我不知道如何在原来的drawGL()函数中实现它:

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);

    glBindTexture(GL_TEXTURE_2D, Input.texID);

    if (prevmode != mode)
    {
        prevmode = mode;
        if (filter[mode].degen)
        {
            // Cache degenerate image, potentially a different size than the system framebuffer
            glBindFramebufferOES(GL_FRAMEBUFFER_OES, DegenFBO);
            glViewport(0, 0, Degen.wide*Degen.s, Degen.high*Degen.t);
            // The entire framebuffer won't be written to if the image was padded to POT.
            // In this case, clearing is a performance win on TBDR systems.
            glClear(GL_COLOR_BUFFER_BIT);
            glDisable(GL_BLEND);
            filter[mode].degen(fullquad, 1.0);
            glBindFramebufferOES(GL_FRAMEBUFFER_OES, SystemFBO);
        }
    }

    // Render filtered image to system framebuffer
    glViewport(0, 0, wide, high);
    filter[mode].func(flipquad, val);
    glCheckError();
}

0 个答案:

没有答案