]> git.mxchange.org Git - flightgear.git/blobdiff - src/Objects/matlib.cxx
I'm attaching diffs to add a new FGInput module to FlightGear
[flightgear.git] / src / Objects / matlib.cxx
index 69f9c2b5a363553609a853ab51e5d8c2627be86c..ac2be6b947324c9dc2168562000846a405ad965d 100644 (file)
@@ -34,7 +34,7 @@
 #endif
 
 #include <GL/glut.h>
-#include <simgear/xgl/xgl.h>
+#include <GL/gl.h>
 
 #include <simgear/compiler.h>
 
@@ -42,8 +42,8 @@
 #include STL_STRING
 
 #include <simgear/debug/logstream.hxx>
-#include <simgear/misc/fgpath.hxx>
-#include <simgear/misc/fgstream.hxx>
+#include <simgear/misc/sg_path.hxx>
+#include <simgear/misc/sgstream.hxx>
 
 #include <Include/general.hxx>
 #include <Main/globals.hxx>
@@ -52,7 +52,7 @@
 
 #include "matlib.hxx"
 
-FG_USING_STD(string);
+SG_USING_STD(string);
 
 
 // global material management class
@@ -65,7 +65,7 @@ FGMaterialLib::FGMaterialLib ( void ) {
 
 
 static bool local_file_exists( const string& path ) {
-    fg_gzifstream in( path );
+    sg_gzifstream in( path );
     if ( ! in.is_open() ) {
        return false;
     } else {
@@ -90,9 +90,9 @@ static bool local_file_exists( const string& path ) {
 bool FGMaterialLib::load( const string& mpath ) {
     string material_name;
 
-    fg_gzifstream in( mpath );
+    sg_gzifstream in( mpath );
     if ( ! in.is_open() ) {
-       FG_LOG( FG_GENERAL, FG_ALERT, "Cannot open file: " << mpath );
+       SG_LOG( SG_GENERAL, SG_ALERT, "Cannot open file: " << mpath );
        exit(-1);
     }
 
@@ -117,7 +117,7 @@ bool FGMaterialLib::load( const string& mpath ) {
        if ( material_name == "alias" ) {
            string src_mat, dst_mat;
            in >> dst_mat >> src_mat;
-           FG_LOG( FG_GENERAL, FG_INFO, "  Material alias: " << dst_mat <<
+           SG_LOG( SG_GENERAL, SG_INFO, "  Material alias: " << dst_mat <<
                    " mapped to " << src_mat );
            FGNewMat m = matlib[src_mat];
            matlib[dst_mat] = m;
@@ -129,18 +129,17 @@ bool FGMaterialLib::load( const string& mpath ) {
                in >> m;
 
                // build the ssgSimpleState
-               FGPath tex_path( globals->get_fg_root() );
+               SGPath tex_path( globals->get_fg_root() );
                tex_path.append( "Textures.high" );
-
-               FGPath tmp_path = tex_path;
-               tmp_path.append( m.get_texture_name() );
-               if ( ! local_file_exists(tmp_path.str())
+               tex_path.append( m.get_texture_name() );
+               if ( ! local_file_exists(tex_path.str())
                     || general.get_glMaxTexSize() < 512 ) {
-                   tex_path = FGPath( globals->get_fg_root() );
+                   tex_path = SGPath( globals->get_fg_root() );
                    tex_path.append( "Textures" );
+                   tex_path.append( m.get_texture_name() );
                }
            
-               FG_LOG( FG_TERRAIN, FG_INFO, "  Loading material " 
+               SG_LOG( SG_TERRAIN, SG_INFO, "  Loading material " 
                        << material_name << " (" << tex_path.c_str() << ")");
 
                GLenum shade_model = GL_SMOOTH;
@@ -150,8 +149,10 @@ bool FGMaterialLib::load( const string& mpath ) {
                    shade_model = GL_FLAT;
                }
 
-               m.build_ssg_state( tex_path.str(), shade_model,
-                                  fgGetBool("/sim/rendering/textures") );
+               m.set_texture_name( tex_path.str() );
+               m.build_ssg_state( shade_model,
+                                  fgGetBool("/sim/rendering/textures"),
+                                  false );
 
 #if EXTRA_DEBUG
                m.dump_info();
@@ -201,10 +202,10 @@ bool FGMaterialLib::add_item ( const string &mat_name, const string &full_path )
     string tex_name = full_path.substr( pos + 1 );
     string tex_path = full_path.substr( 0, pos );
 
-    FGNewMat m( mat_name, tex_name );
+    FGNewMat m( mat_name, full_path );
 
-    FG_LOG( FG_TERRAIN, FG_INFO, "  Loading material " 
-           << mat_name << " (" << tex_path << ")");
+    SG_LOG( SG_TERRAIN, SG_INFO, "  Loading material " 
+           << mat_name << " (" << full_path << ")");
 
 #if EXTRA_DEBUG
     m.dump_info();
@@ -217,8 +218,8 @@ bool FGMaterialLib::add_item ( const string &mat_name, const string &full_path )
        shade_model = GL_FLAT;
     }
 
-    m.build_ssg_state( tex_path, shade_model,
-                      fgGetBool("/sim/rendering/textures") );
+    m.build_ssg_state( shade_model, fgGetBool("/sim/rendering/textures"),
+                      true );
 
     material_lib.matlib[mat_name] = m;
 
@@ -232,7 +233,7 @@ bool FGMaterialLib::add_item ( const string &mat_name, ssgSimpleState *state )
     FGNewMat m( mat_name );
     m.set_ssg_state( state );
 
-    FG_LOG( FG_TERRAIN, FG_INFO, "  Loading material given a premade "
+    SG_LOG( SG_TERRAIN, SG_INFO, "  Loading material given a premade "
            << "ssgSimpleState = " << mat_name );
 
 #if EXTRA_DEBUG
@@ -269,7 +270,7 @@ void FGMaterialLib::set_step ( int step )
     // container::iterator it = begin();
     for ( material_map_iterator it = begin(); it != end(); it++ ) {
        const string &key = it->first;
-       FG_LOG( FG_GENERAL, FG_INFO,
+       SG_LOG( SG_GENERAL, SG_INFO,
                "Updating material " << key << " to step " << step );
        FGNewMat &slot = it->second;
        slot.get_state()->selectStep(step);
@@ -277,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 );
+#else
+            slot.get_textured()->
+                setTexture( (char *)slot.get_texture_name_c_str(), 0, 0, 1 );
+#endif
+            slot.set_texture_loaded( true );
+        }
+    }
+}