|
|
|
@ -4,16 +4,29 @@ namespace SceneUtil
|
|
|
|
|
{
|
|
|
|
|
namespace
|
|
|
|
|
{
|
|
|
|
|
osg::observer_ptr<osg::GLExtensions> sGLExtensions;
|
|
|
|
|
std::set<osg::observer_ptr<osg::GLExtensions>> sGLExtensions;
|
|
|
|
|
|
|
|
|
|
class GLExtensionsObserver : public osg::Observer
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
static GLExtensionsObserver sInstance;
|
|
|
|
|
|
|
|
|
|
void objectDeleted(void* referenced) override
|
|
|
|
|
{
|
|
|
|
|
sGLExtensions.erase(static_cast<osg::GLExtensions*>(referenced));
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
GLExtensionsObserver GLExtensionsObserver::sInstance{};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
osg::GLExtensions& getGLExtensions()
|
|
|
|
|
{
|
|
|
|
|
if (!sGLExtensions)
|
|
|
|
|
if (sGLExtensions.empty())
|
|
|
|
|
throw std::runtime_error(
|
|
|
|
|
"GetGLExtensionsOperation was not used when the current context was created or there is no current "
|
|
|
|
|
"context");
|
|
|
|
|
return *sGLExtensions;
|
|
|
|
|
return **sGLExtensions.begin();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
GetGLExtensionsOperation::GetGLExtensionsOperation()
|
|
|
|
@ -23,6 +36,7 @@ namespace SceneUtil
|
|
|
|
|
|
|
|
|
|
void GetGLExtensionsOperation::operator()(osg::GraphicsContext* graphicsContext)
|
|
|
|
|
{
|
|
|
|
|
sGLExtensions = graphicsContext->getState()->get<osg::GLExtensions>();
|
|
|
|
|
auto [itr, _] = sGLExtensions.emplace(graphicsContext->getState()->get<osg::GLExtensions>());
|
|
|
|
|
(*itr)->addObserver(&GLExtensionsObserver::sInstance);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|