X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=simgear%2Fscene%2Fmaterial%2FTextureBuilder.cxx;h=0c141c475c3415b627c354ad8cb53b4a1d52eb69;hb=aef8f13290c74359c1a7a54bd5e6e375b3f0c49e;hp=0e487a99bd7c84b39c173d7001abf6d4bebe96f8;hpb=5b734d8c527c291cccf7c366fd4b3a741409fb82;p=simgear.git diff --git a/simgear/scene/material/TextureBuilder.cxx b/simgear/scene/material/TextureBuilder.cxx index 0e487a99..0c141c47 100644 --- a/simgear/scene/material/TextureBuilder.cxx +++ b/simgear/scene/material/TextureBuilder.cxx @@ -32,12 +32,13 @@ #include #include #include +#include #include #include #include -#include +#include #include #include #include @@ -54,13 +55,13 @@ using namespace effect; TexEnvCombine* buildTexEnvCombine(Effect* effect, const SGPropertyNode* envProp, - const SGReaderWriterXMLOptions* options); + const SGReaderWriterOptions* options); TexGen* buildTexGen(Effect* Effect, const SGPropertyNode* tgenProp); // Hack to force inclusion of TextureBuilder.cxx in library osg::Texture* TextureBuilder::buildFromType(Effect* effect, const string& type, const SGPropertyNode*props, - const SGReaderWriterXMLOptions* + const SGReaderWriterOptions* options) { return EffectBuilder::buildFromType(effect, type, props, options); @@ -102,7 +103,7 @@ TexEnv* buildTexEnv(Effect* effect, const SGPropertyNode* prop) void TextureUnitBuilder::buildAttribute(Effect* effect, Pass* pass, const SGPropertyNode* prop, - const SGReaderWriterXMLOptions* options) + const SGReaderWriterOptions* options) { if (!isAttributeActive(effect, prop)) return; @@ -132,8 +133,8 @@ void TextureUnitBuilder::buildAttribute(Effect* effect, Pass* pass, texture = TextureBuilder::buildFromType(effect, type, prop, options); } - catch (BuilderException& ) { - SG_LOG(SG_INPUT, SG_ALERT, "No image file, " + catch (BuilderException& e) { + SG_LOG(SG_INPUT, SG_ALERT, e.getFormattedMessage() << ", " << "maybe the reader did not set the filename attribute, " << "using white for type '" << type << "' on '" << pass->getName() << "', in " << prop->getPath() ); texture = StateAttributeFactory::instance()->getWhiteTexture(); @@ -183,7 +184,7 @@ EffectNameValue wrapModesInit[] = EffectPropertyMap wrapModes(wrapModesInit); TexTuple makeTexTuple(Effect* effect, const SGPropertyNode* props, - const SGReaderWriterXMLOptions* options, + const SGReaderWriterOptions* options, const string& texType) { Texture::FilterMode minFilter = Texture::LINEAR_MIPMAP_LINEAR; @@ -211,9 +212,17 @@ TexTuple makeTexTuple(Effect* effect, const SGPropertyNode* props, const SGPropertyNode* pImage = getEffectPropertyChild(effect, props, "image"); string imageName; + string absFileName; if (pImage) + { imageName = pImage->getStringValue(); - string absFileName = osgDB::findDataFile(imageName, options); + absFileName = SGModelLib::findDataFile(imageName, options); + if (absFileName.empty()) + { + SG_LOG(SG_INPUT, SG_ALERT, "Texture file not found: '" + << imageName << "'"); + } + } const SGPropertyNode* pMipmapControl = getEffectPropertyChild(effect, props, "mipmap-control"); @@ -226,14 +235,14 @@ TexTuple makeTexTuple(Effect* effect, const SGPropertyNode* props, } void setAttrs(const TexTuple& attrs, Texture* tex, - const SGReaderWriterXMLOptions* options) + const SGReaderWriterOptions* options) { const string& imageName = attrs.get<0>(); if (imageName.empty()) { throw BuilderException("no image file"); } else { - osgDB::ReaderWriter::ReadResult result - = osgDB::Registry::instance()->readImage(imageName, options); + osgDB::ReaderWriter::ReadResult result; + result = osgDB::readImageFile(imageName, options); if (result.success()) { osg::ref_ptr image = result.getImage(); image = computeMipmap( image.get(), attrs.get<7>() ); @@ -267,7 +276,7 @@ class TexBuilder : public TextureBuilder public: TexBuilder(const string& texType) : _type(texType) {} Texture* build(Effect* effect, const SGPropertyNode*, - const SGReaderWriterXMLOptions* options); + const SGReaderWriterOptions* options); protected: typedef map > TexMap; TexMap texMap; @@ -276,7 +285,7 @@ protected: template Texture* TexBuilder::build(Effect* effect, const SGPropertyNode* props, - const SGReaderWriterXMLOptions* options) + const SGReaderWriterOptions* options) { TexTuple attrs = makeTexTuple(effect, props, options, _type); typename TexMap::iterator itr = texMap.find(attrs); @@ -300,11 +309,11 @@ class WhiteTextureBuilder : public TextureBuilder { public: Texture* build(Effect* effect, const SGPropertyNode*, - const SGReaderWriterXMLOptions* options); + const SGReaderWriterOptions* options); }; Texture* WhiteTextureBuilder::build(Effect* effect, const SGPropertyNode*, - const SGReaderWriterXMLOptions* options) + const SGReaderWriterOptions* options) { return StateAttributeFactory::instance()->getWhiteTexture(); } @@ -318,11 +327,11 @@ class TransparentTextureBuilder : public TextureBuilder { public: Texture* build(Effect* effect, const SGPropertyNode*, - const SGReaderWriterXMLOptions* options); + const SGReaderWriterOptions* options); }; Texture* TransparentTextureBuilder::build(Effect* effect, const SGPropertyNode*, - const SGReaderWriterXMLOptions* options) + const SGReaderWriterOptions* options) { return StateAttributeFactory::instance()->getTransparentTexture(); } @@ -382,14 +391,14 @@ class NoiseBuilder : public TextureBuilder { public: Texture* build(Effect* effect, const SGPropertyNode*, - const SGReaderWriterXMLOptions* options); + const SGReaderWriterOptions* options); protected: typedef map > NoiseMap; NoiseMap _noises; }; Texture* NoiseBuilder::build(Effect* effect, const SGPropertyNode* props, - const SGReaderWriterXMLOptions* options) + const SGReaderWriterOptions* options) { int texSize = 64; const SGPropertyNode* sizeProp = getEffectPropertyChild(effect, props, @@ -450,7 +459,7 @@ class CubeMapBuilder : public TextureBuilder { public: Texture* build(Effect* effect, const SGPropertyNode*, - const SGReaderWriterXMLOptions* options); + const SGReaderWriterOptions* options); protected: typedef map > CubeMap; typedef map > CrossCubeMap; @@ -473,7 +482,7 @@ void copySubImage(const osg::Image* srcImage, int src_s, int src_t, int width, i Texture* CubeMapBuilder::build(Effect* effect, const SGPropertyNode* props, - const SGReaderWriterXMLOptions* options) + const SGReaderWriterOptions* options) { // First check that there is a tag const SGPropertyNode* texturesProp = getEffectPropertyChild(effect, props, "images"); @@ -503,33 +512,33 @@ Texture* CubeMapBuilder::build(Effect* effect, const SGPropertyNode* props, cubeTexture->setWrap(osg::Texture3D::WRAP_T, osg::Texture::CLAMP_TO_EDGE); cubeTexture->setWrap(osg::Texture3D::WRAP_R, osg::Texture::CLAMP_TO_EDGE); - osgDB::ReaderWriter::ReadResult result = - osgDB::Registry::instance()->readImage(_tuple.get<0>(), options); + osgDB::ReaderWriter::ReadResult result; + result = osgDB::readImageFile(_tuple.get<0>(), options); if(result.success()) { osg::Image* image = result.getImage(); cubeTexture->setImage(TextureCubeMap::POSITIVE_X, image); } - result = osgDB::Registry::instance()->readImage(_tuple.get<1>(), options); + result = osgDB::readImageFile(_tuple.get<1>(), options); if(result.success()) { osg::Image* image = result.getImage(); cubeTexture->setImage(TextureCubeMap::NEGATIVE_X, image); } - result = osgDB::Registry::instance()->readImage(_tuple.get<2>(), options); + result = osgDB::readImageFile(_tuple.get<2>(), options); if(result.success()) { osg::Image* image = result.getImage(); cubeTexture->setImage(TextureCubeMap::POSITIVE_Y, image); } - result = osgDB::Registry::instance()->readImage(_tuple.get<3>(), options); + result = osgDB::readImageFile(_tuple.get<3>(), options); if(result.success()) { osg::Image* image = result.getImage(); cubeTexture->setImage(TextureCubeMap::NEGATIVE_Y, image); } - result = osgDB::Registry::instance()->readImage(_tuple.get<4>(), options); + result = osgDB::readImageFile(_tuple.get<4>(), options); if(result.success()) { osg::Image* image = result.getImage(); cubeTexture->setImage(TextureCubeMap::POSITIVE_Z, image); } - result = osgDB::Registry::instance()->readImage(_tuple.get<5>(), options); + result = osgDB::readImageFile(_tuple.get<5>(), options); if(result.success()) { osg::Image* image = result.getImage(); cubeTexture->setImage(TextureCubeMap::NEGATIVE_Z, image); @@ -552,8 +561,8 @@ Texture* CubeMapBuilder::build(Effect* effect, const SGPropertyNode* props, if (itr != _crossmaps.end()) return itr->second.get(); - osgDB::ReaderWriter::ReadResult result = - osgDB::Registry::instance()->readImage(texname, options); + osgDB::ReaderWriter::ReadResult result; + result = osgDB::readImageFile(texname, options); if(result.success()) { osg::Image* image = result.getImage(); image->flipVertical(); // Seems like the image coordinates are somewhat funny, flip to get better ones @@ -682,7 +691,7 @@ EffectNameValue opParamInit[] = EffectPropertyMap operandParams(opParamInit); TexEnvCombine* buildTexEnvCombine(Effect* effect, const SGPropertyNode* envProp, - const SGReaderWriterXMLOptions* options) + const SGReaderWriterOptions* options) { if (!isAttributeActive(effect, envProp)) return 0;