TexturePool::make_texture(const string &extension)

Hello,

I am having difficulties to understand what is going on in

PT(Texture) TexturePool::
make_texture(const string &extension) const {
Texture::make_texture
  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;
}

If the type is known then:

get_texture_type(extension)

returns a function pointer to:

PT(Texture) Texture::
make_texture() {
  return new Texture;
}

otherwise it returns NULL and subsequently PT(Texture) TexturePool::make_texture(const string &extension) returns new Texture

Isn’t it the same?

Yes, in the case of an ordinary texture, it’s the same thing. But in the case of a video texture extension, like .avi or something, then get_texture_type() will return a pointer to the constructor for the appropriate video texture class.

David

Mmh, I don’t see how :frowning:

TexturePool::MakeTextureFunc *TexturePool::
get_texture_type(const string &extension) const {
  MutexHolder holder(_lock);

  string c = downcase(extension);
  TypeRegistry::const_iterator ti;
  ti = _type_registry.find(extension);
  if (ti != _type_registry.end()) {
    return (*ti).second;
  }

  // Check the PNM type registry.
  PNMFileTypeRegistry *pnm_reg = PNMFileTypeRegistry::get_global_ptr();
  PNMFileType *type = pnm_reg->get_type_from_extension(extension);
  if (type != (PNMFileType *)NULL) {
    // This is a known image type; create an ordinary Texture.
    ((TexturePool *)this)->_type_registry[extension] = Texture::make_texture;
    return Texture::make_texture;
  }

  // This is an unknown texture type.
  return NULL;
}

it seems to me it return always

PT(Texture) Texture:make_texture

This is the magic line that returns something else:

return (*ti).second;

In config_grutil.cxx, you’ll see lines like this:

ts->register_texture_type(MovieTexture::make_texture, "avi mov mpg mpeg mp4 wmv asf flv nut ogm");

ts->register_texture_type(FFMpegTexture::make_texture, "avi mov mpg mpeg mp4 wmv asf flv nut ogm");

which are adding these other make_texture() constructors to the registry to be returned by the above line.

David

Oh, I see now.

Thanks a lot