mirror of
https://github.com/OpenMW/openmw.git
synced 2025-01-16 15:29:55 +00:00
Merge branch 'vfs_normalized_path_13' into 'master'
Use normalized path in ImageManager (#8138) See merge request OpenMW/openmw!4377
This commit is contained in:
commit
74d699c502
16 changed files with 74 additions and 56 deletions
|
@ -176,14 +176,14 @@ namespace CSVRender
|
|||
mWaterGeometry->setStateSet(SceneUtil::createSimpleWaterStateSet(Alpha, RenderBin));
|
||||
|
||||
// Add water texture
|
||||
std::string textureName = "textures/water/";
|
||||
textureName += Fallback::Map::getString("Water_SurfaceTexture");
|
||||
textureName += "00.dds";
|
||||
constexpr VFS::Path::NormalizedView prefix("textures/water");
|
||||
VFS::Path::Normalized texturePath(prefix);
|
||||
texturePath /= std::string(Fallback::Map::getString("Water_SurfaceTexture")) + "00.dds";
|
||||
|
||||
Resource::ImageManager* imageManager = mData.getResourceSystem()->getImageManager();
|
||||
|
||||
osg::ref_ptr<osg::Texture2D> waterTexture = new osg::Texture2D();
|
||||
waterTexture->setImage(imageManager->getImage(textureName));
|
||||
waterTexture->setImage(imageManager->getImage(texturePath));
|
||||
waterTexture->setWrap(osg::Texture::WRAP_S, osg::Texture::REPEAT);
|
||||
waterTexture->setWrap(osg::Texture::WRAP_T, osg::Texture::REPEAT);
|
||||
|
||||
|
|
|
@ -2229,9 +2229,10 @@ namespace MWGui
|
|||
ResourceImageSetPointerFix* imgSetPointer = resource->castType<ResourceImageSetPointerFix>(false);
|
||||
if (!imgSetPointer)
|
||||
continue;
|
||||
auto tex_name = imgSetPointer->getImageSet()->getIndexInfo(0, 0).texture;
|
||||
|
||||
osg::ref_ptr<osg::Image> image = mResourceSystem->getImageManager()->getImage(tex_name);
|
||||
const VFS::Path::Normalized path(imgSetPointer->getImageSet()->getIndexInfo(0, 0).texture);
|
||||
|
||||
osg::ref_ptr<osg::Image> image = mResourceSystem->getImageManager()->getImage(path);
|
||||
|
||||
if (image.valid())
|
||||
{
|
||||
|
|
|
@ -41,8 +41,8 @@ namespace
|
|||
{
|
||||
std::ostringstream texname;
|
||||
texname << "textures/water/" << tex << std::setw(2) << std::setfill('0') << i << ".dds";
|
||||
osg::ref_ptr<osg::Texture2D> tex2(
|
||||
new osg::Texture2D(resourceSystem->getImageManager()->getImage(texname.str())));
|
||||
const VFS::Path::Normalized path(texname.str());
|
||||
osg::ref_ptr<osg::Texture2D> tex2(new osg::Texture2D(resourceSystem->getImageManager()->getImage(path)));
|
||||
tex2->setWrap(osg::Texture::WRAP_S, osg::Texture::REPEAT);
|
||||
tex2->setWrap(osg::Texture::WRAP_T, osg::Texture::REPEAT);
|
||||
resourceSystem->getSceneManager()->applyFilterSettings(tex2);
|
||||
|
|
|
@ -403,8 +403,9 @@ namespace MWRender
|
|||
|
||||
osg::ref_ptr<osg::StateSet> stateset = mRainParticleSystem->getOrCreateStateSet();
|
||||
|
||||
constexpr VFS::Path::NormalizedView raindropImage("textures/tx_raindrop_01.dds");
|
||||
osg::ref_ptr<osg::Texture2D> raindropTex
|
||||
= new osg::Texture2D(mSceneManager->getImageManager()->getImage("textures/tx_raindrop_01.dds"));
|
||||
= new osg::Texture2D(mSceneManager->getImageManager()->getImage(raindropImage));
|
||||
raindropTex->setWrap(osg::Texture::WRAP_S, osg::Texture::CLAMP_TO_EDGE);
|
||||
raindropTex->setWrap(osg::Texture::WRAP_T, osg::Texture::CLAMP_TO_EDGE);
|
||||
|
||||
|
@ -768,7 +769,8 @@ namespace MWRender
|
|||
{
|
||||
mClouds = weather.mCloudTexture;
|
||||
|
||||
std::string texture = Misc::ResourceHelpers::correctTexturePath(mClouds, mSceneManager->getVFS());
|
||||
const VFS::Path::Normalized texture
|
||||
= Misc::ResourceHelpers::correctTexturePath(mClouds, mSceneManager->getVFS());
|
||||
|
||||
osg::ref_ptr<osg::Texture2D> cloudTex
|
||||
= new osg::Texture2D(mSceneManager->getImageManager()->getImage(texture));
|
||||
|
@ -790,7 +792,8 @@ namespace MWRender
|
|||
|
||||
if (!mNextClouds.empty())
|
||||
{
|
||||
std::string texture = Misc::ResourceHelpers::correctTexturePath(mNextClouds, mSceneManager->getVFS());
|
||||
const VFS::Path::Normalized texture
|
||||
= Misc::ResourceHelpers::correctTexturePath(mNextClouds, mSceneManager->getVFS());
|
||||
|
||||
osg::ref_ptr<osg::Texture2D> cloudTex
|
||||
= new osg::Texture2D(mSceneManager->getImageManager()->getImage(texture));
|
||||
|
|
|
@ -406,7 +406,7 @@ namespace MWRender
|
|||
}
|
||||
}
|
||||
|
||||
void setTextures(const std::string& phaseTex, const std::string& circleTex)
|
||||
void setTextures(VFS::Path::NormalizedView phaseTex, VFS::Path::NormalizedView circleTex)
|
||||
{
|
||||
mPhaseTex = new osg::Texture2D(mImageManager.getImage(phaseTex));
|
||||
mPhaseTex->setWrap(osg::Texture::WRAP_S, osg::Texture::CLAMP_TO_EDGE);
|
||||
|
@ -766,7 +766,9 @@ namespace MWRender
|
|||
|
||||
Resource::ImageManager& imageManager = *sceneManager.getImageManager();
|
||||
|
||||
osg::ref_ptr<osg::Texture2D> sunTex = new osg::Texture2D(imageManager.getImage("textures/tx_sun_05.dds"));
|
||||
constexpr VFS::Path::NormalizedView image("textures/tx_sun_05.dds");
|
||||
|
||||
osg::ref_ptr<osg::Texture2D> sunTex = new osg::Texture2D(imageManager.getImage(image));
|
||||
sunTex->setWrap(osg::Texture::WRAP_S, osg::Texture::CLAMP_TO_EDGE);
|
||||
sunTex->setWrap(osg::Texture::WRAP_T, osg::Texture::CLAMP_TO_EDGE);
|
||||
|
||||
|
@ -907,8 +909,8 @@ namespace MWRender
|
|||
|
||||
void Sun::createSunFlash(Resource::ImageManager& imageManager)
|
||||
{
|
||||
osg::ref_ptr<osg::Texture2D> tex
|
||||
= new osg::Texture2D(imageManager.getImage("textures/tx_sun_flash_grey_05.dds"));
|
||||
constexpr VFS::Path::NormalizedView image("textures/tx_sun_flash_grey_05.dds");
|
||||
osg::ref_ptr<osg::Texture2D> tex = new osg::Texture2D(imageManager.getImage(image));
|
||||
tex->setWrap(osg::Texture::WRAP_S, osg::Texture::CLAMP_TO_EDGE);
|
||||
tex->setWrap(osg::Texture::WRAP_T, osg::Texture::CLAMP_TO_EDGE);
|
||||
|
||||
|
@ -1115,10 +1117,18 @@ namespace MWRender
|
|||
|
||||
textureName += ".dds";
|
||||
|
||||
const VFS::Path::Normalized texturePath(std::move(textureName));
|
||||
|
||||
if (mType == Moon::Type_Secunda)
|
||||
mUpdater->setTextures(textureName, "textures/tx_mooncircle_full_s.dds");
|
||||
{
|
||||
constexpr VFS::Path::NormalizedView secunda("textures/tx_mooncircle_full_s.dds");
|
||||
mUpdater->setTextures(texturePath, secunda);
|
||||
}
|
||||
else
|
||||
mUpdater->setTextures(textureName, "textures/tx_mooncircle_full_m.dds");
|
||||
{
|
||||
constexpr VFS::Path::NormalizedView masser("textures/tx_mooncircle_full_m.dds");
|
||||
mUpdater->setTextures(texturePath, masser);
|
||||
}
|
||||
}
|
||||
|
||||
int RainCounter::numParticlesToCreate(double dt) const
|
||||
|
|
|
@ -49,7 +49,8 @@ namespace MWRender
|
|||
{
|
||||
if (texture.empty())
|
||||
return;
|
||||
std::string correctedTexture = Misc::ResourceHelpers::correctTexturePath(texture, resourceSystem->getVFS());
|
||||
const VFS::Path::Normalized correctedTexture
|
||||
= Misc::ResourceHelpers::correctTexturePath(texture, resourceSystem->getVFS());
|
||||
// Not sure if wrap settings should be pulled from the overridden texture?
|
||||
osg::ref_ptr<osg::Texture2D> tex
|
||||
= new osg::Texture2D(resourceSystem->getImageManager()->getImage(correctedTexture));
|
||||
|
|
|
@ -589,8 +589,8 @@ namespace MWRender
|
|||
{
|
||||
std::ostringstream texname;
|
||||
texname << "textures/water/" << texture << std::setw(2) << std::setfill('0') << i << ".dds";
|
||||
osg::ref_ptr<osg::Texture2D> tex(
|
||||
new osg::Texture2D(mResourceSystem->getImageManager()->getImage(texname.str())));
|
||||
const VFS::Path::Normalized path(texname.str());
|
||||
osg::ref_ptr<osg::Texture2D> tex(new osg::Texture2D(mResourceSystem->getImageManager()->getImage(path)));
|
||||
tex->setWrap(osg::Texture::WRAP_S, osg::Texture::REPEAT);
|
||||
tex->setWrap(osg::Texture::WRAP_T, osg::Texture::REPEAT);
|
||||
mResourceSystem->getSceneManager()->applyFilterSettings(tex);
|
||||
|
@ -703,8 +703,9 @@ namespace MWRender
|
|||
Shader::ShaderManager& shaderMgr = mResourceSystem->getSceneManager()->getShaderManager();
|
||||
osg::ref_ptr<osg::Program> program = shaderMgr.getProgram("water", defineMap);
|
||||
|
||||
constexpr VFS::Path::NormalizedView waterImage("textures/omw/water_nm.png");
|
||||
osg::ref_ptr<osg::Texture2D> normalMap(
|
||||
new osg::Texture2D(mResourceSystem->getImageManager()->getImage("textures/omw/water_nm.png")));
|
||||
new osg::Texture2D(mResourceSystem->getImageManager()->getImage(waterImage)));
|
||||
normalMap->setWrap(osg::Texture::WRAP_S, osg::Texture::REPEAT);
|
||||
normalMap->setWrap(osg::Texture::WRAP_T, osg::Texture::REPEAT);
|
||||
mResourceSystem->getSceneManager()->applyFilterSettings(normalMap);
|
||||
|
|
|
@ -445,7 +445,8 @@ namespace fx
|
|||
else if (key == "source")
|
||||
{
|
||||
expect<Lexer::String>();
|
||||
auto image = mImageManager.getImage(std::string{ std::get<Lexer::String>(mToken).value }, is3D);
|
||||
const osg::ref_ptr<osg::Image> image
|
||||
= mImageManager.getImage(VFS::Path::Normalized(std::get<Lexer::String>(mToken).value), is3D);
|
||||
if constexpr (is1D)
|
||||
{
|
||||
type = Types::SamplerType::Texture_1D;
|
||||
|
|
|
@ -95,7 +95,7 @@ namespace osgMyGUI
|
|||
if (!mImageManager)
|
||||
throw std::runtime_error("No imagemanager set");
|
||||
|
||||
osg::ref_ptr<osg::Image> image(mImageManager->getImage(fname));
|
||||
osg::ref_ptr<osg::Image> image(mImageManager->getImage(VFS::Path::toNormalized(fname)));
|
||||
mTexture = new osg::Texture2D(image);
|
||||
mTexture->setWrap(osg::Texture::WRAP_S, osg::Texture::CLAMP_TO_EDGE);
|
||||
mTexture->setWrap(osg::Texture::WRAP_T, osg::Texture::CLAMP_TO_EDGE);
|
||||
|
|
|
@ -1022,8 +1022,8 @@ namespace NifOsg
|
|||
if (!mImageManager)
|
||||
return nullptr;
|
||||
|
||||
std::string filename = Misc::ResourceHelpers::correctTexturePath(path, mImageManager->getVFS());
|
||||
return mImageManager->getImage(filename);
|
||||
return mImageManager->getImage(
|
||||
VFS::Path::toNormalized(Misc::ResourceHelpers::correctTexturePath(path, mImageManager->getVFS())));
|
||||
}
|
||||
|
||||
osg::ref_ptr<osg::Texture2D> attachTexture(const std::string& name, osg::ref_ptr<osg::Image> image, bool wrapS,
|
||||
|
|
|
@ -85,11 +85,9 @@ namespace Resource
|
|||
return true;
|
||||
}
|
||||
|
||||
osg::ref_ptr<osg::Image> ImageManager::getImage(std::string_view filename, bool disableFlip)
|
||||
osg::ref_ptr<osg::Image> ImageManager::getImage(VFS::Path::NormalizedView path, bool disableFlip)
|
||||
{
|
||||
const std::string normalized = VFS::Path::normalizeFilename(filename);
|
||||
|
||||
osg::ref_ptr<osg::Object> obj = mCache->getRefFromObjectCache(normalized);
|
||||
osg::ref_ptr<osg::Object> obj = mCache->getRefFromObjectCache(path);
|
||||
if (obj)
|
||||
return osg::ref_ptr<osg::Image>(static_cast<osg::Image*>(obj.get()));
|
||||
else
|
||||
|
@ -97,21 +95,21 @@ namespace Resource
|
|||
Files::IStreamPtr stream;
|
||||
try
|
||||
{
|
||||
stream = mVFS->get(normalized);
|
||||
stream = mVFS->get(path);
|
||||
}
|
||||
catch (std::exception& e)
|
||||
{
|
||||
Log(Debug::Error) << "Failed to open image: " << e.what();
|
||||
mCache->addEntryToObjectCache(normalized, mWarningImage);
|
||||
mCache->addEntryToObjectCache(path.value(), mWarningImage);
|
||||
return mWarningImage;
|
||||
}
|
||||
|
||||
const std::string ext(Misc::getFileExtension(normalized));
|
||||
const std::string ext(Misc::getFileExtension(path.value()));
|
||||
osgDB::ReaderWriter* reader = osgDB::Registry::instance()->getReaderWriterForExtension(ext);
|
||||
if (!reader)
|
||||
{
|
||||
Log(Debug::Error) << "Error loading " << filename << ": no readerwriter for '" << ext << "' found";
|
||||
mCache->addEntryToObjectCache(normalized, mWarningImage);
|
||||
Log(Debug::Error) << "Error loading " << path << ": no readerwriter for '" << ext << "' found";
|
||||
mCache->addEntryToObjectCache(path.value(), mWarningImage);
|
||||
return mWarningImage;
|
||||
}
|
||||
|
||||
|
@ -123,8 +121,8 @@ namespace Resource
|
|||
stream->read((char*)header, 18);
|
||||
if (stream->gcount() != 18)
|
||||
{
|
||||
Log(Debug::Error) << "Error loading " << filename << ": couldn't read TGA header";
|
||||
mCache->addEntryToObjectCache(normalized, mWarningImage);
|
||||
Log(Debug::Error) << "Error loading " << path << ": couldn't read TGA header";
|
||||
mCache->addEntryToObjectCache(path.value(), mWarningImage);
|
||||
return mWarningImage;
|
||||
}
|
||||
int type = header[2];
|
||||
|
@ -142,23 +140,22 @@ namespace Resource
|
|||
= reader->readImage(*stream, disableFlip ? mOptionsNoFlip : mOptions);
|
||||
if (!result.success())
|
||||
{
|
||||
Log(Debug::Error) << "Error loading " << filename << ": " << result.message() << " code "
|
||||
Log(Debug::Error) << "Error loading " << path << ": " << result.message() << " code "
|
||||
<< result.status();
|
||||
mCache->addEntryToObjectCache(normalized, mWarningImage);
|
||||
mCache->addEntryToObjectCache(path.value(), mWarningImage);
|
||||
return mWarningImage;
|
||||
}
|
||||
|
||||
osg::ref_ptr<osg::Image> image = result.getImage();
|
||||
|
||||
image->setFileName(normalized);
|
||||
image->setFileName(std::string(path.value()));
|
||||
if (!checkSupported(image))
|
||||
{
|
||||
static bool uncompress = (getenv("OPENMW_DECOMPRESS_TEXTURES") != nullptr);
|
||||
if (!uncompress)
|
||||
{
|
||||
Log(Debug::Error) << "Error loading " << filename
|
||||
<< ": no S3TC texture compression support installed";
|
||||
mCache->addEntryToObjectCache(normalized, mWarningImage);
|
||||
Log(Debug::Error) << "Error loading " << path << ": no S3TC texture compression support installed";
|
||||
mCache->addEntryToObjectCache(path.value(), mWarningImage);
|
||||
return mWarningImage;
|
||||
}
|
||||
else
|
||||
|
@ -189,7 +186,7 @@ namespace Resource
|
|||
image = newImage;
|
||||
}
|
||||
|
||||
mCache->addEntryToObjectCache(normalized, image);
|
||||
mCache->addEntryToObjectCache(path.value(), image);
|
||||
return image;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,13 +1,12 @@
|
|||
#ifndef OPENMW_COMPONENTS_RESOURCE_IMAGEMANAGER_H
|
||||
#define OPENMW_COMPONENTS_RESOURCE_IMAGEMANAGER_H
|
||||
|
||||
#include <map>
|
||||
#include <string>
|
||||
|
||||
#include <osg/Image>
|
||||
#include <osg/Texture2D>
|
||||
#include <osg/ref_ptr>
|
||||
|
||||
#include <components/vfs/pathutil.hpp>
|
||||
|
||||
#include "resourcemanager.hpp"
|
||||
|
||||
namespace osgDB
|
||||
|
@ -28,7 +27,7 @@ namespace Resource
|
|||
|
||||
/// Create or retrieve an Image
|
||||
/// Returns the dummy image if the given image is not found.
|
||||
osg::ref_ptr<osg::Image> getImage(std::string_view filename, bool disableFlip = false);
|
||||
osg::ref_ptr<osg::Image> getImage(VFS::Path::NormalizedView path, bool disableFlip = false);
|
||||
|
||||
osg::Image* getWarningImage();
|
||||
|
||||
|
|
|
@ -627,7 +627,8 @@ namespace Resource
|
|||
filePath = std::filesystem::relative(filename, osgDB::getCurrentWorkingDirectory());
|
||||
try
|
||||
{
|
||||
return osgDB::ReaderWriter::ReadResult(mImageManager->getImage(Files::pathToUnicodeString(filePath)),
|
||||
return osgDB::ReaderWriter::ReadResult(
|
||||
mImageManager->getImage(VFS::Path::toNormalized(Files::pathToUnicodeString(filePath))),
|
||||
osgDB::ReaderWriter::ReadResult::FILE_LOADED);
|
||||
}
|
||||
catch (std::exception& e)
|
||||
|
|
|
@ -221,7 +221,7 @@ namespace SceneUtil
|
|||
std::vector<osg::ref_ptr<osg::Texture2D>> textures;
|
||||
for (const std::string& name : glowTextureNames)
|
||||
{
|
||||
osg::ref_ptr<osg::Image> image = resourceSystem->getImageManager()->getImage(name);
|
||||
osg::ref_ptr<osg::Image> image = resourceSystem->getImageManager()->getImage(VFS::Path::toNormalized(name));
|
||||
osg::ref_ptr<osg::Texture2D> tex(new osg::Texture2D(image));
|
||||
tex->setWrap(osg::Texture::WRAP_S, osg::Texture2D::REPEAT);
|
||||
tex->setWrap(osg::Texture::WRAP_T, osg::Texture2D::REPEAT);
|
||||
|
|
|
@ -404,17 +404,19 @@ namespace Shader
|
|||
bool normalHeight = false;
|
||||
std::string normalHeightMap = normalMapFileName;
|
||||
Misc::StringUtils::replaceLast(normalHeightMap, ".", mNormalHeightMapPattern + ".");
|
||||
if (mImageManager.getVFS()->exists(normalHeightMap))
|
||||
const VFS::Path::Normalized normalHeightMapPath(normalHeightMap);
|
||||
if (mImageManager.getVFS()->exists(normalHeightMapPath))
|
||||
{
|
||||
image = mImageManager.getImage(normalHeightMap);
|
||||
image = mImageManager.getImage(normalHeightMapPath);
|
||||
normalHeight = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
Misc::StringUtils::replaceLast(normalMapFileName, ".", mNormalMapPattern + ".");
|
||||
if (mImageManager.getVFS()->exists(normalMapFileName))
|
||||
const VFS::Path::Normalized normalMapPath(normalMapFileName);
|
||||
if (mImageManager.getVFS()->exists(normalMapPath))
|
||||
{
|
||||
image = mImageManager.getImage(normalMapFileName);
|
||||
image = mImageManager.getImage(normalMapPath);
|
||||
}
|
||||
}
|
||||
// Avoid using the auto-detected normal map if it's already being used as a bump map.
|
||||
|
@ -464,9 +466,10 @@ namespace Shader
|
|||
{
|
||||
std::string specularMapFileName = diffuseMap->getImage(0)->getFileName();
|
||||
Misc::StringUtils::replaceLast(specularMapFileName, ".", mSpecularMapPattern + ".");
|
||||
if (mImageManager.getVFS()->exists(specularMapFileName))
|
||||
const VFS::Path::Normalized specularMapPath(specularMapFileName);
|
||||
if (mImageManager.getVFS()->exists(specularMapPath))
|
||||
{
|
||||
osg::ref_ptr<osg::Image> image(mImageManager.getImage(specularMapFileName));
|
||||
osg::ref_ptr<osg::Image> image(mImageManager.getImage(specularMapPath));
|
||||
osg::ref_ptr<osg::Texture2D> specularMapTex(new osg::Texture2D(image));
|
||||
specularMapTex->setTextureSize(image->s(), image->t());
|
||||
specularMapTex->setWrap(osg::Texture::WRAP_S, diffuseMap->getWrap(osg::Texture::WRAP_S));
|
||||
|
|
|
@ -44,7 +44,8 @@ namespace Terrain
|
|||
return static_cast<osg::Texture2D*>(obj.get());
|
||||
else
|
||||
{
|
||||
osg::ref_ptr<osg::Texture2D> texture(new osg::Texture2D(mSceneManager->getImageManager()->getImage(name)));
|
||||
osg::ref_ptr<osg::Texture2D> texture(
|
||||
new osg::Texture2D(mSceneManager->getImageManager()->getImage(VFS::Path::toNormalized(name))));
|
||||
texture->setWrap(osg::Texture::WRAP_S, osg::Texture::REPEAT);
|
||||
texture->setWrap(osg::Texture::WRAP_T, osg::Texture::REPEAT);
|
||||
mSceneManager->applyFilterSettings(texture);
|
||||
|
|
Loading…
Reference in a new issue