38 _format = EggTexture::F_unspecified;
39 _force_format =
false;
40 _generic_format =
false;
42 _alpha_mode = EggRenderMode::AM_unspecified;
43 _wrap_u = EggTexture::WM_unspecified;
44 _wrap_v = EggTexture::WM_unspecified;
45 _quality_level = EggTexture::QL_unspecified;
48 _got_coverage_threshold =
false;
49 _coverage_threshold = 0.0;
50 _color_type =
nullptr;
51 _alpha_type =
nullptr;
60 size_t colon = line.find(
':');
61 if (colon == string::npos) {
62 nout <<
"Colon required.\n";
71 vector_string::iterator wi;
72 for (wi = words.begin(); wi != words.end(); ++wi) {
79 if (word.length() > 4 && word.substr(word.length() - 4) ==
".egg") {
82 _egg_patterns.push_back(pattern);
87 size_t dot = word.rfind(
'.');
88 if (dot != string::npos) {
89 word = word.substr(0, dot);
93 _texture_patterns.push_back(pattern);
97 if (_egg_patterns.empty() && _texture_patterns.empty()) {
98 nout <<
"No texture or egg filenames given.\n";
108 while (wi != words.end()) {
109 const string &word = *wi;
110 nassertr(!word.empty(),
false);
112 if (isdigit(word[0])) {
114 if (_size_type != ST_none) {
115 nout <<
"Invalid repeated size request: " << word <<
"\n";
118 if (word[word.length() - 1] ==
'%') {
120 _size_type = ST_scale;
124 if (!(tail ==
"%")) {
133 while (wi != words.end() && isdigit((*wi)[0])) {
134 const string &word = *wi;
137 nout <<
"Invalid size: " << word <<
"\n";
140 numbers.push_back(num);
143 if (numbers.size() < 2) {
144 nout <<
"At least two size numbers must be given, or a percent sign used to indicate scaling.\n";
147 }
else if (numbers.size() == 2) {
148 _size_type = ST_explicit_2;
149 _x_size = numbers[0];
150 _y_size = numbers[1];
152 }
else if (numbers.size() == 3) {
153 _size_type = ST_explicit_3;
154 _x_size = numbers[0];
155 _y_size = numbers[1];
156 _num_channels = numbers[2];
159 nout <<
"Too many size numbers given.\n";
167 if (word ==
"omit") {
168 _keywords.push_back(KW_omit);
170 }
else if (word ==
"nearest") {
171 _keywords.push_back(KW_nearest);
173 }
else if (word ==
"linear") {
174 _keywords.push_back(KW_linear);
176 }
else if (word ==
"mipmap") {
177 _keywords.push_back(KW_mipmap);
179 }
else if (word ==
"cont") {
180 _keywords.push_back(KW_cont);
182 }
else if (word ==
"margin") {
184 if (wi == words.end()) {
185 nout <<
"Argument required for 'margin'.\n";
189 const string &arg = (*wi);
191 nout <<
"Not an integer: " << arg <<
"\n";
195 nout <<
"Invalid margin: " << _margin <<
"\n";
200 }
else if (word ==
"aniso") {
202 if (wi == words.end()) {
203 nout <<
"Integer argument required for 'aniso'.\n";
207 const string &arg = (*wi);
209 nout <<
"Not an integer: " << arg <<
"\n";
212 if ((_aniso_degree < 2) || (_aniso_degree > 16)) {
215 nout <<
"Invalid anistropic degree (range is 2-16): " << _aniso_degree <<
"\n";
219 _keywords.push_back(KW_anisotropic);
221 }
else if (word ==
"coverage") {
223 if (wi == words.end()) {
224 nout <<
"Argument required for 'coverage'.\n";
228 const string &arg = (*wi);
230 nout <<
"Not a number: " << arg <<
"\n";
233 if (_coverage_threshold <= 0.0) {
234 nout <<
"Invalid coverage threshold: " << _coverage_threshold <<
"\n";
237 _got_coverage_threshold =
true;
239 }
else if (word.substr(0, 6) ==
"force-") {
242 string format_name = word.substr(6);
244 if (format != EggTexture::F_unspecified) {
246 _force_format =
true;
248 nout <<
"Unknown image format: " << format_name <<
"\n";
252 }
else if (word ==
"generic") {
255 _generic_format =
true;
257 }
else if (word ==
"keep-format") {
264 if (group !=
nullptr) {
265 _palette_groups.
insert(group);
271 if (format != EggTexture::F_unspecified) {
272 if (!_force_format) {
278 if (am != EggRenderMode::AM_unspecified) {
284 if (ql != EggTexture::QL_unspecified) {
287 }
else if (word.length() > 2 && word[word.length() - 2] ==
'_' &&
288 strchr(
"uv", word[word.length() - 1]) !=
nullptr) {
290 string prefix = word.substr(0, word.length() - 2);
292 if (wm == EggTexture::WM_unspecified) {
295 switch (word[word.length() - 1]) {
307 if (!parse_image_type_request(word, _color_type, _alpha_type)) {
331 string name = egg_file->get_name();
333 bool matched_any =
false;
334 Patterns::const_iterator pi;
335 for (pi = _egg_patterns.begin();
336 pi != _egg_patterns.end() && !matched_any;
338 matched_any = (*pi).matches(name);
346 bool got_cont =
false;
347 Keywords::const_iterator ki;
348 for (ki = _keywords.begin(); ki != _keywords.end(); ++ki) {
389 string name = texture->get_name();
391 bool matched_any =
false;
392 Patterns::const_iterator pi;
393 for (pi = _texture_patterns.begin();
394 pi != _texture_patterns.end() && !matched_any;
396 matched_any = (*pi).matches(name);
407 if (!request._got_size) {
408 switch (_size_type) {
413 if (source !=
nullptr && source->
get_size()) {
414 request._got_size =
true;
415 request._x_size = std::max(1, (
int)(source->
get_x_size() * _scale / 100.0));
416 request._y_size = std::max(1, (
int)(source->
get_y_size() * _scale / 100.0));
421 request._got_num_channels =
true;
422 request._num_channels = _num_channels;
426 request._got_size =
true;
427 request._x_size = _x_size;
428 request._y_size = _y_size;
434 request._margin = _margin;
437 if (_got_coverage_threshold) {
438 request._coverage_threshold = _coverage_threshold;
441 if (_color_type !=
nullptr) {
442 request._properties._color_type = _color_type;
443 request._properties._alpha_type = _alpha_type;
446 if (_quality_level != EggTexture::QL_unspecified) {
447 request._properties._quality_level = _quality_level;
450 if (_format != EggTexture::F_unspecified) {
451 request._format = _format;
452 request._force_format = _force_format;
453 request._generic_format =
false;
456 if (_generic_format) {
457 request._generic_format =
true;
461 request._keep_format =
true;
464 if (_alpha_mode != EggRenderMode::AM_unspecified) {
465 request._alpha_mode = _alpha_mode;
468 if (_wrap_u != EggTexture::WM_unspecified) {
469 request._wrap_u = _wrap_u;
471 if (_wrap_v != EggTexture::WM_unspecified) {
472 request._wrap_v = _wrap_v;
475 bool got_cont =
false;
476 Keywords::const_iterator ki;
477 for (ki = _keywords.begin(); ki != _keywords.end(); ++ki) {
480 request._omit =
true;
484 request._minfilter = EggTexture::FT_nearest;
485 request._magfilter = EggTexture::FT_nearest;
489 request._minfilter = EggTexture::FT_linear;
490 request._magfilter = EggTexture::FT_linear;
494 request._minfilter = EggTexture::FT_linear_mipmap_linear;
495 request._magfilter = EggTexture::FT_linear_mipmap_linear;
499 request._anisotropic_degree = _aniso_degree;
508 texture->_explicitly_assigned_groups.
make_union 509 (texture->_explicitly_assigned_groups, _palette_groups);
510 texture->_explicitly_assigned_groups.
remove_null();
519 texture->_is_surprise =
false;
528 output(std::ostream &out)
const {
529 Patterns::const_iterator pi;
530 for (pi = _texture_patterns.begin(); pi != _texture_patterns.end(); ++pi) {
533 for (pi = _egg_patterns.begin(); pi != _egg_patterns.end(); ++pi) {
538 switch (_size_type) {
543 out <<
" " << _scale <<
"%";
547 out <<
" " << _x_size <<
" " << _y_size;
551 out <<
" " << _x_size <<
" " << _y_size <<
" " << _num_channels;
556 out <<
" margin " << _margin;
559 if (_got_coverage_threshold) {
560 out <<
" coverage " << _coverage_threshold;
563 Keywords::const_iterator ki;
564 for (ki = _keywords.begin(); ki != _keywords.end(); ++ki) {
587 out <<
" aniso " << _aniso_degree;
592 PaletteGroups::const_iterator gi;
593 for (gi = _palette_groups.
begin(); gi != _palette_groups.
end(); ++gi) {
594 out <<
" " << (*gi)->get_name();
597 if (_format != EggTexture::F_unspecified) {
598 out <<
" " << _format;
604 if (_color_type !=
nullptr) {
606 if (_alpha_type !=
nullptr) {
int string_to_int(const string &str, string &tail)
A string-interface wrapper around the C library strtol().
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
iterator end() const
Returns an iterator suitable for traversing the set.
double string_to_double(const string &str, string &tail)
A string-interface wrapper around the C library strtol().
PaletteGroup * test_palette_group(const std::string &name) const
Returns the PaletteGroup with the given name.
void remove_null()
Removes the special "null" group from the set.
set_case_sensitive
Sets whether the match is case sensitive (true) or case insensitive (false).
static AlphaMode string_alpha_mode(const std::string &string)
Returns the AlphaMode value associated with the given string representation, or AM_unspecified if the...
get_suggested_extension
Returns a suitable filename extension (without a leading dot) to suggest for files of this type,...
int get_y_size() const
Returns the size of the image file in pixels in the Y direction.
void clear_surprise()
Removes the 'surprise' flag; this file has been successfully matched against a line in the ....
iterator begin() const
Returns an iterator suitable for traversing the set.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This is the highest level of grouping for TextureImages.
static QualityLevel string_quality_level(const std::string &string)
Returns the TexGen value associated with the given string representation, or ET_unspecified if the st...
static WrapMode string_wrap_mode(const std::string &string)
Returns the WrapMode value associated with the given string representation, or WM_unspecified if the ...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
SourceTextureImage * get_preferred_source()
Determines the preferred source image for examining size and reading pixels, etc.
void match_txa_groups(const PaletteGroups &groups)
Adds the indicated set of groups, read from the .txa file, to the set of groups to which the egg file...
int extract_words(const string &str, vector_string &words)
Divides the string into a number of words according to whitespace.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
int get_x_size() const
Returns the size of the image file in pixels in the X direction.
static Format string_format(const std::string &string)
Returns the Format value associated with the given string representation, or F_unspecified if the str...
bool match_texture(TextureImage *texture) const
Compares the patterns on the line to the indicated TextureImage.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
bool get_size()
Determines the size of the SourceTextureImage, if it is not already known.
This is a texture image reference as it appears in an egg file: the source image of the texture.
bool parse(const std::string &line)
Accepts a string that defines a line of the .txa file and parses it into its constinuent parts.
bool match_egg(EggFile *egg_file) const
Compares the patterns on the line to the indicated EggFile.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
void make_union(const PaletteGroups &a, const PaletteGroups &b)
Computes the union of PaletteGroups a and b, and stores the result in this object.
void insert(PaletteGroup *group)
Inserts a new group to the set, if it is not already there.
This represents a single source texture that is referenced by one or more egg files.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
These are the things that a user might explicitly request to adjust on a texture via a line in the ....
This represents a single egg file known to the palettizer.
This class can be used to test for string matches against standard Unix- shell filename globbing conv...