1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-02-01 06:45:32 +00:00

Fog of war fix

This commit is contained in:
scrawl 2015-05-28 16:20:29 +02:00
parent f4ee805e3b
commit 5f7a82e0da

View file

@ -297,10 +297,13 @@ void LocalMap::requestExteriorMap(MWWorld::CellStore* cell)
setupRenderToTexture(camera, cell->getCell()->getGridX(), cell->getCell()->getGridY()); setupRenderToTexture(camera, cell->getCell()->getGridX(), cell->getCell()->getGridY());
MapSegment& segment = mSegments[std::make_pair(cell->getCell()->getGridX(), cell->getCell()->getGridY())]; MapSegment& segment = mSegments[std::make_pair(cell->getCell()->getGridX(), cell->getCell()->getGridY())];
if (cell->getFog()) if (!segment.mFogOfWarImage)
segment.loadFogOfWar(cell->getFog()->mFogTextures.back()); {
else if (cell->getFog())
segment.initFogOfWar(); segment.loadFogOfWar(cell->getFog()->mFogTextures.back());
else
segment.initFogOfWar();
}
} }
void LocalMap::requestInteriorMap(MWWorld::CellStore* cell) void LocalMap::requestInteriorMap(MWWorld::CellStore* cell)
@ -414,20 +417,23 @@ void LocalMap::requestInteriorMap(MWWorld::CellStore* cell)
setupRenderToTexture(camera, x, y); setupRenderToTexture(camera, x, y);
MapSegment& segment = mSegments[std::make_pair(x,y)]; MapSegment& segment = mSegments[std::make_pair(x,y)];
if (!cell->getFog()) if (!segment.mFogOfWarImage)
segment.initFogOfWar();
else
{ {
ESM::FogState* fog = cell->getFog(); if (!cell->getFog())
segment.initFogOfWar();
// We are using the same bounds and angle as we were using when the textures were originally made. Segments should come out the same. else
if (i >= int(fog->mFogTextures.size()))
{ {
std::cout << "Warning: fog texture count mismatch" << std::endl; ESM::FogState* fog = cell->getFog();
break;
}
segment.loadFogOfWar(fog->mFogTextures[i]); // We are using the same bounds and angle as we were using when the textures were originally made. Segments should come out the same.
if (i >= int(fog->mFogTextures.size()))
{
std::cout << "Warning: fog texture count mismatch" << std::endl;
break;
}
segment.loadFogOfWar(fog->mFogTextures[i]);
}
} }
++i; ++i;
} }
@ -570,7 +576,8 @@ void LocalMap::MapSegment::createFogOfWarTexture()
if (mFogOfWarTexture) if (mFogOfWarTexture)
return; return;
mFogOfWarTexture = new osg::Texture2D; mFogOfWarTexture = new osg::Texture2D;
mFogOfWarTexture->setDataVariance(osg::Object::DYNAMIC); // TODO: synchronize access? for now, the worst that could happen is the draw thread jumping a frame ahead.
//mFogOfWarTexture->setDataVariance(osg::Object::DYNAMIC);
mFogOfWarTexture->setFilter(osg::Texture::MIN_FILTER, osg::Texture::LINEAR); mFogOfWarTexture->setFilter(osg::Texture::MIN_FILTER, osg::Texture::LINEAR);
mFogOfWarTexture->setFilter(osg::Texture::MAG_FILTER, osg::Texture::LINEAR); mFogOfWarTexture->setFilter(osg::Texture::MAG_FILTER, osg::Texture::LINEAR);
mFogOfWarTexture->setWrap(osg::Texture::WRAP_S, osg::Texture::CLAMP_TO_EDGE); mFogOfWarTexture->setWrap(osg::Texture::WRAP_S, osg::Texture::CLAMP_TO_EDGE);
@ -581,6 +588,8 @@ void LocalMap::MapSegment::createFogOfWarTexture()
void LocalMap::MapSegment::initFogOfWar() void LocalMap::MapSegment::initFogOfWar()
{ {
mFogOfWarImage = new osg::Image; mFogOfWarImage = new osg::Image;
// Assign a PixelBufferObject for asynchronous transfer of data to the GPU
mFogOfWarImage->setPixelBufferObject(new osg::PixelBufferObject);
mFogOfWarImage->allocateImage(sFogOfWarResolution, sFogOfWarResolution, 1, GL_RGBA, GL_UNSIGNED_BYTE); mFogOfWarImage->allocateImage(sFogOfWarResolution, sFogOfWarResolution, 1, GL_RGBA, GL_UNSIGNED_BYTE);
assert(mFogOfWarImage->isDataContiguous()); assert(mFogOfWarImage->isDataContiguous());
std::vector<uint32_t> data; std::vector<uint32_t> data;