核心图像与GLKView

时间:2014-03-01 02:54:04

标签: ios objective-c opengl-es core-image glkview

我很难找到如何正确使用核心图像GLKView的任何示例,以便根据用户输入顺利渲染核心图像“食谱”。因此,在阅读Core Image Programming GuideGLKView class reference之后,我想出了一种有效的方法。但是,我不确定它是否有效,所以我希望有人可以确认它没问题,或者指出我的方向更好。

现在,我正在使用GLKViewGLKViewControllerGLKView委托绘制到其父视图控制器,该控制器实现glkView:drawInRect:。绘图方法执行此操作:

- (void)glkView:(GLKView *)view drawInRect:(CGRect)rect {
    // make glkView's background light gray instead of black
    glClearColor(backgroundRGB, backgroundRGB, backgroundRGB, 1.0);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    // a custom object that holds a reference to a CIContext
    ImageEditingContext* context = [ImageEditingContext getInstance];

    // apply a core image recipe
    CIImage *outputImage = [context getFilteredPreviewCIImage];

    // draw the image
    CGRect inRect = outputImage.extent;
    inRect.origin.y = (self.glkView.contentScaleFactor * self.glkView.frame.size.height - inRect.size.height) / 2.0;
    [context.coreImageContext drawImage:outputImage inRect:inRect fromRect:outputImage.extent];
}

具体来说,我关注最后一行[context.coreImageContext drawImage:outputImage inRect:inRect fromRect:outputImage.extent]。从glkView:drawInRect:内调用该方法是否有效?正如我之前提到的,这种方法似乎运行良好,但在运行OpenGL ES分析仪器模板后我开始怀疑它。它标记了这个问题:

  

不使用Flush的多上下文Renderbuffer用法:   Renderbuffer#2 - 您的应用程序使用了一个在不同的上下文中更新的renderbuffer对象,而没有后续的刷新操作。

我的GLKViewCIContext都设置了相同的EAGLContext,因此我不太确定错误消息所指的是什么。非常感谢任何见解!

1 个答案:

答案 0 :(得分:0)

我用glkview成功完成了这项工作。它使用OpenGL感知视图自动设置缓冲区。您根本不需要缓冲区代码,实际上如果正确设置,glkview需要大约3行代码。该应用程序很困惑,因为它会自动为您设置缓冲区,然后您创建第二个应用程序,并且不会为每个帧刷新它,从而导致许多内存问题。看来你也在创建多个上下文,这也是一个不可以。阅读CIImage编程指南。我有一个UISlider,可以使用glkview实时调整图像。您需要做的就是从CIContext初始化glkview,bindDrawable,drawImage。确保使用EaglContext初始化CIContext。你是对的一件事......文件是不存在的。祝好运。

相关问题