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

The following examples show how to use android.opengl.GLES20#glFramebufferRenderbuffer() . 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 updateFrameBufferAttachment(FrameBuffer fb, RenderBuffer rb) {
        boolean needAttach;
        if (rb.getTexture() == null) {
            // if it hasn't been created yet, then attach is required.
            needAttach = rb.getId() == -1;
            updateRenderBuffer(fb, rb);
        } else {
            needAttach = false;
            updateRenderTexture(fb, rb);
        }
        if (needAttach) {
            GLES20.glFramebufferRenderbuffer(GLES20.GL_FRAMEBUFFER,
                    convertAttachmentSlot(rb.getSlot()),
                    GLES20.GL_RENDERBUFFER,
                    rb.getId());

//            RendererUtil.checkGLError();
        }
    }
 
Example 2
Source File: JPGFileEndpoint.java    From UltimateAndroid with Apache License 2.0 5 votes vote down vote up
private void initFBO() {
	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;
	}
	frameBuffer = new int[1];
	texture_out = new int[1];
	depthRenderBuffer = new int[1];
	GLES20.glGenFramebuffers(1, frameBuffer, 0);
	GLES20.glGenRenderbuffers(1, depthRenderBuffer, 0);
	GLES20.glGenTextures(1, texture_out, 0);
	
	GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, frameBuffer[0]);
	
	GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
	GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, texture_out[0]);
	GLES20.glTexImage2D(GLES20.GL_TEXTURE_2D, 0, GLES20.GL_RGBA, getWidth(), getHeight(), 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_MAG_FILTER, GLES20.GL_LINEAR);
	GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_LINEAR);
	GLES20.glFramebufferTexture2D(GLES20.GL_FRAMEBUFFER, GLES20.GL_COLOR_ATTACHMENT0, GLES20.GL_TEXTURE_2D, texture_out[0], 0);
	
	GLES20.glBindRenderbuffer(GLES20.GL_RENDERBUFFER, depthRenderBuffer[0]);
	GLES20.glRenderbufferStorage(GLES20.GL_RENDERBUFFER, GLES20.GL_DEPTH_COMPONENT16, getWidth(), getHeight());
	GLES20.glFramebufferRenderbuffer(GLES20.GL_FRAMEBUFFER, GLES20.GL_DEPTH_ATTACHMENT, GLES20.GL_RENDERBUFFER, depthRenderBuffer[0]);
	
	int status = GLES20.glCheckFramebufferStatus(GLES20.GL_FRAMEBUFFER);
	if (status != GLES20.GL_FRAMEBUFFER_COMPLETE) {
		throw new RuntimeException(this+": Failed to set up render buffer with status "+status+" and error "+GLES20.glGetError());
	}
}
 
Example 3
Source File: JPGFileEndpoint.java    From AndroidFastImageProcessing with MIT License 5 votes vote down vote up
private void initFBO() {
	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;
	}
	frameBuffer = new int[1];
	texture_out = new int[1];
	depthRenderBuffer = new int[1];
	GLES20.glGenFramebuffers(1, frameBuffer, 0);
	GLES20.glGenRenderbuffers(1, depthRenderBuffer, 0);
	GLES20.glGenTextures(1, texture_out, 0);
	
	GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, frameBuffer[0]);
	
	GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
	GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, texture_out[0]);
	GLES20.glTexImage2D(GLES20.GL_TEXTURE_2D, 0, GLES20.GL_RGBA, getWidth(), getHeight(), 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_MAG_FILTER, GLES20.GL_LINEAR);
	GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_LINEAR);
	GLES20.glFramebufferTexture2D(GLES20.GL_FRAMEBUFFER, GLES20.GL_COLOR_ATTACHMENT0, GLES20.GL_TEXTURE_2D, texture_out[0], 0);
	
	GLES20.glBindRenderbuffer(GLES20.GL_RENDERBUFFER, depthRenderBuffer[0]);
	GLES20.glRenderbufferStorage(GLES20.GL_RENDERBUFFER, GLES20.GL_DEPTH_COMPONENT16, getWidth(), getHeight());
	GLES20.glFramebufferRenderbuffer(GLES20.GL_FRAMEBUFFER, GLES20.GL_DEPTH_ATTACHMENT, GLES20.GL_RENDERBUFFER, depthRenderBuffer[0]);
	
	int status = GLES20.glCheckFramebufferStatus(GLES20.GL_FRAMEBUFFER);
	if (status != GLES20.GL_FRAMEBUFFER_COMPLETE) {
		throw new RuntimeException(this+": Failed to set up render buffer with status "+status+" and error "+GLES20.glGetError());
	}
}
 
Example 4
Source File: ScreenRectangle.java    From OpenGLESRecorder with Apache License 2.0 5 votes vote down vote up
private void createFrameBuffer() {
    int [] framebuffers = new int[1];
    GLES20.glGenFramebuffers(1, framebuffers, 0);
    int framebufferId = framebuffers[0];
    GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, framebufferId);
    GLUtil.checkGLError("glBindFramebuffer");
    mFrameBufferID = framebufferId;
    GLES20.glFramebufferTexture2D(GLES20.GL_FRAMEBUFFER, GLES20.GL_COLOR_ATTACHMENT0, GLES20.GL_TEXTURE_2D, mOffScreenTexture, 0);
    GLUtil.checkGLError("beginDraw glFramebufferTexture2D");
    GLES20.glFramebufferRenderbuffer(GLES20.GL_FRAMEBUFFER, GLES20.GL_DEPTH_ATTACHMENT, GLES20.GL_RENDERBUFFER, mRenderBuffer);
    GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, 0);
}
 
Example 5
Source File: FrameBuffer.java    From AAVT with Apache License 2.0 5 votes vote down vote up
/**
 * 创建FrameBuffer
 * @param hasRenderBuffer 是否启用RenderBuffer
 * @param width 宽度
 * @param height 高度
 * @param texType 类型,一般为{@link GLES20#GL_TEXTURE_2D}
 * @param texFormat 纹理格式,一般为{@link GLES20#GL_RGBA}、{@link GLES20#GL_RGB}等
 * @param minParams 纹理的缩小过滤参数
 * @param maxParams 纹理的放大过滤参数
 * @param wrapS 纹理的S环绕参数
 * @param wrapT 纹理的W环绕参数
 * @return 创建结果,0表示成功,其他值为GL错误
 */
public int createFrameBuffer(boolean hasRenderBuffer,int width,int height,int texType,int texFormat,
                             int minParams,int maxParams,int wrapS,int wrapT){
    mFrameTemp=new int[4];
    GLES20.glGenFramebuffers(1,mFrameTemp,0);
    GLES20.glGenTextures(1,mFrameTemp,1);
    GLES20.glBindTexture(texType,mFrameTemp[1]);
    GLES20.glTexImage2D(texType, 0,texFormat, width, height,
            0, texFormat, GLES20.GL_UNSIGNED_BYTE, null);
    //设置缩小过滤为使用纹理中坐标最接近的一个像素的颜色作为需要绘制的像素颜色
    GLES20.glTexParameteri(texType, GLES20.GL_TEXTURE_MIN_FILTER,minParams);
    //设置放大过滤为使用纹理中坐标最接近的若干个颜色,通过加权平均算法得到需要绘制的像素颜色
    GLES20.glTexParameteri(texType, GLES20.GL_TEXTURE_MAG_FILTER,maxParams);
    //设置环绕方向S,截取纹理坐标到[1/2n,1-1/2n]。将导致永远不会与border融合
    GLES20.glTexParameteri(texType, GLES20.GL_TEXTURE_WRAP_S,wrapS);
    //设置环绕方向T,截取纹理坐标到[1/2n,1-1/2n]。将导致永远不会与border融合
    GLES20.glTexParameteri(texType, GLES20.GL_TEXTURE_WRAP_T,wrapT);

    GLES20.glGetIntegerv(GLES20.GL_FRAMEBUFFER_BINDING,mFrameTemp,3);
    GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER,mFrameTemp[0]);
    GLES20.glFramebufferTexture2D(GLES20.GL_FRAMEBUFFER, GLES20.GL_COLOR_ATTACHMENT0,
            texType, mFrameTemp[1], 0);
    if(hasRenderBuffer){
        GLES20.glGenRenderbuffers(1,mFrameTemp,2);
        GLES20.glBindRenderbuffer(GLES20.GL_RENDERBUFFER,mFrameTemp[2]);
        GLES20.glRenderbufferStorage(GLES20.GL_RENDERBUFFER,GLES20.GL_DEPTH_COMPONENT16,width,height);
        GLES20.glFramebufferRenderbuffer(GLES20.GL_FRAMEBUFFER,GLES20.GL_DEPTH_ATTACHMENT,GLES20.GL_RENDERBUFFER,mFrameTemp[2]);
    }
    return GLES20.glGetError();
}
 
Example 6
Source File: BaseRenderOffScreen.java    From rtmp-rtsp-stream-client-java with Apache License 2.0 5 votes vote down vote up
protected void initFBO(int width, int height, int[] fboId, int[] rboId, int[] texId) {
  GlUtil.checkGlError("initFBO_S");

  GLES20.glGenFramebuffers(1, fboId, 0);
  GLES20.glGenRenderbuffers(1, rboId, 0);
  GLES20.glGenTextures(1, texId, 0);

  GLES20.glBindRenderbuffer(GLES20.GL_RENDERBUFFER, rboId[0]);
  GLES20.glRenderbufferStorage(GLES20.GL_RENDERBUFFER, GLES20.GL_DEPTH_COMPONENT16, width,
      height);
  GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, fboId[0]);
  GLES20.glFramebufferRenderbuffer(GLES20.GL_FRAMEBUFFER, GLES20.GL_DEPTH_ATTACHMENT,
      GLES20.GL_RENDERBUFFER, rboId[0]);

  GLES20.glActiveTexture(GLES20.GL_TEXTURE3);
  GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, texId[0]);
  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);
  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, width, height, 0, GLES20.GL_RGBA,
      GLES20.GL_UNSIGNED_BYTE, null);
  GLES20.glFramebufferTexture2D(GLES20.GL_FRAMEBUFFER, GLES20.GL_COLOR_ATTACHMENT0,
      GLES20.GL_TEXTURE_2D, texId[0], 0);

  int status = GLES20.glCheckFramebufferStatus(GLES20.GL_FRAMEBUFFER);
  if (status != GLES20.GL_FRAMEBUFFER_COMPLETE) {
    throw new RuntimeException("FrameBuffer uncompleted code: " + status);
  }
  GlUtil.checkGlError("initFBO_E");
}
 
Example 7
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 8
Source File: AndroidGL.java    From trekarta with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void framebufferRenderbuffer(int target, int attachment, int renderbuffertarget,
                                    int renderbuffer) {
    GLES20.glFramebufferRenderbuffer(target, attachment, renderbuffertarget, renderbuffer);
}
 
Example 9
Source File: GLSurface.java    From libcommon with Apache License 2.0 4 votes vote down vote up
/**
 * 指定したテクスチャをこのオフスクリーンに割り当てる
 * @param texture_name
 * @param width
 * @param height
 */
@Override
public void assignTexture(final int texture_name,
	final int width, final int height) {

	if ((width > mTexWidth) || (height > mTexHeight)) {
		mWidth = width;
		mHeight = height;
		releaseFrameBuffer();
		createFrameBuffer(width, height);
	}
	mFBOTexId = texture_name;
	GLES20.glActiveTexture(TEX_UNIT);
	 // フレームバッファオブジェクトをbindする
	GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, mFrameBufferObj);
	com.serenegiant.glutils.es2.GLHelper.checkGlError("glBindFramebuffer " + mFrameBufferObj);
	// フレームバッファにカラーバッファ(テクスチャ)を接続する
	GLES20.glFramebufferTexture2D(GLES20.GL_FRAMEBUFFER, GLES20.GL_COLOR_ATTACHMENT0,
		TEX_TARGET, mFBOTexId, 0);
	com.serenegiant.glutils.es2.GLHelper.checkGlError("glFramebufferTexture2D");

	if (mHasDepthBuffer) {
		// フレームバッファにデプスバッファを接続する
		GLES20.glFramebufferRenderbuffer(GLES20.GL_FRAMEBUFFER,
			GLES20.GL_DEPTH_ATTACHMENT, GLES20.GL_RENDERBUFFER, mDepthBufferObj);
		com.serenegiant.glutils.es2.GLHelper.checkGlError("glFramebufferRenderbuffer");
	}

	// 正常に終了したかどうかを確認する
	final int status = GLES20.glCheckFramebufferStatus(GLES20.GL_FRAMEBUFFER);
	if (status != GLES20.GL_FRAMEBUFFER_COMPLETE) {
		throw new RuntimeException("Framebuffer not complete, status=" + status);
	}

	 // デフォルトのフレームバッファに戻す
	GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, 0);

	// テクスチャ座標変換行列を初期化
	Matrix.setIdentityM(mTexMatrix, 0);
	mTexMatrix[0] = width / (float)mTexWidth;
	mTexMatrix[5] = height / (float)mTexHeight;
}
 
Example 10
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");
}
 
Example 11
Source File: FrameBuffer.java    From media-for-mobile with Apache License 2.0 4 votes vote down vote up
@Override
public void setResolution(Resolution res) {
    resolution = res;
    if (framebuffer != -1) {
        release();
    }
    int[] glValues = new int[1];

    GLES20.glGenTextures(1, glValues, 0);
    utils.checkEglError("glGenTextures");
    offScreenTexture = glValues[0];

    GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, offScreenTexture);
    utils.checkEglError("glBindTexture");

    GLES20.glTexImage2D(GLES20.GL_TEXTURE_2D, 0, GLES20.GL_RGBA, res.width(), res.height(), 0, GLES20.GL_RGBA, GLES20.GL_UNSIGNED_BYTE, null);
    utils.checkEglError("glTexImage2D");

    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);

    GLES20.glGenFramebuffers(1, glValues, 0);
    utils.checkEglError("glGenFramebuffers");

    framebuffer = glValues[0];

    GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, framebuffer);
    utils.checkEglError("glBindFramebuffer");

    GLES20.glGenRenderbuffers(1, glValues, 0);
    utils.checkEglError("glGenRenderbuffers");
    depthBuffer = glValues[0];

    GLES20.glBindRenderbuffer(GLES20.GL_RENDERBUFFER, depthBuffer);
    utils.checkEglError("glBindRenderbuffer");

    GLES20.glRenderbufferStorage(GLES20.GL_RENDERBUFFER, GLES20.GL_DEPTH_COMPONENT16, res.width(), res.height());
    utils.checkEglError("glRenderbufferStorage");

    GLES20.glFramebufferRenderbuffer(GLES20.GL_FRAMEBUFFER, GLES20.GL_DEPTH_ATTACHMENT, GLES20.GL_RENDERBUFFER, depthBuffer);
    utils.checkEglError("glFramebufferRenderbuffer");

    GLES20.glFramebufferTexture2D(GLES20.GL_FRAMEBUFFER, GLES20.GL_COLOR_ATTACHMENT0, GLES20.GL_TEXTURE_2D, offScreenTexture, 0);
    utils.checkEglError("glFramebufferTexture2D");

    int status = GLES20.glCheckFramebufferStatus(GLES20.GL_FRAMEBUFFER);
    utils.checkEglError("glCheckFramebufferStatus");



    if (status != GLES20.GL_FRAMEBUFFER_COMPLETE) {
        throw new RuntimeException("Incomplete framebuffer. Status: " + status);
    }

    GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, 0);
    utils.checkEglError("glBindFramebuffer(0)");
}
 
Example 12
Source File: GLES20FramebufferObject.java    From CameraRecorder-android with MIT License 4 votes vote down vote up
public void setup(final int width, final int height) {
    final int[] args = new int[1];

    GLES20.glGetIntegerv(GL_MAX_TEXTURE_SIZE, args, 0);
    if (width > args[0] || height > args[0]) {
        throw new IllegalArgumentException("GL_MAX_TEXTURE_SIZE " + args[0]);
    }

    GLES20.glGetIntegerv(GL_MAX_RENDERBUFFER_SIZE, args, 0);
    if (width > args[0] || height > args[0]) {
        throw new IllegalArgumentException("GL_MAX_RENDERBUFFER_SIZE " + args[0]);
    }

    GLES20.glGetIntegerv(GL_FRAMEBUFFER_BINDING, args, 0);
    final int saveFramebuffer = args[0];
    GLES20.glGetIntegerv(GL_RENDERBUFFER_BINDING, args, 0);
    final int saveRenderbuffer = args[0];
    GLES20.glGetIntegerv(GL_TEXTURE_BINDING_2D, args, 0);
    final int saveTexName = args[0];

    release();

    try {
        this.width = width;
        this.height = height;

        GLES20.glGenFramebuffers(args.length, args, 0);
        framebufferName = args[0];
        GLES20.glBindFramebuffer(GL_FRAMEBUFFER, framebufferName);

        GLES20.glGenRenderbuffers(args.length, args, 0);
        renderBufferName = args[0];
        GLES20.glBindRenderbuffer(GL_RENDERBUFFER, renderBufferName);
        GLES20.glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT16, width, height);
        GLES20.glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, renderBufferName);

        GLES20.glGenTextures(args.length, args, 0);
        texName = args[0];
        GLES20.glBindTexture(GL_TEXTURE_2D, texName);

        EglUtil.setupSampler(GL_TEXTURE_2D, GL_LINEAR, GL_NEAREST);

        GLES20.glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, null);
        GLES20.glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texName, 0);

        final int status = GLES20.glCheckFramebufferStatus(GL_FRAMEBUFFER);
        if (status != GL_FRAMEBUFFER_COMPLETE) {
            throw new RuntimeException("Failed to initialize framebuffer object " + status);
        }
    } catch (final RuntimeException e) {
        release();
        throw e;
    }

    GLES20.glBindFramebuffer(GL_FRAMEBUFFER, saveFramebuffer);
    GLES20.glBindRenderbuffer(GL_RENDERBUFFER, saveRenderbuffer);
    GLES20.glBindTexture(GL_TEXTURE_2D, saveTexName);
}
 
Example 13
Source File: MDDrawingCache.java    From Beginner-Level-Android-Studio-Apps with GNU General Public License v3.0 4 votes vote down vote up
private void createFrameBuffer(int width, int height){

        if (this.mTextureIdOutput != 0) {
            GLES20.glDeleteTextures(1, new int[] { this.mTextureIdOutput}, 0);
        }
        if (this.mRenderBufferId != 0) {
            GLES20.glDeleteRenderbuffers(1, new int[] { this.mRenderBufferId }, 0);
        }
        if (this.mFrameBufferId != 0) {
            GLES20.glDeleteFramebuffers(1, new int[] { this.mFrameBufferId }, 0);
        }

        GLES20.glGetIntegerv(GLES20.GL_FRAMEBUFFER_BINDING, originalFramebufferId, 0);

        // frame buffer
        int[] frameBuffer = new int[1];
        GLES20.glGenFramebuffers(1, frameBuffer, 0);
        GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, frameBuffer[0]);
        mFrameBufferId = frameBuffer[0];
        glCheck("Multi Fish Eye frame buffer");

        // renderer buffer
        final int[] renderbufferIds = { 0 };
        GLES20.glGenRenderbuffers(1, renderbufferIds, 0);
        GLES20.glBindRenderbuffer(GLES20.GL_RENDERBUFFER, renderbufferIds[0]);
        GLES20.glRenderbufferStorage(GLES20.GL_RENDERBUFFER, GLES20.GL_DEPTH_COMPONENT16, width, height);
        mRenderBufferId = renderbufferIds[0];
        glCheck("Multi Fish Eye renderer buffer");

        final int[] textureIds = { 0 };
        GLES20.glGenTextures(1, textureIds, 0);
        GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
        GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, textureIds[0]);
        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_MAG_FILTER, GLES20.GL_LINEAR);
        GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_LINEAR);
        GLES20.glTexImage2D(GLES20.GL_TEXTURE_2D, 0, GLES20.GL_RGBA, width, height, 0, GLES20.GL_RGBA, GLES20.GL_UNSIGNED_BYTE, (Buffer)null);
        mTextureIdOutput = textureIds[0];
        glCheck("Multi Fish Eye texture");

        // attach
        GLES20.glFramebufferTexture2D(GLES20.GL_FRAMEBUFFER, GLES20.GL_COLOR_ATTACHMENT0, GLES20.GL_TEXTURE_2D, mTextureIdOutput, 0);
        GLES20.glFramebufferRenderbuffer(GLES20.GL_FRAMEBUFFER, GLES20.GL_DEPTH_ATTACHMENT, GLES20.GL_RENDERBUFFER, renderbufferIds[0]);
        glCheck("Multi Fish Eye attach");

        // check
        final int status = GLES20.glCheckFramebufferStatus(GLES20.GL_FRAMEBUFFER);
        if (status != GLES20.GL_FRAMEBUFFER_COMPLETE) {
            final String s = "Framebuffer is not complete: ";
            final String value = String.valueOf(Integer.toHexString(status));
            throw new RuntimeException((value.length() != 0) ? s.concat(value) : s);
        }

        GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, originalFramebufferId[0]);
        glCheck("Multi Fish Eye attach");
    }
 
Example 14
Source File: Framebuffer.java    From remixed-dungeon with GNU General Public License v3.0 4 votes vote down vote up
public void attach( int point, Renderbuffer buffer ) {
	bind();
	GLES20.glFramebufferRenderbuffer( GLES20.GL_RENDERBUFFER, point, GLES20.GL_TEXTURE_2D, buffer.id() );
}
 
Example 15
Source File: EFramebufferObject.java    From SimpleVideoEdit with Apache License 2.0 4 votes vote down vote up
public void setup(final int width, final int height) {
    final int[] args = new int[1];
    // glGetIntegervは端末の固有の情報を取り出している。
    // ただgetしてcpu上に乗せているだけ。

    // ここでは最大のtextureのサイズ
    GLES20.glGetIntegerv(GL_MAX_TEXTURE_SIZE, args, 0);
    if (width > args[0] || height > args[0]) {
        throw new IllegalArgumentException("GL_MAX_TEXTURE_SIZE " + args[0]);
    }

    GLES20.glGetIntegerv(GL_MAX_RENDERBUFFER_SIZE, args, 0);
    if (width > args[0] || height > args[0]) {
        throw new IllegalArgumentException("GL_MAX_RENDERBUFFER_SIZE " + args[0]);
    }

    GLES20.glGetIntegerv(GL_FRAMEBUFFER_BINDING, args, 0);
    final int saveFramebuffer = args[0];
    GLES20.glGetIntegerv(GL_RENDERBUFFER_BINDING, args, 0);
    final int saveRenderbuffer = args[0];
    GLES20.glGetIntegerv(GL_TEXTURE_BINDING_2D, args, 0);
    final int saveTexName = args[0];

    release();

    try {
        this.width = width;
        this.height = height;

        GLES20.glGenFramebuffers(args.length, args, 0);
        framebufferName = args[0];
        GLES20.glBindFramebuffer(GL_FRAMEBUFFER, framebufferName);

        GLES20.glGenRenderbuffers(args.length, args, 0);
        renderbufferName = args[0];
        GLES20.glBindRenderbuffer(GL_RENDERBUFFER, renderbufferName);
        GLES20.glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT16, width, height);
        GLES20.glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, renderbufferName);

        GLES20.glGenTextures(args.length, args, 0);
        texName = args[0];
        GLES20.glBindTexture(GL_TEXTURE_2D, texName);

        EglUtil.setupSampler(GL_TEXTURE_2D, GL_LINEAR, GL_NEAREST);

        GLES20.glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, null);
        GLES20.glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texName, 0);

        final int status = GLES20.glCheckFramebufferStatus(GL_FRAMEBUFFER);
        if (status != GL_FRAMEBUFFER_COMPLETE) {
            throw new RuntimeException("Failed to initialize framebuffer object " + status);
        }
    } catch (final RuntimeException e) {
        release();
        throw e;
    }

    GLES20.glBindFramebuffer(GL_FRAMEBUFFER, saveFramebuffer);
    GLES20.glBindRenderbuffer(GL_RENDERBUFFER, saveRenderbuffer);
    GLES20.glBindTexture(GL_TEXTURE_2D, saveTexName);
}
 
Example 16
Source File: GlFramebufferObject.java    From Mp4Composer-android with MIT License 4 votes vote down vote up
public void setup(final int width, final int height) {
    final int[] args = new int[1];

    GLES20.glGetIntegerv(GL_MAX_TEXTURE_SIZE, args, 0);
    if (width > args[0] || height > args[0]) {
        throw new IllegalArgumentException("GL_MAX_TEXTURE_SIZE " + args[0]);
    }

    GLES20.glGetIntegerv(GL_MAX_RENDERBUFFER_SIZE, args, 0);
    if (width > args[0] || height > args[0]) {
        throw new IllegalArgumentException("GL_MAX_RENDERBUFFER_SIZE " + args[0]);
    }

    GLES20.glGetIntegerv(GL_FRAMEBUFFER_BINDING, args, 0);
    final int saveFramebuffer = args[0];
    GLES20.glGetIntegerv(GL_RENDERBUFFER_BINDING, args, 0);
    final int saveRenderbuffer = args[0];
    GLES20.glGetIntegerv(GL_TEXTURE_BINDING_2D, args, 0);
    final int saveTexName = args[0];

    release();

    try {
        this.width = width;
        this.height = height;

        GLES20.glGenFramebuffers(args.length, args, 0);
        framebufferName = args[0];
        GLES20.glBindFramebuffer(GL_FRAMEBUFFER, framebufferName);

        GLES20.glGenRenderbuffers(args.length, args, 0);
        renderBufferName = args[0];
        GLES20.glBindRenderbuffer(GL_RENDERBUFFER, renderBufferName);
        GLES20.glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT16, width, height);
        GLES20.glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, renderBufferName);

        GLES20.glGenTextures(args.length, args, 0);
        texName = args[0];
        GLES20.glBindTexture(GL_TEXTURE_2D, texName);

        EglUtil.setupSampler(GL_TEXTURE_2D, GL_LINEAR, GL_NEAREST);

        GLES20.glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, null);
        GLES20.glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texName, 0);

        final int status = GLES20.glCheckFramebufferStatus(GL_FRAMEBUFFER);
        if (status != GL_FRAMEBUFFER_COMPLETE) {
            throw new RuntimeException("Failed to initialize framebuffer object " + status);
        }
    } catch (final RuntimeException e) {
        release();
        throw e;
    }

    GLES20.glBindFramebuffer(GL_FRAMEBUFFER, saveFramebuffer);
    GLES20.glBindRenderbuffer(GL_RENDERBUFFER, saveRenderbuffer);
    GLES20.glBindTexture(GL_TEXTURE_2D, saveTexName);
}
 
Example 17
Source File: BitmapOutput.java    From UltimateAndroid with Apache License 2.0 votes vote down vote up
private void initFBO() {
		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;
		}
		frameBuffer = new int[1];
		texture_out = new int[1];
		depthRenderBuffer = new int[1];
		GLES20.glGenFramebuffers(1, frameBuffer, 0);
		GLES20.glGenRenderbuffers(1, depthRenderBuffer, 0);
		GLES20.glGenTextures(1, texture_out, 0);
		
		GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, frameBuffer[0]);
		
		GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
		GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, texture_out[0]);
		GLES20.glTexImage2D(GLES20.GL_TEXTURE_2D, 0, GLES20.GL_RGBA, getWidth(), getHeight(), 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_MAG_FILTER, GLES20.GL_LINEAR);
		GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_LINEAR);
		GLES20.glFramebufferTexture2D(GLES20.GL_FRAMEBUFFER, GLES20.GL_COLOR_ATTACHMENT0, GLES20.GL_TEXTURE_2D, texture_out[0], 0);
		
		GLES20.glBindRenderbuffer(GLES20.GL_RENDERBUFFER, depthRenderBuffer[0]);
		GLES20.glRenderbufferStorage(GLES20.GL_RENDERBUFFER, GLES20.GL_DEPTH_COMPONENT16, getWidth(), getHeight());
		GLES20.glFramebufferRenderbuffer(GLES20.GL_FRAMEBUFFER, GLES20.GL_DEPTH_ATTACHMENT, GLES20.GL_RENDERBUFFER, depthRenderBuffer[0]);
		
		int status = GLES20.glCheckFramebufferStatus(GLES20.GL_FRAMEBUFFER);
		if (status != GLES20.GL_FRAMEBUFFER_COMPLETE) {
			throw new RuntimeException(this+": Failed to set up render buffer with status "+status+" and error "+GLES20.glGetError());
		}
	} 
Example 18
Source File: BitmapOutput.java    From AndroidFastImageProcessing with MIT License votes vote down vote up
private void initFBO() {
		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;
		}
		frameBuffer = new int[1];
		texture_out = new int[1];
		depthRenderBuffer = new int[1];
		GLES20.glGenFramebuffers(1, frameBuffer, 0);
		GLES20.glGenRenderbuffers(1, depthRenderBuffer, 0);
		GLES20.glGenTextures(1, texture_out, 0);
		
		GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, frameBuffer[0]);
		
		GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
		GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, texture_out[0]);
		GLES20.glTexImage2D(GLES20.GL_TEXTURE_2D, 0, GLES20.GL_RGBA, getWidth(), getHeight(), 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_MAG_FILTER, GLES20.GL_LINEAR);
		GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_LINEAR);
		GLES20.glFramebufferTexture2D(GLES20.GL_FRAMEBUFFER, GLES20.GL_COLOR_ATTACHMENT0, GLES20.GL_TEXTURE_2D, texture_out[0], 0);
		
		GLES20.glBindRenderbuffer(GLES20.GL_RENDERBUFFER, depthRenderBuffer[0]);
		GLES20.glRenderbufferStorage(GLES20.GL_RENDERBUFFER, GLES20.GL_DEPTH_COMPONENT16, getWidth(), getHeight());
		GLES20.glFramebufferRenderbuffer(GLES20.GL_FRAMEBUFFER, GLES20.GL_DEPTH_ATTACHMENT, GLES20.GL_RENDERBUFFER, depthRenderBuffer[0]);
		
		int status = GLES20.glCheckFramebufferStatus(GLES20.GL_FRAMEBUFFER);
		if (status != GLES20.GL_FRAMEBUFFER_COMPLETE) {
			throw new RuntimeException(this+": Failed to set up render buffer with status "+status+" and error "+GLES20.glGetError());
		}
	} 
Example 19
Source File: BitmapOutput.java    From UltimateAndroid with Apache License 2.0 votes vote down vote up
private void initFBO() {
		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;
		}
		frameBuffer = new int[1];
		texture_out = new int[1];
		depthRenderBuffer = new int[1];
		GLES20.glGenFramebuffers(1, frameBuffer, 0);
		GLES20.glGenRenderbuffers(1, depthRenderBuffer, 0);
		GLES20.glGenTextures(1, texture_out, 0);
		
		GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, frameBuffer[0]);
		
		GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
		GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, texture_out[0]);
		GLES20.glTexImage2D(GLES20.GL_TEXTURE_2D, 0, GLES20.GL_RGBA, getWidth(), getHeight(), 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_MAG_FILTER, GLES20.GL_LINEAR);
		GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_LINEAR);
		GLES20.glFramebufferTexture2D(GLES20.GL_FRAMEBUFFER, GLES20.GL_COLOR_ATTACHMENT0, GLES20.GL_TEXTURE_2D, texture_out[0], 0);
		
		GLES20.glBindRenderbuffer(GLES20.GL_RENDERBUFFER, depthRenderBuffer[0]);
		GLES20.glRenderbufferStorage(GLES20.GL_RENDERBUFFER, GLES20.GL_DEPTH_COMPONENT16, getWidth(), getHeight());
		GLES20.glFramebufferRenderbuffer(GLES20.GL_FRAMEBUFFER, GLES20.GL_DEPTH_ATTACHMENT, GLES20.GL_RENDERBUFFER, depthRenderBuffer[0]);
		
		int status = GLES20.glCheckFramebufferStatus(GLES20.GL_FRAMEBUFFER);
		if (status != GLES20.GL_FRAMEBUFFER_COMPLETE) {
			throw new RuntimeException(this+": Failed to set up render buffer with status "+status+" and error "+GLES20.glGetError());
		}
	} 
Example 20
Source File: TwoPassFilter.java    From UltimateAndroid with Apache License 2.0 votes vote down vote up
private void initFBO() {
		if(firstPassFrameBuffer != null) {
			GLES20.glDeleteFramebuffers(1, firstPassFrameBuffer, 0);
			firstPassFrameBuffer = null;
		}
		if(firstPassTextureOut != null) {
			GLES20.glDeleteTextures(1, firstPassTextureOut, 0);
			firstPassTextureOut = null;
		}
		if(firstPassDepthRenderBuffer != null) {
			GLES20.glDeleteRenderbuffers(1, firstPassDepthRenderBuffer, 0);
			firstPassDepthRenderBuffer = null;
		}
		firstPassFrameBuffer = new int[1];
		firstPassTextureOut = new int[1];
		firstPassDepthRenderBuffer = new int[1];
		GLES20.glGenFramebuffers(1, firstPassFrameBuffer, 0);
		GLES20.glGenRenderbuffers(1, firstPassDepthRenderBuffer, 0);
		GLES20.glGenTextures(1, firstPassTextureOut, 0);
		
		GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, firstPassFrameBuffer[0]);
		
		GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
		GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, firstPassTextureOut[0]);
		GLES20.glTexImage2D(GLES20.GL_TEXTURE_2D, 0, GLES20.GL_RGB, getWidth(), getHeight(), 0, GLES20.GL_RGB, GLES20.GL_UNSIGNED_SHORT_5_6_5, 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_MAG_FILTER, GLES20.GL_LINEAR);
		GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_LINEAR);
		GLES20.glFramebufferTexture2D(GLES20.GL_FRAMEBUFFER, GLES20.GL_COLOR_ATTACHMENT0, GLES20.GL_TEXTURE_2D, firstPassTextureOut[0], 0);
		
		GLES20.glBindRenderbuffer(GLES20.GL_RENDERBUFFER, firstPassDepthRenderBuffer[0]);
		GLES20.glRenderbufferStorage(GLES20.GL_RENDERBUFFER, GLES20.GL_DEPTH_COMPONENT16, getWidth(), getHeight());
		GLES20.glFramebufferRenderbuffer(GLES20.GL_FRAMEBUFFER, GLES20.GL_DEPTH_ATTACHMENT, GLES20.GL_RENDERBUFFER, firstPassDepthRenderBuffer[0]);
		
		int status = GLES20.glCheckFramebufferStatus(GLES20.GL_FRAMEBUFFER);
		if (status != GLES20.GL_FRAMEBUFFER_COMPLETE) {
			throw new RuntimeException(this+": Failed to set up render buffer with status "+status+" and error "+GLES20.glGetError());
		}
	}