From 9faf063f4c2a4e86717c017aa664cd905bf191bd Mon Sep 17 00:00:00 2001 From: David Rose Date: Fri, 27 Feb 2009 02:53:11 +0000 Subject: [PATCH] support quality_level --- pandatool/src/eggprogs/eggTextureCards.cxx | 30 +++++++++ pandatool/src/eggprogs/eggTextureCards.h | 2 + .../src/palettizer/textureProperties.cxx | 64 +++++++++++++------ pandatool/src/palettizer/textureProperties.h | 1 + pandatool/src/palettizer/txaLine.cxx | 54 ++++++++++------ pandatool/src/palettizer/txaLine.h | 1 + 6 files changed, 111 insertions(+), 41 deletions(-) diff --git a/pandatool/src/eggprogs/eggTextureCards.cxx b/pandatool/src/eggprogs/eggTextureCards.cxx index 75d7b959b4..ce2413fb22 100644 --- a/pandatool/src/eggprogs/eggTextureCards.cxx +++ b/pandatool/src/eggprogs/eggTextureCards.cxx @@ -86,6 +86,12 @@ EggTextureCards() : EggWriter(true, true) { "(or \"r\" or \"c\"). The default is to leave this unspecified.", &EggTextureCards::dispatch_wrap_mode, NULL, &_wrap_mode); + add_option + ("ql", "[default | fastest | normal | best]", 0, + "Specifies the quality level of the texture. This mainly affects " + "the tinydisplay software renderer.", + &EggTextureCards::dispatch_quality_level, NULL, &_quality_level); + add_option ("f", "format", 0, "Indicates the format for all textures: typical choices are \"rgba12\" " @@ -142,6 +148,7 @@ EggTextureCards() : EggWriter(true, true) { _polygon_geometry.set(-0.5, 0.5, -0.5, 0.5); _polygon_color.set(1.0, 1.0, 1.0, 1.0); _wrap_mode = EggTexture::WM_unspecified; + _quality_level = EggTexture::QL_unspecified; _format = EggTexture::F_unspecified; _format_1 = EggTexture::F_unspecified; _format_2 = EggTexture::F_unspecified; @@ -204,6 +211,28 @@ dispatch_wrap_mode(const string &opt, const string &arg, void *var) { return true; } +//////////////////////////////////////////////////////////////////// +// Function: EggTextureCards::dispatch_quality_level +// Access: Protected, Static +// Description: Standard dispatch function for an option that takes +// one parameter, which is to be interpreted as a +// QualityLevel string. The data pointer is to a +// QualityLevel enum variable. +//////////////////////////////////////////////////////////////////// +bool EggTextureCards:: +dispatch_quality_level(const string &opt, const string &arg, void *var) { + EggTexture::QualityLevel *qlp = (EggTexture::QualityLevel *)var; + + *qlp = EggTexture::string_quality_level(arg); + if (*qlp == EggTexture::QL_unspecified) { + nout << "Invalid quality level parameter for -" << opt << ": " + << arg << "\n"; + return false; + } + + return true; +} + //////////////////////////////////////////////////////////////////// // Function: EggTextureCards::dispatch_format // Access: Protected, Static @@ -359,6 +388,7 @@ run() { EggTexture *tref = new EggTexture(name, filename); tref->set_wrap_mode(_wrap_mode); + tref->set_quality_level(_quality_level); if (texture_ok) { switch (num_channels) { diff --git a/pandatool/src/eggprogs/eggTextureCards.h b/pandatool/src/eggprogs/eggTextureCards.h index ee5cb2a524..c4920895dc 100644 --- a/pandatool/src/eggprogs/eggTextureCards.h +++ b/pandatool/src/eggprogs/eggTextureCards.h @@ -39,6 +39,7 @@ protected: virtual bool handle_args(Args &args); static bool dispatch_wrap_mode(const string &opt, const string &arg, void *var); + static bool dispatch_quality_level(const string &opt, const string &arg, void *var); static bool dispatch_format(const string &opt, const string &arg, void *var); private: @@ -57,6 +58,7 @@ public: Colorf _polygon_color; vector_string _texture_names; EggTexture::WrapMode _wrap_mode; + EggTexture::QualityLevel _quality_level; EggTexture::Format _format; EggTexture::Format _format_1, _format_2, _format_3, _format_4; bool _apply_bface; diff --git a/pandatool/src/palettizer/textureProperties.cxx b/pandatool/src/palettizer/textureProperties.cxx index 853cdabdd2..31e384e992 100644 --- a/pandatool/src/palettizer/textureProperties.cxx +++ b/pandatool/src/palettizer/textureProperties.cxx @@ -223,6 +223,7 @@ get_string() const { result += get_filter_string(_magfilter); result += get_anisotropic_degree_string(_anisotropic_degree); result += get_type_string(_color_type, _alpha_type); + result += get_quality_level_string(_quality_level); return result; } @@ -655,26 +656,26 @@ get_format_string(EggTexture::Format format) { string TextureProperties:: get_filter_string(EggTexture::FilterType filter_type) { switch (filter_type) { - case EggTexture::FT_unspecified: - return "u"; - - case EggTexture::FT_nearest: - return "n"; - - case EggTexture::FT_linear: - return "l"; - - case EggTexture::FT_nearest_mipmap_nearest: - return "m1"; - - case EggTexture::FT_linear_mipmap_nearest: - return "m2"; - - case EggTexture::FT_nearest_mipmap_linear: - return "m3"; - - case EggTexture::FT_linear_mipmap_linear: - return "m"; + case EggTexture::FT_unspecified: + return "u"; + + case EggTexture::FT_nearest: + return "n"; + + case EggTexture::FT_linear: + return "l"; + + case EggTexture::FT_nearest_mipmap_nearest: + return "m1"; + + case EggTexture::FT_linear_mipmap_nearest: + return "m2"; + + case EggTexture::FT_nearest_mipmap_linear: + return "m3"; + + case EggTexture::FT_linear_mipmap_linear: + return "m"; } return "x"; @@ -694,6 +695,29 @@ get_anisotropic_degree_string(int aniso_degree) { } } +//////////////////////////////////////////////////////////////////// +// Function: TextureProperties::get_quality_level_string +// Access: Private, Static +// Description: Returns a short string describing the quality level. +//////////////////////////////////////////////////////////////////// +string TextureProperties:: +get_quality_level_string(EggTexture::QualityLevel quality_level) { + switch (quality_level) { + case EggTexture::QL_unspecified: + case EggTexture::QL_default: + return ""; + + case EggTexture::QL_fastest: + return "f"; + + case EggTexture::QL_normal: + return "n"; + + case EggTexture::QL_best: + return "b"; + } +} + //////////////////////////////////////////////////////////////////// // Function: TextureProperties::get_type_string // Access: Private, Static diff --git a/pandatool/src/palettizer/textureProperties.h b/pandatool/src/palettizer/textureProperties.h index bd6b88d2de..58928b10b4 100644 --- a/pandatool/src/palettizer/textureProperties.h +++ b/pandatool/src/palettizer/textureProperties.h @@ -71,6 +71,7 @@ private: static string get_format_string(EggTexture::Format format); static string get_filter_string(EggTexture::FilterType filter_type); static string get_anisotropic_degree_string(int aniso_degree); + static string get_quality_level_string(EggTexture::QualityLevel quality_level); static string get_type_string(PNMFileType *color_type, PNMFileType *alpha_type); diff --git a/pandatool/src/palettizer/txaLine.cxx b/pandatool/src/palettizer/txaLine.cxx index 5f921052af..4048742113 100644 --- a/pandatool/src/palettizer/txaLine.cxx +++ b/pandatool/src/palettizer/txaLine.cxx @@ -43,6 +43,7 @@ TxaLine() { _alpha_mode = EggRenderMode::AM_unspecified; _wrap_u = EggTexture::WM_unspecified; _wrap_v = EggTexture::WM_unspecified; + _quality_level = EggTexture::QL_unspecified; _got_margin = false; _margin = 0; _got_coverage_threshold = false; @@ -283,28 +284,35 @@ parse(const string &line) { if (am != EggRenderMode::AM_unspecified) { _alpha_mode = am; - } else if (word.length() > 2 && word[word.length() - 2] == '_' && - strchr("uv", word[word.length() - 1]) != NULL) { - // It must be a wrap mode for u or v. - string prefix = word.substr(0, word.length() - 2); - EggTexture::WrapMode wm = EggTexture::string_wrap_mode(prefix); - if (wm == EggTexture::WM_unspecified) { - return false; - } - switch (word[word.length() - 1]) { - case 'u': - _wrap_u = wm; - break; - - case 'v': - _wrap_v = wm; - break; - } - } else { - // Maybe it's an image file request. - if (!parse_image_type_request(word, _color_type, _alpha_type)) { - return false; + // Maybe it's a quality level. + EggTexture::QualityLevel ql = EggTexture::string_quality_level(word); + if (ql != EggTexture::QL_unspecified) { + _quality_level = ql; + + } else if (word.length() > 2 && word[word.length() - 2] == '_' && + strchr("uv", word[word.length() - 1]) != NULL) { + // It must be a wrap mode for u or v. + string prefix = word.substr(0, word.length() - 2); + EggTexture::WrapMode wm = EggTexture::string_wrap_mode(prefix); + if (wm == EggTexture::WM_unspecified) { + return false; + } + switch (word[word.length() - 1]) { + case 'u': + _wrap_u = wm; + break; + + case 'v': + _wrap_v = wm; + break; + } + + } else { + // Maybe it's an image file request. + if (!parse_image_type_request(word, _color_type, _alpha_type)) { + return false; + } } } } @@ -450,6 +458,10 @@ match_texture(TextureImage *texture) const { request._properties._alpha_type = _alpha_type; } + if (_quality_level != EggTexture::QL_unspecified) { + request._properties._quality_level = _quality_level; + } + if (_format != EggTexture::F_unspecified) { request._format = _format; request._force_format = _force_format; diff --git a/pandatool/src/palettizer/txaLine.h b/pandatool/src/palettizer/txaLine.h index f4acd12b7f..64aefa5c54 100644 --- a/pandatool/src/palettizer/txaLine.h +++ b/pandatool/src/palettizer/txaLine.h @@ -70,6 +70,7 @@ private: bool _keep_format; EggRenderMode::AlphaMode _alpha_mode; EggTexture::WrapMode _wrap_u, _wrap_v; + EggTexture::QualityLevel _quality_level; int _aniso_degree; bool _got_margin;