- Timestamp:
- May 24, 2006, 5:38:28 PM (19 years ago)
- Location:
- branches/water/src/lib/graphics
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/water/src/lib/graphics/shader.cc
r7221 r7818 40 40 this->setClassID(CL_SHADER, "Shader"); 41 41 42 this->fragmentShaderFile = "";43 this->vertexShaderFile = "";44 42 this->shaderProgram = 0; 45 43 this->vertexShader = 0; … … 48 46 if (GLEW_ARB_shader_objects && GLEW_ARB_shading_language_100) 49 47 { 50 GLint status = 0;51 52 48 this->shaderProgram = glCreateProgramObjectARB(); 53 49 54 50 if (!vertexShaderFile.empty()) 55 this->loadShaderProgramm(S HADER_VERTEX, vertexShaderFile);51 this->loadShaderProgramm(Shader::Vertex, vertexShaderFile); 56 52 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 63 57 } 64 58 else … … 78 72 79 73 // delete what has to be deleted here 80 this->deleteProgram(S HADER_VERTEX);81 this->deleteProgram(S HADER_FRAGMENT);74 this->deleteProgram(Shader::Vertex); 75 this->deleteProgram(Shader::Fragment); 82 76 83 77 if (this->fragmentShader != 0) … … 116 110 117 111 118 bool Shader::loadShaderProgramm(S HADER_TYPEtype, const std::string& fileName)112 bool Shader::loadShaderProgramm(Shader::Type type, const std::string& fileName) 119 113 { 120 114 GLhandleARB shader = 0; 121 115 122 if (type != S HADER_VERTEX && type != SHADER_FRAGMENT)116 if (type != Shader::Vertex && type != Shader::Fragment) 123 117 return false; 124 118 this->deleteProgram(type); … … 127 121 std::vector<char*>* program = fileReadArray(fileName); 128 122 129 if (type == S HADER_VERTEX&& GLEW_ARB_vertex_shader)123 if (type == Shader::Vertex && GLEW_ARB_vertex_shader) 130 124 { 131 125 this->vertexShaderFile = fileName; … … 134 128 } 135 129 136 if (type == S HADER_FRAGMENT&& GLEW_ARB_fragment_shader)130 if (type == Shader::Fragment && GLEW_ARB_fragment_shader) 137 131 { 138 132 this->fragmentShaderFile = fileName; … … 158 152 delete program; 159 153 } 154 155 156 void 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 160 167 161 168 char* Shader::fileRead(const std::string& fileName) … … 228 235 229 236 230 void Shader::deleteProgram(S HADER_TYPEtype)237 void Shader::deleteProgram(Shader::Type type) 231 238 { 232 239 GLint status = 0; 233 if (type == S HADER_VERTEX&& this->vertexShader != 0)240 if (type == Shader::Vertex && this->vertexShader != 0) 234 241 { 235 242 this->vertexShaderFile = ""; … … 241 248 this->vertexShader = 0; 242 249 } 243 else if (type == S HADER_FRAGMENT&& this->fragmentShader != 0)250 else if (type == Shader::Fragment && this->fragmentShader != 0) 244 251 { 245 252 this->fragmentShaderFile = ""; -
branches/water/src/lib/graphics/shader.h
r7785 r7818 12 12 13 13 14 typedef enum15 {16 SHADER_NONE = 0,17 SHADER_FRAGMENT = 1,18 SHADER_VERTEX = 0,19 20 } SHADER_TYPE;21 22 14 // FORWARD DECLARATION 23 15 24 16 25 17 //! A class for ... 26 class Shader : public BaseObject { 18 class 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; 27 29 28 30 public: … … 32 34 static bool unload(Shader* shader); 33 35 34 bool loadShaderProgramm(SHADER_TYPE type, const std::string& fileName); 36 37 static bool checkShaderAbility(); 35 38 void activateShader(); 36 39 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 38 47 39 48 char* fileRead(const std::string& fileName); 40 49 std::vector<char*>* fileReadArray(const std::string& fileName); 41 50 42 static bool checkShaderAbility();43 51 44 52 inline static bool shaderActive() { return (Shader::storedShader != NULL)? true : false; }; … … 47 55 inline static void restoreShader() { if (storedShader != NULL) storedShader->activateShader(); storedShader = NULL; }; 48 56 49 GLhandleARB getProgram() { return this->shaderProgram; }50 GLhandleARB getVertexS() { return this->vertexShader; }51 GLhandleARB getFragmentS() { return this->fragmentShader; }52 57 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 54 62 void debug() const; 55 63 56 private: 64 static void printError(GLhandleARB program); 65 57 66 58 67 private: 59 68 std::string fragmentShaderFile; 60 69 std::string vertexShaderFile; 70 61 71 GLhandleARB shaderProgram; 72 62 73 GLhandleARB vertexShader; 63 74 GLhandleARB fragmentShader;
Note: See TracChangeset
for help on using the changeset viewer.