From 1297993a344001b42d2d93d4ad181786fd2192ec Mon Sep 17 00:00:00 2001 From: Josh Yelon Date: Fri, 26 Oct 2007 21:54:20 +0000 Subject: [PATCH] Added concept of a texture's Pad Region --- panda/src/gobj/texture.I | 59 ++++++++++++++++++++++++++++++++++++++ panda/src/gobj/texture.cxx | 17 ++++++++++- panda/src/gobj/texture.h | 19 +++++++++--- 3 files changed, 90 insertions(+), 5 deletions(-) diff --git a/panda/src/gobj/texture.I b/panda/src/gobj/texture.I index 87a05a1c83..bd089629d5 100644 --- a/panda/src/gobj/texture.I +++ b/panda/src/gobj/texture.I @@ -502,6 +502,62 @@ get_z_size() const { return _z_size; } +//////////////////////////////////////////////////////////////////// +// Function: Texture::get_pad_x_size +// Access: Published +// Description: Returns size of the pad region. See set_pad_size. +//////////////////////////////////////////////////////////////////// +INLINE int Texture:: +get_pad_x_size() const { + return _pad_x_size; +} + +//////////////////////////////////////////////////////////////////// +// Function: Texture::get_pad_y_size +// Access: Published +// Description: Returns size of the pad region. See set_pad_size. +//////////////////////////////////////////////////////////////////// +INLINE int Texture:: +get_pad_y_size() const { + return _pad_y_size; +} + +//////////////////////////////////////////////////////////////////// +// Function: Texture::get_pad_z_size +// Access: Published +// Description: Returns size of the pad region. See set_pad_size. +//////////////////////////////////////////////////////////////////// +INLINE int Texture:: +get_pad_z_size() const { + return _pad_z_size; +} + +//////////////////////////////////////////////////////////////////// +// Function: Texture::set_pad_size +// Access: Published +// Description: Sets the size of the pad region. +// +// Sometimes, when a video card demands power-of-two +// textures, it is necessary to create a big texture +// and then only use a portion of it. The pad region +// indicates which portion of the texture is not +// really in use. All operations use the texture +// as a whole, including the pad region, unless they +// explicitly state that they use only the non-pad +// region. +// +// Changing the texture's size clears the pad region. +//////////////////////////////////////////////////////////////////// +INLINE void Texture:: +set_pad_size(int x, int y, int z) { + if (x > _x_size) x = _x_size; + if (y > _y_size) y = _y_size; + if (z > _z_size) z = _z_size; + _pad_x_size = x; + _pad_y_size = y; + _pad_z_size = z; +} + //////////////////////////////////////////////////////////////////// // Function: Texture::get_num_components // Access: Published @@ -1087,6 +1143,7 @@ set_x_size(int x_size) { _x_size = x_size; ++_image_modified; clear_ram_image(); + set_pad_size(); } } @@ -1104,6 +1161,7 @@ set_y_size(int y_size) { _y_size = y_size; ++_image_modified; clear_ram_image(); + set_pad_size(); } } @@ -1123,6 +1181,7 @@ set_z_size(int z_size) { _z_size = z_size; ++_image_modified; clear_ram_image(); + set_pad_size(); } } diff --git a/panda/src/gobj/texture.cxx b/panda/src/gobj/texture.cxx index ff4e112e8f..c890a9a84e 100644 --- a/panda/src/gobj/texture.cxx +++ b/panda/src/gobj/texture.cxx @@ -79,6 +79,10 @@ Texture(const string &name) : set_format(F_rgb); set_component_type(T_unsigned_byte); + _pad_x_size = 0; + _pad_y_size = 0; + _pad_z_size = 0; + _loaded_from_image = false; _loaded_from_txo = false; _has_read_pages = false; @@ -104,6 +108,9 @@ Texture(const Texture ©) : _x_size(copy._x_size), _y_size(copy._y_size), _z_size(copy._z_size), + _pad_x_size(copy._pad_x_size), + _pad_y_size(copy._pad_y_size), + _pad_z_size(copy._pad_z_size), _num_components(copy._num_components), _component_width(copy._component_width), _texture_type(copy._texture_type), @@ -151,6 +158,9 @@ operator = (const Texture ©) { _x_size = copy._x_size; _y_size = copy._y_size; _z_size = copy._z_size; + _pad_x_size = copy._pad_x_size; + _pad_y_size = copy._pad_y_size; + _pad_z_size = copy._pad_z_size; _num_components = copy._num_components; _component_width = copy._component_width; _texture_type = copy._texture_type; @@ -245,6 +255,7 @@ setup_texture(Texture::TextureType texture_type, int x_size, int y_size, set_format(format); clear_ram_image(); + set_pad_size(); _loaded_from_image = false; _loaded_from_txo = false; _has_read_pages = false; @@ -2643,11 +2654,14 @@ reconsider_image_properties(int x_size, int y_size, int num_components, nassertr(x_size == y_size, false); } #endif + if ((_x_size != x_size)||(_y_size != y_size)) { + set_pad_size(); + } _x_size = x_size; _y_size = y_size; _num_components = num_components; set_component_type(component_type); - + } else { if (_x_size != x_size || _y_size != y_size || @@ -3541,6 +3555,7 @@ fillin(DatagramIterator &scan, BamReader *manager, bool has_rawdata) { _ram_images[n]._image = image; } _loaded_from_image = true; + set_pad_size(); ++_image_modified; ++_properties_modified; } diff --git a/panda/src/gobj/texture.h b/panda/src/gobj/texture.h index 21b5f86520..27535615d3 100644 --- a/panda/src/gobj/texture.h +++ b/panda/src/gobj/texture.h @@ -340,6 +340,13 @@ PUBLISHED: INLINE void set_x_size(int x_size); INLINE void set_y_size(int y_size); INLINE void set_z_size(int z_size); + + INLINE int get_pad_x_size() const; + INLINE int get_pad_y_size() const; + INLINE int get_pad_z_size() const; + + INLINE void set_pad_size(int x=0, int y=0, int z=0); + void set_format(Format format); void set_component_type(ComponentType component_type); INLINE void set_loaded_from_image(); @@ -504,6 +511,10 @@ protected: bool _render_to_texture; bool _match_framebuffer_format; + int _pad_x_size; + int _pad_y_size; + int _pad_z_size; + // A Texture keeps a list (actually, a map) of all the // PreparedGraphicsObjects tables that it has been prepared into. // Each PGO conversely keeps a list (a set) of all the Textures that @@ -511,7 +522,7 @@ protected: // itself from the other's list. typedef pmap Contexts; Contexts _contexts; - + // It is common, when using normal maps, specular maps, gloss maps, // and such, to use a file naming convention where the filenames // of the special maps are derived by concatenating a suffix to @@ -519,7 +530,7 @@ protected: // lookup of the special maps given the diffuse map and the suffix. typedef pmap RelatedTextures; RelatedTextures _related_textures; - + CompressionMode _ram_image_compression; // There is usually one RamImage for the mipmap level 0 (the base @@ -527,10 +538,10 @@ protected: // additional mipmap levels. typedef pvector RamImages; RamImages _ram_images; - + UpdateSeq _properties_modified; UpdateSeq _image_modified; - + private: // The auxiliary data is not recorded to a bam file. typedef pmap AuxData;