Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 7835 in orxonox.OLD for branches/water


Ignore:
Timestamp:
May 24, 2006, 8:55:03 PM (19 years ago)
Author:
bensch
Message:

orxonox/water: Uniform class, (total inline Class, that handles Uniforms of Shader-Programs

File:
1 edited

Legend:

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

    r7834 r7835  
    1515
    1616
     17
    1718//! A class for ...
    1819class Shader : public BaseObject
    1920{
     21public:
     22  class Uniform
     23  {
    2024  public:
     25    Uniform(const Shader* shader, const std::string& location) { glGetUniformLocationARB(shader->getProgram(), location.c_str()) ; }
     26    Uniform(const Shader& shader, const std::string& location) { glGetUniformLocation(shader.getProgram(), location.c_str()) ; };
     27    Uniform(GLhandleARB shaderProgram, const std::string& location) { glGetUniformLocation(shaderProgram, location.c_str()) ; };
     28
     29    void set(float v0) const { glUniform1f(this->uniform, v0); }
     30    void set(float v0, float v1) const { glUniform2f(this->uniform, v0, v1); }
     31    void set(float v0, float v1, float v2) const { glUniform3f(this->uniform, v0, v1, v2); }
     32    void set(float v0, float v1, float v2, float v3) const { glUniform4f(this->uniform, v0, v1, v2, v3); }
     33
     34    void set(int v0) const { glUniform1i(this->uniform, v0); }
     35    void set(int v0, int v1) const { glUniform2i(this->uniform, v0, v1); }
     36    void set(int v0, int v1, int v2) const { glUniform3i(this->uniform, v0, v1, v2); }
     37    void set(int v0, int v1, int v2, int v3) const { glUniform4i(this->uniform, v0, v1, v2, v3); }
     38
     39    void setV(unsigned int count, float* vv) const
     40    {
     41      switch (count)
     42      {
     43        case 1:
     44          glUniform1fv(this->uniform, 1, vv);
     45          break;
     46        case 2:
     47          glUniform2fv(this->uniform, 2, vv);
     48          break;
     49        case 3:
     50          glUniform3fv(this->uniform, 3, vv);
     51          break;
     52        case 4:
     53          glUniform4fv(this->uniform, 4, vv);
     54          break;
     55      }
     56    }
     57    void setV(unsigned int count, int* vv) const
     58    {
     59      switch (count)
     60      {
     61        case 1:
     62          glUniform1iv(this->uniform, 1, vv);
     63          break;
     64        case 2:
     65          glUniform2iv(this->uniform, 2, vv);
     66          break;
     67        case 3:
     68          glUniform3iv(this->uniform, 3, vv);
     69          break;
     70        case 4:
     71          glUniform4iv(this->uniform, 4, vv);
     72          break;
     73      }
     74    }
     75    private:
     76    GLint uniform;
     77  };
     78
    2179  typedef enum
    2280  {
     
    2684
    2785    Program    = 4,
    28   } Type;
     86  }
     87  Type;
    2988
    30   public:
     89public:
    3190  Shader(const std::string& vertexShaderFile = "", const std::string& fragmentShaderFile = "");
    3291  virtual ~Shader();
     
    3998  static void deactivateShader();
    4099
     100  Shader::Uniform getUniform(const std::string& location) { return Shader::Uniform(this, location); }
    41101
    42102  bool loadShaderProgramm(Shader::Type type, const std::string& fileName);
     
    49109
    50110
    51   inline static bool shaderActive() { return (Shader::storedShader != NULL)? true : false; };
     111inline static bool shaderActive() { return (Shader::storedShader != NULL)? true : false; };
    52112  inline static Shader* getActiveShader() { return Shader::storedShader; };
    53113  inline static void suspendShader() { Shader* currShader = storedShader; if (storedShader!= NULL) { Shader::deactivateShader(); Shader::storedShader = currShader;} };
    54114  inline static void restoreShader() { if (storedShader != NULL) storedShader->activateShader(); storedShader = NULL; };
     115
     116
    55117
    56118
     
    64126
    65127
    66  private:
    67    std::string            fragmentShaderFile;
    68    std::string            vertexShaderFile;
     128private:
     129  std::string            fragmentShaderFile;
     130  std::string            vertexShaderFile;
    69131
    70    GLhandleARB            shaderProgram;
     132  GLhandleARB            shaderProgram;
    71133
    72    GLhandleARB            vertexShader;
    73    GLhandleARB            fragmentShader;
     134  GLhandleARB            vertexShader;
     135  GLhandleARB            fragmentShader;
    74136
    75137
    76    static Shader*         storedShader;
     138  static Shader*         storedShader;
    77139};
    78140
Note: See TracChangeset for help on using the changeset viewer.