Changeset 9806 in orxonox.OLD for branches/new_class_id/src/lib/graphics/shader.h
- Timestamp:
- Sep 24, 2006, 10:30:13 PM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/new_class_id/src/lib/graphics/shader.h
r9715 r9806 16 16 17 17 18 //! A class for ...18 //! The Shader is a Class-wrapper around the OpenGL Shader Language (GLSL). 19 19 class Shader : public BaseObject 20 20 { … … 38 38 void set(int v0, int v1, int v2, int v3) const { glUniform4i(this->uniform, v0, v1, v2, v3); } 39 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 } 40 void setV(unsigned int count, float* vv) const; 41 void setV(unsigned int count, int* vv) const; 42 76 43 private: 77 44 GLint uniform; 78 45 }; 79 46 47 //! The Type of Shader. 80 48 typedef enum 81 49 { 82 None = 0, 83 Fragment = 1, 84 Vertex = 2, 85 86 Program = 4, 87 } 88 Type; 50 None = 0, //!< No Type at all 51 Fragment = 1, //!< Fragment Shader. 52 Vertex = 2, //!< Vertex Shader. 53 Program = 4, //!< Compiled Shader Programm. 54 } Type; 89 55 90 56 public: 91 57 Shader(const std::string& vertexShaderFile = "", const std::string& fragmentShaderFile = ""); 92 58 virtual ~Shader(); 93 static Shader* getShader(const std::string& vertexShaderFile, const std::string& fragmentShaderFile);94 static bool unload(Shader* shader);95 59 60 61 Shader::Uniform getUniform(const std::string& location) { return Shader::Uniform(this, location); } 62 63 GLhandleARB getProgram() const { return this->shaderProgram; } 64 GLhandleARB getVertexS() const { return this->vertexShader; } 65 GLhandleARB getFragmentS() const { return this->fragmentShader; } 96 66 97 67 static bool checkShaderAbility(); 98 68 void activateShader(); 99 void bindShader(const char* name, const float* value, size_t size);100 69 static void deactivateShader(); 101 70 102 Shader::Uniform getUniform(const std::string& location) { return Shader::Uniform(this, location); } 71 void debug() const; 103 72 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; }; 73 inline static bool isShaderActive() { return (Shader::storedShader != NULL) ? true : false; }; 114 74 inline static Shader* getActiveShader() { return Shader::storedShader; }; 115 75 inline static void suspendShader() { Shader* currShader = storedShader; if (storedShader!= NULL) { Shader::deactivateShader(); Shader::storedShader = currShader;} }; 116 76 inline static void restoreShader() { if (storedShader != NULL) storedShader->activateShader(); storedShader = NULL; }; 117 77 118 119 120 121 GLhandleARB getProgram() const { return this->shaderProgram; }122 GLhandleARB getVertexS() const { return this->vertexShader; }123 GLhandleARB getFragmentS() const { return this->fragmentShader; }124 125 void debug() const;126 127 78 static void printError(GLhandleARB program); 128 79 80 private: 81 void bindShader(const char* name, const float* value, size_t size); 82 void linkShaderProgram(); 83 bool readShader(const std::string& fileName, std::string& output); 84 bool loadShaderProgramm(Shader::Type type, const std::string& fileName); 85 void deleteProgram(Shader::Type type); 129 86 130 87 private:
Note: See TracChangeset
for help on using the changeset viewer.