Ios 应用多个滤波器的图像处理
我一直在努力使Apple GLImageProcessing示例同时使用两个过滤器 注意:我知道这一点在这里已经被弃用了:这里: 目前,我被另一个问题困住了:Ios 应用多个滤波器的图像处理,ios,image-processing,opengl-es,filter,Ios,Image Processing,Opengl Es,Filter,我一直在努力使Apple GLImageProcessing示例同时使用两个过滤器 注意:我知道这一点在这里已经被弃用了:这里: 目前,我被另一个问题困住了: // Remember the FBO being used for the display framebuffer glGetIntegerv(GL_FRAMEBUFFER_BINDING_OES, (GLint *)&SystemFBO); // Create the texture and the FBO the will
// 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();
}
void drawGL(整数宽、整数高、浮点值、整数模式)
{
静态模式=-1;
类型定义无效(*PROCFNC)(V2fT2f*,浮动);
类型定义结构{
procfunc-func;
procfunc-degen;
}过滤器;
常量过滤器[]={
{亮度},
{对比},
{外推,灰度},
{hue},
{extraction,blur},//通过将采样减小到一半大小,可以放大模糊
};
#定义NUM_过滤器(sizeof(过滤器)/sizeof(过滤器[0]))
rt_断言(模式
阿伦在你的第一个链接问题中的回答是否有效?他似乎已经完成了两个链式过滤器的实现。@BradLarson使用他的代码,我得到了这个编译错误;使用未声明的标识符'ResultTexture'。我不知道这个ResultTexture和ResultTextRefBo是在哪里/如何设置的。我让它工作了——我只需要设置两个Gluint。请随意将您的评论作为答案发布,我会将其标记为已回答;我在10-15秒后收到内存警告,应用程序崩溃。@JakobHalskov-你能解释一下你是怎么解决问题的吗?我和你有同样的问题。非常感谢。