#include "glextensions.hpp" #include namespace SceneUtil { namespace { std::set> sGLExtensions; class GLExtensionsObserver : public osg::Observer { public: static GLExtensionsObserver sInstance; ~GLExtensionsObserver() override { for (auto& ptr : sGLExtensions) { osg::ref_ptr ref; if (ptr.lock(ref)) ref->removeObserver(this); } } void objectDeleted(void* referenced) override { sGLExtensions.erase(static_cast(referenced)); } }; // construct after sGLExtensions so this gets destroyed first. GLExtensionsObserver GLExtensionsObserver::sInstance{}; } bool glExtensionsReady() { return !sGLExtensions.empty(); } osg::GLExtensions& getGLExtensions() { 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.begin(); } GetGLExtensionsOperation::GetGLExtensionsOperation() : GraphicsOperation("GetGLExtensionsOperation", false) { } void GetGLExtensionsOperation::operator()(osg::GraphicsContext* graphicsContext) { auto [itr, _] = sGLExtensions.emplace(graphicsContext->getState()->get()); (*itr)->addObserver(&GLExtensionsObserver::sInstance); } }