如何在 UIView 和 EAGLView 之间进行混合?
我在 EAGLView 层上渲染了一个 opengl 场景,在 UIView 上渲染了一些其他元素(圆圈等)(它是 EAGLView 的同级,位于其上方)。是否可以在两层之间混合颜色?我想做一些差异混合以获得 EAGLView 颜色的反转效果。
我一直在尝试 CGBlendMode,但它似乎只影响我在当前视图中绘制的内容。我认为这与 CGContext 有关,但我对细节有点模糊,我可以强制 UIView 和 EAGLView 具有相同的 CGContext 以便在它们之间进行混合吗?
感谢帮助、更正、澄清。提前致谢, -S
I have an opengl scene rendering on an EAGLView layer and some other elements (circles and such) rendering on a UIView (which is a sibling of the EAGLView, positioned above it). Is it possible to blend colors between the two layers? I'd like to do some difference blending to get an inversion effect on the colors from EAGLView.
I've been playing around with CGBlendMode but it only seems to affect what I'm drawing in that current view. I think this has something to do with the CGContext but I'm a little hazy on the details, can I force the UIView and the EAGLView to have the same CGContext so that the blending works between them?
Help, corrections, clarifications are all appreciated. Thanks in advance,
-S
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
简短的回答是你不能。长答案如下。
EAGLView
指的是 Xcode 中 OpenGL ES 模板中包含的UIView
子类。该类的特殊之处在于,layerClass
类方法被重写并返回CAEAGLLayer
类,而不是默认的CALayer
类。UIView
和CALayer
成对工作。所有UIView
对象都由CALayer
支持,CALayer
是负责布局和渲染到屏幕的对象。UIView
是CALayer
的委托,负责在需要时绘制其图形。CALayer
将让它的委托(UIView
)绘制到CGContextRef
中。每个 UIView 都有一个上下文,因此您不能使用 CGBlendMode 来混合多个视图,因为它只能在一个 UIView 上下文中运行。CALayer
的混合应该使用过滤器属性来完成。这些是为 iPhone 操作系统定义的,但根据文档,可用的过滤器未定义。这是因为 Core Image 目前在 iPhone 操作系统上不可用。Short answer is you can not. Long answer follows.
By
EAGLView
you must mean the subclass ofUIView
that is included in the OpenGL ES Template in Xcode. What makes this class special is that thelayerClass
class method is overridden and return theCAEAGLLayer
class instead of theCALayer
class, as is default.UIView
andCALayer
work in pairs. AllUIView
objects are backed by aCALayer
, theCALayer
is the object responsible for layout and rendering to screen. TheUIView
is a delegate to theCALayer
, and is responsible for drawing it's graphics when needed.CALayer
will let it's delegate (theUIView
) draw into aCGContextRef
. It is one context perUIView
, so you can not useCGBlendMode
to blend several views since it will only function within one single UIView context.Blending of
CALayer
should be done using the filter properties. These are defined for iPhone OS but the available filters are undefined according to the documentation. This is because Core Image is not available on iPhone OS at this time.我不认为你能够在这个意义上混合颜色。你能做的最好的事情就是让一个完全遮挡另一个,或者让顶层半透明(在这种情况下,你会看到下面的部分) - 但你将无法进行 XOR 类型绘图。
I don't think you'll be able to blend colours in that sense. The best you can do is have one completely obscuring the other, or have the top layer semi-transparent (in which case, you'll see the part underneath) - but you won't be able to do XOR type drawing.