- Timestamp:
- Oct 8, 2005, 5:27:22 PM (19 years ago)
- Location:
- trunk/src
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/lib/graphics/shader.cc
r5322 r5323 23 23 #include "debug.h" 24 24 #include "array.h" 25 26 #include "resource_manager.h" 25 27 26 28 … … 102 104 } 103 105 106 Shader* Shader::getShader(const char* vertexShaderFile, const char* fragmentShaderFile) 107 { 108 return (Shader*)ResourceManager::getInstance()->load(vertexShaderFile, SHADER, RP_LEVEL, (void*)fragmentShaderFile); 109 } 110 111 bool Shader::unload(Shader* shader) 112 { 113 return ResourceManager::getInstance()->unload(shader); 114 } 115 104 116 Shader* Shader::storedShader = NULL; 105 117 -
trunk/src/lib/graphics/shader.h
r5319 r5323 26 26 class Shader : public BaseObject { 27 27 28 public:28 public: 29 29 Shader(const char* vertexShaderFile = NULL, const char* fragmentShaderFile = NULL); 30 30 virtual ~Shader(); 31 static Shader* getShader(const char* vertexShaderFile, const char* fragmentShaderFile); 32 static bool unload(Shader* shader); 31 33 32 34 bool loadShaderProgramm(SHADER_TYPE type, const char* fileName); … … 41 43 42 44 inline static bool shaderActive() { return (Shader::storedShader != NULL)?true:false; }; 45 inline static Shader* getActiveShader() { return Shader::storedShader; }; 43 46 inline static void suspendShader() { Shader* currShader = storedShader; if (storedShader!= NULL) { Shader::deactivateShader(); Shader::storedShader = currShader;} }; 44 47 inline static void restoreShader() { if (storedShader != NULL) storedShader->activateShader(); storedShader = NULL; }; -
trunk/src/util/resource_manager.cc
r5308 r5323 36 36 #include "ogg_player.h" 37 37 #endif /* NO_AUDIO */ 38 #ifndef NO_SHADERS 39 #include "shader.h" 40 #endif /* NO_SHADERS */ 38 41 39 42 #include "list.h" … … 190 193 #ifndef NO_MODEL 191 194 #define __IF_OK 192 if (!strnc mp(fileName+(strlen(fileName)-4), ".obj", 4))195 if (!strncasecmp(fileName+(strlen(fileName)-4), ".obj", 4)) 193 196 tmpType = OBJ; 194 197 else if (!strncmp(fileName+(strlen(fileName)-4), ".md2", 4)) 195 198 tmpType = MD2; 196 else if (!strc mp(fileName, "cube") ||197 !strc mp(fileName, "sphere") ||198 !strc mp(fileName, "plane") ||199 !strc mp(fileName, "cylinder") ||200 !strc mp(fileName, "cone"))199 else if (!strcasecmp(fileName, "cube") || 200 !strcasecmp(fileName, "sphere") || 201 !strcasecmp(fileName, "plane") || 202 !strcasecmp(fileName, "cylinder") || 203 !strcasecmp(fileName, "cone")) 201 204 tmpType = PRIM; 202 205 #endif /* NO_MODEL */ … … 206 209 #endif 207 210 #define __IF_OK 208 if (!strnc mp(fileName+(strlen(fileName)-4), ".wav", 4))211 if (!strncasecmp(fileName+(strlen(fileName)-4), ".wav", 4)) 209 212 tmpType = WAV; 210 else if (!strnc mp(fileName+(strlen(fileName)-4), ".mp3", 4))213 else if (!strncasecmp(fileName+(strlen(fileName)-4), ".mp3", 4)) 211 214 tmpType = MP3; 212 else if (!strnc mp(fileName+(strlen(fileName)-4), ".ogg", 4))215 else if (!strncasecmp(fileName+(strlen(fileName)-4), ".ogg", 4)) 213 216 tmpType = OGG; 214 217 #endif /* NO_AUDIO */ … … 218 221 #endif 219 222 #define __IF_OK 220 if (!strnc mp(fileName+(strlen(fileName)-4), ".ttf", 4))223 if (!strncasecmp(fileName+(strlen(fileName)-4), ".ttf", 4)) 221 224 tmpType = TTF; 222 225 #endif /* NO_TEXT */ 226 #ifndef NO_SHADERS 227 #ifdef __IF_OK 228 else 229 #endif 230 #define __IF_OK 231 if (!strncasecmp(fileName+(strlen(fileName)-5), ".vert", 5)) 232 tmpType = SHADER; 233 #endif /* NO_SHADERS */ 223 234 #ifndef NO_TEXTURES 224 235 #ifdef __IF_OK … … 308 319 if (param1 != NULL) 309 320 { 310 tmpResource->s kinFileName = new char[strlen((const char*)param1)+1];311 strcpy(tmpResource->s kinFileName, (const char*) param1);321 tmpResource->secFileName = new char[strlen((const char*)param1)+1]; 322 strcpy(tmpResource->secFileName, (const char*) param1); 312 323 } 313 324 else 314 tmpResource->s kinFileName = NULL;315 tmpResource->pointer = new MD2Data(fullName, tmpResource->s kinFileName);325 tmpResource->secFileName = NULL; 326 tmpResource->pointer = new MD2Data(fullName, tmpResource->secFileName); 316 327 } 317 328 break; … … 372 383 break; 373 384 #endif /* NO_TEXTURES */ 385 #ifndef NO_SHADERS 386 case SHADER: 387 if(ResourceManager::isFile(fullName)) 388 { 389 char* secFullName = NULL; 390 if (param1 != NULL) 391 { 392 secFullName = ResourceManager::getFullName((const char*)param1); 393 printf("%s\n", secFullName); 394 if (ResourceManager::isFile(secFullName)) 395 { 396 printf("ok:: %s\n", secFullName); 397 tmpResource->secFileName = new char[strlen((const char*)param1)+1]; 398 strcpy(tmpResource->secFileName, (const char*) param1); 399 } 400 else 401 { 402 delete[] secFullName; 403 secFullName = NULL; 404 tmpResource->secFileName = NULL; 405 } 406 } 407 else 408 tmpResource->secFileName = NULL; 409 printf("%s::%s\n", fullName, secFullName); 410 tmpResource->pointer = new Shader(fullName, secFullName); 411 if (secFullName != NULL) 412 delete[] secFullName; 413 } 414 break; 415 #endif /* NO_SHADERS */ 374 416 default: 375 417 tmpResource->pointer = NULL; … … 458 500 break; 459 501 #endif /* NO_TEXTURES */ 502 #ifndef NO_SHADERS 503 case SHADER: 504 delete (Shader*)resource->pointer; 505 break; 506 #endif /* NO_SHADERS */ 460 507 default: 461 508 PRINTF(2)("NOT YET IMPLEMENTED !!FIX FIX!!\n"); … … 537 584 if (!param1) 538 585 { 539 if (enumRes->s kinFileName == NULL)586 if (enumRes->secFileName == NULL) 540 587 match = true; 541 588 } 542 else if (!strcmp(enumRes->s kinFileName, (const char*)param1))589 else if (!strcmp(enumRes->secFileName, (const char*)param1)) 543 590 match = true; 544 591 break; … … 555 602 break; 556 603 #endif /* NO_TEXT */ 604 #ifndef NO_SHADERS 605 case SHADER: 606 if (!param1) 607 { 608 if (enumRes->secFileName == NULL) 609 match = true; 610 } 611 else if (!strcmp(enumRes->secFileName, (const char*)param1)) 612 match = true; 613 #endif /* NO_SHADERS */ 557 614 default: 558 615 match = true; … … 862 919 break; 863 920 #endif 921 #ifndef NO_SHADERS 922 case SHADER: 923 return "Shader"; 924 break; 925 #endif 864 926 default: 865 927 return "unknown Format"; -
trunk/src/util/resource_manager.h
r5308 r5323 43 43 #endif /* NO_AUDIO */ 44 44 #ifndef NO_TEXTURES 45 IMAGE 45 IMAGE, //!< loading an image 46 46 #endif /* NO_TEXTURES */ 47 #ifndef NO_SHADERS 48 SHADER, //!< openGL-shader program 49 #endif /* NO_SHADERS */ 47 50 }; 48 51 … … 75 78 float modelSize; //!< the size of the model (OBJ/PRIM) 76 79 #ifndef NO_MODEL 77 char* s kinFileName; //!< skinFileName (MD2)80 char* secFileName; //!< a seconf fileName 78 81 #endif /* NO_MODEL */ 79 82 #ifndef NO_TEXT -
trunk/src/world_entities/npc2.cc
r5313 r5323 32 32 33 33 this->loadModelWithScale("models/ships/bolido.obj", 3); 34 this->shader = new Shader("toon.vert", "toon.frag"); 35 this->shader->activateShader(); 36 //exit(-1); 34 this->shader = Shader::getShader("toon.vert", "toon.frag"); 37 35 38 36 this->obj = gluNewQuadric(); … … 44 42 NPC2::~NPC2 () 45 43 { 46 delete this->shader;44 Shader::unload(this->shader); 47 45 gluDeleteQuadric(this->obj); 48 49 46 } 50 47 … … 87 84 glMultMatrixf((float*)matrix); 88 85 89 shader->activateShader(); 86 if (this->shader != NULL && this->shader != Shader::getActiveShader()) 87 { 88 shader->activateShader(); 89 } 90 90 gluSphere(this->obj, 3, 10, 10); 91 91 //shader->deactivateShader();
Note: See TracChangeset
for help on using the changeset viewer.