support quality_level

This commit is contained in:
David Rose 2009-02-27 02:53:11 +00:00
parent 737f3bfc47
commit 9faf063f4c
6 changed files with 111 additions and 41 deletions

View File

@ -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) {

View File

@ -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;

View File

@ -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

View File

@ -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);

View File

@ -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;

View File

@ -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;