结合Cocos2d和GLKView来渲染相同的数据 [英] Combining Cocos2d and GLKView to render the same data

查看:361
本文介绍了结合Cocos2d和GLKView来渲染相同的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用cocos2d引擎来渲染一些动画到CCGLView,它放在常规UIViews旁边的应用程序主窗口。我的应用程序使用外部屏幕,我想在该屏幕上渲染与CCGLView完全相同的内容,但没有任何其他意见。我需要以有效的方式执行此操作,所以截取CCGLView不是一个选项。

I use cocos2d engine to render some animation to CCGLView which is placed on app main window next to regular UIViews. My application uses external screen and I would like to render on that screen exactly the same content as in CCGLView but without any other views. And I need to perform this operation in an efficient manner so taking screenshots of CCGLView is not an option.

根据我的理解,没有这样的选项使用cocos2d,因为它支持只提供一个场景(CCDirector时间只更新一个CCGLView)。

As I understand there is no such option using cocos2d as It supports presenting only one scene at time (CCDirector updates only one CCGLView at time).

所以我的问题是:

是否可以使用GLKView实现这个目标?我从CCGLView访问帧缓冲区对象,我可以从缓冲区中读取像素。我认为最好的选择是使用cocos2d runloop,并在常规cocos2d渲染旁边执行此操作。不幸的是我不知道openGLES太多,我不知道如何可以实现这一点。 cocos2d使用openGLES 2.0。

Is it possible to achieve this goal using GLKView? I have access to frame buffer object from CCGLView and I can read pixels from the buffer. I think that the best option would be to use cocos2d runloop and perform this operation next to regular cocos2d rendering. Unfortunately I don't know too much about openGLES and I don't know how I can achieve this. cocos2d uses openGLES 2.0.

编辑:

现在唯一的建议来自@ s1ddok CCRenderTexture绘制到CCGLView放置在主窗口,并使用CCRenderTexture的数据呈现到外部窗口。但我仍然不明白我如何能够第二次渲染纹理 - 这一次到另一个视图。使用另一个CCGLView将需要将此视图配置为CCDirector的目标,我该如何做?此外,第二个CCGLView将共享EAGLContext与第一个...所以如何强制cocos2d渲染到第二个CCGLView?任何帮助是赞赏!

For now the only suggestion came from @s1ddok (thanks) and the idea is to use CCRenderTexture to draw into CCGLView placed on main window and use CCRenderTexture's data to render to the external window. But I still don't understand how I can render the texture for the second time - this time to another view. Using another CCGLView would require configuring this view as a target for CCDirector, how can I do that? Moreover second CCGLView will share EAGLContext with the first one... So how to force cocos2d to render to the second CCGLView? Any help is appreciated!

推荐答案

我猜你最好的方式是CCRenderTexture。渲染整个场景,然后在外部屏幕上显示数据。

I guess the best way you can go is CCRenderTexture. Render the whole scene onto it and then display the data on external screen.

这是多种用途的常见做法,例如,如果您需要将着色器应用于整个场景或某物。

It is a common practice for multiple purposes, for example, if you need to apply shader to a whole scene or something.

这实际上将允许您每帧渲染场景,然后对UIKit和外部屏幕使用相同的数据。

This actually will allow you to render scene only once every frame, and then use the same data for UIKit and external screen.

这篇关于结合Cocos2d和GLKView来渲染相同的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆