Get the GLExtensions instance when a context is created

fix-osga-rotate-wildly
AnyOldName3 2 years ago committed by AnyOldName3
parent e4a9e83609
commit 36a75cdb29

@ -48,6 +48,7 @@
#include <components/debug/debuglog.hpp>
#include <components/resource/resourcesystem.hpp>
#include <components/resource/scenemanager.hpp>
#include <components/sceneutil/glextensions.hpp>
#include <components/sceneutil/lightmanager.hpp>
#include "../widget/scenetoolmode.hpp"
@ -76,6 +77,8 @@ namespace CSVRender
= new osgViewer::GraphicsWindowEmbedded(0, 0, width(), height());
mWidget->setGraphicsWindowEmbedded(window);
mRenderer->setRealizeOperation(new SceneUtil::GetGLExtensionsOperation());
int frameRateLimit = CSMPrefs::get()["Rendering"]["framerate-limit"].toInt();
mRenderer->setRunMaxFrameRate(frameRateLimit);
mRenderer->setUseConfigureAffinity(false);

@ -31,6 +31,7 @@
#include <components/stereo/multiview.hpp>
#include <components/stereo/stereomanager.hpp>
#include <components/sceneutil/glextensions.hpp>
#include <components/sceneutil/workqueue.hpp>
#include <components/files/configurationmanager.hpp>
@ -600,6 +601,7 @@ void OMW::Engine::createWindow()
mViewer->setRealizeOperation(realizeOperations);
osg::ref_ptr<IdentifyOpenGLOperation> identifyOp = new IdentifyOpenGLOperation();
realizeOperations->add(identifyOp);
realizeOperations->add(new SceneUtil::GetGLExtensionsOperation());
if (Debug::shouldDebugOpenGL())
realizeOperations->add(new Debug::EnableGLDebugOperation());
@ -780,13 +782,13 @@ void OMW::Engine::prepareEngine()
// gui needs our shaders path before everything else
mResourceSystem->getSceneManager()->setShaderPath(mResDir / "shaders");
osg::ref_ptr<osg::GLExtensions> exts = osg::GLExtensions::Get(0, false);
bool shadersSupported = exts && (exts->glslLanguageVersion >= 1.2f);
osg::GLExtensions& exts = SceneUtil::getGLExtensions();
bool shadersSupported = exts.glslLanguageVersion >= 1.2f;
#if OSG_VERSION_LESS_THAN(3, 6, 6)
// hack fix for https://github.com/openscenegraph/OpenSceneGraph/issues/1028
if (exts)
exts->glRenderbufferStorageMultisampleCoverageNV = nullptr;
if (!osg::isGLExtensionSupported(exts.contextID, "NV_framebuffer_multisample_coverage"))
exts.glRenderbufferStorageMultisampleCoverageNV = nullptr;
#endif
osg::ref_ptr<osg::Group> guiRoot = new osg::Group;
@ -844,18 +846,18 @@ void OMW::Engine::prepareEngine()
const MWWorld::Store<ESM::GameSetting>* gmst = &mWorld->getStore().get<ESM::GameSetting>();
mL10nManager->setGmstLoader(
[gmst, misses = std::set<std::string, std::less<>>()](std::string_view gmstName) mutable {
const ESM::GameSetting* res = gmst->search(gmstName);
if (res && res->mValue.getType() == ESM::VT_String)
return res->mValue.getString();
else
const ESM::GameSetting* res = gmst->search(gmstName);
if (res && res->mValue.getType() == ESM::VT_String)
return res->mValue.getString();
else
{
if (misses.count(gmstName) == 0)
{
if (misses.count(gmstName) == 0)
{
misses.emplace(gmstName);
Log(Debug::Error) << "GMST " << gmstName << " not found";
}
return std::string("GMST:") + std::string(gmstName);
misses.emplace(gmstName);
Log(Debug::Error) << "GMST " << gmstName << " not found";
}
return std::string("GMST:") + std::string(gmstName);
}
});
mWindowManager->setStore(mWorld->getStore());

@ -10,6 +10,7 @@
#include <components/resource/scenemanager.hpp>
#include <components/sceneutil/color.hpp>
#include <components/sceneutil/depth.hpp>
#include <components/sceneutil/glextensions.hpp>
#include <components/shader/shadermanager.hpp>
#include "../mwworld/ptr.hpp"
@ -43,9 +44,9 @@ namespace MWRender
mUseCompute = false;
#else
constexpr float minimumGLVersionRequiredForCompute = 4.4;
osg::GLExtensions* exts = osg::GLExtensions::Get(0, false);
mUseCompute = exts->glVersion >= minimumGLVersionRequiredForCompute
&& exts->glslLanguageVersion >= minimumGLVersionRequiredForCompute;
osg::GLExtensions& exts = SceneUtil::getGLExtensions();
mUseCompute = exts.glVersion >= minimumGLVersionRequiredForCompute
&& exts.glslLanguageVersion >= minimumGLVersionRequiredForCompute;
#endif
if (mUseCompute)

@ -122,7 +122,7 @@ add_component_dir (sceneutil
lightmanager lightutil positionattitudetransform workqueue pathgridutil waterutil writescene serialize optimizer
detourdebugdraw navmesh agentpath shadow mwshadowtechnique recastmesh shadowsbin osgacontroller rtt
screencapture depth color riggeometryosgaextension extradata unrefqueue lightcommon lightingmethod clearcolor
cullsafeboundsvisitor keyframe nodecallback textkeymap
cullsafeboundsvisitor keyframe nodecallback textkeymap glextensions
)
add_component_dir (nif

@ -5,6 +5,7 @@
#include <components/debug/debuglog.hpp>
#include <components/misc/pathhelpers.hpp>
#include <components/sceneutil/glextensions.hpp>
#include <components/vfs/manager.hpp>
#include <components/vfs/pathutil.hpp>
@ -65,12 +66,11 @@ namespace Resource
case (GL_COMPRESSED_RGBA_S3TC_DXT3_EXT):
case (GL_COMPRESSED_RGBA_S3TC_DXT5_EXT):
{
osg::GLExtensions* exts = osg::GLExtensions::Get(0, false);
if (exts
&& !exts->isTextureCompressionS3TCSupported
osg::GLExtensions& exts = SceneUtil::getGLExtensions();
if (!exts.isTextureCompressionS3TCSupported
// This one works too. Should it be included in isTextureCompressionS3TCSupported()? Submitted as a
// patch to OSG.
&& !osg::isGLExtensionSupported(0, "GL_S3_s3tc"))
&& !osg::isGLExtensionSupported(exts.contextID, "GL_S3_s3tc"))
{
return false;
}

@ -4,6 +4,7 @@
#include <array>
#include <components/debug/debuglog.hpp>
#include <components/sceneutil/glextensions.hpp>
#include <components/settings/values.hpp>
namespace SceneUtil
@ -116,8 +117,7 @@ namespace SceneUtil
if (Settings::camera().mReverseZ)
{
osg::ref_ptr<osg::GLExtensions> exts = osg::GLExtensions::Get(0, false);
if (exts && exts->isClipControlSupported)
if (SceneUtil::getGLExtensions().isClipControlSupported)
{
enableReverseZ = true;
Log(Debug::Info) << "Using reverse-z depth buffer";

@ -0,0 +1,28 @@
#include "glextensions.hpp"
namespace SceneUtil
{
namespace
{
osg::observer_ptr<osg::GLExtensions> sGLExtensions;
}
osg::GLExtensions& getGLExtensions()
{
if (!sGLExtensions)
throw std::runtime_error(
"GetGLExtensionsOperation was not used when the current context was created or there is no current "
"context");
return *sGLExtensions;
}
GetGLExtensionsOperation::GetGLExtensionsOperation()
: GraphicsOperation("GetGLExtensionsOperation", false)
{
}
void GetGLExtensionsOperation::operator()(osg::GraphicsContext* graphicsContext)
{
sGLExtensions = graphicsContext->getState()->get<osg::GLExtensions>();
}
}

@ -0,0 +1,20 @@
#ifndef OPENMW_COMPONENTS_SCENEUTIL_GLEXTENSIONS_H
#define OPENMW_COMPONENTS_SCENEUTIL_GLEXTENSIONS_H
#include <osg/GLExtensions>
#include <osg/GraphicsThread>
namespace SceneUtil
{
osg::GLExtensions& getGLExtensions();
class GetGLExtensionsOperation : public osg::GraphicsOperation
{
public:
GetGLExtensionsOperation();
void operator()(osg::GraphicsContext* graphicsContext) override;
};
}
#endif

@ -13,6 +13,7 @@
#include <osgUtil/CullVisitor>
#include <components/resource/scenemanager.hpp>
#include <components/sceneutil/glextensions.hpp>
#include <components/sceneutil/util.hpp>
#include <components/shader/shadermanager.hpp>
@ -824,9 +825,9 @@ namespace SceneUtil
, mPointLightFadeEnd(0.f)
, mPointLightFadeStart(0.f)
{
osg::GLExtensions* exts = osg::GLExtensions::Get(0, false);
bool supportsUBO = exts && exts->isUniformBufferObjectSupported;
bool supportsGPU4 = exts && exts->isGpuShader4Supported;
osg::GLExtensions& exts = SceneUtil::getGLExtensions();
bool supportsUBO = exts.isUniformBufferObjectSupported;
bool supportsGPU4 = exts.isGpuShader4Supported;
mSupported[static_cast<int>(LightingMethod::FFP)] = true;
mSupported[static_cast<int>(LightingMethod::PerObjectUniform)] = true;

@ -30,6 +30,7 @@
#include <deque>
#include <vector>
#include "glextensions.hpp"
#include "shadowsbin.hpp"
namespace {
@ -920,8 +921,7 @@ void SceneUtil::MWShadowTechnique::setupCastingShader(Shader::ShaderManager & sh
// This can't be part of the constructor as OSG mandates that there be a trivial constructor available
osg::ref_ptr<osg::Shader> castingVertexShader = shaderManager.getShader("shadowcasting.vert");
osg::ref_ptr<osg::GLExtensions> exts = osg::GLExtensions::Get(0, false);
std::string useGPUShader4 = exts && exts->isGpuShader4Supported ? "1" : "0";
std::string useGPUShader4 = SceneUtil::getGLExtensions().isGpuShader4Supported ? "1" : "0";
for (int alphaFunc = GL_NEVER; alphaFunc <= GL_ALWAYS; ++alphaFunc)
{
auto& program = _castingPrograms[alphaFunc - GL_NEVER];

@ -22,6 +22,7 @@
#include <components/misc/osguservalues.hpp>
#include <components/misc/strings/algorithm.hpp>
#include <components/resource/imagemanager.hpp>
#include <components/sceneutil/glextensions.hpp>
#include <components/sceneutil/morphgeometry.hpp>
#include <components/sceneutil/riggeometry.hpp>
#include <components/sceneutil/riggeometryosgaextension.hpp>
@ -676,8 +677,7 @@ namespace Shader
defineMap["adjustCoverage"] = "1";
// Preventing alpha tested stuff shrinking as lower mip levels are used requires knowing the texture size
osg::ref_ptr<osg::GLExtensions> exts = osg::GLExtensions::Get(0, false);
if (exts && exts->isGpuShader4Supported)
if (SceneUtil::getGLExtensions().isGpuShader4Supported)
defineMap["useGPUShader4"] = "1";
// We could fall back to a texture size uniform if EXT_gpu_shader4 is missing
}

Loading…
Cancel
Save