GLImageProcessing Multiple Filters?

后端 未结 2 1440
鱼传尺愫
鱼传尺愫 2020-12-17 05:06

I have read through this question here: Can example "GLImageProcessing" work with multi filters However, I still do not understand how to edit the sample code fo

2条回答
  •  抹茶落季
    2020-12-17 05:54

    You can extend this scheme by alternating between two buffers:

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

提交回复
热议问题