samedi 15 juin 2019

How to have two different type of variables in unordererd_map

This is my current class structure.

I find the need to add another Variable with the name of TextureCubeMap in the class.

Currently i was keeping track of all the Texture2D instances with the help of Unordererd_map.

1)std::unordered_map m_filePathToId;

2)std::unordered_map m_idToTexture;

3)std::unordered_map m_idInstances;

I want to create two objects from this class , one for texture2D and one for TextureCubemap.

My question is that how do i keep track of TextureCubeMap in the class.

Should i make three more unordered_map to keep track of cubeMap which seems bit raw.

Please suggest me the ways of handling this issue.

typedef uint32_t UniqueTextureId;

class TextureManager
{
  private:
  // increment and return for each new texture loaded. 
  // zero should indicate an invalid texture
  UniqueTextureId m_idGenerator = 0;
  // a lookup to turn the file path into a unique ID
  std::unordered_map<std::string, UniqueTextureId> m_filePathToId;
  // a lookup to get the texture from an ID
  std::unordered_map<UniqueTextureId, Texture2D> m_idToTexture;
  // a lookup to get the number of instances of the  ID
  std::unordered_map<UniqueTextureId, int > m_idInstances;

   // a method to take a raw filepath and... 
   // 1. convert \ to /
   // 2. make lower case on windows
   // 3. convert any absolute paths to relative paths
   // 4. If a paths starts with ./, remove the first two chars. 
   std::string tidyUpFilePath(std::string str);

   Texture2D loadTextureFromFile(const GLchar *file, GLboolean alpha);
   TextureCubeMap loadCubeTextureFromFile(const GLchar *file, GLboolean 
 alpha);

 public:

    // return a unique ID for this texture (which can probably be
   // unique only within the current TextureManager). 
   UniqueTextureId LoadTexture(const GLchar *file, GLboolean alpha );
   UniqueTextureId LoadCubeTexture(const GLchar *file, GLboolean alpha);

   // Do not return a Texture2D object! (return a pointer instead)
   // if you return a copy of the texture, there is a good chance 
   // the destructor will end up calling glDeleteTextures each 
   // time the returned object is destroyed, which will cause a right 
   // bother for the next frame!
   Texture2D* GetTexture(UniqueTextureId id) ;

  // turn a file path into an integer
  UniqueTextureId filePathToId(std::string messyPath);

  const int NumberOfTexture();

  ~TextureManager();
};

Aucun commentaire:

Enregistrer un commentaire