From cd8659ea2b6b005e257227238066f5e0fa5215c5 Mon Sep 17 00:00:00 2001 From: David Rose Date: Tue, 5 Sep 2006 19:42:07 +0000 Subject: [PATCH] add :powertwo option --- pandatool/src/egg-palettize/eggPalettize.cxx | 6 ++++ pandatool/src/palettizer/txaFile.cxx | 34 ++++++++++++++++++++ pandatool/src/palettizer/txaFile.h | 1 + 3 files changed, 41 insertions(+) diff --git a/pandatool/src/egg-palettize/eggPalettize.cxx b/pandatool/src/egg-palettize/eggPalettize.cxx index cff4231619..6d5c4d17d9 100644 --- a/pandatool/src/egg-palettize/eggPalettize.cxx +++ b/pandatool/src/egg-palettize/eggPalettize.cxx @@ -430,6 +430,12 @@ describe_input_file() { "also be overridden for a particular texture using the 'coverage' " "keyword on the texture line.\n\n"); + show_text(" :powertwo flag", 10, + "Specifies whether textures should be forced to a power of two " + "size when they are not placed within a palette. Use 1 for true, " + "to force textures to a power of two; or 0 to leave them exactly " + "the size they are specified. The default is true.\n\n"); + show_text(" :round fraction fuzz", 10, "When the coverage area is computed, it may optionally be " "rounded up to the next sizeable unit before placing the " diff --git a/pandatool/src/palettizer/txaFile.cxx b/pandatool/src/palettizer/txaFile.cxx index 5533e3b4ba..50f74b04eb 100644 --- a/pandatool/src/palettizer/txaFile.cxx +++ b/pandatool/src/palettizer/txaFile.cxx @@ -77,6 +77,9 @@ read(istream &in, const string &filename) { } else if (words[0] == ":coverage") { okflag = parse_coverage_line(words); + } else if (words[0] == ":powertwo") { + okflag = parse_powertwo_line(words); + } else if (words[0] == ":imagetype") { okflag = parse_imagetype_line(words); @@ -400,6 +403,37 @@ parse_coverage_line(const vector_string &words) { return true; } +//////////////////////////////////////////////////////////////////// +// Function: TxaFile::parse_powertwo_line +// Access: Private +// Description: Handles the line in a .txa file that begins with the +// keyword ":powertwo" and indicates whether textures +// should by default be forced to a power of two. +//////////////////////////////////////////////////////////////////// +bool TxaFile:: +parse_powertwo_line(const vector_string &words) { + if (words.size() != 2) { + nout << "Exactly one parameter required for :powertwo, either a 0 " + << "or a 1.\n"; + return false; + } + + int flag; + if (!string_to_int(words[1], flag)) { + nout << "Invalid powertwo flag: " << words[1] << "\n"; + return false; + } + + if (flag != 0 && flag != 1) { + nout << "Invalid powertwo flag: " << flag << "\n"; + return false; + } + + pal->_force_power_2 = (flag != 0); + + return true; +} + //////////////////////////////////////////////////////////////////// // Function: TxaFile::parse_imagetype_line // Access: Private diff --git a/pandatool/src/palettizer/txaFile.h b/pandatool/src/palettizer/txaFile.h index 9bad135f87..9c5b9d4e29 100644 --- a/pandatool/src/palettizer/txaFile.h +++ b/pandatool/src/palettizer/txaFile.h @@ -53,6 +53,7 @@ private: bool parse_margin_line(const vector_string &words); bool parse_background_line(const vector_string &words); bool parse_coverage_line(const vector_string &words); + bool parse_powertwo_line(const vector_string &words); bool parse_imagetype_line(const vector_string &words); bool parse_shadowtype_line(const vector_string &words); bool parse_round_line(const vector_string &words);