英文:
Do I need to load functions for every opengl context separately?
问题
我正在尝试在Windows上使用glad加载OpenGL函数。不久我发现我需要一个有效的OpenGL上下文来加载函数。一切都正常,但我不太确定每次创建窗口时加载OpenGL函数是否是一个好主意。
这些函数是否在多个OpenGL上下文之间共享,还是我需要为每个创建的上下文加载它们?
英文:
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?
答案1
得分: 3
函数加载时的语义在不同环境下有所不同:
-
WGL(= Win32):函数指针与上下文绑定,因此您必须管理每个上下文的一组函数并相应地使用它们。
-
GLX(= X11):函数指针在不同上下文之间是通用的,内部进行实现的分派。
-
macOS:函数指针是通用的,但少数动态加载的函数是特定于苹果的,并且很少使用,因此这不是一个问题。
英文:
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
答案2
得分: 2
你需要一个有效的OpenGL上下文才能建立与驱动程序的连接。只要两个上下文使用相同的驱动程序,一切都应该没问题,因为函数只是该驱动程序的DLL的入口点。
现在,如果你使用不同的驱动程序创建了两个上下文,可能会出现问题。例如,如果你有两张不同厂商的显卡,就可能发生这种情况。每个上下文都需要从相应的驱动程序中加载函数。
英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论