]> git.mxchange.org Git - flightgear.git/blobdiff - Objects/material.cxx
Changes from NHV to make the code more dynamic with fewer hard coded limits.
[flightgear.git] / Objects / material.cxx
index b4c48228b95f2d500b036cddb0082d0470436e64..d5210dc0085ae4f15efe8b7f4fea63c3616357dc 100644 (file)
@@ -55,8 +55,8 @@ fgMATERIAL_MGR material_mgr;
 // Constructor
 fgMATERIAL::fgMATERIAL ( void )
     : texture_name(""),
-      alpha(0),
-      list_size(0)
+      alpha(0)
+      // , list_size(0)
 {
     ambient[0]  = ambient[1]  = ambient[2]  = ambient[3]  = 0.0;
     diffuse[0]  = diffuse[1]  = diffuse[2]  = diffuse[3]  = 0.0;
@@ -64,26 +64,25 @@ fgMATERIAL::fgMATERIAL ( void )
     emissive[0] = emissive[1] = emissive[2] = emissive[3] = 0.0;
 }
 
-
-int fgMATERIAL::append_sort_list( fgFRAGMENT *object ) {
-    if ( list_size < FG_MAX_MATERIAL_FRAGS )
-    {
+/*
+int
+fgMATERIAL::append_sort_list( fgFRAGMENT *object )
+{
+    if ( list_size < FG_MAX_MATERIAL_FRAGS ) {
        list[ list_size++ ] = object;
        return 1;
-    }
-    else
-    {
+    } else {
        return 0;
     }
 }
+*/
 
 istream&
 operator >> ( istream& in, fgMATERIAL& m )
 {
     string token;
 
-    for (;;)
-    {
+    for (;;) {
        in >> token;
        if ( token == "texture" )
        {
@@ -134,8 +133,6 @@ operator >> ( istream& in, fgMATERIAL& m )
 void
 fgMATERIAL::load_texture()
 {
-    if ( current_options.get_textures() )
-    {
        GLubyte *texbuf;
        int width, height;
 
@@ -215,7 +212,6 @@ fgMATERIAL::load_texture()
            xglTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0,
                          GL_RGBA, GL_UNSIGNED_BYTE, texbuf);
        }
-    }
 }
 
 
@@ -226,6 +222,7 @@ fgMATERIAL::~fgMATERIAL ( void ) {
 
 // Constructor
 fgMATERIAL_MGR::fgMATERIAL_MGR ( void ) {
+    textures_loaded = false;
 }
 
 
@@ -252,9 +249,11 @@ fgMATERIAL::render_fragments()
     }
 
     fgTILE* last_tile_ptr = NULL;
-    for ( size_t i = 0; i < list_size; ++i )
-    {
-       fgFRAGMENT* frag_ptr = list[i];
+    frag_list_iterator current = list.begin();
+    frag_list_iterator last = list.end();
+
+    for ( ; current != last; ++current ) {
+       fgFRAGMENT* frag_ptr = *current;
        current_view.tris_rendered += frag_ptr->num_faces();
        if ( frag_ptr->tile_ptr != last_tile_ptr )
        {
@@ -271,7 +270,9 @@ fgMATERIAL::render_fragments()
 
 
 // Load a library of material properties
-int fgMATERIAL_MGR::load_lib ( void ) {
+int
+fgMATERIAL_MGR::load_lib ( void )
+{
     string material_name;
 
     // build the path name to the material db
@@ -297,23 +298,27 @@ int fgMATERIAL_MGR::load_lib ( void ) {
            printf( "  Loading material %s\n", material_name.c_str() );
            fgMATERIAL m;
            in.stream() >> m;
-           m.load_texture();
+
+           if ( current_options.get_textures() ) {
+               m.load_texture();
+           }
+
            material_mgr.material_map[material_name] = m;
        }
     }
 
-//     iterator last = end();
-//     for ( iterator it = begin(); it != last; ++it )
-//     {
-//     (*it).second.load_texture();
-//     }
+    if ( current_options.get_textures() ) {
+       textures_loaded = true;
+    }
 
     return(1);
 }
 
 
 // Initialize the transient list of fragments for each material property
-void fgMATERIAL_MGR::init_transient_material_lists( void ) {
+void
+fgMATERIAL_MGR::init_transient_material_lists( void )
+{
     iterator last = end();
     for ( iterator it = begin(); it != last; ++it )
     {
@@ -321,6 +326,7 @@ void fgMATERIAL_MGR::init_transient_material_lists( void ) {
     }
 }
 
+
 bool
 fgMATERIAL_MGR::find( const string& material, fgMATERIAL*& mtl_ptr )
 {
@@ -351,6 +357,12 @@ fgMATERIAL_MGR::render_fragments()
 
 
 // $Log$
+// Revision 1.8  1998/10/12 23:49:17  curt
+// Changes from NHV to make the code more dynamic with fewer hard coded limits.
+//
+// Revision 1.7  1998/09/17 18:35:52  curt
+// Tweaks and optimizations by Norman Vine.
+//
 // Revision 1.6  1998/09/15 01:35:05  curt
 // cleaned up my fragment.num_faces hack :-) to use the STL (no need in
 // duplicating work.)