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 "palettizer.h"
#include <stdio.h>
#include "pnmFileType.h"
#include "datagram.h"
#include "datagramIterator.h"
@ -40,6 +40,7 @@ TextureProperties() {
_force_format = false;
_minfilter = EggTexture::FT_unspecified;
_magfilter = EggTexture::FT_unspecified;
_anisotropic_degree = 0;
_color_type = (PNMFileType *)NULL;
_alpha_type = (PNMFileType *)NULL;
}
@ -57,6 +58,7 @@ TextureProperties(const TextureProperties &copy) :
_force_format(copy._force_format),
_minfilter(copy._minfilter),
_magfilter(copy._magfilter),
_anisotropic_degree(copy._anisotropic_degree),
_color_type(copy._color_type),
_alpha_type(copy._alpha_type)
{
@ -75,6 +77,7 @@ operator = (const TextureProperties &copy) {
_force_format = copy._force_format;
_minfilter = copy._minfilter;
_magfilter = copy._magfilter;
_anisotropic_degree = copy._anisotropic_degree;
_color_type = copy._color_type;
_alpha_type = copy._alpha_type;
}
@ -153,9 +156,11 @@ get_string() const {
num << _num_channels;
result += num.str();
}
result += get_format_string(_format);
result += get_filter_string(_minfilter);
result += get_filter_string(_magfilter);
result += get_anisotropic_degree_string(_anisotropic_degree);
result += get_type_string(_color_type, _alpha_type);
return result;
}
@ -182,6 +187,7 @@ update_properties(const TextureProperties &other) {
_minfilter = union_filter(_minfilter, other._minfilter);
_magfilter = union_filter(_magfilter, other._magfilter);
_anisotropic_degree = max(_anisotropic_degree, other._anisotropic_degree);
if (_color_type == (PNMFileType *)NULL) {
_color_type = other._color_type;
@ -339,6 +345,7 @@ update_egg_tex(EggTexture *egg_tex) const {
egg_tex->set_format(_format);
egg_tex->set_minfilter(_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 {
return (_format == other._format &&
_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) {
return (int)_magfilter < (int)other._magfilter;
}
if (_anisotropic_degree != other._anisotropic_degree) {
return _anisotropic_degree < other._anisotropic_degree;
}
if (_color_type != other._color_type) {
return _color_type < other._color_type;
}
@ -393,6 +404,7 @@ operator == (const TextureProperties &other) const {
return (_format == other._format &&
_minfilter == other._minfilter &&
_magfilter == other._magfilter &&
_anisotropic_degree == other._anisotropic_degree &&
_color_type == other._color_type &&
(_color_type == (PNMFileType *)NULL ||
_alpha_type == other._alpha_type));
@ -512,6 +524,21 @@ get_filter_string(EggTexture::FilterType filter_type) {
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
// Access: Private, Static
@ -612,6 +639,7 @@ write_datagram(BamWriter *writer, Datagram &datagram) {
datagram.add_bool(_force_format);
datagram.add_int32((int)_minfilter);
datagram.add_int32((int)_magfilter);
datagram.add_int32(_anisotropic_degree);
writer->write_pointer(datagram, _color_type);
writer->write_pointer(datagram, _alpha_type);
}
@ -681,6 +709,7 @@ fillin(DatagramIterator &scan, BamReader *manager) {
}
_minfilter = (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); // _alpha_type
}

View File

@ -61,17 +61,20 @@ public:
EggTexture::Format _format;
bool _force_format;
EggTexture::FilterType _minfilter, _magfilter;
int _anisotropic_degree;
PNMFileType *_color_type;
PNMFileType *_alpha_type;
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_type_string(PNMFileType *color_type,
PNMFileType *alpha_type);
static EggTexture::Format union_format(EggTexture::Format a,
EggTexture::Format b);
static EggTexture::FilterType union_filter(EggTexture::FilterType a,
EggTexture::FilterType b);
// 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._minfilter = _egg_tex->get_minfilter();
_properties._magfilter = _egg_tex->get_magfilter();
_properties._anisotropic_degree = _egg_tex->get_anisotropic_degree();
string name = filename.get_basename();
TextureImage *texture = pal->get_texture(name);
@ -413,6 +414,10 @@ write(ostream &out, int indent_level) const {
break;
}
if(_properties._anisotropic_degree>1) {
out << " aniso " << _properties._anisotropic_degree;
}
out << "\n";
}

View File

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

View File

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

View File

@ -38,6 +38,7 @@ TxaLine() {
_scale = 0.0;
_x_size = 0;
_y_size = 0;
_aniso_degree = 0;
_num_channels = 0;
_format = EggTexture::F_unspecified;
_force_format = false;
@ -189,6 +190,26 @@ parse(const string &line) {
}
_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") {
++wi;
if (wi == words.end()) {
@ -295,6 +316,7 @@ match_egg(EggFile *egg_file) const {
case KW_nearest:
case KW_linear:
case KW_mipmap:
case KW_anisotropic:
// These mean nothing to an egg file.
break;
@ -421,6 +443,10 @@ match_texture(TextureImage *texture) const {
request._magfilter = EggTexture::FT_linear_mipmap_linear;
break;
case KW_anisotropic:
request._anisotropic_degree = _aniso_degree;
break;
case KW_cont:
got_cont = true;
break;

View File

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