Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 5273 in orxonox.OLD for trunk/src/lib


Ignore:
Timestamp:
Oct 1, 2005, 10:39:27 PM (19 years ago)
Author:
bensch
Message:

orxonox/trunk: now shaders do not execute (segfault) on non-shader hardware

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/lib/graphics/shader.cc

    r5271 r5273  
    1919
    2020#include "stdlibincl.h"
     21#include "compiler.h"
    2122#include <stdio.h>
    2223#include "debug.h"
     
    4445
    4546   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     }
    5663}
    5764
     
    6673  this->deleteProgram(SHADER_FRAGMENT);
    6774
    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);
    7181}
    7282
     
    98108    shader = this->fragmentShader = glCreateShaderObjectARB(GL_FRAGMENT_SHADER_ARB);
    99109  }
    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}
    112125
    113126char* Shader::fileRead(const char* fileName)
     
    139152void Shader::activateShader()
    140153{
    141   glUseProgramObjectARB(this->shaderProgram);
     154  if (likely (this->shaderProgram != 0))
     155    glUseProgramObjectARB(this->shaderProgram);
    142156}
    143157
     
    150164void Shader::deleteProgram(SHADER_TYPE type)
    151165{
    152   if (type == SHADER_VERTEX)
     166  if (type == SHADER_VERTEX && this->vertexShader != 0)
    153167  {
    154168    delete[] this->vertexShaderFile;
     
    157171    this->vertexShader = 0;
    158172  }
    159   else if (type == SHADER_FRAGMENT)
     173  else if (type == SHADER_FRAGMENT && this->fragmentShader != 0)
    160174  {
    161175    delete[] this->fragmentShaderFile;
     
    171185void Shader::printError(GLenum program)
    172186{
     187  if (program == 0)
     188    return;
     189
    173190  int infologLength = 0;
    174191  int charsWritten  = 0;
     
    206223        PRINT(3)("%d: %s\n", i, this->fragmentShaderSource->getEntry(i));*/
    207224  }
    208 
    209 
    210 }
    211 
     225}
     226
Note: See TracChangeset for help on using the changeset viewer.