Java Code Examples for android.opengl.GLES20#glEnableVertexAttribArray()

The following examples show how to use android.opengl.GLES20#glEnableVertexAttribArray() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RippleFilterRender.java    From rtmp-rtsp-stream-client-java with Apache License 2.0 6 votes vote down vote up
@Override
protected void drawFilter() {
  GLES20.glUseProgram(program);

  squareVertex.position(SQUARE_VERTEX_DATA_POS_OFFSET);
  GLES20.glVertexAttribPointer(aPositionHandle, 3, GLES20.GL_FLOAT, false,
      SQUARE_VERTEX_DATA_STRIDE_BYTES, squareVertex);
  GLES20.glEnableVertexAttribArray(aPositionHandle);

  squareVertex.position(SQUARE_VERTEX_DATA_UV_OFFSET);
  GLES20.glVertexAttribPointer(aTextureHandle, 2, GLES20.GL_FLOAT, false,
      SQUARE_VERTEX_DATA_STRIDE_BYTES, squareVertex);
  GLES20.glEnableVertexAttribArray(aTextureHandle);

  GLES20.glUniformMatrix4fv(uMVPMatrixHandle, 1, false, MVPMatrix, 0);
  GLES20.glUniformMatrix4fv(uSTMatrixHandle, 1, false, STMatrix, 0);
  GLES20.glUniform2f(uResolutionHandle, getWidth(), getHeight());
  GLES20.glUniform1f(uSpeedHandle, speed);
  float time = ((float) (System.currentTimeMillis() - START_TIME)) / 1000f;
  if (time >= 10) START_TIME += 10000;
  GLES20.glUniform1f(uTimeHandle, time);
  GLES20.glUniform1i(uSamplerHandle, 4);
  GLES20.glActiveTexture(GLES20.GL_TEXTURE4);
  GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, previousTexId);
}
 
Example 2
Source File: SharpnessFilterRender.java    From rtmp-rtsp-stream-client-java with Apache License 2.0 6 votes vote down vote up
@Override
protected void drawFilter() {
  GLES20.glUseProgram(program);

  squareVertex.position(SQUARE_VERTEX_DATA_POS_OFFSET);
  GLES20.glVertexAttribPointer(aPositionHandle, 3, GLES20.GL_FLOAT, false,
      SQUARE_VERTEX_DATA_STRIDE_BYTES, squareVertex);
  GLES20.glEnableVertexAttribArray(aPositionHandle);

  squareVertex.position(SQUARE_VERTEX_DATA_UV_OFFSET);
  GLES20.glVertexAttribPointer(aTextureHandle, 2, GLES20.GL_FLOAT, false,
      SQUARE_VERTEX_DATA_STRIDE_BYTES, squareVertex);
  GLES20.glEnableVertexAttribArray(aTextureHandle);

  GLES20.glUniformMatrix4fv(uMVPMatrixHandle, 1, false, MVPMatrix, 0);
  GLES20.glUniformMatrix4fv(uSTMatrixHandle, 1, false, STMatrix, 0);
  GLES20.glUniform2f(uStepSizeHandle, 1f / getWidth(), 1f / getHeight());
  GLES20.glUniform1f(uSharpnessHandle, sharpness);

  GLES20.glUniform1i(uSamplerHandle, 4);
  GLES20.glActiveTexture(GLES20.GL_TEXTURE4);
  GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, previousTexId);
}
 
Example 3
Source File: CameraGLRendererBase.java    From LPR with Apache License 2.0 6 votes vote down vote up
private void initShaders() {
    String strGLVersion = GLES20.glGetString(GLES20.GL_VERSION);
    if (strGLVersion != null)
        Log.i(LOGTAG, "OpenGL ES version: " + strGLVersion);

    GLES20.glClearColor(1.0f, 1.0f, 1.0f, 1.0f);

    progOES = loadShader(vss, fssOES);
    vPosOES = GLES20.glGetAttribLocation(progOES, "vPosition");
    vTCOES  = GLES20.glGetAttribLocation(progOES, "vTexCoord");
    GLES20.glEnableVertexAttribArray(vPosOES);
    GLES20.glEnableVertexAttribArray(vTCOES);

    prog2D  = loadShader(vss, fss2D);
    vPos2D = GLES20.glGetAttribLocation(prog2D, "vPosition");
    vTC2D  = GLES20.glGetAttribLocation(prog2D, "vTexCoord");
    GLES20.glEnableVertexAttribArray(vPos2D);
    GLES20.glEnableVertexAttribArray(vTC2D);
}
 
Example 4
Source File: GlPreview.java    From GPUVideo-android with MIT License 6 votes vote down vote up
public void draw(final int texName, final float[] mvpMatrix, final float[] stMatrix, final float aspectRatio) {
    useProgram();

    GLES20.glUniformMatrix4fv(getHandle("uMVPMatrix"), 1, false, mvpMatrix, 0);
    GLES20.glUniformMatrix4fv(getHandle("uSTMatrix"), 1, false, stMatrix, 0);
    GLES20.glUniform1f(getHandle("uCRatio"), aspectRatio);

    GLES20.glBindBuffer(GL_ARRAY_BUFFER, getVertexBufferName());
    GLES20.glEnableVertexAttribArray(getHandle("aPosition"));
    GLES20.glVertexAttribPointer(getHandle("aPosition"), VERTICES_DATA_POS_SIZE, GL_FLOAT, false, VERTICES_DATA_STRIDE_BYTES, VERTICES_DATA_POS_OFFSET);
    GLES20.glEnableVertexAttribArray(getHandle("aTextureCoord"));
    GLES20.glVertexAttribPointer(getHandle("aTextureCoord"), VERTICES_DATA_UV_SIZE, GL_FLOAT, false, VERTICES_DATA_STRIDE_BYTES, VERTICES_DATA_UV_OFFSET);

    GLES20.glActiveTexture(GL_TEXTURE0);
    GLES20.glBindTexture(texTarget, texName);
    GLES20.glUniform1i(getHandle(DEFAULT_UNIFORM_SAMPLER), 0);

    GLES20.glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);

    GLES20.glDisableVertexAttribArray(getHandle("aPosition"));
    GLES20.glDisableVertexAttribArray(getHandle("aTextureCoord"));
    GLES20.glBindBuffer(GL_ARRAY_BUFFER, 0);
    GLES20.glBindTexture(GL_TEXTURE_2D, 0);
}
 
Example 5
Source File: Triangle.java    From recordablesurfaceview with Apache License 2.0 5 votes vote down vote up
/**
 * Encapsulates the OpenGL ES instructions for drawing this shape.
 *
 * @param mvpMatrix - The Model View Project matrix in which to draw
 * this shape.
 */
public void draw(float[] mvpMatrix) {
    // Add program to OpenGL environment
    GLES20.glUseProgram(mProgram);

    // get handle to vertex shader's vPosition member
    mPositionHandle = GLES20.glGetAttribLocation(mProgram, "vPosition");

    // Enable a handle to the triangle vertices
    GLES20.glEnableVertexAttribArray(mPositionHandle);

    // Prepare the triangle coordinate data
    GLES20.glVertexAttribPointer(
            mPositionHandle, COORDS_PER_VERTEX,
            GLES20.GL_FLOAT, false,
            vertexStride, vertexBuffer);

    // get handle to fragment shader's vColor member
    mColorHandle = GLES20.glGetUniformLocation(mProgram, "vColor");

    // Set color for drawing the triangle
    GLES20.glUniform4fv(mColorHandle, 1, color, 0);

    // get handle to shape's transformation matrix
    mMVPMatrixHandle = GLES20.glGetUniformLocation(mProgram, "uMVPMatrix");
    MyGLRenderer.checkGlError("glGetUniformLocation");

    // Apply the projection and view transformation
    GLES20.glUniformMatrix4fv(mMVPMatrixHandle, 1, false, mvpMatrix, 0);
    MyGLRenderer.checkGlError("glUniformMatrix4fv");

    // Draw the triangle
    GLES20.glDrawArrays(GLES20.GL_TRIANGLES, 0, vertexCount);

    // Disable vertex array
    GLES20.glDisableVertexAttribArray(mPositionHandle);
}
 
Example 6
Source File: GLES20Canvas.java    From PhotoMovie with Apache License 2.0 5 votes vote down vote up
private void draw(ShaderParameter[] params, int type, int count, float x, float y, float width,
                  float height) {
    setMatrix(params, x, y, width, height);
    int positionHandle = params[INDEX_POSITION].handle;
    GLES20.glEnableVertexAttribArray(positionHandle);
    checkError();
    GLES20.glDrawArrays(type, 0, count);
    checkError();
    GLES20.glDisableVertexAttribArray(positionHandle);
    checkError();
}
 
Example 7
Source File: Painting.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
private void render(int mask, int color) {
    Shader shader = shaders.get(brush.isLightSaber() ? "blitWithMaskLight" : "blitWithMask");
    if (shader == null) {
        return;
    }

    GLES20.glUseProgram(shader.program);

    GLES20.glUniformMatrix4fv(shader.getUniform("mvpMatrix"), 1, false, FloatBuffer.wrap(renderProjection));
    GLES20.glUniform1i(shader.getUniform("texture"), 0);
    GLES20.glUniform1i(shader.getUniform("mask"), 1);
    Shader.SetColorUniform(shader.getUniform("color"), color);

    GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
    GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, getTexture());

    GLES20.glActiveTexture(GLES20.GL_TEXTURE1);
    GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mask);

    GLES20.glBlendFunc(GLES20.GL_ONE, GLES20.GL_ONE_MINUS_SRC_ALPHA);

    GLES20.glVertexAttribPointer(0, 2, GLES20.GL_FLOAT, false, 8, vertexBuffer);
    GLES20.glEnableVertexAttribArray(0);
    GLES20.glVertexAttribPointer(1, 2, GLES20.GL_FLOAT, false, 8, textureBuffer);
    GLES20.glEnableVertexAttribArray(1);

    GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, 4);

    Utils.HasGLError();
}
 
Example 8
Source File: Painting.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
private void render(int mask, int color) {
    Shader shader = shaders.get(brush.isLightSaber() ? "blitWithMaskLight" : "blitWithMask");
    if (shader == null) {
        return;
    }

    GLES20.glUseProgram(shader.program);

    GLES20.glUniformMatrix4fv(shader.getUniform("mvpMatrix"), 1, false, FloatBuffer.wrap(renderProjection));
    GLES20.glUniform1i(shader.getUniform("texture"), 0);
    GLES20.glUniform1i(shader.getUniform("mask"), 1);
    Shader.SetColorUniform(shader.getUniform("color"), color);

    GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
    GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, getTexture());

    GLES20.glActiveTexture(GLES20.GL_TEXTURE1);
    GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mask);

    GLES20.glBlendFunc(GLES20.GL_ONE, GLES20.GL_ONE_MINUS_SRC_ALPHA);

    GLES20.glVertexAttribPointer(0, 2, GLES20.GL_FLOAT, false, 8, vertexBuffer);
    GLES20.glEnableVertexAttribArray(0);
    GLES20.glVertexAttribPointer(1, 2, GLES20.GL_FLOAT, false, 8, textureBuffer);
    GLES20.glEnableVertexAttribArray(1);

    GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, 4);

    Utils.HasGLError();
}
 
Example 9
Source File: BackgroundRenderer.java    From augmentedreality with Apache License 2.0 4 votes vote down vote up
/**
 * Draws the AR background image. The image will be drawn such that virtual content rendered with
 * the matrices provided by {@link com.google.ar.core.Camera#getViewMatrix(float[], int)} and
 * {@link com.google.ar.core.Camera#getProjectionMatrix(float[], int, float, float)} will
 * accurately follow static physical objects. This must be called <b>before</b> drawing virtual
 * content.
 *
 * @param frame The last {@code Frame} returned by {@link Session#update()}.
 */
public void draw(Frame frame) {
  // If display rotation changed (also includes view size change), we need to re-query the uv
  // coordinates for the screen rect, as they may have changed as well.
  if (frame.hasDisplayGeometryChanged()) {
    frame.transformDisplayUvCoords(quadTexCoord, quadTexCoordTransformed);
  }

  // No need to test or write depth, the screen quad has arbitrary depth, and is expected
  // to be drawn first.
  GLES20.glDisable(GLES20.GL_DEPTH_TEST);
  GLES20.glDepthMask(false);

  GLES20.glBindTexture(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, textureId);

  GLES20.glUseProgram(quadProgram);

  // Set the vertex positions.
  GLES20.glVertexAttribPointer(
      quadPositionParam, COORDS_PER_VERTEX, GLES20.GL_FLOAT, false, 0, quadVertices);

  // Set the texture coordinates.
  GLES20.glVertexAttribPointer(
      quadTexCoordParam,
      TEXCOORDS_PER_VERTEX,
      GLES20.GL_FLOAT,
      false,
      0,
      quadTexCoordTransformed);

  // Enable vertex arrays
  GLES20.glEnableVertexAttribArray(quadPositionParam);
  GLES20.glEnableVertexAttribArray(quadTexCoordParam);

  GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, 4);

  // Disable vertex arrays
  GLES20.glDisableVertexAttribArray(quadPositionParam);
  GLES20.glDisableVertexAttribArray(quadTexCoordParam);

  // Restore the depth state for further drawing.
  GLES20.glDepthMask(true);
  GLES20.glEnable(GLES20.GL_DEPTH_TEST);

  ShaderUtil.checkGLError(TAG, "Draw");
}
 
Example 10
Source File: FullFrameTexture.java    From media-for-mobile with Apache License 2.0 4 votes vote down vote up
private void renderQuad(int aPosition) {
    GLES20.glVertexAttribPointer(aPosition, 2, GLES20.GL_BYTE, false, 0, fullQuadVertices);
    GLES20.glEnableVertexAttribArray(aPosition);
    GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, 4);
}
 
Example 11
Source File: BasicCustomVideoRenderer.java    From opentok-android-sdk-samples with MIT License 4 votes vote down vote up
@Override
public void onSurfaceCreated(GL10 gl, EGLConfig config) {
    GLES20.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);

    int vertexShader = loadShader(GLES20.GL_VERTEX_SHADER,
            vertexShaderCode);
    int fragmentShader = loadShader(GLES20.GL_FRAGMENT_SHADER,
            fragmentShaderCode);

    mProgram = GLES20.glCreateProgram(); // create empty OpenGL ES
    // Program
    GLES20.glAttachShader(mProgram, vertexShader); // add the vertex
    // shader to program
    GLES20.glAttachShader(mProgram, fragmentShader); // add the fragment
    // shader to
    // program
    GLES20.glLinkProgram(mProgram);

    int positionHandle = GLES20.glGetAttribLocation(mProgram,
            "aPosition");
    int textureHandle = GLES20.glGetAttribLocation(mProgram,
            "aTextureCoord");

    GLES20.glVertexAttribPointer(positionHandle, COORDS_PER_VERTEX,
            GLES20.GL_FLOAT, false, COORDS_PER_VERTEX * 4,
            mVertexBuffer);

    GLES20.glEnableVertexAttribArray(positionHandle);

    GLES20.glVertexAttribPointer(textureHandle,
            TEXTURECOORDS_PER_VERTEX, GLES20.GL_FLOAT, false,
            TEXTURECOORDS_PER_VERTEX * 4, mTextureBuffer);

    GLES20.glEnableVertexAttribArray(textureHandle);

    GLES20.glUseProgram(mProgram);
    int i = GLES20.glGetUniformLocation(mProgram, "Ytex");
    GLES20.glUniform1i(i, 0); /* Bind Ytex to texture unit 0 */

    i = GLES20.glGetUniformLocation(mProgram, "Utex");
    GLES20.glUniform1i(i, 1); /* Bind Utex to texture unit 1 */

    i = GLES20.glGetUniformLocation(mProgram, "Vtex");
    GLES20.glUniform1i(i, 2); /* Bind Vtex to texture unit 2 */

    mTextureWidth = 0;
    mTextureHeight = 0;
}
 
Example 12
Source File: BackgroundRenderer.java    From amazon-sumerian-arcore-starter-app with Apache License 2.0 4 votes vote down vote up
/**
 * Draws the AR background image.  The image will be drawn such that virtual content rendered
 * with the matrices provided by {@link com.google.ar.core.Camera#getViewMatrix(float[], int)}
 * and {@link com.google.ar.core.Camera#getProjectionMatrix(float[], int, float, float)} will
 * accurately follow static physical objects.
 * This must be called <b>before</b> drawing virtual content.
 *
 * @param frame The last {@code Frame} returned by {@link Session#update()}.
 */
public void draw(Frame frame) {
    // If display rotation changed (also includes view size change), we need to re-query the uv
    // coordinates for the screen rect, as they may have changed as well.
    if (frame.hasDisplayGeometryChanged()) {
        frame.transformDisplayUvCoords(mQuadTexCoord, mQuadTexCoordTransformed);
    }

    // No need to test or write depth, the screen quad has arbitrary depth, and is expected
    // to be drawn first.
    GLES20.glDisable(GLES20.GL_DEPTH_TEST);
    GLES20.glDepthMask(false);

    GLES20.glBindTexture(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, mTextureId);

    GLES20.glUseProgram(mQuadProgram);

    // Set the vertex positions.
    GLES20.glVertexAttribPointer(
            mQuadPositionParam, COORDS_PER_VERTEX, GLES20.GL_FLOAT, false, 0, mQuadVertices);

    // Set the texture coordinates.
    GLES20.glVertexAttribPointer(mQuadTexCoordParam, TEXCOORDS_PER_VERTEX,
            GLES20.GL_FLOAT, false, 0, mQuadTexCoordTransformed);

    // Enable vertex arrays
    GLES20.glEnableVertexAttribArray(mQuadPositionParam);
    GLES20.glEnableVertexAttribArray(mQuadTexCoordParam);

    GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, 4);

    // Disable vertex arrays
    GLES20.glDisableVertexAttribArray(mQuadPositionParam);
    GLES20.glDisableVertexAttribArray(mQuadTexCoordParam);

    // Restore the depth state for further drawing.
    GLES20.glDepthMask(true);
    GLES20.glEnable(GLES20.GL_DEPTH_TEST);

    ShaderUtil.checkGLError(TAG, "Draw");
}
 
Example 13
Source File: PositionColorShaderProgram.java    From 30-android-libraries-in-30-days with Apache License 2.0 4 votes vote down vote up
@Override
public void unbind(final GLState pGLState) {
	GLES20.glEnableVertexAttribArray(ShaderProgramConstants.ATTRIBUTE_TEXTURECOORDINATES_LOCATION);
	
	super.unbind(pGLState);
}
 
Example 14
Source File: Texture2dProgram.java    From IjkVRPlayer with Apache License 2.0 4 votes vote down vote up
/**
 * Issues the draw call.  Does the full setup on every call.
 *
 * @param mvpMatrix The 4x4 projection matrix.
 * @param vertexBuffer Buffer with vertex position data.
 * @param firstVertex Index of first vertex to use in vertexBuffer.
 * @param vertexCount Number of vertices in vertexBuffer.
 * @param coordsPerVertex The number of coordinates per vertex (e.g. x,y is 2).
 * @param vertexStride Width, in bytes, of the position data for each vertex (often
 *        vertexCount * sizeof(float)).
 * @param texMatrix A 4x4 transformation matrix for texture coords.  (Primarily intended
 *        for use with SurfaceTexture.)
 * @param texBuffer Buffer with vertex texture data.
 * @param texStride Width, in bytes, of the texture data for each vertex.
 */
public void draw(float[] mvpMatrix, FloatBuffer vertexBuffer, int firstVertex,
        int vertexCount, int coordsPerVertex, int vertexStride,
        float[] texMatrix, FloatBuffer texBuffer, int textureId, int texStride) {
    GlUtil.checkGlError("draw start");

    // Select the program.
    GLES20.glUseProgram(mProgramHandle);
    GlUtil.checkGlError("glUseProgram");

    // Set the texture.
    GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
    GLES20.glBindTexture(mTextureTarget, textureId);

    // Copy the model / view / projection matrix over.
    GLES20.glUniformMatrix4fv(muMVPMatrixLoc, 1, false, mvpMatrix, 0);
    GlUtil.checkGlError("glUniformMatrix4fv");

    // Copy the texture transformation matrix over.
    GLES20.glUniformMatrix4fv(muTexMatrixLoc, 1, false, texMatrix, 0);
    GlUtil.checkGlError("glUniformMatrix4fv");

    // Enable the "aPosition" vertex attribute.
    GLES20.glEnableVertexAttribArray(maPositionLoc);
    GlUtil.checkGlError("glEnableVertexAttribArray");

    // Connect vertexBuffer to "aPosition".
    GLES20.glVertexAttribPointer(maPositionLoc, coordsPerVertex,
        GLES20.GL_FLOAT, false, vertexStride, vertexBuffer);
    GlUtil.checkGlError("glVertexAttribPointer");

    // Enable the "aTextureCoord" vertex attribute.
    GLES20.glEnableVertexAttribArray(maTextureCoordLoc);
    GlUtil.checkGlError("glEnableVertexAttribArray");

    // Connect texBuffer to "aTextureCoord".
    GLES20.glVertexAttribPointer(maTextureCoordLoc, 2,
            GLES20.GL_FLOAT, false, texStride, texBuffer);
        GlUtil.checkGlError("glVertexAttribPointer");

    // Populate the convolution kernel, if present.
    if (muKernelLoc >= 0) {
        GLES20.glUniform1fv(muKernelLoc, KERNEL_SIZE, mKernel, 0);
        GLES20.glUniform2fv(muTexOffsetLoc, KERNEL_SIZE, mTexOffset, 0);
        GLES20.glUniform1f(muColorAdjustLoc, mColorAdjust);
    }

    // Draw the rect.
    GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, firstVertex, vertexCount);
    GlUtil.checkGlError("glDrawArrays");

    // Done -- disable vertex array, texture, and program.
    GLES20.glDisableVertexAttribArray(maPositionLoc);
    GLES20.glDisableVertexAttribArray(maTextureCoordLoc);
    GLES20.glBindTexture(mTextureTarget, 0);
    GLES20.glUseProgram(0);
}
 
Example 15
Source File: Texture2dProgram.java    From grafika with Apache License 2.0 4 votes vote down vote up
/**
 * Issues the draw call.  Does the full setup on every call.
 *
 * @param mvpMatrix The 4x4 projection matrix.
 * @param vertexBuffer Buffer with vertex position data.
 * @param firstVertex Index of first vertex to use in vertexBuffer.
 * @param vertexCount Number of vertices in vertexBuffer.
 * @param coordsPerVertex The number of coordinates per vertex (e.g. x,y is 2).
 * @param vertexStride Width, in bytes, of the position data for each vertex (often
 *        vertexCount * sizeof(float)).
 * @param texMatrix A 4x4 transformation matrix for texture coords.  (Primarily intended
 *        for use with SurfaceTexture.)
 * @param texBuffer Buffer with vertex texture data.
 * @param texStride Width, in bytes, of the texture data for each vertex.
 */
public void draw(float[] mvpMatrix, FloatBuffer vertexBuffer, int firstVertex,
        int vertexCount, int coordsPerVertex, int vertexStride,
        float[] texMatrix, FloatBuffer texBuffer, int textureId, int texStride) {
    GlUtil.checkGlError("draw start");

    // Select the program.
    GLES20.glUseProgram(mProgramHandle);
    GlUtil.checkGlError("glUseProgram");

    // Set the texture.
    GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
    GLES20.glBindTexture(mTextureTarget, textureId);

    // Copy the model / view / projection matrix over.
    GLES20.glUniformMatrix4fv(muMVPMatrixLoc, 1, false, mvpMatrix, 0);
    GlUtil.checkGlError("glUniformMatrix4fv");

    // Copy the texture transformation matrix over.
    GLES20.glUniformMatrix4fv(muTexMatrixLoc, 1, false, texMatrix, 0);
    GlUtil.checkGlError("glUniformMatrix4fv");

    // Enable the "aPosition" vertex attribute.
    GLES20.glEnableVertexAttribArray(maPositionLoc);
    GlUtil.checkGlError("glEnableVertexAttribArray");

    // Connect vertexBuffer to "aPosition".
    GLES20.glVertexAttribPointer(maPositionLoc, coordsPerVertex,
        GLES20.GL_FLOAT, false, vertexStride, vertexBuffer);
    GlUtil.checkGlError("glVertexAttribPointer");

    // Enable the "aTextureCoord" vertex attribute.
    GLES20.glEnableVertexAttribArray(maTextureCoordLoc);
    GlUtil.checkGlError("glEnableVertexAttribArray");

    // Connect texBuffer to "aTextureCoord".
    GLES20.glVertexAttribPointer(maTextureCoordLoc, 2,
            GLES20.GL_FLOAT, false, texStride, texBuffer);
        GlUtil.checkGlError("glVertexAttribPointer");

    // Populate the convolution kernel, if present.
    if (muKernelLoc >= 0) {
        GLES20.glUniform1fv(muKernelLoc, KERNEL_SIZE, mKernel, 0);
        GLES20.glUniform2fv(muTexOffsetLoc, KERNEL_SIZE, mTexOffset, 0);
        GLES20.glUniform1f(muColorAdjustLoc, mColorAdjust);
    }

    // Draw the rect.
    GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, firstVertex, vertexCount);
    GlUtil.checkGlError("glDrawArrays");

    // Done -- disable vertex array, texture, and program.
    GLES20.glDisableVertexAttribArray(maPositionLoc);
    GLES20.glDisableVertexAttribArray(maTextureCoordLoc);
    GLES20.glBindTexture(mTextureTarget, 0);
    GLES20.glUseProgram(0);
}
 
Example 16
Source File: RRGLProgramColour.java    From RedReader with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void onActivated() {
	super.onActivated();
	GLES20.glEnableVertexAttribArray(mColorHandle);
}
 
Example 17
Source File: GLSprite.java    From Tanks with MIT License 4 votes vote down vote up
@Override
public void draw(RendererContext context)
{
  Data data = dataProvider.get();
  Vector3 color = data.colorCoefficients;
  ShaderSprite shader = (ShaderSprite)Shader.getCurrent();

  // get dynamic resources
  Image image = GameContext.resources.getImage(new FileImageSource(data.imageName));
  Texture textureData = GameContext.resources.getTexture(new FileTextureSource(image.getTextureName(), false));

  // set texture matrix
  setTextureCoordinates(image.getCoordinates());

  // build result matrix
  Matrix.multiplyMM(modelViewMatrix, 0, context.getOrthoMatrix(), 0, data.modelMatrix, 0);

  // bind texture to 0 slot
  GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
  GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, textureData.getHandle());

  // send data to shader
  GLES20.glUniform1i(shader.uniformTextureHandle, 0);
  GLES20.glUniformMatrix3fv(shader.uniformTextureMatrixHandle, 1, false, textureMatrix.getArray(), 0);
  GLES20.glUniformMatrix4fv(shader.uniformModelViewMatrixHandle, 1, false, modelViewMatrix, 0);
  GLES20.glUniform4f(shader.uniformColorCoefficients, color.getX(), color.getY(), color.getZ(), 1);

  // set buffer or reset if dynamic
  GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, geometryData.getHandle());

  switch (geometryData.getMode())
  {
  case Static:
    GLES20.glVertexAttribPointer(shader.attributePositionHandle, 2, GLES20.GL_FLOAT, false, 16, 0);
    GLES20.glVertexAttribPointer(shader.attributeTexCoordHandle, 2, GLES20.GL_FLOAT, false, 16, 8);
    break;

  case Dynamic:
    FloatBuffer buffer = geometryData.getData();
    buffer.position(0);
    GLES20.glVertexAttribPointer(shader.attributePositionHandle, 2, GLES20.GL_FLOAT, false, 16, buffer);
    buffer.position(2);
    GLES20.glVertexAttribPointer(shader.attributeTexCoordHandle, 2, GLES20.GL_FLOAT, false, 16, buffer);
    break;
  }

  // enable arrays
  GLES20.glEnableVertexAttribArray(shader.attributePositionHandle);
  GLES20.glEnableVertexAttribArray(shader.attributeTexCoordHandle);

  // validating if debug
  shader.validate();
  geometryData.validate();
  textureData.validate();

  // draw
  GLES20.glDrawArrays(GLES20.GL_TRIANGLES, 0, geometryData.getPointsCount());

  // disable arrays
  GLES20.glDisableVertexAttribArray(shader.attributePositionHandle);
  GLES20.glDisableVertexAttribArray(shader.attributeTexCoordHandle);

  // release dynamic resources
  GameContext.resources.release(image);
  GameContext.resources.release(textureData);
}
 
Example 18
Source File: GLDrawer.java    From Building-Android-UIs-with-Custom-Views with MIT License 4 votes vote down vote up
@Override
public void onDrawFrame(GL10 unused) {
    angle = ((float) SystemClock.elapsedRealtime() - startTime) * 0.02f;
    GLES20.glClearColor(1.0f, 0.0f, 0.0f, 1.0f);
    GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT | GLES20.GL_DEPTH_BUFFER_BIT);

    Matrix.setLookAtM(mViewMatrix, 0,
            0, 0, -4,
            0f, 0f, 0f,
            0f, 1.0f, 0.0f);

    Matrix.multiplyMM(mMVPMatrix, 0, mProjectionMatrix, 0, mViewMatrix, 0);
    Matrix.rotateM(mMVPMatrix, 0, angle, 1.f, 1.f, 1.f);

    GLES20.glUseProgram(shaderProgram);

    int positionHandle = GLES20.glGetAttribLocation(shaderProgram, "vPosition");

    GLES20.glVertexAttribPointer(positionHandle, 3,
            GLES20.GL_FLOAT, false,
            0, vertexBuffer);

    int texCoordHandle = GLES20.glGetAttribLocation(shaderProgram, "aTex");
    GLES20.glVertexAttribPointer(texCoordHandle, 2,
            GLES20.GL_FLOAT, false,
            0, texBuffer);

    int mMVPMatrixHandle = GLES20.glGetUniformLocation(shaderProgram, "uMVPMatrix");

    GLES20.glUniformMatrix4fv(mMVPMatrixHandle, 1, false, mMVPMatrix, 0);

    int texHandle = GLES20.glGetUniformLocation(shaderProgram, "sTex");
    GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
    GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, textureId);
    GLES20.glUniform1i(texHandle, 0);

    GLES20.glEnable(GLES20.GL_DEPTH_TEST);
    GLES20.glEnableVertexAttribArray(texHandle);
    GLES20.glEnableVertexAttribArray(positionHandle);
    GLES20.glDrawElements(
            GLES20.GL_TRIANGLES, index.length,
            GLES20.GL_UNSIGNED_SHORT, indexBuffer);

    GLES20.glDisableVertexAttribArray(positionHandle);
    GLES20.glDisableVertexAttribArray(texHandle);
    GLES20.glDisable(GLES20.GL_DEPTH_TEST);
}
 
Example 19
Source File: GLParticles.java    From Tanks with MIT License 4 votes vote down vote up
@Override
protected void draw(RendererContext context, Data data)
{
  if (isEnabled())
    particles.update();

  ShaderParticles shader = (ShaderParticles) Shader.getCurrent();

  // build result matrix
  Matrix.multiplyMM(modelProjectionViewMatrix, 0, context.getProjectionViewMatrix(), 0, modelMatrix, 0);

  // bind texture to 0 slot
  GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
  GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, textureData.getHandle());

  // send data to shader
  float life = count * updateTimeout;
  GLES20.glUniform2f(shader.uniformLifeTimeHandle, life, particles.getTime());
  GLES20.glUniformMatrix4fv(shader.uniformMatrixHandle, 1, false, modelProjectionViewMatrix, 0);
  GLES20.glUniform1i(shader.uniformTextureHandle, 0);
  GLES20.glUniform2f(shader.uniformPointSize, startPointSize, endPointSize);
  GLES20.glUniform4fv(shader.uniformStartColor, 1, startColor.getRaw(), 0);
  GLES20.glUniform4fv(shader.uniformEndColor, 1, endColor.getRaw(), 0);

  // reset array buffer
  GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, 0);

  // set offsets to arrays for buffer
  FloatBuffer buffer = particles.getBuffer();
  buffer.position(0);
  GLES20.glVertexAttribPointer(shader.attributeDirectionVectorHandle, 3, GLES20.GL_FLOAT, false, 16, buffer);
  buffer.position(3);
  GLES20.glVertexAttribPointer(shader.attributeStartTimeHandle, 1, GLES20.GL_FLOAT, false, 16, buffer);

  // enable attribute arrays
  GLES20.glEnableVertexAttribArray(shader.attributeDirectionVectorHandle);
  GLES20.glEnableVertexAttribArray(shader.attributeStartTimeHandle);

  // validating if debug
  shader.validate();

  // draw
  GLES20.glDrawArrays(GLES20.GL_POINTS, 0, particles.getCount());

  // disable attribute arrays
  GLES20.glDisableVertexAttribArray(shader.attributeDirectionVectorHandle);
  GLES20.glDisableVertexAttribArray(shader.attributeStartTimeHandle);

  // auto unbind if max time reached
  if (maxTime > 0 && particles.getTime() > maxTime && !unbinded)
  {
    unbinded = true;
    unbind();
  }
}
 
Example 20
Source File: VideoResourceInput.java    From UltimateAndroid with Apache License 2.0 votes vote down vote up
@Override
	protected void passShaderValues() {
		renderVertices.position(0);
		GLES20.glVertexAttribPointer(positionHandle, 2, GLES20.GL_FLOAT, false, 8, renderVertices);  
		GLES20.glEnableVertexAttribArray(positionHandle); 
		textureVertices[curRotation].position(0);
		GLES20.glVertexAttribPointer(texCoordHandle, 2, GLES20.GL_FLOAT, false, 8, textureVertices[curRotation]);  
		GLES20.glEnableVertexAttribArray(texCoordHandle); 
		
		bindTexture();
	    GLES20.glUniform1i(textureHandle, 0);
	    
	    videoTex.getTransformMatrix(matrix);
		GLES20.glUniformMatrix4fv(matrixHandle, 1, false, matrix, 0);
	}