Index: trunk/src/lib/graphics/importer/texture.cc
===================================================================
--- trunk/src/lib/graphics/importer/texture.cc	(revision 6100)
+++ trunk/src/lib/graphics/importer/texture.cc	(revision 6139)
@@ -19,4 +19,6 @@
 
 #include "debug.h"
+#include "compiler.h"
+#include <math.h>
 
 // INCLUDING SDL_Image
@@ -37,4 +39,5 @@
   this->texture = 0;
   this->image = NULL;
+  this->priority = 0.5;
 
   if (imageName != NULL)
@@ -177,5 +180,5 @@
  * @returns a !!new!! Surface, that is loadable by openGL.
  */
-SDL_Surface* Texture::prepareSurface(SDL_Surface* surface, bool& hasAlpha)
+SDL_Surface* Texture::prepareSurface(SDL_Surface* surface, bool& hasAlpha) const
 {
   PRINTF(4)("Loading texture to OpenGL-Environment.\n");
@@ -237,5 +240,5 @@
  * @returns The ID of the texture.
  */
-GLuint Texture::loadTexToGL (const SDL_Surface* surface)
+GLuint Texture::loadTexToGL (const SDL_Surface* surface) const
 {
 //   if (this->texture != 0 && glIsTexture(this->texture))
@@ -243,5 +246,10 @@
 //   this->texture = 0;
 
-  GLuint texture;
+  int      errorCode = 0;           //!< the error code for the texture loading functions
+  GLuint   texture;                 //!< the OpenGL texture handle
+  int      mipmapLevel = 0;         //!< the maximum mipmap level for this texture
+  int      mipmapWidth = 0;         //!< the width of the mipmap
+  int      mipmapHight = 0;         //!< the height of the mipmap
+
 
   if (surface == NULL)
@@ -251,7 +259,13 @@
   glGenTextures(1, &texture);
   glBindTexture(GL_TEXTURE_2D, texture);
-  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
-  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
-  // build the Texture
+
+  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, /*GL_LINEAR*/ GL_LINEAR_MIPMAP_LINEAR);
+  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, /*GL_LINEAR*/ GL_LINEAR);
+  /* control the mipmap levels */
+  glTexParameterf(GL_TEXTURE_ENV, GL_TEXTURE_MIN_LOD, -100);
+  glTexParameterf(GL_TEXTURE_ENV, GL_TEXTURE_MAX_LOD, 0);
+  glTexParameterf(GL_TEXTURE_ENV, GL_TEXTURE_PRIORITY, this->priority);
+
+  /* build the Texture  OpenGL V >= 1.1 */
   glTexImage2D(GL_TEXTURE_2D,
                0,
@@ -262,13 +276,38 @@
                GL_UNSIGNED_BYTE,
                surface->pixels);
-  // build the MipMaps
-  gluBuild2DMipmaps(GL_TEXTURE_2D,
-                    GL_RGBA,
-                    surface->w,
-                    surface->h,
-                    GL_RGBA,
-                    GL_UNSIGNED_BYTE,
-                    surface->pixels);
+
+  // build the MipMaps automaticaly
+  errorCode = gluBuild2DMipmaps(GL_TEXTURE_2D,
+                                GL_RGBA,
+                                surface->w,
+                                surface->h,
+                                GL_RGBA,
+                                GL_UNSIGNED_BYTE,
+                                surface->pixels
+                               );
+  if(unlikely(errorCode != 0))
+    PRINTF(1)("Error while loading texture, gluBuild2DMipmaps returned %i\n", errorCode);
+
+#define max(a,b) (a>b)?a:b
+  mipmapLevel = (int)(log2f(max(surface->w, surface->h)));
+#undef max
+  PRINTF(5)("Built the texture mipmpaps, got: %i levels of detail\n", mipmapLevel);
+
+  /* now actualy load the mipmaps into the graphics memory */
+  glGetTexLevelParameteriv(GL_PROXY_TEXTURE_2D, 1, GL_TEXTURE_WIDTH, &mipmapWidth);
+  glGetTexLevelParameteriv(GL_PROXY_TEXTURE_2D, 1, GL_TEXTURE_WIDTH, &mipmapHight);
+  PRINTF(5)(" Mipmap at level %i has a %ix%i resolution\n", 1, mipmapWidth, mipmapHight);
+  glTexImage2D(GL_PROXY_TEXTURE_2D,
+               1,
+               GL_RGBA,
+               mipmapWidth, mipmapHight,
+               0,
+               GL_RGBA,
+               GL_UNSIGNED_BYTE,
+               NULL
+               );
+
   glBindTexture(GL_TEXTURE_2D, 0);
   return texture;
 }
+
Index: trunk/src/lib/graphics/importer/texture.h
===================================================================
--- trunk/src/lib/graphics/importer/texture.h	(revision 6100)
+++ trunk/src/lib/graphics/importer/texture.h	(revision 6139)
@@ -39,6 +39,6 @@
 
       // Utility functionality:
-      static SDL_Surface* prepareSurface(SDL_Surface* input, bool& hasAlpha);
-      static GLuint loadTexToGL (const SDL_Surface* surface);
+      SDL_Surface* prepareSurface(SDL_Surface* input, bool& hasAlpha) const;
+      GLuint loadTexToGL (const SDL_Surface* surface) const;
 
     protected:
@@ -53,4 +53,5 @@
       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)
 
       static bool      texturesEnabled;    //!< If the Textures are enabled.
