Пример #1
0
void glsl_vertex :: openMess(t_symbol *filename)
{
  if(NULL==filename || NULL==filename->s_name)return;
  if(&s_==filename)return;

  if( !GLEW_VERSION_1_1 ) { /* stupid check whether we have a valid context */
    post("shader '%s' will be loaded when rendering is turned on (openGL context needed)", filename->s_name);
    m_shaderFilename=filename;
    return;
  }

  if(!isRunnable()) {
    return;
  }

  // Clean up any open files
  closeMess();

  std::string fn = findFile(filename->s_name);
  const char*buf=fn.c_str();

  FILE *file = fopen(buf,"rb");
  if(file) {
    fseek(file,0,SEEK_END);
    long size = ftell(file);
    if(size<0){fclose(file);error("error reading filesize");return;}
    m_shaderString = new char[size + 1];
    memset(m_shaderString,0,size + 1);
    fseek(file,0,SEEK_SET);
    size_t count=fread(m_shaderString,1,size,file);
    int err=ferror(file);
    fclose(file);
    if(err){error("error %d reading file (%d<%d)", err, count, size); return;}
  } else {
    error("could not find shader-file: '%s'", buf);
    return;
    /*
      // assuming that the "filename" is actually a shader-program per se
      m_shaderString = new char[strlen(buf) + 1];
      strcpy(m_shaderString,buf);
    */
  }
  m_size=strlen(m_shaderString);

  if(GLEW_VERSION_2_0)
    openMessGL2();
  else if (GLEW_ARB_vertex_shader) 
    openMessARB();

  logpost(NULL, 5, "Loaded file: %s", buf);
  m_shaderFilename=NULL;
}
Пример #2
0
void glsl_vertex :: loadShader()
{
  if(NULL==m_shaderFilename || NULL==m_shaderFilename->s_name)return;

  if(!isRunnable()) {
    return;
  }

  // Clean up any open files
  closeMess();

  std::string fn = findFile(m_shaderFilename->s_name);
  const char*buf=fn.c_str();

  FILE *file = fopen(buf,"rb");
  if(file) {
    fseek(file,0,SEEK_END);
    long size = ftell(file);
    if(size<0){fclose(file);error("error reading filesize");return;}
    m_shaderString = new char[size + 1];
    memset(m_shaderString,0,size + 1);
    fseek(file,0,SEEK_SET);
    size_t count=fread(m_shaderString,1,size,file);
    m_shaderString[size]='\0';
    int err=ferror(file);
    fclose(file);
    if(err){error("error %d reading file (%d<%d)", err, count, size); return;}
  } else {
    error("could not find shader-file: '%s'", buf);
    return;
    /*
      // assuming that the "filename" is actually a shader-program per se
      m_shaderString = new char[strlen(buf) + 1];
      strcpy(m_shaderString,buf);
    */
  }
  m_size=strlen(m_shaderString);

  if(GLEW_VERSION_2_0)
    openMessGL2();
  else if (GLEW_ARB_vertex_shader)
    openMessARB();

  verbose(1, "Loaded file: %s", buf);
  m_shaderFilename=NULL;
}
Пример #3
0
void glsl_geometry :: openMess(t_symbol *filename)
{
  if(NULL==filename || NULL==filename->s_name)return;
  if(&s_==filename)return;
  if( !GLEW_VERSION_1_1 ) { /* stupid check whether we have a valid context */
    post("shader '%s' will be loaded when rendering is turned on (openGL context needed)", filename->s_name);
    m_shaderFilename=filename;
    return;
  }

  if(!isRunnable()) {
    return;
  }

  // Clean up any open files
  closeMess();

  std::string fn = findFile(filename->s_name);
  const char*buf=fn.c_str();

  FILE *file = fopen(buf,"rb");
  if(file) {
    fseek(file,0,SEEK_END);
    long size = ftell(file);
    if(size<0){fclose(file);error("error reading filesize");return;}
    m_shaderString = new char[size + 1];
    memset(m_shaderString,0,size + 1);
    fseek(file,0,SEEK_SET);
    size_t count=fread(m_shaderString,1,size,file);
    m_shaderString[size]='\0';
    int err=ferror(file);
    fclose(file);
    if(err){error("error %d reading file (%d<%d)", err, count, size); return;}
  } else {
    error("could not find shader-file: '%s'", buf);
    return;
    /*
      // assuming that the "filename" is actually a shader-program per se
      m_shaderString = new char[strlen(buf) + 1];
      strcpy(m_shaderString,buf);
    */
  }
  m_size=strlen(m_shaderString);

  if(GLEW_EXT_geometry_shader4) // GLEW_VERSION_2_1
    openMessGL2();
  else if (GLEW_ARB_geometry_shader4)
    openMessARB();

  verbose(1, "Loaded file: %s", buf);
  m_shaderFilename=NULL;

  if (m_shader || m_shaderARB)
    {
      t_atom a;
      // send shaderID to outlet
      gem::utils::glsl::atom_setshader(a, m_shader?m_shader:m_shaderARB);

      outlet_list(m_outShaderID, gensym("list"), 1, &a);
    }
}