From ff6944701fbb96ae9eec93ceb857b1a2b2d550bf Mon Sep 17 00:00:00 2001 From: Bret Curtis Date: Wed, 14 Jun 2023 22:14:38 +0200 Subject: [PATCH] Be more explicit about use of CLAMP_TO_EDGE instead of defaulting to GL CLAMP --- apps/openmw/mwgui/loadingscreen.cpp | 2 ++ apps/openmw/mwrender/characterpreview.cpp | 2 ++ apps/openmw/mwrender/luminancecalculator.cpp | 6 ++++++ apps/openmw/mwrender/postprocessor.cpp | 15 ++++++++++++--- apps/openmw/mwrender/precipitationocclusion.cpp | 2 ++ apps/openmw/mwrender/screenshotmanager.cpp | 2 ++ apps/openmw/mwrender/skyutil.cpp | 2 ++ apps/openmw/mwrender/transparentpass.cpp | 2 ++ components/fx/parse_constants.hpp | 1 - components/fx/technique.hpp | 4 ++++ components/myguiplatform/myguirendermanager.cpp | 2 ++ components/sceneutil/shadow.cpp | 2 ++ components/stereo/multiview.cpp | 6 ++++++ 13 files changed, 44 insertions(+), 4 deletions(-) diff --git a/apps/openmw/mwgui/loadingscreen.cpp b/apps/openmw/mwgui/loadingscreen.cpp index f86fa5164c..3574333fda 100644 --- a/apps/openmw/mwgui/loadingscreen.cpp +++ b/apps/openmw/mwgui/loadingscreen.cpp @@ -295,6 +295,8 @@ namespace MWGui if (!mTexture) { mTexture = new osg::Texture2D; + mTexture->setWrap(osg::Texture::WRAP_S, osg::Texture::CLAMP_TO_EDGE); + mTexture->setWrap(osg::Texture::WRAP_T, osg::Texture::CLAMP_TO_EDGE); mTexture->setInternalFormat(GL_RGB); mTexture->setResizeNonPowerOfTwoHint(false); } diff --git a/apps/openmw/mwrender/characterpreview.cpp b/apps/openmw/mwrender/characterpreview.cpp index a121927935..38238b121f 100644 --- a/apps/openmw/mwrender/characterpreview.cpp +++ b/apps/openmw/mwrender/characterpreview.cpp @@ -268,6 +268,8 @@ namespace MWRender noBlendAlphaEnv->setCombine_RGB(osg::TexEnvCombine::REPLACE); noBlendAlphaEnv->setSource0_RGB(osg::TexEnvCombine::PREVIOUS); osg::ref_ptr dummyTexture = new osg::Texture2D(); + dummyTexture->setWrap(osg::Texture::WRAP_S, osg::Texture::CLAMP_TO_EDGE); + dummyTexture->setWrap(osg::Texture::WRAP_T, osg::Texture::CLAMP_TO_EDGE); dummyTexture->setInternalFormat(GL_DEPTH_COMPONENT); dummyTexture->setTextureSize(1, 1); // This might clash with a shadow map, so make sure it doesn't cast shadows diff --git a/apps/openmw/mwrender/luminancecalculator.cpp b/apps/openmw/mwrender/luminancecalculator.cpp index b267b94e59..e0d275b177 100644 --- a/apps/openmw/mwrender/luminancecalculator.cpp +++ b/apps/openmw/mwrender/luminancecalculator.cpp @@ -35,6 +35,8 @@ namespace MWRender buffer.mipmappedSceneLuminanceTex->setInternalFormat(GL_R16F); buffer.mipmappedSceneLuminanceTex->setSourceFormat(GL_RED); buffer.mipmappedSceneLuminanceTex->setSourceType(GL_FLOAT); + buffer.mipmappedSceneLuminanceTex->setWrap(osg::Texture::WRAP_S, osg::Texture::CLAMP_TO_EDGE); + buffer.mipmappedSceneLuminanceTex->setWrap(osg::Texture::WRAP_T, osg::Texture::CLAMP_TO_EDGE); buffer.mipmappedSceneLuminanceTex->setFilter( osg::Texture2D::MIN_FILTER, osg::Texture2D::LINEAR_MIPMAP_NEAREST); buffer.mipmappedSceneLuminanceTex->setFilter(osg::Texture2D::MAG_FILTER, osg::Texture2D::LINEAR); @@ -45,11 +47,15 @@ namespace MWRender buffer.luminanceTex->setInternalFormat(GL_R16F); buffer.luminanceTex->setSourceFormat(GL_RED); buffer.luminanceTex->setSourceType(GL_FLOAT); + buffer.luminanceTex->setWrap(osg::Texture::WRAP_S, osg::Texture::CLAMP_TO_EDGE); + buffer.luminanceTex->setWrap(osg::Texture::WRAP_T, osg::Texture::CLAMP_TO_EDGE); buffer.luminanceTex->setFilter(osg::Texture2D::MIN_FILTER, osg::Texture2D::NEAREST); buffer.luminanceTex->setFilter(osg::Texture2D::MAG_FILTER, osg::Texture2D::NEAREST); buffer.luminanceTex->setTextureSize(1, 1); buffer.luminanceProxyTex = new osg::Texture2D(*buffer.luminanceTex); + buffer.luminanceProxyTex->setWrap(osg::Texture::WRAP_S, osg::Texture::CLAMP_TO_EDGE); + buffer.luminanceProxyTex->setWrap(osg::Texture::WRAP_T, osg::Texture::CLAMP_TO_EDGE); buffer.resolveFbo = new osg::FrameBufferObject; buffer.resolveFbo->setAttachment(osg::FrameBufferObject::BufferComponent::COLOR_BUFFER0, diff --git a/apps/openmw/mwrender/postprocessor.cpp b/apps/openmw/mwrender/postprocessor.cpp index 9ddae99950..659f61c702 100644 --- a/apps/openmw/mwrender/postprocessor.cpp +++ b/apps/openmw/mwrender/postprocessor.cpp @@ -164,6 +164,8 @@ namespace MWRender mTextures[i][Tex_OpaqueDepth] = new osg::Texture2DArray; else mTextures[i][Tex_OpaqueDepth] = new osg::Texture2D; + mTextures[i][Tex_OpaqueDepth]->setWrap(osg::Texture::WRAP_S, osg::Texture::CLAMP_TO_EDGE); + mTextures[i][Tex_OpaqueDepth]->setWrap(osg::Texture::WRAP_T, osg::Texture::CLAMP_TO_EDGE); } } @@ -598,13 +600,18 @@ namespace MWRender // user-defined samplers for (const osg::Texture* texture : technique->getTextures()) { + osg::ref_ptr sample; + if (const auto* tex1D = dynamic_cast(texture)) - node.mRootStateSet->setTextureAttribute(texUnit, new osg::Texture1D(*tex1D)); + sample = new osg::Texture1D(*tex1D); else if (const auto* tex2D = dynamic_cast(texture)) - node.mRootStateSet->setTextureAttribute(texUnit, new osg::Texture2D(*tex2D)); + sample = new osg::Texture2D(*tex2D); else if (const auto* tex3D = dynamic_cast(texture)) - node.mRootStateSet->setTextureAttribute(texUnit, new osg::Texture3D(*tex3D)); + sample= new osg::Texture3D(*tex3D); + sample->setWrap(osg::Texture::WRAP_S, osg::Texture::CLAMP_TO_EDGE); + sample->setWrap(osg::Texture::WRAP_T, osg::Texture::CLAMP_TO_EDGE); + node.mRootStateSet->setTextureAttribute(texUnit, sample); node.mRootStateSet->addUniform(new osg::Uniform(texture->getName().c_str(), texUnit++)); } @@ -637,6 +644,8 @@ namespace MWRender const auto [w, h] = rt.mSize.get(renderWidth(), renderHeight()); subPass.mRenderTexture = new osg::Texture2D(*rt.mTarget); + subPass.mRenderTexture ->setWrap(osg::Texture::WRAP_S, osg::Texture::CLAMP_TO_EDGE); + subPass.mRenderTexture ->setWrap(osg::Texture::WRAP_T, osg::Texture::CLAMP_TO_EDGE); renderTargetCache[rt.mTarget] = subPass.mRenderTexture; subPass.mRenderTexture->setTextureSize(w, h); subPass.mRenderTexture->setName(std::string(pass->getTarget())); diff --git a/apps/openmw/mwrender/precipitationocclusion.cpp b/apps/openmw/mwrender/precipitationocclusion.cpp index 444ed8a1ed..c1e11ae93b 100644 --- a/apps/openmw/mwrender/precipitationocclusion.cpp +++ b/apps/openmw/mwrender/precipitationocclusion.cpp @@ -48,6 +48,8 @@ namespace : mDummyTexture(new osg::Texture2D) { mDummyTexture->setInternalFormat(GL_RGB); + mDummyTexture->setWrap(osg::Texture::WRAP_S, osg::Texture::CLAMP_TO_EDGE); + mDummyTexture->setWrap(osg::Texture::WRAP_T, osg::Texture::CLAMP_TO_EDGE); mDummyTexture->setTextureSize(1, 1); Shader::ShaderManager& shaderMgr diff --git a/apps/openmw/mwrender/screenshotmanager.cpp b/apps/openmw/mwrender/screenshotmanager.cpp index a0c7fabdbc..4179b2807e 100644 --- a/apps/openmw/mwrender/screenshotmanager.cpp +++ b/apps/openmw/mwrender/screenshotmanager.cpp @@ -315,6 +315,8 @@ namespace MWRender texture->setResizeNonPowerOfTwoHint(false); texture->setFilter(osg::Texture::MIN_FILTER, osg::Texture::LINEAR); texture->setFilter(osg::Texture::MAG_FILTER, osg::Texture::LINEAR); + texture->setWrap(osg::Texture::WRAP_S, osg::Texture::CLAMP_TO_EDGE); + texture->setWrap(osg::Texture::WRAP_T, osg::Texture::CLAMP_TO_EDGE); camera->attach(osg::Camera::COLOR_BUFFER, texture); image->setDataType(GL_UNSIGNED_BYTE); diff --git a/apps/openmw/mwrender/skyutil.cpp b/apps/openmw/mwrender/skyutil.cpp index 661f9c305c..2a21b950eb 100644 --- a/apps/openmw/mwrender/skyutil.cpp +++ b/apps/openmw/mwrender/skyutil.cpp @@ -482,6 +482,8 @@ namespace MWRender , mTexture(new osg::Texture2D(imageManager->getWarningImage())) , mForceShaders(forceShaders) { + mTexture->setWrap(osg::Texture::WRAP_S, osg::Texture::CLAMP_TO_EDGE); + mTexture->setWrap(osg::Texture::WRAP_T, osg::Texture::CLAMP_TO_EDGE); } void AtmosphereNightUpdater::setFade(float fade) diff --git a/apps/openmw/mwrender/transparentpass.cpp b/apps/openmw/mwrender/transparentpass.cpp index a0736b650b..ce53b1c219 100644 --- a/apps/openmw/mwrender/transparentpass.cpp +++ b/apps/openmw/mwrender/transparentpass.cpp @@ -26,6 +26,8 @@ namespace MWRender image->setColor(osg::Vec4(1, 1, 1, 1), 0, 0); osg::ref_ptr dummyTexture = new osg::Texture2D(image); + dummyTexture->setWrap(osg::Texture::WRAP_S, osg::Texture::CLAMP_TO_EDGE); + dummyTexture->setWrap(osg::Texture::WRAP_T, osg::Texture::CLAMP_TO_EDGE); constexpr osg::StateAttribute::OverrideValue modeOff = osg::StateAttribute::OFF | osg::StateAttribute::OVERRIDE; constexpr osg::StateAttribute::OverrideValue modeOn = osg::StateAttribute::ON | osg::StateAttribute::OVERRIDE; diff --git a/components/fx/parse_constants.hpp b/components/fx/parse_constants.hpp index 3c9e3b59c8..fc68e4ea77 100644 --- a/components/fx/parse_constants.hpp +++ b/components/fx/parse_constants.hpp @@ -83,7 +83,6 @@ namespace fx } }; constexpr std::array, 6> WrapMode = { { - { "clamp", osg::Texture::CLAMP }, { "clamp_to_edge", osg::Texture::CLAMP_TO_EDGE }, { "clamp_to_border", osg::Texture::CLAMP_TO_BORDER }, { "repeat", osg::Texture::REPEAT }, diff --git a/components/fx/technique.hpp b/components/fx/technique.hpp index 844e4b552a..3373193fdd 100644 --- a/components/fx/technique.hpp +++ b/components/fx/technique.hpp @@ -62,7 +62,11 @@ namespace fx if (other.mRenderTarget) mRenderTarget = new osg::FrameBufferObject(*other.mRenderTarget, copyOp); if (other.mRenderTexture) + { mRenderTexture = new osg::Texture2D(*other.mRenderTexture, copyOp); + mRenderTexture->setWrap(osg::Texture::WRAP_S, osg::Texture::CLAMP_TO_EDGE); + mRenderTexture->setWrap(osg::Texture::WRAP_T, osg::Texture::CLAMP_TO_EDGE); + } } }; diff --git a/components/myguiplatform/myguirendermanager.cpp b/components/myguiplatform/myguirendermanager.cpp index 4ee1190a99..5d32641b6d 100644 --- a/components/myguiplatform/myguirendermanager.cpp +++ b/components/myguiplatform/myguirendermanager.cpp @@ -184,6 +184,8 @@ namespace osgMyGUI mStateSet->setMode(GL_BLEND, osg::StateAttribute::ON); mDummyTexture = new osg::Texture2D; + mDummyTexture->setWrap(osg::Texture::WRAP_S, osg::Texture::CLAMP_TO_EDGE); + mDummyTexture->setWrap(osg::Texture::WRAP_T, osg::Texture::CLAMP_TO_EDGE); mDummyTexture->setInternalFormat(GL_RGB); mDummyTexture->setTextureSize(1, 1); diff --git a/components/sceneutil/shadow.cpp b/components/sceneutil/shadow.cpp index 4cf8a89255..f2748d70f1 100644 --- a/components/sceneutil/shadow.cpp +++ b/components/sceneutil/shadow.cpp @@ -93,6 +93,8 @@ namespace SceneUtil fakeShadowMapImage->allocateImage(1, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT); *(float*)fakeShadowMapImage->data() = std::numeric_limits::infinity(); osg::ref_ptr fakeShadowMapTexture = new osg::Texture2D(fakeShadowMapImage); + fakeShadowMapTexture->setWrap(osg::Texture::WRAP_S, osg::Texture::CLAMP_TO_EDGE); + fakeShadowMapTexture->setWrap(osg::Texture::WRAP_T, osg::Texture::CLAMP_TO_EDGE); fakeShadowMapTexture->setShadowComparison(true); fakeShadowMapTexture->setShadowCompareFunc(osg::Texture::ShadowCompareFunc::ALWAYS); for (int i = baseShadowTextureUnit; i < baseShadowTextureUnit + numberOfShadowMapsPerLight; ++i) diff --git a/components/stereo/multiview.cpp b/components/stereo/multiview.cpp index 5111870c2b..047a52747b 100644 --- a/components/stereo/multiview.cpp +++ b/components/stereo/multiview.cpp @@ -243,6 +243,8 @@ namespace Stereo } osg::ref_ptr texture2d = new osg::Texture2D; + texture2d->setWrap(osg::Texture::WRAP_S, osg::Texture::CLAMP_TO_EDGE); + texture2d->setWrap(osg::Texture::WRAP_T, osg::Texture::CLAMP_TO_EDGE); texture2d->setSubloadCallback(new Texture2DViewSubloadCallback(textureArray, layer)); texture2d->setTextureSize(textureArray->getTextureWidth(), textureArray->getTextureHeight()); texture2d->setBorderColor(textureArray->getBorderColor()); @@ -429,12 +431,16 @@ namespace Stereo auto tex = new osg::Texture2DMultisample(); tex->setTextureSize(width, height); tex->setNumSamples(samples); + tex->setWrap(osg::Texture::WRAP_S, osg::Texture::CLAMP_TO_EDGE); + tex->setWrap(osg::Texture::WRAP_T, osg::Texture::CLAMP_TO_EDGE); return tex; } else { auto tex = new osg::Texture2D(); tex->setTextureSize(width, height); + tex->setWrap(osg::Texture::WRAP_S, osg::Texture::CLAMP_TO_EDGE); + tex->setWrap(osg::Texture::WRAP_T, osg::Texture::CLAMP_TO_EDGE); return tex; } }