OpenGLSurface goes black on window deactivate.

Thanks to the work with the Visual Atomicity, I’ve solved all but one of the OpenGLSurface issues that I’m currently experiencing.

All of these issues are due to the fact I’m using Layer-backed Windows, sadly I need to do so in order to solve some weirdness on Yosemite and above, also to be able to use the interface that I want to use.

The problem:
When the document window loses focus the OpenGLContext goes black, when the window re-gains focus the preview is displayed once again.

Current solution:
Is to use a deferred update, this however causes the preview to flicker on deactivate, and be black on re-activate. Once again calling the deferred update fixes this, at the expense of a flicker.

We have to use a deferred update as simply asking the OpenGL to render in the activate/deactivate event doesn’t solve anything.

The flickering is better than a black screen, but it’s amateurish and one thing I want with this product is for it to look and feel rock solid.

I’ve tried disabling double buffering, but it makes the flickering even worse (sadly).

Here’s my current theory, when the window is deactivated the ‘back buffer’ of the OpenGLSurface trades places with the foreground buffer. And it’s swapped back when the window re-activates.

Does anyone know if this is true and if so, do you know of a way to update the back buffer before the window loses focus, without flushing the buffer to the foreground?

One last thing, in the ‘Render’ event, you can return a boolean value. If I return true, the flickering returns and I can find no documentation on what the return value is for.

I’m not sure why it’s happening but putting OpenGLSurface1.Render in both Window.Activate and Deactivate works for me.

I would expect the back buffer to be garbage or the previous drawing. In my testing when the window deactivates the OpenGLSurface disappears and reappears when activated, not black.

On both Activate and Deactivate the OpenGLSurface gets a Render event. With the extra OpenGLSurface1.Render call in those events there’s still only 1 Render event triggered.

Also, if I use a NSOpenGLView created via declares this doesn’t happen. No drawRect events are received when switching activation and the current drawing stays put.

Are you using Layer-Backed Views?

I’m contemplating going down that route, some of the reading I’ve done on the Apple developer forums says that this also has issues on Layer-Backed Views and the recommendation is to use a custom View with a NSOpenGLContext (which is what I presume the OpenGlSurface is).

I run this in Window.Open to set NSFullSizeContentViewWindowMask

[code]declare sub setStyle lib “Cocoa” selector “setStyleMask:” (id As integer, v As UInt32)

setStyle(self.Handle, 15+32768)[/code]

By itself this caused the OpenGLSurface to disappear when deactivated.

That style mask does seem to activate Layer-Backed Views, and so now you can see some one of the issues that arise from using Layer-Backed Views and a OpenGLSurface.

Using NSOpenGLView doesn’t show the problem so maybe it’s something in how OpenGLSurface handles flushing. In particular I find it curious that OpenGLSurface raises a render event when activation switches while NSOpenGLView doesn’t. I don’t know about the recommendation to use NSOpenGLContext though.