Bug 425

Summary: Can never bind attributes to shader program due to faulty logic
Product: [JogAmp] Jogl Reporter: Robert B <robert.c.baruch>
Component: openglAssignee: Sven Gothel <sgothel>
Status: VERIFIED FIXED    
Severity: major    
Priority: P3    
Version: 2   
Hardware: All   
OS: all   
Type: DEFECT SCM Refs:
2d22d9a880fee84af422505e69c1642c7a505b0f 8297ef88b927e07b41760ab3e9de05bc49fd4695
Workaround: ---
Deadline: 2010-11-30   

Description Robert B 2010-10-29 07:45:27 CEST
According to the logic in ShaderProgram and ShaderState, glBindAttribLocation will always fail because it requires that the program be attached to the state but not linked, and attaching the program to the state (attachProgram) requires that the program be linked (because attachProgram calls ShaderProgram.glUseProgram, which requires the program be linked).

Perhaps glUseProgram could be modified so that if on is false, it shouldn't check whether the program is linked?

Here is a method which illustrates the contradiction:

   public ShaderState gltLoadShaderPairSrcWithAttributes(GL2 gl, String vertexSrc, String fragmentSrc, 
            HashMap<Integer, String> attributes) 
    { 
        ByteArrayOutputStream verboseOutBuffer = new ByteArrayOutputStream(); 
        PrintStream verboseOut = new PrintStream(verboseOutBuffer, true); 

         // Create ShaderCode objects 

        ShaderCode vertexShaderCode = new ShaderCode(GL2.GL_VERTEX_SHADER, 1, 
                new String[][]{ { vertexSrc } }); 
        ShaderCode fragmentShaderCode = new ShaderCode(GL2.GL_FRAGMENT_SHADER, 1, 
                new String[][]{ { fragmentSrc } }); 

        // Put them in a ShaderProgram 

        ShaderProgram program = new ShaderProgram(); 
        program.add(vertexShaderCode); 
        program.add(fragmentShaderCode); 

        // Create a new ShaderState 

        ShaderState shaderState = new ShaderState(); 

        // Link the programs here? 

        if (!program.link(gl, verboseOut)) 
            throw new GLException("Failed to compile and link shaders: " + verboseOutBuffer.toString()); 

        // Attach the program to the state. Requires that the program be linked. 

        shaderState.attachShaderProgram(gl, program); 

        // Set some attributes. Requires that the program be attached BUT NOT LINKED??? 

        Set<Entry<Integer, String>> attributeSet = attributes.entrySet(); 
        Iterator<Entry<Integer, String>> iterator = attributeSet.iterator(); 
        while (iterator.hasNext()) 
        { 
            Entry<Integer, String> entry = iterator.next(); 
            shaderState.glBindAttribLocation(gl, entry.getKey(), entry.getValue()); 
        } 

        return shaderState; 
}
Comment 2 Sven Gothel 2011-04-10 01:33:32 CEST
verified with mentioned test