Index: branches/water/src/lib/graphics/importer/material.h
===================================================================
--- branches/water/src/lib/graphics/importer/material.h	(revision 7782)
+++ branches/water/src/lib/graphics/importer/material.h	(revision 7783)
@@ -1,8 +1,8 @@
 /*!
-  \file material.h
-  \brief Contains the Material Class that handles Material for 3D-Objects.
-  @todo free SDL-surface when deleting Material.
-  @todo delete imgNameWithPath after use creation.
-*/
+ * @file material.h
+ * @brief Contains the Material Class that handles Material for 3D-Objects.
+ * @todo free SDL-surface when deleting Material.
+ * @todo delete imgNameWithPath after use creation.
+ */
 
 #ifndef _MATERIAL_H
Index: branches/water/src/lib/graphics/importer/texture.cc
===================================================================
--- branches/water/src/lib/graphics/importer/texture.cc	(revision 7782)
+++ branches/water/src/lib/graphics/importer/texture.cc	(revision 7783)
@@ -20,5 +20,4 @@
 #include "debug.h"
 #include "compiler.h"
-#include <math.h>
 
 // INCLUDING SDL_Image
@@ -30,55 +29,18 @@
 
 
-
-
-Texture::Texture(GLenum target)
-{
-  this->init();
-  this->generateTexture(texture, target);
-}
-
-/**
- *  Constructor for a Texture
-*/
-Texture::Texture(const std::string& imageName, GLenum target)
-{
-  this->init();
-
-  if (!imageName.empty())
-  {
-    this->setName(imageName);
-    this->loadImage(imageName, target);
-  }
-}
-
-
-
-Texture::Texture(SDL_Surface* surface, GLenum target)
-{
-  this->init();
-
-  if(surface != NULL)
-  {
-    this->loadSurface(surface, target);
-
-  }
-}
-
-void Texture::init()
-{
-  this->setClassID(CL_TEXTURE, "Texture");
-
+TextureData::TextureData()
+{
   this->bAlpha = false;
   this->texture = 0;
   this->image = NULL;
-  this->priority = 0.5;
-}
-
-/**
- *  Destructor of a Texture
-
-   Frees Data, and deletes the textures from GL
-*/
-Texture::~Texture()
+}
+
+
+/**
+ * @brief Destructor of a Texture
+ *
+ *  Frees Data, and deletes the textures from GL
+ */
+TextureData::~TextureData()
 {
   if (this->texture != 0)
@@ -90,4 +52,111 @@
 
 /**
+ * @brief Loads an SDL_Surface.
+ */
+bool TextureData::loadSurface(SDL_Surface* surface, GLenum target)
+{
+  if (Texture::getTextureEnableState())
+  {
+    SDL_Surface* newSurf = Texture::prepareSurface(surface, this->bAlpha);
+    if (newSurf != NULL)
+    {
+      this->setSurface(newSurf);
+      this->setTexture(Texture::loadTexToGL(newSurf, target));
+      return true;
+    }
+  }
+  return false;
+}
+
+
+
+/**
+ * @brief set the surface this Texture handles
+ * @param newSurface the new Surface to set as the image for this Texture.
+ *
+ * This deletes the old version of the stored Texture,
+ * and sets the newly given Surface as current.
+ */
+bool TextureData::setSurface(SDL_Surface* newSurface)
+{
+  if (this->image != NULL)
+    SDL_FreeSurface(this->image);
+
+  this->image = newSurface;
+
+  return (this->image != NULL);
+}
+
+
+
+bool TextureData::setTexture(GLuint texture)
+{
+     // unload the old Texture.
+  if (this->texture != 0 && glIsTexture(this->getTexture()))
+  {
+    glDeleteTextures(1, &this->texture);
+  }
+  this->texture = texture;
+  return (texture != 0);
+}
+
+
+
+
+
+Texture::Texture(GLenum target)
+{
+  this->init();
+  GLuint texture;
+  this->generateTexture(texture, target);
+  this->data->setTexture(texture);
+}
+
+/**
+ *  Constructor for a Texture
+*/
+Texture::Texture(const std::string& imageName, GLenum target)
+{
+  this->init();
+
+  if (!imageName.empty())
+  {
+    this->setName(imageName);
+    this->loadImage(imageName, target);
+  }
+}
+
+
+
+Texture::Texture(SDL_Surface* surface, GLenum target)
+{
+  this->init();
+
+  if(surface != NULL)
+  {
+    this->data->loadSurface(surface, target);
+  }
+}
+
+void Texture::init()
+{
+  this->setClassID(CL_TEXTURE, "Texture");
+
+  this->data = CountPointer<TextureData>(new TextureData());
+
+  this->priority = 0.5;
+}
+
+/**
+ *  Destructor of a Texture
+
+   Frees Data, and deletes the textures from GL
+*/
+Texture::~Texture()
+{
+}
+
+
+/**
  * @brief loads an Image from a file to a Texture
  * @param imageName The image to load
@@ -105,5 +174,5 @@
       if(tmpSurf != NULL)
       {
-        this->loadSurface(tmpSurf, target);
+        this->data->loadSurface(tmpSurf, target);
         SDL_FreeSurface(tmpSurf);
         return true;
@@ -112,5 +181,5 @@
       {
         PRINTF(1)("IMG_Load: %s\n", IMG_GetError());
-        this->texture = 0;
+        this->setTexture(0);
         return false;
       }
@@ -126,39 +195,4 @@
 
 /**
- * @brief Loads an SDL_Surface.
- */
-bool Texture::loadSurface(SDL_Surface* surface, GLenum target)
-{
-  if (Texture::texturesEnabled)
-  {
-    // some image was loaded before
-    if (this->image != NULL)
-    {
-      SDL_FreeSurface(this->image);
-      this->image = NULL;
-    }
-
-    // unload the old Texture.
-    if (this->texture != 0 && glIsTexture(this->texture))
-    {
-      glDeleteTextures(1, &this->texture);
-      this->texture = 0;
-    }
-
-    bool hasAlpha;
-    SDL_Surface* newSurf = this->prepareSurface(surface, hasAlpha);
-    if (newSurf != NULL)
-    {
-      this->setSurface(newSurf);
-      this->setAlpha(hasAlpha);
-      this->setTexture(Texture::loadTexToGL(newSurf, target));
-      return true;
-    }
-  }
-  return false;
-}
-
-
-/**
  * @brief rebuilds the texture.
  * reloads the Texture from Memory to OpenGL.
@@ -166,36 +200,12 @@
 bool Texture::rebuild()
 {
-  if (this->texture != 0)
-  {
-    if (glIsTexture(this->texture))
-      glDeleteTextures(1,&this->texture);
-    this->setTexture(0);
-  }
-
-  if (this->image != NULL)
+  this->data->setTexture(0);
+
+  if (this->data->getStoredImage() != NULL)
   {
     PRINTF(3)("Reloading Texture of %s '%s'\n", this->getClassName(), this->getName());
-    this->setTexture(loadTexToGL(this->image));
-  }
-}
-
-
-/**
- * @brief set the surface this Texture handles
- * @param newSurface the new Surface to set as the image for this Texture.
- *
- * This deletes the old version of the stored Texture,
- * and sets the newly given Surface as current.
- */
-bool Texture::setSurface(SDL_Surface* newSurface)
-{
-  if (this->image != NULL)
-    SDL_FreeSurface(this->image);
-
-  this->image = newSurface;
-
-  return (this->image != NULL);
-}
-
+    this->setTexture(Texture::loadTexToGL(this->data->getStoredImage()));
+  }
+}
 
 bool Texture::texturesEnabled = true;
@@ -220,5 +230,5 @@
  * @returns a !!new!! Surface, that is loadable by openGL.
  */
-SDL_Surface* Texture::prepareSurface(SDL_Surface* surface, bool& hasAlpha) const
+SDL_Surface* Texture::prepareSurface(SDL_Surface* surface, bool& hasAlpha)
 {
   PRINTF(4)("Loading texture to OpenGL-Environment.\n");
@@ -258,5 +268,5 @@
   }
 
-  /* Copy the surface into the GL texture image */
+  /* Copy the surface into the GL texture this->data->getStoredImage() */
   area.x = 0;
   area.y = 0;
@@ -281,9 +291,9 @@
  * @returns The ID of the texture.
  */
-GLuint Texture::loadTexToGL (const SDL_Surface* surface, GLenum target) const
-{
-  //   if (this->texture != 0 && glIsTexture(this->texture))
-  //     glDeleteTextures(1, &this->texture);
-  //   this->texture = 0;
+GLuint Texture::loadTexToGL (const SDL_Surface* surface, GLenum target)
+{
+  //   if (this->data->getTexture() != 0 && glIsTexture(this->data->getTexture()))
+  //     glDeleteTextures(1, &this->data->getTexture());
+  //   this->data->getTexture() = 0;
 
   int      errorCode = 0;           //!< the error code for the texture loading functions
@@ -297,7 +307,9 @@
     return 0;
 
-  /* Create an OpenGL texture for the image */
-  this->generateTexture(texture, target);
-  glTexParameterf(GL_TEXTURE_ENV, GL_TEXTURE_PRIORITY, this->priority);
+  /* Create an OpenGL texture for the this->data->getStoredImage() */
+  Texture::generateTexture(texture, target);
+
+  /// TODO CHECK THIS BACK in
+  //glTexParameterf(GL_TEXTURE_ENV, GL_TEXTURE_PRIORITY, this->priority);
 
   /* build the Texture  OpenGL V >= 1.1 */
@@ -330,5 +342,5 @@
 void Texture::generateTexture(GLuint& texture, GLenum target)
 {
-  if (!glIsTexture(texture))
+  if (texture == 0 && !glIsTexture(texture))
   {
     glGenTextures(1, &texture);
@@ -346,3 +358,2 @@
   glTexParameterf(GL_TEXTURE_ENV, GL_TEXTURE_MAX_LOD, 0);
 }
-
Index: branches/water/src/lib/graphics/importer/texture.h
===================================================================
--- branches/water/src/lib/graphics/importer/texture.h	(revision 7782)
+++ branches/water/src/lib/graphics/importer/texture.h	(revision 7783)
@@ -10,55 +10,88 @@
 
 #include "glincl.h"
+#include "count_pointer.h"
 
 /* Forward Declaration */
 struct SDL_Surface;
 
-//! A Class, that reads in Textures from different fileformats.
-  class Texture : public BaseObject
-  {
-    public:
-      Texture(GLenum target = GL_TEXTURE_2D);
-      Texture(const std::string& imageName, GLenum target = GL_TEXTURE_2D);
-      Texture(SDL_Surface* surface, GLenum target = GL_TEXTURE_2D);
-      virtual ~Texture();
 
-      bool loadImage(const std::string& imageName, GLenum target = GL_TEXTURE_2D);
-      bool loadSurface(SDL_Surface* surface, GLenum target = GL_TEXTURE_2D);
-      virtual bool rebuild();
+class TextureData
+{
+  public:
+    TextureData();
+    ~TextureData();
 
-      /** @returns The textureID of this texture.  */
-      inline GLuint getTexture() const { return this->texture; };
-      /** @returns true if texture has alpha, false otherwise */
-      inline bool hasAlpha() const  {return bAlpha; }
-      /** @returns the stored image of this Texture */
-      const SDL_Surface* const getStoredImage() const { return this->image; };
+    inline GLuint getTexture() const { return this->texture; };
+    /** @returns true if texture has alpha, false otherwise */
+    inline bool hasAlpha() const  {return this->bAlpha; }
+    /** @returns the stored image of this Texture */
+    const SDL_Surface* const getStoredImage() const { return this->image; };
+
+    bool loadSurface(SDL_Surface* surface, GLenum target = GL_TEXTURE_2D);
 
 
 
-      static void setTextureEnableState(bool texturesEnabled);
-      /** @returns true if Textures are enabled */
-      inline static bool getTextureEnableState() { return Texture::texturesEnabled; };
+    bool rebuild();
 
-      // Utility functionality:
-      SDL_Surface* prepareSurface(SDL_Surface* input, bool& hasAlpha) const;
-      GLuint loadTexToGL (const SDL_Surface* surface, GLenum target = GL_TEXTURE_2D) const;
+    bool setSurface(SDL_Surface* newSurface);
+    bool setAlpha(bool hasAlpha) { this->bAlpha = hasAlpha; };
+    bool setTexture(GLuint texture);
 
-    protected:
-      bool setSurface(SDL_Surface* newSurface);
-      bool setAlpha(bool hasAlpha) { this->bAlpha = hasAlpha; };
-      bool setTexture(GLuint texture) { this->texture = texture; };
+  private:
+    GLuint           texture;            //!< The Texture-ID of opengl from this Texture.
+    bool             bAlpha;             //!< if the texture has an alpha channel.
+    SDL_Surface*     image;              //!< The SDL_Surfce that stores the Texture on it.
+};
 
-    private:
-      void init();
-      static void generateTexture(GLuint& texture, GLenum target);
 
-    private:
-      GLuint           texture;            //!< The Texture-ID of opengl from this Texture.
-      bool             bAlpha;             //!< if the texture has an alpha channel.
-      SDL_Surface*     image;              //!< The SDL_Surfce that stores the Texture on it.
-      GLclampf         priority;           //!< the priority of the current texture (used for garphics cards with limited mem)
+//! A Class, that reads in Textures from different fileformats.
+class Texture : public BaseObject
+{
+public:
 
-      static bool      texturesEnabled;    //!< If the Textures are enabled.
-  };
+public:
+  Texture(GLenum target = GL_TEXTURE_2D);
+  Texture(const std::string& imageName, GLenum target = GL_TEXTURE_2D);
+  Texture(SDL_Surface* surface, GLenum target = GL_TEXTURE_2D);
+
+  virtual ~Texture();
+
+  bool loadImage(const std::string& imageName, GLenum target = GL_TEXTURE_2D);
+  bool loadSurface(SDL_Surface* surface, GLenum target = GL_TEXTURE_2D);
+  virtual bool rebuild();
+
+  /** @returns The textureID of this texture.  */
+  inline GLuint getTexture() const { return this->data->getTexture(); };
+  /** @returns true if texture has alpha, false otherwise */
+  inline bool hasAlpha() const  { return this->data->hasAlpha(); }
+  /** @returns the stored image of this Texture */
+  const SDL_Surface* const getStoredImage() const { return this->data->getStoredImage(); };
+
+
+
+  static void setTextureEnableState(bool texturesEnabled);
+  /** @returns true if Textures are enabled */
+  inline static bool getTextureEnableState() { return Texture::texturesEnabled; };
+
+  // Utility functionality:
+  static SDL_Surface* prepareSurface(SDL_Surface* input, bool& hasAlpha);
+  static GLuint loadTexToGL (const SDL_Surface* surface, GLenum target = GL_TEXTURE_2D);
+
+
+protected:
+  bool setSurface(SDL_Surface* newSurface) { return this->data->setSurface(newSurface); };
+  bool setAlpha(bool hasAlpha) { return this->data->setAlpha(hasAlpha); };
+  bool setTexture(GLuint texture) { return this->data->setTexture(texture); };
+
+private:
+  void init();
+  static void generateTexture(GLuint& texture, GLenum target);
+
+private:
+  CountPointer<TextureData>     data;               //!< The TextureData
+  GLclampf                      priority;           //!< the priority of the current texture (used for garphics cards with limited mem)
+
+  static bool                   texturesEnabled;    //!< If the Textures are enabled.
+};
 
 #endif /* _TEXTURE_H */
