From a01a26a009b519126037f58ae0cabd903d25c665 Mon Sep 17 00:00:00 2001 From: curt Date: Tue, 15 May 2001 00:01:04 +0000 Subject: [PATCH] Re-added support for loading on-the-fly textures. --- src/Main/main.cxx | 7 ++++++- src/Objects/matlib.cxx | 28 ++++++++++++++++++++-------- src/Objects/matlib.hxx | 4 ++++ src/Objects/newmat.hxx | 8 ++++++++ 4 files changed, 38 insertions(+), 9 deletions(-) diff --git a/src/Main/main.cxx b/src/Main/main.cxx index dacc1abd5..685f5db0b 100644 --- a/src/Main/main.cxx +++ b/src/Main/main.cxx @@ -81,6 +81,7 @@ #ifdef FG_NETWORK_OLK #include #endif +#include #include #include #ifdef ENABLE_AUDIO_SUPPORT @@ -1035,6 +1036,9 @@ static void fgMainLoop( void ) { cur_fdm_state->get_Latitude() * SGD_RADIANS_TO_DEGREES ); + // see if we need to load any deferred-load textures + material_lib.load_next_deferred(); + // Process/manage pending events global_events.Process(); @@ -1525,10 +1529,11 @@ int main( int argc, char **argv ) { 0.0 ); globals->set_ephem( ephem ); + thesky = new SGSky; + SGPath sky_tex_path( globals->get_fg_root() ); sky_tex_path.append( "Textures" ); sky_tex_path.append( "Sky" ); - thesky = new SGSky; thesky->texture_path( sky_tex_path.str() ); thesky->build( 550.0, 550.0, diff --git a/src/Objects/matlib.cxx b/src/Objects/matlib.cxx index 60fa40ea5..bfe1b9992 100644 --- a/src/Objects/matlib.cxx +++ b/src/Objects/matlib.cxx @@ -278,11 +278,23 @@ void FGMaterialLib::set_step ( int step ) } - - - - - - - - +// Load one pending "deferred" texture. Return true if a texture +// loaded successfully, false if no pending, or error. +void FGMaterialLib::load_next_deferred() { + // container::iterator it = begin(); + for ( material_map_iterator it = begin(); it != end(); it++ ) { + const string &key = it->first; + FGNewMat &slot = it->second; + if ( ! slot.get_texture_loaded() ) { + SG_LOG( SG_GENERAL, SG_INFO, "Loading texture for " << key ); +#ifdef PLIB_1_2_X + slot.get_textured()-> + setTexture( (char *)slot.get_texture_name_c_str(), 0, 0, 0 ); +#else + slot.get_textured()-> + setTexture( (char *)slot.get_texture_name_c_str(), 0, 0 ); +#endif + slot.set_texture_loaded( true ); + } + } +} diff --git a/src/Objects/matlib.hxx b/src/Objects/matlib.hxx index ad9ef450a..5bc7543e0 100644 --- a/src/Objects/matlib.hxx +++ b/src/Objects/matlib.hxx @@ -87,6 +87,10 @@ public: void set_step (int step); + // Load one pending "deferred" texture. Return true if a texture + // loaded successfully, false if no pending, or error. + void load_next_deferred(); + material_map_iterator begin() { return matlib.begin(); } const_material_map_iterator begin() const { return matlib.begin(); } diff --git a/src/Objects/newmat.hxx b/src/Objects/newmat.hxx index 39ff8f499..acd9169be 100644 --- a/src/Objects/newmat.hxx +++ b/src/Objects/newmat.hxx @@ -113,8 +113,13 @@ public: inline void set_material_name( const string& n ) { material_name = n; } inline string get_texture_name() const { return texture_name; } + inline const char *get_texture_name_c_str() const { + return texture_name.c_str(); + } inline void set_texture_name( const string& n ) { texture_name = n; } + inline ssgSimpleState *get_textured() { return textured; } + inline double get_xsize() const { return xsize; } inline double get_ysize() const { return ysize; } inline void set_xsize( double x ) { xsize = x; } @@ -129,6 +134,9 @@ public: inline void set_specular( sgVec4 s ) { sgCopyVec4( specular, s ); } inline void set_emission( sgVec4 e ) { sgCopyVec4( emission, e ); } + inline bool get_texture_loaded() const { return texture_loaded; } + inline void set_texture_loaded( bool val ) { texture_loaded = val; } + inline double get_light_coverage () const { return light_coverage; } inline void set_light_coverage (double coverage) { light_coverage = coverage; -- 2.39.5