views:

42

answers:

1

I am trying to check that my NSOpenGLView has a valid context but it seems that a call to openGLContext will not help me figure this out. openGLContext seems to always returns a an NsOpenGlContext (it returns the current context if the view has one and if not it makes a context and returns that). Is there another method I could use instead?

A: 

OpenGL contexts are selected per-thread. NSOpenGLView will tell you which context should be used to draw in the view (ie. which one has had [context setView: view] called on), but not which context is currently selected in the thread that's executing the code. It's a bit like selecting pen/brush to draw with in old Windows.

I understand that you want to know if you can draw in view. To do that, check if current context is the one that NSOpenGLView returns, and if not, set it to be.

To get current OpenGL context for the thread: NSOpenGLContext* context = [NSOpenGLContext currentContext]; To set one as current: [context makeCurrentContext]; To clear current context (ie. set no current context): [NSOpenGLContext clearCurrentContext];

In general, see docs for NSOpenGLContext.

Yaten512