From 48a23d61b26192b54cecbc2939aac6999a7d7542 Mon Sep 17 00:00:00 2001 From: scrawl Date: Mon, 2 Jan 2017 04:01:04 +0100 Subject: [PATCH] Mask out water in global map overlay --- apps/openmw/mwrender/globalmap.cpp | 32 ++++++++++++++++++++++++++++++ apps/openmw/mwrender/globalmap.hpp | 1 + 2 files changed, 33 insertions(+) diff --git a/apps/openmw/mwrender/globalmap.cpp b/apps/openmw/mwrender/globalmap.cpp index 6663b8b29..eae63c514 100644 --- a/apps/openmw/mwrender/globalmap.cpp +++ b/apps/openmw/mwrender/globalmap.cpp @@ -7,6 +7,7 @@ #include #include #include +#include #include @@ -144,6 +145,10 @@ namespace MWRender image->allocateImage(mWidth, mHeight, 1, GL_RGB, GL_UNSIGNED_BYTE); unsigned char* data = image->data(); + osg::ref_ptr alphaImage = new osg::Image; + alphaImage->allocateImage(mWidth, mHeight, 1, GL_ALPHA, GL_UNSIGNED_BYTE); + unsigned char* alphaData = alphaImage->data(); + for (int x = mMinX; x <= mMaxX; ++x) { for (int y = mMinY; y <= mMaxY; ++y) @@ -208,6 +213,8 @@ namespace MWRender data[texelY * mWidth * 3 + texelX * 3] = r; data[texelY * mWidth * 3 + texelX * 3+1] = g; data[texelY * mWidth * 3 + texelX * 3+2] = b; + + alphaData[texelY * mWidth+ texelX] = (y2 < 0) ? static_cast(0) : static_cast(255); } } loadingListener->increaseProgress(); @@ -224,6 +231,14 @@ namespace MWRender mBaseTexture->setImage(image); mBaseTexture->setResizeNonPowerOfTwoHint(false); + mAlphaTexture = new osg::Texture2D; + mAlphaTexture->setWrap(osg::Texture::WRAP_S, osg::Texture::CLAMP_TO_EDGE); + mAlphaTexture->setWrap(osg::Texture::WRAP_T, osg::Texture::CLAMP_TO_EDGE); + mAlphaTexture->setFilter(osg::Texture::MIN_FILTER, osg::Texture::LINEAR); + mAlphaTexture->setFilter(osg::Texture::MAG_FILTER, osg::Texture::LINEAR); + mAlphaTexture->setImage(alphaImage); + mAlphaTexture->setResizeNonPowerOfTwoHint(false); + clear(); loadingListener->loadingOff(); @@ -299,6 +314,23 @@ namespace MWRender stateset->setTextureAttributeAndModes(0, texture, osg::StateAttribute::ON); stateset->setMode(GL_LIGHTING, osg::StateAttribute::OFF); stateset->setMode(GL_DEPTH_TEST, osg::StateAttribute::OFF); + + if (mAlphaTexture) + { + osg::ref_ptr texcoords = new osg::Vec2Array; + texcoords->push_back(osg::Vec2f(0.f, 0.f)); + texcoords->push_back(osg::Vec2f(0.f, 1.f)); + texcoords->push_back(osg::Vec2f(1.f, 1.f)); + texcoords->push_back(osg::Vec2f(1.f, 0.f)); + geom->setTexCoordArray(1, texcoords, osg::Array::BIND_PER_VERTEX); + + stateset->setTextureAttributeAndModes(1, mAlphaTexture, osg::StateAttribute::ON); + osg::ref_ptr texEnvCombine = new osg::TexEnvCombine; + texEnvCombine->setCombine_RGB(osg::TexEnvCombine::REPLACE); + texEnvCombine->setSource0_RGB(osg::TexEnvCombine::PREVIOUS); + stateset->setTextureAttributeAndModes(1, texEnvCombine); + } + camera->addChild(geom); } diff --git a/apps/openmw/mwrender/globalmap.hpp b/apps/openmw/mwrender/globalmap.hpp index df8aa9962..1c44439fd 100644 --- a/apps/openmw/mwrender/globalmap.hpp +++ b/apps/openmw/mwrender/globalmap.hpp @@ -107,6 +107,7 @@ namespace MWRender std::vector< std::pair > mExploredCells; osg::ref_ptr mBaseTexture; + osg::ref_ptr mAlphaTexture; // GPU copy of overlay // Note, uploads are pushed through a Camera, instead of through mOverlayImage