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

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

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

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

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

@ -4,6 +4,7 @@
#include <array> #include <array>
#include <components/debug/debuglog.hpp> #include <components/debug/debuglog.hpp>
#include <components/sceneutil/glextensions.hpp>
#include <components/settings/values.hpp> #include <components/settings/values.hpp>
namespace SceneUtil namespace SceneUtil
@ -116,8 +117,7 @@ namespace SceneUtil
if (Settings::camera().mReverseZ) if (Settings::camera().mReverseZ)
{ {
osg::ref_ptr<osg::GLExtensions> exts = osg::GLExtensions::Get(0, false); if (SceneUtil::getGLExtensions().isClipControlSupported)
if (exts && exts->isClipControlSupported)
{ {
enableReverseZ = true; enableReverseZ = true;
Log(Debug::Info) << "Using reverse-z depth buffer"; 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 <osgUtil/CullVisitor>
#include <components/resource/scenemanager.hpp> #include <components/resource/scenemanager.hpp>
#include <components/sceneutil/glextensions.hpp>
#include <components/sceneutil/util.hpp> #include <components/sceneutil/util.hpp>
#include <components/shader/shadermanager.hpp> #include <components/shader/shadermanager.hpp>
@ -824,9 +825,9 @@ namespace SceneUtil
, mPointLightFadeEnd(0.f) , mPointLightFadeEnd(0.f)
, mPointLightFadeStart(0.f) , mPointLightFadeStart(0.f)
{ {
osg::GLExtensions* exts = osg::GLExtensions::Get(0, false); osg::GLExtensions& exts = SceneUtil::getGLExtensions();
bool supportsUBO = exts && exts->isUniformBufferObjectSupported; bool supportsUBO = exts.isUniformBufferObjectSupported;
bool supportsGPU4 = exts && exts->isGpuShader4Supported; bool supportsGPU4 = exts.isGpuShader4Supported;
mSupported[static_cast<int>(LightingMethod::FFP)] = true; mSupported[static_cast<int>(LightingMethod::FFP)] = true;
mSupported[static_cast<int>(LightingMethod::PerObjectUniform)] = true; mSupported[static_cast<int>(LightingMethod::PerObjectUniform)] = true;

@ -30,6 +30,7 @@
#include <deque> #include <deque>
#include <vector> #include <vector>
#include "glextensions.hpp"
#include "shadowsbin.hpp" #include "shadowsbin.hpp"
namespace { 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 // 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::Shader> castingVertexShader = shaderManager.getShader("shadowcasting.vert");
osg::ref_ptr<osg::GLExtensions> exts = osg::GLExtensions::Get(0, false); std::string useGPUShader4 = SceneUtil::getGLExtensions().isGpuShader4Supported ? "1" : "0";
std::string useGPUShader4 = exts && exts->isGpuShader4Supported ? "1" : "0";
for (int alphaFunc = GL_NEVER; alphaFunc <= GL_ALWAYS; ++alphaFunc) for (int alphaFunc = GL_NEVER; alphaFunc <= GL_ALWAYS; ++alphaFunc)
{ {
auto& program = _castingPrograms[alphaFunc - GL_NEVER]; auto& program = _castingPrograms[alphaFunc - GL_NEVER];

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

Loading…
Cancel
Save