我可以使opengl扩展指针全球吗? [英] Can I make opengl extension pointers global?

查看:170
本文介绍了我可以使opengl扩展指针全球吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用opengl / windows 10 / visual c ++ 2015



我在我的程序中有一个Window类,创建并维护一个win32屏幕窗口, 'opengl上下文。作为这样做的一部分,它获得指向很多opengl'扩展'函数的指针。



我的问题是我可以存储这些扩展指针全局/ class static或者我需要为每个实例或窗口保留一个副本,因为它们会有不同的opengl上下文?

解决方案

div>


指针是否有效,并且对于我创建的每个opengl上下文都是一样的,或者我需要为每个创建的窗口重复一遍吗?


这取决于操作系统和所使用的窗口系统。 WGL规范说,OpenGL允许扩展函数指针对于每个OpenGL上下文是不同的:


wglGetProcAddress()



...



备注 b

OpenGL库支持其函数的多个实现。
在一个渲染上下文中支持的扩展函数不是在单独的渲染上下文中必须可用的
。因此,对于在应用程序中给予渲染上下文的
,只使用由wglGetProcAddress函数返回的函数地址


X11 / GLX指定(第35页,第3.3.12节),无论上下文如何,OpenGL扩展函数指针都是不变的(即不改变):


GL函数指针返回 glXGetProcAddress 独立于当前绑定的上下文,可以由任何支持扩展的上下文使用。


在Windows的情况下,最可行的方法是在上下文句柄和包含所有函数指针的结构之间有一个映射,即

  struct glfunctions {
/ *所有函数指针* /
};
std :: map< HGLRC,glfunctions> context_glfunctions;

您可以随意向地图添加某种形式的LRU,不得不经过整个地图。


Using opengl/windows 10/visual c++ 2015

I have a 'Window' class in my program which creates and maintains a win32 screen window including making a 'modern' opengl context on it. As part of doing this it obtains pointers to lots of opengl 'extension' functions.

My question is can I store those extension pointers globally/class static or do I need to keep a copy for every instance or Window as they'll have different opengl contexts? Are the pointers valid and the same for every opengl context I create or do I need to do it over and over again for every window I create?

解决方案

Are the pointers valid and the same for every opengl context I create or do I need to do it over and over again for every window I create?

That depends on the operating system and the windowing system used. The WGL specification says, that OpenGL extension function pointers are permitted to be different for each OpenGL context:

wglGetProcAddress():

...

Remarks

The OpenGL library supports multiple implementations of its functions. Extension functions supported in one rendering context are not necessarily available in a separate rendering context. Thus, for a given rendering context in an application, use the function addresses returned by the wglGetProcAddress function only.

In contrast to that X11/GLX specifies (page 35, section 3.3.12) that OpenGL extension function pointers are invariant (i.e. don't change) regardless of the context:

GL function pointers returned by glXGetProcAddress are independent of the currently bound context and may be used by any context which supports the extension.

In case of Windows the most viable approach would be to have a map between context handle and a structure holding all the function pointers, i.e.

struct glfunctions {
    /* all the function pointers */
};
std::map<HGLRC,glfunctions> context_glfunctions;

Feel free to add some form of LRU to the map, so that repeated lookups of the context don't have to go through the whole map.

这篇关于我可以使opengl扩展指针全球吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆