- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我已经在这里阅读了这个问题:Can example "GLImageProcessing" work with multi filters但是,我仍然不明白如何编辑 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();
}
最佳答案
您可以通过在两个缓冲区之间交替来扩展此方案:
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);
关于iphone - GLImageProcessing 多个滤镜?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6425861/
我已经在这里阅读了这个问题:Can example "GLImageProcessing" work with multi filters但是,我仍然不明白如何编辑 GLImageProcessing
我想用上面的代码在我的 ViewController 中显示 EAGLView: [((EAGLView*)self.view) drawView]; 但它因错误而崩溃; [UIView drawVi
我使用示例 GLImageProcessing,但它无法同时处理亮度和对比度的图像,因此我编写了调整亮度和对比度的代码,但它根本不起作用,任何人都可以帮助我解决这个问题,谢谢您的评价 //init g
我目前正在尝试模糊图像的一部分。我使用苹果的示例代码 here 示例代码本身可以模糊整个图像并将其绘制到 EAGLView,我想做的是通过提供 ROI 仅模糊图像的一部分。 我不知道如何为函数提供 R
我正在使用 glImageProcessing来自 Apple 的示例,用于执行一些过滤操作。但是,我希望能够将新图像加载到纹理中。 目前,该示例使用以下行加载图像: loadTexture("Ima
苹果的oplengl GLImageProcessing加载图像并应用图像调整:亮度、饱和度、对比度、色调和清晰度。 如何在 CCSprite 上使用 GLImageProcessing? 如有任何帮
这是 Apple 的示例代码,但在 iPad 模拟器上无法正常工作。我没有我一直在努力让它在 iPad 模拟器上正常工作。图像偏移到大约屏幕的中心,但不完全是。 最佳答案 我发现了问题。当使用“为 i
我重新实现了 Apple 的 GLImageProcessing使用 OpenGL ES 2 着色器。效果是完美的,但锐度过滤器的性能不是很好 — 它仅以 20 FPS 的速度运行。 着色器代码很简单
我是一名优秀的程序员,十分优秀!