anisotropic texfilter support

This commit is contained in:
cxgeorge 2002-08-22 23:17:51 +00:00
parent b7829a141d
commit 67750a8932
7 changed files with 103 additions and 36 deletions

View File

@ -18,7 +18,7 @@
#include "textureProperties.h" #include "textureProperties.h"
#include "palettizer.h" #include "palettizer.h"
#include <stdio.h>
#include "pnmFileType.h" #include "pnmFileType.h"
#include "datagram.h" #include "datagram.h"
#include "datagramIterator.h" #include "datagramIterator.h"
@ -40,6 +40,7 @@ TextureProperties() {
_force_format = false; _force_format = false;
_minfilter = EggTexture::FT_unspecified; _minfilter = EggTexture::FT_unspecified;
_magfilter = EggTexture::FT_unspecified; _magfilter = EggTexture::FT_unspecified;
_anisotropic_degree = 0;
_color_type = (PNMFileType *)NULL; _color_type = (PNMFileType *)NULL;
_alpha_type = (PNMFileType *)NULL; _alpha_type = (PNMFileType *)NULL;
} }
@ -57,6 +58,7 @@ TextureProperties(const TextureProperties &copy) :
_force_format(copy._force_format), _force_format(copy._force_format),
_minfilter(copy._minfilter), _minfilter(copy._minfilter),
_magfilter(copy._magfilter), _magfilter(copy._magfilter),
_anisotropic_degree(copy._anisotropic_degree),
_color_type(copy._color_type), _color_type(copy._color_type),
_alpha_type(copy._alpha_type) _alpha_type(copy._alpha_type)
{ {
@ -75,6 +77,7 @@ operator = (const TextureProperties &copy) {
_force_format = copy._force_format; _force_format = copy._force_format;
_minfilter = copy._minfilter; _minfilter = copy._minfilter;
_magfilter = copy._magfilter; _magfilter = copy._magfilter;
_anisotropic_degree = copy._anisotropic_degree;
_color_type = copy._color_type; _color_type = copy._color_type;
_alpha_type = copy._alpha_type; _alpha_type = copy._alpha_type;
} }
@ -153,9 +156,11 @@ get_string() const {
num << _num_channels; num << _num_channels;
result += num.str(); result += num.str();
} }
result += get_format_string(_format); result += get_format_string(_format);
result += get_filter_string(_minfilter); result += get_filter_string(_minfilter);
result += get_filter_string(_magfilter); result += get_filter_string(_magfilter);
result += get_anisotropic_degree_string(_anisotropic_degree);
result += get_type_string(_color_type, _alpha_type); result += get_type_string(_color_type, _alpha_type);
return result; return result;
} }
@ -182,6 +187,7 @@ update_properties(const TextureProperties &other) {
_minfilter = union_filter(_minfilter, other._minfilter); _minfilter = union_filter(_minfilter, other._minfilter);
_magfilter = union_filter(_magfilter, other._magfilter); _magfilter = union_filter(_magfilter, other._magfilter);
_anisotropic_degree = max(_anisotropic_degree, other._anisotropic_degree);
if (_color_type == (PNMFileType *)NULL) { if (_color_type == (PNMFileType *)NULL) {
_color_type = other._color_type; _color_type = other._color_type;
@ -339,6 +345,7 @@ update_egg_tex(EggTexture *egg_tex) const {
egg_tex->set_format(_format); egg_tex->set_format(_format);
egg_tex->set_minfilter(_minfilter); egg_tex->set_minfilter(_minfilter);
egg_tex->set_magfilter(_minfilter); egg_tex->set_magfilter(_minfilter);
egg_tex->set_anisotropic_degree(_anisotropic_degree);
} }
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
@ -353,7 +360,8 @@ bool TextureProperties::
egg_properties_match(const TextureProperties &other) const { egg_properties_match(const TextureProperties &other) const {
return (_format == other._format && return (_format == other._format &&
_minfilter == other._minfilter && _minfilter == other._minfilter &&
_magfilter == other._magfilter); _magfilter == other._magfilter &&
_anisotropic_degree == other._anisotropic_degree);
} }
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
@ -372,6 +380,9 @@ operator < (const TextureProperties &other) const {
if (_magfilter != other._magfilter) { if (_magfilter != other._magfilter) {
return (int)_magfilter < (int)other._magfilter; return (int)_magfilter < (int)other._magfilter;
} }
if (_anisotropic_degree != other._anisotropic_degree) {
return _anisotropic_degree < other._anisotropic_degree;
}
if (_color_type != other._color_type) { if (_color_type != other._color_type) {
return _color_type < other._color_type; return _color_type < other._color_type;
} }
@ -393,6 +404,7 @@ operator == (const TextureProperties &other) const {
return (_format == other._format && return (_format == other._format &&
_minfilter == other._minfilter && _minfilter == other._minfilter &&
_magfilter == other._magfilter && _magfilter == other._magfilter &&
_anisotropic_degree == other._anisotropic_degree &&
_color_type == other._color_type && _color_type == other._color_type &&
(_color_type == (PNMFileType *)NULL || (_color_type == (PNMFileType *)NULL ||
_alpha_type == other._alpha_type)); _alpha_type == other._alpha_type));
@ -487,31 +499,46 @@ get_format_string(EggTexture::Format format) {
string TextureProperties:: string TextureProperties::
get_filter_string(EggTexture::FilterType filter_type) { get_filter_string(EggTexture::FilterType filter_type) {
switch (filter_type) { switch (filter_type) {
case EggTexture::FT_unspecified: case EggTexture::FT_unspecified:
return "u"; return "u";
case EggTexture::FT_nearest: case EggTexture::FT_nearest:
return "n"; return "n";
case EggTexture::FT_linear: case EggTexture::FT_linear:
return "l"; return "l";
case EggTexture::FT_nearest_mipmap_nearest: case EggTexture::FT_nearest_mipmap_nearest:
return "m1"; return "m1";
case EggTexture::FT_linear_mipmap_nearest: case EggTexture::FT_linear_mipmap_nearest:
return "m2"; return "m2";
case EggTexture::FT_nearest_mipmap_linear: case EggTexture::FT_nearest_mipmap_linear:
return "m3"; return "m3";
case EggTexture::FT_linear_mipmap_linear: case EggTexture::FT_linear_mipmap_linear:
return "m"; return "m";
} }
return "x"; return "x";
} }
string TextureProperties::
get_anisotropic_degree_string(int aniso_degree) {
if(aniso_degree<=1)
return "";
else {
char deg_str[20];
deg_str[0]='a';
deg_str[1]='n';
sprintf(deg_str+2,"%d",aniso_degree);
string result(deg_str);
return result;
}
}
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Function: TextureProperties::get_type_string // Function: TextureProperties::get_type_string
// Access: Private, Static // Access: Private, Static
@ -612,6 +639,7 @@ write_datagram(BamWriter *writer, Datagram &datagram) {
datagram.add_bool(_force_format); datagram.add_bool(_force_format);
datagram.add_int32((int)_minfilter); datagram.add_int32((int)_minfilter);
datagram.add_int32((int)_magfilter); datagram.add_int32((int)_magfilter);
datagram.add_int32(_anisotropic_degree);
writer->write_pointer(datagram, _color_type); writer->write_pointer(datagram, _color_type);
writer->write_pointer(datagram, _alpha_type); writer->write_pointer(datagram, _alpha_type);
} }
@ -681,6 +709,7 @@ fillin(DatagramIterator &scan, BamReader *manager) {
} }
_minfilter = (EggTexture::FilterType)scan.get_int32(); _minfilter = (EggTexture::FilterType)scan.get_int32();
_magfilter = (EggTexture::FilterType)scan.get_int32(); _magfilter = (EggTexture::FilterType)scan.get_int32();
_anisotropic_degree = scan.get_int32();
manager->read_pointer(scan); // _color_type manager->read_pointer(scan); // _color_type
manager->read_pointer(scan); // _alpha_type manager->read_pointer(scan); // _alpha_type
} }

View File

@ -61,17 +61,20 @@ public:
EggTexture::Format _format; EggTexture::Format _format;
bool _force_format; bool _force_format;
EggTexture::FilterType _minfilter, _magfilter; EggTexture::FilterType _minfilter, _magfilter;
int _anisotropic_degree;
PNMFileType *_color_type; PNMFileType *_color_type;
PNMFileType *_alpha_type; PNMFileType *_alpha_type;
private: private:
static string get_format_string(EggTexture::Format format); static string get_format_string(EggTexture::Format format);
static string get_filter_string(EggTexture::FilterType filter_type); static string get_filter_string(EggTexture::FilterType filter_type);
static string get_anisotropic_degree_string(int aniso_degree);
static string get_type_string(PNMFileType *color_type, static string get_type_string(PNMFileType *color_type,
PNMFileType *alpha_type); PNMFileType *alpha_type);
static EggTexture::Format union_format(EggTexture::Format a, static EggTexture::Format union_format(EggTexture::Format a,
EggTexture::Format b); EggTexture::Format b);
static EggTexture::FilterType union_filter(EggTexture::FilterType a, static EggTexture::FilterType union_filter(EggTexture::FilterType a,
EggTexture::FilterType b); EggTexture::FilterType b);
// The TypedWritable interface follows. // The TypedWritable interface follows.

View File

@ -104,6 +104,7 @@ from_egg(EggFile *egg_file, EggData *data, EggTexture *egg_tex) {
_properties._format = _egg_tex->get_format(); _properties._format = _egg_tex->get_format();
_properties._minfilter = _egg_tex->get_minfilter(); _properties._minfilter = _egg_tex->get_minfilter();
_properties._magfilter = _egg_tex->get_magfilter(); _properties._magfilter = _egg_tex->get_magfilter();
_properties._anisotropic_degree = _egg_tex->get_anisotropic_degree();
string name = filename.get_basename(); string name = filename.get_basename();
TextureImage *texture = pal->get_texture(name); TextureImage *texture = pal->get_texture(name);
@ -402,15 +403,19 @@ write(ostream &out, int indent_level) const {
} }
switch (_properties._minfilter) { switch (_properties._minfilter) {
case EggTexture::FT_nearest_mipmap_nearest: case EggTexture::FT_nearest_mipmap_nearest:
case EggTexture::FT_linear_mipmap_nearest: case EggTexture::FT_linear_mipmap_nearest:
case EggTexture::FT_nearest_mipmap_linear: case EggTexture::FT_nearest_mipmap_linear:
case EggTexture::FT_linear_mipmap_linear: case EggTexture::FT_linear_mipmap_linear:
out << " mipmap"; out << " mipmap";
break; break;
default: default:
break; break;
}
if(_properties._anisotropic_degree>1) {
out << " aniso " << _properties._anisotropic_degree;
} }
out << "\n"; out << "\n";

View File

@ -35,6 +35,7 @@ TextureRequest() {
_force_format = false; _force_format = false;
_minfilter = EggTexture::FT_unspecified; _minfilter = EggTexture::FT_unspecified;
_magfilter = EggTexture::FT_unspecified; _magfilter = EggTexture::FT_unspecified;
_anisotropic_degree = 0;
_alpha_mode = EggRenderMode::AM_unspecified; _alpha_mode = EggRenderMode::AM_unspecified;
_omit = false; _omit = false;
_margin = 0; _margin = 0;

View File

@ -48,6 +48,7 @@ public:
bool _force_format; bool _force_format;
EggTexture::FilterType _minfilter; EggTexture::FilterType _minfilter;
EggTexture::FilterType _magfilter; EggTexture::FilterType _magfilter;
int _anisotropic_degree;
EggRenderMode::AlphaMode _alpha_mode; EggRenderMode::AlphaMode _alpha_mode;
bool _omit; bool _omit;
int _margin; int _margin;

View File

@ -38,6 +38,7 @@ TxaLine() {
_scale = 0.0; _scale = 0.0;
_x_size = 0; _x_size = 0;
_y_size = 0; _y_size = 0;
_aniso_degree = 0;
_num_channels = 0; _num_channels = 0;
_format = EggTexture::F_unspecified; _format = EggTexture::F_unspecified;
_force_format = false; _force_format = false;
@ -189,6 +190,26 @@ parse(const string &line) {
} }
_got_margin = true; _got_margin = true;
} else if (word == "aniso") {
++wi;
if (wi == words.end()) {
nout << "Integer argument required for 'aniso'.\n";
return false;
}
const string &arg = (*wi);
if (!string_to_int(arg, _aniso_degree)) {
nout << "Not an integer: " << arg << "\n";
return false;
}
if ((_aniso_degree < 2) || (_aniso_degree > 16)) {
// make it an error to specific degree 0 or 1, which means no anisotropy so it's probably an input mistake
nout << "Invalid anistropic degree (range is 2-16): " << _aniso_degree << "\n";
return false;
}
_keywords.push_back(KW_anisotropic);
} else if (word == "coverage") { } else if (word == "coverage") {
++wi; ++wi;
if (wi == words.end()) { if (wi == words.end()) {
@ -295,6 +316,7 @@ match_egg(EggFile *egg_file) const {
case KW_nearest: case KW_nearest:
case KW_linear: case KW_linear:
case KW_mipmap: case KW_mipmap:
case KW_anisotropic:
// These mean nothing to an egg file. // These mean nothing to an egg file.
break; break;
@ -421,6 +443,10 @@ match_texture(TextureImage *texture) const {
request._magfilter = EggTexture::FT_linear_mipmap_linear; request._magfilter = EggTexture::FT_linear_mipmap_linear;
break; break;
case KW_anisotropic:
request._anisotropic_degree = _aniso_degree;
break;
case KW_cont: case KW_cont:
got_cont = true; got_cont = true;
break; break;

View File

@ -72,6 +72,7 @@ private:
bool _force_format; bool _force_format;
EggRenderMode::AlphaMode _alpha_mode; EggRenderMode::AlphaMode _alpha_mode;
int _aniso_degree;
bool _got_margin; bool _got_margin;
int _margin; int _margin;
bool _got_coverage_threshold; bool _got_coverage_threshold;
@ -82,7 +83,8 @@ private:
KW_nearest, KW_nearest,
KW_linear, KW_linear,
KW_mipmap, KW_mipmap,
KW_cont KW_cont,
KW_anisotropic
}; };
typedef pvector<Keyword> Keywords; typedef pvector<Keyword> Keywords;