4

I am trying to load opengl functions on windows using glad. Soon I figured out that I need to have valid opengl context to load functions. Everything works, but I am not really sure if it's good idea to load opengl functions everytime I create window.

Are these functions shared between multiple opengl contexts or do I need to load them for every context that I create?

genpfault
  • 51,148
  • 11
  • 85
  • 139
Etwus
  • 549
  • 5
  • 15

2 Answers2

3

Semantics on function loading differ between environments:

  • WGL (=Win32): Functions pointers are tied to the context, so you must manage a per-context set of functions and use them accordingly.

  • GLX (=X11): Function pointers are universal between contexts, dispatch to the implementation happens internally.

  • macOS: Function pointers are universal, however the few dynamically loaded functions are specific to Apple and rarely used, so it's a non-issue

datenwolf
  • 159,371
  • 13
  • 185
  • 298
2

You need a valid OpenGL context in order to establish the connection to the driver. As long as both contexts use the same driver, everything should be fine, since functions are just entry points to that driver's DLL.

Now, there can be a problem if you create two contexts with different drivers. This can happen, for example, if you have two graphics cards by different vendors. Each context would need to load the functions from the respective driver.

Yakov Galka
  • 70,775
  • 16
  • 139
  • 220