Ver código fonte

add -f option

David Rose 24 anos atrás
pai
commit
66490510c2

+ 30 - 0
pandatool/src/eggprogs/eggTextureCards.cxx

@@ -80,9 +80,16 @@ EggTextureCards() : EggWriter(true, true) {
      "(or \"r\" or \"c\").  The default is to leave this unspecified.",
      "(or \"r\" or \"c\").  The default is to leave this unspecified.",
      &EggTextureCards::dispatch_wrap_mode, NULL, &_wrap_mode);
      &EggTextureCards::dispatch_wrap_mode, NULL, &_wrap_mode);
 
 
+  add_option
+    ("f", "format", 0,
+     "Indicates the format of the texture: typical choices are \"rgba12\" "
+     "or \"rgb5\" or \"alpha\".  The default is to leave this unspecified.",
+     &EggTextureCards::dispatch_format, NULL, &_format);
+
   _polygon_geometry.set(-0.5, 0.5, -0.5, 0.5);
   _polygon_geometry.set(-0.5, 0.5, -0.5, 0.5);
   _polygon_color.set(1.0, 1.0, 1.0, 1.0);
   _polygon_color.set(1.0, 1.0, 1.0, 1.0);
   _wrap_mode = EggTexture::WM_unspecified;
   _wrap_mode = EggTexture::WM_unspecified;
+  _format = EggTexture::F_unspecified;
 }
 }
 
 
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
@@ -139,6 +146,28 @@ dispatch_wrap_mode(const string &opt, const string &arg, void *var) {
   return true;
   return true;
 }
 }
 
 
+////////////////////////////////////////////////////////////////////
+//     Function: EggTextureCards::dispatch_format
+//       Access: Protected, Static
+//  Description: Standard dispatch function for an option that takes
+//               one parameter, which is to be interpreted as a
+//               Format string.  The data pointer is to a Format
+//               enum variable.
+////////////////////////////////////////////////////////////////////
+bool EggTextureCards::
+dispatch_format(const string &opt, const string &arg, void *var) {
+  EggTexture::Format *fp = (EggTexture::Format *)var;
+
+  *fp = EggTexture::string_format(arg);
+  if (*fp == EggTexture::F_unspecified) {
+    nout << "Invalid format parameter for -" << opt << ": "
+         << arg << "\n";
+    return false;
+  }
+
+  return true;
+}
+
 
 
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 //     Function: EggTextureCards::scan_texture
 //     Function: EggTextureCards::scan_texture
@@ -251,6 +280,7 @@ run() {
     if (texture_ok) {
     if (texture_ok) {
       EggTexture *tref = new EggTexture(name, filename);
       EggTexture *tref = new EggTexture(name, filename);
       tref->set_wrap_mode(_wrap_mode);
       tref->set_wrap_mode(_wrap_mode);
+      tref->set_format(_format);
       group->add_child(tref);
       group->add_child(tref);
 
 
       // Each polygon gets placed in its own sub-group.  This will make
       // Each polygon gets placed in its own sub-group.  This will make

+ 2 - 0
pandatool/src/eggprogs/eggTextureCards.h

@@ -42,6 +42,7 @@ protected:
   virtual bool handle_args(Args &args);
   virtual bool handle_args(Args &args);
 
 
   static bool dispatch_wrap_mode(const string &opt, const string &arg, void *var);
   static bool dispatch_wrap_mode(const string &opt, const string &arg, void *var);
+  static bool dispatch_format(const string &opt, const string &arg, void *var);
 
 
 private:
 private:
   bool scan_texture(const Filename &filename, LVecBase4d &geometry);
   bool scan_texture(const Filename &filename, LVecBase4d &geometry);
@@ -57,6 +58,7 @@ public:
   Colorf _polygon_color;
   Colorf _polygon_color;
   vector_string _texture_names;
   vector_string _texture_names;
   EggTexture::WrapMode _wrap_mode;
   EggTexture::WrapMode _wrap_mode;
+  EggTexture::Format _format;
 };
 };
 
 
 #endif
 #endif