]> git.jsancho.org Git - lugaru.git/blobdiff - Source/Graphic/Texture.hpp
Cleaned up TextureRes lifecycle to make sure it’s destroyed by RAII
[lugaru.git] / Source / Graphic / Texture.hpp
index 0f1282898053bd6b56310860f7db2fd046dd5d5d..54df61336cdecc4d6ba849d5fab29f9ba2a0a697 100644 (file)
@@ -26,8 +26,7 @@ along with Lugaru.  If not, see <http://www.gnu.org/licenses/>.
 #include <map>
 #include <string>
 #include <vector>
-
-using namespace std;
+#include <memory>
 
 class TextureRes
 {
@@ -47,17 +46,20 @@ public:
     TextureRes(const string& filename, bool hasMipmap, GLubyte* array, int* skinsize);
     ~TextureRes();
     void bind();
+
+    /* Make sure TextureRes never gets copied */
+    TextureRes(TextureRes const& other) = delete;
+    TextureRes & operator=(TextureRes const& other) = delete;
 };
 
 class Texture
 {
 private:
-    TextureRes* tex;
+    std::shared_ptr<TextureRes> tex;
 public:
-    inline Texture(): tex(NULL) {}
+    inline Texture(): tex(nullptr) {}
     void load(const string& filename, bool hasMipmap);
     void load(const string& filename, bool hasMipmap, GLubyte* array, int* skinsizep);
-    void destroy();
     void bind();
 };