Forráskód Böngészése

Add Texture::set_auto_texture_scale()

David Rose 14 éve
szülő
commit
3d89cef544

+ 1 - 1
panda/src/display/graphicsEngine.cxx

@@ -2130,7 +2130,7 @@ auto_adjust_capabilities(GraphicsStateGuardian *gsg) {
     textures_power_2 = ATS_down; // Not a fix.  Just suppresses further error messages.
     textures_power_2 = ATS_down; // Not a fix.  Just suppresses further error messages.
   }
   }
   
   
-  if (textures_auto_power_2 && !Texture::have_textures_power_2()) {
+  if (textures_auto_power_2 && !Texture::has_textures_power_2()) {
     if (gsg->get_supports_tex_non_pow2()) {
     if (gsg->get_supports_tex_non_pow2()) {
       Texture::set_textures_power_2(ATS_none);
       Texture::set_textures_power_2(ATS_none);
     } else {
     } else {

+ 2 - 55
panda/src/gobj/config_gobj.cxx

@@ -550,59 +550,6 @@ ConfigureFn(config_gobj) {
   UserVertexTransform::register_with_read_factory();
   UserVertexTransform::register_with_read_factory();
 }
 }
 
 
-ostream &
-operator << (ostream &out, AutoTextureScale ats) {
-  switch (ats) {
-  case ATS_none:
-    return out << "none";
-   
-  case ATS_down:
-    return out << "down";
-    
-  case ATS_up:
-    return out << "up";
-    
-  case ATS_pad:
-    return out << "pad";
-
-  case ATS_UNSPECIFIED:
-    return out << "UNSPECIFIED";
-  }
-
-  return out << "**invalid AutoTextureScale (" << (int)ats << ")**";
-}
-
-istream &
-operator >> (istream &in, AutoTextureScale &ats) {
-  string word;
-  in >> word;
-
-  if (cmp_nocase(word, "none") == 0 ||
-      cmp_nocase(word, "0") == 0 ||
-      cmp_nocase(word, "#f") == 0 ||
-      (!word.empty() && tolower(word[0]) == 'f')) {
-    ats = ATS_none;
-
-  } else if (cmp_nocase(word, "down") == 0 ||
-             cmp_nocase(word, "1") == 0 ||
-             cmp_nocase(word, "#t") == 0 ||
-             (!word.empty() && tolower(word[0]) == 't')) {
-    ats = ATS_down;
-
-  } else if (cmp_nocase(word, "up") == 0) {
-    ats = ATS_up;
-
-  } else if (cmp_nocase(word, "pad") == 0) {
-    ats = ATS_pad;
-
-  } else {
-    gobj_cat->error() << "Invalid AutoTextureScale value: " << word << "\n";
-    ats = ATS_none;
-  }
-
-  return in;
-}
-
 ostream &
 ostream &
 operator << (ostream &out, ShaderUtilization sgc) {
 operator << (ostream &out, ShaderUtilization sgc) {
   switch (sgc) {
   switch (sgc) {
@@ -615,8 +562,8 @@ operator << (ostream &out, ShaderUtilization sgc) {
   case SUT_advanced:
   case SUT_advanced:
     return out << "advanced";
     return out << "advanced";
 
 
-  case SUT_UNSPECIFIED:
-    return out << "UNSPECIFIED";
+  case SUT_unspecified:
+    return out << "unspecified";
   }
   }
 
 
   return out << "**invalid ShaderUtilization (" << (int)sgc << ")**";
   return out << "**invalid ShaderUtilization (" << (int)sgc << ")**";

+ 2 - 10
panda/src/gobj/config_gobj.h

@@ -23,27 +23,19 @@
 #include "configVariableDouble.h"
 #include "configVariableDouble.h"
 #include "configVariableFilename.h"
 #include "configVariableFilename.h"
 #include "configVariableString.h"
 #include "configVariableString.h"
+#include "autoTextureScale.h"
 
 
 NotifyCategoryDecl(gobj, EXPCL_PANDA_GOBJ, EXPTP_PANDA_GOBJ);
 NotifyCategoryDecl(gobj, EXPCL_PANDA_GOBJ, EXPTP_PANDA_GOBJ);
 
 
 BEGIN_PUBLISH
 BEGIN_PUBLISH
-enum AutoTextureScale {
-  ATS_none,
-  ATS_down,
-  ATS_up,
-  ATS_pad,
-  ATS_UNSPECIFIED,
-};
 enum ShaderUtilization {
 enum ShaderUtilization {
   SUT_none,
   SUT_none,
   SUT_basic,
   SUT_basic,
   SUT_advanced,
   SUT_advanced,
-  SUT_UNSPECIFIED,
+  SUT_unspecified,
 };
 };
 END_PUBLISH
 END_PUBLISH
 
 
-EXPCL_PANDA_GOBJ ostream &operator << (ostream &out, AutoTextureScale ats);
-EXPCL_PANDA_GOBJ istream &operator >> (istream &in, AutoTextureScale &ats);
 EXPCL_PANDA_GOBJ ostream &operator << (ostream &out, ShaderUtilization sut);
 EXPCL_PANDA_GOBJ ostream &operator << (ostream &out, ShaderUtilization sut);
 EXPCL_PANDA_GOBJ istream &operator >> (istream &in, ShaderUtilization &sut);
 EXPCL_PANDA_GOBJ istream &operator >> (istream &in, ShaderUtilization &sut);
 
 

+ 2 - 2
panda/src/gobj/shader.I

@@ -102,7 +102,7 @@ set_shader_utilization(ShaderUtilization sut) {
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 INLINE ShaderUtilization Shader::
 INLINE ShaderUtilization Shader::
 get_shader_utilization() {
 get_shader_utilization() {
-  if (_shader_utilization == SUT_UNSPECIFIED) {
+  if (_shader_utilization == SUT_unspecified) {
     return shader_utilization;
     return shader_utilization;
   } else {
   } else {
     return _shader_utilization;
     return _shader_utilization;
@@ -119,7 +119,7 @@ get_shader_utilization() {
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 INLINE bool Shader::
 INLINE bool Shader::
 have_shader_utilization() {
 have_shader_utilization() {
-  return (_shader_utilization != SUT_UNSPECIFIED);
+  return (_shader_utilization != SUT_unspecified);
 }
 }
 
 
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////

+ 1 - 1
panda/src/gobj/shader.cxx

@@ -29,7 +29,7 @@ Shader::ShaderTable Shader::_load_table;
 Shader::ShaderTable Shader::_make_table;
 Shader::ShaderTable Shader::_make_table;
 Shader::ShaderCaps Shader::_default_caps;
 Shader::ShaderCaps Shader::_default_caps;
 int Shader::_shaders_generated;
 int Shader::_shaders_generated;
-ShaderUtilization Shader::_shader_utilization = SUT_UNSPECIFIED;
+ShaderUtilization Shader::_shader_utilization = SUT_unspecified;
 
 
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 //     Function: Shader::cp_report_error
 //     Function: Shader::cp_report_error

+ 98 - 41
panda/src/gobj/texture.I

@@ -1879,6 +1879,90 @@ get_simple_image_modified() const {
   return cdata->_simple_image_modified;
   return cdata->_simple_image_modified;
 }
 }
 
 
+////////////////////////////////////////////////////////////////////
+//     Function: Texture::set_auto_texture_scale
+//       Access: Published
+//  Description: Specifies the power-of-2 texture-scaling mode that
+//               will be applied to this particular texture when it is
+//               next loaded from disk.  See set_textures_power_2().
+////////////////////////////////////////////////////////////////////
+INLINE void Texture::
+set_auto_texture_scale(AutoTextureScale scale) {
+  CDWriter cdata(_cycler, true);
+  cdata->_auto_texture_scale = scale;
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: Texture::get_auto_texture_scale
+//       Access: Published
+//  Description: Returns the power-of-2 texture-scaling mode that will
+//               be applied to this particular texture when it is next
+//               loaded from disk.  See set_textures_power_2().
+////////////////////////////////////////////////////////////////////
+INLINE AutoTextureScale Texture::
+get_auto_texture_scale() const {
+  CDReader cdata(_cycler);
+  return do_get_auto_texture_scale(cdata);
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: Texture::has_auto_texture_scale
+//       Access: Published
+//  Description: Returns true if set_auto_texture_scale() has been set
+//               to something other than ATS_unspecified for this
+//               particular texture.
+////////////////////////////////////////////////////////////////////
+INLINE bool Texture::
+has_auto_texture_scale() const {
+  CDReader cdata(_cycler);
+  return (cdata->_auto_texture_scale != ATS_unspecified);
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: Texture::set_textures_power_2
+//       Access: Published, Static
+//  Description: Set this flag to ATS_none, ATS_up, ATS_down, or
+//               ATS_pad to control the scaling of textures in
+//               general, if a particular texture does not override
+//               this.  See also set_auto_texture_scale() for the
+//               per-texture override.
+////////////////////////////////////////////////////////////////////
+INLINE void Texture::
+set_textures_power_2(AutoTextureScale scale) {
+  _textures_power_2 = scale;
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: Texture::get_textures_power_2
+//       Access: Published, Static
+//  Description: This flag returns ATS_none, ATS_up, or ATS_down
+//               and controls the scaling of textures in general.  It
+//               is initialized from the config variable of the same
+//               name, but it can be subsequently adjusted.  See also
+//               get_auto_texture_scale().
+////////////////////////////////////////////////////////////////////
+INLINE AutoTextureScale Texture::
+get_textures_power_2() {
+  if (_textures_power_2 == ATS_unspecified) {
+    return textures_power_2;
+  } else {
+    return _textures_power_2;
+  }
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: Texture::has_textures_power_2
+//       Access: Published, Static
+//  Description: If true, then get_textures_power_2 has been
+//               set using set_textures_power_2.
+//               If false, then get_textures_power_2 simply
+//               returns the config variable of the same name.
+////////////////////////////////////////////////////////////////////
+INLINE bool Texture::
+has_textures_power_2() {
+  return (_textures_power_2 != ATS_unspecified);
+}
+
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 //     Function: Texture::set_filename
 //     Function: Texture::set_filename
 //       Access: Published
 //       Access: Published
@@ -2341,6 +2425,20 @@ do_clear_ram_image(CData *cdata) {
   cdata->_ram_images.clear();
   cdata->_ram_images.clear();
 }
 }
 
 
+////////////////////////////////////////////////////////////////////
+//     Function: Texture::do_get_auto_texture_scale
+//       Access: Protected
+//  Description: 
+////////////////////////////////////////////////////////////////////
+INLINE AutoTextureScale Texture::
+do_get_auto_texture_scale(const CData *cdata) const {
+  if (cdata->_auto_texture_scale == ATS_unspecified) {
+    return get_textures_power_2();
+  } else {
+    return cdata->_auto_texture_scale;
+  }
+}
+
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 //     Function: Texture::store_unscaled_byte
 //     Function: Texture::store_unscaled_byte
 //       Access: Private, Static
 //       Access: Private, Static
@@ -2469,47 +2567,6 @@ is_dds_filename(const Filename &fullpath) {
   return (downcase(extension) == "dds");
   return (downcase(extension) == "dds");
 }
 }
 
 
-////////////////////////////////////////////////////////////////////
-//     Function: Texture::set_textures_power_2
-//       Access: Published, Static
-//  Description: Set this flag to ATS_none, ATS_up, or ATS_down
-//               to control the scaling of textures.
-////////////////////////////////////////////////////////////////////
-INLINE void Texture::
-set_textures_power_2(AutoTextureScale scale) {
-  _textures_power_2 = scale;
-}
-
-////////////////////////////////////////////////////////////////////
-//     Function: Texture::get_textures_power_2
-//       Access: Published, Static
-//  Description: This flag returns ATS_none, ATS_up, or ATS_down
-//               and controls the scaling of textures.  It is
-//               initialized from the config variable of the same
-//               name, but it can be subsequently adjusted.
-////////////////////////////////////////////////////////////////////
-INLINE AutoTextureScale Texture::
-get_textures_power_2() {
-  if (_textures_power_2 == ATS_UNSPECIFIED) {
-    return textures_power_2;
-  } else {
-    return _textures_power_2;
-  }
-}
-
-////////////////////////////////////////////////////////////////////
-//     Function: Texture::have_textures_power_2
-//       Access: Published, Static
-//  Description: If true, then get_textures_power_2 has been
-//               set using set_textures_power_2.
-//               If false, then get_textures_power_2 simply
-//               returns the config variable of the same name.
-////////////////////////////////////////////////////////////////////
-INLINE bool Texture::
-have_textures_power_2() {
-  return (_textures_power_2 != ATS_UNSPECIFIED);
-}
-
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 //     Function: Texture::RamImage::Constructor
 //     Function: Texture::RamImage::Constructor
 //       Access: Public
 //       Access: Public

+ 33 - 14
panda/src/gobj/texture.cxx

@@ -89,7 +89,7 @@ ConfigVariableInt texture_anisotropic_degree
 PStatCollector Texture::_texture_read_pcollector("*:Texture:Read");
 PStatCollector Texture::_texture_read_pcollector("*:Texture:Read");
 TypeHandle Texture::_type_handle;
 TypeHandle Texture::_type_handle;
 TypeHandle Texture::CData::_type_handle;
 TypeHandle Texture::CData::_type_handle;
-AutoTextureScale Texture::_textures_power_2 = ATS_UNSPECIFIED;
+AutoTextureScale Texture::_textures_power_2 = ATS_unspecified;
 
 
 // Stuff to read and write DDS files.
 // Stuff to read and write DDS files.
 
 
@@ -1751,7 +1751,7 @@ write(ostream &out, int indent_level) const {
 void Texture::
 void Texture::
 set_size_padded(int x, int y, int z) {
 set_size_padded(int x, int y, int z) {
   CDWriter cdata(_cycler, true);
   CDWriter cdata(_cycler, true);
-  if (get_textures_power_2() != ATS_none) {
+  if (do_get_auto_texture_scale(cdata) != ATS_none) {
     do_set_x_size(cdata, up_to_power_2(x));
     do_set_x_size(cdata, up_to_power_2(x));
     do_set_y_size(cdata, up_to_power_2(y));
     do_set_y_size(cdata, up_to_power_2(y));
     do_set_z_size(cdata, up_to_power_2(z));
     do_set_z_size(cdata, up_to_power_2(z));
@@ -1884,7 +1884,7 @@ down_to_power_2(int value) {
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 void Texture::
 void Texture::
 consider_rescale(PNMImage &pnmimage) {
 consider_rescale(PNMImage &pnmimage) {
-  consider_rescale(pnmimage, get_name());
+  consider_rescale(pnmimage, get_name(), get_auto_texture_scale());
 }
 }
 
 
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
@@ -1899,10 +1899,10 @@ consider_rescale(PNMImage &pnmimage) {
 //               pnmimage.read().  Also see rescale_texture().
 //               pnmimage.read().  Also see rescale_texture().
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 void Texture::
 void Texture::
-consider_rescale(PNMImage &pnmimage, const string &name) {
+consider_rescale(PNMImage &pnmimage, const string &name, AutoTextureScale auto_texture_scale) {
   int new_x_size = pnmimage.get_x_size();
   int new_x_size = pnmimage.get_x_size();
   int new_y_size = pnmimage.get_y_size();
   int new_y_size = pnmimage.get_y_size();
-  if (adjust_size(new_x_size, new_y_size, name, false)) {
+  if (adjust_size(new_x_size, new_y_size, name, false, auto_texture_scale)) {
     pnmimage.set_read_size(new_x_size, new_y_size);
     pnmimage.set_read_size(new_x_size, new_y_size);
   }
   }
 }
 }
@@ -2523,7 +2523,7 @@ has_binary_alpha(Format format) {
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 bool Texture::
 bool Texture::
 adjust_size(int &x_size, int &y_size, const string &name,
 adjust_size(int &x_size, int &y_size, const string &name,
-            bool for_padding) {
+            bool for_padding, AutoTextureScale auto_texture_scale) {
   bool exclude = false;
   bool exclude = false;
   int num_excludes = exclude_texture_scale.get_num_unique_values();
   int num_excludes = exclude_texture_scale.get_num_unique_values();
   for (int i = 0; i < num_excludes && !exclude; ++i) {
   for (int i = 0; i < num_excludes && !exclude; ++i) {
@@ -2546,7 +2546,10 @@ adjust_size(int &x_size, int &y_size, const string &name,
     new_y_size = min(max(new_y_size, (int)texture_scale_limit), y_size);
     new_y_size = min(max(new_y_size, (int)texture_scale_limit), y_size);
   }
   }
 
 
-  AutoTextureScale ats = get_textures_power_2();
+  AutoTextureScale ats = auto_texture_scale;
+  if (ats == ATS_unspecified) {
+    ats = textures_power_2;
+  }
   if (!for_padding && ats == ATS_pad) {
   if (!for_padding && ats == ATS_pad) {
     // If we're not calculating the padding size--that is, we're
     // If we're not calculating the padding size--that is, we're
     // calculating the initial scaling size instead--then ignore
     // calculating the initial scaling size instead--then ignore
@@ -2567,7 +2570,7 @@ adjust_size(int &x_size, int &y_size, const string &name,
     break;
     break;
 
 
   case ATS_none:
   case ATS_none:
-  case ATS_UNSPECIFIED:
+  case ATS_unspecified:
     break;
     break;
   }
   }
 
 
@@ -2586,7 +2589,7 @@ adjust_size(int &x_size, int &y_size, const string &name,
     break;
     break;
 
 
   case ATS_none:
   case ATS_none:
-  case ATS_UNSPECIFIED:
+  case ATS_unspecified:
     break;
     break;
   }
   }
 
 
@@ -2635,7 +2638,7 @@ reconsider_dirty() {
 bool Texture::
 bool Texture::
 do_adjust_this_size(const CData *cdata, int &x_size, int &y_size, const string &name,
 do_adjust_this_size(const CData *cdata, int &x_size, int &y_size, const string &name,
                     bool for_padding) const {
                     bool for_padding) const {
-  return adjust_size(x_size, y_size, name, for_padding);
+  return adjust_size(x_size, y_size, name, for_padding, cdata->_auto_texture_scale);
 }
 }
 
 
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
@@ -2651,6 +2654,10 @@ do_read(CData *cdata, const Filename &fullpath, const Filename &alpha_fullpath,
         const LoaderOptions &options, BamCacheRecord *record) {
         const LoaderOptions &options, BamCacheRecord *record) {
   PStatTimer timer(_texture_read_pcollector);
   PStatTimer timer(_texture_read_pcollector);
 
 
+  if (options.get_auto_texture_scale() != ATS_unspecified) {
+    cdata->_auto_texture_scale = options.get_auto_texture_scale();
+  }
+
   bool header_only = ((options.get_texture_flags() & (LoaderOptions::TF_preload | LoaderOptions::TF_preload_simple)) == 0);
   bool header_only = ((options.get_texture_flags() & (LoaderOptions::TF_preload | LoaderOptions::TF_preload_simple)) == 0);
   if (record != (BamCacheRecord *)NULL) {
   if (record != (BamCacheRecord *)NULL) {
     header_only = false;
     header_only = false;
@@ -2910,7 +2917,7 @@ do_read_one(CData *cdata, const Filename &fullpath, const Filename &alpha_fullpa
       y_size = 1;
       y_size = 1;
 
 
     } else {
     } else {
-      consider_rescale(image, fullpath.get_basename());
+      consider_rescale(image, fullpath.get_basename(), do_get_auto_texture_scale(cdata));
       x_size = image.get_read_x_size();
       x_size = image.get_read_x_size();
       y_size = image.get_read_y_size();
       y_size = image.get_read_y_size();
     }
     }
@@ -2932,7 +2939,7 @@ do_read_one(CData *cdata, const Filename &fullpath, const Filename &alpha_fullpa
     if (z == 0 && n == 0) {
     if (z == 0 && n == 0) {
       cdata->_orig_file_x_size = image.get_x_size();
       cdata->_orig_file_x_size = image.get_x_size();
       cdata->_orig_file_y_size = image.get_y_size();
       cdata->_orig_file_y_size = image.get_y_size();
-      consider_rescale(image, fullpath.get_basename());
+      consider_rescale(image, fullpath.get_basename(), do_get_auto_texture_scale(cdata));
     } else {
     } else {
       image.set_read_size(do_get_expected_mipmap_x_size(cdata, n),
       image.set_read_size(do_get_expected_mipmap_x_size(cdata, n),
                           do_get_expected_mipmap_y_size(cdata, n));
                           do_get_expected_mipmap_y_size(cdata, n));
@@ -3087,7 +3094,7 @@ do_read_one(CData *cdata, const Filename &fullpath, const Filename &alpha_fullpa
   // image.
   // image.
   int pad_x_size = 0;
   int pad_x_size = 0;
   int pad_y_size = 0;
   int pad_y_size = 0;
-  if (get_textures_power_2() == ATS_pad) {
+  if (do_get_auto_texture_scale(cdata) == ATS_pad) {
     int new_x_size = image.get_x_size();
     int new_x_size = image.get_x_size();
     int new_y_size = image.get_y_size();
     int new_y_size = image.get_y_size();
     if (do_adjust_this_size(cdata, new_x_size, new_y_size, fullpath.get_basename(), true)) {
     if (do_adjust_this_size(cdata, new_x_size, new_y_size, fullpath.get_basename(), true)) {
@@ -4582,7 +4589,7 @@ do_rescale_texture(CData *cdata) {
   // Maybe we should pad the image.
   // Maybe we should pad the image.
   int pad_x_size = 0;
   int pad_x_size = 0;
   int pad_y_size = 0;
   int pad_y_size = 0;
-  if (get_textures_power_2() == ATS_pad) {
+  if (do_get_auto_texture_scale(cdata) == ATS_pad) {
     new_x_size = cdata->_x_size;
     new_x_size = cdata->_x_size;
     new_y_size = cdata->_y_size;
     new_y_size = cdata->_y_size;
     if (do_adjust_this_size(cdata, new_x_size, new_y_size, get_name(), true)) {
     if (do_adjust_this_size(cdata, new_x_size, new_y_size, get_name(), true)) {
@@ -7111,6 +7118,7 @@ do_write_datagram_body(CData *cdata, BamWriter *manager, Datagram &me) {
   me.add_uint8(cdata->_format);
   me.add_uint8(cdata->_format);
   me.add_uint8(cdata->_num_components);
   me.add_uint8(cdata->_num_components);
 
 
+  me.add_uint8(cdata->_auto_texture_scale);
   me.add_uint32(cdata->_orig_file_x_size);
   me.add_uint32(cdata->_orig_file_x_size);
   me.add_uint32(cdata->_orig_file_y_size);
   me.add_uint32(cdata->_orig_file_y_size);
 
 
@@ -7225,9 +7233,11 @@ make_this_from_bam(const FactoryParams &params) {
     // pointer as a temporary object to read all of the attributes
     // pointer as a temporary object to read all of the attributes
     // from the bam stream.
     // from the bam stream.
     Texture *dummy = this;
     Texture *dummy = this;
+    AutoTextureScale auto_texture_scale = ATS_unspecified;
     {
     {
       CDWriter cdata_dummy(dummy->_cycler, true);
       CDWriter cdata_dummy(dummy->_cycler, true);
       dummy->do_fillin_body(cdata_dummy, scan, manager);
       dummy->do_fillin_body(cdata_dummy, scan, manager);
+      auto_texture_scale = cdata_dummy->_auto_texture_scale;
     }
     }
 
 
     if (filename.empty()) {
     if (filename.empty()) {
@@ -7253,6 +7263,7 @@ make_this_from_bam(const FactoryParams &params) {
       if (dummy->uses_mipmaps()) {
       if (dummy->uses_mipmaps()) {
         options.set_texture_flags(options.get_texture_flags() | LoaderOptions::TF_generate_mipmaps);
         options.set_texture_flags(options.get_texture_flags() | LoaderOptions::TF_generate_mipmaps);
       }
       }
+      options.set_auto_texture_scale(auto_texture_scale);
 
 
       switch (texture_type) {
       switch (texture_type) {
       case TT_1d_texture:
       case TT_1d_texture:
@@ -7321,8 +7332,14 @@ do_fillin_body(CData *cdata, DatagramIterator &scan, BamReader *manager) {
 
 
   cdata->_format = (Format)scan.get_uint8();
   cdata->_format = (Format)scan.get_uint8();
   cdata->_num_components = scan.get_uint8();
   cdata->_num_components = scan.get_uint8();
+
   ++(cdata->_properties_modified);
   ++(cdata->_properties_modified);
 
 
+  cdata->_auto_texture_scale = ATS_unspecified;
+  if (manager->get_file_minor_ver() >= 28) {
+    cdata->_auto_texture_scale = (AutoTextureScale)scan.get_uint8();
+  }
+
   bool has_simple_ram_image = false;
   bool has_simple_ram_image = false;
   if (manager->get_file_minor_ver() >= 18) {
   if (manager->get_file_minor_ver() >= 18) {
     cdata->_orig_file_x_size = scan.get_uint32();
     cdata->_orig_file_x_size = scan.get_uint32();
@@ -7481,6 +7498,7 @@ CData() {
   _keep_ram_image = true;
   _keep_ram_image = true;
   _border_color.set(0.0f, 0.0f, 0.0f, 1.0f);
   _border_color.set(0.0f, 0.0f, 0.0f, 1.0f);
   _compression = CM_default;
   _compression = CM_default;
+  _auto_texture_scale = ATS_unspecified;
   _ram_image_compression = CM_off;
   _ram_image_compression = CM_off;
   _render_to_texture = false;
   _render_to_texture = false;
   _match_framebuffer_format = false;
   _match_framebuffer_format = false;
@@ -7589,6 +7607,7 @@ do_assign(const Texture::CData *copy) {
   _compression = copy->_compression;
   _compression = copy->_compression;
   _match_framebuffer_format = copy->_match_framebuffer_format;
   _match_framebuffer_format = copy->_match_framebuffer_format;
   _quality_level = copy->_quality_level;
   _quality_level = copy->_quality_level;
+  _auto_texture_scale = copy->_auto_texture_scale;
   _ram_image_compression = copy->_ram_image_compression;
   _ram_image_compression = copy->_ram_image_compression;
   _ram_images = copy->_ram_images;
   _ram_images = copy->_ram_images;
   _simple_x_size = copy->_simple_x_size;
   _simple_x_size = copy->_simple_x_size;

+ 10 - 3
panda/src/gobj/texture.h

@@ -386,6 +386,10 @@ PUBLISHED:
   INLINE UpdateSeq get_image_modified() const;
   INLINE UpdateSeq get_image_modified() const;
   INLINE UpdateSeq get_simple_image_modified() const;
   INLINE UpdateSeq get_simple_image_modified() const;
 
 
+  INLINE void set_auto_texture_scale(AutoTextureScale scale);
+  INLINE AutoTextureScale get_auto_texture_scale() const;
+  INLINE bool has_auto_texture_scale() const;
+
   void prepare(PreparedGraphicsObjects *prepared_objects);
   void prepare(PreparedGraphicsObjects *prepared_objects);
   bool is_prepared(PreparedGraphicsObjects *prepared_objects) const;
   bool is_prepared(PreparedGraphicsObjects *prepared_objects) const;
   bool was_image_modified(PreparedGraphicsObjects *prepared_objects) const;
   bool was_image_modified(PreparedGraphicsObjects *prepared_objects) const;
@@ -406,7 +410,7 @@ PUBLISHED:
 
 
   INLINE static void set_textures_power_2(AutoTextureScale scale);
   INLINE static void set_textures_power_2(AutoTextureScale scale);
   INLINE static AutoTextureScale get_textures_power_2();
   INLINE static AutoTextureScale get_textures_power_2();
-  INLINE static bool have_textures_power_2();
+  INLINE static bool has_textures_power_2();
 
 
 PUBLISHED:
 PUBLISHED:
   // These are published, but in general, you shouldn't be mucking
   // These are published, but in general, you shouldn't be mucking
@@ -465,7 +469,7 @@ PUBLISHED:
   static int down_to_power_2(int value);
   static int down_to_power_2(int value);
 
 
   void consider_rescale(PNMImage &pnmimage);
   void consider_rescale(PNMImage &pnmimage);
-  static void consider_rescale(PNMImage &pnmimage, const string &name);
+  static void consider_rescale(PNMImage &pnmimage, const string &name, AutoTextureScale auto_texture_scale = ATS_unspecified);
   INLINE bool rescale_texture();
   INLINE bool rescale_texture();
 
 
   static string format_texture_type(TextureType tt);
   static string format_texture_type(TextureType tt);
@@ -503,7 +507,7 @@ public:
   static bool has_binary_alpha(Format format);
   static bool has_binary_alpha(Format format);
 
 
   static bool adjust_size(int &x_size, int &y_size, const string &name,
   static bool adjust_size(int &x_size, int &y_size, const string &name,
-                          bool for_padding);
+                          bool for_padding, AutoTextureScale auto_texture_scale = ATS_unspecified);
   INLINE bool adjust_this_size(int &x_size, int &y_size, const string &name,
   INLINE bool adjust_this_size(int &x_size, int &y_size, const string &name,
                                bool for_padding) const;
                                bool for_padding) const;
 
 
@@ -630,6 +634,8 @@ protected:
   virtual bool do_can_reload(const CData *cdata) const;
   virtual bool do_can_reload(const CData *cdata) const;
   bool do_reload(CData *cdata);
   bool do_reload(CData *cdata);
 
 
+  INLINE AutoTextureScale do_get_auto_texture_scale(const CData *cdata) const;
+
   virtual bool do_has_bam_rawdata(const CData *cdata) const;
   virtual bool do_has_bam_rawdata(const CData *cdata) const;
   virtual void do_get_bam_rawdata(CData *cdata);
   virtual void do_get_bam_rawdata(CData *cdata);
 
 
@@ -800,6 +806,7 @@ protected:
     int _orig_file_x_size;
     int _orig_file_x_size;
     int _orig_file_y_size;
     int _orig_file_y_size;
   
   
+    AutoTextureScale _auto_texture_scale;
     CompressionMode _ram_image_compression;
     CompressionMode _ram_image_compression;
 
 
     // There is usually one RamImage for the mipmap level 0 (the base
     // There is usually one RamImage for the mipmap level 0 (the base

+ 19 - 0
panda/src/gobj/videoTexture.cxx

@@ -212,6 +212,25 @@ do_can_reload(const Texture::CData *cdata) const {
   return true;
   return true;
 }
 }
 
 
+////////////////////////////////////////////////////////////////////
+//     Function: VideoTexture::do_adjust_this_size
+//       Access: Protected, Virtual
+//  Description: Works like adjust_size, but also considers the
+//               texture class.  Movie textures, for instance, always
+//               pad outwards, never scale down.
+////////////////////////////////////////////////////////////////////
+bool VideoTexture::
+do_adjust_this_size(const Texture::CData *cdata_tex,
+                    int &x_size, int &y_size, const string &name,
+                    bool for_padding) const {
+  AutoTextureScale ats = do_get_auto_texture_scale(cdata_tex);
+  if (ats != ATS_none) {
+    ats = ATS_pad;
+  }
+
+  return adjust_size(x_size, y_size, name, for_padding, ats);
+}
+
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 //     Function: VideoTexture::consider_update
 //     Function: VideoTexture::consider_update
 //       Access: Protected, Virtual
 //       Access: Protected, Virtual

+ 4 - 0
panda/src/gobj/videoTexture.h

@@ -53,6 +53,10 @@ protected:
   virtual void do_reload_ram_image(Texture::CData *cdata, bool allow_compression);
   virtual void do_reload_ram_image(Texture::CData *cdata, bool allow_compression);
   virtual bool do_can_reload(const Texture::CData *cdata) const;
   virtual bool do_can_reload(const Texture::CData *cdata) const;
 
 
+  virtual bool do_adjust_this_size(const Texture::CData *cdata, 
+                                   int &x_size, int &y_size, const string &name, 
+                                   bool for_padding) const;
+
   virtual void consider_update();
   virtual void consider_update();
   INLINE void clear_current_frame();
   INLINE void clear_current_frame();
   virtual void do_update_frame(Texture::CData *cdata_tex, int frame)=0;
   virtual void do_update_frame(Texture::CData *cdata_tex, int frame)=0;

+ 4 - 9
panda/src/grutil/movieTexture.cxx

@@ -196,17 +196,12 @@ bool MovieTexture::
 do_adjust_this_size(const Texture::CData *cdata_tex,
 do_adjust_this_size(const Texture::CData *cdata_tex,
                     int &x_size, int &y_size, const string &name,
                     int &x_size, int &y_size, const string &name,
                     bool for_padding) const {
                     bool for_padding) const {
-  if (cdata_tex->_texture_type == TT_cube_map) {
-    // Texture must be square.
-    x_size = y_size = max(x_size, y_size);
+  AutoTextureScale ats = do_get_auto_texture_scale(cdata_tex);
+  if (ats != ATS_none) {
+    ats = ATS_pad;
   }
   }
 
 
-  if (Texture::get_textures_power_2() != ATS_none) {
-    x_size = up_to_power_2(x_size);
-    y_size = up_to_power_2(y_size);
-  }
-
-  return true;
+  return adjust_size(x_size, y_size, name, for_padding, ats);
 }
 }
 
 
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////

+ 1 - 4
panda/src/movies/movieVideoCursor.cxx

@@ -63,10 +63,7 @@ void MovieVideoCursor::
 setup_texture(Texture *tex) const {
 setup_texture(Texture *tex) const {
   int fullx = size_x();
   int fullx = size_x();
   int fully = size_y();
   int fully = size_y();
-  if (Texture::get_textures_power_2()) {
-    fullx = Texture::up_to_power_2(fullx);
-    fully = Texture::up_to_power_2(fully);
-  }
+  tex->adjust_this_size(fullx, fully, tex->get_name(), true);
   Texture::Format fmt = (get_num_components() == 4) ? Texture::F_rgba : Texture::F_rgb;
   Texture::Format fmt = (get_num_components() == 4) ? Texture::F_rgba : Texture::F_rgb;
   tex->setup_texture(Texture::TT_2d_texture, fullx, fully, 1, Texture::T_unsigned_byte, fmt);
   tex->setup_texture(Texture::TT_2d_texture, fullx, fully, 1, Texture::T_unsigned_byte, fmt);
   tex->set_pad_size(fullx - size_x(), fully - size_y());
   tex->set_pad_size(fullx - size_x(), fully - size_y());

+ 3 - 0
panda/src/putil/Sources.pp

@@ -10,6 +10,7 @@
   
   
   #define SOURCES \
   #define SOURCES \
     animInterface.h animInterface.I \
     animInterface.h animInterface.I \
+    autoTextureScale.h \
     bam.h \
     bam.h \
     bamCache.h bamCache.I \
     bamCache.h bamCache.I \
     bamCacheIndex.h bamCacheIndex.I \
     bamCacheIndex.h bamCacheIndex.I \
@@ -73,6 +74,7 @@
     
     
  #define INCLUDED_SOURCES \
  #define INCLUDED_SOURCES \
     animInterface.cxx \
     animInterface.cxx \
+    autoTextureScale.cxx \
     bamCache.cxx \
     bamCache.cxx \
     bamCacheIndex.cxx \
     bamCacheIndex.cxx \
     bamCacheRecord.cxx \
     bamCacheRecord.cxx \
@@ -119,6 +121,7 @@
 
 
   #define INSTALL_HEADERS \
   #define INSTALL_HEADERS \
     animInterface.h animInterface.I \
     animInterface.h animInterface.I \
+    autoTextureScale.h \
     bam.h \
     bam.h \
     bamCache.h bamCache.I \
     bamCache.h bamCache.I \
     bamCacheIndex.h bamCacheIndex.I \
     bamCacheIndex.h bamCacheIndex.I \

+ 70 - 0
panda/src/putil/autoTextureScale.cxx

@@ -0,0 +1,70 @@
+// Filename: autoTextureScale.cxx
+// Created by:  drose (28Nov11)
+//
+////////////////////////////////////////////////////////////////////
+//
+// PANDA 3D SOFTWARE
+// Copyright (c) Carnegie Mellon University.  All rights reserved.
+//
+// All use of this software is subject to the terms of the revised BSD
+// license.  You should have received a copy of this license along
+// with this source code in a file named "LICENSE."
+//
+////////////////////////////////////////////////////////////////////
+
+#include "autoTextureScale.h"
+#include "string_utils.h"
+#include "config_util.h"
+
+ostream &
+operator << (ostream &out, AutoTextureScale ats) {
+  switch (ats) {
+  case ATS_none:
+    return out << "none";
+   
+  case ATS_down:
+    return out << "down";
+    
+  case ATS_up:
+    return out << "up";
+    
+  case ATS_pad:
+    return out << "pad";
+
+  case ATS_unspecified:
+    return out << "unspecified";
+  }
+
+  return out << "**invalid AutoTextureScale (" << (int)ats << ")**";
+}
+
+istream &
+operator >> (istream &in, AutoTextureScale &ats) {
+  string word;
+  in >> word;
+
+  if (cmp_nocase(word, "none") == 0 ||
+      cmp_nocase(word, "0") == 0 ||
+      cmp_nocase(word, "#f") == 0 ||
+      (!word.empty() && tolower(word[0]) == 'f')) {
+    ats = ATS_none;
+
+  } else if (cmp_nocase(word, "down") == 0 ||
+             cmp_nocase(word, "1") == 0 ||
+             cmp_nocase(word, "#t") == 0 ||
+             (!word.empty() && tolower(word[0]) == 't')) {
+    ats = ATS_down;
+
+  } else if (cmp_nocase(word, "up") == 0) {
+    ats = ATS_up;
+
+  } else if (cmp_nocase(word, "pad") == 0) {
+    ats = ATS_pad;
+
+  } else {
+    util_cat->error() << "Invalid AutoTextureScale value: " << word << "\n";
+    ats = ATS_none;
+  }
+
+  return in;
+}

+ 33 - 0
panda/src/putil/autoTextureScale.h

@@ -0,0 +1,33 @@
+// Filename: autoTextureScale.h
+// Created by:  drose (28Nov11)
+//
+////////////////////////////////////////////////////////////////////
+//
+// PANDA 3D SOFTWARE
+// Copyright (c) Carnegie Mellon University.  All rights reserved.
+//
+// All use of this software is subject to the terms of the revised BSD
+// license.  You should have received a copy of this license along
+// with this source code in a file named "LICENSE."
+//
+////////////////////////////////////////////////////////////////////
+
+#ifndef AUTOTEXTURESCALE_H
+#define AUTOTEXTURESCALE_H
+
+#include "pandabase.h"
+
+BEGIN_PUBLISH
+enum AutoTextureScale {
+  ATS_none,
+  ATS_down,
+  ATS_up,
+  ATS_pad,
+  ATS_unspecified,
+};
+END_PUBLISH
+
+EXPCL_PANDA_PUTIL ostream &operator << (ostream &out, AutoTextureScale ats);
+EXPCL_PANDA_PUTIL istream &operator >> (istream &in, AutoTextureScale &ats);
+
+#endif

+ 2 - 1
panda/src/putil/bam.h

@@ -33,7 +33,7 @@ static const unsigned short _bam_major_ver = 6;
 // Bumped to major version 6 on 2/11/06 to factor out PandaNode::CData.
 // Bumped to major version 6 on 2/11/06 to factor out PandaNode::CData.
 
 
 static const unsigned short _bam_first_minor_ver = 14;
 static const unsigned short _bam_first_minor_ver = 14;
-static const unsigned short _bam_minor_ver = 27;
+static const unsigned short _bam_minor_ver = 28;
 // Bumped to minor version 14 on 12/19/07 to change default ColorAttrib.
 // Bumped to minor version 14 on 12/19/07 to change default ColorAttrib.
 // Bumped to minor version 15 on 4/9/08 to add TextureAttrib::_implicit_sort.
 // Bumped to minor version 15 on 4/9/08 to add TextureAttrib::_implicit_sort.
 // Bumped to minor version 16 on 5/13/08 to add Texture::_quality_level.
 // Bumped to minor version 16 on 5/13/08 to add Texture::_quality_level.
@@ -48,6 +48,7 @@ static const unsigned short _bam_minor_ver = 27;
 // Bumped to minor version 25 on 6/22/11 to add support for caching movie files.
 // Bumped to minor version 25 on 6/22/11 to add support for caching movie files.
 // Bumped to minor version 26 on 8/5/11 to add multiview (stereo) Textures.
 // Bumped to minor version 26 on 8/5/11 to add multiview (stereo) Textures.
 // Bumped to minor version 27 on 10/9/11 to add stdfloat_double.
 // Bumped to minor version 27 on 10/9/11 to add stdfloat_double.
+// Bumped to minor version 28 on 11/28/11 to add Texture::_auto_texture_scale.
 
 
 
 
 #endif
 #endif

+ 28 - 2
panda/src/putil/loaderOptions.I

@@ -22,7 +22,8 @@ INLINE LoaderOptions::
 LoaderOptions(int flags, int texture_flags) : 
 LoaderOptions(int flags, int texture_flags) : 
   _flags(flags), 
   _flags(flags), 
   _texture_flags(texture_flags),
   _texture_flags(texture_flags),
-  _texture_num_views(0)
+  _texture_num_views(0),
+  _auto_texture_scale(ATS_unspecified)
 {
 {
 }
 }
 
 
@@ -35,7 +36,8 @@ INLINE LoaderOptions::
 LoaderOptions(const LoaderOptions &copy) :
 LoaderOptions(const LoaderOptions &copy) :
   _flags(copy._flags),
   _flags(copy._flags),
   _texture_flags(copy._texture_flags),
   _texture_flags(copy._texture_flags),
-  _texture_num_views(copy._texture_num_views)
+  _texture_num_views(copy._texture_num_views),
+  _auto_texture_scale(copy._auto_texture_scale)
 {
 {
 }
 }
 
 
@@ -49,6 +51,7 @@ operator = (const LoaderOptions &copy) {
   _flags = copy._flags;
   _flags = copy._flags;
   _texture_flags = copy._texture_flags;
   _texture_flags = copy._texture_flags;
   _texture_num_views = copy._texture_num_views;
   _texture_num_views = copy._texture_num_views;
+  _auto_texture_scale = copy._auto_texture_scale;
 }
 }
 
 
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
@@ -117,3 +120,26 @@ INLINE int LoaderOptions::
 get_texture_num_views() const {
 get_texture_num_views() const {
   return _texture_num_views;
   return _texture_num_views;
 }
 }
+
+////////////////////////////////////////////////////////////////////
+//     Function: LoaderOptions::set_auto_texture_scale
+//       Access: Published
+//  Description: Set this flag to ATS_none, ATS_up, ATS_down, or
+//               ATS_pad to control how a texture is scaled from
+//               disk when it is subsequently loaded.  Set it to
+//               ATS_unspecified to restore the default behavior.
+////////////////////////////////////////////////////////////////////
+INLINE void LoaderOptions::
+set_auto_texture_scale(AutoTextureScale scale) {
+  _auto_texture_scale = scale;
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: LoaderOptions::get_auto_texture_scale
+//       Access: Published
+//  Description: See set_auto_texture_scale().
+////////////////////////////////////////////////////////////////////
+INLINE AutoTextureScale LoaderOptions::
+get_auto_texture_scale() const {
+  return _auto_texture_scale;
+}

+ 6 - 1
panda/src/putil/loaderOptions.cxx

@@ -25,7 +25,8 @@ LoaderOptions::
 LoaderOptions(int flags) : 
 LoaderOptions(int flags) : 
   _flags(flags), 
   _flags(flags), 
   _texture_flags(0),
   _texture_flags(0),
-  _texture_num_views(0)
+  _texture_num_views(0),
+  _auto_texture_scale(ATS_unspecified)
 {
 {
   // Shadowing the variables in config_util for static init ordering
   // Shadowing the variables in config_util for static init ordering
   // issues.
   // issues.
@@ -86,6 +87,10 @@ output(ostream &out) const {
     out << "0";
     out << "0";
   }
   }
 
 
+  if (_auto_texture_scale != ATS_unspecified) {
+    out << ", ATS_" << _auto_texture_scale;
+  }
+
   out << ")";
   out << ")";
 }
 }
 
 

+ 5 - 0
panda/src/putil/loaderOptions.h

@@ -16,6 +16,7 @@
 #define LOADEROPTIONS_H
 #define LOADEROPTIONS_H
 
 
 #include "pandabase.h"
 #include "pandabase.h"
+#include "autoTextureScale.h"
 
 
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 //       Class : LoaderOptions
 //       Class : LoaderOptions
@@ -60,6 +61,9 @@ PUBLISHED:
   INLINE void set_texture_num_views(int num_views);
   INLINE void set_texture_num_views(int num_views);
   INLINE int get_texture_num_views() const;
   INLINE int get_texture_num_views() const;
 
 
+  INLINE void set_auto_texture_scale(AutoTextureScale scale);
+  INLINE AutoTextureScale get_auto_texture_scale() const;
+
   void output(ostream &out) const;
   void output(ostream &out) const;
 
 
 private:
 private:
@@ -70,6 +74,7 @@ private:
   int _flags;
   int _flags;
   int _texture_flags;
   int _texture_flags;
   int _texture_num_views;
   int _texture_num_views;
+  AutoTextureScale _auto_texture_scale;
 };
 };
 
 
 INLINE ostream &operator << (ostream &out, const LoaderOptions &opts) {
 INLINE ostream &operator << (ostream &out, const LoaderOptions &opts) {

+ 1 - 0
panda/src/putil/putil_composite1.cxx

@@ -1,4 +1,5 @@
 #include "animInterface.cxx"
 #include "animInterface.cxx"
+#include "autoTextureScale.cxx"
 #include "bamCache.cxx"
 #include "bamCache.cxx"
 #include "bamCacheIndex.cxx"
 #include "bamCacheIndex.cxx"
 #include "bamCacheRecord.cxx"
 #include "bamCacheRecord.cxx"

+ 1 - 5
panda/src/vision/openCVTexture.cxx

@@ -233,11 +233,7 @@ do_reconsider_video_properties(Texture::CData *cdata,
 
 
   int x_size = width;
   int x_size = width;
   int y_size = height;
   int y_size = height;
-
-  if (Texture::get_textures_power_2() != ATS_none) {
-    x_size = up_to_power_2(width);
-    y_size = up_to_power_2(height);
-  }
+  do_adjust_this_size(cdata, x_size, y_size, get_name(), true);
 
 
   if (vision_cat.is_debug()) {
   if (vision_cat.is_debug()) {
     vision_cat.debug()
     vision_cat.debug()