Is it possible to put an OpenGL ES rendering view over an UIView, while the UIView shines through like if the OpenGL ES was a PNG with transparency?

▼魔方 西西 提交于 2019-12-08 04:07:34

问题


I have no idea about it, but if that was possible (like Flash, for example), then that would be really cool.

I have an view-based app where I need probably some OpenGL ES capabilities, but don't want to have fullscreen OpenGL ES. I just need it at certain small areas for drawing little charts and other stuff that may be hard to do with core graphics.


回答1:


Yes,

you should be able to implement this through Quartz Core using layers (see the CALayer class documentation). Indeed, you can have layers hierarchies. Basically you associate each UIView to a different layer, then the layers are rendered together providing a single, composite layer. Besides, you can also apply transforms and animations to layers.

You need to import the QuartzCore header and do something like

#import <QuartzCore/QuartzCore.h>
UIView *myView = [[UIView alloc] initWithFrame...
UIView *openGLView = [UIView alloc] initWithFrame...

CaLayer *myViewLayer = myView.layer;
[myViewLayer addSubLayer: openGLView.layer];

Then, when myView appears on the screen, all the sublayers are merged together and rendered on screen. What happens is that each view renders its layer, while myViewLayer is rendered merging together the two layers.

You can have as many layers as you like. You can create an arbitrary hierarchi by using the CALayer methods

– addSublayer: – removeFromSuperlayer
– insertSublayer:atIndex:
– insertSublayer:below:
– insertSublayer:above:
– replaceSublayer:with:




回答2:


Yes, it is possible, but I strongly advise against it.

The Apple Technical Note TN2230: Optimizing OpenGL ES for iPhone OS covers all do's and don'ts.

This Apple documentation covering best practices could help understanding some more do's and don'ts.




回答3:


This "technique" works very well and is quite common, as UIKit is designed just for this kind of thing, it also works the other way as well (OpenGL in the background or foreground or any combination). Just remember to turn off Opaque flag.

But, I am not sure about rendering GL to a CALayer that is actively being animated; it may just not update during its animation. =) Have fun!



来源:https://stackoverflow.com/questions/931564/is-it-possible-to-put-an-opengl-es-rendering-view-over-an-uiview-while-the-uivi

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!