From 74a1ebca02bf2ca855b46c601c1ff13f1646b8be Mon Sep 17 00:00:00 2001 From: David Rose Date: Wed, 2 Nov 2005 18:57:30 +0000 Subject: [PATCH] add textures-header-only --- panda/src/gobj/config_gobj.cxx | 8 ++++ panda/src/gobj/config_gobj.h | 1 + panda/src/gobj/texture.cxx | 72 ++++++++++++++++++++++++++++------ 3 files changed, 68 insertions(+), 13 deletions(-) diff --git a/panda/src/gobj/config_gobj.cxx b/panda/src/gobj/config_gobj.cxx index c14572c56b..e187fa14d9 100644 --- a/panda/src/gobj/config_gobj.cxx +++ b/panda/src/gobj/config_gobj.cxx @@ -188,6 +188,14 @@ ConfigVariableEnum textures_square "a square aspect ratio when they are loaded from disk. Set this " "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 ("geom-cache-size", 5000, PRC_DESC("Specifies the maximum number of entries in the cache " diff --git a/panda/src/gobj/config_gobj.h b/panda/src/gobj/config_gobj.h index 6cc55bae81..ad1a2dc693 100644 --- a/panda/src/gobj/config_gobj.h +++ b/panda/src/gobj/config_gobj.h @@ -61,6 +61,7 @@ extern EXPCL_PANDA ConfigVariableBool connect_triangle_strips; extern EXPCL_PANDA ConfigVariableEnum bam_texture_mode; extern EXPCL_PANDA ConfigVariableEnum textures_power_2; extern EXPCL_PANDA ConfigVariableEnum textures_square; +extern EXPCL_PANDA ConfigVariableBool textures_header_only; extern EXPCL_PANDA ConfigVariableInt geom_cache_size; extern EXPCL_PANDA ConfigVariableInt geom_cache_min_frames; diff --git a/panda/src/gobj/texture.cxx b/panda/src/gobj/texture.cxx index 21ea52d429..cb41ccd056 100644 --- a/panda/src/gobj/texture.cxx +++ b/panda/src/gobj/texture.cxx @@ -288,10 +288,25 @@ bool Texture:: read(const Filename &fullpath, int z, int primary_file_num_channels) { 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()) { @@ -327,19 +342,50 @@ bool Texture:: read(const Filename &fullpath, const Filename &alpha_fullpath, int z, int primary_file_num_channels, int alpha_file_channel) { 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; - 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()) { set_name(fullpath.get_basename_wo_extension()); }