我可以使opengl扩展指针全球吗

我可以使opengl扩展指针全球吗

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

问题描述

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



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



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

解决方案

div>

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

与,无论上下文如何,OpenGL扩展函数指针都是不变的(即不改变):

在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?

解决方案

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:

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:

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扩展指针全球吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-21 12:27