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

The following examples show how to use android.opengl.GLES20#glDepthMask() . 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: PreviewRenderer.java    From retroboy with MIT License 6 votes vote down vote up
@Override
public void onSurfaceCreated(GL10 glUnused, EGLConfig config) {
	// Turn off unneeded features 
	GLES20.glDisable(GLES20.GL_BLEND);
	GLES20.glDisable(GLES20.GL_CULL_FACE);
	GLES20.glDisable(GLES20.GL_DITHER);
	GLES20.glDisable(GLES20.GL_DEPTH_TEST);
	GLES20.glDisable(GLES20.GL_SCISSOR_TEST);
	GLES20.glDisable(GLES20.GL_STENCIL_TEST);
	GLES20.glDepthMask(false);

	// Background color
	GLES20.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
	
	_program = new ShaderProgram(_context, PreviewShader.SHADER_SOURCE_ID, AtkinsonShader.SHADER_SOURCE_ID);
}
 
Example 2
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 3
Source File: BackgroundRenderer.java    From justaline-android with Apache License 2.0 5 votes vote down vote up
/**
 * Draws the AR background image.  The image will be drawn such that virtual content rendered
 * with the matrices provided by {@link Camera#getViewMatrix(float[], int)} and
 * {@link Camera#getProjectionMatrix(float[], int, float, float)} will accurately follow
 * static physical objects.  This must be called <b>before</b> drawing virtual content.
 *
 * @param frame The last {@code Frame} returned by {@link Session#update()}.
 */
public void draw(Frame frame) {
    // We need to re-query the uv coordinates for the screen rect, as they may have
    // changed as well.
    frame.transformDisplayUvCoords(mQuadTexCoord, mQuadTexCoordTransformed);

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

    GLES20.glBindTexture(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, mTextureId);

    GLES20.glUseProgram(mQuadProgram);

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

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

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

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

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

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

    ShaderUtil.checkGLError(TAG, "Draw");
}
 
Example 4
Source File: BackgroundRenderer.java    From unity-ads-android with Apache License 2.0 5 votes vote down vote up
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1)
void draw(Frame frame) {
	// If display rotation changed (also includes view size change), we need to re-query the uv
	// coordinates for the screen rect, as they may have changed as well.
	if (frame.hasDisplayGeometryChanged()) {
		frame.transformDisplayUvCoords(quadTexCoord, quadTexCoordTransformed);
	}

	GLES20.glDisable(GLES20.GL_DEPTH_TEST);
	GLES20.glDepthMask(false);

	GLES20.glBindTexture(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, textureId);

	GLES20.glUseProgram(quadProgram);

	GLES20.glVertexAttribPointer(
			quadPositionParam, COORDS_PER_VERTEX, GLES20.GL_FLOAT, false, 0, quadVertices);

	GLES20.glVertexAttribPointer(
			quadTexCoordParam,
			TEXCOORDS_PER_VERTEX,
			GLES20.GL_FLOAT,
			false,
			0,
			quadTexCoordTransformed);

	GLES20.glEnableVertexAttribArray(quadPositionParam);
	GLES20.glEnableVertexAttribArray(quadTexCoordParam);

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

	GLES20.glDisableVertexAttribArray(quadPositionParam);
	GLES20.glDisableVertexAttribArray(quadTexCoordParam);

	GLES20.glDepthMask(true);
	GLES20.glEnable(GLES20.GL_DEPTH_TEST);
}
 
Example 5
Source File: ARSurfaceViewRenderer.java    From geoar-app with Apache License 2.0 5 votes vote down vote up
@Override
public void onSurfaceCreated(GL10 glUnused, EGLConfig config) {
	/** Set the background clear color to "black" and transparent */
	GLES20.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);

	/** set up the view matrix */
	GLESCamera.resetViewMatrix();

	/** Enable depth testing */
	GLES20.glEnable(GLES20.GL_DEPTH_TEST);
	GLES20.glClearDepthf(1.0f);
	GLES20.glDepthFunc(GLES20.GL_LESS);
	GLES20.glDepthMask(true);

	/** Enable texture mapping */
	GLES20.glEnable(GLES20.GL_TEXTURE_2D);

	/** Enable blending */
	GLES20.glEnable(GLES20.GL_BLEND);
	GLES20.glBlendFunc(GLES20.GL_SRC_ALPHA, GLES20.GL_ONE_MINUS_SRC_ALPHA);
	// GLES20.glBlendFunc(GLES20.GL_ONE, GLES20.GL_ONE);

	/**
	 * Backface culling - here back-facing facets are culled when facet
	 * culling is enabled
	 */
	GLES20.glEnable(GLES20.GL_CULL_FACE);
	GLES20.glCullFace(GLES20.GL_BACK); // GL_FRONT_AND_BACK for no facets

	// Resets all cached handlers because the context was lost so that they
	// are recreated later on demand.
	FeatureShader.resetShaders();
	Texture.resetTextures();
	initScene();
}
 
Example 6
Source File: GLES20WallpaperRenderer.java    From alynx-live-wallpaper with Apache License 2.0 4 votes vote down vote up
@Override
public void onSurfaceCreated(GL10 gl10, EGLConfig eglConfig) {
    // No depth test for 2D video.
    GLES20.glDisable(GLES20.GL_DEPTH_TEST);
    GLES20.glDepthMask(false);
    GLES20.glDisable(GLES20.GL_CULL_FACE);
    GLES20.glDisable(GLES20.GL_BLEND);

    GLES20.glGenTextures(textures.length, textures, 0);
    GLES20.glBindTexture(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, textures[0]);
    GLES20.glTexParameteri(
        GLES11Ext.GL_TEXTURE_EXTERNAL_OES,
        GLES20.GL_TEXTURE_MIN_FILTER,
        GLES20.GL_LINEAR
    );
    GLES20.glTexParameteri(
        GLES11Ext.GL_TEXTURE_EXTERNAL_OES,
        GLES20.GL_TEXTURE_MAG_FILTER,
        GLES20.GL_LINEAR
    );
    GLES20.glTexParameteri(
        GLES11Ext.GL_TEXTURE_EXTERNAL_OES,
        GLES20.GL_TEXTURE_WRAP_S,
        GLES20.GL_CLAMP_TO_EDGE
    );
    GLES20.glTexParameteri(
        GLES11Ext.GL_TEXTURE_EXTERNAL_OES,
        GLES20.GL_TEXTURE_WRAP_T,
        GLES20.GL_CLAMP_TO_EDGE
    );

    program = Utils.linkProgramGLES20(
        Utils.compileShaderResourceGLES20(
            context, GLES20.GL_VERTEX_SHADER, R.raw.vertex_20
        ),
        Utils.compileShaderResourceGLES20(
            context, GLES20.GL_FRAGMENT_SHADER, R.raw.fragment_20
        )
    );
    mvpLocation = GLES20.glGetUniformLocation(program, "mvp");
    // Locations are NOT set in shader sources.
    positionLocation = GLES20.glGetAttribLocation(program, "in_position");
    texCoordLocation = GLES20.glGetAttribLocation(program, "in_tex_coord");

    GLES20.glGenBuffers(buffers.length, buffers, 0);

    GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, buffers[0]);
    GLES20.glBufferData(
        GLES20.GL_ARRAY_BUFFER, vertices.capacity() * BYTES_PER_FLOAT,
        vertices, GLES20.GL_STATIC_DRAW
    );
    GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, 0);

    GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, buffers[1]);
    GLES20.glBufferData(
        GLES20.GL_ARRAY_BUFFER, texCoords.capacity() * BYTES_PER_FLOAT,
        texCoords, GLES20.GL_STATIC_DRAW
    );
    GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, 0);

    GLES20.glBindBuffer(GLES20.GL_ELEMENT_ARRAY_BUFFER, buffers[2]);
    GLES20.glBufferData(
        GLES20.GL_ELEMENT_ARRAY_BUFFER, indices.capacity() * BYTES_PER_INT,
        indices, GLES20.GL_STATIC_DRAW
    );
    GLES20.glBindBuffer(GLES20.GL_ELEMENT_ARRAY_BUFFER, 0);

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

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

    GLES20.glBindTexture(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, mTextureId);

    GLES20.glUseProgram(mQuadProgram);

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

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

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

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

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

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

    ShaderUtil.checkGLError(TAG, "Draw");
}
 
Example 8
Source File: ObjectRenderer.java    From react-native-arcore with MIT License 4 votes vote down vote up
/**
 * Draws the model.
 *
 * @param cameraView  A 4x4 view matrix, in column-major order.
 * @param cameraPerspective  A 4x4 projection matrix, in column-major order.
 * @param lightIntensity  Illumination intensity.  Combined with diffuse and specular material
 *     properties.
 * @see #setBlendMode(BlendMode)
 * @see #updateModelMatrix(float[], float)
 * @see #setMaterialProperties(float, float, float, float)
 * @see Matrix
 */
public void draw(float[] cameraView, float[] cameraPerspective, float lightIntensity) {

    ShaderUtil.checkGLError(TAG, "Before draw");

    // Build the ModelView and ModelViewProjection matrices
    // for calculating object position and light.
    Matrix.multiplyMM(mModelViewMatrix, 0, cameraView, 0, mModelMatrix, 0);
    Matrix.multiplyMM(mModelViewProjectionMatrix, 0, cameraPerspective, 0, mModelViewMatrix, 0);

    GLES20.glUseProgram(mProgram);

    // Set the lighting environment properties.
    Matrix.multiplyMV(mViewLightDirection, 0, mModelViewMatrix, 0, LIGHT_DIRECTION, 0);
    normalizeVec3(mViewLightDirection);
    GLES20.glUniform4f(mLightingParametersUniform,
        mViewLightDirection[0], mViewLightDirection[1], mViewLightDirection[2], lightIntensity);

    // Set the object material properties.
    GLES20.glUniform4f(mMaterialParametersUniform, mAmbient, mDiffuse, mSpecular,
        mSpecularPower);

    // Attach the object texture.
    GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
    GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mTextures[0]);
    GLES20.glUniform1i(mTextureUniform, 0);

    // Set the vertex attributes.
    GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, mVertexBufferId);

    GLES20.glVertexAttribPointer(
        mPositionAttribute, COORDS_PER_VERTEX, GLES20.GL_FLOAT, false, 0, mVerticesBaseAddress);
    GLES20.glVertexAttribPointer(
        mNormalAttribute, 3, GLES20.GL_FLOAT, false, 0, mNormalsBaseAddress);
    GLES20.glVertexAttribPointer(
        mTexCoordAttribute, 2, GLES20.GL_FLOAT, false, 0, mTexCoordsBaseAddress);

    GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, 0);

    // Set the ModelViewProjection matrix in the shader.
    GLES20.glUniformMatrix4fv(
        mModelViewUniform, 1, false, mModelViewMatrix, 0);
    GLES20.glUniformMatrix4fv(
        mModelViewProjectionUniform, 1, false, mModelViewProjectionMatrix, 0);

    // Enable vertex arrays
    GLES20.glEnableVertexAttribArray(mPositionAttribute);
    GLES20.glEnableVertexAttribArray(mNormalAttribute);
    GLES20.glEnableVertexAttribArray(mTexCoordAttribute);

    if (mBlendMode != null) {
        GLES20.glDepthMask(false);
        GLES20.glEnable(GLES20.GL_BLEND);
        switch (mBlendMode) {
            case Shadow:
                // Multiplicative blending function for Shadow.
                GLES20.glBlendFunc(GLES20.GL_ZERO, GLES20.GL_ONE_MINUS_SRC_ALPHA);
                break;
            case Grid:
                // Grid, additive blending function.
                GLES20.glBlendFunc(GLES20.GL_SRC_ALPHA, GLES20.GL_ONE_MINUS_SRC_ALPHA);
                break;
        }
    }

    GLES20.glBindBuffer(GLES20.GL_ELEMENT_ARRAY_BUFFER, mIndexBufferId);
    GLES20.glDrawElements(GLES20.GL_TRIANGLES, mIndexCount, GLES20.GL_UNSIGNED_SHORT, 0);
    GLES20.glBindBuffer(GLES20.GL_ELEMENT_ARRAY_BUFFER, 0);

    if (mBlendMode != null) {
        GLES20.glDisable(GLES20.GL_BLEND);
        GLES20.glDepthMask(true);
    }

    // Disable vertex arrays
    GLES20.glDisableVertexAttribArray(mPositionAttribute);
    GLES20.glDisableVertexAttribArray(mNormalAttribute);
    GLES20.glDisableVertexAttribArray(mTexCoordAttribute);

    GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, 0);

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

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

    GLES20.glBindTexture(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, mTextureId);

    GLES20.glUseProgram(mQuadProgram);

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

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

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

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

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

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

    ShaderUtil.checkGLError(TAG, "Draw");
}
 
Example 10
Source File: ObjectRenderer.java    From poly-sample-android with Apache License 2.0 4 votes vote down vote up
public void draw(
    float[] cameraView,
    float[] cameraPerspective,
    float[] colorCorrectionRgba,
    float[] objColor) {

  ShaderUtil.checkGLError(TAG, "Before draw");

  // Build the ModelView and ModelViewProjection matrices
  // for calculating object position and light.
  Matrix.multiplyMM(modelViewMatrix, 0, cameraView, 0, modelMatrix, 0);
  Matrix.multiplyMM(modelViewProjectionMatrix, 0, cameraPerspective, 0, modelViewMatrix, 0);

  GLES20.glUseProgram(program);

  // Set the lighting environment properties.
  Matrix.multiplyMV(viewLightDirection, 0, modelViewMatrix, 0, LIGHT_DIRECTION, 0);
  normalizeVec3(viewLightDirection);
  GLES20.glUniform4f(
      lightingParametersUniform,
      viewLightDirection[0],
      viewLightDirection[1],
      viewLightDirection[2],
      1.f);
  GLES20.glUniform4fv(colorCorrectionParameterUniform, 1, colorCorrectionRgba, 0);

  // Set the object color property.
  GLES20.glUniform4fv(colorUniform, 1, objColor, 0);

  // Set the object material properties.
  GLES20.glUniform4f(materialParametersUniform, ambient, diffuse, specular, specularPower);

  // Attach the object texture.
  GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
  GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, textures[0]);
  GLES20.glUniform1i(textureUniform, 0);

  // Set the vertex attributes.
  GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, vertexBufferId);

  GLES20.glVertexAttribPointer(
      positionAttribute, COORDS_PER_VERTEX, GLES20.GL_FLOAT, false, 0, verticesBaseAddress);
  GLES20.glVertexAttribPointer(normalAttribute, 3, GLES20.GL_FLOAT, false, 0, normalsBaseAddress);
  GLES20.glVertexAttribPointer(
      texCoordAttribute, 2, GLES20.GL_FLOAT, false, 0, texCoordsBaseAddress);

  GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, 0);

  // Set the ModelViewProjection matrix in the shader.
  GLES20.glUniformMatrix4fv(modelViewUniform, 1, false, modelViewMatrix, 0);
  GLES20.glUniformMatrix4fv(modelViewProjectionUniform, 1, false, modelViewProjectionMatrix, 0);

  // Enable vertex arrays
  GLES20.glEnableVertexAttribArray(positionAttribute);
  GLES20.glEnableVertexAttribArray(normalAttribute);
  GLES20.glEnableVertexAttribArray(texCoordAttribute);

  if (blendMode != null) {
    GLES20.glDepthMask(false);
    GLES20.glEnable(GLES20.GL_BLEND);
    switch (blendMode) {
      case Shadow:
        // Multiplicative blending function for Shadow.
        GLES20.glBlendFunc(GLES20.GL_ZERO, GLES20.GL_ONE_MINUS_SRC_ALPHA);
        break;
      case Grid:
        // Grid, additive blending function.
        GLES20.glBlendFunc(GLES20.GL_SRC_ALPHA, GLES20.GL_ONE_MINUS_SRC_ALPHA);
        break;
    }
  }

  GLES20.glBindBuffer(GLES20.GL_ELEMENT_ARRAY_BUFFER, indexBufferId);
  GLES20.glDrawElements(GLES20.GL_TRIANGLES, indexCount, GLES20.GL_UNSIGNED_SHORT, 0);
  GLES20.glBindBuffer(GLES20.GL_ELEMENT_ARRAY_BUFFER, 0);

  if (blendMode != null) {
    GLES20.glDisable(GLES20.GL_BLEND);
    GLES20.glDepthMask(true);
  }

  // Disable vertex arrays
  GLES20.glDisableVertexAttribArray(positionAttribute);
  GLES20.glDisableVertexAttribArray(normalAttribute);
  GLES20.glDisableVertexAttribArray(texCoordAttribute);

  GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, 0);

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

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

  GLES20.glBindTexture(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, textureId);

  GLES20.glUseProgram(quadProgram);

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

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

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

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

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

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

  ShaderUtil.checkGLError(TAG, "Draw");
}
 
Example 12
Source File: BackgroundRenderer.java    From ar-drawing-java with Apache License 2.0 4 votes vote down vote up
/**
 * Draws the AR background image.  The image will be drawn such that virtual content rendered
 * with the matrices provided by {@link Frame#getViewMatrix(float[], int)} and
 * {@link Session#getProjectionMatrix(float[], int, float, float)} will accurately follow
 * static physical objects.  This must be called <b>before</b> drawing virtual content.
 *
 * @param frame The last {@code Frame} returned by {@link Session#update()}.
 */
public void draw(Frame frame) {

    if (frame == null) {
        return;
    }

    // If display rotation changed (also includes view size change), we need to re-query the uv
    // coordinates for the screen rect, as they may have changed as well.
    if (frame.hasDisplayGeometryChanged()) {
        frame.transformDisplayUvCoords(mQuadTexCoord, mQuadTexCoordTransformed);
    }

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

    GLES20.glBindTexture(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, mTextureId);

    GLES20.glUseProgram(mQuadProgram);

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

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

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

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

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

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

    ShaderUtil.checkGLError(TAG, "Draw");
}
 
Example 13
Source File: AndroidGL.java    From trekarta with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void depthMask(boolean flag) {
    GLES20.glDepthMask(flag);

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

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

  GLES20.glBindTexture(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, textureId);

  GLES20.glUseProgram(quadProgram);

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

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

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

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

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

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

  ShaderUtil.checkGLError(TAG, "Draw");
}