Android Open Source - touchgloid Program






From Project

Back to project page touchgloid.

License

The source code is released under:

MIT License

If you think the Android project touchgloid listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package rucamzu.opengl;
/*ww w .ja va2  s.  co  m*/
import static android.opengl.GLES20.GL_LINK_STATUS;
import static android.opengl.GLES20.GL_FLOAT;
import static android.opengl.GLES20.glAttachShader;
import static android.opengl.GLES20.glCreateProgram;
import static android.opengl.GLES20.glDisableVertexAttribArray;
import static android.opengl.GLES20.glEnableVertexAttribArray;
import static android.opengl.GLES20.glGetAttribLocation;
import static android.opengl.GLES20.glGetProgramiv;
import static android.opengl.GLES20.glGetUniformLocation;
import static android.opengl.GLES20.glDeleteProgram;
import static android.opengl.GLES20.glLinkProgram;
import static android.opengl.GLES20.glUniformMatrix4fv;
import static android.opengl.GLES20.glUseProgram;
import static android.opengl.GLES20.glVertexAttribPointer;

public class Program extends Object {

  public static Program create() {
    return new Program(glCreateProgram());
  }
  
  private Program(int id) {
    super(id);
  }

  public Program attach(VertexShader vertexShader) {
    glAttachShader(id, vertexShader.id);
    return this;
  }

  public Program attach(FragmentShader fragmentShader) {
    glAttachShader(id, fragmentShader.id);
    return this;
  }

  public Program link() {
    glLinkProgram(id);
    return this;
  }

  public int status() {
    int[] status = { 0 };
    
    glGetProgramiv(id, GL_LINK_STATUS, status, 0);
    
    return status[0];
  }

  public Program use() {
    glUseProgram(id);
    return this;
  }

  public Attribute getAttribute(String name) {
    return new Attribute(getAttribLocation(name));
  }

  public class Attribute extends Object {

    Attribute(int id) {
      super(id);
    }

    public Attribute enable() {
      glEnableVertexAttribArray(id);
      return this;
    }

    public Attribute set(int elements) {
      glVertexAttribPointer(id, elements, GL_FLOAT, false, 0, 0);
      return this;
    }

    public Attribute disable() {
      glDisableVertexAttribArray(id);
      return this;
    }
    
    public void delete() {
    }

  }

  int getAttribLocation(String name) {
    return glGetAttribLocation(id, name);
  }


  public Uniform getUniform(String name) {
    return new Uniform(getUniformLocation(name));
  }

  public class Uniform extends Object {

    Uniform(int id) {
      super(id);
    }

    public Uniform set(Transform transform) {
       glUniformMatrix4fv(id, 1, false, transform.getElements(), 0);
      return this;
    }

    public void delete() {
    }

  }

  int getUniformLocation(String name) {
    return glGetUniformLocation(id, name);
  }

  @Override
  public void delete() {
    glDeleteProgram(id);
  }
  
}




Java Source Code List

rucamzu.opengl.Buffer.java
rucamzu.opengl.FragmentShader.java
rucamzu.opengl.IndexBuffer.java
rucamzu.opengl.Object.java
rucamzu.opengl.Program.java
rucamzu.opengl.Shader.java
rucamzu.opengl.Transform.java
rucamzu.opengl.Vector.java
rucamzu.opengl.VertexBuffer.java
rucamzu.opengl.VertexShader.java
rucamzu.touchgloid.TouchgloidActivity.java
rucamzu.touchgloid.TouchgloidRenderer.java
rucamzu.touchgloid.TouchgloidView.java