Changeset 9806 in orxonox.OLD for branches/new_class_id/src/lib/graphics/shader_data.cc
- Timestamp:
- Sep 24, 2006, 10:30:13 PM (18 years ago)
- File:
-
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
branches/new_class_id/src/lib/graphics/shader_data.cc
r9803 r9806 16 16 //#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_ 17 17 18 #include "shader .h"18 #include "shader_data.h" 19 19 20 20 #include "stdlibincl.h" … … 33 33 34 34 35 ObjectListDefinition(Shader );35 ObjectListDefinition(ShaderData); 36 36 37 37 /** … … 41 41 { 42 42 this->registerObject(this, Shader::_objectList); 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 43 this->shaderProgram = 0; 44 this->vertexShader = 0; 45 this->fragmentShader = 0; 46 47 if (GLEW_ARB_shader_objects && GLEW_ARB_shading_language_100) 48 { 49 this->shaderProgram = glCreateProgramObjectARB(); 50 51 if (!vertexShaderFile.empty()) 52 this->loadShaderProgramm(Shader::Vertex, vertexShaderFile); 53 if (!fragmentShaderFile.empty()) 54 this->loadShaderProgramm(Shader::Fragment, fragmentShaderFile); 55 56 this->linkShaderProgram(); 57 58 } 59 else 60 { 61 PRINTF(2)("Shaders are not supported on your hardware\n"); 62 } 63 63 } 64 64 … … 91 91 //glLinkProgramARB(this->shaderProgram); 92 92 glDeleteObjectARB(this->shaderProgram); 93 93 // link error checking 94 94 glGetObjectParameterivARB(this->shaderProgram, GL_OBJECT_DELETE_STATUS_ARB, &status); 95 95 if (status == GL_INVALID_VALUE || status == GL_INVALID_OPERATION) 96 96 this->printError(this->shaderProgram); 97 97 } 98 }99 100 Shader* Shader::getShader(const std::string& vertexShaderFile, const std::string& fragmentShaderFile)101 {102 return (Shader*)ResourceManager::getInstance()->load(vertexShaderFile, SHADER, RP_LEVEL, fragmentShaderFile);103 }104 105 bool Shader::unload(Shader* shader)106 {107 return ResourceManager::getInstance()->unload(shader);108 98 } 109 99 … … 161 151 162 152 glLinkProgramARB(this->shaderProgram); 163 153 // link error checking 164 154 glGetObjectParameterivARB(this->shaderProgram, GL_OBJECT_LINK_STATUS_ARB, &status); 165 155 if (status == GL_INVALID_VALUE || status == GL_INVALID_OPERATION) … … 203 193 void Shader::bindShader(const char* name, const float* value, size_t size) 204 194 { 205 if (likely (this->shaderProgram != 0)) { 206 glUseProgramObjectARB(this->shaderProgram); 207 208 unsigned int location = glGetUniformLocationARB(this->shaderProgram, name); 209 /* This is EXPENSIVE and should be avoided. */ 210 211 if (size == 1) glUniform1fvARB(location, 1, value); 212 else if (size == 2) glUniform2fvARB(location, 1, value); 213 else if (size == 3) glUniform3fvARB(location, 1, value); 214 else if (size == 4) glUniform4fvARB(location, 1, value); 215 else if (size == 9) glUniformMatrix3fvARB(location, 1, false, value); 216 else if (size == 16) glUniformMatrix4fvARB(location, 1, false, value); 217 218 } 195 if (likely (this->shaderProgram != 0)) 196 { 197 glUseProgramObjectARB(this->shaderProgram); 198 199 unsigned int location = glGetUniformLocationARB(this->shaderProgram, name); 200 /* This is EXPENSIVE and should be avoided. */ 201 202 if (size == 1) glUniform1fvARB(location, 1, value); 203 else if (size == 2) glUniform2fvARB(location, 1, value); 204 else if (size == 3) glUniform3fvARB(location, 1, value); 205 else if (size == 4) glUniform4fvARB(location, 1, value); 206 else if (size == 9) glUniformMatrix3fvARB(location, 1, false, value); 207 else if (size == 16) glUniformMatrix4fvARB(location, 1, false, value); 208 209 } 219 210 } 220 211 221 212 void Shader::deactivateShader() 222 213 { 223 if (storedShader != NULL)224 glUseProgramObjectARB(0);225 Shader::storedShader = NULL;214 if (storedShader != NULL) 215 glUseProgramObjectARB(0); 216 Shader::storedShader = NULL; 226 217 } 227 218 … … 292 283 if (this->vertexShader != 0) 293 284 { 294 /* PRINT(3)("VertexShaderProgramm: number=%d, file='%s'\n", this->vertexShader, this->vertexShaderFile);295 if (this->vertexShaderSource != NULL)296 for (unsigned int i = 0; i < this->vertexShaderSource->getCount(); i++)297 PRINT(3)("%d: %s\n", i, this->vertexShaderSource->getEntry(i));298 }299 if (this->fragmentShader != 0)300 {301 PRINT(3)("FragmentShaderProgramm: number=%d, file='%s'\n", this->fragmentShader, this->fragmentShaderFile);302 if (this->fragmentShaderSource != NULL)303 for (unsigned int i = 0; i < this->fragmentShaderSource->getCount(); i++)304 PRINT(3)("%d: %s\n", i, this->fragmentShaderSource->getEntry(i));*/305 } 306 } 307 285 /* PRINT(3)("VertexShaderProgramm: number=%d, file='%s'\n", this->vertexShader, this->vertexShaderFile); 286 if (this->vertexShaderSource != NULL) 287 for (unsigned int i = 0; i < this->vertexShaderSource->getCount(); i++) 288 PRINT(3)("%d: %s\n", i, this->vertexShaderSource->getEntry(i)); 289 } 290 if (this->fragmentShader != 0) 291 { 292 PRINT(3)("FragmentShaderProgramm: number=%d, file='%s'\n", this->fragmentShader, this->fragmentShaderFile); 293 if (this->fragmentShaderSource != NULL) 294 for (unsigned int i = 0; i < this->fragmentShaderSource->getCount(); i++) 295 PRINT(3)("%d: %s\n", i, this->fragmentShaderSource->getEntry(i));*/ 296 } 297 } 298
Note: See TracChangeset
for help on using the changeset viewer.