Ver código fonte

make_texture() is a useful function to publish

David Rose 14 anos atrás
pai
commit
4ebdf7b6fa

+ 13 - 0
panda/src/gobj/texturePool.I

@@ -338,3 +338,16 @@ INLINE const Filename &TexturePool::
 get_fake_texture_image() {
   return get_global_ptr()->_fake_texture_image;
 }
+
+////////////////////////////////////////////////////////////////////
+//     Function: TexturePool::make_texture
+//       Access: Published, Static
+//  Description: Creates a new Texture object of the appropriate type
+//               for the indicated filename extension, according to
+//               the types that have been registered via
+//               register_texture_type().
+////////////////////////////////////////////////////////////////////
+PT(Texture) TexturePool::
+make_texture(const string &extension) {
+  return get_global_ptr()->ns_make_texture(extension);
+}

+ 25 - 25
panda/src/gobj/texturePool.cxx

@@ -110,26 +110,6 @@ get_texture_type(const string &extension) const {
   return NULL;
 }
 
-////////////////////////////////////////////////////////////////////
-//     Function: TexturePool::make_texture
-//       Access: Public
-//  Description: Creates a new Texture object of the appropriate type
-//               for the indicated filename extension, according to
-//               the types that have been registered via
-//               register_texture_type().
-////////////////////////////////////////////////////////////////////
-PT(Texture) TexturePool::
-make_texture(const string &extension) const {
-  MakeTextureFunc *func = get_texture_type(extension);
-  if (func != NULL) {
-    return func();
-  }
-
-  // We don't know what kind of file type this is; return an ordinary
-  // Texture in case it's an image file with no extension.
-  return new Texture;
-}
-
 ////////////////////////////////////////////////////////////////////
 //     Function: TexturePool::write_texture_types
 //       Access: Public
@@ -299,7 +279,7 @@ ns_load_texture(const Filename &orig_filename, int primary_file_num_channels,
         
     } else {
       // Read it the conventional way.
-      tex = make_texture(ext);
+      tex = ns_make_texture(ext);
       if (!tex->read(filename, Filename(), primary_file_num_channels, 0,
                      0, 0, false, read_mipmaps, record, options)) {
         // This texture was not found or could not be read.
@@ -430,7 +410,7 @@ ns_load_texture(const Filename &orig_filename,
     gobj_cat.info()
       << "Loading texture " << filename << " and alpha component "
       << alpha_filename << endl;
-    tex = make_texture(filename.get_extension());
+    tex = ns_make_texture(filename.get_extension());
     if (!tex->read(filename, alpha_filename, primary_file_num_channels,
                    alpha_file_channel, 0, 0, false, read_mipmaps, NULL,
                    options)) {
@@ -550,7 +530,7 @@ ns_load_3d_texture(const Filename &filename_pattern,
     // cache; it needs to be loaded from its source image(s).
     gobj_cat.info()
       << "Loading 3-d texture " << filename << "\n";
-    tex = make_texture(filename.get_extension());
+    tex = ns_make_texture(filename.get_extension());
     tex->setup_3d_texture();
     if (!tex->read(filename, 0, 0, true, read_mipmaps, options)) {
       // This texture was not found or could not be read.
@@ -656,7 +636,7 @@ ns_load_2d_texture_array(const Filename &filename_pattern,
     // cache; it needs to be loaded from its source image(s).
     gobj_cat.info()
       << "Loading 2-d texture array " << filename << "\n";
-    tex = make_texture(filename.get_extension());
+    tex = ns_make_texture(filename.get_extension());
     tex->setup_2d_texture_array();
     if (!tex->read(filename, 0, 0, true, read_mipmaps, options)) {
       // This texture was not found or could not be read.
@@ -757,7 +737,7 @@ ns_load_cube_map(const Filename &filename_pattern, bool read_mipmaps,
     // cache; it needs to be loaded from its source image(s).
     gobj_cat.info()
       << "Loading cube map texture " << filename << "\n";
-    tex = make_texture(filename.get_extension());
+    tex = ns_make_texture(filename.get_extension());
     tex->setup_cube_map();
     if (!tex->read(filename, 0, 0, true, read_mipmaps, options)) {
       // This texture was not found or could not be read.
@@ -1044,6 +1024,26 @@ ns_find_all_textures(const string &name) const {
   return result;
 }
 
+////////////////////////////////////////////////////////////////////
+//     Function: TexturePool::ns_make_texture
+//       Access: Public
+//  Description: Creates a new Texture object of the appropriate type
+//               for the indicated filename extension, according to
+//               the types that have been registered via
+//               register_texture_type().
+////////////////////////////////////////////////////////////////////
+PT(Texture) TexturePool::
+ns_make_texture(const string &extension) const {
+  MakeTextureFunc *func = get_texture_type(extension);
+  if (func != NULL) {
+    return func();
+  }
+
+  // We don't know what kind of file type this is; return an ordinary
+  // Texture in case it's an image file with no extension.
+  return new Texture;
+}
+
 ////////////////////////////////////////////////////////////////////
 //     Function: TexturePool::resolve_filename
 //       Access: Private

+ 2 - 1
panda/src/gobj/texturePool.h

@@ -81,6 +81,7 @@ PUBLISHED:
   INLINE static void clear_fake_texture_image();
   INLINE static bool has_fake_texture_image();
   INLINE static const Filename &get_fake_texture_image();
+  INLINE static PT(Texture) make_texture(const string &extension);
 
   static void write(ostream &out);
 
@@ -90,7 +91,6 @@ public:
   void register_filter(TexturePoolFilter *filter);
   
   MakeTextureFunc *get_texture_type(const string &extension) const;
-  PT(Texture) make_texture(const string &extension) const;
   void write_texture_types(ostream &out, int indent_level) const;
 
   static TexturePool *get_global_ptr();
@@ -128,6 +128,7 @@ private:
   void ns_list_contents(ostream &out) const;
   Texture *ns_find_texture(const string &name) const;
   TextureCollection ns_find_all_textures(const string &name) const;
+  PT(Texture) ns_make_texture(const string &extension) const;
 
   void resolve_filename(Filename &new_filename, const Filename &orig_filename);