Results 1 to 4 of 4

Thread: getUniformLocation: is uniform exists or not.

  1. #1
    Junior Member
    Join Date
    Dec 2009
    Posts
    9

    getUniformLocation: is uniform exists or not.

    getUniformLocation returns WebGLUniformLocation object even if there is no uniform in program (for example, getAttribLocation returns -1 in this case).
    How to check if an uniform really exists?

  2. #2
    Junior Member
    Join Date
    Jan 2010
    Posts
    8

    Re: getUniformLocation: is uniform exists or not.

    An easy way to test if it would exist would be by pulling the value of it and see what it returns.
    tested with lesson1 of learningwebgl.

    var uniformlocation = gl.getUniformLocation(shaderProgram, "uMVMatrix");
    var uniform = gl.getUniform(shaderProgram, uniformlocation);
    uniform === WebGLFloatArray;

    var uniformlocation = gl.getUniformLocation(shaderProgram, "ThisMatrixdoesn'texist");
    var uniform = gl.getUniform(shaderProgram, uniformlocation);
    uniform === null;

    Btw this is only tested in chromium but I believe this would be an easy way to find it.

  3. #3
    Junior Member
    Join Date
    Jan 2010
    Posts
    8

    Re: getUniformLocation: is uniform exists or not.

    var uniformlocation,uniform;
    uniformlocation = gl.getUniformLocation(shaderProgram, NameOfUniformVariable);
    if (uniformlocation !== -1){
    uniform = gl.getUniform(shaderProgram, uniformlocation);
    } else {
    uniform = null;
    }

    if uniform now returns null then it means it doesn't exist in that shader

    This is tested in both minefield and chromium
    hopefully the other browser work with this code too

  4. #4
    Junior Member
    Join Date
    Dec 2009
    Posts
    9

    Re: getUniformLocation: is uniform exists or not.

    Thanks, easywebgl.

Similar Threads

  1. GetUniformLocation returning -1
    By EricHosick in forum WebGL - General
    Replies: 1
    Last Post: 11-13-2011, 04:32 AM
  2. A problem about the non-uniform scaling.
    By akaiwall in forum OpenVG and VGU
    Replies: 3
    Last Post: 04-15-2009, 08:59 AM
  3. uniform OMX IL implementation
    By virajk in forum OpenMAX IL
    Replies: 3
    Last Post: 09-09-2008, 01:32 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •