0

I am writing a program using an API that needs to get an OpenGL low-level context, but I am unable to understand when does the function CGLGetCurrentContext should return a value (an integer representing the context), and when it shouldn't.

Right now, the function CGLGetCurrentContext() is returning NULL, and this is breaking my program. How can I fix this?

What is the purpose of this function? How are OpenGL contexts modeled?

GBF_Gabriel
  • 2,636
  • 2
  • 17
  • 15
  • 1
    From: http://mirror.informatimago.com/next/developer.apple.com/documentation/GraphicsImaging/Conceptual/OpenGL/chap5/chapter_5_section_16.html the function returns a _pointer_ [that is opaque], and _not_ an integer. Are you ever _setting_ the context? See also: http://mirror.informatimago.com/next/developer.apple.com/documentation/GraphicsImaging/Conceptual/OpenGL/chap5/chapter_5_section_37.html#//apple_ref/doc/c_ref/CGLContextObj From https://cpp.hotexamples.com/examples/-/-/CGLGetCurrentContext/cpp-cglgetcurrentcontext-function-examples.html it seems that it may be somewhat apple specific – Craig Estey Apr 04 '20 at 02:35

1 Answers1

1

OpenGL has a conception of an active rendering context bound to the working thread. So that you may consider CGLGetCurrentContext() as returning some thread-local variable. It is expected to return some value if:

  • Some code created an OpenGL context.
  • Some code activated OpenGL context within current working thread.
  • You call CGLGetCurrentContext() within the same working thread, and the code before didn't deactivated it.

As you have not specified details of your code, I may consider that OpenGL is managed by code not written by you, which makes it difficult to suggest why CGLGetCurrentContext() might be NULL.

I may only say that my macOS application uses CGLGetCurrentContext() and it works as expected.

gkv311
  • 2,612
  • 1
  • 10
  • 11
  • I understand I asked a question too vague, I thought I just wasn't finding any documentation explaining how the context works, but it turns out there isn't any extensive documentation for this. I'll create a follow-up question focusing on my specific problem. – GBF_Gabriel Apr 04 '20 at 19:49
  • Follow-up question posted: https://stackoverflow.com/questions/61035830/how-to-create-an-opengl-context-on-an-nodejs-native-addon-on-macos – GBF_Gabriel Apr 04 '20 at 22:57