Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Sep 24, 2006, 10:30:13 PM (19 years ago)
Author:
bensch
Message:

try with the shader

File:
1 copied

Legend:

Unmodified
Added
Removed
  • branches/new_class_id/src/lib/graphics/shader_data.h

    r9803 r9806  
    11/*!
    2  * @file shader.h
     2 * @file shader_data.h
    33 * @brief Definition of the Shader rendering class
    44*/
    55
    6 #ifndef _SHADER_H
    7 #define _SHADER_H
     6#ifndef _SHADER_DATA_H
     7#define _SHADER_DATA_H
    88
    99#include "base_object.h"
    10 #include "glincl.h"
     10
     11#include "shader_types.h"
    1112#include <vector>
    1213
     
    1617
    1718
    18 //! A class for ...
    19 class Shader : public BaseObject
     19//! The ShaderData is a Class-wrapper around the OpenGL Shader Language (GLSL).
     20class ShaderData : public BaseObject
    2021{
    21   ObjectListDeclaration(Shader);
     22  ObjectListDeclaration(ShaderData);
    2223public:
    23   class Uniform
    24   {
    25   public:
    26     Uniform(const Shader* shader, const std::string& location) { this->uniform = glGetUniformLocationARB(shader->getProgram(), location.c_str()) ; }
    27     Uniform(const Shader& shader, const std::string& location) { this->uniform = glGetUniformLocation(shader.getProgram(), location.c_str()) ; };
    28     Uniform(GLhandleARB shaderProgram, const std::string& location) { this->uniform = glGetUniformLocation(shaderProgram, location.c_str()) ; };
     24  ShaderData(const std::string& vertexShaderFile = "", const std::string& fragmentShaderFile = "");
     25  virtual ~ShaderData();
    2926
    30     void set(float v0) const { glUniform1f(this->uniform, v0); }
    31     void set(float v0, float v1) const { glUniform2f(this->uniform, v0, v1); }
    32     void set(float v0, float v1, float v2) const { glUniform3f(this->uniform, v0, v1, v2); }
    33     void set(float v0, float v1, float v2, float v3) const { glUniform4f(this->uniform, v0, v1, v2, v3); }
     27  Shaders::Uniform getUniform(const std::string& location) { return Shader::Uniform(this, location); }
    3428
    35     void set(int v0) const { glUniform1i(this->uniform, v0); }
    36     void set(int v0, int v1) const { glUniform2i(this->uniform, v0, v1); }
    37     void set(int v0, int v1, int v2) const { glUniform3i(this->uniform, v0, v1, v2); }
    38     void set(int v0, int v1, int v2, int v3) const { glUniform4i(this->uniform, v0, v1, v2, v3); }
    39 
    40     void setV(unsigned int count, float* vv) const
    41     {
    42       switch (count)
    43       {
    44         case 1:
    45         glUniform1fv(this->uniform, 1, vv);
    46         break;
    47         case 2:
    48         glUniform2fv(this->uniform, 2, vv);
    49         break;
    50         case 3:
    51         glUniform3fv(this->uniform, 3, vv);
    52         break;
    53         case 4:
    54         glUniform4fv(this->uniform, 4, vv);
    55         break;
    56       }
    57     }
    58     void setV(unsigned int count, int* vv) const
    59     {
    60       switch (count)
    61       {
    62         case 1:
    63         glUniform1iv(this->uniform, 1, vv);
    64         break;
    65         case 2:
    66         glUniform2iv(this->uniform, 2, vv);
    67         break;
    68         case 3:
    69         glUniform3iv(this->uniform, 3, vv);
    70         break;
    71         case 4:
    72         glUniform4iv(this->uniform, 4, vv);
    73         break;
    74       }
    75     }
    76   private:
    77     GLint uniform;
    78   };
    79 
    80   typedef enum
    81   {
    82     None       = 0,
    83     Fragment   = 1,
    84     Vertex     = 2,
    85 
    86     Program    = 4,
    87   }
    88   Type;
    89 
    90 public:
    91   Shader(const std::string& vertexShaderFile = "", const std::string& fragmentShaderFile = "");
    92   virtual ~Shader();
    93   static Shader* getShader(const std::string& vertexShaderFile, const std::string& fragmentShaderFile);
    94   static bool unload(Shader* shader);
    95 
    96 
    97   static bool checkShaderAbility();
    98   void activateShader();
    99   void bindShader(const char* name, const float* value, size_t size);
    100   static void deactivateShader();
    101 
    102 Shader::Uniform getUniform(const std::string& location) { return Shader::Uniform(this, location); }
    103 
    104   bool loadShaderProgramm(Shader::Type type, const std::string& fileName);
    105   void deleteProgram(Shader::Type type);
    106 
    107   void linkShaderProgram();
    108 
    109 
    110   bool readShader(const std::string& fileName, std::string& output);
    111 
    112 
    113 inline static bool shaderActive() { return (Shader::storedShader != NULL)? true : false; };
    114   inline static Shader* getActiveShader() { return Shader::storedShader; };
    115   inline static void suspendShader() { Shader* currShader = storedShader; if (storedShader!= NULL) { Shader::deactivateShader(); Shader::storedShader = currShader;} };
    116   inline static void restoreShader() { if (storedShader != NULL) storedShader->activateShader(); storedShader = NULL; };
    117 
    118 
    119 
    120 
    121 GLhandleARB getProgram() const { return this->shaderProgram; }
     29  GLhandleARB getProgram() const { return this->shaderProgram; }
    12230  GLhandleARB getVertexS() const { return this->vertexShader; }
    12331  GLhandleARB getFragmentS() const { return this->fragmentShader; }
    12432
     33  void activateShader();
     34
    12535  void debug() const;
    126 
    127   static void printError(GLhandleARB program);
    128 
     36private:
     37  void bindShader(const char* name, const float* value, size_t size);
     38  void linkShaderProgram();
     39  bool readShader(const std::string& fileName, std::string& output);
     40  bool loadShaderProgramm(Shader::Type type, const std::string& fileName);
     41  void deleteProgram(Shader::Type type);
    12942
    13043private:
     
    13649  GLhandleARB            vertexShader;
    13750  GLhandleARB            fragmentShader;
    138 
    139 
    140   static Shader*         storedShader;
    14151};
    14252
    143 #endif /* _SHADER_H */
     53#endif /* _SHADER_DATA_H */
Note: See TracChangeset for help on using the changeset viewer.