- Timestamp:
- Oct 8, 2005, 1:08:09 PM (19 years ago)
- Location:
- trunk/src
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/lib/graphics/graphics_engine.cc
r5286 r5318 24 24 #include "debug.h" 25 25 #include "text_engine.h" 26 26 #include "shader.h" 27 27 #include "ini_parser.h" 28 28 #include "substring.h" 29 29 30 30 31 using namespace std; … … 544 545 { 545 546 GraphicsEngine::storeMatrices(); 547 Shader::suspendShader(); 546 548 Render2D::getInstance()->draw(E2D_ALL_LAYERS); 549 Shader::restoreShader(); 547 550 LightManager::getInstance()->draw(); 548 551 } -
trunk/src/lib/graphics/render2D/render_2d.cc
r5317 r5318 23 23 #include "element_2d.h" 24 24 25 #include "shader.h"26 27 25 #include <math.h> 28 26 29 27 using namespace std; 30 31 32 28 33 29 /** … … 126 122 void Render2D::draw(unsigned int layer) const 127 123 { 128 Shader::suspendShader();129 130 124 GraphicsEngine::enter2DMode(); 131 125 … … 149 143 } 150 144 GraphicsEngine::leave2DMode(); 151 152 Shader::restoreShader();153 145 } -
trunk/src/lib/graphics/shader.cc
r5317 r5318 22 22 #include <stdio.h> 23 23 #include "debug.h" 24 #include "array.h" 24 25 25 26 … … 66 67 /** 67 68 * standard deconstructor 68 */69 */ 69 70 Shader::~Shader () 70 71 { 72 if (storedShader == this) 73 Shader::deactivateShader(); 74 71 75 // delete what has to be deleted here 72 76 this->deleteProgram(SHADER_VERTEX); … … 79 83 if (this->shaderProgram != 0) 80 84 glDeleteObjectARB(this->shaderProgram); 85 81 86 } 82 87 … … 93 98 94 99 95 const char* program = fileRead(fileName);100 Array<char*>* program = fileReadArray(fileName); 96 101 if (program == NULL) 97 102 return false; 103 98 104 if (type == SHADER_VERTEX && GLEW_ARB_vertex_shader) 99 105 { … … 114 120 if (shader != 0) 115 121 { 116 glShaderSourceARB(shader, 1, (const GLcharARB**)&program, NULL); 117 try { 122 glShaderSourceARB(shader, program->getCount(), (const GLcharARB**)program->getArray(), NULL); 118 123 glCompileShaderARB(shader); 119 }120 catch (...)121 {122 124 this->printError(shader); 123 }124 125 glAttachObjectARB(this->shaderProgram, shader); 125 delete[] program;126 126 } 127 delete program; 127 128 } 128 129 … … 153 154 } 154 155 156 157 Array<char*>* Shader::fileReadArray(const char* fileName) 158 { 159 FILE* stream; //< The stream we use to read the file. 160 161 if( (stream = fopen (fileName, "rt")) == NULL) 162 { 163 PRINTF(1)("Shader could not open %s\n", fileName); 164 return NULL; 165 } 166 Array<char*>* file = new Array<char*>; 167 168 char lineBuffer[PARSELINELENGHT]; 169 char* addString; 170 while(fgets (lineBuffer, PARSELINELENGHT, stream) != NULL) 171 { 172 addString = new char[strlen(lineBuffer)+1]; 173 strcpy(addString, lineBuffer); 174 file->addEntry(addString); 175 } 176 fclose(stream); 177 file->finalizeArray(); 178 return file; 179 } 180 181 182 155 183 void Shader::activateShader() 156 184 { -
trunk/src/lib/graphics/shader.h
r5317 r5318 10 10 #include "glincl.h" 11 11 12 template<class T> class Array; 12 13 13 14 typedef enum … … 35 36 36 37 char* fileRead(const char* fileName); 38 Array<char*>* fileReadArray(const char* fileName); 37 39 38 40 static bool checkShaderAbility(); 39 41 40 42 inline static bool shaderActive() { return (Shader::storedShader != NULL)?true:false; }; 41 inline static void suspendShader() { Shader* currShader =storedShader; if (currShader!= NULL) { Shader::deactivateShader(); Shader::storedShader = currShader;} };43 inline static void suspendShader() { Shader* currShader = storedShader; if (storedShader!= NULL) { Shader::deactivateShader(); Shader::storedShader = currShader;} }; 42 44 inline static void restoreShader() { if (storedShader != NULL) storedShader->activateShader(); storedShader = NULL; }; 43 45 -
trunk/src/story_entities/world.cc
r5298 r5318 74 74 #include "npc.h" 75 75 #include "npc2.h" 76 #include "shader.h" 76 77 77 78 SHELL_COMMAND(speed, World, setSpeed); … … 143 144 // erease everything that is left. 144 145 delete NullParent::getInstance(); 146 Shader::suspendShader(); 145 147 146 148 // unload the resources !!
Note: See TracChangeset
for help on using the changeset viewer.