Class CompiledProgram

java.lang.Object
cz.fidentis.analyst.glsl.code.impl.CompiledProgram
All Implemented Interfaces:
GlslProgram

public class CompiledProgram extends Object implements GlslProgram
A proxy object storing the information about a GLSL program compiled on GPU. The class follow the Builder principles. Usage:
     CompiledProgram program = new CompiledProgram(...)
           .addShader(shader1)
           .addShader(shader2)
           .addShader(shader3)
           .compile();
 
  • Constructor Details

    • CompiledProgram

      public CompiledProgram(com.jogamp.opengl.GLContext glContext, GlslProgramDef programDef)
      Links existing shaders into a program.
      Parameters:
      glContext - OpenGL context. Must not be null. Must be at least GL2.
      programDef - The definition of the program to be compiled
      Throws:
      com.jogamp.opengl.GLException - if the program initiation fails
  • Method Details

    • addShader

      public CompiledProgram addShader(CompiledShader shader)
      Links program with the given shader.
      Parameters:
      shader - compiled shader to be added to the program
      Returns:
      this object
    • compile

      public CompiledProgram compile() throws com.jogamp.opengl.GLException
      Compiles the program on GPU.
      Returns:
      this object
      Throws:
      com.jogamp.opengl.GLException - if the compilation fails
    • release

      public void release()
      Ask GPU to release the program from its memory.
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • getProgramId

      public int getProgramId()
      Description copied from interface: GlslProgram
      Returns the ID of the program in the OpenGL context
      Specified by:
      getProgramId in interface GlslProgram
      Returns:
      program's ID
    • getProgramDef

      public GlslProgramDef getProgramDef()
      Description copied from interface: GlslProgram
      Returns the GLSL program definition which was used to create this program.
      Specified by:
      getProgramDef in interface GlslProgram
      Returns:
      program's definition
    • getUniformLocation

      public int getUniformLocation(String key)
      Description copied from interface: GlslProgram
      Returns ID of the given named uniform location in the OpenGL context.
      Specified by:
      getUniformLocation in interface GlslProgram
      Parameters:
      key - name
      Returns:
      ID of the given named uniform location in the OpenGL context or -1
    • setMat4fVar

      public void setMat4fVar(String varName, float[] value)
      Description copied from interface: GlslProgram
      Sets the value to a uniform Matrix4fv variable defined in the compiled program.
      Specified by:
      setMat4fVar in interface GlslProgram
      Parameters:
      varName - variable name (see GlslProgramDef)
      value - Value to be assigned
    • setNumberVar

      public void setNumberVar(String varName, Number value)
      Description copied from interface: GlslProgram
      Sets the value to a uniform 1f or 1i variable defined in the compiled program.
      Specified by:
      setNumberVar in interface GlslProgram
      Parameters:
      varName - variable name (see GlslProgramDef)
      value - Value to be assigned. Must be either float or integer
    • setVec4fVar

      public void setVec4fVar(String varName, float v1, float v2, float v3, float v4)
      Description copied from interface: GlslProgram
      Sets the value to a uniform 4f variable defined in the compiled program.
      Specified by:
      setVec4fVar in interface GlslProgram
      Parameters:
      varName - variable name (see GlslProgramDef)
      v1 - First value to be assigned
      v2 - Second value to be assigned
      v3 - Third value to be assigned
      v4 - Fourth value to be assigned