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

The following examples show how to use android.opengl.GLES20#glDeleteFramebuffers() . 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: JPGFileEndpoint.java    From AndroidFastImageProcessing with MIT License 6 votes vote down vote up
@Override
public void destroy() {
	super.destroy();
	if(frameBuffer != null) {
		GLES20.glDeleteFramebuffers(1, frameBuffer, 0);
		frameBuffer = null;
	}
	if(texture_out != null) {
		GLES20.glDeleteTextures(1, texture_out, 0);
		texture_out = null;
	}
	if(depthRenderBuffer != null) {
		GLES20.glDeleteRenderbuffers(1, depthRenderBuffer, 0);
		depthRenderBuffer = null;
	}
}
 
Example 2
Source File: CameraGLRendererBase.java    From MOAAP with MIT License 5 votes vote down vote up
private void deleteFBO()
{
    Log.d(LOGTAG, "deleteFBO("+mFBOWidth+"x"+mFBOHeight+")");
    GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, 0);
    GLES20.glDeleteFramebuffers(1, FBO, 0);

    deleteTex(texFBO);
    deleteTex(texDraw);
    mFBOWidth = mFBOHeight = 0;
}
 
Example 3
Source File: CameraGLRendererBase.java    From MOAAP with MIT License 5 votes vote down vote up
private void deleteFBO()
{
    Log.d(LOGTAG, "deleteFBO("+mFBOWidth+"x"+mFBOHeight+")");
    GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, 0);
    GLES20.glDeleteFramebuffers(1, FBO, 0);

    deleteTex(texFBO);
    deleteTex(texDraw);
    mFBOWidth = mFBOHeight = 0;
}
 
Example 4
Source File: GlTextureFrameBuffer.java    From webrtc_android with MIT License 5 votes vote down vote up
/**
 * Release texture and framebuffer. An EGLContext must be bound on the current thread when calling
 * this function. This object should not be used after this call.
 */
public void release() {
  GLES20.glDeleteTextures(1, new int[] {textureId}, 0);
  textureId = 0;
  GLES20.glDeleteFramebuffers(1, new int[] {frameBufferId}, 0);
  frameBufferId = 0;
  width = 0;
  height = 0;
}
 
Example 5
Source File: CameraGLRendererBase.java    From MOAAP with MIT License 5 votes vote down vote up
private void deleteFBO()
{
    Log.d(LOGTAG, "deleteFBO("+mFBOWidth+"x"+mFBOHeight+")");
    GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, 0);
    GLES20.glDeleteFramebuffers(1, FBO, 0);

    deleteTex(texFBO);
    deleteTex(texDraw);
    mFBOWidth = mFBOHeight = 0;
}
 
Example 6
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 7
Source File: CameraGLRendererBase.java    From real_time_circle_detection_android with MIT License 5 votes vote down vote up
private void deleteFBO()
{
    Log.d(LOGTAG, "deleteFBO("+mFBOWidth+"x"+mFBOHeight+")");
    GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, 0);
    GLES20.glDeleteFramebuffers(1, FBO, 0);

    deleteTex(texFBO);
    deleteTex(texDraw);
    mFBOWidth = mFBOHeight = 0;
}
 
Example 8
Source File: GLES20FramebufferObject.java    From CameraRecorder-android with MIT License 5 votes vote down vote up
public void release() {
    final int[] args = new int[1];
    args[0] = texName;
    GLES20.glDeleteTextures(args.length, args, 0);
    texName = 0;
    args[0] = renderBufferName;
    GLES20.glDeleteRenderbuffers(args.length, args, 0);
    renderBufferName = 0;
    args[0] = framebufferName;
    GLES20.glDeleteFramebuffers(args.length, args, 0);
    framebufferName = 0;
}
 
Example 9
Source File: GLState.java    From 30-android-libraries-in-30-days with Apache License 2.0 5 votes vote down vote up
public void deleteFramebuffer(final int pHardwareFramebufferID) {
	if(this.mCurrentFramebufferID == pHardwareFramebufferID) {
		this.mCurrentFramebufferID = -1;
	}
	this.mHardwareIDContainer[0] = pHardwareFramebufferID;
	GLES20.glDeleteFramebuffers(1, this.mHardwareIDContainer, 0);
}
 
Example 10
Source File: CameraGLRendererBase.java    From pasm-yolov3-Android with GNU General Public License v3.0 5 votes vote down vote up
private void deleteFBO()
{
    Log.d(LOGTAG, "deleteFBO("+mFBOWidth+"x"+mFBOHeight+")");
    GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, 0);
    GLES20.glDeleteFramebuffers(1, FBO, 0);

    deleteTex(texFBO);
    deleteTex(texDraw);
    mFBOWidth = mFBOHeight = 0;
}
 
Example 11
Source File: FrameBufferSource.java    From Tanks with MIT License 5 votes vote down vote up
@Override
public void release(FrameBuffer frameBuffer)
{
  GLES20.glDeleteFramebuffers(1, new int[] { frameBuffer.frameBufferHandle }, 0);
  GLES20.glDeleteRenderbuffers(1, new int[]{ frameBuffer.renderTextureHandle }, 0);
  GLES20.glDeleteTextures(1, new int[]{ frameBuffer.depthTextureHandle }, 0);
}
 
Example 12
Source File: CameraGLRendererBase.java    From OpenCV-Android-Object-Detection with MIT License 5 votes vote down vote up
private void deleteFBO()
{
    Log.d(LOGTAG, "deleteFBO("+mFBOWidth+"x"+mFBOHeight+")");
    GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, 0);
    GLES20.glDeleteFramebuffers(1, FBO, 0);

    deleteTex(texFBO);
    deleteTex(texDraw);
    mFBOWidth = mFBOHeight = 0;
}
 
Example 13
Source File: OpenGlUtils.java    From TikTok with Apache License 2.0 4 votes vote down vote up
public static Bitmap drawToBitmapByFilter(Bitmap bitmap, GPUImageFilter filter,
                                          int displayWidth, int displayHeight, boolean rotate){
    if(filter == null)
        return null;
    int width = bitmap.getWidth();
    int height = bitmap.getHeight();
    int[] mFrameBuffers = new int[1];
    int[] mFrameBufferTextures = new int[1];
    GLES20.glGenFramebuffers(1, mFrameBuffers, 0);
    GLES20.glGenTextures(1, mFrameBufferTextures, 0);
    GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mFrameBufferTextures[0]);
    GLES20.glTexImage2D(GLES20.GL_TEXTURE_2D, 0, GLES20.GL_RGBA, width, height, 0,
            GLES20.GL_RGBA, GLES20.GL_UNSIGNED_BYTE, null);
    GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D,
            GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_LINEAR);
    GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D,
            GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_LINEAR);
    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.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, mFrameBuffers[0]);
    GLES20.glFramebufferTexture2D(GLES20.GL_FRAMEBUFFER, GLES20.GL_COLOR_ATTACHMENT0,
            GLES20.GL_TEXTURE_2D, mFrameBufferTextures[0], 0);
    GLES20.glViewport(0, 0, width, height);
    filter.onInputSizeChanged(width, height);
    filter.onDisplaySizeChanged(displayWidth, displayHeight);
    int textureId = OpenGlUtils.loadTexture(bitmap, OpenGlUtils.NO_TEXTURE, true);
    if(rotate){
        FloatBuffer gLCubeBuffer = ByteBuffer
                .allocateDirect(TextureRotationUtil.CUBE_BAAB.length * 4)
                .order(ByteOrder.nativeOrder())
                .asFloatBuffer();
        gLCubeBuffer.put(TextureRotationUtil.CUBE_BAAB).position(0);

        FloatBuffer gLTextureBuffer = ByteBuffer
                .allocateDirect(TextureRotationUtil.TEXTURE_NO_ROTATION.length * 4)
                .order(ByteOrder.nativeOrder())
                .asFloatBuffer();
        gLTextureBuffer.put(TextureRotationUtil.getRotation(Rotation.ROTATION_90, true, false)).position(0);
        filter.onDrawFrame(textureId, gLCubeBuffer, gLTextureBuffer);
    }else {
        filter.onDrawFrame(textureId);
    }
    IntBuffer ib = IntBuffer.allocate(width * height);
    GLES20.glReadPixels(0, 0, width, height, GLES20.GL_RGBA, GLES20.GL_UNSIGNED_BYTE, ib);
    Bitmap result = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
    result.copyPixelsFromBuffer(IntBuffer.wrap(ib.array()));
    GLES20.glDeleteTextures(1, new int[]{textureId}, 0);
    GLES20.glDeleteFramebuffers(1, mFrameBuffers, 0);
    GLES20.glDeleteTextures(1, mFrameBufferTextures, 0);
    filter.onInputSizeChanged(displayWidth, displayHeight);
    return result;
}
 
Example 14
Source File: FBO.java    From Fatigue-Detection with MIT License 4 votes vote down vote up
void destroy(){
    GLES20.glDeleteTextures(1, new int[]{frameBufferTexture}, 0);
    GLES20.glDeleteFramebuffers(1, new int[]{frameBuffer}, 0);
}
 
Example 15
Source File: GLES20IdImpl.java    From TurboLauncher with Apache License 2.0 4 votes vote down vote up
@Override
public void glDeleteFramebuffers(GL11ExtensionPack gl11ep, int n, int[] buffers, int offset) {
    GLES20.glDeleteFramebuffers(n, buffers, offset);
    GLES20Canvas.checkError();
}
 
Example 16
Source File: CameraSurfaceView.java    From Paddle-Lite-Demo with Apache License 2.0 4 votes vote down vote up
public void openCamera() {
    if (disableCamera) return;
    camera = Camera.open(selectedCameraId);
    List<Size> supportedPreviewSizes = camera.getParameters().getSupportedPreviewSizes();
    Size previewSize = Utils.getOptimalPreviewSize(supportedPreviewSizes, EXPECTED_PREVIEW_WIDTH,
            EXPECTED_PREVIEW_HEIGHT);
    Camera.Parameters parameters = camera.getParameters();
    parameters.setPreviewSize(previewSize.width, previewSize.height);
    if (parameters.getSupportedFocusModes().contains(Camera.Parameters.FOCUS_MODE_CONTINUOUS_VIDEO)) {
        parameters.setFocusMode(Camera.Parameters.FOCUS_MODE_CONTINUOUS_VIDEO);
    }
    camera.setParameters(parameters);
    int degree = Utils.getCameraDisplayOrientation(context, selectedCameraId);
    camera.setDisplayOrientation(degree);
    boolean rotate = degree == 90 || degree == 270;
    textureWidth = rotate ? previewSize.height : previewSize.width;
    textureHeight = rotate ? previewSize.width : previewSize.height;
    // Destroy FBO and draw textures
    GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, 0);
    GLES20.glDeleteFramebuffers(1, fbo, 0);
    GLES20.glDeleteTextures(1, drawTexureId, 0);
    GLES20.glDeleteTextures(1, fboTexureId, 0);
    // Normal texture for storing modified camera preview data(RGBA format)
    GLES20.glGenTextures(1, drawTexureId, 0);
    GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, drawTexureId[0]);
    GLES20.glTexImage2D(GLES20.GL_TEXTURE_2D, 0, GLES20.GL_RGBA, textureWidth, textureHeight, 0,
            GLES20.GL_RGBA, GLES20.GL_UNSIGNED_BYTE, null);
    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);
    GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_NEAREST);
    GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_NEAREST);
    // FBO texture for storing camera preview data(RGBA format)
    GLES20.glGenTextures(1, fboTexureId, 0);
    GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, fboTexureId[0]);
    GLES20.glTexImage2D(GLES20.GL_TEXTURE_2D, 0, GLES20.GL_RGBA, textureWidth, textureHeight, 0,
            GLES20.GL_RGBA, GLES20.GL_UNSIGNED_BYTE, null);
    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);
    GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_NEAREST);
    GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_NEAREST);
    // Generate FBO and bind to FBO texture
    GLES20.glGenFramebuffers(1, fbo, 0);
    GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, fbo[0]);
    GLES20.glFramebufferTexture2D(GLES20.GL_FRAMEBUFFER, GLES20.GL_COLOR_ATTACHMENT0, GLES20.GL_TEXTURE_2D,
            fboTexureId[0], 0);
    try {
        camera.setPreviewTexture(surfaceTexture);
    } catch (IOException exception) {
        Log.e(TAG, "IOException caused by setPreviewDisplay()", exception);
    }
    camera.startPreview();
}
 
Example 17
Source File: GLES20IdImpl.java    From android-openGL-canvas with Apache License 2.0 4 votes vote down vote up
@Override
public void glDeleteFramebuffers(int n, int[] buffers, int offset) {
    GLES20.glDeleteFramebuffers(n, buffers, offset);
    GLES20Canvas.checkError();
}
 
Example 18
Source File: FBORender.java    From EZFilter with MIT License 4 votes vote down vote up
private void initFBO() {
    // 初始化输出纹理
    if (mTextureOut != null) {
        GLES20.glDeleteTextures(1, mTextureOut, 0);
        mTextureOut = null;
    }
    mTextureOut = new int[1];
    GLES20.glGenTextures(1, mTextureOut, 0);
    GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
    GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mTextureOut[0]);

    GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D,
            GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_LINEAR);
    GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D,
            GLES20.GL_TEXTURE_MIN_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);

    GLES20.glTexImage2D(GLES20.GL_TEXTURE_2D, 0, GLES20.GL_RGBA,
            getWidth(), getHeight(), 0, GLES20.GL_RGBA,
            GLES20.GL_UNSIGNED_BYTE, null);

    // 初始化帧缓冲和深度缓冲
    if (mFrameBuffer != null) {
        GLES20.glDeleteFramebuffers(1, mFrameBuffer, 0);
        mFrameBuffer = null;
    }
    if (mDepthRenderBuffer != null) {
        GLES20.glDeleteRenderbuffers(1, mDepthRenderBuffer, 0);
        mDepthRenderBuffer = null;
    }
    mFrameBuffer = new int[1];
    mDepthRenderBuffer = new int[1];
    GLES20.glGenFramebuffers(1, mFrameBuffer, 0);
    GLES20.glGenRenderbuffers(1, mDepthRenderBuffer, 0);
    GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, mFrameBuffer[0]);
    GLES20.glFramebufferTexture2D(GLES20.GL_FRAMEBUFFER,
            GLES20.GL_COLOR_ATTACHMENT0, GLES20.GL_TEXTURE_2D,
            mTextureOut[0], 0);
    GLES20.glBindRenderbuffer(GLES20.GL_RENDERBUFFER, mDepthRenderBuffer[0]);
    GLES20.glRenderbufferStorage(GLES20.GL_RENDERBUFFER,
            GLES20.GL_DEPTH_COMPONENT16, getWidth(), getHeight());
    GLES20.glFramebufferRenderbuffer(GLES20.GL_FRAMEBUFFER,
            GLES20.GL_DEPTH_ATTACHMENT, GLES20.GL_RENDERBUFFER,
            mDepthRenderBuffer[0]);
}
 
Example 19
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 20
Source File: BitmapOutput.java    From AndroidFastImageProcessing with MIT License votes vote down vote up
@Override
	public void destroy() {
		super.destroy();
		if(frameBuffer != null) {
			GLES20.glDeleteFramebuffers(1, frameBuffer, 0);
			frameBuffer = null;
		}
		if(texture_out != null) {
			GLES20.glDeleteTextures(1, texture_out, 0);
			texture_out = null;
		}
		if(depthRenderBuffer != null) {
			GLES20.glDeleteRenderbuffers(1, depthRenderBuffer, 0);
			depthRenderBuffer = null;
		}
	}