Merged changes from branches/supertux-milestone2-grumbel/ to trunk/supertux/
[supertux.git] / src / video / texture.hpp
1 //  SuperTux
2 //  Copyright (C) 2006 Matthias Braun <matze@braunis.de>
3 //
4 //  This program is free software: you can redistribute it and/or modify
5 //  it under the terms of the GNU General Public License as published by
6 //  the Free Software Foundation, either version 3 of the License, or
7 //  (at your option) any later version.
8 //
9 //  This program is distributed in the hope that it will be useful,
10 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
11 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 //  GNU General Public License for more details.
13 //
14 //  You should have received a copy of the GNU General Public License
15 //  along with this program.  If not, see <http://www.gnu.org/licenses/>.
16
17 #ifndef HEADER_SUPERTUX_VIDEO_TEXTURE_HPP
18 #define HEADER_SUPERTUX_VIDEO_TEXTURE_HPP
19
20 #include <config.h>
21
22 #include <assert.h>
23 #include <string>
24
25 #include "video/texture_manager.hpp"
26
27 /// bitset for drawing effects
28 enum DrawingEffect {
29   /** Don't apply anything */
30   NO_EFFECT,
31   /** Draw the Surface upside down */
32   VERTICAL_FLIP,
33   /** Draw the Surface from left to down */
34   HORIZONTAL_FLIP,
35   NUM_EFFECTS
36 };
37
38 /**
39  * This class is a wrapper around a texture handle. It stores the texture width
40  * and height and provides convenience functions for uploading SDL_Surfaces
41  * into the texture
42  */
43 class Texture
44 {
45 protected:
46   int refcount;
47   std::string filename;
48
49 public:
50   Texture() : refcount(0), filename() {}
51   virtual ~Texture() {}
52
53   virtual unsigned int get_texture_width() const = 0;
54   virtual unsigned int get_texture_height() const = 0;
55   virtual unsigned int get_image_width() const = 0;
56   virtual unsigned int get_image_height() const = 0;
57
58   std::string get_filename() const
59   {
60     return filename;
61   }
62
63   void set_filename(std::string filename)
64   {
65     this->filename = filename;
66   }
67
68   void ref()
69   {
70     refcount++;
71   }
72
73   void unref()
74   {
75     assert(refcount > 0);
76     refcount--;
77     if(refcount == 0)
78       release();
79   }
80
81 private:
82   void release()
83   {
84     texture_manager->release(this);
85   }
86
87 private:
88   Texture(const Texture&);
89   Texture& operator=(const Texture&);
90 };
91
92 #endif
93
94 /* EOF */