mirror of
https://github.com/OpenMW/openmw.git
synced 2025-02-03 16: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,
|
sFogOfWarResolution, sFogOfWarResolution,
|
||||||
0,
|
0,
|
||||||
PF_A8R8G8B8,
|
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;
|
return tex;
|
||||||
|
@ -457,6 +459,30 @@ bool LocalMap::isPositionExplored (float nX, float nY, int x, int y, bool interi
|
||||||
return alpha < 200;
|
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)
|
void LocalMap::updatePlayer (const Ogre::Vector3& position, const Ogre::Quaternion& orientation)
|
||||||
{
|
{
|
||||||
if (sFogOfWarSkip != 0)
|
if (sFogOfWarSkip != 0)
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
|
|
||||||
#include <OgreAxisAlignedBox.h>
|
#include <OgreAxisAlignedBox.h>
|
||||||
#include <OgreColourValue.h>
|
#include <OgreColourValue.h>
|
||||||
|
#include <OgreResource.h>
|
||||||
|
|
||||||
namespace MWWorld
|
namespace MWWorld
|
||||||
{
|
{
|
||||||
|
@ -23,12 +24,14 @@ namespace MWRender
|
||||||
///
|
///
|
||||||
/// \brief Local map rendering
|
/// \brief Local map rendering
|
||||||
///
|
///
|
||||||
class LocalMap
|
class LocalMap : public Ogre::ManualResourceLoader
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
LocalMap(OEngine::Render::OgreRenderer*, MWRender::RenderingManager* rendering);
|
LocalMap(OEngine::Render::OgreRenderer*, MWRender::RenderingManager* rendering);
|
||||||
~LocalMap();
|
~LocalMap();
|
||||||
|
|
||||||
|
virtual void loadResource(Ogre::Resource* resource);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Clear all savegame-specific data (i.e. fog of war textures)
|
* Clear all savegame-specific data (i.e. fog of war textures)
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Reference in a new issue