- // First, all the texture properties
- const SGPropertyNode* pTexture2d = prop->getChild("texture2d");
- if (!pTexture2d)
- return;
- const SGPropertyNode* pImage
- = getEffectPropertyChild(effect, pTexture2d, "image");
- if (!pImage)
- return;
- const char* imageName = pImage->getStringValue();
- Texture::FilterMode minFilter = Texture::LINEAR_MIPMAP_LINEAR;
- findAttr(filterModes, getEffectPropertyChild(effect, pTexture2d, "filter"),
- minFilter);
- Texture::FilterMode magFilter = Texture::LINEAR;
- findAttr(filterModes, getEffectPropertyChild(effect, pTexture2d,
- "mag-filter"),
- magFilter);
- const SGPropertyNode* pWrapS
- = getEffectPropertyChild(effect, pTexture2d, "wrap-s");
- Texture::WrapMode sWrap = Texture::CLAMP;
- findAttr(wrapModes, pWrapS, sWrap);
- const SGPropertyNode* pWrapT
- = getEffectPropertyChild(effect, pTexture2d, "wrap-t");
- Texture::WrapMode tWrap = Texture::CLAMP;
- findAttr(wrapModes, pWrapT, tWrap);
- const SGPropertyNode* pWrapR
- = getEffectPropertyChild(effect, pTexture2d, "wrap-r");
- Texture::WrapMode rWrap = Texture::CLAMP;
- findAttr(wrapModes, pWrapR, rWrap);
- TexTuple tuple(imageName, minFilter, magFilter, sWrap, tWrap, rWrap);
- TexMap::iterator texIter = texMap.find(tuple);
- Texture2D* texture = 0;
- if (texIter != texMap.end()) {
- texture = texIter->second.get();
- } else {
- texture = new Texture2D;
- osgDB::ReaderWriter::ReadResult result
- = osgDB::Registry::instance()->readImage(imageName, options);
- if (result.success()) {
- osg::Image* image = result.getImage();
- texture->setImage(image);
- int s = image->s();
- int t = image->t();
-
- if (s <= t && 32 <= s) {
- SGSceneFeatures::instance()->setTextureCompression(texture);
- } else if (t < s && 32 <= t) {
- SGSceneFeatures::instance()->setTextureCompression(texture);
- }
- texture->setMaxAnisotropy(SGSceneFeatures::instance()
- ->getTextureFilter());
- } else {
- SG_LOG(SG_INPUT, SG_ALERT, "failed to load effect texture file "
- << imageName);
- }
- // texture->setDataVariance(osg::Object::STATIC);
- texture->setFilter(Texture::MIN_FILTER, minFilter);
- texture->setFilter(Texture::MAG_FILTER, magFilter);
- texture->setWrap(Texture::WRAP_S, sWrap);
- texture->setWrap(Texture::WRAP_T, tWrap);
- texture->setWrap(Texture::WRAP_R, rWrap);
- texMap.insert(make_pair(tuple, texture));
- }
- // Decode the texture unit
- int unit = 0;
- const SGPropertyNode* pUnit = prop->getChild("unit");
- if (pUnit) {
- unit = pUnit->getValue<int>();
- } else {
- const SGPropertyNode* pName = prop->getChild("name");
- if (pName)
- try {
- unit = boost::lexical_cast<int>(pName->getStringValue());
- } catch (boost::bad_lexical_cast& lex) {
- SG_LOG(SG_INPUT, SG_ALERT, "can't decode name as texture unit "
- << lex.what());
- }
- }
- pass->setTextureAttributeAndModes(unit, texture);
- const SGPropertyNode* envProp = prop->getChild("environment");
- if (envProp) {
- TexEnv* env = buildTexEnv(effect, envProp);
- if (env)
- pass->setTextureAttributeAndModes(unit, env);
- }