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