Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

try with the shader

File:
1 copied

Legend:

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

    r9803 r9806  
    1616//#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_
    1717
    18 #include "shader.h"
     18#include "shader_data.h"
    1919
    2020#include "stdlibincl.h"
     
    3333
    3434
    35 ObjectListDefinition(Shader);
     35ObjectListDefinition(ShaderData);
    3636
    3737/**
     
    4141{
    4242  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      }
     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  }
    6363}
    6464
     
    9191    //glLinkProgramARB(this->shaderProgram);
    9292    glDeleteObjectARB(this->shaderProgram);
    93        // link error checking
     93    // link error checking
    9494    glGetObjectParameterivARB(this->shaderProgram, GL_OBJECT_DELETE_STATUS_ARB, &status);
    9595    if (status == GL_INVALID_VALUE || status == GL_INVALID_OPERATION)
    9696      this->printError(this->shaderProgram);
    9797  }
    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);
    10898}
    10999
     
    161151
    162152  glLinkProgramARB(this->shaderProgram);
    163        // link error checking
     153  // link error checking
    164154  glGetObjectParameterivARB(this->shaderProgram, GL_OBJECT_LINK_STATUS_ARB, &status);
    165155  if (status == GL_INVALID_VALUE || status == GL_INVALID_OPERATION)
     
    203193void Shader::bindShader(const char* name, const float* value, size_t size)
    204194{
    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         }
     195  if (likely (this->shaderProgram != 0))
     196  {
     197    glUseProgramObjectARB(this->shaderProgram);
     198
     199    unsigned int location = glGetUniformLocationARB(this->shaderProgram, name);
     200    /* This is EXPENSIVE and should be avoided. */
     201
     202    if      (size == 1)  glUniform1fvARB(location, 1, value);
     203    else if (size == 2)  glUniform2fvARB(location, 1, value);
     204    else if (size == 3)  glUniform3fvARB(location, 1, value);
     205    else if (size == 4)  glUniform4fvARB(location, 1, value);
     206    else if (size == 9)  glUniformMatrix3fvARB(location, 1, false, value);
     207    else if (size == 16) glUniformMatrix4fvARB(location, 1, false, value);
     208
     209  }
    219210}
    220211
    221212void Shader::deactivateShader()
    222213{
    223  if (storedShader != NULL)
    224    glUseProgramObjectARB(0);
    225  Shader::storedShader = NULL;
     214  if (storedShader != NULL)
     215    glUseProgramObjectARB(0);
     216  Shader::storedShader = NULL;
    226217}
    227218
     
    292283  if (this->vertexShader != 0)
    293284  {
    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 
     285    /*    PRINT(3)("VertexShaderProgramm: number=%d, file='%s'\n", this->vertexShader, this->vertexShaderFile);
     286        if (this->vertexShaderSource != NULL)
     287          for (unsigned int i = 0; i < this->vertexShaderSource->getCount(); i++)
     288            PRINT(3)("%d: %s\n", i, this->vertexShaderSource->getEntry(i));
     289      }
     290      if (this->fragmentShader != 0)
     291      {
     292        PRINT(3)("FragmentShaderProgramm: number=%d, file='%s'\n", this->fragmentShader, this->fragmentShaderFile);
     293        if (this->fragmentShaderSource != NULL)
     294          for (unsigned int i = 0; i < this->fragmentShaderSource->getCount(); i++)
     295            PRINT(3)("%d: %s\n", i, this->fragmentShaderSource->getEntry(i));*/
     296  }
     297}
     298
Note: See TracChangeset for help on using the changeset viewer.