Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 7818 in orxonox.OLD for branches


Ignore:
Timestamp:
May 24, 2006, 5:38:28 PM (19 years ago)
Author:
bensch
Message:

Better nicer Shader

Location:
branches/water/src/lib/graphics
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/water/src/lib/graphics/shader.cc

    r7221 r7818  
    4040   this->setClassID(CL_SHADER, "Shader");
    4141
    42    this->fragmentShaderFile = "";
    43    this->vertexShaderFile = "";
    4442   this->shaderProgram = 0;
    4543   this->vertexShader = 0;
     
    4846   if (GLEW_ARB_shader_objects && GLEW_ARB_shading_language_100)
    4947     {
    50        GLint status = 0;
    51 
    5248       this->shaderProgram = glCreateProgramObjectARB();
    5349
    5450       if (!vertexShaderFile.empty())
    55          this->loadShaderProgramm(SHADER_VERTEX, vertexShaderFile);
     51         this->loadShaderProgramm(Shader::Vertex, vertexShaderFile);
    5652       if (!fragmentShaderFile.empty())
    57          this->loadShaderProgramm(SHADER_FRAGMENT, fragmentShaderFile);
    58        glLinkProgramARB(this->shaderProgram);
    59        // link error checking
    60        glGetObjectParameterivARB(this->shaderProgram, GL_OBJECT_LINK_STATUS_ARB, &status);
    61        if (status == GL_INVALID_VALUE || status == GL_INVALID_OPERATION)
    62          this->printError(this->shaderProgram);
     53         this->loadShaderProgramm(Shader::Fragment, fragmentShaderFile);
     54
     55       this->linkShaderProgram();
     56
    6357    }
    6458   else
     
    7872
    7973  // delete what has to be deleted here
    80   this->deleteProgram(SHADER_VERTEX);
    81   this->deleteProgram(SHADER_FRAGMENT);
     74  this->deleteProgram(Shader::Vertex);
     75  this->deleteProgram(Shader::Fragment);
    8276
    8377  if (this->fragmentShader != 0)
     
    116110
    117111
    118 bool Shader::loadShaderProgramm(SHADER_TYPE type, const std::string& fileName)
     112bool Shader::loadShaderProgramm(Shader::Type type, const std::string& fileName)
    119113{
    120114  GLhandleARB shader = 0;
    121115
    122   if (type != SHADER_VERTEX && type != SHADER_FRAGMENT)
     116  if (type != Shader::Vertex && type != Shader::Fragment)
    123117    return false;
    124118  this->deleteProgram(type);
     
    127121  std::vector<char*>* program = fileReadArray(fileName);
    128122
    129   if (type == SHADER_VERTEX && GLEW_ARB_vertex_shader)
     123  if (type == Shader::Vertex && GLEW_ARB_vertex_shader)
    130124  {
    131125    this->vertexShaderFile = fileName;
     
    134128  }
    135129
    136   if (type == SHADER_FRAGMENT && GLEW_ARB_fragment_shader)
     130  if (type == Shader::Fragment && GLEW_ARB_fragment_shader)
    137131  {
    138132    this->fragmentShaderFile = fileName;
     
    158152  delete program;
    159153}
     154
     155
     156void Shader::linkShaderProgram()
     157{
     158  GLint status = 0;
     159
     160  glLinkProgramARB(this->shaderProgram);
     161       // link error checking
     162  glGetObjectParameterivARB(this->shaderProgram, GL_OBJECT_LINK_STATUS_ARB, &status);
     163  if (status == GL_INVALID_VALUE || status == GL_INVALID_OPERATION)
     164    this->printError(this->shaderProgram);
     165}
     166
    160167
    161168char* Shader::fileRead(const std::string& fileName)
     
    228235
    229236
    230 void Shader::deleteProgram(SHADER_TYPE type)
     237void Shader::deleteProgram(Shader::Type type)
    231238{
    232239  GLint status = 0;
    233   if (type == SHADER_VERTEX && this->vertexShader != 0)
     240  if (type == Shader::Vertex && this->vertexShader != 0)
    234241  {
    235242    this->vertexShaderFile = "";
     
    241248    this->vertexShader = 0;
    242249  }
    243   else if (type == SHADER_FRAGMENT && this->fragmentShader != 0)
     250  else if (type == Shader::Fragment && this->fragmentShader != 0)
    244251  {
    245252    this->fragmentShaderFile = "";
  • branches/water/src/lib/graphics/shader.h

    r7785 r7818  
    1212
    1313
    14 typedef enum
    15 {
    16   SHADER_NONE       = 0,
    17   SHADER_FRAGMENT   = 1,
    18   SHADER_VERTEX     = 0,
    19 
    20 } SHADER_TYPE;
    21 
    2214// FORWARD DECLARATION
    2315
    2416
    2517//! A class for ...
    26 class Shader : public BaseObject {
     18class Shader : public BaseObject
     19{
     20  public:
     21  typedef enum
     22  {
     23    None       = 0,
     24    Fragment   = 1,
     25    Vertex     = 2,
     26
     27    Program    = 4,
     28  } Type;
    2729
    2830  public:
     
    3234  static bool unload(Shader* shader);
    3335
    34   bool loadShaderProgramm(SHADER_TYPE type, const std::string& fileName);
     36
     37  static bool checkShaderAbility();
    3538  void activateShader();
    3639  static void deactivateShader();
    37   void deleteProgram(SHADER_TYPE type);
     40
     41
     42  bool loadShaderProgramm(Shader::Type type, const std::string& fileName);
     43  void deleteProgram(Shader::Type type);
     44
     45  void linkShaderProgram();
     46
    3847
    3948  char* fileRead(const std::string& fileName);
    4049  std::vector<char*>* fileReadArray(const std::string& fileName);
    4150
    42   static bool checkShaderAbility();
    4351
    4452  inline static bool shaderActive() { return (Shader::storedShader != NULL)? true : false; };
     
    4755  inline static void restoreShader() { if (storedShader != NULL) storedShader->activateShader(); storedShader = NULL; };
    4856
    49   GLhandleARB getProgram() { return this->shaderProgram; }
    50   GLhandleARB getVertexS() { return this->vertexShader; }
    51   GLhandleARB getFragmentS() { return this->fragmentShader; }
    5257
    53   void printError(GLhandleARB program);
     58  GLhandleARB getProgram() const { return this->shaderProgram; }
     59  GLhandleARB getVertexS() const { return this->vertexShader; }
     60  GLhandleARB getFragmentS() const { return this->fragmentShader; }
     61
    5462  void debug() const;
    5563
    56   private:
     64  static void printError(GLhandleARB program);
     65
    5766
    5867 private:
    5968   std::string            fragmentShaderFile;
    6069   std::string            vertexShaderFile;
     70
    6171   GLhandleARB            shaderProgram;
     72
    6273   GLhandleARB            vertexShader;
    6374   GLhandleARB            fragmentShader;
Note: See TracChangeset for help on using the changeset viewer.