Index: branches/new_class_id/src/lib/graphics/Makefile.am
===================================================================
--- branches/new_class_id/src/lib/graphics/Makefile.am	(revision 9816)
+++ branches/new_class_id/src/lib/graphics/Makefile.am	(revision 9818)
@@ -9,4 +9,5 @@
 		light.cc \
 		shader.cc \
+		shader_data.cc \
 		\
 		render2D/render_2d.cc \
Index: branches/new_class_id/src/lib/graphics/shader.cc
===================================================================
--- branches/new_class_id/src/lib/graphics/shader.cc	(revision 9816)
+++ branches/new_class_id/src/lib/graphics/shader.cc	(revision 9818)
@@ -74,5 +74,9 @@
 
 
-
+Shader::Shader()
+  : data(new ShaderData)
+{
+  
+}
 
 /**
@@ -80,175 +84,23 @@
 */
 Shader::Shader (const std::string& vertexShaderFile, const std::string& fragmentShaderFile)
+  : data(new ShaderData)
 {
-  this->registerObject(this, Shader::_objectList);
-  this->shaderProgram = 0;
-  this->vertexShader = 0;
-  this->fragmentShader = 0;
+  if (!Shader::checkShaderAbility())
+    PRINTF(2)("Your system does not support shaders\n");
+  else
+    this->load(vertexShaderFile, fragmentShaderFile);
 
-  if (GLEW_ARB_shader_objects && GLEW_ARB_shading_language_100)
-  {
-    this->shaderProgram = glCreateProgramObjectARB();
-
-    if (!vertexShaderFile.empty())
-      this->loadShaderProgramm(Shader::Vertex, vertexShaderFile);
-    if (!fragmentShaderFile.empty())
-      this->loadShaderProgramm(Shader::Fragment, fragmentShaderFile);
-
-    this->linkShaderProgram();
-
-  }
-  else
-  {
-    PRINTF(2)("Shaders are not supported on your hardware\n");
-  }
 }
 
+const Shader* Shader::storedShader = NULL;
 
-/**
- * standard deconstructor
- */
-Shader::~Shader ()
+void Shader::activateShader() const
 {
-  if (this->shaderProgram == glGetHandleARB(GL_PROGRAM_OBJECT_ARB))
-    Shader::deactivateShader();
-
-  // delete what has to be deleted here
-  this->deleteProgram(Shader::Vertex);
-  this->deleteProgram(Shader::Fragment);
-
-  if (this->fragmentShader != 0)
+  if (likely (this->getProgram() != 0))
   {
-    glDetachObjectARB(this->shaderProgram, this->fragmentShader);
-    glDeleteObjectARB(this->fragmentShader);
-  }
-  if (this->vertexShader != 0)
-  {
-    glDetachObjectARB(this->shaderProgram, this->vertexShader);
-    glDeleteObjectARB(this->vertexShader);
-  }
-  if (this->shaderProgram != 0)
-  {
-    GLint status = 0;
-    //glLinkProgramARB(this->shaderProgram);
-    glDeleteObjectARB(this->shaderProgram);
-    // link error checking
-    glGetObjectParameterivARB(this->shaderProgram, GL_OBJECT_DELETE_STATUS_ARB, &status);
-    if (status == GL_INVALID_VALUE || status == GL_INVALID_OPERATION)
-      this->printError(this->shaderProgram);
-  }
-}
-
-Shader* Shader::storedShader = NULL;
-
-
-bool Shader::loadShaderProgramm(Shader::Type type, const std::string& fileName)
-{
-  GLhandleARB shader = 0;
-
-  if (type != Shader::Vertex && type != Shader::Fragment)
-    return false;
-  this->deleteProgram(type);
-
-
-  std::string program;
-  if (!readShader(fileName, program))
-    return false;
-
-  if (type == Shader::Vertex && GLEW_ARB_vertex_shader)
-  {
-    this->vertexShaderFile = fileName;
-
-    shader = this->vertexShader = glCreateShaderObjectARB(GL_VERTEX_SHADER_ARB);
-  }
-
-  if (type == Shader::Fragment && GLEW_ARB_fragment_shader)
-  {
-    this->fragmentShaderFile = fileName;
-
-    shader = this->fragmentShader = glCreateShaderObjectARB(GL_FRAGMENT_SHADER_ARB);
-  }
-
-  if (shader != 0)
-  {
-    GLint status = 0;
-    const char* prog = program.c_str();
-
-    glShaderSourceARB(shader, 1, &prog, NULL);
-    glCompileShaderARB(shader);
-    // checking on error.
-    glGetObjectParameterivARB(shader, GL_OBJECT_COMPILE_STATUS_ARB, &status);
-    if (status == GL_INVALID_VALUE || status == GL_INVALID_OPERATION)
-      this->printError(shader);
-    else
-      glAttachObjectARB(this->shaderProgram, shader);
-  }
-  return true;
-}
-
-
-void Shader::linkShaderProgram()
-{
-  GLint status = 0;
-
-  glLinkProgramARB(this->shaderProgram);
-  // link error checking
-  glGetObjectParameterivARB(this->shaderProgram, GL_OBJECT_LINK_STATUS_ARB, &status);
-  if (status == GL_INVALID_VALUE || status == GL_INVALID_OPERATION)
-    this->printError(this->shaderProgram);
-}
-
-
-bool Shader::readShader(const std::string& fileName, std::string& output)
-{
-  char lineBuffer[PARSELINELENGTH];
-
-  std::ifstream shader;
-  shader.open(fileName.c_str());
-  if (!shader.is_open())
-    return false;
-
-
-  while (!shader.eof())
-  {
-    shader.getline(lineBuffer, PARSELINELENGTH);
-    output += lineBuffer;
-    output += "\n";
-  }
-
-
-  shader.close();
-  return true;
-}
-
-
-
-void Shader::activateShader()
-{
-  if (likely (this->shaderProgram != 0))
-  {
-    glUseProgramObjectARB(this->shaderProgram);
+    glUseProgramObjectARB(this->getProgram());
     Shader::storedShader = this;
   }
 }
-
-void Shader::bindShader(const char* name, const float* value, size_t size)
-{
-  if (likely (this->shaderProgram != 0))
-  {
-    glUseProgramObjectARB(this->shaderProgram);
-
-    unsigned int location = glGetUniformLocationARB(this->shaderProgram, name);
-    /* This is EXPENSIVE and should be avoided. */
-
-    if      (size == 1)  glUniform1fvARB(location, 1, value);
-    else if (size == 2)  glUniform2fvARB(location, 1, value);
-    else if (size == 3)  glUniform3fvARB(location, 1, value);
-    else if (size == 4)  glUniform4fvARB(location, 1, value);
-    else if (size == 9)  glUniformMatrix3fvARB(location, 1, false, value);
-    else if (size == 16) glUniformMatrix4fvARB(location, 1, false, value);
-
-  }
-}
-
 void Shader::deactivateShader()
 {
@@ -256,54 +108,4 @@
     glUseProgramObjectARB(0);
   Shader::storedShader = NULL;
-}
-
-
-void Shader::deleteProgram(Shader::Type type)
-{
-  GLint status = 0;
-  if (type == Shader::Vertex && this->vertexShader != 0)
-  {
-    this->vertexShaderFile = "";
-    glDetachObjectARB(this->shaderProgram, this->vertexShader);
-    glDeleteObjectARB(this->vertexShader);
-    glGetObjectParameterivARB(this->vertexShader, GL_OBJECT_DELETE_STATUS_ARB, &status);
-    if (status == GL_INVALID_VALUE || status == GL_INVALID_OPERATION)
-      Shader::printError(this->vertexShader);
-    this->vertexShader = 0;
-  }
-  else if (type == Shader::Fragment && this->fragmentShader != 0)
-  {
-    this->fragmentShaderFile = "";
-    glDetachObjectARB(this->shaderProgram, this->fragmentShader);
-    glDeleteObjectARB(this->fragmentShader);
-    glGetObjectParameterivARB(this->fragmentShader, GL_OBJECT_DELETE_STATUS_ARB, &status);
-    if (status == GL_INVALID_VALUE || status == GL_INVALID_OPERATION)
-      Shader::printError(this->fragmentShader);
-    this->fragmentShader = 0;
-  }
-  else
-    return;
-}
-
-
-void Shader::printError(GLhandleARB program)
-{
-  if (program == 0)
-    return;
-
-  int infologLength = 0;
-  int charsWritten  = 0;
-  char *infoLog;
-
-  glGetObjectParameterivARB(program, GL_OBJECT_INFO_LOG_LENGTH_ARB,
-                            &infologLength);
-
-  if (infologLength > 0)
-  {
-    infoLog = new char[infologLength+1];
-    glGetInfoLogARB(program, infologLength, &charsWritten, infoLog);
-    printf("%s\n", infoLog);
-    delete[] infoLog;
-  }
 }
 
@@ -319,21 +121,3 @@
 }
 
-void Shader::debug() const
-{
-  PRINT(3)("Shader info: (SHADER: %d)\n", this->shaderProgram);
-  if (this->vertexShader != 0)
-  {
-    /*    PRINT(3)("VertexShaderProgramm: number=%d, file='%s'\n", this->vertexShader, this->vertexShaderFile);
-        if (this->vertexShaderSource != NULL)
-          for (unsigned int i = 0; i < this->vertexShaderSource->getCount(); i++)
-            PRINT(3)("%d: %s\n", i, this->vertexShaderSource->getEntry(i));
-      }
-      if (this->fragmentShader != 0)
-      {
-        PRINT(3)("FragmentShaderProgramm: number=%d, file='%s'\n", this->fragmentShader, this->fragmentShaderFile);
-        if (this->fragmentShaderSource != NULL)
-          for (unsigned int i = 0; i < this->fragmentShaderSource->getCount(); i++)
-            PRINT(3)("%d: %s\n", i, this->fragmentShaderSource->getEntry(i));*/
-  }
-}
 
Index: branches/new_class_id/src/lib/graphics/shader.h
===================================================================
--- branches/new_class_id/src/lib/graphics/shader.h	(revision 9816)
+++ branches/new_class_id/src/lib/graphics/shader.h	(revision 9818)
@@ -8,7 +8,5 @@
 
 #include "base_object.h"
-#include "glincl.h"
-#include <vector>
-
+#include "shader_data.h"
 
 // FORWARD DECLARATION
@@ -24,5 +22,4 @@
   {
   public:
-    Uniform(const Shader* shader, const std::string& location) { this->uniform = glGetUniformLocationARB(shader->getProgram(), location.c_str()) ; }
     Uniform(const Shader& shader, const std::string& location) { this->uniform = glGetUniformLocation(shader.getProgram(), location.c_str()) ; };
     Uniform(GLhandleARB shaderProgram, const std::string& location) { this->uniform = glGetUniformLocation(shaderProgram, location.c_str()) ; };
@@ -45,55 +42,41 @@
   };
 
-  //! The Type of Shader.
-  typedef enum
-  {
-    None       = 0,     //!< No Type at all
-    Fragment   = 1,     //!< Fragment Shader.
-    Vertex     = 2,     //!< Vertex Shader.
-    Program    = 4,     //!< Compiled Shader Programm.
-  }  Type;
 
 public:
-  Shader(const std::string& vertexShaderFile = "", const std::string& fragmentShaderFile = "");
-  virtual ~Shader();
+  Shader();
+  Shader(const std::string& vertexShaderFile, const std::string& fragmentShaderFile = "");
+
+  Shader& operator=(const Shader& shader) { this->data = shader.data; return *this; };
+  const ShaderData::Pointer& dataPointer() const { return data; };
+  void acquireData(const ShaderData::Pointer& pointer) { this->data = pointer; };
+
+  bool load(const std::string& vertexShaderFile, const std::string& fragmentShaderFile = "")
+    { return this->data->load(vertexShaderFile, fragmentShaderFile); }
 
 
-  Shader::Uniform getUniform(const std::string& location) { return Shader::Uniform(this, location); }
+  Shader::Uniform getUniform(const std::string& location) { return Shader::Uniform(*this, location); }
 
-  GLhandleARB getProgram() const { return this->shaderProgram; }
-  GLhandleARB getVertexS() const { return this->vertexShader; }
-  GLhandleARB getFragmentS() const { return this->fragmentShader; }
+  GLhandleARB getProgram() const { return this->data->getProgram(); }
+  GLhandleARB getVertexS() const { return this->data->getVertexS(); }
+  GLhandleARB getFragmentS() const { return this->data->getFragmentS(); }
+
+  void activateShader() const;
+  static void deactivateShader();
+
+  void debug() const { this->data->debug(); };
+
 
   static bool checkShaderAbility();
-  void activateShader();
-  static void deactivateShader();
-
-  void debug() const;
 
   inline static bool isShaderActive() { return (Shader::storedShader != NULL) ? true : false; };
-  inline static Shader* getActiveShader() { return Shader::storedShader; };
-  inline static void suspendShader() { Shader* currShader = storedShader; if (storedShader!= NULL) { Shader::deactivateShader(); Shader::storedShader = currShader;} };
+  inline static const Shader* getActiveShader() { return Shader::storedShader; };
+
+  inline static void suspendShader() { const Shader* currShader = storedShader; if (storedShader!= NULL) { Shader::deactivateShader(); Shader::storedShader = currShader;} };
   inline static void restoreShader() { if (storedShader != NULL) storedShader->activateShader(); storedShader = NULL; };
 
-  static void printError(GLhandleARB program);
+private:
+  ShaderData::Pointer    data;
 
-private:
-  void bindShader(const char* name, const float* value, size_t size);
-  void linkShaderProgram();
-  bool readShader(const std::string& fileName, std::string& output);
-  bool loadShaderProgramm(Shader::Type type, const std::string& fileName);
-  void deleteProgram(Shader::Type type);
-
-private:
-  std::string            fragmentShaderFile;
-  std::string            vertexShaderFile;
-
-  GLhandleARB            shaderProgram;
-
-  GLhandleARB            vertexShader;
-  GLhandleARB            fragmentShader;
-
-
-  static Shader*         storedShader;
+  static const Shader*         storedShader;
 };
 
Index: branches/new_class_id/src/lib/graphics/shader_data.cc
===================================================================
--- branches/new_class_id/src/lib/graphics/shader_data.cc	(revision 9816)
+++ branches/new_class_id/src/lib/graphics/shader_data.cc	(revision 9818)
@@ -38,11 +38,16 @@
  * standard constructor
 */
-Shader::Shader (const std::string& vertexShaderFile, const std::string& fragmentShaderFile)
-{
-  this->registerObject(this, Shader::_objectList);
+ShaderData::ShaderData ()
+{
+  this->registerObject(this, ShaderData::_objectList);
   this->shaderProgram = 0;
   this->vertexShader = 0;
   this->fragmentShader = 0;
-
+}
+
+
+/// TODO fix that shaders are unloaded first. then loaded
+bool ShaderData::load(const std::string& vertexShaderFile, const std::string& fragmentShaderFile)
+{
   if (GLEW_ARB_shader_objects && GLEW_ARB_shading_language_100)
   {
@@ -50,7 +55,7 @@
 
     if (!vertexShaderFile.empty())
-      this->loadShaderProgramm(Shader::Vertex, vertexShaderFile);
+      this->loadShaderProgramm(ShaderData::Vertex, vertexShaderFile);
     if (!fragmentShaderFile.empty())
-      this->loadShaderProgramm(Shader::Fragment, fragmentShaderFile);
+      this->loadShaderProgramm(ShaderData::Fragment, fragmentShaderFile);
 
     this->linkShaderProgram();
@@ -62,17 +67,16 @@
   }
 }
-
 
 /**
  * standard deconstructor
  */
-Shader::~Shader ()
+ShaderData::~ShaderData ()
 {
   if (this->shaderProgram == glGetHandleARB(GL_PROGRAM_OBJECT_ARB))
-    Shader::deactivateShader();
+    glUseProgramObjectARB(0);
 
   // delete what has to be deleted here
-  this->deleteProgram(Shader::Vertex);
-  this->deleteProgram(Shader::Fragment);
+  this->deleteProgram(ShaderData::Vertex);
+  this->deleteProgram(ShaderData::Fragment);
 
   if (this->fragmentShader != 0)
@@ -98,12 +102,9 @@
 }
 
-Shader* Shader::storedShader = NULL;
-
-
-bool Shader::loadShaderProgramm(Shader::Type type, const std::string& fileName)
+bool ShaderData::loadShaderProgramm(ShaderData::Type type, const std::string& fileName)
 {
   GLhandleARB shader = 0;
 
-  if (type != Shader::Vertex && type != Shader::Fragment)
+  if (type != ShaderData::Vertex && type != ShaderData::Fragment)
     return false;
   this->deleteProgram(type);
@@ -114,5 +115,5 @@
     return false;
 
-  if (type == Shader::Vertex && GLEW_ARB_vertex_shader)
+  if (type == ShaderData::Vertex && GLEW_ARB_vertex_shader)
   {
     this->vertexShaderFile = fileName;
@@ -121,5 +122,5 @@
   }
 
-  if (type == Shader::Fragment && GLEW_ARB_fragment_shader)
+  if (type == ShaderData::Fragment && GLEW_ARB_fragment_shader)
   {
     this->fragmentShaderFile = fileName;
@@ -146,5 +147,5 @@
 
 
-void Shader::linkShaderProgram()
+void ShaderData::linkShaderProgram()
 {
   GLint status = 0;
@@ -158,5 +159,5 @@
 
 
-bool Shader::readShader(const std::string& fileName, std::string& output)
+bool ShaderData::readShader(const std::string& fileName, std::string& output)
 {
   char lineBuffer[PARSELINELENGTH];
@@ -180,16 +181,5 @@
 }
 
-
-
-void Shader::activateShader()
-{
-  if (likely (this->shaderProgram != 0))
-  {
-    glUseProgramObjectARB(this->shaderProgram);
-    Shader::storedShader = this;
-  }
-}
-
-void Shader::bindShader(const char* name, const float* value, size_t size)
+void ShaderData::bindShader(const char* name, const float* value, size_t size)
 {
   if (likely (this->shaderProgram != 0))
@@ -210,16 +200,8 @@
 }
 
-void Shader::deactivateShader()
-{
-  if (storedShader != NULL)
-    glUseProgramObjectARB(0);
-  Shader::storedShader = NULL;
-}
-
-
-void Shader::deleteProgram(Shader::Type type)
+void ShaderData::deleteProgram(ShaderData::Type type)
 {
   GLint status = 0;
-  if (type == Shader::Vertex && this->vertexShader != 0)
+  if (type == ShaderData::Vertex && this->vertexShader != 0)
   {
     this->vertexShaderFile = "";
@@ -228,8 +210,8 @@
     glGetObjectParameterivARB(this->vertexShader, GL_OBJECT_DELETE_STATUS_ARB, &status);
     if (status == GL_INVALID_VALUE || status == GL_INVALID_OPERATION)
-      Shader::printError(this->vertexShader);
+      ShaderData::printError(this->vertexShader);
     this->vertexShader = 0;
   }
-  else if (type == Shader::Fragment && this->fragmentShader != 0)
+  else if (type == ShaderData::Fragment && this->fragmentShader != 0)
   {
     this->fragmentShaderFile = "";
@@ -238,5 +220,5 @@
     glGetObjectParameterivARB(this->fragmentShader, GL_OBJECT_DELETE_STATUS_ARB, &status);
     if (status == GL_INVALID_VALUE || status == GL_INVALID_OPERATION)
-      Shader::printError(this->fragmentShader);
+      ShaderData::printError(this->fragmentShader);
     this->fragmentShader = 0;
   }
@@ -246,5 +228,5 @@
 
 
-void Shader::printError(GLhandleARB program)
+void ShaderData::printError(GLhandleARB program)
 {
   if (program == 0)
@@ -267,18 +249,7 @@
 }
 
-bool Shader::checkShaderAbility()
-{
-  if (GLEW_ARB_shader_objects &&
-      GLEW_ARB_shading_language_100 &&
-      GLEW_ARB_vertex_shader &&
-      GLEW_ARB_fragment_shader)
-    return true;
-  else
-    return false;
-}
-
-void Shader::debug() const
-{
-  PRINT(3)("Shader info: (SHADER: %d)\n", this->shaderProgram);
+void ShaderData::debug() const
+{
+  PRINT(3)("ShaderData info: (SHADER: %d)\n", this->shaderProgram);
   if (this->vertexShader != 0)
   {
Index: branches/new_class_id/src/lib/graphics/shader_data.h
===================================================================
--- branches/new_class_id/src/lib/graphics/shader_data.h	(revision 9816)
+++ branches/new_class_id/src/lib/graphics/shader_data.h	(revision 9818)
@@ -9,7 +9,7 @@
 #include "base_object.h"
 
-#include "shader_types.h"
+#include "glincl.h"
 #include <vector>
-
+#include "count_pointer.h"
 
 // FORWARD DECLARATION
@@ -21,9 +21,20 @@
 {
   ObjectListDeclaration(ShaderData);
+  //! The Type of Shader.
+  typedef enum  {
+    None       = 0,     //!< No Type at all
+    Fragment   = 1,     //!< Fragment Shader.
+    Vertex     = 2,     //!< Vertex Shader.
+    Program    = 4,     //!< Compiled Shader Programm.
+  }  Type;
+
+ public:
+  typedef CountPointer<ShaderData> Pointer;
 public:
-  ShaderData(const std::string& vertexShaderFile = "", const std::string& fragmentShaderFile = "");
+  ShaderData();
   virtual ~ShaderData();
 
-  Shaders::Uniform getUniform(const std::string& location) { return Shader::Uniform(this, location); }
+  bool load(const std::string& vertexShaderFile = "", const std::string& fragmentShaderFile = "");
+
 
   GLhandleARB getProgram() const { return this->shaderProgram; }
@@ -38,8 +49,11 @@
   void linkShaderProgram();
   bool readShader(const std::string& fileName, std::string& output);
-  bool loadShaderProgramm(Shader::Type type, const std::string& fileName);
-  void deleteProgram(Shader::Type type);
+  bool loadShaderProgramm(ShaderData::Type type, const std::string& fileName);
+  void deleteProgram(ShaderData::Type type);
+
+  static void printError(GLhandleARB program);
 
 private:
+
   std::string            fragmentShaderFile;
   std::string            vertexShaderFile;
