mirror of https://github.com/OpenMW/openmw.git
Merge branch 'get-glextensions-properly' into 'master'
Get the GLExtensions instance when a context is created Closes #7351 See merge request OpenMW/openmw!3022fix-osga-rotate-wildly
commit
e340b06411
@ -0,0 +1,60 @@
|
||||
#include "glextensions.hpp"
|
||||
|
||||
#include <osg/GraphicsContext>
|
||||
|
||||
namespace SceneUtil
|
||||
{
|
||||
namespace
|
||||
{
|
||||
std::set<osg::observer_ptr<osg::GLExtensions>> sGLExtensions;
|
||||
|
||||
class GLExtensionsObserver : public osg::Observer
|
||||
{
|
||||
public:
|
||||
static GLExtensionsObserver sInstance;
|
||||
|
||||
~GLExtensionsObserver() override
|
||||
{
|
||||
for (auto& ptr : sGLExtensions)
|
||||
{
|
||||
osg::ref_ptr<osg::GLExtensions> ref;
|
||||
if (ptr.lock(ref))
|
||||
ref->removeObserver(this);
|
||||
}
|
||||
}
|
||||
|
||||
void objectDeleted(void* referenced) override
|
||||
{
|
||||
sGLExtensions.erase(static_cast<osg::GLExtensions*>(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<osg::GLExtensions>());
|
||||
(*itr)->addObserver(&GLExtensionsObserver::sInstance);
|
||||
}
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
#ifndef OPENMW_COMPONENTS_SCENEUTIL_GLEXTENSIONS_H
|
||||
#define OPENMW_COMPONENTS_SCENEUTIL_GLEXTENSIONS_H
|
||||
|
||||
#include <osg/GLExtensions>
|
||||
#include <osg/GraphicsThread>
|
||||
|
||||
namespace SceneUtil
|
||||
{
|
||||
bool glExtensionsReady();
|
||||
osg::GLExtensions& getGLExtensions();
|
||||
|
||||
class GetGLExtensionsOperation : public osg::GraphicsOperation
|
||||
{
|
||||
public:
|
||||
GetGLExtensionsOperation();
|
||||
|
||||
void operator()(osg::GraphicsContext* graphicsContext) override;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue