Android Open Source - OpenGL-es3-android Texture Shader Program






From Project

Back to project page OpenGL-es3-android.

License

The source code is released under:

GNU General Public License

If you think the Android project OpenGL-es3-android 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 com.opengles3.demo.programs;
/*from ww  w.  j  a v a2 s  .  c o  m*/
import com.example.opengl_es_3_demo.R;

import android.content.Context;
import android.opengl.GLES30;

public class TextureShaderProgram extends ShaderProgram {
  //Uniform locations
  private final int uMatrixLocation;
  private final int uTextureUnitLocation;
  
  //Attribute locations
  private final int aPositionLocation;
  private final int aTextureCoordinatesLocation;
  
  public TextureShaderProgram(Context context){
    super(context, R.raw.texture_vertex_shader,R.raw.texture_fragment_shader);
    
    uMatrixLocation = GLES30.glGetUniformLocation(program, U_MATRIX);
    uTextureUnitLocation = GLES30.glGetUniformLocation(program, U_TEXTURE_UNIT);
    
    aPositionLocation = GLES30.glGetAttribLocation(program, A_POSITION);
    aTextureCoordinatesLocation = GLES30.glGetAttribLocation(program, A_TEXTURE_COORDINATES);
    
  }
  public void setUniforms(float[] matrix, int textureId){
    //pass the matrix to shader program
    GLES30.glUniformMatrix4fv(uMatrixLocation, 1, false, matrix, 0);
    //set active texture as unit 0
    GLES30.glActiveTexture(GLES30.GL_TEXTURE0);
    //bind texture to unit 0
    GLES30.glBindTexture(GLES30.GL_TEXTURE_2D, textureId);
    //inform sampler to use texture in shader from unit 0
    GLES30.glUniform1i(uTextureUnitLocation, 0);
    
    
  }
  public int getPositionAttributeLocation(){
    return aPositionLocation;
  }
  public int getTextureCoordinateAttributeLocation(){
    return aTextureCoordinatesLocation;
  }
}




Java Source Code List

com.opengles3.demo.GLRenderer.java
com.opengles3.demo.GLTextureView.java
com.opengles3.demo.MainActivity.java
com.opengles3.demo.geometry.ObjectBuilder.java
com.opengles3.demo.geometry.Shapes.java
com.opengles3.demo.geometry.VertexArray.java
com.opengles3.demo.objects.Mallet.java
com.opengles3.demo.objects.Puck.java
com.opengles3.demo.objects.Table.java
com.opengles3.demo.objects.TexturedTriangleFan.java
com.opengles3.demo.programs.ColorShaderProgram.java
com.opengles3.demo.programs.ShaderProgram.java
com.opengles3.demo.programs.TextureShaderProgram.java
com.opengles3.demo.tools.Debug.java
com.opengles3.demo.tools.Tools.java