Question

I have a GPUImageView object connected to video camera. When i add subview to it. Subview appears for millisecond and then disappears. I think it is redraw by next video frame !

I searched on web without result! And then i looked at GPUImageView inheritance:

GPUImageView on mac inherits from NSOpenGLView, so i look for how to add subview on NSOpenGLView. Apple provide example how to do this, it is called LayerBackedOpenGLView here is link : https://developer.apple.com/library/mac/samplecode/LayerBackedOpenGLView/Introduction/Intro.html.

They use : [openGLView setWantsLayer:YES]; and this make subview apear but on GPUImageView (video stream from camera) disapears and becomes with some mess.

Apple mention that :

Enabling the "wantsLayer" property of an NSOpenGLView activates layer-backed rendering of the OpenGL view. The layer-backed rendering mode uses its own NSOpenGLContext, which is distinct from the NSOpenGLContext that the view uses for drawing in non-layer-backed mode. AppKit, working in concert with CoreAnimation, automatically creates this context and assigns it to the view.

I am newbie on Mac, and don't know OpenGL, so maybe i am doing something wrong or missed something. I need a way to add subview on GPUImageView.

My question is: How can i add subview on GPUImageView object (on MAC) with condition that :

  • Subview must be visible
  • Content must be displayed too. (in my case video stream displayed on GPUImageView)
Was it helpful?

Solution

Adding a layer is not the same as adding a subview. If you want to display something on top of the GPUImageView, then you will need to add a layer to the GPUImageView with the method -addSublayer (called on the original layer of the GPUImageView), then draw the additional content to this layer.

In order to display a video feed, you can use the pre-cooked AVCaptureVidoPreviewLayer if your video is coming from an AVCapture.

An alternative solution would be to have both your video feed and your GPUImageView belong to the same superview, then handle the layout of both views in the superview.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top