Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Sep 24, 2006, 10:30:13 PM (19 years ago)
Author:
bensch
Message:

try with the shader

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/new_class_id/src/lib/graphics/shader.cc

    r9715 r9806  
    3535ObjectListDefinition(Shader);
    3636
     37void Shader::Uniform::setV(unsigned int count, float* vv) const
     38{
     39  switch (count)
     40  {
     41    case 1:
     42    glUniform1fv(this->uniform, 1, vv);
     43    break;
     44    case 2:
     45    glUniform2fv(this->uniform, 2, vv);
     46    break;
     47    case 3:
     48    glUniform3fv(this->uniform, 3, vv);
     49    break;
     50    case 4:
     51    glUniform4fv(this->uniform, 4, vv);
     52    break;
     53  }
     54}
     55void Shader::Uniform::setV(unsigned int count, int* vv) const
     56{
     57  switch (count)
     58  {
     59    case 1:
     60    glUniform1iv(this->uniform, 1, vv);
     61    break;
     62    case 2:
     63    glUniform2iv(this->uniform, 2, vv);
     64    break;
     65    case 3:
     66    glUniform3iv(this->uniform, 3, vv);
     67    break;
     68    case 4:
     69    glUniform4iv(this->uniform, 4, vv);
     70    break;
     71  }
     72}
     73
     74
     75
     76
     77
    3778/**
    3879 * standard constructor
     
    4182{
    4283  this->registerObject(this, Shader::_objectList);
    43    this->shaderProgram = 0;
    44    this->vertexShader = 0;
    45    this->fragmentShader = 0;
    46 
    47    if (GLEW_ARB_shader_objects && GLEW_ARB_shading_language_100)
    48      {
    49        this->shaderProgram = glCreateProgramObjectARB();
    50 
    51        if (!vertexShaderFile.empty())
    52          this->loadShaderProgramm(Shader::Vertex, vertexShaderFile);
    53        if (!fragmentShaderFile.empty())
    54          this->loadShaderProgramm(Shader::Fragment, fragmentShaderFile);
    55 
    56        this->linkShaderProgram();
    57 
    58     }
    59    else
    60      {
    61        PRINTF(2)("Shaders are not supported on your hardware\n");
    62      }
     84  this->shaderProgram = 0;
     85  this->vertexShader = 0;
     86  this->fragmentShader = 0;
     87
     88  if (GLEW_ARB_shader_objects && GLEW_ARB_shading_language_100)
     89  {
     90    this->shaderProgram = glCreateProgramObjectARB();
     91
     92    if (!vertexShaderFile.empty())
     93      this->loadShaderProgramm(Shader::Vertex, vertexShaderFile);
     94    if (!fragmentShaderFile.empty())
     95      this->loadShaderProgramm(Shader::Fragment, fragmentShaderFile);
     96
     97    this->linkShaderProgram();
     98
     99  }
     100  else
     101  {
     102    PRINTF(2)("Shaders are not supported on your hardware\n");
     103  }
    63104}
    64105
     
    91132    //glLinkProgramARB(this->shaderProgram);
    92133    glDeleteObjectARB(this->shaderProgram);
    93        // link error checking
     134    // link error checking
    94135    glGetObjectParameterivARB(this->shaderProgram, GL_OBJECT_DELETE_STATUS_ARB, &status);
    95136    if (status == GL_INVALID_VALUE || status == GL_INVALID_OPERATION)
    96137      this->printError(this->shaderProgram);
    97138  }
    98 }
    99 
    100 Shader* Shader::getShader(const std::string& vertexShaderFile, const std::string& fragmentShaderFile)
    101 {
    102   return (Shader*)ResourceManager::getInstance()->load(vertexShaderFile, SHADER,  RP_LEVEL, fragmentShaderFile);
    103 }
    104 
    105 bool Shader::unload(Shader* shader)
    106 {
    107   return ResourceManager::getInstance()->unload(shader);
    108139}
    109140
     
    161192
    162193  glLinkProgramARB(this->shaderProgram);
    163        // link error checking
     194  // link error checking
    164195  glGetObjectParameterivARB(this->shaderProgram, GL_OBJECT_LINK_STATUS_ARB, &status);
    165196  if (status == GL_INVALID_VALUE || status == GL_INVALID_OPERATION)
     
    203234void Shader::bindShader(const char* name, const float* value, size_t size)
    204235{
    205         if (likely (this->shaderProgram != 0)) {
    206                 glUseProgramObjectARB(this->shaderProgram);
    207 
    208                 unsigned int location = glGetUniformLocationARB(this->shaderProgram, name);
    209                 /* This is EXPENSIVE and should be avoided. */
    210 
    211                 if      (size == 1)  glUniform1fvARB(location, 1, value);
    212                 else if (size == 2)  glUniform2fvARB(location, 1, value);
    213                 else if (size == 3)  glUniform3fvARB(location, 1, value);
    214                 else if (size == 4)  glUniform4fvARB(location, 1, value);
    215                 else if (size == 9)  glUniformMatrix3fvARB(location, 1, false, value);
    216                 else if (size == 16) glUniformMatrix4fvARB(location, 1, false, value);
    217 
    218         }
     236  if (likely (this->shaderProgram != 0))
     237  {
     238    glUseProgramObjectARB(this->shaderProgram);
     239
     240    unsigned int location = glGetUniformLocationARB(this->shaderProgram, name);
     241    /* This is EXPENSIVE and should be avoided. */
     242
     243    if      (size == 1)  glUniform1fvARB(location, 1, value);
     244    else if (size == 2)  glUniform2fvARB(location, 1, value);
     245    else if (size == 3)  glUniform3fvARB(location, 1, value);
     246    else if (size == 4)  glUniform4fvARB(location, 1, value);
     247    else if (size == 9)  glUniformMatrix3fvARB(location, 1, false, value);
     248    else if (size == 16) glUniformMatrix4fvARB(location, 1, false, value);
     249
     250  }
    219251}
    220252
    221253void Shader::deactivateShader()
    222254{
    223  if (storedShader != NULL)
    224    glUseProgramObjectARB(0);
    225  Shader::storedShader = NULL;
     255  if (storedShader != NULL)
     256    glUseProgramObjectARB(0);
     257  Shader::storedShader = NULL;
    226258}
    227259
     
    292324  if (this->vertexShader != 0)
    293325  {
    294 /*    PRINT(3)("VertexShaderProgramm: number=%d, file='%s'\n", this->vertexShader, this->vertexShaderFile);
    295     if (this->vertexShaderSource != NULL)
    296       for (unsigned int i = 0; i < this->vertexShaderSource->getCount(); i++)
    297         PRINT(3)("%d: %s\n", i, this->vertexShaderSource->getEntry(i));
    298   }
    299   if (this->fragmentShader != 0)
    300   {
    301     PRINT(3)("FragmentShaderProgramm: number=%d, file='%s'\n", this->fragmentShader, this->fragmentShaderFile);
    302     if (this->fragmentShaderSource != NULL)
    303       for (unsigned int i = 0; i < this->fragmentShaderSource->getCount(); i++)
    304         PRINT(3)("%d: %s\n", i, this->fragmentShaderSource->getEntry(i));*/
    305   }
    306 }
    307 
     326    /*    PRINT(3)("VertexShaderProgramm: number=%d, file='%s'\n", this->vertexShader, this->vertexShaderFile);
     327        if (this->vertexShaderSource != NULL)
     328          for (unsigned int i = 0; i < this->vertexShaderSource->getCount(); i++)
     329            PRINT(3)("%d: %s\n", i, this->vertexShaderSource->getEntry(i));
     330      }
     331      if (this->fragmentShader != 0)
     332      {
     333        PRINT(3)("FragmentShaderProgramm: number=%d, file='%s'\n", this->fragmentShader, this->fragmentShaderFile);
     334        if (this->fragmentShaderSource != NULL)
     335          for (unsigned int i = 0; i < this->fragmentShaderSource->getCount(); i++)
     336            PRINT(3)("%d: %s\n", i, this->fragmentShaderSource->getEntry(i));*/
     337  }
     338}
     339
Note: See TracChangeset for help on using the changeset viewer.