示例#1
0
  public void link() {
    for (Shader s : shaders) {
      if (null != s && s.shader == -1) {
        s.compile();
      }
    }
    int newProgram = linkProgram(shaders);
    if (program != -1) {
      glDeleteProgram(program);
      program = -1;
    }
    this.uniforms.clear();
    this.attributes.clear();
    program = newProgram;
    if (program == -1) {
      throw new IllegalStateException("Link failure");
    }
    int count = glGetProgrami(program, GL_ACTIVE_UNIFORMS);
    for (int i = 0; i < count; ++i) {
      String name = glGetActiveUniform(program, i, 256);
      int location = glGetUniformLocation(program, name);
      this.uniforms.put(name, location);
    }

    count = glGetProgrami(program, GL_ACTIVE_ATTRIBUTES);
    for (int i = 0; i < count; ++i) {
      String name = glGetActiveAttrib(program, i, 256);
      int location = glGetAttribLocation(program, name);
      this.attributes.put(name, location);
    }
  }
示例#2
0
 public static int linkProgram(Shader... shaders) {
   int newProgram = glCreateProgram();
   for (Shader s : shaders) {
     if (null != s) {
       s.attach(newProgram);
     }
   }
   glLinkProgram(newProgram);
   int linkResult = glGetProgrami(newProgram, GL_LINK_STATUS);
   if (GL_TRUE != linkResult) {
     String log = getLog(newProgram);
     LOG.warn("Link failed: " + log);
     glDeleteProgram(newProgram);
     throw new RuntimeException(log);
   }
   return newProgram;
 }