diff --git a/panda/src/display/graphicsEngine.cxx b/panda/src/display/graphicsEngine.cxx index 1ef87c2e35..bc102e0c6c 100644 --- a/panda/src/display/graphicsEngine.cxx +++ b/panda/src/display/graphicsEngine.cxx @@ -2130,7 +2130,7 @@ auto_adjust_capabilities(GraphicsStateGuardian *gsg) { textures_power_2 = ATS_down; // Not a fix. Just suppresses further error messages. } - if (textures_auto_power_2 && !Texture::have_textures_power_2()) { + if (textures_auto_power_2 && !Texture::has_textures_power_2()) { if (gsg->get_supports_tex_non_pow2()) { Texture::set_textures_power_2(ATS_none); } else { diff --git a/panda/src/gobj/config_gobj.cxx b/panda/src/gobj/config_gobj.cxx index 5082353427..682f9d385f 100644 --- a/panda/src/gobj/config_gobj.cxx +++ b/panda/src/gobj/config_gobj.cxx @@ -550,59 +550,6 @@ ConfigureFn(config_gobj) { UserVertexTransform::register_with_read_factory(); } -ostream & -operator << (ostream &out, AutoTextureScale ats) { - switch (ats) { - case ATS_none: - return out << "none"; - - case ATS_down: - return out << "down"; - - case ATS_up: - return out << "up"; - - case ATS_pad: - return out << "pad"; - - case ATS_UNSPECIFIED: - return out << "UNSPECIFIED"; - } - - return out << "**invalid AutoTextureScale (" << (int)ats << ")**"; -} - -istream & -operator >> (istream &in, AutoTextureScale &ats) { - string word; - in >> word; - - if (cmp_nocase(word, "none") == 0 || - cmp_nocase(word, "0") == 0 || - cmp_nocase(word, "#f") == 0 || - (!word.empty() && tolower(word[0]) == 'f')) { - ats = ATS_none; - - } else if (cmp_nocase(word, "down") == 0 || - cmp_nocase(word, "1") == 0 || - cmp_nocase(word, "#t") == 0 || - (!word.empty() && tolower(word[0]) == 't')) { - ats = ATS_down; - - } else if (cmp_nocase(word, "up") == 0) { - ats = ATS_up; - - } else if (cmp_nocase(word, "pad") == 0) { - ats = ATS_pad; - - } else { - gobj_cat->error() << "Invalid AutoTextureScale value: " << word << "\n"; - ats = ATS_none; - } - - return in; -} - ostream & operator << (ostream &out, ShaderUtilization sgc) { switch (sgc) { @@ -615,8 +562,8 @@ operator << (ostream &out, ShaderUtilization sgc) { case SUT_advanced: return out << "advanced"; - case SUT_UNSPECIFIED: - return out << "UNSPECIFIED"; + case SUT_unspecified: + return out << "unspecified"; } return out << "**invalid ShaderUtilization (" << (int)sgc << ")**"; diff --git a/panda/src/gobj/config_gobj.h b/panda/src/gobj/config_gobj.h index 2014fa8444..674c46865e 100644 --- a/panda/src/gobj/config_gobj.h +++ b/panda/src/gobj/config_gobj.h @@ -23,27 +23,19 @@ #include "configVariableDouble.h" #include "configVariableFilename.h" #include "configVariableString.h" +#include "autoTextureScale.h" NotifyCategoryDecl(gobj, EXPCL_PANDA_GOBJ, EXPTP_PANDA_GOBJ); BEGIN_PUBLISH -enum AutoTextureScale { - ATS_none, - ATS_down, - ATS_up, - ATS_pad, - ATS_UNSPECIFIED, -}; enum ShaderUtilization { SUT_none, SUT_basic, SUT_advanced, - SUT_UNSPECIFIED, + SUT_unspecified, }; END_PUBLISH -EXPCL_PANDA_GOBJ ostream &operator << (ostream &out, AutoTextureScale ats); -EXPCL_PANDA_GOBJ istream &operator >> (istream &in, AutoTextureScale &ats); EXPCL_PANDA_GOBJ ostream &operator << (ostream &out, ShaderUtilization sut); EXPCL_PANDA_GOBJ istream &operator >> (istream &in, ShaderUtilization &sut); diff --git a/panda/src/gobj/shader.I b/panda/src/gobj/shader.I index dfd9297a96..3672072b9e 100755 --- a/panda/src/gobj/shader.I +++ b/panda/src/gobj/shader.I @@ -102,7 +102,7 @@ set_shader_utilization(ShaderUtilization sut) { //////////////////////////////////////////////////////////////////// INLINE ShaderUtilization Shader:: get_shader_utilization() { - if (_shader_utilization == SUT_UNSPECIFIED) { + if (_shader_utilization == SUT_unspecified) { return shader_utilization; } else { return _shader_utilization; @@ -119,7 +119,7 @@ get_shader_utilization() { //////////////////////////////////////////////////////////////////// INLINE bool Shader:: have_shader_utilization() { - return (_shader_utilization != SUT_UNSPECIFIED); + return (_shader_utilization != SUT_unspecified); } //////////////////////////////////////////////////////////////////// diff --git a/panda/src/gobj/shader.cxx b/panda/src/gobj/shader.cxx index de3d45a78f..a5303f32c6 100755 --- a/panda/src/gobj/shader.cxx +++ b/panda/src/gobj/shader.cxx @@ -29,7 +29,7 @@ Shader::ShaderTable Shader::_load_table; Shader::ShaderTable Shader::_make_table; Shader::ShaderCaps Shader::_default_caps; int Shader::_shaders_generated; -ShaderUtilization Shader::_shader_utilization = SUT_UNSPECIFIED; +ShaderUtilization Shader::_shader_utilization = SUT_unspecified; //////////////////////////////////////////////////////////////////// // Function: Shader::cp_report_error diff --git a/panda/src/gobj/texture.I b/panda/src/gobj/texture.I index 188492663e..36e2b2e2dc 100644 --- a/panda/src/gobj/texture.I +++ b/panda/src/gobj/texture.I @@ -1879,6 +1879,90 @@ get_simple_image_modified() const { return cdata->_simple_image_modified; } +//////////////////////////////////////////////////////////////////// +// Function: Texture::set_auto_texture_scale +// Access: Published +// Description: Specifies the power-of-2 texture-scaling mode that +// will be applied to this particular texture when it is +// next loaded from disk. See set_textures_power_2(). +//////////////////////////////////////////////////////////////////// +INLINE void Texture:: +set_auto_texture_scale(AutoTextureScale scale) { + CDWriter cdata(_cycler, true); + cdata->_auto_texture_scale = scale; +} + +//////////////////////////////////////////////////////////////////// +// Function: Texture::get_auto_texture_scale +// Access: Published +// Description: Returns the power-of-2 texture-scaling mode that will +// be applied to this particular texture when it is next +// loaded from disk. See set_textures_power_2(). +//////////////////////////////////////////////////////////////////// +INLINE AutoTextureScale Texture:: +get_auto_texture_scale() const { + CDReader cdata(_cycler); + return do_get_auto_texture_scale(cdata); +} + +//////////////////////////////////////////////////////////////////// +// Function: Texture::has_auto_texture_scale +// Access: Published +// Description: Returns true if set_auto_texture_scale() has been set +// to something other than ATS_unspecified for this +// particular texture. +//////////////////////////////////////////////////////////////////// +INLINE bool Texture:: +has_auto_texture_scale() const { + CDReader cdata(_cycler); + return (cdata->_auto_texture_scale != ATS_unspecified); +} + +//////////////////////////////////////////////////////////////////// +// Function: Texture::set_textures_power_2 +// Access: Published, Static +// Description: Set this flag to ATS_none, ATS_up, ATS_down, or +// ATS_pad to control the scaling of textures in +// general, if a particular texture does not override +// this. See also set_auto_texture_scale() for the +// per-texture override. +//////////////////////////////////////////////////////////////////// +INLINE void Texture:: +set_textures_power_2(AutoTextureScale scale) { + _textures_power_2 = scale; +} + +//////////////////////////////////////////////////////////////////// +// Function: Texture::get_textures_power_2 +// Access: Published, Static +// Description: This flag returns ATS_none, ATS_up, or ATS_down +// and controls the scaling of textures in general. It +// is initialized from the config variable of the same +// name, but it can be subsequently adjusted. See also +// get_auto_texture_scale(). +//////////////////////////////////////////////////////////////////// +INLINE AutoTextureScale Texture:: +get_textures_power_2() { + if (_textures_power_2 == ATS_unspecified) { + return textures_power_2; + } else { + return _textures_power_2; + } +} + +//////////////////////////////////////////////////////////////////// +// Function: Texture::has_textures_power_2 +// Access: Published, Static +// Description: If true, then get_textures_power_2 has been +// set using set_textures_power_2. +// If false, then get_textures_power_2 simply +// returns the config variable of the same name. +//////////////////////////////////////////////////////////////////// +INLINE bool Texture:: +has_textures_power_2() { + return (_textures_power_2 != ATS_unspecified); +} + //////////////////////////////////////////////////////////////////// // Function: Texture::set_filename // Access: Published @@ -2341,6 +2425,20 @@ do_clear_ram_image(CData *cdata) { cdata->_ram_images.clear(); } +//////////////////////////////////////////////////////////////////// +// Function: Texture::do_get_auto_texture_scale +// Access: Protected +// Description: +//////////////////////////////////////////////////////////////////// +INLINE AutoTextureScale Texture:: +do_get_auto_texture_scale(const CData *cdata) const { + if (cdata->_auto_texture_scale == ATS_unspecified) { + return get_textures_power_2(); + } else { + return cdata->_auto_texture_scale; + } +} + //////////////////////////////////////////////////////////////////// // Function: Texture::store_unscaled_byte // Access: Private, Static @@ -2469,47 +2567,6 @@ is_dds_filename(const Filename &fullpath) { return (downcase(extension) == "dds"); } -//////////////////////////////////////////////////////////////////// -// Function: Texture::set_textures_power_2 -// Access: Published, Static -// Description: Set this flag to ATS_none, ATS_up, or ATS_down -// to control the scaling of textures. -//////////////////////////////////////////////////////////////////// -INLINE void Texture:: -set_textures_power_2(AutoTextureScale scale) { - _textures_power_2 = scale; -} - -//////////////////////////////////////////////////////////////////// -// Function: Texture::get_textures_power_2 -// Access: Published, Static -// Description: This flag returns ATS_none, ATS_up, or ATS_down -// and controls the scaling of textures. It is -// initialized from the config variable of the same -// name, but it can be subsequently adjusted. -//////////////////////////////////////////////////////////////////// -INLINE AutoTextureScale Texture:: -get_textures_power_2() { - if (_textures_power_2 == ATS_UNSPECIFIED) { - return textures_power_2; - } else { - return _textures_power_2; - } -} - -//////////////////////////////////////////////////////////////////// -// Function: Texture::have_textures_power_2 -// Access: Published, Static -// Description: If true, then get_textures_power_2 has been -// set using set_textures_power_2. -// If false, then get_textures_power_2 simply -// returns the config variable of the same name. -//////////////////////////////////////////////////////////////////// -INLINE bool Texture:: -have_textures_power_2() { - return (_textures_power_2 != ATS_UNSPECIFIED); -} - //////////////////////////////////////////////////////////////////// // Function: Texture::RamImage::Constructor // Access: Public diff --git a/panda/src/gobj/texture.cxx b/panda/src/gobj/texture.cxx index 1665db15d4..9e10684d3f 100644 --- a/panda/src/gobj/texture.cxx +++ b/panda/src/gobj/texture.cxx @@ -89,7 +89,7 @@ ConfigVariableInt texture_anisotropic_degree PStatCollector Texture::_texture_read_pcollector("*:Texture:Read"); TypeHandle Texture::_type_handle; TypeHandle Texture::CData::_type_handle; -AutoTextureScale Texture::_textures_power_2 = ATS_UNSPECIFIED; +AutoTextureScale Texture::_textures_power_2 = ATS_unspecified; // Stuff to read and write DDS files. @@ -1751,7 +1751,7 @@ write(ostream &out, int indent_level) const { void Texture:: set_size_padded(int x, int y, int z) { CDWriter cdata(_cycler, true); - if (get_textures_power_2() != ATS_none) { + if (do_get_auto_texture_scale(cdata) != ATS_none) { do_set_x_size(cdata, up_to_power_2(x)); do_set_y_size(cdata, up_to_power_2(y)); do_set_z_size(cdata, up_to_power_2(z)); @@ -1884,7 +1884,7 @@ down_to_power_2(int value) { //////////////////////////////////////////////////////////////////// void Texture:: consider_rescale(PNMImage &pnmimage) { - consider_rescale(pnmimage, get_name()); + consider_rescale(pnmimage, get_name(), get_auto_texture_scale()); } //////////////////////////////////////////////////////////////////// @@ -1899,10 +1899,10 @@ consider_rescale(PNMImage &pnmimage) { // pnmimage.read(). Also see rescale_texture(). //////////////////////////////////////////////////////////////////// void Texture:: -consider_rescale(PNMImage &pnmimage, const string &name) { +consider_rescale(PNMImage &pnmimage, const string &name, AutoTextureScale auto_texture_scale) { int new_x_size = pnmimage.get_x_size(); int new_y_size = pnmimage.get_y_size(); - if (adjust_size(new_x_size, new_y_size, name, false)) { + if (adjust_size(new_x_size, new_y_size, name, false, auto_texture_scale)) { pnmimage.set_read_size(new_x_size, new_y_size); } } @@ -2523,7 +2523,7 @@ has_binary_alpha(Format format) { //////////////////////////////////////////////////////////////////// bool Texture:: adjust_size(int &x_size, int &y_size, const string &name, - bool for_padding) { + bool for_padding, AutoTextureScale auto_texture_scale) { bool exclude = false; int num_excludes = exclude_texture_scale.get_num_unique_values(); for (int i = 0; i < num_excludes && !exclude; ++i) { @@ -2546,7 +2546,10 @@ adjust_size(int &x_size, int &y_size, const string &name, new_y_size = min(max(new_y_size, (int)texture_scale_limit), y_size); } - AutoTextureScale ats = get_textures_power_2(); + AutoTextureScale ats = auto_texture_scale; + if (ats == ATS_unspecified) { + ats = textures_power_2; + } if (!for_padding && ats == ATS_pad) { // If we're not calculating the padding size--that is, we're // calculating the initial scaling size instead--then ignore @@ -2567,7 +2570,7 @@ adjust_size(int &x_size, int &y_size, const string &name, break; case ATS_none: - case ATS_UNSPECIFIED: + case ATS_unspecified: break; } @@ -2586,7 +2589,7 @@ adjust_size(int &x_size, int &y_size, const string &name, break; case ATS_none: - case ATS_UNSPECIFIED: + case ATS_unspecified: break; } @@ -2635,7 +2638,7 @@ reconsider_dirty() { bool Texture:: do_adjust_this_size(const CData *cdata, int &x_size, int &y_size, const string &name, bool for_padding) const { - return adjust_size(x_size, y_size, name, for_padding); + return adjust_size(x_size, y_size, name, for_padding, cdata->_auto_texture_scale); } //////////////////////////////////////////////////////////////////// @@ -2651,6 +2654,10 @@ do_read(CData *cdata, const Filename &fullpath, const Filename &alpha_fullpath, const LoaderOptions &options, BamCacheRecord *record) { PStatTimer timer(_texture_read_pcollector); + if (options.get_auto_texture_scale() != ATS_unspecified) { + cdata->_auto_texture_scale = options.get_auto_texture_scale(); + } + bool header_only = ((options.get_texture_flags() & (LoaderOptions::TF_preload | LoaderOptions::TF_preload_simple)) == 0); if (record != (BamCacheRecord *)NULL) { header_only = false; @@ -2910,7 +2917,7 @@ do_read_one(CData *cdata, const Filename &fullpath, const Filename &alpha_fullpa y_size = 1; } else { - consider_rescale(image, fullpath.get_basename()); + consider_rescale(image, fullpath.get_basename(), do_get_auto_texture_scale(cdata)); x_size = image.get_read_x_size(); y_size = image.get_read_y_size(); } @@ -2932,7 +2939,7 @@ do_read_one(CData *cdata, const Filename &fullpath, const Filename &alpha_fullpa if (z == 0 && n == 0) { cdata->_orig_file_x_size = image.get_x_size(); cdata->_orig_file_y_size = image.get_y_size(); - consider_rescale(image, fullpath.get_basename()); + consider_rescale(image, fullpath.get_basename(), do_get_auto_texture_scale(cdata)); } else { image.set_read_size(do_get_expected_mipmap_x_size(cdata, n), do_get_expected_mipmap_y_size(cdata, n)); @@ -3087,7 +3094,7 @@ do_read_one(CData *cdata, const Filename &fullpath, const Filename &alpha_fullpa // image. int pad_x_size = 0; int pad_y_size = 0; - if (get_textures_power_2() == ATS_pad) { + if (do_get_auto_texture_scale(cdata) == ATS_pad) { int new_x_size = image.get_x_size(); int new_y_size = image.get_y_size(); if (do_adjust_this_size(cdata, new_x_size, new_y_size, fullpath.get_basename(), true)) { @@ -4582,7 +4589,7 @@ do_rescale_texture(CData *cdata) { // Maybe we should pad the image. int pad_x_size = 0; int pad_y_size = 0; - if (get_textures_power_2() == ATS_pad) { + if (do_get_auto_texture_scale(cdata) == ATS_pad) { new_x_size = cdata->_x_size; new_y_size = cdata->_y_size; if (do_adjust_this_size(cdata, new_x_size, new_y_size, get_name(), true)) { @@ -7111,6 +7118,7 @@ do_write_datagram_body(CData *cdata, BamWriter *manager, Datagram &me) { me.add_uint8(cdata->_format); me.add_uint8(cdata->_num_components); + me.add_uint8(cdata->_auto_texture_scale); me.add_uint32(cdata->_orig_file_x_size); me.add_uint32(cdata->_orig_file_y_size); @@ -7225,9 +7233,11 @@ make_this_from_bam(const FactoryParams ¶ms) { // pointer as a temporary object to read all of the attributes // from the bam stream. Texture *dummy = this; + AutoTextureScale auto_texture_scale = ATS_unspecified; { CDWriter cdata_dummy(dummy->_cycler, true); dummy->do_fillin_body(cdata_dummy, scan, manager); + auto_texture_scale = cdata_dummy->_auto_texture_scale; } if (filename.empty()) { @@ -7253,6 +7263,7 @@ make_this_from_bam(const FactoryParams ¶ms) { if (dummy->uses_mipmaps()) { options.set_texture_flags(options.get_texture_flags() | LoaderOptions::TF_generate_mipmaps); } + options.set_auto_texture_scale(auto_texture_scale); switch (texture_type) { case TT_1d_texture: @@ -7321,8 +7332,14 @@ do_fillin_body(CData *cdata, DatagramIterator &scan, BamReader *manager) { cdata->_format = (Format)scan.get_uint8(); cdata->_num_components = scan.get_uint8(); + ++(cdata->_properties_modified); + cdata->_auto_texture_scale = ATS_unspecified; + if (manager->get_file_minor_ver() >= 28) { + cdata->_auto_texture_scale = (AutoTextureScale)scan.get_uint8(); + } + bool has_simple_ram_image = false; if (manager->get_file_minor_ver() >= 18) { cdata->_orig_file_x_size = scan.get_uint32(); @@ -7481,6 +7498,7 @@ CData() { _keep_ram_image = true; _border_color.set(0.0f, 0.0f, 0.0f, 1.0f); _compression = CM_default; + _auto_texture_scale = ATS_unspecified; _ram_image_compression = CM_off; _render_to_texture = false; _match_framebuffer_format = false; @@ -7589,6 +7607,7 @@ do_assign(const Texture::CData *copy) { _compression = copy->_compression; _match_framebuffer_format = copy->_match_framebuffer_format; _quality_level = copy->_quality_level; + _auto_texture_scale = copy->_auto_texture_scale; _ram_image_compression = copy->_ram_image_compression; _ram_images = copy->_ram_images; _simple_x_size = copy->_simple_x_size; diff --git a/panda/src/gobj/texture.h b/panda/src/gobj/texture.h index 42d02a8326..5d6ef8d393 100644 --- a/panda/src/gobj/texture.h +++ b/panda/src/gobj/texture.h @@ -386,6 +386,10 @@ PUBLISHED: INLINE UpdateSeq get_image_modified() const; INLINE UpdateSeq get_simple_image_modified() const; + INLINE void set_auto_texture_scale(AutoTextureScale scale); + INLINE AutoTextureScale get_auto_texture_scale() const; + INLINE bool has_auto_texture_scale() const; + void prepare(PreparedGraphicsObjects *prepared_objects); bool is_prepared(PreparedGraphicsObjects *prepared_objects) const; bool was_image_modified(PreparedGraphicsObjects *prepared_objects) const; @@ -406,7 +410,7 @@ PUBLISHED: INLINE static void set_textures_power_2(AutoTextureScale scale); INLINE static AutoTextureScale get_textures_power_2(); - INLINE static bool have_textures_power_2(); + INLINE static bool has_textures_power_2(); PUBLISHED: // These are published, but in general, you shouldn't be mucking @@ -465,7 +469,7 @@ PUBLISHED: static int down_to_power_2(int value); void consider_rescale(PNMImage &pnmimage); - static void consider_rescale(PNMImage &pnmimage, const string &name); + static void consider_rescale(PNMImage &pnmimage, const string &name, AutoTextureScale auto_texture_scale = ATS_unspecified); INLINE bool rescale_texture(); static string format_texture_type(TextureType tt); @@ -503,7 +507,7 @@ public: static bool has_binary_alpha(Format format); static bool adjust_size(int &x_size, int &y_size, const string &name, - bool for_padding); + bool for_padding, AutoTextureScale auto_texture_scale = ATS_unspecified); INLINE bool adjust_this_size(int &x_size, int &y_size, const string &name, bool for_padding) const; @@ -630,6 +634,8 @@ protected: virtual bool do_can_reload(const CData *cdata) const; bool do_reload(CData *cdata); + INLINE AutoTextureScale do_get_auto_texture_scale(const CData *cdata) const; + virtual bool do_has_bam_rawdata(const CData *cdata) const; virtual void do_get_bam_rawdata(CData *cdata); @@ -800,6 +806,7 @@ protected: int _orig_file_x_size; int _orig_file_y_size; + AutoTextureScale _auto_texture_scale; CompressionMode _ram_image_compression; // There is usually one RamImage for the mipmap level 0 (the base diff --git a/panda/src/gobj/videoTexture.cxx b/panda/src/gobj/videoTexture.cxx index 12d9b5a41b..796661b0cb 100644 --- a/panda/src/gobj/videoTexture.cxx +++ b/panda/src/gobj/videoTexture.cxx @@ -212,6 +212,25 @@ do_can_reload(const Texture::CData *cdata) const { return true; } +//////////////////////////////////////////////////////////////////// +// Function: VideoTexture::do_adjust_this_size +// Access: Protected, Virtual +// Description: Works like adjust_size, but also considers the +// texture class. Movie textures, for instance, always +// pad outwards, never scale down. +//////////////////////////////////////////////////////////////////// +bool VideoTexture:: +do_adjust_this_size(const Texture::CData *cdata_tex, + int &x_size, int &y_size, const string &name, + bool for_padding) const { + AutoTextureScale ats = do_get_auto_texture_scale(cdata_tex); + if (ats != ATS_none) { + ats = ATS_pad; + } + + return adjust_size(x_size, y_size, name, for_padding, ats); +} + //////////////////////////////////////////////////////////////////// // Function: VideoTexture::consider_update // Access: Protected, Virtual diff --git a/panda/src/gobj/videoTexture.h b/panda/src/gobj/videoTexture.h index 09a4cfa1ed..a133d43641 100644 --- a/panda/src/gobj/videoTexture.h +++ b/panda/src/gobj/videoTexture.h @@ -53,6 +53,10 @@ protected: virtual void do_reload_ram_image(Texture::CData *cdata, bool allow_compression); virtual bool do_can_reload(const Texture::CData *cdata) const; + virtual bool do_adjust_this_size(const Texture::CData *cdata, + int &x_size, int &y_size, const string &name, + bool for_padding) const; + virtual void consider_update(); INLINE void clear_current_frame(); virtual void do_update_frame(Texture::CData *cdata_tex, int frame)=0; diff --git a/panda/src/grutil/movieTexture.cxx b/panda/src/grutil/movieTexture.cxx index 5b2f4f237c..338eb74d7d 100644 --- a/panda/src/grutil/movieTexture.cxx +++ b/panda/src/grutil/movieTexture.cxx @@ -196,17 +196,12 @@ bool MovieTexture:: do_adjust_this_size(const Texture::CData *cdata_tex, int &x_size, int &y_size, const string &name, bool for_padding) const { - if (cdata_tex->_texture_type == TT_cube_map) { - // Texture must be square. - x_size = y_size = max(x_size, y_size); + AutoTextureScale ats = do_get_auto_texture_scale(cdata_tex); + if (ats != ATS_none) { + ats = ATS_pad; } - if (Texture::get_textures_power_2() != ATS_none) { - x_size = up_to_power_2(x_size); - y_size = up_to_power_2(y_size); - } - - return true; + return adjust_size(x_size, y_size, name, for_padding, ats); } //////////////////////////////////////////////////////////////////// diff --git a/panda/src/movies/movieVideoCursor.cxx b/panda/src/movies/movieVideoCursor.cxx index f694dbe12c..2e3dfefe12 100644 --- a/panda/src/movies/movieVideoCursor.cxx +++ b/panda/src/movies/movieVideoCursor.cxx @@ -63,10 +63,7 @@ void MovieVideoCursor:: setup_texture(Texture *tex) const { int fullx = size_x(); int fully = size_y(); - if (Texture::get_textures_power_2()) { - fullx = Texture::up_to_power_2(fullx); - fully = Texture::up_to_power_2(fully); - } + tex->adjust_this_size(fullx, fully, tex->get_name(), true); Texture::Format fmt = (get_num_components() == 4) ? Texture::F_rgba : Texture::F_rgb; tex->setup_texture(Texture::TT_2d_texture, fullx, fully, 1, Texture::T_unsigned_byte, fmt); tex->set_pad_size(fullx - size_x(), fully - size_y()); diff --git a/panda/src/putil/Sources.pp b/panda/src/putil/Sources.pp index 9abcbadd70..28c6c0a0ae 100644 --- a/panda/src/putil/Sources.pp +++ b/panda/src/putil/Sources.pp @@ -10,6 +10,7 @@ #define SOURCES \ animInterface.h animInterface.I \ + autoTextureScale.h \ bam.h \ bamCache.h bamCache.I \ bamCacheIndex.h bamCacheIndex.I \ @@ -73,6 +74,7 @@ #define INCLUDED_SOURCES \ animInterface.cxx \ + autoTextureScale.cxx \ bamCache.cxx \ bamCacheIndex.cxx \ bamCacheRecord.cxx \ @@ -119,6 +121,7 @@ #define INSTALL_HEADERS \ animInterface.h animInterface.I \ + autoTextureScale.h \ bam.h \ bamCache.h bamCache.I \ bamCacheIndex.h bamCacheIndex.I \ diff --git a/panda/src/putil/autoTextureScale.cxx b/panda/src/putil/autoTextureScale.cxx new file mode 100644 index 0000000000..bd9ea61296 --- /dev/null +++ b/panda/src/putil/autoTextureScale.cxx @@ -0,0 +1,70 @@ +// Filename: autoTextureScale.cxx +// Created by: drose (28Nov11) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + +#include "autoTextureScale.h" +#include "string_utils.h" +#include "config_util.h" + +ostream & +operator << (ostream &out, AutoTextureScale ats) { + switch (ats) { + case ATS_none: + return out << "none"; + + case ATS_down: + return out << "down"; + + case ATS_up: + return out << "up"; + + case ATS_pad: + return out << "pad"; + + case ATS_unspecified: + return out << "unspecified"; + } + + return out << "**invalid AutoTextureScale (" << (int)ats << ")**"; +} + +istream & +operator >> (istream &in, AutoTextureScale &ats) { + string word; + in >> word; + + if (cmp_nocase(word, "none") == 0 || + cmp_nocase(word, "0") == 0 || + cmp_nocase(word, "#f") == 0 || + (!word.empty() && tolower(word[0]) == 'f')) { + ats = ATS_none; + + } else if (cmp_nocase(word, "down") == 0 || + cmp_nocase(word, "1") == 0 || + cmp_nocase(word, "#t") == 0 || + (!word.empty() && tolower(word[0]) == 't')) { + ats = ATS_down; + + } else if (cmp_nocase(word, "up") == 0) { + ats = ATS_up; + + } else if (cmp_nocase(word, "pad") == 0) { + ats = ATS_pad; + + } else { + util_cat->error() << "Invalid AutoTextureScale value: " << word << "\n"; + ats = ATS_none; + } + + return in; +} diff --git a/panda/src/putil/autoTextureScale.h b/panda/src/putil/autoTextureScale.h new file mode 100644 index 0000000000..317fc2629d --- /dev/null +++ b/panda/src/putil/autoTextureScale.h @@ -0,0 +1,33 @@ +// Filename: autoTextureScale.h +// Created by: drose (28Nov11) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + +#ifndef AUTOTEXTURESCALE_H +#define AUTOTEXTURESCALE_H + +#include "pandabase.h" + +BEGIN_PUBLISH +enum AutoTextureScale { + ATS_none, + ATS_down, + ATS_up, + ATS_pad, + ATS_unspecified, +}; +END_PUBLISH + +EXPCL_PANDA_PUTIL ostream &operator << (ostream &out, AutoTextureScale ats); +EXPCL_PANDA_PUTIL istream &operator >> (istream &in, AutoTextureScale &ats); + +#endif diff --git a/panda/src/putil/bam.h b/panda/src/putil/bam.h index 45a4adb511..efe5291b6a 100644 --- a/panda/src/putil/bam.h +++ b/panda/src/putil/bam.h @@ -33,7 +33,7 @@ static const unsigned short _bam_major_ver = 6; // Bumped to major version 6 on 2/11/06 to factor out PandaNode::CData. static const unsigned short _bam_first_minor_ver = 14; -static const unsigned short _bam_minor_ver = 27; +static const unsigned short _bam_minor_ver = 28; // Bumped to minor version 14 on 12/19/07 to change default ColorAttrib. // Bumped to minor version 15 on 4/9/08 to add TextureAttrib::_implicit_sort. // Bumped to minor version 16 on 5/13/08 to add Texture::_quality_level. @@ -48,6 +48,7 @@ static const unsigned short _bam_minor_ver = 27; // Bumped to minor version 25 on 6/22/11 to add support for caching movie files. // Bumped to minor version 26 on 8/5/11 to add multiview (stereo) Textures. // Bumped to minor version 27 on 10/9/11 to add stdfloat_double. +// Bumped to minor version 28 on 11/28/11 to add Texture::_auto_texture_scale. #endif diff --git a/panda/src/putil/loaderOptions.I b/panda/src/putil/loaderOptions.I index d77ef168a2..3be3f16e6d 100644 --- a/panda/src/putil/loaderOptions.I +++ b/panda/src/putil/loaderOptions.I @@ -22,7 +22,8 @@ INLINE LoaderOptions:: LoaderOptions(int flags, int texture_flags) : _flags(flags), _texture_flags(texture_flags), - _texture_num_views(0) + _texture_num_views(0), + _auto_texture_scale(ATS_unspecified) { } @@ -35,7 +36,8 @@ INLINE LoaderOptions:: LoaderOptions(const LoaderOptions ©) : _flags(copy._flags), _texture_flags(copy._texture_flags), - _texture_num_views(copy._texture_num_views) + _texture_num_views(copy._texture_num_views), + _auto_texture_scale(copy._auto_texture_scale) { } @@ -49,6 +51,7 @@ operator = (const LoaderOptions ©) { _flags = copy._flags; _texture_flags = copy._texture_flags; _texture_num_views = copy._texture_num_views; + _auto_texture_scale = copy._auto_texture_scale; } //////////////////////////////////////////////////////////////////// @@ -117,3 +120,26 @@ INLINE int LoaderOptions:: get_texture_num_views() const { return _texture_num_views; } + +//////////////////////////////////////////////////////////////////// +// Function: LoaderOptions::set_auto_texture_scale +// Access: Published +// Description: Set this flag to ATS_none, ATS_up, ATS_down, or +// ATS_pad to control how a texture is scaled from +// disk when it is subsequently loaded. Set it to +// ATS_unspecified to restore the default behavior. +//////////////////////////////////////////////////////////////////// +INLINE void LoaderOptions:: +set_auto_texture_scale(AutoTextureScale scale) { + _auto_texture_scale = scale; +} + +//////////////////////////////////////////////////////////////////// +// Function: LoaderOptions::get_auto_texture_scale +// Access: Published +// Description: See set_auto_texture_scale(). +//////////////////////////////////////////////////////////////////// +INLINE AutoTextureScale LoaderOptions:: +get_auto_texture_scale() const { + return _auto_texture_scale; +} diff --git a/panda/src/putil/loaderOptions.cxx b/panda/src/putil/loaderOptions.cxx index 7553f6ed3b..c31118f3d2 100644 --- a/panda/src/putil/loaderOptions.cxx +++ b/panda/src/putil/loaderOptions.cxx @@ -25,7 +25,8 @@ LoaderOptions:: LoaderOptions(int flags) : _flags(flags), _texture_flags(0), - _texture_num_views(0) + _texture_num_views(0), + _auto_texture_scale(ATS_unspecified) { // Shadowing the variables in config_util for static init ordering // issues. @@ -86,6 +87,10 @@ output(ostream &out) const { out << "0"; } + if (_auto_texture_scale != ATS_unspecified) { + out << ", ATS_" << _auto_texture_scale; + } + out << ")"; } diff --git a/panda/src/putil/loaderOptions.h b/panda/src/putil/loaderOptions.h index 1a3b99882e..4be344091e 100644 --- a/panda/src/putil/loaderOptions.h +++ b/panda/src/putil/loaderOptions.h @@ -16,6 +16,7 @@ #define LOADEROPTIONS_H #include "pandabase.h" +#include "autoTextureScale.h" //////////////////////////////////////////////////////////////////// // Class : LoaderOptions @@ -60,6 +61,9 @@ PUBLISHED: INLINE void set_texture_num_views(int num_views); INLINE int get_texture_num_views() const; + INLINE void set_auto_texture_scale(AutoTextureScale scale); + INLINE AutoTextureScale get_auto_texture_scale() const; + void output(ostream &out) const; private: @@ -70,6 +74,7 @@ private: int _flags; int _texture_flags; int _texture_num_views; + AutoTextureScale _auto_texture_scale; }; INLINE ostream &operator << (ostream &out, const LoaderOptions &opts) { diff --git a/panda/src/putil/putil_composite1.cxx b/panda/src/putil/putil_composite1.cxx index fe142339c6..f1f2f9d7ec 100644 --- a/panda/src/putil/putil_composite1.cxx +++ b/panda/src/putil/putil_composite1.cxx @@ -1,4 +1,5 @@ #include "animInterface.cxx" +#include "autoTextureScale.cxx" #include "bamCache.cxx" #include "bamCacheIndex.cxx" #include "bamCacheRecord.cxx" diff --git a/panda/src/vision/openCVTexture.cxx b/panda/src/vision/openCVTexture.cxx index 3afacbafd2..040ca63817 100644 --- a/panda/src/vision/openCVTexture.cxx +++ b/panda/src/vision/openCVTexture.cxx @@ -233,11 +233,7 @@ do_reconsider_video_properties(Texture::CData *cdata, int x_size = width; int y_size = height; - - if (Texture::get_textures_power_2() != ATS_none) { - x_size = up_to_power_2(width); - y_size = up_to_power_2(height); - } + do_adjust_this_size(cdata, x_size, y_size, get_name(), true); if (vision_cat.is_debug()) { vision_cat.debug()