Пример #1
0
// print absolutely everything about a shader program - only useful if you get really
// stuck wondering why a shader isn't working properly 
void CShader::printSPInfo( const GLuint& sp) {
    int params = -1;
    int i;

    LogMsg<<"--------------------shader program "<<sp<<" info--------------------"<<LogEndl;
    glGetProgramiv( sp, GL_LINK_STATUS, &params);
    LogMsg<<"GL_LINK_STATUS = "<<params<<LogEndl;

    glGetProgramiv( sp, GL_ATTACHED_SHADERS, &params);
    LogMsg<<"GL_ATTACHED_SHADERS = "<<params<<LogEndl;


    glGetProgramiv( sp, GL_ACTIVE_ATTRIBUTES, &params);
    LogMsg<<"GL_ACTIVE_ATTRIBUTES = "<<params<<LogEndl;

    for( i = 0; i < params; ++i) {
        char name[64];
        int maxLength = 64;
        int actualLength = 0;
        int size = 0;
        GLenum type;
        glGetActiveAttrib( sp, i, maxLength, &actualLength, &size, &type, name);
        if( size > 1) {
            int j;
            for( j = 0; j < size; ++j) {
                ostringstream ss;
                int location;
                ss<<name<<"["<<j<<"]";
                std::string longName = ss.str();
                location = glGetAttribLocation(sp, longName.c_str() );
                LogMsg<<i<<"i) type: "<<glTypeToString( type )<<", name: "<<longName<<", location: "<<location<<LogEndl;
            }
        } else {
            int location = glGetAttribLocation( sp, name );
            LogMsg<<i<<") type: "<<glTypeToString( type )<<", name: "<<name<<", location: "<<location<<LogEndl;
        }
    }

    glGetProgramiv( sp, GL_ACTIVE_UNIFORMS, &params);
    LogMsg<<"GL_ACTIVE_UNIFORMS = "<<params<<LogEndl;
    for( i = 0; i < params; ++i) {
        char name[64];
        int maxLength = 64;
        int actualLength = 0;
        int size = 0;
        GLenum type;
        glGetActiveUniform( sp, i, maxLength, &actualLength, &size, &type, name);
        if( size > 1) {
            int j;
            for( j = 0; j < size; ++j) {
                ostringstream ss;
                int location;
                ss<<name<<"["<<j<<"]";
                std::string longName = ss.str();
                location = glGetUniformLocation( sp, longName.c_str() );
                LogMsg<<i<<"i) type: "<<glTypeToString( type )<<", name: "<<longName<<", location: "<<location<<LogEndl;
            }
        } else {
            int location = glGetUniformLocation( sp, name);
            LogMsg<<i<<") type: "<<glTypeToString( type )<<", name: "<<name<<", location: "<<location<<LogEndl;
        }
    }

    printSPInfoLog( sp );
}
Пример #2
0
void queso::ShaderProgram::printAllInfo() {
  LOG(INFO) << "[Program " << m_handle << "]: All information:";

  int params = -1;

  // Link status
  glGetProgramiv(m_handle, GL_LINK_STATUS, &params);
  char value[32];
  LOG(INFO) << "\tGL_LINK_STATUS: " << (params == GL_TRUE ? "GL_TRUE" : "GL_FALSE");

  // Attached shaders
  glGetProgramiv(m_handle, GL_ATTACHED_SHADERS, &params);
  LOG(INFO) << "\tGL_ATTACHED_SHADERS: " << params;
  if (m_vertex)
    LOG(INFO) << "\t\t[Vertex " << m_vertex->getHandle() << "]: " << m_vertex->getFilename();
  if (m_fragment)
    LOG(INFO) << "\t\t[Fragment " << m_fragment->getHandle() << "]: " << m_fragment->getFilename();

  // Active attributes
  glGetProgramiv(m_handle, GL_ACTIVE_ATTRIBUTES, &params);
  LOG(INFO) << "\tGL_ACTIVE_ATTRIBUTES: " << params;
  for (unsigned int i = 0; i < params; i++) {
    char name[64];
    int max_len = 64, actual_len = 0, size = 0;
    GLenum type;
    glGetActiveAttrib(m_handle, i, max_len, &actual_len, &size, &type, name);
    if (size > 1) {
      for (int j = 0; j < size; j++) {
        std::stringstream oss;
        oss << name << "[" << j << "]";
        int location = glGetAttribLocation(m_handle, oss.str().c_str());
        LOG(INFO) << "\t\tAttribute #" << i
          << ": type=" << glTypeToString(type)
          << ", name=" << oss.str()
          << ", location=" << location;
      }
    } else {
      int location = glGetAttribLocation(m_handle, name);
      LOG(INFO) << "\t\tAttribute #" << i
        << ": type=" << glTypeToString(type)
        << ", name=" << name
        << ", location=" << location;
    }
  }

  // Active uniforms
  glGetProgramiv(m_handle, GL_ACTIVE_UNIFORMS, &params);
  LOG(INFO) << "\tGL_ACTIVE_UNIFORMS: " << params;
  for (unsigned int i = 0; i < params; i++) {
    char name[64];
    int max_len = 64, actual_len = 0, size = 0;
    GLenum type;
    glGetActiveUniform(m_handle, i, max_len, &actual_len, &size, &type, name);
    if (size > 1) {
      for (int j = 0; j < size; j++) {
        std::stringstream oss;
        oss << name << "[" << j << "]";
        int location = glGetUniformLocation(m_handle, oss.str().c_str());
        LOG(INFO) << "\t\tAttribute #" << i
          << ": type=" << glTypeToString(type)
          << ", name=" << oss.str()
          << ", location=" << location;
      }
    } else {
      int location = glGetUniformLocation(m_handle, name);
      LOG(INFO) << "\t\tAttribute #" << i
        << ": type=" << glTypeToString(type)
        << ", name=" << name
        << ", location=" << location;
    }
  }

  // Log info
  LOG(INFO) << getProgramLogInfo();
}