- Timestamp:
- Sep 26, 2005, 11:33:55 PM (19 years ago)
- Location:
- trunk/src/lib
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/lib/graphics/graphics_engine.cc
r5261 r5262 31 31 32 32 33 #include "shader.h" 34 33 35 /** 34 36 * standard constructor 35 @todo this constructor is not jet implemented - do it 36 */ 37 */ 37 38 GraphicsEngine::GraphicsEngine () 38 39 { … … 60 61 this->hwVersion = NULL; 61 62 this->hwExtensions = NULL; 63 64 Shader shader("test.txt"); 65 shader.debug(); 66 exit(-1); 62 67 } 63 68 -
trunk/src/lib/graphics/shader.cc
r5261 r5262 18 18 #include "shader.h" 19 19 20 #include "array.h" 21 #include "stdlibincl.h" 22 #include <stdio.h> 23 #include "debug.h" 24 25 26 #ifndef PARSELINELENGHT 27 #define PARSELINELENGHT 512 //!< how many chars to read at once 28 #endif 29 20 30 using namespace std; 21 31 … … 24 34 * standard constructor 25 35 */ 26 Shader::Shader ( SHADER_TYPE type, ...)36 Shader::Shader (const char* vertexShaderFile, const char* fragmentShaderFile) 27 37 { 28 38 this->setClassID(CL_SHADER, "Shader"); … … 35 45 this->vertexShader = 0; 36 46 this->fragmentShader = 0; 47 48 if (vertexShaderFile != NULL) 49 this->loadShaderProgramm(SHADER_VERTEX, vertexShaderFile); 50 if (fragmentShaderFile != NULL) 51 this->loadShaderProgramm(SHADER_FRAGMENT, fragmentShaderFile); 37 52 } 38 53 … … 44 59 { 45 60 // delete what has to be deleted here 46 delete[] this->fragmentShaderFile; 47 delete[] this->vertexShaderFile; 48 delete[] this->fragmentShaderSource; 49 delete[] this->vertexShaderSource; 50 61 this->deleteProgram(SHADER_VERTEX); 62 this->deleteProgram(SHADER_FRAGMENT); 51 63 // DELETE THE PROGRAMS 52 64 /* this->shaderProgram = 0; … … 58 70 bool Shader::loadShaderProgramm(SHADER_TYPE type, const char* fileName) 59 71 { 60 if (type != SHADER_VERTEX ||type != SHADER_FRAGMENT)72 if (type != SHADER_VERTEX && type != SHADER_FRAGMENT) 61 73 return false; 74 this->deleteProgram(type); 75 76 FILE* stream; //< The stream we use to read the file. 77 78 if( (stream = fopen (fileName, "r")) == NULL) 79 { 80 PRINTF(1)("Shader could not open %s\n", fileName); 81 return false; 82 } 83 Array<char*>* program = new Array<char*>; 84 if (type == SHADER_VERTEX) 85 { 86 this->vertexShaderFile = new char[strlen(fileName)+1]; 87 strcpy(this->vertexShaderFile, fileName); 88 this->vertexShaderSource = program; 89 } 90 else 91 { 92 this->fragmentShaderFile = new char[strlen(fileName)+1]; 93 strcpy(this->fragmentShaderFile, fileName); 94 this->fragmentShaderSource = program; 95 } 96 97 char lineBuffer[PARSELINELENGHT]; 98 char* addString; 99 while( !feof( stream)) 100 { 101 // get next line 102 fgets (lineBuffer, PARSELINELENGHT, stream); 103 if (strchr(lineBuffer, '\n')) 104 { 105 addString = new char[strlen(lineBuffer)]; 106 strncpy(addString, lineBuffer, strlen (lineBuffer)-1); 107 addString[strlen(lineBuffer)-1] ='\0'; 108 } 109 else 110 { 111 addString = new char[strlen(lineBuffer)+1]; 112 strcpy(addString, lineBuffer); 113 } 114 program->addEntry(addString); 115 116 printf(lineBuffer); 117 } 118 fclose(stream); 119 120 program->finalizeArray(); 62 121 63 122 123 // this->shaderProgram = glCreateProgramObjectARB(); 124 this->vertexShader =1; 64 125 } 65 126 … … 68 129 69 130 } 131 132 133 void Shader::deleteProgram(SHADER_TYPE type) 134 { 135 Array<char*>* deleteArray = NULL; 136 if (type == SHADER_VERTEX) 137 { 138 deleteArray = this->vertexShaderSource; 139 this->vertexShaderSource = NULL; 140 delete[] this->vertexShaderFile; 141 this->vertexShaderFile = NULL; 142 } 143 else if (type == SHADER_FRAGMENT) 144 { 145 deleteArray = this->fragmentShaderSource; 146 this->fragmentShaderSource = NULL; 147 delete[] this->fragmentShaderFile; 148 this->fragmentShaderFile = NULL; 149 } 150 else 151 return; 152 153 if (deleteArray == NULL) 154 return; 155 else 156 { 157 deleteArray->finalizeArray(); 158 for (unsigned int i = 0; i < deleteArray->getCount(); i++) 159 { 160 delete[] deleteArray->getEntry(i); 161 } 162 delete deleteArray; 163 } 164 } 165 166 void Shader::debug() const 167 { 168 PRINT(3)("Shader info: (SHADER: %d)\n", this->shaderProgram); 169 if (this->vertexShader != 0) 170 { 171 PRINT(3)("VertexShaderProgramm: number=%d, file='%s'\n", this->vertexShader, this->vertexShaderFile); 172 if (this->vertexShaderSource != NULL) 173 for (unsigned int i = 0; i < this->vertexShaderSource->getCount(); i++) 174 PRINT(3)("%d: %s\n", i, this->vertexShaderSource->getEntry(i)); 175 } 176 if (this->fragmentShader != 0) 177 { 178 PRINT(3)("FragmentShaderProgramm: number=%d, file='%s'\n", this->fragmentShader, this->fragmentShaderFile); 179 if (this->fragmentShaderSource != NULL) 180 for (unsigned int i = 0; i < this->fragmentShaderSource->getCount(); i++) 181 PRINT(3)("%d: %s\n", i, this->fragmentShaderSource->getEntry(i)); 182 } 183 184 185 } 186 -
trunk/src/lib/graphics/shader.h
r5261 r5262 20 20 21 21 // FORWARD DECLARATION 22 22 template<class T> class Array; 23 23 24 24 … … 27 27 28 28 public: 29 Shader( SHADER_TYPE type, ...);29 Shader(const char* vertexShaderFile = NULL, const char* fragmentShaderFile = NULL); 30 30 virtual ~Shader(); 31 31 32 32 bool loadShaderProgramm(SHADER_TYPE type, const char* fileName); 33 33 bool activateShader(); 34 void deleteProgram(SHADER_TYPE type); 35 36 void debug() const; 37 38 private: 34 39 35 40 private: 36 41 char* fragmentShaderFile; 37 42 char* vertexShaderFile; 38 char*fragmentShaderSource;39 char*vertexShaderSource;43 Array<char*>* fragmentShaderSource; 44 Array<char*>* vertexShaderSource; 40 45 GLenum shaderProgram; 41 46 GLenum vertexShader; -
trunk/src/lib/util/array.h
r5100 r5262 15 15 16 16 /*! 17 \file array.h18 \brief Contains the Array Class that handles arrays of classes.17 @file array.h 18 @brief Contains the Array Class that handles arrays of classes. 19 19 this class creates a Array of a semi-Dynamic length. 20 20 beware, that after finalizing the array may not be resized again. … … 90 90 { 91 91 PRINTF(5)("deleting array\n"); 92 Entry* walker = this->firstEntry; 93 Entry* previous; 94 while (walker) 92 if (!this->finalized) 95 93 { 96 previous = walker; 97 walker = walker->next; 98 delete previous; 94 Entry* walker = this->firstEntry; 95 Entry* previous; 96 while (walker) 97 { 98 previous = walker; 99 walker = walker->next; 100 delete previous; 101 } 99 102 } 100 if ( finalized)103 if (this->finalized) 101 104 delete[] this->array; 102 105 } … … 109 112 void Array<T>::finalizeArray () 110 113 { 114 if (this->finalized) 115 return; 111 116 PRINTF(5)("Finalizing array. Length: %i\n", entryCount); 112 117 if (!(this->array = new T [this->entryCount])) 113 118 PRINTF(1)("could not allocate %i data Blocks\n", this->entryCount); 114 119 Entry* walker = this->firstEntry; 115 for (int i=0; i <this->entryCount; i++)120 for (int i=0; i < this->entryCount; i++) 116 121 { 117 122 this->array[i] = walker->value;
Note: See TracChangeset
for help on using the changeset viewer.