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

The following examples show how to use android.opengl.GLES20#glFinish() . 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: GlVideoRenderer.java    From LiTr with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/**
 * Draws the data from SurfaceTexture onto the current EGL surface.
 */
private void drawFrame(long presentationTimeNs) {
    initInputSurfaceTexture();

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

    triangleVertices.position(TRIANGLE_VERTICES_DATA_POS_OFFSET);
    GLES20.glVertexAttribPointer(aPositionHandle, 3, GLES20.GL_FLOAT, false,
            TRIANGLE_VERTICES_DATA_STRIDE_BYTES, triangleVertices);
    GlRenderUtils.checkGlError("glVertexAttribPointer maPosition");
    GLES20.glEnableVertexAttribArray(aPositionHandle);
    GlRenderUtils.checkGlError("glEnableVertexAttribArray aPositionHandle");
    triangleVertices.position(TRIANGLE_VERTICES_DATA_UV_OFFSET);
    GLES20.glVertexAttribPointer(aTextureHandle, 2, GLES20.GL_FLOAT, false,
            TRIANGLE_VERTICES_DATA_STRIDE_BYTES, triangleVertices);
    GlRenderUtils.checkGlError("glVertexAttribPointer aTextureHandle");
    GLES20.glEnableVertexAttribArray(aTextureHandle);
    GlRenderUtils.checkGlError("glEnableVertexAttribArray aTextureHandle");

    for (GlFilter filter : filters) {
        filter.apply(presentationTimeNs);
    }

    GLES20.glFinish();
}
 
Example 2
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 3
Source File: TextureRenderer.java    From VideoCompressor with Apache License 2.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 4
Source File: TextureRenderer.java    From SiliCompressor with Apache License 2.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 5
Source File: GSYVideoGLViewCustomRender2.java    From GSYVideoPlayer with Apache License 2.0 5 votes vote down vote up
@Override
public void onDrawFrame(GL10 glUnused) {
    super.onDrawFrame(glUnused);
    float[] transform = new float[16];
    Matrix.setIdentityM(transform, 0);
    Matrix.scaleM(transform, 0, 0.8f, 0.8f, 1);
    GLES20.glUniformMatrix4fv(getMuMVPMatrixHandle(), 1, false, transform, 0);
    GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, 4);
    GLES20.glFinish();
}
 
Example 6
Source File: TextureRenderer.java    From react-native-video-helper with MIT License 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 7
Source File: TextureRenderer.java    From VideoProcessor with Apache License 2.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: TextureRender.java    From android-transcoder with Apache License 2.0 5 votes vote down vote up
public void drawFrame(SurfaceTexture st) {
    checkGlError("onDrawFrame start");
    st.getTransformMatrix(mSTMatrix);
    GLES20.glClearColor(0.0f, 1.0f, 0.0f, 1.0f);
    GLES20.glClear(GLES20.GL_DEPTH_BUFFER_BIT | GLES20.GL_COLOR_BUFFER_BIT);
    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");
    Matrix.setIdentityM(mMVPMatrix, 0);
    GLES20.glUniformMatrix4fv(muMVPMatrixHandle, 1, false, mMVPMatrix, 0);
    GLES20.glUniformMatrix4fv(muSTMatrixHandle, 1, false, mSTMatrix, 0);
    GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, 4);
    checkGlError("glDrawArrays");
    GLES20.glFinish();
}
 
Example 9
Source File: GLProgram.java    From AndroidDemo with MIT License 5 votes vote down vote up
/**
 * render the frame
 * the YUV data will be converted to RGB by shader.
 */
public void drawFrame() {
    GLES20.glUseProgram(_program);
    checkGlError("glUseProgram");

    GLES20.glVertexAttribPointer(_positionHandle, 2, GLES20.GL_FLOAT, false, 8, _vertice_buffer);
    checkGlError("glVertexAttribPointer mPositionHandle");
    GLES20.glEnableVertexAttribArray(_positionHandle);

    GLES20.glVertexAttribPointer(_coordHandle, 2, GLES20.GL_FLOAT, false, 8, _coord_buffer);
    checkGlError("glVertexAttribPointer maTextureHandle");
    GLES20.glEnableVertexAttribArray(_coordHandle);

    // bind textures
    GLES20.glActiveTexture(_textureI);
    GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, _ytid);
    GLES20.glUniform1i(_yhandle, _tIindex);

    GLES20.glActiveTexture(_textureII);
    GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, _utid);
    GLES20.glUniform1i(_uhandle, _tIIindex);

    GLES20.glActiveTexture(_textureIII);
    GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, _vtid);
    GLES20.glUniform1i(_vhandle, _tIIIindex);

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

    GLES20.glDisableVertexAttribArray(_positionHandle);
    GLES20.glDisableVertexAttribArray(_coordHandle);
}
 
Example 10
Source File: TextureRender.java    From phoenix with Apache License 2.0 5 votes vote down vote up
public void drawFrame(SurfaceTexture st) {
    checkGlError("onDrawFrame start");
    st.getTransformMatrix(mSTMatrix);
    GLES20.glClearColor(0.0f, 1.0f, 0.0f, 1.0f);
    GLES20.glClear(GLES20.GL_DEPTH_BUFFER_BIT | GLES20.GL_COLOR_BUFFER_BIT);
    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");
    Matrix.setIdentityM(mMVPMatrix, 0);
    GLES20.glUniformMatrix4fv(muMVPMatrixHandle, 1, false, mMVPMatrix, 0);
    GLES20.glUniformMatrix4fv(muSTMatrixHandle, 1, false, mSTMatrix, 0);
    GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, 4);
    checkGlError("glDrawArrays");
    GLES20.glFinish();
}
 
Example 11
Source File: TextureRenderer.java    From talk-android with MIT License 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 12
Source File: TextureManager.java    From libstreaming with Apache License 2.0 5 votes vote down vote up
public void drawFrame() {	
	checkGlError("onDrawFrame start");
	mSurfaceTexture.getTransformMatrix(mSTMatrix);

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

	GLES20.glUseProgram(mProgram);
	checkGlError("glUseProgram");

	GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
	GLES20.glBindTexture(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, 0);
	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");

	Matrix.setIdentityM(mMVPMatrix, 0);
	GLES20.glUniformMatrix4fv(muMVPMatrixHandle, 1, false, mMVPMatrix, 0);
	GLES20.glUniformMatrix4fv(muSTMatrixHandle, 1, false, mSTMatrix, 0);

	GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, 4);
	checkGlError("glDrawArrays");
	GLES20.glFinish();
}
 
Example 13
Source File: MyGLRenderer.java    From myMediaCodecPlayer-for-FPV with MIT License 4 votes vote down vote up
@Override
public void onDrawFrame(GL10 glUnused) {
    //updateSurface=true;
    /*long timeBUpdate=System.currentTimeMillis();
    synchronized(this) {
        if (updateSurface) {
            mSurfaceTexture.updateTexImage();
            updateSurface = false;
        }
    }*/
    //long timeBUpdate=System.currentTimeMillis();
    //Danger: getTimestamp can't be used to compare with System.nanoTime or System.currentTimeMillis
    //because it's zero point depends on the sources providing the image;
    mSurfaceTexture.updateTexImage();
    GLES20.glFinish();
    /*mSurfaceTexture.updateTexImage();
    GLES20.glFinish();
    mSurfaceTexture.updateTexImage();
    GLES20.glFinish();
    mSurfaceTexture.updateTexImage();
    GLES20.glFinish();
    mSurfaceTexture.updateTexImage();
    GLES20.glFinish();*/
    //Log.w("renderer", "since last time: " + ((mSurfaceTexture.getTimestamp() - SurfaceTextureTimeB) / 1000));
    //SurfaceTextureTimeB=mSurfaceTexture.getTimestamp();
    //Log.w("MyGLRenderer","Time for updating:"+(System.currentTimeMillis()-timeBUpdate));
    //GLES20.glFinish();
    //GLES20.glFlush();
    /*if((System.currentTimeMillis()-timeBUpdate)>=12){
        Log.w("MyGLRenderer","Time for updating:"+(System.currentTimeMillis()-timeBUpdate));
    }*/
    GLES20.glClear(GLES20.GL_DEPTH_BUFFER_BIT | GLES20.GL_COLOR_BUFFER_BIT);
    GLES20.glUseProgram(mProgram);
    GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
    GLES20.glBindTexture(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);
    GLES20.glEnableVertexAttribArray(maPositionHandle);
    mTriangleVertices.position(TRIANGLE_VERTICES_DATA_UV_OFFSET);
    GLES20.glVertexAttribPointer(maTextureHandle, 3, GLES20.GL_FLOAT, false,
            TRIANGLE_VERTICES_DATA_STRIDE_BYTES, mTriangleVertices);
    GLES20.glEnableVertexAttribArray(maTextureHandle);
    Matrix.setIdentityM(mMVPMatrix, 0);
    GLES20.glUniformMatrix4fv(muMVPMatrixHandle, 1, false, mMVPMatrix, 0);
    GLES20.glUniformMatrix4fv(muSTMatrixHandle, 1, false, mSTMatrix, 0);
    GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, 4);
    GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 4, 8);
    //GLES20.glFinish();

    //
    zaehlerFramerate++;
    if((System.currentTimeMillis()-timeb)>1000) {
        //System.out.println("fps:"+(zaehlerFramerate/1));
        fps = (zaehlerFramerate / 1);
        timeb = System.currentTimeMillis();
        zaehlerFramerate = 0;
        Log.w("MyGLRenderer", "fps:" + fps);
    }
}
 
Example 14
Source File: GSYVideoGLViewCustomRender.java    From GSYVideoPlayer with Apache License 2.0 4 votes vote down vote up
@Override
public void onDrawFrame(GL10 glUnused) {
    super.onDrawFrame(glUnused);

    //curProgram = createProgram(getVertexShader(), mBitmapEffect.getShader(mSurfaceView));

    GLES20.glUseProgram(curProgram);
    checkGlError("glUseProgram");

    //绑定注入bitmap
    int mFilterInputTextureUniform2 = GLES20.glGetUniformLocation(curProgram, "sTexture2");
    GLES20.glActiveTexture(GLES20.GL_TEXTURE3);
    GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mTexturesBitmap[0]);
    GLES20.glUniform1i(mFilterInputTextureUniform2, mTexturesBitmap[0]);

    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, 3, 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.glEnable(GLES20.GL_BLEND);
    GLES20.glBlendFunc(GLES20.GL_SRC_ALPHA, GLES20.GL_ONE_MINUS_SRC_ALPHA);

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

    GLES20.glFinish();
    GLES20.glDisable(GLES20.GL_BLEND);
}
 
Example 15
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 16
Source File: RoundedTextureView.java    From android-RoundedTextureView with Apache License 2.0 4 votes vote down vote up
@Override public void onDrawFrame(GL10 glUnused) {
  synchronized (this) {
    if (updateSurface) {
      surfaceTexture.updateTexImage();
      surfaceTexture.getTransformMatrix(stMatrix);
      updateSurface = false;
    }
  }

  GLES20.glClearColor(.0f, .0f, .0f, .0f);
  int clearMask = GLES20.GL_COLOR_BUFFER_BIT | GLES20.GL_DEPTH_BUFFER_BIT;
  if (usesCoverageAa) {
    // Tegra weirdness
    clearMask |= GL_COVERAGE_BUFFER_BIT_NV;
  }
  GLES20.glClear(clearMask);

  GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_S,
      GLES20.GL_CLAMP_TO_EDGE);
  GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_T,
      GLES20.GL_CLAMP_TO_EDGE);

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

  GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
  GLES20.glBindTexture(GL_TEXTURE_EXTERNAL_OES, textureID);

  triangleVertices.position(TRIANGLE_VERTICES_DATA_POS_OFFSET);
  GLES20.glVertexAttribPointer(aPositionHandle, 3, GLES20.GL_FLOAT, false,
      TRIANGLE_VERTICES_DATA_STRIDE_BYTES, triangleVertices);
  checkGlError("glVertexAttribPointer aPosition");
  GLES20.glEnableVertexAttribArray(aPositionHandle);
  checkGlError("glEnableVertexAttribArray aPositionHandle");

  triangleVertices.position(TRIANGLE_VERTICES_DATA_UV_OFFSET);
  GLES20.glVertexAttribPointer(aTextureHandle, 3, GLES20.GL_FLOAT, false,
      TRIANGLE_VERTICES_DATA_STRIDE_BYTES, triangleVertices);
  checkGlError("glVertexAttribPointer aTextureHandle");
  GLES20.glEnableVertexAttribArray(aTextureHandle);
  checkGlError("glEnableVertexAttribArray aTextureHandle");

  Matrix.setIdentityM(mvpMatrix, 0);
  Matrix.scaleM(mvpMatrix, 0, 1f, 1f, 1f);
  GLES20.glUniformMatrix4fv(mvpMatrixHandle, 1, false, mvpMatrix, 0);
  GLES20.glUniformMatrix4fv(ustMatrixHandle, 1, false, stMatrix, 0);

  GLES20.glDrawElements(GLES20.GL_TRIANGLES, triangleIndicesData.length, GL10.GL_UNSIGNED_SHORT,
      triangleIndices);

  checkGlError("glDrawElements");
  GLES20.glFinish();
}
 
Example 17
Source File: BitmapUtil.java    From PLDroidShortVideo with Apache License 2.0 4 votes vote down vote up
/**
 * 读取图片(glReadPixels)
 *
 * @param textureId
 * @param mtx
 * @param mvp
 * @param texWidth
 * @param texHeight
 * @param listener
 * @param isOes     是否是OES纹理
 */
public static void glReadBitmap(int textureId, float[] mtx, float[] mvp, final int texWidth, final int texHeight, final OnReadBitmapListener listener,
                                boolean isOes) {
    final IntBuffer intBuffer = IntBuffer.allocate(texWidth * texHeight);
    int[] textures = new int[1];
    GLES20.glGenTextures(1, textures, 0);
    GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, textures[0]);
    GLES20.glTexImage2D(GLES20.GL_TEXTURE_2D, 0, GLES20.GL_RGBA, texWidth, texHeight, 0, GLES20.GL_RGBA, GLES20.GL_UNSIGNED_BYTE, null);
    int[] mFrameBuffers = new int[1];
    GLES20.glGenFramebuffers(1, mFrameBuffers, 0);
    GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
    GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, textures[0]);
    GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, mFrameBuffers[0]);
    GLES20.glFramebufferTexture2D(GLES20.GL_FRAMEBUFFER, GLES20.GL_COLOR_ATTACHMENT0, GLES20.GL_TEXTURE_2D, textures[0], 0);
    int viewport[] = new int[4];
    GLES20.glGetIntegerv(GLES20.GL_VIEWPORT, viewport, 0);
    GLES20.glViewport(0, 0, texWidth, texHeight);
    if (isOes)
        new ProgramTextureOES().drawFrame(textureId, mtx, mvp);
    else
        new ProgramTexture2d().drawFrame(textureId, mtx, mvp);
    GLES20.glReadPixels(0, 0, texWidth, texHeight, GL10.GL_RGBA, GL10.GL_UNSIGNED_BYTE, intBuffer);
    GLES20.glFinish();
    AsyncTask.execute(new Runnable() {
        @Override
        public void run() {
            final int bitmapSource[] = new int[texWidth * texHeight];
            int offset1, offset2;
            int[] data = intBuffer.array();
            for (int i = 0; i < texHeight; i++) {
                offset1 = i * texWidth;
                offset2 = (texHeight - i - 1) * texWidth;
                for (int j = 0; j < texWidth; j++) {
                    int texturePixel = data[offset1 + j];
                    int blue = (texturePixel >> 16) & 0xff;
                    int red = (texturePixel << 16) & 0x00ff0000;
                    int pixel = (texturePixel & 0xff00ff00) | red | blue | 0xff000000;
                    bitmapSource[offset2 + j] = pixel;
                }
            }
            final Bitmap shotCaptureBitmap = Bitmap.createBitmap(bitmapSource, texWidth, texHeight, Bitmap.Config.ARGB_8888).copy(Bitmap.Config.ARGB_8888, true);
            if (listener != null) {
                listener.onReadBitmapListener(shotCaptureBitmap);
            }
        }
    });
    GLES20.glViewport(viewport[0], viewport[1], viewport[2], viewport[3]);
    GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, 0);
    GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, 0);
    GLES20.glDeleteTextures(1, textures, 0);
    GLES20.glDeleteFramebuffers(1, mFrameBuffers, 0);
}
 
Example 18
Source File: VideoSurfaceView.java    From VideoChatHeads with The Unlicense 4 votes vote down vote up
public void onDrawFrame(GL10 glUnused) {
    synchronized(this) {
        if (mUpdateSurface) {
            mSurfaceTexture.updateTexImage();
            mSurfaceTexture.getTransformMatrix(mSTMatrix);
            mUpdateSurface = false;
        }
    }

    GLES20.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
    int clearMask = GLES20.GL_COLOR_BUFFER_BIT | GLES20.GL_DEPTH_BUFFER_BIT;
    if (mUsesCoverageAa) { // Tegra weirdness
        final int GL_COVERAGE_BUFFER_BIT_NV = 0x8000;
        clearMask |= GL_COVERAGE_BUFFER_BIT_NV;
    }
    GLES20.glClear(clearMask);

    GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_S,
            GLES20.GL_CLAMP_TO_EDGE);
    GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_T,
            GLES20.GL_CLAMP_TO_EDGE);

    GLES20.glUseProgram(mProgram);
    checkGlError("glUseProgram");

    GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
    GLES20.glBindTexture(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, 3, GLES20.GL_FLOAT, false,
            TRIANGLE_VERTICES_DATA_STRIDE_BYTES, mTriangleVertices);
    checkGlError("glVertexAttribPointer maTextureHandle");
    GLES20.glEnableVertexAttribArray(maTextureHandle);
    checkGlError("glEnableVertexAttribArray maTextureHandle");

    Matrix.setIdentityM(mMVPMatrix, 0);
    Matrix.scaleM(mMVPMatrix, 0, 1f, 1f, 1f);
    GLES20.glUniformMatrix4fv(muMVPMatrixHandle, 1, false, mMVPMatrix, 0);
    GLES20.glUniformMatrix4fv(muSTMatrixHandle, 1, false, mSTMatrix, 0);

    // Alternatively we can use
    //
    // GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, mTriangleVerticesData.length / 5);
    //
    // but with the current geometry setup it ends up drawing a lot of 'degenerate'
    // triangles which represents more work for our shaders, especially the fragment one.
    GLES20.glDrawElements(GLES20.GL_TRIANGLES, mTriangleIndicesData.length,
            GL10.GL_UNSIGNED_SHORT, mTriangleIndices);

    checkGlError("glDrawElements");
    GLES20.glFinish();
}
 
Example 19
Source File: AndroidGL.java    From trekarta with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void finish() {
    GLES20.glFinish();

}
 
Example 20
Source File: GLState.java    From tilt-game-android with MIT License 2 votes vote down vote up
/**
 * Tells the OpenGL driver to send all pending commands to the GPU immediately,
 * and then blocks until the effects of those commands have been completed on the GPU.
 * Since this is a costly method it should be only called when really needed.
 *
 * @see {@link #flush()},
 * 		{@link RenderTexture#end(GLState, boolean, boolean)}.
 */
public void finish() {
	GLES20.glFinish();
}