Java Code Examples for android.opengl.GLES20#GL_DEPTH_BUFFER_BIT

The following examples show how to use android.opengl.GLES20#GL_DEPTH_BUFFER_BIT . 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: OGLESShaderRenderer.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public void clearBuffers(boolean color, boolean depth, boolean stencil) {
    int bits = 0;
    if (color) {
        bits = GLES20.GL_COLOR_BUFFER_BIT;
    }
    if (depth) {
        bits |= GLES20.GL_DEPTH_BUFFER_BIT;
        if (context.depthWriteEnabled == false) {
            GLES20.glDepthMask(true);
            context.depthWriteEnabled = true;
        }
    }
    if (stencil) {
        bits |= GLES20.GL_STENCIL_BUFFER_BIT;
    }
    if (bits != 0) {
        if (verboseLogging) {
            logger.log(Level.INFO, "GLES20.glClear(color={0}, depth={1}, stencil={2})", new Object[]{color, depth, stencil});
        }
        GLES20.glClear(bits);
        checkGLError();
    }
}
 
Example 2
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 3
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();
}