Menu

#5 No API for access getActiveAttrib/getActiveUniform

1.0
closed
nobody
None
2018-01-24
2015-06-03
Amorph
No

No way to call getActiveAttrib and getActiveUniform
This functions may return WebGLActiveInfo object

https://www.khronos.org/registry/webgl/specs/latest/1.0/

WebGLActiveInfo? getActiveAttrib(WebGLProgram? program, GLuint index);
WebGLActiveInfo? getActiveUniform(WebGLProgram? program, GLuint index);

Discussion

  • Kamil Kolaczynski

    These functions are missing. I will add them in the next Synthclipse release (planned at the end of the month).

    For now you can use the following workaround:

    function getActiveAttrib(programID, index) {
        var activeAttributes = gl.getProgramParameter(programID, gl.ACTIVE_ATTRIBUTES);
    
        if (index < 0 || index >= activeAttributes) {
            out.println("ERROR: There is no active attribute with index " + index
                    + ". Active attributes count: " + activeAttributes);
            return;
        }
        var maxLen = Arrays.newIntArray(1);
        gl.getProgramiv(programID, gl.ACTIVE_ATTRIBUTE_MAX_LENGTH, maxLen, 0);
    
        var written = Arrays.newIntArray(1);
        var size = Arrays.newIntArray(1);
        var type = Arrays.newIntArray(1);
        var nameBuf = Arrays.newByteArray(maxLen[0]);
    
        gl.getActiveAttrib(programID, index, maxLen[0], written, 0, size, 0, type, 0, nameBuf, 0);
    
        var name = new java.lang.String(nameBuf, 0, written[0]);
        return { name: name, size: size[0], type: type[0] };
    }
    
    function getActiveUniform(programID, index) {
        var activeUniforms = gl.getProgramParameter(programID, gl.ACTIVE_UNIFORMS);
    
        if (index < 0 || index >= activeUniforms) {
            out.println("ERROR: There is no active uniform with index " + index
                    + ". Active uniforms count: " + activeUniforms);
            return;
        }
        var maxLen = Arrays.newIntArray(1);
        gl.getProgramiv(programID, gl.ACTIVE_UNIFORM_MAX_LENGTH, maxLen, 0);
    
        var written = Arrays.newIntArray(1);
        var size = Arrays.newIntArray(1);
        var type = Arrays.newIntArray(1);
        var nameBuf = Arrays.newByteArray(maxLen[0]);
    
        gl.getActiveUniform(programID, index, maxLen[0], written, 0, size, 0, type, 0, nameBuf, 0);
    
        var name = new java.lang.String(nameBuf, 0, written[0]);
        return { name: name, size: size[0], type: type[0] };
    }
    
    // tested on:
    // JSX Examples\I. Low Level\1. WebGL - Triangle and Square\triangle-and-square.jsx
    function test() {
        var activeAttributes = gl.getProgramParameter(shaderProgram.id, gl.ACTIVE_ATTRIBUTES);
    
        out.println("Active attributes: ")
        for (var i = 0; i < activeAttributes; i++) {
            var info = getActiveAttrib(shaderProgram.id, i);
            out.println((i + 1) + ") name: " + info.name + ", size: " + info.size + ", type: " + info.type);
        }
    
        var activeUniforms = gl.getProgramParameter(shaderProgram.id, gl.ACTIVE_ATTRIBUTES);
    
        out.println("\nActive unifomrs: ")
        for (var i = 0; i < activeUniforms; i++) {
            var info = getActiveUniform(shaderProgram.id, i);
            out.println((i + 1) + ") name: " + info.name + ", size: " + info.size + ", type: " + info.type);
        }
    }
    

    Also if you are using Synth API (not pure WebGL) these functions might be helpful:
    GLSLProgram.printActiveAttributes()
    GLSLProgram.printActiveUniforms()

    (Check out "JSX Examples\II. Synth API\1. ProgramFactory\program-factory.jsx" for a use case)

     
  • Amorph

    Amorph - 2015-06-04

    Thanks for the quick help)
    I'm trying to write another WebGL framework in Synthclipse, so I think, I'll provide more bugs.

    PS. I found one more bug, if comment buffer data commit, for example:

    gl.bindBuffer(gl.ARRAY_BUFFER, squareVertexPositionBuffer.id);

    Eclipse will crash

     
  • Kamil Kolaczynski

    Thanks for another bug report. Unfortunately I don't know if I will be able to fix this error.

     
  • Kamil Kolaczynski

    • status: open --> closed
     

Log in to post a comment.