Tulip  4.1.0
Better Visualization Through Research
 All Classes Files Functions Variables Enumerations Enumerator Properties Groups Pages
GlTextureManager.h
1 /*
2  *
3  * This file is part of Tulip (www.tulip-software.org)
4  *
5  * Authors: David Auber and the Tulip development Team
6  * from LaBRI, University of Bordeaux 1 and Inria Bordeaux - Sud Ouest
7  *
8  * Tulip is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU Lesser General Public License
10  * as published by the Free Software Foundation, either version 3
11  * of the License, or (at your option) any later version.
12  *
13  * Tulip is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16  * See the GNU General Public License for more details.
17  *
18  */
19 ///@cond DOXYGEN_HIDDEN
20 
21 #ifndef Tulip_GLTEXTUREMANAGER_H
22 #define Tulip_GLTEXTUREMANAGER_H
23 
24 #include <map>
25 
26 #include <tulip/tulipconf.h>
27 
28 #include <cassert>
29 #include <tulip/OpenGlConfigManager.h>
30 #include <string>
31 #include <set>
32 #include <iostream>
33 
34 namespace tlp {
35 
36 struct GlTexture {
37  GLuint *id;
38  int height;
39  int width;
40  unsigned int spriteNumber;
41 };
42 
43 /** \brief Class to manage textures
44  * Singleton class to load/store textures need by OpenGL rendering
45  */
46 class TLP_GL_SCOPE GlTextureManager {
47 
48  typedef std::map<std::string,GlTexture> TextureUnit;
49  typedef std::map<unsigned long,TextureUnit> ContextAndTextureMap;
50 
51 public:
52 
53  /**
54  * Create the texture manager singleton
55  */
56  static void createInst();
57  /**
58  * Return the texture manager singleton, il singleton doesn't exist this function create it
59  */
60  static GlTextureManager &getInst() {
61  if(!inst)
62  inst=new GlTextureManager();
63 
64  return *inst;
65  }
66 
67  /**
68  * Change the current OpenGl context (each OpenGl window have a different OpenGl context)
69  */
70  void changeContext(unsigned long context);
71  /**
72  * Remove all textures of an OpenGl context and remove this context
73  */
74  void removeContext(unsigned long context);
75 
76  /**
77  * Return texture info (id, width and height) for the given name
78  */
79  GlTexture getTextureInfo(const std::string&);
80 
81  /**
82  * Check if a texture fo the given name exists in the current context
83  */
84  bool existsTexture(const std::string& filename);
85  /**
86  * Load texture with given name
87  */
88  bool loadTexture(const std::string&);
89  /**
90  * Remove texture with given name
91  */
92  void deleteTexture(const std::string &);
93  /**
94  * Begin a new texture with given name
95  */
96  void beginNewTexture(const std::string&);
97  /**
98  * Activate a texture with given name
99  */
100  bool activateTexture(const std::string&,unsigned int);
101  /**
102  * Activate a texture with given name
103  */
104  bool activateTexture(const std::string&);
105  /**
106  * Disable texture with given name
107  */
108  void desactivateTexture();
109  /**
110  * Set animationStep for next textures (for next activateTexture)
111  */
112  void setAnimationFrame(unsigned int id) {
113  animationFrame=id;
114  }
115  /**
116  * Get animationStep of next textures
117  */
118  unsigned int getAnimationFrame() {
119  return animationFrame;
120  }
121  /**
122  * Clear vector of textures with error
123  */
124  void clearErrorVector() {
125  texturesWithError.clear();
126  }
127  /**
128  * Remove an entry of vector of textures with error
129  */
130  void removeEntryOfErrorVector(const std::string &name) {
131  texturesWithError.erase(name);
132  }
133 
134 
135  /**
136  * Register an external texture is GlTextureManager
137  */
138  void registerExternalTexture(const std::string &textureName, const GLuint textureId);
139 
140 private:
141 
142  /**
143  * empty private constructor for singleton
144  */
145  GlTextureManager();
146 
147  static GlTextureManager* inst;
148 
149  unsigned long currentContext;
150 
151  ContextAndTextureMap texturesMap;
152  std::set<std::string> texturesWithError;
153 
154  unsigned int animationFrame;
155 
156 };
157 
158 }
159 
160 #endif // Tulip_GLTEXTUREMANAGER_H
161 ///@endcond