com.android.grafika.gles.GlUtil Java Examples

The following examples show how to use com.android.grafika.gles.GlUtil. 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: TextureFromCameraActivity.java    From pause-resume-video-recording with Apache License 2.0 6 votes vote down vote up
/**
 * Releases most of the GL resources we currently hold (anything allocated by
 * surfaceAvailable()).
 * <p>
 * Does not release EglCore.
 */
private void releaseGl() {
    GlUtil.checkGlError("releaseGl start");

    if (mWindowSurface != null) {
        mWindowSurface.release();
        mWindowSurface = null;
    }
    if (mTexProgram != null) {
        mTexProgram.release();
        mTexProgram = null;
    }
    GlUtil.checkGlError("releaseGl done");

    mEglCore.makeNothingCurrent();
}
 
Example #2
Source File: HardwareScalerActivity.java    From grafika with Apache License 2.0 6 votes vote down vote up
/**
 * Releases most of the GL resources we currently hold.
 * <p>
 * Does not release EglCore.
 */
private void releaseGl() {
    GlUtil.checkGlError("releaseGl start");

    if (mWindowSurface != null) {
        mWindowSurface.release();
        mWindowSurface = null;
    }
    if (mFlatProgram != null) {
        mFlatProgram.release();
        mFlatProgram = null;
    }
    if (mTexProgram != null) {
        mTexProgram.release();
        mTexProgram = null;
    }
    GlUtil.checkGlError("releaseGl done");

    mEglCore.makeNothingCurrent();
}
 
Example #3
Source File: ScheduledSwapActivity.java    From grafika with Apache License 2.0 6 votes vote down vote up
/**
 * Draws the scene.
 */
private void draw() {
    GlUtil.checkGlError("draw start");

    GLES20.glClearColor(0f, 0f, 0f, 1f);
    GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT);

    GLES20.glEnable(GLES20.GL_SCISSOR_TEST);
    GLES20.glScissor(mPosition, mHeight * 2 / 8, mBlockWidth, mHeight / 8);
    GLES20.glClearColor(1f, 1f * (mDroppedFrames & 0x01),
            1f * (mChoreographerSkips & 0x01), 1f);
    GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT);
    GLES20.glDisable(GLES20.GL_SCISSOR_TEST);

    GlUtil.checkGlError("draw done");
}
 
Example #4
Source File: TextureFromCameraActivity.java    From grafika with Apache License 2.0 6 votes vote down vote up
/**
 * Releases most of the GL resources we currently hold (anything allocated by
 * surfaceAvailable()).
 * <p>
 * Does not release EglCore.
 */
private void releaseGl() {
    GlUtil.checkGlError("releaseGl start");

    if (mWindowSurface != null) {
        mWindowSurface.release();
        mWindowSurface = null;
    }
    if (mTexProgram != null) {
        mTexProgram.release();
        mTexProgram = null;
    }
    GlUtil.checkGlError("releaseGl done");

    mEglCore.makeNothingCurrent();
}
 
Example #5
Source File: RecordFBOActivity.java    From pause-resume-video-recording with Apache License 2.0 5 votes vote down vote up
/**
 * Releases most of the GL resources we currently hold.
 * <p>
 * Does not release EglCore.
 */
private void releaseGl() {
    GlUtil.checkGlError("releaseGl start");

    int[] values = new int[1];

    if (mWindowSurface != null) {
        mWindowSurface.release();
        mWindowSurface = null;
    }
    if (mProgram != null) {
        mProgram.release();
        mProgram = null;
    }
    if (mOffscreenTexture > 0) {
        values[0] = mOffscreenTexture;
        GLES20.glDeleteTextures(1, values, 0);
        mOffscreenTexture = -1;
    }
    if (mFramebuffer > 0) {
        values[0] = mFramebuffer;
        GLES20.glDeleteFramebuffers(1, values, 0);
        mFramebuffer = -1;
    }
    if (mDepthBuffer > 0) {
        values[0] = mDepthBuffer;
        GLES20.glDeleteRenderbuffers(1, values, 0);
        mDepthBuffer = -1;
    }
    if (mFullScreen != null) {
        mFullScreen.release(false); // TODO: should be "true"; must ensure mEglCore current
        mFullScreen = null;
    }

    GlUtil.checkGlError("releaseGl done");

    mEglCore.makeNothingCurrent();
}
 
Example #6
Source File: RecordFBOActivity.java    From pause-resume-video-recording with Apache License 2.0 5 votes vote down vote up
/**
 * Draws the scene.
 */
private void draw() {
    GlUtil.checkGlError("draw start");

    // Clear to a non-black color to make the content easily differentiable from
    // the pillar-/letter-boxing.
    GLES20.glClearColor(0.2f, 0.2f, 0.2f, 1.0f);
    GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT);

    mTri.draw(mProgram, mDisplayProjectionMatrix);
    mRect.draw(mProgram, mDisplayProjectionMatrix);
    for (int i = 0; i < 4; i++) {
        if (false && mPreviousWasDropped) {
            mEdges[i].setColor(1.0f, 0.0f, 0.0f);
        } else {
            mEdges[i].setColor(0.5f, 0.5f, 0.5f);
        }
        mEdges[i].draw(mProgram, mDisplayProjectionMatrix);
    }

    // Give a visual indication of the recording method.
    switch (mRecordMethod) {
        case RECMETHOD_DRAW_TWICE:
            mRecordRect.setColor(1.0f, 0.0f, 0.0f);
            break;
        case RECMETHOD_FBO:
            mRecordRect.setColor(0.0f, 1.0f, 0.0f);
            break;
        case RECMETHOD_BLIT_FRAMEBUFFER:
            mRecordRect.setColor(0.0f, 0.0f, 1.0f);
            break;
        default:
    }
    mRecordRect.draw(mProgram, mDisplayProjectionMatrix);

    GlUtil.checkGlError("draw done");
}
 
Example #7
Source File: TextureFromCameraActivity.java    From pause-resume-video-recording with Apache License 2.0 5 votes vote down vote up
/**
 * Draws the scene and submits the buffer.
 */
private void draw() {
    GlUtil.checkGlError("draw start");

    GLES20.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
    GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT);
    mRect.draw(mTexProgram, mDisplayProjectionMatrix);
    mWindowSurface.swapBuffers();

    GlUtil.checkGlError("draw done");
}
 
Example #8
Source File: HardwareScalerActivity.java    From grafika with Apache License 2.0 5 votes vote down vote up
/**
 * Draws the scene.
 */
private void draw() {
    GlUtil.checkGlError("draw start");

    // Clear to a non-black color to make the content easily differentiable from
    // the pillar-/letter-boxing.
    GLES20.glClearColor(0.2f, 0.2f, 0.2f, 1.0f);
    GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT);

    // Textures may include alpha, so turn blending on.
    GLES20.glEnable(GLES20.GL_BLEND);
    GLES20.glBlendFunc(GLES20.GL_ONE, GLES20.GL_ONE_MINUS_SRC_ALPHA);
    if (mUseFlatShading) {
        mTri.draw(mFlatProgram, mDisplayProjectionMatrix);
        mRect.draw(mFlatProgram, mDisplayProjectionMatrix);
    } else {
        mTri.draw(mTexProgram, mDisplayProjectionMatrix);
        mRect.draw(mTexProgram, mDisplayProjectionMatrix);
    }
    GLES20.glDisable(GLES20.GL_BLEND);

    for (int i = 0; i < 4; i++) {
        mEdges[i].draw(mFlatProgram, mDisplayProjectionMatrix);
    }

    GlUtil.checkGlError("draw done");
}
 
Example #9
Source File: ScheduledSwapActivity.java    From grafika with Apache License 2.0 5 votes vote down vote up
/**
 * Releases most of the GL resources we currently hold.
 * <p>
 * Does not release EglCore.
 */
private void releaseGl() {
    GlUtil.checkGlError("releaseGl start");

    if (mWindowSurface != null) {
        mWindowSurface.release();
        mWindowSurface = null;
    }

    GlUtil.checkGlError("releaseGl done");

    mEglCore.makeNothingCurrent();
}
 
Example #10
Source File: RecordFBOActivity.java    From grafika with Apache License 2.0 5 votes vote down vote up
/**
 * Releases most of the GL resources we currently hold.
 * <p>
 * Does not release EglCore.
 */
private void releaseGl() {
    GlUtil.checkGlError("releaseGl start");

    int[] values = new int[1];

    if (mWindowSurface != null) {
        mWindowSurface.release();
        mWindowSurface = null;
    }
    if (mProgram != null) {
        mProgram.release();
        mProgram = null;
    }
    if (mOffscreenTexture > 0) {
        values[0] = mOffscreenTexture;
        GLES20.glDeleteTextures(1, values, 0);
        mOffscreenTexture = -1;
    }
    if (mFramebuffer > 0) {
        values[0] = mFramebuffer;
        GLES20.glDeleteFramebuffers(1, values, 0);
        mFramebuffer = -1;
    }
    if (mDepthBuffer > 0) {
        values[0] = mDepthBuffer;
        GLES20.glDeleteRenderbuffers(1, values, 0);
        mDepthBuffer = -1;
    }
    if (mFullScreen != null) {
        mFullScreen.release(false); // TODO: should be "true"; must ensure mEglCore current
        mFullScreen = null;
    }

    GlUtil.checkGlError("releaseGl done");

    mEglCore.makeNothingCurrent();
}
 
Example #11
Source File: RecordFBOActivity.java    From grafika with Apache License 2.0 5 votes vote down vote up
/**
 * Draws the scene.
 */
private void draw() {
    GlUtil.checkGlError("draw start");

    // Clear to a non-black color to make the content easily differentiable from
    // the pillar-/letter-boxing.
    GLES20.glClearColor(0.2f, 0.2f, 0.2f, 1.0f);
    GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT);

    mTri.draw(mProgram, mDisplayProjectionMatrix);
    mRect.draw(mProgram, mDisplayProjectionMatrix);
    for (int i = 0; i < 4; i++) {
        if (false && mPreviousWasDropped) {
            mEdges[i].setColor(1.0f, 0.0f, 0.0f);
        } else {
            mEdges[i].setColor(0.5f, 0.5f, 0.5f);
        }
        mEdges[i].draw(mProgram, mDisplayProjectionMatrix);
    }

    // Give a visual indication of the recording method.
    switch (mRecordMethod) {
        case RECMETHOD_DRAW_TWICE:
            mRecordRect.setColor(1.0f, 0.0f, 0.0f);
            break;
        case RECMETHOD_FBO:
            mRecordRect.setColor(0.0f, 1.0f, 0.0f);
            break;
        case RECMETHOD_BLIT_FRAMEBUFFER:
            mRecordRect.setColor(0.0f, 0.0f, 1.0f);
            break;
        default:
    }
    mRecordRect.draw(mProgram, mDisplayProjectionMatrix);

    GlUtil.checkGlError("draw done");
}
 
Example #12
Source File: TextureFromCameraActivity.java    From grafika with Apache License 2.0 5 votes vote down vote up
/**
 * Draws the scene and submits the buffer.
 */
private void draw() {
    GlUtil.checkGlError("draw start");

    GLES20.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
    GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT);
    mRect.draw(mTexProgram, mDisplayProjectionMatrix);
    mWindowSurface.swapBuffers();

    GlUtil.checkGlError("draw done");
}
 
Example #13
Source File: GLTextureRender.java    From IjkVRPlayer with Apache License 2.0 4 votes vote down vote up
@Override
public void onSurfaceChanged(GL10 gl, int width, int height) {
    if (BuildConfig.DEBUG) Log.d(TAG, "onSurfaceChanged " + width + "x" + height);
    GLES20.glViewport(0, 0, width, height);
    GlUtil.checkGlError("glViewport");
}
 
Example #14
Source File: RecordFBOActivity.java    From pause-resume-video-recording with Apache License 2.0 4 votes vote down vote up
/**
 * Prepares the off-screen framebuffer.
 */
private void prepareFramebuffer(int width, int height) {
    GlUtil.checkGlError("prepareFramebuffer start");

    int[] values = new int[1];

    // Create a texture object and bind it.  This will be the color buffer.
    GLES20.glGenTextures(1, values, 0);
    GlUtil.checkGlError("glGenTextures");
    mOffscreenTexture = values[0];   // expected > 0
    GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mOffscreenTexture);
    GlUtil.checkGlError("glBindTexture " + mOffscreenTexture);

    // Create texture storage.
    GLES20.glTexImage2D(GLES20.GL_TEXTURE_2D, 0, GLES20.GL_RGBA, width, height, 0,
            GLES20.GL_RGBA, GLES20.GL_UNSIGNED_BYTE, null);

    // Set parameters.  We're probably using non-power-of-two dimensions, so
    // some values may not be available for use.
    GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MIN_FILTER,
            GLES20.GL_NEAREST);
    GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MAG_FILTER,
            GLES20.GL_LINEAR);
    GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_S,
            GLES20.GL_CLAMP_TO_EDGE);
    GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_T,
            GLES20.GL_CLAMP_TO_EDGE);
    GlUtil.checkGlError("glTexParameter");

    // Create framebuffer object and bind it.
    GLES20.glGenFramebuffers(1, values, 0);
    GlUtil.checkGlError("glGenFramebuffers");
    mFramebuffer = values[0];    // expected > 0
    GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, mFramebuffer);
    GlUtil.checkGlError("glBindFramebuffer " + mFramebuffer);

    // Create a depth buffer and bind it.
    GLES20.glGenRenderbuffers(1, values, 0);
    GlUtil.checkGlError("glGenRenderbuffers");
    mDepthBuffer = values[0];    // expected > 0
    GLES20.glBindRenderbuffer(GLES20.GL_RENDERBUFFER, mDepthBuffer);
    GlUtil.checkGlError("glBindRenderbuffer " + mDepthBuffer);

    // Allocate storage for the depth buffer.
    GLES20.glRenderbufferStorage(GLES20.GL_RENDERBUFFER, GLES20.GL_DEPTH_COMPONENT16,
            width, height);
    GlUtil.checkGlError("glRenderbufferStorage");

    // Attach the depth buffer and the texture (color buffer) to the framebuffer object.
    GLES20.glFramebufferRenderbuffer(GLES20.GL_FRAMEBUFFER, GLES20.GL_DEPTH_ATTACHMENT,
            GLES20.GL_RENDERBUFFER, mDepthBuffer);
    GlUtil.checkGlError("glFramebufferRenderbuffer");
    GLES20.glFramebufferTexture2D(GLES20.GL_FRAMEBUFFER, GLES20.GL_COLOR_ATTACHMENT0,
            GLES20.GL_TEXTURE_2D, mOffscreenTexture, 0);
    GlUtil.checkGlError("glFramebufferTexture2D");

    // See if GLES is happy with all this.
    int status = GLES20.glCheckFramebufferStatus(GLES20.GL_FRAMEBUFFER);
    if (status != GLES20.GL_FRAMEBUFFER_COMPLETE) {
        throw new RuntimeException("Framebuffer not complete, status=" + status);
    }

    // Switch back to the default framebuffer.
    GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, 0);

    GlUtil.checkGlError("prepareFramebuffer done");
}
 
Example #15
Source File: RecordFBOActivity.java    From grafika with Apache License 2.0 4 votes vote down vote up
/**
 * Prepares the off-screen framebuffer.
 */
private void prepareFramebuffer(int width, int height) {
    GlUtil.checkGlError("prepareFramebuffer start");

    int[] values = new int[1];

    // Create a texture object and bind it.  This will be the color buffer.
    GLES20.glGenTextures(1, values, 0);
    GlUtil.checkGlError("glGenTextures");
    mOffscreenTexture = values[0];   // expected > 0
    GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mOffscreenTexture);
    GlUtil.checkGlError("glBindTexture " + mOffscreenTexture);

    // Create texture storage.
    GLES20.glTexImage2D(GLES20.GL_TEXTURE_2D, 0, GLES20.GL_RGBA, width, height, 0,
            GLES20.GL_RGBA, GLES20.GL_UNSIGNED_BYTE, null);

    // Set parameters.  We're probably using non-power-of-two dimensions, so
    // some values may not be available for use.
    GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MIN_FILTER,
            GLES20.GL_NEAREST);
    GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MAG_FILTER,
            GLES20.GL_LINEAR);
    GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_S,
            GLES20.GL_CLAMP_TO_EDGE);
    GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_T,
            GLES20.GL_CLAMP_TO_EDGE);
    GlUtil.checkGlError("glTexParameter");

    // Create framebuffer object and bind it.
    GLES20.glGenFramebuffers(1, values, 0);
    GlUtil.checkGlError("glGenFramebuffers");
    mFramebuffer = values[0];    // expected > 0
    GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, mFramebuffer);
    GlUtil.checkGlError("glBindFramebuffer " + mFramebuffer);

    // Create a depth buffer and bind it.
    GLES20.glGenRenderbuffers(1, values, 0);
    GlUtil.checkGlError("glGenRenderbuffers");
    mDepthBuffer = values[0];    // expected > 0
    GLES20.glBindRenderbuffer(GLES20.GL_RENDERBUFFER, mDepthBuffer);
    GlUtil.checkGlError("glBindRenderbuffer " + mDepthBuffer);

    // Allocate storage for the depth buffer.
    GLES20.glRenderbufferStorage(GLES20.GL_RENDERBUFFER, GLES20.GL_DEPTH_COMPONENT16,
            width, height);
    GlUtil.checkGlError("glRenderbufferStorage");

    // Attach the depth buffer and the texture (color buffer) to the framebuffer object.
    GLES20.glFramebufferRenderbuffer(GLES20.GL_FRAMEBUFFER, GLES20.GL_DEPTH_ATTACHMENT,
            GLES20.GL_RENDERBUFFER, mDepthBuffer);
    GlUtil.checkGlError("glFramebufferRenderbuffer");
    GLES20.glFramebufferTexture2D(GLES20.GL_FRAMEBUFFER, GLES20.GL_COLOR_ATTACHMENT0,
            GLES20.GL_TEXTURE_2D, mOffscreenTexture, 0);
    GlUtil.checkGlError("glFramebufferTexture2D");

    // See if GLES is happy with all this.
    int status = GLES20.glCheckFramebufferStatus(GLES20.GL_FRAMEBUFFER);
    if (status != GLES20.GL_FRAMEBUFFER_COMPLETE) {
        throw new RuntimeException("Framebuffer not complete, status=" + status);
    }

    // Switch back to the default framebuffer.
    GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, 0);

    GlUtil.checkGlError("prepareFramebuffer done");
}