protected void readUniformsFromSource(GL2 gl, String source) {
   // read the uniforms defined by the shader source
   int samplerNumber = 0;
   Pattern uniformPattern = Pattern.compile("uniform\\s+(\\w+)\\s+([^;]+);");
   Matcher matcher = uniformPattern.matcher(source);
   while (matcher.find()) {
     String[] names = matcher.group(2).split("\\s*,\\s*");
     if (matcher.group(1).equals("sampler2D")) {
       // a sampler2D was found; set them to incremental integers (assume that they are defined by
       // texture order)
       for (String name : names) {
         gl.glUniform1i(gl.glGetUniformLocation(shaderProgram, name), samplerNumber++);
       }
     } else {
       for (String name : names) {
         // check if we have a setter for this uniform name
         IUniformSetter setter = setters.get(name);
         if (setter != null) {
           int uniformLocation = gl.glGetUniformLocation(shaderProgram, name);
           uniforms.put(uniformLocation, setter);
         }
       }
     }
   }
 }
 @Override
 public void uniforms() {
   GL2 gl = getGL();
   // System.out.println("A : kernelSize = " + kernelSize);
   gl.glUniform4f(uniform("ScaleFactor"), scaleFactor, scaleFactor, scaleFactor, scaleFactor);
   gl.glUniform1i(uniform("KernelSize"), kernelSize);
   // System.out.println("B");
   gl.glUniform4fv(uniform("KernelValueH[0]"), kernelValueH.length, kernelValueH, 0);
   gl.glUniform4fv(uniform("KernelValueV[0]"), kernelValueV.length, kernelValueV, 0);
   // System.out.println("C");
   gl.glUniform2fv(uniform("Offset[0]"), offsets.length, offsets, 0);
 }
Ejemplo n.º 3
0
 public void setTextureUnit(GL2 gl, String texname, int texunit) {
   int[] params = new int[] {0};
   gl.glGetProgramiv(_progId, GL2.GL_LINK_STATUS, params, 0);
   if (params[0] != 1) {
     System.err.println("Error: setTextureUnit needs program to be linked.");
   }
   int id = gl.glGetUniformLocation(_progId, texname);
   if (id == -1) {
     System.err.println("Warning: Invalid texture " + texname);
     return;
   }
   gl.glUniform1i(id, texunit);
 }
Ejemplo n.º 4
0
  public void drawTextureToOffScreenTextureUsingShader(int texId, int attachment, Program program)
        // public void drawTextureToOffScreenTextureUsingShader(Texture tex, int attachment, Program
        // program)
      {
    GL2 gl = getGL();

    program.bind();

    gl.glBindTexture(GL_TEXTURE_2D, texId);
    // gl.glBindTexture(GL_TEXTURE_2D, tex.getTextureObject());
    gl.glDrawBuffer(attachment);
    gl.glEnable(GL_TEXTURE_2D);
    // gl.glActiveTexture(GL_TEXTURE0);
    gl.glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);

    gl.glViewport(0, 0, fboWidth, fboHeight);

    gl.glUniform1i(program.uniform("theTexture"), 0);
    // set projection to ortho
    gl.glMatrixMode(gl.GL_PROJECTION);

    gl.glPushMatrix();
    {
      gl.glLoadIdentity();
      Renderer.getInstance().glu.gluOrtho2D(0, fboWidth, fboHeight, 0);

      gl.glMatrixMode(gl.GL_MODELVIEW);

      gl.glPushMatrix();
      {
        gl.glLoadIdentity();

        gl.glColor4f(1f, 1f, 1f, 1f);
        drawSquare(gl, 0, 0, fboWidth, fboHeight);
      }
      gl.glPopMatrix();

      gl.glMatrixMode(gl.GL_PROJECTION);
    }
    gl.glPopMatrix();

    gl.glMatrixMode(gl.GL_MODELVIEW);

    gl.glDisable(GL_TEXTURE_2D);
    program.unbind();
  }
Ejemplo n.º 5
0
 public void setUniforms(GL2 gl) {
   gl.glUniform1i(textureLocation, 0);
 }