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

The following examples show how to use android.opengl.GLES20#glVertexAttribPointer() . 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: FeatureShader.java    From geoar-app with Apache License 2.0 6 votes vote down vote up
public void setColors(final int colorBufferHandle) {
	if (colorBufferHandle < 0) {
		LOG.debug("colorbufferhandle is not a valid handle");
		return;
	}
	if (programHandle == -1) {
		initProgram();
	}

	if (colorHandle >= 0) {
		GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, colorBufferHandle);
		GLES20.glVertexAttribPointer(colorHandle, 4, GLES20.GL_FLOAT,
				false, 0, 0);
		GLES20.glEnableVertexAttribArray(colorHandle);
	}
}
 
Example 2
Source File: PhotoFilterView.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
private void drawSharpenPass() {
    GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, renderFrameBuffer[0]);
    GLES20.glFramebufferTexture2D(GLES20.GL_FRAMEBUFFER, GLES20.GL_COLOR_ATTACHMENT0, GLES20.GL_TEXTURE_2D, renderTexture[0], 0);
    GLES20.glClear(0);

    GLES20.glUseProgram(sharpenShaderProgram);
    GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
    GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, renderTexture[1]);
    GLES20.glUniform1i(sharpenSourceImageHandle, 0);
    if (showOriginal) {
        GLES20.glUniform1f(sharpenHandle, 0);
    } else {
        GLES20.glUniform1f(sharpenHandle, getSharpenValue());
    }
    GLES20.glUniform1f(sharpenWidthHandle, renderBufferWidth);
    GLES20.glUniform1f(sharpenHeightHandle, renderBufferHeight);
    GLES20.glEnableVertexAttribArray(sharpenInputTexCoordHandle);
    GLES20.glVertexAttribPointer(sharpenInputTexCoordHandle, 2, GLES20.GL_FLOAT, false, 8, textureBuffer);
    GLES20.glEnableVertexAttribArray(sharpenPositionHandle);
    GLES20.glVertexAttribPointer(sharpenPositionHandle, 2, GLES20.GL_FLOAT, false, 8, vertexInvertBuffer);
    GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, 4);
}
 
Example 3
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 4
Source File: GLES20Canvas.java    From TurboLauncher with Apache License 2.0 5 votes vote down vote up
private void setPosition(ShaderParameter[] params, int offset) {
    GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, mBoxCoordinates);
    checkError();
    GLES20.glVertexAttribPointer(params[INDEX_POSITION].handle, COORDS_PER_VERTEX,
            GLES20.GL_FLOAT, false, VERTEX_STRIDE, offset * VERTEX_STRIDE);
    checkError();
    GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, 0);
    checkError();
}
 
Example 5
Source File: MDAbsObject3D.java    From MD360Player4Android with Apache License 2.0 5 votes vote down vote up
public void uploadVerticesBufferIfNeed(MD360Program program, int index){
    FloatBuffer vertexBuffer = getVerticesBuffer(index);
    if (vertexBuffer == null) return;

    vertexBuffer.position(0);

    // set data to OpenGL
    int positionHandle = program.getPositionHandle();
    GLES20.glVertexAttribPointer(positionHandle, sPositionDataSize, GLES20.GL_FLOAT, false, 0, vertexBuffer);
    GLES20.glEnableVertexAttribArray(positionHandle);

}
 
Example 6
Source File: MDAbsObject3D.java    From Beginner-Level-Android-Studio-Apps with GNU General Public License v3.0 5 votes vote down vote up
public void uploadVerticesBufferIfNeed(MD360Program program, int index){
    FloatBuffer vertexBuffer = getVerticesBuffer(index);
    if (vertexBuffer == null) return;

    vertexBuffer.position(0);

    // set data to OpenGL
    int positionHandle = program.getPositionHandle();
    GLES20.glVertexAttribPointer(positionHandle, sPositionDataSize, GLES20.GL_FLOAT, false, 0, vertexBuffer);
    GLES20.glEnableVertexAttribArray(positionHandle);

}
 
Example 7
Source File: TextureRenderer.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
public void drawFrame(SurfaceTexture st, boolean invert) {
    checkGlError("onDrawFrame start");
    st.getTransformMatrix(mSTMatrix);

    if (invert) {
        mSTMatrix[5] = -mSTMatrix[5];
        mSTMatrix[13] = 1.0f - mSTMatrix[13];
    }

    GLES20.glUseProgram(mProgram);
    checkGlError("glUseProgram");
    GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
    GLES20.glBindTexture(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, mTextureID);
    mTriangleVertices.position(TRIANGLE_VERTICES_DATA_POS_OFFSET);
    GLES20.glVertexAttribPointer(maPositionHandle, 3, GLES20.GL_FLOAT, false, TRIANGLE_VERTICES_DATA_STRIDE_BYTES, mTriangleVertices);
    checkGlError("glVertexAttribPointer maPosition");
    GLES20.glEnableVertexAttribArray(maPositionHandle);
    checkGlError("glEnableVertexAttribArray maPositionHandle");
    mTriangleVertices.position(TRIANGLE_VERTICES_DATA_UV_OFFSET);
    GLES20.glVertexAttribPointer(maTextureHandle, 2, GLES20.GL_FLOAT, false, TRIANGLE_VERTICES_DATA_STRIDE_BYTES, mTriangleVertices);
    checkGlError("glVertexAttribPointer maTextureHandle");
    GLES20.glEnableVertexAttribArray(maTextureHandle);
    checkGlError("glEnableVertexAttribArray maTextureHandle");

    GLES20.glUniformMatrix4fv(muSTMatrixHandle, 1, false, mSTMatrix, 0);
    GLES20.glUniformMatrix4fv(muMVPMatrixHandle, 1, false, mMVPMatrix, 0);
    GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, 4);
    checkGlError("glDrawArrays");
    GLES20.glFinish();
}
 
Example 8
Source File: MyOSDReceiverRenderer.java    From myMediaCodecPlayer-for-FPV with MIT License 5 votes vote down vote up
public void draw(float[] viewM){
    GLES20.glUseProgram(mProgram);
    GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, buffers[0]);
    GLES20.glEnableVertexAttribArray(mPositionHandle);
    GLES20.glVertexAttribPointer(mPositionHandle, mPositionDataSize, GLES20.GL_FLOAT, false, mStrideBytes, 0);
    GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, buffers[0]);
    GLES20.glEnableVertexAttribArray(mColorHandle);
    GLES20.glVertexAttribPointer(mColorHandle, mColorDataSize,
            GLES20.GL_FLOAT, false, mStrideBytes, mColorOffset * mBytesPerFloat);
    if(enable_height){
        Matrix.multiplyMM(mMVPM, 0, viewM, 0, mHeightModelM, 0);
        Matrix.multiplyMM(mMVPM, 0, mProjM, 0, mMVPM, 0);
        GLES20.glUniformMatrix4fv(mMVPMatrixHandle, 1, false, mMVPM, 0);
        GLES20.glDrawArrays(GLES20.GL_TRIANGLES, 0, 18 * 6);
    }
    if(enable_model){
        Matrix.multiplyMM(mMVPM, 0, viewM, 0, mKopterModelM, 0);
        Matrix.multiplyMM(mMVPM, 0, mProjM, 0, mMVPM, 0);
        GLES20.glUniformMatrix4fv(mMVPMatrixHandle, 1, false, mMVPM, 0);
        GLES20.glDrawArrays(GLES20.GL_TRIANGLES, 18*6, 5*3);
    }
    if(enable_height){
        GLES20.glDrawArrays(GLES20.GL_TRIANGLES, (18*6)+(5*3), 2*3);
    }
    if(enable_home_arrow){
        Matrix.multiplyMM(mMVPM, 0, viewM, 0, mHomeArrowModelM, 0);
        Matrix.multiplyMM(mMVPM, 0, mProjM, 0, mMVPM, 0);
        GLES20.glUniformMatrix4fv(mMVPMatrixHandle, 1, false, mMVPM, 0);
        GLES20.glDrawArrays(GLES20.GL_TRIANGLES, (18*6)+(7*3), 3);
    }
    GLES20.glDisableVertexAttribArray(mPositionHandle);
    GLES20.glDisableVertexAttribArray(mColorHandle);
    GLES20.glDisableVertexAttribArray(mMVPMatrixHandle);
    GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, 0);
}
 
Example 9
Source File: ProgramLandmarks.java    From sealrtc-android with MIT License 5 votes vote down vote up
@Override
public void drawFrame(int textureId, float[] texMatrix, float[] mvpMatrix) {
    // Add program to OpenGL environment
    GLES20.glUseProgram(mProgramHandle);

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

    // Prepare the triangle coordinate data
    GLES20.glVertexAttribPointer(
            mPositionHandle,
            Drawable2d.COORDS_PER_VERTEX,
            GLES20.GL_FLOAT,
            false,
            Drawable2d.VERTEXTURE_STRIDE,
            mDrawable2d.vertexArray());

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

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

    GLES20.glUniform1f(mPointSizeHandle, POINT_SIZE);

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

    // Disable vertex array
    GLES20.glDisableVertexAttribArray(mPositionHandle);
    GLES20.glUseProgram(0);
}
 
Example 10
Source File: ProgramTextureOES.java    From PLDroidShortVideo with Apache License 2.0 4 votes vote down vote up
@Override
public void drawFrame(int textureId, float[] texMatrix, float[] mvpMatrix) {
    GlUtil.checkGlError("draw start");

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

    // Set the texture.
    GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
    GLES20.glBindTexture(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, 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, Drawable2d.COORDS_PER_VERTEX,
            GLES20.GL_FLOAT, false, Drawable2d.VERTEXTURE_STRIDE, mDrawable2d.vertexArray());
    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, Drawable2d.TEXTURE_COORD_STRIDE, mDrawable2d.texCoordArray());
    GlUtil.checkGlError("glVertexAttribPointer");

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

    // Done -- disable vertex array, texture, and program.
    GLES20.glDisableVertexAttribArray(maPositionLoc);
    GLES20.glDisableVertexAttribArray(maTextureCoordLoc);
    GLES20.glBindTexture(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, 0);
    GLES20.glUseProgram(0);
}
 
Example 11
Source File: Spheres.java    From ShapesInOpenGLES2.0 with MIT License 4 votes vote down vote up
/**
     * draws Sphere objects
     * @param aMVPMatrix
     */
    public void render(float[] aMVPMatrix) {

        if(BLENDING) {
            // Enable blending
            GLES20.glEnable(GLES20.GL_BLEND);
//            GLES20.glBlendFuncSeparate(GLES20.GL_ONE_MINUS_SRC_COLOR, GLES20.GL_ONE_MINUS_DST_COLOR, GLES20.GL_ONE_MINUS_SRC_ALPHA, GLES20.GL_ONE_MINUS_DST_ALPHA);
            GLES20.glBlendFunc( GLES20.GL_ONE_MINUS_SRC_ALPHA, GLES20.GL_ONE_MINUS_DST_ALPHA);

//            GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT);
        }
        // Set our per-vertex lighting program.
        GLES20.glUseProgram(aSphereProgramHandle);

        int aSphereMVPMatrixHandle = GLES20.glGetUniformLocation(aSphereProgramHandle, "u_MVPMatrix");
        int aSpherePositionHandle = GLES20.glGetAttribLocation(aSphereProgramHandle, "a_Position");
        int aSphereColorHandle = GLES20.glGetAttribLocation(aSphereProgramHandle, "a_Color");

        // Pass in the combined matrix.
        //GLES20.glUniformMatrix4fv(aMVPMatrixHandle, 1, false, aMVPMatrix, 0);
        GLES20.glUniformMatrix4fv(aSphereMVPMatrixHandle, 1, false, aMVPMatrix, 0);

        GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, aSpheresVerticesBufferIdx);
        GLES20.glEnableVertexAttribArray(aSpherePositionHandle);
        GLES20.glVertexAttribPointer(aSpherePositionHandle, POSITION_DATA_SIZE, GLES20.GL_FLOAT, false, 0, 0);

        GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, aSpheresColorsBufferIdx);
        GLES20.glEnableVertexAttribArray(aSphereColorHandle);
        GLES20.glVertexAttribPointer(aSphereColorHandle, COLOR_DATA_SIZE , GLES20.GL_FLOAT, false, 0, 0);

        GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, 0);

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

        // draw the vertices using indices
//            GLES20.glBindBuffer(GLES20.GL_ELEMENT_ARRAY_BUFFER, aSphereIndicesBufferIdx);
//            GLES20.glDrawElements(GLES20.GL_TRIANGLE_STRIP, indexCount, GLES20.GL_UNSIGNED_SHORT, 0);

        // Clear the currently bound buffer (so future OpenGL calls do not use this buffer).
//            GLES20.glBindBuffer(GLES20.GL_ELEMENT_ARRAY_BUFFER, 0);

        if(BLENDING) {
            // Enable blending
            GLES20.glDisable(GLES20.GL_BLEND);
//            GLES20.glBlendFuncSeparate(GLES20.GL_ONE_MINUS_SRC_COLOR, GLES20.GL_ONE_MINUS_DST_COLOR, GLES20.GL_ONE_MINUS_SRC_ALPHA, GLES20.GL_ONE_MINUS_DST_ALPHA);

//            GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT);
        }
    }
 
Example 12
Source File: TextureRenderer.java    From Telegram with GNU General Public License v2.0 4 votes vote down vote up
public void drawFrame(SurfaceTexture st, boolean invert) {
    checkGlError("onDrawFrame start");
    if (isPhoto) {
        GLES20.glUseProgram(simpleShaderProgram);
        GLES20.glActiveTexture(GLES20.GL_TEXTURE0);

        GLES20.glUniform1i(simpleSourceImageHandle, 0);
        GLES20.glEnableVertexAttribArray(simpleInputTexCoordHandle);
        GLES20.glVertexAttribPointer(maTextureHandle, 2, GLES20.GL_FLOAT, false, 8, textureBuffer);
        GLES20.glEnableVertexAttribArray(simplePositionHandle);
    } else {
        st.getTransformMatrix(mSTMatrix);

        if (blendEnabled) {
            GLES20.glDisable(GLES20.GL_BLEND);
            blendEnabled = false;
        }
        if (filterShaders != null) {
            filterShaders.onVideoFrameUpdate(mSTMatrix);

            GLES20.glViewport(0, 0, videoWidth, videoHeight);
            filterShaders.drawEnhancePass();
            filterShaders.drawSharpenPass();
            filterShaders.drawCustomParamsPass();
            boolean blurred = filterShaders.drawBlurPass();

            GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, 0);

            GLES20.glUseProgram(simpleShaderProgram);
            GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
            GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, filterShaders.getRenderTexture(blurred ? 0 : 1));

            GLES20.glUniform1i(simpleSourceImageHandle, 0);
            GLES20.glEnableVertexAttribArray(simpleInputTexCoordHandle);
            GLES20.glVertexAttribPointer(simpleInputTexCoordHandle, 2, GLES20.GL_FLOAT, false, 8, filterShaders.getTextureBuffer());
            GLES20.glEnableVertexAttribArray(simplePositionHandle);
            GLES20.glVertexAttribPointer(simplePositionHandle, 2, GLES20.GL_FLOAT, false, 8, filterShaders.getVertexBuffer());
            GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, 4);
        } else {
            if (invert) {
                mSTMatrix[5] = -mSTMatrix[5];
                mSTMatrix[13] = 1.0f - mSTMatrix[13];
            }
            GLES20.glUseProgram(mProgram);
            GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
            GLES20.glBindTexture(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, mTextureID);

            GLES20.glVertexAttribPointer(maPositionHandle, 2, GLES20.GL_FLOAT, false, 8, verticesBuffer);
            GLES20.glEnableVertexAttribArray(maPositionHandle);
            GLES20.glVertexAttribPointer(maTextureHandle, 2, GLES20.GL_FLOAT, false, 8, textureBuffer);
            GLES20.glEnableVertexAttribArray(maTextureHandle);

            GLES20.glUniformMatrix4fv(muSTMatrixHandle, 1, false, mSTMatrix, 0);
            GLES20.glUniformMatrix4fv(muMVPMatrixHandle, 1, false, mMVPMatrix, 0);
            GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, 4);

            if (paintTexture != null || stickerTexture != null) {
                GLES20.glUseProgram(simpleShaderProgram);
                GLES20.glActiveTexture(GLES20.GL_TEXTURE0);

                GLES20.glUniform1i(simpleSourceImageHandle, 0);
                GLES20.glEnableVertexAttribArray(simpleInputTexCoordHandle);
                GLES20.glVertexAttribPointer(maTextureHandle, 2, GLES20.GL_FLOAT, false, 8, textureBuffer);
                GLES20.glEnableVertexAttribArray(simplePositionHandle);
            }
        }
    }
    if (paintTexture != null) {
        for (int a = 0; a < paintTexture.length; a++) {
            drawTexture(true, paintTexture[a]);
        }
    }
    if (stickerTexture != null) {
        for (int a = 0, N = mediaEntities.size(); a < N; a++) {
            VideoEditedInfo.MediaEntity entity = mediaEntities.get(a);
            if (entity.ptr != 0) {
                RLottieDrawable.getFrame(entity.ptr, (int) entity.currentFrame, stickerBitmap, 512, 512, stickerBitmap.getRowBytes());
                GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, stickerTexture[0]);
                GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, stickerBitmap, 0);
                entity.currentFrame += entity.framesPerDraw;
                if (entity.currentFrame >= entity.metadata[0]) {
                    entity.currentFrame = 0;
                }
                drawTexture(false, stickerTexture[0], entity.x, entity.y, entity.width, entity.height, entity.rotation, (entity.subType & 2) != 0);
            } else if (entity.bitmap != null) {
                GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, stickerTexture[0]);
                GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, entity.bitmap, 0);
                drawTexture(false, stickerTexture[0], entity.x, entity.y, entity.width, entity.height, entity.rotation, (entity.subType & 2) != 0);
            }
        }
    }
    GLES20.glFinish();
}
 
Example 13
Source File: GlSceneRendererBackground.java    From ParticlesDrawable with Apache License 2.0 4 votes vote down vote up
void drawScene(@NonNull final float[] matrix) {
    if (hasTexture && width != 0 && height != 0) {
        ensureBackgroundTextureCoordiantes();
        ensureBackgroundCooridnates();

        backgroundTextureCoordinates.position(0);
        backgroundCoordinates.position(0);

        GLES20.glUseProgram(program);
        GLErrorChecker.checkGlError("background glUseProgram");

        final int positionHandle = GLES20.glGetAttribLocation(program, "vPosition");
        GLES20.glEnableVertexAttribArray(positionHandle);

        GLES20.glVertexAttribPointer(
                positionHandle,
                COORDINATES_PER_VERTEX,
                GLES20.GL_SHORT,
                false,
                0,
                backgroundCoordinates);

        final int texCoordHandle = GLES20.glGetAttribLocation(program, "aTexCoord");
        GLES20.glEnableVertexAttribArray(texCoordHandle);

        GLES20.glVertexAttribPointer(
                texCoordHandle,
                COORDINATES_PER_VERTEX,
                GLES20.GL_BYTE,
                false,
                0,
                backgroundTextureCoordinates);

        final int mvpMatrixHandle = GLES20.glGetUniformLocation(program, "uMVPMatrix");
        GLES20.glUniformMatrix4fv(mvpMatrixHandle, 1, false, matrix, 0);

        GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, textureId);
        GLES20.glDrawArrays(GLES20.GL_TRIANGLES, 0, 6);
        GLErrorChecker.checkGlError("background glDrawArrays");
    }
}
 
Example 14
Source File: TextureRenderer.java    From Telegram-FOSS with GNU General Public License v2.0 4 votes vote down vote up
public void drawFrame(SurfaceTexture st, boolean invert) {
    checkGlError("onDrawFrame start");
    if (isPhoto) {
        GLES20.glUseProgram(simpleShaderProgram);
        GLES20.glActiveTexture(GLES20.GL_TEXTURE0);

        GLES20.glUniform1i(simpleSourceImageHandle, 0);
        GLES20.glEnableVertexAttribArray(simpleInputTexCoordHandle);
        GLES20.glVertexAttribPointer(maTextureHandle, 2, GLES20.GL_FLOAT, false, 8, textureBuffer);
        GLES20.glEnableVertexAttribArray(simplePositionHandle);
    } else {
        st.getTransformMatrix(mSTMatrix);

        if (blendEnabled) {
            GLES20.glDisable(GLES20.GL_BLEND);
            blendEnabled = false;
        }
        if (filterShaders != null) {
            filterShaders.onVideoFrameUpdate(mSTMatrix);

            GLES20.glViewport(0, 0, videoWidth, videoHeight);
            filterShaders.drawEnhancePass();
            filterShaders.drawSharpenPass();
            filterShaders.drawCustomParamsPass();
            boolean blurred = filterShaders.drawBlurPass();

            GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, 0);

            GLES20.glUseProgram(simpleShaderProgram);
            GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
            GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, filterShaders.getRenderTexture(blurred ? 0 : 1));

            GLES20.glUniform1i(simpleSourceImageHandle, 0);
            GLES20.glEnableVertexAttribArray(simpleInputTexCoordHandle);
            GLES20.glVertexAttribPointer(simpleInputTexCoordHandle, 2, GLES20.GL_FLOAT, false, 8, filterShaders.getTextureBuffer());
            GLES20.glEnableVertexAttribArray(simplePositionHandle);
            GLES20.glVertexAttribPointer(simplePositionHandle, 2, GLES20.GL_FLOAT, false, 8, filterShaders.getVertexBuffer());
            GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, 4);
        } else {
            if (invert) {
                mSTMatrix[5] = -mSTMatrix[5];
                mSTMatrix[13] = 1.0f - mSTMatrix[13];
            }
            GLES20.glUseProgram(mProgram);
            GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
            GLES20.glBindTexture(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, mTextureID);

            GLES20.glVertexAttribPointer(maPositionHandle, 2, GLES20.GL_FLOAT, false, 8, verticesBuffer);
            GLES20.glEnableVertexAttribArray(maPositionHandle);
            GLES20.glVertexAttribPointer(maTextureHandle, 2, GLES20.GL_FLOAT, false, 8, textureBuffer);
            GLES20.glEnableVertexAttribArray(maTextureHandle);

            GLES20.glUniformMatrix4fv(muSTMatrixHandle, 1, false, mSTMatrix, 0);
            GLES20.glUniformMatrix4fv(muMVPMatrixHandle, 1, false, mMVPMatrix, 0);
            GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, 4);

            if (paintTexture != null || stickerTexture != null) {
                GLES20.glUseProgram(simpleShaderProgram);
                GLES20.glActiveTexture(GLES20.GL_TEXTURE0);

                GLES20.glUniform1i(simpleSourceImageHandle, 0);
                GLES20.glEnableVertexAttribArray(simpleInputTexCoordHandle);
                GLES20.glVertexAttribPointer(maTextureHandle, 2, GLES20.GL_FLOAT, false, 8, textureBuffer);
                GLES20.glEnableVertexAttribArray(simplePositionHandle);
            }
        }
    }
    if (paintTexture != null) {
        for (int a = 0; a < paintTexture.length; a++) {
            drawTexture(true, paintTexture[a]);
        }
    }
    if (stickerTexture != null) {
        for (int a = 0, N = mediaEntities.size(); a < N; a++) {
            VideoEditedInfo.MediaEntity entity = mediaEntities.get(a);
            if (entity.ptr != 0) {
                RLottieDrawable.getFrame(entity.ptr, (int) entity.currentFrame, stickerBitmap, 512, 512, stickerBitmap.getRowBytes());
                GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, stickerTexture[0]);
                GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, stickerBitmap, 0);
                entity.currentFrame += entity.framesPerDraw;
                if (entity.currentFrame >= entity.metadata[0]) {
                    entity.currentFrame = 0;
                }
                drawTexture(false, stickerTexture[0], entity.x, entity.y, entity.width, entity.height, entity.rotation, (entity.subType & 2) != 0);
            } else if (entity.bitmap != null) {
                GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, stickerTexture[0]);
                GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, entity.bitmap, 0);
                drawTexture(false, stickerTexture[0], entity.x, entity.y, entity.width, entity.height, entity.rotation, (entity.subType & 2) != 0);
            }
        }
    }
    GLES20.glFinish();
}
 
Example 15
Source File: InstantCameraView.java    From TelePlus-Android with GNU General Public License v2.0 4 votes vote down vote up
private void handleVideoFrameAvailable(long timestampNanos, Integer cameraId) {
    try {
        drainEncoder(false);
    } catch (Exception e) {
        FileLog.e(e);
    }
    long dt, alphaDt;
    if (!lastCameraId.equals(cameraId)) {
        lastTimestamp = -1;
        lastCameraId = cameraId;
    }
    if (lastTimestamp == -1) {
        lastTimestamp = timestampNanos;
        if (currentTimestamp != 0) {
            dt = (System.currentTimeMillis() - lastCommitedFrameTime) * 1000000;
            alphaDt = 0;
        } else {
            alphaDt = dt = 0;
        }
    } else {
        alphaDt = dt = (timestampNanos - lastTimestamp);
        lastTimestamp = timestampNanos;
    }
    lastCommitedFrameTime = System.currentTimeMillis();
    if (!skippedFirst) {
        skippedTime += dt;
        if (skippedTime < 200000000) {
            return;
        }
        skippedFirst = true;
    }
    currentTimestamp += dt;
    if (videoFirst == -1) {
        videoFirst = timestampNanos / 1000;
        if (BuildVars.LOGS_ENABLED) {
            FileLog.d("first video frame was at " + videoFirst);
        }
    }
    videoLast = timestampNanos;

    GLES20.glUseProgram(drawProgram);
    GLES20.glVertexAttribPointer(positionHandle, 3, GLES20.GL_FLOAT, false, 12, vertexBuffer);
    GLES20.glEnableVertexAttribArray(positionHandle);
    GLES20.glVertexAttribPointer(textureHandle, 2, GLES20.GL_FLOAT, false, 8, textureBuffer);
    GLES20.glEnableVertexAttribArray(textureHandle);
    GLES20.glUniform1f(scaleXHandle, scaleX);
    GLES20.glUniform1f(scaleYHandle, scaleY);
    GLES20.glUniformMatrix4fv(vertexMatrixHandle, 1, false, mMVPMatrix, 0);

    GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
    if (oldCameraTexture[0] != 0) {
        if (!blendEnabled) {
            GLES20.glEnable(GLES20.GL_BLEND);
            blendEnabled = true;
        }
        GLES20.glUniformMatrix4fv(textureMatrixHandle, 1, false, moldSTMatrix, 0);
        GLES20.glUniform1f(alphaHandle, 1.0f);
        GLES20.glBindTexture(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, oldCameraTexture[0]);
        GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, 4);
    }
    GLES20.glUniformMatrix4fv(textureMatrixHandle, 1, false, mSTMatrix, 0);
    GLES20.glUniform1f(alphaHandle, cameraTextureAlpha);
    GLES20.glBindTexture(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, cameraTexture[0]);
    GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, 4);

    GLES20.glDisableVertexAttribArray(positionHandle);
    GLES20.glDisableVertexAttribArray(textureHandle);
    GLES20.glBindTexture(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, 0);
    GLES20.glUseProgram(0);

    EGLExt.eglPresentationTimeANDROID(eglDisplay, eglSurface, currentTimestamp);
    EGL14.eglSwapBuffers(eglDisplay, eglSurface);

    if (oldCameraTexture[0] != 0 && cameraTextureAlpha < 1.0f) {
        cameraTextureAlpha += alphaDt / 200000000.0f;
        if (cameraTextureAlpha > 1) {
            GLES20.glDisable(GLES20.GL_BLEND);
            blendEnabled = false;
            cameraTextureAlpha = 1;
            GLES20.glDeleteTextures(1, oldCameraTexture, 0);
            oldCameraTexture[0] = 0;
            if (!cameraReady) {
                cameraReady = true;
            }
        }
    } else if (!cameraReady) {
        cameraReady = true;
    }
}
 
Example 16
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 17
Source File: VideoTextureRenderer.java    From AndroidOpenGLVideoDemo with Apache License 2.0 4 votes vote down vote up
@Override
protected boolean draw()
{
    synchronized (this)
    {
        if (frameAvailable)
        {
            videoTexture.updateTexImage();
            videoTexture.getTransformMatrix(videoTextureTransform);
            frameAvailable = false;
        }
        else
        {
            return false;
        }

    }

    if (adjustViewport)
        adjustViewport();

    GLES20.glClearColor(1.0f, 0.0f, 0.0f, 0.0f);
    GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT);

    // Draw texture
    GLES20.glUseProgram(shaderProgram);
    int textureParamHandle = GLES20.glGetUniformLocation(shaderProgram, "texture");
    int textureCoordinateHandle = GLES20.glGetAttribLocation(shaderProgram, "vTexCoordinate");
    int positionHandle = GLES20.glGetAttribLocation(shaderProgram, "vPosition");
    int textureTranformHandle = GLES20.glGetUniformLocation(shaderProgram, "textureTransform");

    GLES20.glEnableVertexAttribArray(positionHandle);
    GLES20.glVertexAttribPointer(positionHandle, 3, GLES20.GL_FLOAT, false, 4 * 3, vertexBuffer);

    GLES20.glBindTexture(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, textures[0]);
    GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
    GLES20.glUniform1i(textureParamHandle, 0);

    GLES20.glEnableVertexAttribArray(textureCoordinateHandle);
    GLES20.glVertexAttribPointer(textureCoordinateHandle, 4, GLES20.GL_FLOAT, false, 0, textureBuffer);

    GLES20.glUniformMatrix4fv(textureTranformHandle, 1, false, videoTextureTransform, 0);

    GLES20.glDrawElements(GLES20.GL_TRIANGLES, DRAW_ORDER.length, GLES20.GL_UNSIGNED_SHORT, drawListBuffer);
    GLES20.glDisableVertexAttribArray(positionHandle);
    GLES20.glDisableVertexAttribArray(textureCoordinateHandle);

    return true;
}
 
Example 18
Source File: Quad.java    From ShapesInOpenGLES2.0 with MIT License 4 votes vote down vote up
/**
     * draws Quad shape object.
     * @param aMVPMatrix
     * @param texture
     */
    public void render(float[] aMVPMatrix, final int texture) {
//        // Use culling to remove back faces.
        GLES20.glDisable(GLES20.GL_CULL_FACE);

        // Set our per-vertex lighting program.
        GLES20.glUseProgram(aQuadProgramHandle);

        // Set program handles for cube drawing.
        aMVPMatrixHandle = GLES20.glGetUniformLocation(aQuadProgramHandle, "u_MVPMatrix");
        aPositionHandle = GLES20.glGetAttribLocation(aQuadProgramHandle, "a_Position");
        aColorHandle = GLES20.glGetAttribLocation(aQuadProgramHandle, "a_Color");
        aTextureCoordinateHandle = GLES20.glGetAttribLocation(aQuadProgramHandle, "a_TexCoordinate");
        aTextureUniformHandle = GLES20.glGetUniformLocation(aQuadProgramHandle, "u_Texture");

        // Pass in the combined matrix.
        GLES20.glUniformMatrix4fv(aMVPMatrixHandle, 1, false, aMVPMatrix, 0);

        if (qvbo[0] > 0 && qibo[0] > 0) {
            GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, qvbo[0]);

            // Bind Attributes
            GLES20.glVertexAttribPointer(aPositionHandle, POSITION_DATA_SIZE, GLES20.GL_FLOAT, false,
                    STRIDE, 0);
            GLES20.glEnableVertexAttribArray(aPositionHandle);

            GLES20.glVertexAttribPointer(aColorHandle, COLOR_DATA_SIZE, GLES20.GL_FLOAT, false,
                    STRIDE, (POSITION_DATA_SIZE) * BYTES_PER_FLOAT);
            GLES20.glEnableVertexAttribArray(aColorHandle);

            GLES20.glVertexAttribPointer(aTextureCoordinateHandle, UV_DATA_SIZE, GLES20.GL_FLOAT, false,
                    STRIDE, (POSITION_DATA_SIZE + COLOR_DATA_SIZE) * BYTES_PER_FLOAT);
            GLES20.glEnableVertexAttribArray(aTextureCoordinateHandle);

            GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
            GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, texture);
            GLES20.glUniform1f(aTextureUniformHandle, 0);

            // Draw
            GLES20.glBindBuffer(GLES20.GL_ELEMENT_ARRAY_BUFFER, qibo[0]);
            GLES20.glDrawElements(GLES20.GL_TRIANGLE_STRIP, indexCount, GLES20.GL_UNSIGNED_SHORT, 0);

            GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, 0);
            GLES20.glBindBuffer(GLES20.GL_ELEMENT_ARRAY_BUFFER, 0);
        }

//        // Use culling to remove back faces.
//        GLES20.glEnable(GLES20.GL_CULL_FACE);
    }
 
Example 19
Source File: CameraGLRenderer.java    From VideoRecorder with Apache License 2.0 4 votes vote down vote up
private void drawTexture(int tex, boolean isOES, int fbo) {

        checkGlError("draw startRecord");
        GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, fbo);

        if (fbo == 0)
            GLES20.glViewport(0, 0, mSurfaceSize.getWidth(), mSurfaceSize.getHeight());
        else
            GLES20.glViewport(0, 0, mFBOWidth, mFBOHeight);

        GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT);

        if (isOES) {
            GLES20.glUseProgram(mProgramOES);
            checkGlError("glUseProgram");
            GLES20.glVertexAttribPointer(aPosOES, 2, GLES20.GL_FLOAT, false, 4 * 2, mVertexBuffer);
            checkGlError("glVertexAttribPointer");
            GLES20.glVertexAttribPointer(aTexCoordOES, 2, GLES20.GL_FLOAT, false, 4 * 2, mTexOESBuffer);
            checkGlError("glVertexAttribPointer");
            // Copy the model / view / projection matrix over.
            GLES20.glUniformMatrix4fv(uMVPMatrixOES, 1, false, mMVPMatrixOES, 0);
            checkGlError("glUniformMatrix4fv");
            // Copy the texture transformation matrix over.
            GLES20.glUniformMatrix4fv(uTexMatrixOES, 1, false, mTexMatrixOES, 0);
            checkGlError("glUniformMatrix4fv");

            GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
            GLES20.glBindTexture(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, tex);
            GLES20.glUniform1i(uTextureOES, 0);

        } else {
            GLES20.glUseProgram(mProgram2D);
            checkGlError("glUseProgram");
            GLES20.glVertexAttribPointer(vPos2D, 2, GLES20.GL_FLOAT, false, 4 * 2, mVertexBuffer);
            checkGlError("glVertexAttribPointer");
            GLES20.glVertexAttribPointer(vTexCoord2D, 2, GLES20.GL_FLOAT, false, 4 * 2, mTex2DBuffer);
            checkGlError("glVertexAttribPointer");
            // Copy the model / view / projection matrix over.
            GLES20.glUniformMatrix4fv(uMVPMatrix2D, 1, false, mMVPMatrix2D, 0);
            checkGlError("glUniformMatrix4fv");
            // Copy the texture transformation matrix over.
            GLES20.glUniformMatrix4fv(uTexMatrix2D, 1, false, mTexMatrix2D, 0);
            checkGlError("glUniformMatrix4fv");

            GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
            GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, tex);
            GLES20.glUniform1i(uTexture2D, 0);
        }

        GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, 4);
        checkGlError("glDrawArrays");
        GLES20.glUseProgram(0);
    }
 
Example 20
Source File: VideoResourceInput.java    From AndroidFastImageProcessing with MIT License 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);
	}