Class GlProgram

  • public final class GlProgram
    extends Object
    Represents a GLSL shader program.

    After constructing a program, keep a reference for its lifetime and call delete() (or release the current GL context) when it's no longer needed.

    • Constructor Detail

      • GlProgram

        public GlProgram​(Context context,
                         String vertexShaderFilePath,
                         String fragmentShaderFilePath)
                  throws IOException,
        Compiles a GL shader program from vertex and fragment shader GLSL GLES20 code.
        context - The Context.
        vertexShaderFilePath - The path to a vertex shader program.
        fragmentShaderFilePath - The path to a fragment shader program.
        IOException - When failing to read shader files.
      • GlProgram

        public GlProgram​(String vertexShaderGlsl,
                         String fragmentShaderGlsl)
                  throws GlUtil.GlException
        Creates a GL shader program from vertex and fragment shader GLSL GLES20 code.

        This involves slow steps, like compiling, linking, and switching the GL program, so do not call this in fast rendering loops.

        vertexShaderGlsl - The vertex shader program.
        fragmentShaderGlsl - The fragment shader program.
    • Method Detail

      • loadAsset

        public static String loadAsset​(Context context,
                                       String assetPath)
                                throws IOException
        Loads a file from the assets folder.
        context - The Context.
        assetPath - The path to the file to load, from the assets folder.
        The content of the file to load.
        IOException - If the file couldn't be read.
      • getUniformLocation

        public int getUniformLocation​(String uniformName)
        Returns the location of a GlProgram.Uniform.
      • getAttributeArrayLocationAndEnable

        public int getAttributeArrayLocationAndEnable​(String attributeName)
                                               throws GlUtil.GlException
        Returns the location of an GlProgram.Attribute, which has been enabled as a vertex attribute array.
      • setBufferAttribute

        public void setBufferAttribute​(String name,
                                       float[] values,
                                       int size)
        Sets a float buffer type attribute.
      • setSamplerTexIdUniform

        public void setSamplerTexIdUniform​(String name,
                                           int texId,
                                           int texUnitIndex)
        Sets a texture sampler type uniform.
        name - The uniform's name.
        texId - The texture identifier.
        texUnitIndex - The texture unit index. Use a different index (0, 1, 2, ...) for each texture sampler in the program.
      • setIntUniform

        public void setIntUniform​(String name,
                                  int value)
        Sets an int type uniform.
      • setFloatUniform

        public void setFloatUniform​(String name,
                                    float value)
        Sets a float type uniform.
      • setFloatsUniform

        public void setFloatsUniform​(String name,
                                     float[] value)
        Sets a float[] type uniform.