Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

panda/src/gobj/config_gobj.cxx

Go to the documentation of this file.
00001 // Filename: config_gobj.cxx
00002 // Created by:  drose (01Oct99)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) 2001, Disney Enterprises, Inc.  All rights reserved
00008 //
00009 // All use of this software is subject to the terms of the Panda 3d
00010 // Software license.  You should have received a copy of this license
00011 // along with this source code; you will also find a current copy of
00012 // the license at http://www.panda3d.org/license.txt .
00013 //
00014 // To contact the maintainers of this program write to
00015 // panda3d@yahoogroups.com .
00016 //
00017 ////////////////////////////////////////////////////////////////////
00018 
00019 #include <config_util.h>
00020 #include "boundedObject.h"
00021 #include "config_gobj.h"
00022 #include "drawable.h"
00023 #include "geom.h"
00024 #include "geomprimitives.h"
00025 #include "imageBuffer.h"
00026 #include "material.h"
00027 #include "orthographicLens.h"
00028 #include "matrixLens.h"
00029 #include "perspectiveLens.h"
00030 #include "pixelBuffer.h"
00031 #include "lens.h"
00032 #include "texture.h"
00033 
00034 #include "dconfig.h"
00035 #include "string_utils.h"
00036 
00037 Configure(config_gobj);
00038 NotifyCategoryDef(gobj, "");
00039 
00040 // Set this to the maximum size a texture is allowed to be in either
00041 // dimension.  This is generally intended as a simple way to restrict
00042 // texture sizes for limited graphics cards.  When this is greater
00043 // than zero, each texture image loaded from a file (but only those
00044 // loaded from a file) will be automatically scaled down, if
00045 // necessary, so that neither dimension is larger than this value.
00046 const int max_texture_dimension = config_gobj.GetInt("max-texture-dimension", -1);
00047 
00048 // Set textures-power-2 to force texture dimensions to a power of two.
00049 // If this is "up" or "down", the textures will be scaled up or down
00050 // to the next power of two, as indicated; otherwise, if this is #t,
00051 // the textures will be scaled down.  If this is #f or unspecified,
00052 // the textures will be left at whatever size they are.
00053 
00054 // These are filled in by the ConfigureFn block, below.
00055 bool textures_up_power_2 = false;
00056 bool textures_down_power_2 = false;
00057 
00058 // Set textures-square to force texture dimensions to a square aspect
00059 // ratio.  This works similarly to textures-power-2, above.  If this
00060 // is "up" or "down", the textures will be scaled up or down to the
00061 // containing square or the inscribed square, respectively; otherwise,
00062 // if this is #t, the textures will be scaled down.  If this is #f or
00063 // unspecified, the textures will be left at whatever size they are.
00064 
00065 // These are filled in by the ConfigureFn block, below.
00066 bool textures_up_square = false;
00067 bool textures_down_square = false;
00068 
00069 
00070 // Set this to true to retain the ram image for each texture after it
00071 // has been prepared with the GSG.  This will allow the texture to be
00072 // prepared with multiple GSG, or to be re-prepared later after it is
00073 // explicitly released from the GSG, without having to reread the
00074 // texture image from disk; but it will consume memory somewhat
00075 // wastefully.
00076 bool keep_texture_ram = config_gobj.GetBool("keep-texture-ram", false);
00077 
00078 // Ditto for Geom's.  This is a little more dangerous, because if
00079 // anyone calls release_all_geoms() on the GSG, we won't be able to
00080 // restore them automatically.
00081 bool keep_geom_ram = config_gobj.GetBool("keep-geom-ram", true);
00082 
00083 // Set this true to allow the use of retained mode rendering, which
00084 // creates specific cache information (like display lists or vertex
00085 // buffers) with the GSG for static geometry, when supported by the
00086 // GSG.  Set it false to use only immediate mode, which sends the
00087 // vertices to the GSG every frame.
00088 bool retained_mode = config_gobj.GetBool("retained-mode", false);
00089 
00090 
00091 // Set this to specify how textures should be written into Bam files.
00092 // Currently, the options are:
00093 
00094 //    fullpath - write the full pathname loaded.
00095 //    relative - search for the texture as a filename relative to the
00096 //               model-path or texture-path and write the relative pathname.
00097 //    basename - write only the basename of the file, no directory portion
00098 //               at all.
00099 
00100 BamTextureMode bam_texture_mode;
00101 
00102 // Set this to enable a speedy-load mode where you don't care what the
00103 // world looks like, you just want it to load in minimal time.  This
00104 // causes all texture loads via the TexturePool to load the same
00105 // texture file, which will presumably only be loaded once.
00106 const string fake_texture_image = config_gobj.GetString("fake-texture-image", "");
00107 
00108 // must be set to true for LOD_number debugging items to work
00109 const bool debug_LOD_mode = config_gobj.GetBool("debug-LOD-mode", false);
00110 
00111 // if this is >=0, select_child always returns this LOD number
00112 const int select_LOD_number = config_gobj.GetInt("select-LOD-number", -1);
00113 
00114 // this controls the LOD child number returned by compute_child
00115 // use it to force the LOD alg to not select the highest level(s) of LOD
00116 // minimum_LOD_number=0 will screen out no LODs, and increasing it
00117 // will screen out successively higher levels
00118 const int minimum_LOD_number = config_gobj.GetInt("minimum-LOD-number", 0);
00119 
00120 const float lod_stress_factor = config_gobj.GetFloat("lod-stress-factor", 1.0f);
00121 
00122 // The default near and far plane distances.
00123 const float default_near = config_gobj.GetFloat("default-near", 1.0f);
00124 const float default_far = config_gobj.GetFloat("default-far", 1000.0f);
00125 
00126 static BamTextureMode
00127 parse_texture_mode(const string &mode) {
00128   if (cmp_nocase(mode, "unchanged") == 0) {
00129     return BTM_unchanged;
00130   } else if (cmp_nocase(mode, "fullpath") == 0) {
00131     return BTM_fullpath;
00132   } else if (cmp_nocase(mode, "relative") == 0) {
00133     return BTM_relative;
00134   } else if (cmp_nocase(mode, "basename") == 0) {
00135     return BTM_basename;
00136   }
00137 
00138   gobj_cat->error() << "Invalid bam-texture-mode: " << mode << "\n";
00139   return BTM_relative;
00140 }
00141 
00142 ConfigureFn(config_gobj) {
00143   string texture_mode = config_util.GetString("bam-texture-mode", "relative");
00144   bam_texture_mode = parse_texture_mode(texture_mode);
00145 
00146   string textures_power_2 = config_gobj.GetString("textures-power-2", "");
00147   if (cmp_nocase(textures_power_2, "up") == 0) {
00148     textures_up_power_2 = true;
00149     textures_down_power_2 = false;
00150 
00151   } else if (cmp_nocase(textures_power_2, "down") == 0) {
00152     textures_up_power_2 = false;
00153     textures_down_power_2 = true;
00154 
00155   } else {
00156     textures_up_power_2 = false;
00157     textures_down_power_2 = config_gobj.GetBool("textures-power-2", false);
00158   }
00159 
00160   string textures_square = config_gobj.GetString("textures-square", "");
00161   if (cmp_nocase(textures_square, "up") == 0) {
00162     textures_up_square = true;
00163     textures_down_square = false;
00164 
00165   } else if (cmp_nocase(textures_square, "down") == 0) {
00166     textures_up_square = false;
00167     textures_down_square = true;
00168 
00169   } else {
00170     textures_up_square = false;
00171     textures_down_square = config_gobj.GetBool("textures-square", false);
00172   }
00173 
00174   BoundedObject::init_type();
00175   Geom::init_type();
00176   GeomLine::init_type();
00177   GeomLinestrip::init_type();
00178   GeomPoint::init_type();
00179   GeomSprite::init_type();
00180   GeomPolygon::init_type();
00181   GeomQuad::init_type();
00182   GeomSphere::init_type();
00183   GeomTri::init_type();
00184   GeomTrifan::init_type();
00185   GeomTristrip::init_type();
00186   ImageBuffer::init_type();
00187   Material::init_type();
00188   OrthographicLens::init_type();
00189   MatrixLens::init_type();
00190   PerspectiveLens::init_type();
00191   PixelBuffer::init_type();
00192   Lens::init_type();
00193   Texture::init_type();
00194   dDrawable::init_type();
00195 
00196   //Registration of writeable object's creation
00197   //functions with BamReader's factory
00198   GeomPoint::register_with_read_factory();
00199   GeomLine::register_with_read_factory();
00200   GeomLinestrip::register_with_read_factory();
00201   GeomSprite::register_with_read_factory();
00202   GeomPolygon::register_with_read_factory();
00203   GeomQuad::register_with_read_factory();
00204   GeomTri::register_with_read_factory();
00205   GeomTristrip::register_with_read_factory();
00206   GeomTrifan::register_with_read_factory();
00207   GeomSphere::register_with_read_factory();
00208   Material::register_with_read_factory();
00209   Texture::register_with_read_factory();
00210 }

Generated on Fri May 2 00:39:17 2003 for Panda by doxygen1.3