X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=simgear%2Fscene%2Fmaterial%2Fmat.cxx;h=2d488f345eb7db8da34c8bbebbba5b3a9fcdd932;hb=373a0e4a7d59c3f8ed1d66ff6145de61ecd46279;hp=595771901db3a93c8d3ee3dbe0467b705efb2190;hpb=702fb014a5ba8f83ec8c5f342bd69586cdefdc9e;p=simgear.git diff --git a/simgear/scene/material/mat.cxx b/simgear/scene/material/mat.cxx index 59577190..2d488f34 100644 --- a/simgear/scene/material/mat.cxx +++ b/simgear/scene/material/mat.cxx @@ -49,9 +49,8 @@ SG_USING_STD(map); #include #include -#include "mat.hxx" -static map > _tex_cache; +#include "mat.hxx" //////////////////////////////////////////////////////////////////////// @@ -101,11 +100,6 @@ SGMaterial::read_properties( const string &fg_root, const SGPropertyNode * props { string tname = textures[i]->getStringValue(); string otname = tname; - if (season && strncmp(season, "summer", 6)) - { - if (tname.substr(0,7) == "Terrain") - tname.insert(7,"."+string(season)); - } if (tname == "") { tname = "unknown.rgb"; @@ -141,8 +135,16 @@ SGMaterial::read_properties( const string &fg_root, const SGPropertyNode * props wrapu = props->getBoolValue("wrapu", true); wrapv = props->getBoolValue("wrapv", true); mipmap = props->getBoolValue("mipmap", true); - filtering = props->getDoubleValue("filtering", 1.0); light_coverage = props->getDoubleValue("light-coverage", 0.0); + tree_coverage = props->getDoubleValue("tree-coverage", 0.0); + tree_height = props->getDoubleValue("tree-height-m", 0.0); + tree_width = props->getDoubleValue("tree-width-m", 0.0); + tree_range = props->getDoubleValue("tree-range-m", 0.0); + tree_varieties = props->getIntValue("tree-varieties", 1); + + SGPath tpath( fg_root ); + tpath.append(props->getStringValue("tree-texture")); + tree_texture = tpath.str(); // surface values for use with ground reactions solid = props->getBoolValue("solid", true); @@ -205,7 +207,6 @@ SGMaterial::init () wrapv = true; mipmap = true; - filtering = 1.0f; light_coverage = 0.0; solid = true; @@ -223,35 +224,24 @@ SGMaterial::init () } } -bool -SGMaterial::load_texture ( int n ) -{ - int i = (n >= 0) ? n : 0 ; - int end = (n >= 0) ? n+1 : _status.size(); - - for (; i < end; i++) - { - if ( !_status[i].texture_loaded ) { - SG_LOG( SG_GENERAL, SG_INFO, "Loading deferred texture " - << _status[i].texture_path ); - assignTexture(_status[i].state.get(), _status[i].texture_path, - wrapu, wrapv, mipmap, filtering ); - _status[i].texture_loaded = true; - } - } - return true; -} - osg::StateSet * -SGMaterial::get_state (int n) const +SGMaterial::get_state (int n) { if (_status.size() == 0) { SG_LOG( SG_GENERAL, SG_WARN, "No state available."); return NULL; } + + int i = n >= 0 ? n : _current_ptr; + + if(!_status[i].texture_loaded) + { + assignTexture(_status[i].state.get(), _status[i].texture_path, + wrapu, wrapv, mipmap); + _status[i].texture_loaded = true; + } + osg::StateSet *st = _status[i].state.get(); - osg::StateSet *st = (n >= 0) ? _status[n].state.get() - : _status[_current_ptr].state.get(); _current_ptr += 1; if (_current_ptr >= _status.size()) _current_ptr = 0; @@ -280,13 +270,7 @@ SGMaterial::build_state( bool defer_tex_load ) stateSet->setMode(GL_LIGHTING, osg::StateAttribute::ON); - if ( !defer_tex_load ) { - SG_LOG(SG_INPUT, SG_INFO, " " << _status[i].texture_path ); - assignTexture( stateSet, _status[i].texture_path, wrapu, wrapv, 1, filtering ); - _status[i].texture_loaded = true; - } else { - _status[i].texture_loaded = false; - } + _status[i].texture_loaded = false; osg::Material* material = new osg::Material; material->setColorMode(osg::Material::AMBIENT_AND_DIFFUSE); @@ -319,23 +303,13 @@ void SGMaterial::set_state( osg::StateSet *s ) } void SGMaterial::assignTexture( osg::StateSet *state, const std::string &fname, - int _wrapu, int _wrapv, int _mipmap, float filtering ) + bool _wrapu, bool _wrapv, bool _mipmap ) { - map >::iterator _tex_cache_iter; - _tex_cache_iter = _tex_cache.find(fname); - if (_tex_cache_iter == _tex_cache.end()) - { - osg::Texture2D* texture = SGLoadTexture2D(fname, _wrapu, _wrapv, - mipmap ? -1 : 0); - texture->setMaxAnisotropy( filtering); - state->setTextureAttributeAndModes(0, texture); - _tex_cache[fname] = texture; - } - else - { - state->setTextureAttributeAndModes(0, _tex_cache_iter->second.get()); - // cout << "Cache hit: " << fname << endl; - } + osg::Texture2D* texture = SGLoadTexture2D(fname, 0, _wrapu, _wrapv, + mipmap ? -1 : 0); + texture->setMaxAnisotropy( SGGetTextureFilter()); + state->setTextureAttributeAndModes(0, texture); + osg::TexEnv* texEnv = new osg::TexEnv; texEnv->setMode(osg::TexEnv::MODULATE); state->setTextureAttributeAndModes(0, texEnv); @@ -362,5 +336,12 @@ SGMaterialGlyph::SGMaterialGlyph(SGPropertyNode *p) : { } +void +SGSetTextureFilter( int max) { + SGSceneFeatures::instance()->setTextureFilter( max); +} -// end of mat.cxx +int +SGGetTextureFilter() { + return SGSceneFeatures::instance()->getTextureFilter(); +}