More -Weffc++ cleanup
[supertux.git] / src / video / texture.hpp
index 0e4dd89..589fd95 100644 (file)
@@ -1,12 +1,10 @@
-//  $Id$
-//
 //  SuperTux
 //  Copyright (C) 2006 Matthias Braun <matze@braunis.de>
 //
-//  This program is free software; you can redistribute it and/or
-//  modify it under the terms of the GNU General Public License
-//  as published by the Free Software Foundation; either version 2
-//  of the License, or (at your option) any later version.
+//  This program is free software: you can redistribute it and/or modify
+//  it under the terms of the GNU General Public License as published by
+//  the Free Software Foundation, either version 3 of the License, or
+//  (at your option) any later version.
 //
 //  This program is distributed in the hope that it will be useful,
 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
 //  GNU General Public License for more details.
 //
 //  You should have received a copy of the GNU General Public License
-//  along with this program; if not, write to the Free Software
-//  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+//  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+#ifndef HEADER_SUPERTUX_VIDEO_TEXTURE_HPP
+#define HEADER_SUPERTUX_VIDEO_TEXTURE_HPP
 
-#ifndef __TEXTURE_HPP__
-#define __TEXTURE_HPP__
+#include <config.h>
 
-#include <SDL.h>
-#include <GL/gl.h>
+#include <assert.h>
+#include <string>
+
+#include "video/texture_manager.hpp"
+
+/// bitset for drawing effects
+enum DrawingEffect {
+  /** Don't apply anything */
+  NO_EFFECT,
+  /** Draw the Surface upside down */
+  VERTICAL_FLIP,
+  /** Draw the Surface from left to down */
+  HORIZONTAL_FLIP,
+  NUM_EFFECTS
+};
 
 /**
  * This class is a wrapper around a texture handle. It stores the texture width
 class Texture
 {
 protected:
-  friend class TextureManager;
-  GLuint handle;
-  unsigned int width;
-  unsigned int height;
+  int refcount;
+  std::string filename;
 
 public:
-  Texture(unsigned int width, unsigned int height, GLenum glformat);
-  Texture(SDL_Surface* surface, GLenum glformat);
-  virtual ~Texture();
-  
-  GLuint get_handle() const
+  Texture() : refcount(0), filename() {}
+  virtual ~Texture() {}
+
+  virtual unsigned int get_texture_width() const = 0;
+  virtual unsigned int get_texture_height() const = 0;
+  virtual unsigned int get_image_width() const = 0;
+  virtual unsigned int get_image_height() const = 0;
+
+  std::string get_filename() const
   {
-    return handle;
+    return filename;
   }
 
-  unsigned int get_width() const
+  void set_filename(std::string filename)
   {
-    return width;
+    this->filename = filename;
   }
 
-  unsigned int get_height() const
+  void ref()
+  {
+    refcount++;
+  }
+
+  void unref()
+  {
+    assert(refcount > 0);
+    refcount--;
+    if(refcount == 0)
+      release();
+  }
+
+private:
+  void release()
   {
-    return height;
+    texture_manager->release(this);
   }
 
 private:
-  void set_texture_params();
+  Texture(const Texture&);
+  Texture& operator=(const Texture&);
 };
 
 #endif
 
+/* EOF */