mirror of
https://github.com/OpenMW/openmw.git
synced 2025-02-03 13:45:34 +00:00
Add ManualResourceLoader for fog of war textures (Fixes #1675)
This commit is contained in:
parent
4b3e12bfb4
commit
4ec51b386a
2 changed files with 31 additions and 2 deletions
|
@ -340,7 +340,9 @@ Ogre::TexturePtr LocalMap::createFogOfWarTexture(const std::string &texName)
|
|||
sFogOfWarResolution, sFogOfWarResolution,
|
||||
0,
|
||||
PF_A8R8G8B8,
|
||||
TU_DYNAMIC_WRITE_ONLY);
|
||||
TU_DYNAMIC_WRITE_ONLY,
|
||||
this // ManualResourceLoader required if the texture contents are lost (due to lost devices nonsense that can occur with D3D)
|
||||
);
|
||||
}
|
||||
|
||||
return tex;
|
||||
|
@ -457,6 +459,30 @@ bool LocalMap::isPositionExplored (float nX, float nY, int x, int y, bool interi
|
|||
return alpha < 200;
|
||||
}
|
||||
|
||||
void LocalMap::loadResource(Ogre::Resource* resource)
|
||||
{
|
||||
std::string resourceName = resource->getName();
|
||||
size_t pos = resourceName.find("_fog");
|
||||
if (pos != std::string::npos)
|
||||
resourceName = resourceName.substr(0, pos);
|
||||
if (mBuffers.find(resourceName) == mBuffers.end())
|
||||
{
|
||||
// create a buffer to use for dynamic operations
|
||||
std::vector<uint32> buffer;
|
||||
|
||||
// initialize to (0, 0, 0, 1)
|
||||
buffer.resize(sFogOfWarResolution*sFogOfWarResolution, 0xFF000000);
|
||||
mBuffers[resourceName] = buffer;
|
||||
}
|
||||
|
||||
std::vector<uint32>& buffer = mBuffers[resourceName];
|
||||
|
||||
Ogre::Texture* tex = dynamic_cast<Ogre::Texture*>(resource);
|
||||
tex->createInternalResources();
|
||||
memcpy(tex->getBuffer()->lock(HardwareBuffer::HBL_DISCARD), &buffer[0], sFogOfWarResolution*sFogOfWarResolution*4);
|
||||
tex->getBuffer()->unlock();
|
||||
}
|
||||
|
||||
void LocalMap::updatePlayer (const Ogre::Vector3& position, const Ogre::Quaternion& orientation)
|
||||
{
|
||||
if (sFogOfWarSkip != 0)
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
|
||||
#include <OgreAxisAlignedBox.h>
|
||||
#include <OgreColourValue.h>
|
||||
#include <OgreResource.h>
|
||||
|
||||
namespace MWWorld
|
||||
{
|
||||
|
@ -23,12 +24,14 @@ namespace MWRender
|
|||
///
|
||||
/// \brief Local map rendering
|
||||
///
|
||||
class LocalMap
|
||||
class LocalMap : public Ogre::ManualResourceLoader
|
||||
{
|
||||
public:
|
||||
LocalMap(OEngine::Render::OgreRenderer*, MWRender::RenderingManager* rendering);
|
||||
~LocalMap();
|
||||
|
||||
virtual void loadResource(Ogre::Resource* resource);
|
||||
|
||||
/**
|
||||
* Clear all savegame-specific data (i.e. fog of war textures)
|
||||
*/
|
||||
|
|
Loading…
Reference in a new issue