Jelajahi Sumber

add textures-header-only

David Rose 20 tahun lalu
induk
melakukan
74a1ebca02
3 mengubah file dengan 68 tambahan dan 13 penghapusan
  1. 8 0
      panda/src/gobj/config_gobj.cxx
  2. 1 0
      panda/src/gobj/config_gobj.h
  3. 59 13
      panda/src/gobj/texture.cxx

+ 8 - 0
panda/src/gobj/config_gobj.cxx

@@ -188,6 +188,14 @@ ConfigVariableEnum<AutoTextureScale> textures_square
           "a square aspect ratio when they are loaded from disk.  Set this "
           "a square aspect ratio when they are loaded from disk.  Set this "
           "to 'none', 'down', or 'up'.  See textures-power-2."));
           "to 'none', 'down', or 'up'.  See textures-power-2."));
 
 
+extern EXPCL_PANDA ConfigVariableBool textures_header_only;
+ConfigVariableBool textures_header_only
+("textures-header-only", false,
+ PRC_DESC("If this is true, texture images will not actually be loaded from "
+	  "disk, but the image header information will be consulted to verify "
+	  "number of channels and so forth.  The texture images themselves "
+	  "will be generated in a default blue color."));
+
 ConfigVariableInt geom_cache_size
 ConfigVariableInt geom_cache_size
 ("geom-cache-size", 5000,
 ("geom-cache-size", 5000,
  PRC_DESC("Specifies the maximum number of entries in the cache "
  PRC_DESC("Specifies the maximum number of entries in the cache "

+ 1 - 0
panda/src/gobj/config_gobj.h

@@ -61,6 +61,7 @@ extern EXPCL_PANDA ConfigVariableBool connect_triangle_strips;
 extern EXPCL_PANDA ConfigVariableEnum<BamTextureMode> bam_texture_mode;
 extern EXPCL_PANDA ConfigVariableEnum<BamTextureMode> bam_texture_mode;
 extern EXPCL_PANDA ConfigVariableEnum<AutoTextureScale> textures_power_2;
 extern EXPCL_PANDA ConfigVariableEnum<AutoTextureScale> textures_power_2;
 extern EXPCL_PANDA ConfigVariableEnum<AutoTextureScale> textures_square;
 extern EXPCL_PANDA ConfigVariableEnum<AutoTextureScale> textures_square;
+extern EXPCL_PANDA ConfigVariableBool textures_header_only;
 
 
 extern EXPCL_PANDA ConfigVariableInt geom_cache_size;
 extern EXPCL_PANDA ConfigVariableInt geom_cache_size;
 extern EXPCL_PANDA ConfigVariableInt geom_cache_min_frames;
 extern EXPCL_PANDA ConfigVariableInt geom_cache_min_frames;

+ 59 - 13
panda/src/gobj/texture.cxx

@@ -288,10 +288,25 @@ bool Texture::
 read(const Filename &fullpath, int z, int primary_file_num_channels) {
 read(const Filename &fullpath, int z, int primary_file_num_channels) {
   PNMImage image;
   PNMImage image;
 
 
-  if (!image.read(fullpath, NULL, false)) {
-    gobj_cat.error()
-      << "Texture::read() - couldn't read: " << fullpath << endl;
-    return false;
+  if (textures_header_only) {
+    if (!image.read_header(fullpath)) {
+      gobj_cat.error()
+	<< "Texture::read() - couldn't read: " << fullpath << endl;
+      return false;
+    }
+    image = PNMImage(1, 1, image.get_num_channels(), image.get_maxval(),
+		     image.get_type());
+    image.fill(0.2, 0.3, 1.0);
+    if (image.has_alpha()) {
+      image.alpha_fill(1.0);
+    }
+
+  } else {
+    if (!image.read(fullpath, NULL, false)) {
+      gobj_cat.error()
+	<< "Texture::read() - couldn't read: " << fullpath << endl;
+      return false;
+    }
   }
   }
 
 
   if (!has_name()) {
   if (!has_name()) {
@@ -327,19 +342,50 @@ bool Texture::
 read(const Filename &fullpath, const Filename &alpha_fullpath,
 read(const Filename &fullpath, const Filename &alpha_fullpath,
      int z, int primary_file_num_channels, int alpha_file_channel) {
      int z, int primary_file_num_channels, int alpha_file_channel) {
   PNMImage image;
   PNMImage image;
-  if (!image.read(fullpath, NULL, false)) {
-    gobj_cat.error()
-      << "Texture::read() - couldn't read: " << fullpath << endl;
-    return false;
+  if (textures_header_only) {
+    if (!image.read_header(fullpath)) {
+      gobj_cat.error()
+	<< "Texture::read() - couldn't read: " << fullpath << endl;
+      return false;
+    }
+    image = PNMImage(1, 1, image.get_num_channels(), image.get_maxval(),
+		     image.get_type());
+    image.fill(0.2, 0.3, 1.0);
+    if (image.has_alpha()) {
+      image.alpha_fill(1.0);
+    }
+
+  } else {
+    if (!image.read(fullpath, NULL, false)) {
+      gobj_cat.error()
+	<< "Texture::read() - couldn't read: " << fullpath << endl;
+      return false;
+    }
   }
   }
 
 
   PNMImage alpha_image;
   PNMImage alpha_image;
-  if (!alpha_image.read(alpha_fullpath, NULL, true)) {
-    gobj_cat.error()
-      << "Texture::read() - couldn't read (alpha): " << alpha_fullpath << endl;
-    return false;
-  }
+  if (textures_header_only) {
+    if (!alpha_image.read_header(alpha_fullpath)) {
+      gobj_cat.error()
+	<< "Texture::read() - couldn't read: " << alpha_fullpath << endl;
+      return false;
+    }
+    alpha_image = PNMImage(1, 1, alpha_image.get_num_channels(), 
+			   alpha_image.get_maxval(),
+			   alpha_image.get_type());
+    alpha_image.fill(1.0);
+    if (alpha_image.has_alpha()) {
+      alpha_image.alpha_fill(1.0);
+    }
 
 
+  } else {
+    if (!alpha_image.read(alpha_fullpath, NULL, true)) {
+      gobj_cat.error()
+	<< "Texture::read() - couldn't read (alpha): " << alpha_fullpath << endl;
+      return false;
+    }
+  }
+    
   if (!has_name()) {
   if (!has_name()) {
     set_name(fullpath.get_basename_wo_extension());
     set_name(fullpath.get_basename_wo_extension());
   }
   }