ios - 带 GLKView 的核心图像

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

我很难找到任何示例来说明如何将 Core Image 与 GLKView 一起正确使用,以便顺畅地呈现 Core Image“配方”以响应用户输入。所以,看完Core Image Programming Guide之后和 GLKView class reference ,我想出了一个可行的方法。但是,我不确定它是否有效,所以我希望有人可以确认它没问题,或者为我指明更好的方向。

现在,我正在使用一个带有 GLKViewControllerGLKViewGLKView 将绘图委托(delegate)给其父 View Controller ,它实现了 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 Analysis Instruments 模板后我开始怀疑它。它用这个问题标记了行:

Multi-context Renderbuffer Usage Without Flush: Renderbuffer #2 - Your application used a renderbuffer object that has been updated in a different context without a subsequent flush operation.

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

最佳答案

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

关于ios - 带 GLKView 的核心图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22109498/

相关文章:

Objective-C、JSON 和对象映射

ios - Ionic cordova 应用程序适用于所有浏览器和 IOS 9,但不再适用于 IOS 8 [无错误地卡住]

ios - 我可以在没有苹果开发者帐户的真实苹果设备上测试我的 Flutter 应用程序吗?如果可以,我该怎么做?

ios - 接收 block 的函数?

ios - iOS 中的 GCM(Google Cloud Messaging)(通知和数据负载。)

onDrawFrame 之外的 Android OpenGL 游戏循环

带有 GLSurfaceView.Renderer 的安卓传感器

javascript - 实现鼠标平滑的最有效方法

ios - Twilio 平台上的回声消除

ios - 将数据从 tableviewcontroller 发送到 detailviewcontroller