Class cc.GLProgram

Class Summary
Constructor Attributes Constructor Name and Description
 
Class that implements a WebGL program

Method Summary

Class Detail

cc.GLProgram()
Class that implements a WebGL program

Method Detail

  • addAttribute(attributeName, index)
    It will add a new attribute to the shader
    Parameters:
    {String} attributeName
    {Number} index
  • <static> {cc.GLProgram} cc.GLProgram.create(vShaderFileName, fShaderFileName)
    Create a cc.GLProgram object
    Parameters:
    {String} vShaderFileName
    {String} fShaderFileName
    Deprecated:
    since v3.0, please use new cc.GLProgram(vShaderFileName, fShaderFileName) instead
    Returns:
    {cc.GLProgram}
  • {cc.GLProgram} ctor(vShaderFileName, fShaderFileName, glContext)
    Create a cc.GLProgram object
    Parameters:
    {String} vShaderFileName
    {String} fShaderFileName
    glContext
    Returns:
    {cc.GLProgram}
  • destroyProgram()
    destroy program
  • {String} fragmentShaderLog()
    returns the fragmentShader error log
    Returns:
    {String}
  • {String} getFragmentShaderLog()
    returns the fragmentShader error log
    Returns:
    {String}
  • {WebGLProgram} getProgram()
    get WebGLProgram object
    Returns:
    {WebGLProgram}
  • {String} getProgramLog()
    returns the program error log
    Returns:
    {String}
  • {Number} getUniformLocationForName(name)
    calls retrieves the named uniform location for this shader program.
    Parameters:
    {String} name
    Returns:
    {Number}
  • {WebGLUniformLocation} getUniformMVPMatrix()
    get uniform MVP matrix
    Returns:
    {WebGLUniformLocation}
  • {WebGLUniformLocation} getUniformSampler()
    get uniform sampler
    Returns:
    {WebGLUniformLocation}
  • {String} getVertexShaderLog()
    returns the vertexShader error log
    Returns:
    {String}
  • {Boolean} init(vShaderFilename, fShaderFileName)
    Initializes the CCGLProgram with a vertex and fragment with contents of filenames
    Parameters:
    {String} vShaderFilename
    {String} fShaderFileName
    Returns:
    {Boolean}
  • {Boolean} initWithString(vertShaderStr, fragShaderStr)
    Initializes the cc.GLProgram with a vertex and fragment with string
    Parameters:
    {String} vertShaderStr
    {String} fragShaderStr
    Returns:
    {Boolean}
  • {Boolean} initWithVertexShaderByteArray(vertShaderStr, fragShaderStr)
    Initializes the cc.GLProgram with a vertex and fragment with string
    Parameters:
    {String} vertShaderStr
    {String} fragShaderStr
    Returns:
    {Boolean}
  • {Boolean} initWithVertexShaderFilename(vShaderFilename, fShaderFileName)
    Initializes the CCGLProgram with a vertex and fragment with contents of filenames
    Parameters:
    {String} vShaderFilename
    {String} fShaderFileName
    Returns:
    {Boolean}
  • links the glProgram
    Returns:
    {Boolean}
  • {String} programLog()
    returns the program error log
    Returns:
    {String}
  • reset()
    reload all shaders, this function is designed for android
    when opengl context lost, so don't call it.
  • retain()
    Currently JavaScript Bindings (JSB), in some cases, needs to use retain and release. This is a bug in JSB, and the ugly workaround is to use retain/release. So, these 2 methods were added to be compatible with JSB. This is a hack, and should be removed once JSB fixes the retain/release bug
  • setUniformForModelViewProjectionMatrix()
    will update the MVP matrix on the MVP uniform if it is different than the previous call for this same shader program.
  • setUniformLocationI32(location, i1)
    calls glUniform1i only if the values are different than the previous call for this same shader program.
    Parameters:
    {WebGLUniformLocation} location
    {Number} i1
  • setUniformLocationWith1f(location, f1)
    calls glUniform1f only if the values are different than the previous call for this same shader program.
    Parameters:
    {WebGLUniformLocation} location
    {Number} f1
  • setUniformLocationWith1i(location, i1)
    calls glUniform1i only if the values are different than the previous call for this same shader program.
    Parameters:
    {WebGLUniformLocation} location
    {Number} i1
  • setUniformLocationWith2f(location, f1, f2)
    calls glUniform2f only if the values are different than the previous call for this same shader program.
    Parameters:
    {WebGLUniformLocation} location
    {Number} f1
    {Number} f2
  • setUniformLocationWith2fv(location, floatArray, numberOfArrays)
    calls glUniform2fv only if the values are different than the previous call for this same shader program.
    Parameters:
    {WebGLUniformLocation} location
    {Float32Array} floatArray
    {Number} numberOfArrays
  • setUniformLocationWith2i(location, i1, i2)
    calls glUniform2i only if the values are different than the previous call for this same shader program.
    Parameters:
    {WebGLUniformLocation} location
    {Number} i1
    {Number} i2
  • setUniformLocationWith2iv(location, intArray, numberOfArrays)
    calls glUniform2iv only if the values are different than the previous call for this same shader program.
    Parameters:
    {WebGLUniformLocation} location
    {Int32Array} intArray
    {Number} numberOfArrays
  • setUniformLocationWith3f(location, f1, f2, f3)
    calls glUniform3f only if the values are different than the previous call for this same shader program.
    Parameters:
    {WebGLUniformLocation} location
    {Number} f1
    {Number} f2
    {Number} f3
  • setUniformLocationWith3fv(location, floatArray, numberOfArrays)
    calls glUniform3fv only if the values are different than the previous call for this same shader program.
    Parameters:
    {WebGLUniformLocation} location
    {Float32Array} floatArray
    {Number} numberOfArrays
  • setUniformLocationWith3i(location, i1, i2, i3)
    calls glUniform3i only if the values are different than the previous call for this same shader program.
    Parameters:
    {WebGLUniformLocation} location
    {Number} i1
    {Number} i2
    {Number} i3
  • setUniformLocationWith3iv(location, intArray, numberOfArrays)
    calls glUniform3iv only if the values are different than the previous call for this same shader program.
    Parameters:
    {WebGLUniformLocation} location
    {Int32Array} intArray
    {Number} numberOfArrays
  • setUniformLocationWith4f(location, f1, f2, f3, f4)
    calls glUniform4f only if the values are different than the previous call for this same shader program.
    Parameters:
    {WebGLUniformLocation} location
    {Number} f1
    {Number} f2
    {Number} f3
    {Number} f4
  • setUniformLocationWith4fv(location, floatArray, numberOfArrays)
    calls glUniform4fv only if the values are different than the previous call for this same shader program.
    Parameters:
    {WebGLUniformLocation} location
    {Float32Array} floatArray
    {Number} numberOfArrays
  • setUniformLocationWith4i(location, i1, i2, i3, i4)
    calls glUniform4i only if the values are different than the previous call for this same shader program.
    Parameters:
    {WebGLUniformLocation} location
    {Number} i1
    {Number} i2
    {Number} i3
    {Number} i4
  • setUniformLocationWith4iv(location, intArray, numberOfArrays)
    calls glUniform4iv only if the values are different than the previous call for this same shader program.
    Parameters:
    {WebGLUniformLocation} location
    {Int32Array} intArray
    {Number} numberOfArrays
  • setUniformLocationWithMatrix4fv(location, matrixArray, numberOfMatrices)
    calls glUniformMatrix4fv only if the values are different than the previous call for this same shader program.
    Parameters:
    {WebGLUniformLocation} location
    {Float32Array} matrixArray
    {Number} numberOfMatrices
  • setUniformsForBuiltins()
    will update the builtin uniforms if they are different than the previous call for this same shader program.
  • updateUniforms()
    It will create 4 uniforms: cc.UNIFORM_PMATRIX cc.UNIFORM_MVMATRIX cc.UNIFORM_MVPMATRIX cc.UNIFORM_SAMPLER
  • use()
    it will call glUseProgram()
  • {String} vertexShaderLog()
    returns the vertexShader error log
    Returns:
    {String}