Changeset 5273 in orxonox.OLD for trunk/src/lib
- Timestamp:
- Oct 1, 2005, 10:39:27 PM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/lib/graphics/shader.cc
r5271 r5273 19 19 20 20 #include "stdlibincl.h" 21 #include "compiler.h" 21 22 #include <stdio.h> 22 23 #include "debug.h" … … 44 45 45 46 if (GLEW_ARB_shader_objects && GLEW_ARB_shading_language_100) 46 this->shaderProgram = glCreateProgramObjectARB(); 47 48 if (vertexShaderFile != NULL) 49 this->loadShaderProgramm(SHADER_VERTEX, vertexShaderFile); 50 if (fragmentShaderFile != NULL) 51 this->loadShaderProgramm(SHADER_FRAGMENT, fragmentShaderFile); 52 try { 53 glLinkProgramARB(this->shaderProgram); } 54 catch(GLenum errorCode) { 55 this->printError(this->shaderProgram); } 47 { 48 this->shaderProgram = glCreateProgramObjectARB(); 49 50 if (vertexShaderFile != NULL) 51 this->loadShaderProgramm(SHADER_VERTEX, vertexShaderFile); 52 if (fragmentShaderFile != NULL) 53 this->loadShaderProgramm(SHADER_FRAGMENT, fragmentShaderFile); 54 try { 55 glLinkProgramARB(this->shaderProgram); } 56 catch(GLenum errorCode) { 57 this->printError(this->shaderProgram); } 58 } 59 else 60 { 61 PRINTF(2)("Shaders are not supported on your hardware\n"); 62 } 56 63 } 57 64 … … 66 73 this->deleteProgram(SHADER_FRAGMENT); 67 74 68 glDeleteObjectARB(this->fragmentShader); 69 glDeleteObjectARB(this->vertexShader); 70 glDeleteObjectARB(this->shaderProgram); 75 if (this->fragmentShader != 0) 76 glDeleteObjectARB(this->fragmentShader); 77 if (this->vertexShader != 0) 78 glDeleteObjectARB(this->vertexShader); 79 if (this->shaderProgram != 0) 80 glDeleteObjectARB(this->shaderProgram); 71 81 } 72 82 … … 98 108 shader = this->fragmentShader = glCreateShaderObjectARB(GL_FRAGMENT_SHADER_ARB); 99 109 } 100 glShaderSourceARB(shader, 1, (const GLcharARB**)&program, NULL); 101 try { 102 glCompileShaderARB(shader); 103 } 104 catch (...) 105 { 106 this->printError(shader); 107 } 108 glAttachObjectARB(this->shaderProgram, shader); 109 delete[] program; 110 } 111 110 111 if (shader != 0) 112 { 113 glShaderSourceARB(shader, 1, (const GLcharARB**)&program, NULL); 114 try { 115 glCompileShaderARB(shader); 116 } 117 catch (...) 118 { 119 this->printError(shader); 120 } 121 glAttachObjectARB(this->shaderProgram, shader); 122 delete[] program; 123 } 124 } 112 125 113 126 char* Shader::fileRead(const char* fileName) … … 139 152 void Shader::activateShader() 140 153 { 141 glUseProgramObjectARB(this->shaderProgram); 154 if (likely (this->shaderProgram != 0)) 155 glUseProgramObjectARB(this->shaderProgram); 142 156 } 143 157 … … 150 164 void Shader::deleteProgram(SHADER_TYPE type) 151 165 { 152 if (type == SHADER_VERTEX )166 if (type == SHADER_VERTEX && this->vertexShader != 0) 153 167 { 154 168 delete[] this->vertexShaderFile; … … 157 171 this->vertexShader = 0; 158 172 } 159 else if (type == SHADER_FRAGMENT )173 else if (type == SHADER_FRAGMENT && this->fragmentShader != 0) 160 174 { 161 175 delete[] this->fragmentShaderFile; … … 171 185 void Shader::printError(GLenum program) 172 186 { 187 if (program == 0) 188 return; 189 173 190 int infologLength = 0; 174 191 int charsWritten = 0; … … 206 223 PRINT(3)("%d: %s\n", i, this->fragmentShaderSource->getEntry(i));*/ 207 224 } 208 209 210 } 211 225 } 226
Note: See TracChangeset
for help on using the changeset viewer.