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

The following examples show how to use android.opengl.GLES20#glClear() . 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: TextureRenderer.java    From android-MediaEffects with Apache License 2.0 5 votes vote down vote up
public void renderTexture(int texId) {
    // Bind default FBO
    GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, 0);

    // Use our shader program
    GLES20.glUseProgram(mProgram);
    GLToolbox.checkGlError("glUseProgram");

    // Set viewport
    GLES20.glViewport(0, 0, mViewWidth, mViewHeight);
    GLToolbox.checkGlError("glViewport");

    // Disable blending
    GLES20.glDisable(GLES20.GL_BLEND);

    // Set the vertex attributes
    GLES20.glVertexAttribPointer(mTexCoordHandle, 2, GLES20.GL_FLOAT, false,
            0, mTexVertices);
    GLES20.glEnableVertexAttribArray(mTexCoordHandle);
    GLES20.glVertexAttribPointer(mPosCoordHandle, 2, GLES20.GL_FLOAT, false,
            0, mPosVertices);
    GLES20.glEnableVertexAttribArray(mPosCoordHandle);
    GLToolbox.checkGlError("vertex attribute setup");

    // Set the input texture
    GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
    GLToolbox.checkGlError("glActiveTexture");
    GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, texId);
    GLToolbox.checkGlError("glBindTexture");
    GLES20.glUniform1i(mTexSamplerHandle, 0);

    // Draw
    GLES20.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
    GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT);
    GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, 4);
}
 
Example 2
Source File: GLES20Canvas.java    From LB-Launcher with Apache License 2.0 5 votes vote down vote up
@Override
public void clearBuffer() {
    GLES20.glClearColor(0f, 0f, 0f, 1f);
    checkError();
    GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT);
    checkError();
}
 
Example 3
Source File: GLTextureRender.java    From IjkVRPlayer with Apache License 2.0 5 votes vote down vote up
@Override
public void onDrawFrame(GL10 gl) {
    if (BuildConfig.DEBUG) {
        Log.d(TAG, "onDrawFrame tex=" + mTextureId);
    }
    // Latch the latest frame.  If there isn't anything new, we'll just re-use whatever
    // was there before.
    mSurfaceTexture.updateTexImage();
    mSurfaceTexture.getTransformMatrix(mSTMatrix);
    // Clear dirty rect
    GLES20.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
    GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT);
    // Draw the video frame.
    mRect.drawFrame(mTextureId, mSTMatrix);
}
 
Example 4
Source File: CameraGLRendererBase.java    From ml-authentication with Apache License 2.0 5 votes vote down vote up
private void drawTex(int tex, boolean isOES, int fbo)
{
    GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, fbo);

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

    GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT);

    if(isOES) {
        GLES20.glUseProgram(progOES);
        GLES20.glVertexAttribPointer(vPosOES, 2, GLES20.GL_FLOAT, false, 4*2, vert);
        GLES20.glVertexAttribPointer(vTCOES,  2, GLES20.GL_FLOAT, false, 4*2, texOES);
    } else {
        GLES20.glUseProgram(prog2D);
        GLES20.glVertexAttribPointer(vPos2D, 2, GLES20.GL_FLOAT, false, 4*2, vert);
        GLES20.glVertexAttribPointer(vTC2D,  2, GLES20.GL_FLOAT, false, 4*2, tex2D);
    }

    GLES20.glActiveTexture(GLES20.GL_TEXTURE0);

    if(isOES) {
        GLES20.glBindTexture(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, tex);
        GLES20.glUniform1i(GLES20.glGetUniformLocation(progOES, "sTexture"), 0);
    } else {
        GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, tex);
        GLES20.glUniform1i(GLES20.glGetUniformLocation(prog2D, "sTexture"), 0);
    }

    GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, 4);
    GLES20.glFlush();
}
 
Example 5
Source File: CameraGLRendererBase.java    From LPR with Apache License 2.0 5 votes vote down vote up
@Override
public void onDrawFrame(GL10 gl) {
    //Log.i(LOGTAG, "onDrawFrame start");

    if (!mHaveFBO)
        return;

    synchronized(this) {
        if (mUpdateST) {
            mSTexture.updateTexImage();
            mUpdateST = false;
        }

        GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT);

        CameraTextureListener texListener = mView.getCameraTextureListener();
        if(texListener != null) {
            //Log.d(LOGTAG, "haveUserCallback");
            // texCamera(OES) -> texFBO
            drawTex(texCamera[0], true, FBO[0]);

            // call user code (texFBO -> texDraw)
            boolean modified = texListener.onCameraTexture(texFBO[0], texDraw[0], mCameraWidth, mCameraHeight);

            if(modified) {
                // texDraw -> screen
                drawTex(texDraw[0], false, 0);
            } else {
                // texFBO -> screen
                drawTex(texFBO[0], false, 0);
            }
        } else {
            Log.d(LOGTAG, "texCamera(OES) -> screen");
            // texCamera(OES) -> screen
            drawTex(texCamera[0], true, 0);
        }
        //Log.i(LOGTAG, "onDrawFrame end");
    }
}
 
Example 6
Source File: CameraGLRendererBase.java    From AndroidDocumentScanner with MIT License 5 votes vote down vote up
@Override
public void onDrawFrame(GL10 gl) {
    //Log.i(LOGTAG, "onDrawFrame start");

    if (!mHaveFBO)
        return;

    synchronized(this) {
        if (mUpdateST) {
            mSTexture.updateTexImage();
            mUpdateST = false;
        }

        GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT);

        CameraTextureListener texListener = mView.getCameraTextureListener();
        if(texListener != null) {
            //Log.d(LOGTAG, "haveUserCallback");
            // texCamera(OES) -> texFBO
            drawTex(texCamera[0], true, FBO[0]);

            // call user code (texFBO -> texDraw)
            boolean modified = texListener.onCameraTexture(texFBO[0], texDraw[0], mCameraWidth, mCameraHeight);

            if(modified) {
                // texDraw -> screen
                drawTex(texDraw[0], false, 0);
            } else {
                // texFBO -> screen
                drawTex(texFBO[0], false, 0);
            }
        } else {
            Log.d(LOGTAG, "texCamera(OES) -> screen");
            // texCamera(OES) -> screen
            drawTex(texCamera[0], true, 0);
        }
        //Log.i(LOGTAG, "onDrawFrame end");
    }
}
 
Example 7
Source File: CameraGLRendererBase.java    From react-native-documentscanner-android with MIT License 5 votes vote down vote up
private void drawTex(int tex, boolean isOES, int fbo)
{
    GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, fbo);

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

    GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT);

    if(isOES) {
        GLES20.glUseProgram(progOES);
        GLES20.glVertexAttribPointer(vPosOES, 2, GLES20.GL_FLOAT, false, 4*2, vert);
        GLES20.glVertexAttribPointer(vTCOES,  2, GLES20.GL_FLOAT, false, 4*2, texOES);
    } else {
        GLES20.glUseProgram(prog2D);
        GLES20.glVertexAttribPointer(vPos2D, 2, GLES20.GL_FLOAT, false, 4*2, vert);
        GLES20.glVertexAttribPointer(vTC2D,  2, GLES20.GL_FLOAT, false, 4*2, tex2D);
    }

    GLES20.glActiveTexture(GLES20.GL_TEXTURE0);

    if(isOES) {
        GLES20.glBindTexture(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, tex);
        GLES20.glUniform1i(GLES20.glGetUniformLocation(progOES, "sTexture"), 0);
    } else {
        GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, tex);
        GLES20.glUniform1i(GLES20.glGetUniformLocation(prog2D, "sTexture"), 0);
    }

    GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, 4);
    GLES20.glFlush();
}
 
Example 8
Source File: EglRenderer.java    From VideoCRE with MIT License 5 votes vote down vote up
private void clearSurfaceOnRenderThread(float r, float g, float b, float a) {
  if (eglBase != null && eglBase.hasSurface()) {
    logD("clearSurface");
    GLES20.glClearColor(r, g, b, a);
    GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT);
    eglBase.swapBuffers(-1);
  }
}
 
Example 9
Source File: CameraRender.java    From rtmp-rtsp-stream-client-java with Apache License 2.0 5 votes vote down vote up
@Override
public void draw() {
  GlUtil.checkGlError("drawCamera start");
  GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, renderHandler.getFboId()[0]);

  surfaceTexture.getTransformMatrix(STMatrix);
  GLES20.glViewport(0, 0, width, height);
  GLES20.glUseProgram(program);
  GLES20.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
  GLES20.glClear(GLES20.GL_DEPTH_BUFFER_BIT | GLES20.GL_COLOR_BUFFER_BIT);

  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(aTextureCameraHandle, 2, GLES20.GL_FLOAT, false,
      SQUARE_VERTEX_DATA_STRIDE_BYTES, squareVertex);
  GLES20.glEnableVertexAttribArray(aTextureCameraHandle);

  GLES20.glUniformMatrix4fv(uMVPMatrixHandle, 1, false, MVPMatrix, 0);
  GLES20.glUniformMatrix4fv(uSTMatrixHandle, 1, false, STMatrix, 0);
  //camera
  GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
  GLES20.glBindTexture(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, textureID[0]);
  //draw
  GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, 4);

  GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, 0);
  GlUtil.checkGlError("drawCamera end");
}
 
Example 10
Source File: EngineRenderer.java    From 30-android-libraries-in-30-days with Apache License 2.0 5 votes vote down vote up
@Override
public void onDrawFrame(final GL10 pGL) {
	synchronized(GLState.class) {
		if (this.mMultiSampling && this.mConfigChooser.isCoverageMultiSampling()) {
			final int GL_COVERAGE_BUFFER_BIT_NV = 0x8000;
			GLES20.glClear(GL_COVERAGE_BUFFER_BIT_NV);
		}

		try {
			this.mEngine.onDrawFrame(this.mGLState);
		} catch (final InterruptedException e) {
			Debug.e("GLThread interrupted!", e);
		}
	}
}
 
Example 11
Source File: CameraGLRendererBase.java    From sudokufx with Apache License 2.0 5 votes vote down vote up
private void drawTex(int tex, boolean isOES, int fbo)
{
    GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, fbo);

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

    GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT);

    if(isOES) {
        GLES20.glUseProgram(progOES);
        GLES20.glVertexAttribPointer(vPosOES, 2, GLES20.GL_FLOAT, false, 4*2, vert);
        GLES20.glVertexAttribPointer(vTCOES,  2, GLES20.GL_FLOAT, false, 4*2, texOES);
    } else {
        GLES20.glUseProgram(prog2D);
        GLES20.glVertexAttribPointer(vPos2D, 2, GLES20.GL_FLOAT, false, 4*2, vert);
        GLES20.glVertexAttribPointer(vTC2D,  2, GLES20.GL_FLOAT, false, 4*2, tex2D);
    }

    GLES20.glActiveTexture(GLES20.GL_TEXTURE0);

    if(isOES) {
        GLES20.glBindTexture(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, tex);
        GLES20.glUniform1i(GLES20.glGetUniformLocation(progOES, "sTexture"), 0);
    } else {
        GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, tex);
        GLES20.glUniform1i(GLES20.glGetUniformLocation(prog2D, "sTexture"), 0);
    }

    GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, 4);
    GLES20.glFlush();
}
 
Example 12
Source File: ParticleSystemRenderer.java    From StarWars.Android with MIT License 5 votes vote down vote up
private void drawGl() {
    GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT | GLES20.GL_DEPTH_BUFFER_BIT);

    GLES20.glUseProgram(programHandle);

    // Set program handles
    mvpMatrixHandle = GLES20.glGetUniformLocation(programHandle, "u_MVPMatrix");
    mvMatrixHandle = GLES20.glGetUniformLocation(programHandle, "u_MVMatrix");
    timeHandle = GLES20.glGetUniformLocation(programHandle, "u_Time");
    resolutionHandle = GLES20.glGetUniformLocation(programHandle, "u_Resolution");

    positionHandle = GLES20.glGetAttribLocation(programHandle, "a_Position");
    normalHandle = GLES20.glGetAttribLocation(programHandle, "a_Normal");
    textureCoordinateHandle = GLES20.glGetAttribLocation(programHandle, "a_TexCoordinate");
    miscHandle = GLES20.glGetAttribLocation(programHandle, "a_Misc");

    Matrix.setIdentityM(mModelMatrix, 0);
    Matrix.translateM(mModelMatrix, 0, 0.0f, 0.0f, 5f);

    Matrix.multiplyMM(mMVPMatrix, 0, mViewMatrix, 0, mModelMatrix, 0);

    // Pass in the modelview matrix.
    GLES20.glUniformMatrix4fv(mvMatrixHandle, 1, false, mMVPMatrix, 0);

    Matrix.multiplyMM(mTemporaryMatrix, 0, mProjectionMatrix, 0, mMVPMatrix, 0);
    System.arraycopy(mTemporaryMatrix, 0, mMVPMatrix, 0, 16);

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

    // Pass in u_Time
    GLES20.glUniform1f(timeHandle, (System.currentTimeMillis() - mStartTime) / 3500f);

    // u_Resolution
    GLES20.glUniform2f(resolutionHandle, mWidth, mHeight);

    GLES20.glBlendFunc(GLES20.GL_SRC_ALPHA, GLES20.GL_ONE_MINUS_SRC_ALPHA);
    GLES20.glEnable(GLES20.GL_BLEND);
}
 
Example 13
Source File: CameraGLRendererBase.java    From MOAAP with MIT License 5 votes vote down vote up
private void drawTex(int tex, boolean isOES, int fbo)
{
    GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, fbo);

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

    GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT);

    if(isOES) {
        GLES20.glUseProgram(progOES);
        GLES20.glVertexAttribPointer(vPosOES, 2, GLES20.GL_FLOAT, false, 4*2, vert);
        GLES20.glVertexAttribPointer(vTCOES,  2, GLES20.GL_FLOAT, false, 4*2, texOES);
    } else {
        GLES20.glUseProgram(prog2D);
        GLES20.glVertexAttribPointer(vPos2D, 2, GLES20.GL_FLOAT, false, 4*2, vert);
        GLES20.glVertexAttribPointer(vTC2D,  2, GLES20.GL_FLOAT, false, 4*2, tex2D);
    }

    GLES20.glActiveTexture(GLES20.GL_TEXTURE0);

    if(isOES) {
        GLES20.glBindTexture(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, tex);
        GLES20.glUniform1i(GLES20.glGetUniformLocation(progOES, "sTexture"), 0);
    } else {
        GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, tex);
        GLES20.glUniform1i(GLES20.glGetUniformLocation(prog2D, "sTexture"), 0);
    }

    GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, 4);
    GLES20.glFlush();
}
 
Example 14
Source File: CameraGLRendererBase.java    From MOAAP with MIT License 5 votes vote down vote up
@Override
public void onDrawFrame(GL10 gl) {
    //Log.i(LOGTAG, "onDrawFrame start");

    if (!mHaveFBO)
        return;

    synchronized(this) {
        if (mUpdateST) {
            mSTexture.updateTexImage();
            mUpdateST = false;
        }

        GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT);

        CameraTextureListener texListener = mView.getCameraTextureListener();
        if(texListener != null) {
            //Log.d(LOGTAG, "haveUserCallback");
            // texCamera(OES) -> texFBO
            drawTex(texCamera[0], true, FBO[0]);

            // call user code (texFBO -> texDraw)
            boolean modified = texListener.onCameraTexture(texFBO[0], texDraw[0], mCameraWidth, mCameraHeight);

            if(modified) {
                // texDraw -> screen
                drawTex(texDraw[0], false, 0);
            } else {
                // texFBO -> screen
                drawTex(texFBO[0], false, 0);
            }
        } else {
            Log.d(LOGTAG, "texCamera(OES) -> screen");
            // texCamera(OES) -> screen
            drawTex(texCamera[0], true, 0);
        }
        //Log.i(LOGTAG, "onDrawFrame end");
    }
}
 
Example 15
Source File: MyGLRenderer.java    From poly-sample-android with Apache License 2.0 4 votes vote down vote up
@Override
public void onDrawFrame(GL10 unused) {
  // Update the spin animation.
  long now = System.currentTimeMillis();
  float deltaT = Math.min((now - lastFrameTime) * 0.001f, 0.1f);
  lastFrameTime = now;
  angleDegrees += deltaT * MODEL_ROTATION_SPEED_DPS;

  // Draw background color.
  GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT | GLES20.GL_DEPTH_BUFFER_BIT);

  // Make a model matrix that rotates the model about the Y axis so it appears to spin.
  Matrix.setRotateM(modelMatrix, 0, angleDegrees, 0, 1, 0);

  // Set the camera position (View matrix)
  Matrix.setLookAtM(viewMatrix, 0,
      // Camera position.
      EYE_X, EYE_Y, EYE_Z,
      // Point that the camera is looking at.
      TARGET_X, TARGET_Y, TARGET_Z,
      // The vector that defines which way is up.
      UP_X, UP_Y, UP_Z);

  // Calculate the MVP matrix (model-view-projection) by multiplying the model, view, and
  // projection matrices together.
  Matrix.multiplyMM(tmpMatrix, 0, viewMatrix, 0, modelMatrix, 0);  // V * M
  Matrix.multiplyMM(mvpMatrix, 0, projMatrix, 0, tmpMatrix, 0);  // P * V * M

  // objectToRender is volatile, so we capture it in a local variable.
  RawObject obj = objectToRender;

  if (readyToRender) {
    // We're ready to render, so just render using our existing VBOs and IBO.
    myShader.render(mvpMatrix, indexCount, ibo, positionsVbo, colorsVbo);
  } else if (obj != null) {
    // The object is ready, but we haven't consumed it yet. We need to create the VBOs and IBO
    // to render the object.
    indexCount = obj.indexCount;
    ibo = MyGLUtils.createIbo(obj.indices);
    positionsVbo = MyGLUtils.createVbo(obj.positions);
    colorsVbo = MyGLUtils.createVbo(obj.colors);
    // Now we're ready to render the object.
    readyToRender = true;
    Log.d(TAG, "VBOs/IBO created. Now ready to render object.");
  }
}
 
Example 16
Source File: CameraFilter.java    From PLDroidMediaStreaming with Apache License 2.0 4 votes vote down vote up
@Override
protected void drawArrays(int firstVertex, int vertexCount) {
    GLES20.glClearColor(0f, 0f, 0f, 1f);
    GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT);
    GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, firstVertex, vertexCount);
}
 
Example 17
Source File: PhotoFilterView.java    From TelePlus-Android with GNU General Public License v2.0 4 votes vote down vote up
private boolean drawBlurPass() {
    if (showOriginal || blurType == 0) {
        return false;
    }
    if (needUpdateBlurTexture) {
        GLES20.glUseProgram(blurShaderProgram);
        GLES20.glUniform1i(blurSourceImageHandle, 0);
        GLES20.glEnableVertexAttribArray(blurInputTexCoordHandle);
        GLES20.glVertexAttribPointer(blurInputTexCoordHandle, 2, GLES20.GL_FLOAT, false, 8, textureBuffer);
        GLES20.glEnableVertexAttribArray(blurPositionHandle);
        GLES20.glVertexAttribPointer(blurPositionHandle, 2, GLES20.GL_FLOAT, false, 8, vertexInvertBuffer);

        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.glActiveTexture(GLES20.GL_TEXTURE0);
        GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, renderTexture[1]);
        GLES20.glUniform1f(blurWidthHandle, 0.0f);
        GLES20.glUniform1f(blurHeightHandle, 1.0f / renderBufferHeight);
        GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, 4);

        GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, renderFrameBuffer[2]);
        GLES20.glFramebufferTexture2D(GLES20.GL_FRAMEBUFFER, GLES20.GL_COLOR_ATTACHMENT0, GLES20.GL_TEXTURE_2D, renderTexture[2], 0);
        GLES20.glClear(0);
        GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
        GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, renderTexture[0]);
        GLES20.glUniform1f(blurWidthHandle, 1.0f / renderBufferWidth);
        GLES20.glUniform1f(blurHeightHandle, 0.0f);
        GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, 4);
        needUpdateBlurTexture = false;
    }

    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);
    if (blurType == 1) {
        GLES20.glUseProgram(radialBlurShaderProgram);
        GLES20.glUniform1i(radialBlurSourceImageHandle, 0);
        GLES20.glUniform1i(radialBlurSourceImage2Handle, 1);
        GLES20.glUniform1f(radialBlurExcludeSizeHandle, blurExcludeSize);
        GLES20.glUniform1f(radialBlurExcludeBlurSizeHandle, blurExcludeBlurSize);
        GLES20.glUniform2f(radialBlurExcludePointHandle, blurExcludePoint.x, blurExcludePoint.y);
        GLES20.glUniform1f(radialBlurAspectRatioHandle, (float) renderBufferHeight / (float) renderBufferWidth);
        GLES20.glEnableVertexAttribArray(radialBlurInputTexCoordHandle);
        GLES20.glVertexAttribPointer(radialBlurInputTexCoordHandle, 2, GLES20.GL_FLOAT, false, 8, textureBuffer);
        GLES20.glEnableVertexAttribArray(radialBlurPositionHandle);
        GLES20.glVertexAttribPointer(radialBlurPositionHandle, 2, GLES20.GL_FLOAT, false, 8, vertexInvertBuffer);
    } else if (blurType == 2) {
        GLES20.glUseProgram(linearBlurShaderProgram);
        GLES20.glUniform1i(linearBlurSourceImageHandle, 0);
        GLES20.glUniform1i(linearBlurSourceImage2Handle, 1);
        GLES20.glUniform1f(linearBlurExcludeSizeHandle, blurExcludeSize);
        GLES20.glUniform1f(linearBlurExcludeBlurSizeHandle, blurExcludeBlurSize);
        GLES20.glUniform1f(linearBlurAngleHandle, blurAngle);
        GLES20.glUniform2f(linearBlurExcludePointHandle, blurExcludePoint.x, blurExcludePoint.y);
        GLES20.glUniform1f(linearBlurAspectRatioHandle, (float) renderBufferHeight / (float) renderBufferWidth);
        GLES20.glEnableVertexAttribArray(linearBlurInputTexCoordHandle);
        GLES20.glVertexAttribPointer(linearBlurInputTexCoordHandle, 2, GLES20.GL_FLOAT, false, 8, textureBuffer);
        GLES20.glEnableVertexAttribArray(linearBlurPositionHandle);
        GLES20.glVertexAttribPointer(linearBlurPositionHandle, 2, GLES20.GL_FLOAT, false, 8, vertexInvertBuffer);
    }

    GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
    GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, renderTexture[1]);
    GLES20.glActiveTexture(GLES20.GL_TEXTURE1);
    GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, renderTexture[2]);
    GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, 4);

    return true;
}
 
Example 18
Source File: OpenGLRenderer.java    From smartGL with Apache License 2.0 4 votes vote down vote up
@Override
public void onDrawFrame(GL10 gl10) {

    computeFps();

    GLES20.glClearColor(mClearColor[0], mClearColor[1], mClearColor[2], mClearColor[3]);    // RGBA
    GLES20.glClear(GLES20.GL_DEPTH_BUFFER_BIT | GLES20.GL_COLOR_BUFFER_BIT);

    checkDoubleSided(gl10);

    synchronized (this) {

        if (!mInitDone) {
            return;
        }

        if (mOpenGLView != null) {
            OpenGLView view = mOpenGLView.get();
            if (view != null) {
                view.onPreRender(this);
            }
        }

        if ((mCamera != null) && mCamera.isDirty()) {
            computeProjMatrix3D(mProj3DMatrix);
        }

        onPreRender(gl10);

        if (mRenderPasses != null) {

            int passNumber = 0;
            final int prgSize = mRenderPasses.size();
            for (int prgIt = 0; prgIt < prgSize; ++prgIt) {
                final RenderPass renderPass = mRenderPasses.get(prgIt);
                if (!renderPass.isLoaded()) {
                    renderPass.load();
                }

                renderPass.sortObjects();

                ++passNumber;
                onPreRenderPass(gl10, passNumber);

                Vector<RenderObject> mainObjectList = renderPass.getRenderObjects();
                //Vector<RenderObject> objectList = buildObjectList(mainObjectList);	// recursive with Container Objects

                if (renderPass.useZBuffer()) {
                    gl10.glEnable(GL10.GL_DEPTH_TEST);
                    if (renderPass.clearZBuffer()) {
                        GLES20.glClear(GLES20.GL_DEPTH_BUFFER_BIT);
                    }
                } else {
                    gl10.glDisable(GL10.GL_DEPTH_TEST);
                }

                mPreviousShader = null;
                mUseTexture = false;
                mUseColor = false;
                mVertexAttribId = -1;
                mUvAttribId = -1;
                mColorAttribId = -1;
                mProjMatrixId = -1;

                // OBJECTS
                for (int renderObjIt = 0; renderObjIt < mainObjectList.size(); ++renderObjIt) {
                    RenderObject object = mainObjectList.get(renderObjIt);
                    boolean render = object.shouldDisplay(this);
                    if (object.isContainer()) {
                        renderContainer(renderPass, (RenderObjectContainer) object, render);
                    } else {
                        renderObject(renderPass, object, render);
                    }

                }

                onPostRenderPass(gl10, passNumber);
            }
        }
        //handleTouchEvents();
        onPostRender(gl10);

        if (mScreenshotListener != null) {
            doTakeScreenshot(gl10);
        }
    }

}
 
Example 19
Source File: CameraSurfaceView.java    From Paddle-Lite-Demo with Apache License 2.0 4 votes vote down vote up
@Override
public void onDrawFrame(GL10 gl) {
    if (surfaceTexture == null) return;

    GLES20.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
    GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT | GLES20.GL_DEPTH_BUFFER_BIT);
    surfaceTexture.updateTexImage();
    float matrix[] = new float[16];
    surfaceTexture.getTransformMatrix(matrix);

    // camTextureId->fboTexureId
    GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, fbo[0]);
    GLES20.glViewport(0, 0, textureWidth, textureHeight);
    GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT);
    GLES20.glUseProgram(progCam2FBO);
    GLES20.glVertexAttribPointer(vcCam2FBO, 2, GLES20.GL_FLOAT, false, 4 * 2, vertexCoordsBuffer);
    textureCoordsBuffer.clear();
    textureCoordsBuffer.put(transformTextureCoordinates(textureCoords, matrix));
    textureCoordsBuffer.position(0);
    GLES20.glVertexAttribPointer(tcCam2FBO, 2, GLES20.GL_FLOAT, false, 4 * 2, textureCoordsBuffer);
    GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
    GLES20.glBindTexture(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, camTextureId[0]);
    GLES20.glUniform1i(GLES20.glGetUniformLocation(progCam2FBO, "sTexture"), 0);
    GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, 4);
    GLES20.glFlush();

    // Check if the draw texture is set
    int targetTexureId = fboTexureId[0];
    if (onTextureChangedListener != null) {
        boolean modified = onTextureChangedListener.onTextureChanged(fboTexureId[0], drawTexureId[0],
                textureWidth, textureHeight);
        if (modified) {
            targetTexureId = drawTexureId[0];
        }
    }

    // fboTexureId/drawTexureId->Screen
    GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, 0);
    GLES20.glViewport(0, 0, surfaceWidth, surfaceHeight);
    GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT);
    GLES20.glUseProgram(progTex2Screen);
    GLES20.glVertexAttribPointer(vcTex2Screen, 2, GLES20.GL_FLOAT, false, 4 * 2, vertexCoordsBuffer);
    textureCoordsBuffer.clear();
    textureCoordsBuffer.put(textureCoords);
    textureCoordsBuffer.position(0);
    GLES20.glVertexAttribPointer(tcTex2Screen, 2, GLES20.GL_FLOAT, false, 4 * 2, textureCoordsBuffer);
    GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
    GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, targetTexureId);
    GLES20.glUniform1i(GLES20.glGetUniformLocation(progTex2Screen, "sTexture"), 0);
    GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, 4);
    GLES20.glFlush();
}
 
Example 20
Source File: TwoPassFilter.java    From UltimateAndroid with Apache License 2.0 votes vote down vote up
@Override
	protected void drawFrame() {
		currentPass = 1;
		if(firstPassFrameBuffer == null) {
			if(getWidth() != 0 && getHeight() != 0) {
				initFBO();
			} else {
				return;
			}
		}

		GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, firstPassFrameBuffer[0]);
		
		if(texture_in == 0) {
			return;
		}
		
		GLES20.glViewport(0, 0, getWidth(), getHeight());
        GLES20.glUseProgram(programHandle);

		GLES20.glClear(GLES20.GL_DEPTH_BUFFER_BIT | GLES20.GL_COLOR_BUFFER_BIT);
		GLES20.glClearColor(getBackgroundRed(), getBackgroundGreen(), getBackgroundBlue(), getBackgroundAlpha());
		
		passShaderValues();
		
		GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, 4); 
		
		texture_in = firstPassTextureOut[0];
		
		GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, 0);
		
		currentPass = 2;
		super.drawFrame();
	}