Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Dec 7, 2006, 7:02:27 PM (17 years ago)
Author:
rennerc
Message:

fix for segfault with ati r300 driver

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/world_entities/environments/mapped_water.cc

    r9882 r10034  
    5252  this->registerObject(this, MappedWater::_objectList);
    5353  this->toList(OM_ENVIRON);
     54 
     55  cam_uni = NULL;
     56  light_uni = NULL;
     57  color_uni = NULL;
     58  shineSize_uni = NULL;
     59  shineStrength_uni = NULL;
     60  reflStrength_uni = NULL;
     61  refr_uni = NULL;
    5462
    5563  /// sets start values and parameters
     
    7886MappedWater::~MappedWater()
    7987{
    80   delete cam_uni;
    81   delete color_uni;
    82   delete light_uni;
    83   delete shineSize_uni;
    84   delete shineStrength_uni;
    85   delete reflStrength_uni;
    86   delete refr_uni;
     88  if ( cam_uni )
     89    delete cam_uni;
     90 
     91  if ( color_uni )
     92    delete color_uni;
     93 
     94  if ( light_uni )
     95    delete light_uni;
     96 
     97  if ( shineSize_uni )
     98    delete shineSize_uni;
     99 
     100  if ( shineStrength_uni )
     101    delete shineStrength_uni;
     102 
     103  if ( reflStrength_uni )
     104    delete reflStrength_uni;
     105 
     106  if ( refr_uni )
     107    delete refr_uni;
    87108}
    88109
     
    164185void MappedWater::initShaders()
    165186{
     187  if ( !Shader::isSupported() )
     188  {
     189        return;
     190  }
     191       
    166192  // load shader files
    167193  shader = ResourceShader( "shaders/mapped_water.vert", "shaders/mapped_water.frag");
     
    225251void MappedWater::resetWaterColor(float r, float g, float b)
    226252{
     253  if ( !Shader::isSupported() )
     254  {
     255        return;
     256  }
     257 
    227258  this->shader.activateShader();
    228259  this->waterColor = Vector(r, g, b);
     
    240271void MappedWater::resetShineSize(float shine)
    241272{
     273  if ( !Shader::isSupported() )
     274  {
     275        return;
     276  }
     277 
    242278  this->shader.activateShader();
    243279  this->shineSize = shine;
     
    255291void MappedWater::resetShineStrength(float strength)
    256292{
     293  if ( !Shader::isSupported() )
     294  {
     295        return;
     296  }
     297 
    257298  this->shader.activateShader();
    258299  this->shineStrength = strength;
     
    270311void MappedWater::resetReflStrength(float strength)
    271312{
     313  if ( !Shader::isSupported() )
     314  {
     315        return;
     316  }
     317 
    272318  this->shader.activateShader();
    273319  this->reflStrength = strength;
     
    285331void MappedWater::resetRefraction(float refraction)
    286332{
     333  if ( !Shader::isSupported() )
     334  {
     335        return;
     336  }
     337 
    287338  this->shader.activateShader();
    288339  this->refraction = refraction;
     
    302353void MappedWater::resetLightPos(float x, float y, float z)
    303354{
     355  if ( !Shader::isSupported() )
     356  {
     357        return;
     358  }
     359 
    304360  this->shader.activateShader();
    305361  this->lightPos = Vector(x, y, z);
     
    555611
    556612  mat.select();
    557 
    558   this->shader.activateShader();
    559 
    560   // reset the camera uniform to the current cam position
    561   Vector pos = State::getCameraNode()->getAbsCoor();
    562   cam_uni->set(pos.x, pos.y, pos.z, 1.0f);
    563 
    564   glDisable(GL_BLEND);
    565 
    566   // TODO change texture coords, so water doesnt look distorted when xWidth != zWidth
    567   glBegin(GL_QUADS);
    568   // The back left vertice for the water
    569   glMultiTexCoord2f(GL_TEXTURE0, 0, waterUV);                   // Reflection texture
    570   glMultiTexCoord2f(GL_TEXTURE1, 0, waterUV - move);            // Refraction texture
    571   glMultiTexCoord2f(GL_TEXTURE2, 0, normalUV + move2);          // Normal map texture
    572   glMultiTexCoord2f(GL_TEXTURE3, 0, 0);                         // DUDV map texture
    573   glVertex3f(this->waterVerts[0], this->waterHeight, this->waterVerts[1]);
    574 
    575   // The front left vertice for the water
    576   glMultiTexCoord2f(GL_TEXTURE0, 0, 0);                         // Reflection texture
    577   glMultiTexCoord2f(GL_TEXTURE1, 0, -move);                     // Refraction texture
    578   glMultiTexCoord2f(GL_TEXTURE2, 0, move2);                     // Normal map texture
    579   glMultiTexCoord2f(GL_TEXTURE3, 0, 0);                         // DUDV map texture
    580   glVertex3f(this->waterVerts[2], this->waterHeight, this->waterVerts[3]);
    581 
    582   // The front right vertice for the water
    583   glMultiTexCoord2f(GL_TEXTURE0, waterUV, 0);                   // Reflection texture
    584   glMultiTexCoord2f(GL_TEXTURE1, waterUV, -move);               // Refraction texture
    585   glMultiTexCoord2f(GL_TEXTURE2, normalUV, move2);              // Normal map texture
    586   glMultiTexCoord2f(GL_TEXTURE3, 0, 0);                         // DUDV map texture
    587   glVertex3f(this->waterVerts[4], this->waterHeight, this->waterVerts[5]);
    588 
    589   // The back right vertice for the water
    590   glMultiTexCoord2f(GL_TEXTURE0, waterUV, waterUV);             // Reflection texture
    591   glMultiTexCoord2f(GL_TEXTURE1, waterUV, waterUV - move);      // Refraction texture
    592   glMultiTexCoord2f(GL_TEXTURE2, normalUV, normalUV + move2);   // Normal map texture
    593   glMultiTexCoord2f(GL_TEXTURE3, 0, 0);                         // DUDV map texture
    594   glVertex3f(this->waterVerts[6], this->waterHeight, this->waterVerts[7]);
    595   glEnd();
    596 
    597   this->shader.deactivateShader();
    598 
     613  if ( Shader::isSupported() )
     614  {
     615    this->shader.activateShader();
     616 
     617    // reset the camera uniform to the current cam position
     618    Vector pos = State::getCameraNode()->getAbsCoor();
     619    cam_uni->set(pos.x, pos.y, pos.z, 1.0f);
     620 
     621    glDisable(GL_BLEND);
     622 
     623    // TODO change texture coords, so water doesnt look distorted when xWidth != zWidth
     624    glBegin(GL_QUADS);
     625    // The back left vertice for the water
     626    glMultiTexCoord2f(GL_TEXTURE0, 0, waterUV);                   // Reflection texture
     627    glMultiTexCoord2f(GL_TEXTURE1, 0, waterUV - move);            // Refraction texture
     628    glMultiTexCoord2f(GL_TEXTURE2, 0, normalUV + move2);          // Normal map texture
     629    glMultiTexCoord2f(GL_TEXTURE3, 0, 0);                         // DUDV map texture
     630    glVertex3f(this->waterVerts[0], this->waterHeight, this->waterVerts[1]);
     631 
     632    // The front left vertice for the water
     633    glMultiTexCoord2f(GL_TEXTURE0, 0, 0);                         // Reflection texture
     634    glMultiTexCoord2f(GL_TEXTURE1, 0, -move);                     // Refraction texture
     635    glMultiTexCoord2f(GL_TEXTURE2, 0, move2);                     // Normal map texture
     636    glMultiTexCoord2f(GL_TEXTURE3, 0, 0);                         // DUDV map texture
     637    glVertex3f(this->waterVerts[2], this->waterHeight, this->waterVerts[3]);
     638 
     639    // The front right vertice for the water
     640    glMultiTexCoord2f(GL_TEXTURE0, waterUV, 0);                   // Reflection texture
     641    glMultiTexCoord2f(GL_TEXTURE1, waterUV, -move);               // Refraction texture
     642    glMultiTexCoord2f(GL_TEXTURE2, normalUV, move2);              // Normal map texture
     643    glMultiTexCoord2f(GL_TEXTURE3, 0, 0);                         // DUDV map texture
     644    glVertex3f(this->waterVerts[4], this->waterHeight, this->waterVerts[5]);
     645 
     646    // The back right vertice for the water
     647    glMultiTexCoord2f(GL_TEXTURE0, waterUV, waterUV);             // Reflection texture
     648    glMultiTexCoord2f(GL_TEXTURE1, waterUV, waterUV - move);      // Refraction texture
     649    glMultiTexCoord2f(GL_TEXTURE2, normalUV, normalUV + move2);   // Normal map texture
     650    glMultiTexCoord2f(GL_TEXTURE3, 0, 0);                         // DUDV map texture
     651    glVertex3f(this->waterVerts[6], this->waterHeight, this->waterVerts[7]);
     652    glEnd();
     653 
     654    this->shader.deactivateShader();
     655  }
    599656  mat.unselect();
    600657
Note: See TracChangeset for help on using the changeset viewer.