diff --git a/panda/src/gobj/texture.cxx b/panda/src/gobj/texture.cxx index abddc14cab..6bc9b1a778 100644 --- a/panda/src/gobj/texture.cxx +++ b/panda/src/gobj/texture.cxx @@ -498,6 +498,9 @@ read_pages(Filename fullpath_pattern, int z_size) { } } + set_fullpath(fullpath_pattern); + clear_alpha_fullpath(); + return true; } @@ -1614,16 +1617,16 @@ consider_downgrade(PNMImage &pnmimage, int num_channels) { //////////////////////////////////////////////////////////////////// void Texture:: register_with_read_factory() { - BamReader::get_factory()->register_factory(get_class_type(), make_Texture); + BamReader::get_factory()->register_factory(get_class_type(), make_from_bam); } //////////////////////////////////////////////////////////////////// -// Function: Texture::make_Texture -// Access: Protected +// Function: Texture::make_from_bam +// Access: Protected, Static // Description: Factory method to generate a Texture object //////////////////////////////////////////////////////////////////// TypedWritable *Texture:: -make_Texture(const FactoryParams ¶ms) { +make_from_bam(const FactoryParams ¶ms) { // The process of making a texture is slightly different than making // other TypedWritable objects. That is because all creation of // Textures should be done through calls to TexturePool, which @@ -1634,7 +1637,8 @@ make_Texture(const FactoryParams ¶ms) { parse_params(params, scan, manager); - // Get the filenames so we can look up the file on disk first. + // Get the filenames and texture type so we can look up the file on + // disk first. string name = scan.get_string(); Filename filename = scan.get_string(); Filename alpha_filename = scan.get_string(); @@ -1642,6 +1646,7 @@ make_Texture(const FactoryParams ¶ms) { int primary_file_num_channels = scan.get_uint8(); int alpha_file_channel = scan.get_uint8(); bool has_rawdata = scan.get_bool(); + TextureType texture_type = (TextureType)scan.get_uint8(); Texture *me = NULL; if (has_rawdata) { @@ -1659,15 +1664,34 @@ make_Texture(const FactoryParams ¶ms) { } else { // This texture does have a filename, so try to load it from disk. VirtualFileSystem *vfs = VirtualFileSystem::get_global_ptr(); - if (!manager->get_filename().empty()) - vfs->resolve_filename(filename,manager->get_filename().get_dirname()); - if (alpha_filename.empty()) { - me = TexturePool::load_texture(filename, primary_file_num_channels); - } else { - if (!manager->get_filename().empty()) - vfs->resolve_filename(alpha_filename, manager->get_filename().get_dirname()); - me = TexturePool::load_texture(filename, alpha_filename, - primary_file_num_channels, alpha_file_channel); + if (!manager->get_filename().empty()) { + // If texture filename was given relative to the bam filename, + // expand it now. + DSearchPath bam_dir = manager->get_filename().get_dirname(); + vfs->resolve_filename(filename, bam_dir); + if (!alpha_filename.empty()) { + vfs->resolve_filename(alpha_filename, bam_dir); + } + } + + switch (texture_type) { + case TT_1d_texture: + case TT_2d_texture: + if (alpha_filename.empty()) { + me = TexturePool::load_texture(filename, primary_file_num_channels); + } else { + me = TexturePool::load_texture(filename, alpha_filename, + primary_file_num_channels, alpha_file_channel); + } + break; + + case TT_3d_texture: + me = TexturePool::load_3d_texture(filename); + break; + + case TT_cube_map: + me = TexturePool::load_cube_map(filename); + break; } } } @@ -1697,8 +1721,6 @@ make_Texture(const FactoryParams ¶ms) { void Texture:: fillin(DatagramIterator &scan, BamReader *manager, bool has_rawdata) { // We have already read in the filenames; don't read them again. - - _texture_type = (TextureType)scan.get_uint8(); _wrap_u = (WrapMode)scan.get_uint8(); _wrap_v = (WrapMode)scan.get_uint8(); _wrap_w = (WrapMode)scan.get_uint8(); @@ -1804,9 +1826,9 @@ write_datagram(BamWriter *manager, Datagram &me) { me.add_uint8(_primary_file_num_channels); me.add_uint8(_alpha_file_channel); me.add_bool(has_rawdata); + me.add_uint8(_texture_type); // The data beginning at this point is handled by fillin(). - me.add_uint8(_texture_type); me.add_uint8(_wrap_u); me.add_uint8(_wrap_v); me.add_uint8(_wrap_w); diff --git a/panda/src/gobj/texture.h b/panda/src/gobj/texture.h index 16aac52289..cc2d55e284 100644 --- a/panda/src/gobj/texture.h +++ b/panda/src/gobj/texture.h @@ -356,12 +356,11 @@ protected: // Datagram stuff public: static void register_with_read_factory(); - virtual void write_datagram(BamWriter* manager, Datagram &me); - - static TypedWritable *make_Texture(const FactoryParams ¶ms); + virtual void write_datagram(BamWriter *manager, Datagram &me); protected: - void fillin(DatagramIterator& scan, BamReader* manager, bool has_rawdata = false); + static TypedWritable *make_from_bam(const FactoryParams ¶ms); + void fillin(DatagramIterator &scan, BamReader *manager, bool has_rawdata); public: static TypeHandle get_class_type() { diff --git a/panda/src/gobj/texturePool.cxx b/panda/src/gobj/texturePool.cxx index b89f74514e..284ee296e1 100644 --- a/panda/src/gobj/texturePool.cxx +++ b/panda/src/gobj/texturePool.cxx @@ -298,6 +298,7 @@ ns_load_texture(const Filename &orig_filename, Texture *TexturePool:: ns_load_3d_texture(const Filename &filename_pattern) { Filename filename(filename_pattern); + filename.set_pattern(true); VirtualFileSystem *vfs = VirtualFileSystem::get_global_ptr(); vfs->resolve_filename(filename, get_texture_path()) || @@ -317,6 +318,7 @@ ns_load_3d_texture(const Filename &filename_pattern) { if (!tex->read_pages(filename)) { // This texture was not found or could not be read. report_texture_unreadable(filename); + return NULL; } // Set the original filename, before we searched along the path. @@ -334,6 +336,7 @@ ns_load_3d_texture(const Filename &filename_pattern) { Texture *TexturePool:: ns_load_cube_map(const Filename &filename_pattern) { Filename filename(filename_pattern); + filename.set_pattern(true); VirtualFileSystem *vfs = VirtualFileSystem::get_global_ptr(); vfs->resolve_filename(filename, get_texture_path()) || @@ -353,6 +356,7 @@ ns_load_cube_map(const Filename &filename_pattern) { if (!tex->read_pages(filename)) { // This texture was not found or could not be read. report_texture_unreadable(filename); + return NULL; } // Set the original filename, before we searched along the path. diff --git a/panda/src/gobj/videoTexture.I b/panda/src/gobj/videoTexture.I index 94e9e5e260..306caa1346 100644 --- a/panda/src/gobj/videoTexture.I +++ b/panda/src/gobj/videoTexture.I @@ -17,40 +17,6 @@ //////////////////////////////////////////////////////////////////// -//////////////////////////////////////////////////////////////////// -// Function: VideoTexture::set_power_2 -// Access: Published -// Description: Sets the flag that indicates whether a newly-loaded -// VideoTexture will be constrained to dimensions that are -// a power of 2 or not. If true, then a newly-loaded -// video stream will be set within the smallest power of -// 2 texture that will fit it; if false, a newly-loaded -// video stream will be set within a texture that -// exactly fits it, even if that means creating a -// texture whose dimensions are not a power of 2. -// -// This must be set before the first call to read(). -// The default value is false if the Config.prc variable -// textures-power-2 is "none", true otherwise. -//////////////////////////////////////////////////////////////////// -INLINE void VideoTexture:: -set_power_2(bool power_2) { - _power_2 = power_2; -} - -//////////////////////////////////////////////////////////////////// -// Function: VideoTexture::get_power_2 -// Access: Published -// Description: Returns the flag that indicates whether a -// newly-loaded VideoTexture will be constrained to -// dimensions that are a power of 2 or not. See -// set_power_2(). -//////////////////////////////////////////////////////////////////// -INLINE bool VideoTexture:: -get_power_2() const { - return _power_2; -} - //////////////////////////////////////////////////////////////////// // Function: VideoTexture::get_video_width // Access: Published diff --git a/panda/src/gobj/videoTexture.cxx b/panda/src/gobj/videoTexture.cxx index 4cbc015ee9..6bb22bd4e4 100644 --- a/panda/src/gobj/videoTexture.cxx +++ b/panda/src/gobj/videoTexture.cxx @@ -33,7 +33,6 @@ VideoTexture:: VideoTexture(const string &name) : Texture(name) { - _power_2 = (textures_power_2 != ATS_none); _video_width = 0; _video_height = 0; @@ -50,7 +49,6 @@ VideoTexture:: VideoTexture(const VideoTexture ©) : Texture(copy), AnimInterface(copy), - _power_2(copy._power_2), _video_width(copy._video_width), _video_height(copy._video_height), _last_frame_update(copy._last_frame_update), diff --git a/panda/src/gobj/videoTexture.h b/panda/src/gobj/videoTexture.h index e101e9c50b..51f27a6439 100644 --- a/panda/src/gobj/videoTexture.h +++ b/panda/src/gobj/videoTexture.h @@ -37,9 +37,6 @@ protected: VideoTexture(const VideoTexture ©); PUBLISHED: - INLINE void set_power_2(bool power_2); - INLINE bool get_power_2() const; - virtual bool has_ram_image() const; virtual bool get_keep_ram_image() const; @@ -62,7 +59,6 @@ protected: virtual void update_frame(int frame)=0; private: - bool _power_2; int _video_width; int _video_height; int _last_frame_update; diff --git a/panda/src/grutil/config_grutil.cxx b/panda/src/grutil/config_grutil.cxx index d759f15cc3..30f966f6f0 100644 --- a/panda/src/grutil/config_grutil.cxx +++ b/panda/src/grutil/config_grutil.cxx @@ -67,6 +67,7 @@ init_libgrutil() { #ifdef HAVE_OPENCV OpenCVTexture::init_type(); + OpenCVTexture::register_with_read_factory(); PandaSystem *ps = PandaSystem::get_global_ptr(); ps->add_system("OpenCV"); diff --git a/panda/src/grutil/openCVTexture.cxx b/panda/src/grutil/openCVTexture.cxx index 1ac0f4e903..b5df2047c1 100644 --- a/panda/src/grutil/openCVTexture.cxx +++ b/panda/src/grutil/openCVTexture.cxx @@ -278,7 +278,7 @@ reconsider_video_properties(const OpenCVTexture::VideoStream &stream, int x_size = width; int y_size = height; - if (get_power_2()) { + if (textures_power_2 != ATS_none) { x_size = up_to_power_2(width); y_size = up_to_power_2(height); } @@ -409,6 +409,27 @@ update_frame(int frame) { } } +//////////////////////////////////////////////////////////////////// +// Function: OpenCVTexture::register_with_read_factory +// Access: Public, Static +// Description: Factory method to generate a Texture object +//////////////////////////////////////////////////////////////////// +void OpenCVTexture:: +register_with_read_factory() { + // Since Texture is such a funny object that is reloaded from the + // TexturePool each time, instead of actually being read fully from + // the bam file, and since the VideoTexture and OpenCVTexture + // classes don't really add any useful data to the bam record, we + // don't need to define make_from_bam(), fillin(), or + // write_datagram() in this class--we just inherit the same + // functions from Texture. + + // We do, however, have to register this class with the BamReader, + // to avoid warnings about creating the wrong kind of object from + // the bam file. + BamReader::get_factory()->register_factory(get_class_type(), make_from_bam); +} + //////////////////////////////////////////////////////////////////// // Function: OpenCVTexture::VideoStream::Constructor // Access: Public diff --git a/panda/src/grutil/openCVTexture.h b/panda/src/grutil/openCVTexture.h index b80f66e72b..c0bc4188ff 100644 --- a/panda/src/grutil/openCVTexture.h +++ b/panda/src/grutil/openCVTexture.h @@ -100,6 +100,9 @@ private: typedef pvector Pages; Pages _pages; +public: + static void register_with_read_factory(); + public: static TypeHandle get_class_type() { return _type_handle;