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

The following examples show how to use android.opengl.GLES20#glRenderbufferStorage() . 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: RenderBuffer.java    From MusicVisualization with Apache License 2.0 5 votes vote down vote up
public RenderBuffer(int width, int height, int activeTexUnit) {
    this.width = width;
    this.height = height;
    this.activeTexUnit = activeTexUnit;
    int[] genbuf = new int[1];

    // Generate and bind 2d texture
    GLES20.glActiveTexture(activeTexUnit);
    texId = MyGLUtils.genTexture();
    IntBuffer texBuffer =
            ByteBuffer.allocateDirect(width * height * 4).order(ByteOrder.nativeOrder()).asIntBuffer();
    GLES20.glTexImage2D(GLES20.GL_TEXTURE_2D, 0, GLES20.GL_RGBA, width, height, 0, GLES20.GL_RGBA, GLES20.GL_UNSIGNED_BYTE, texBuffer);

    GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER, GL10.GL_LINEAR);
    GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, GL10.GL_TEXTURE_MAG_FILTER, GL10.GL_LINEAR);
    GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_S, GL10.GL_CLAMP_TO_EDGE);
    GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_T, GL10.GL_CLAMP_TO_EDGE);

    // Generate frame buffer
    GLES20.glGenFramebuffers(1, genbuf, 0);
    frameBufferId = genbuf[0];
    // Bind frame buffer
    GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, frameBufferId);

    // Generate render buffer
    GLES20.glGenRenderbuffers(1, genbuf, 0);
    renderBufferId = genbuf[0];
    // Bind render buffer
    GLES20.glBindRenderbuffer(GLES20.GL_RENDERBUFFER, renderBufferId);
    GLES20.glRenderbufferStorage(GLES20.GL_RENDERBUFFER, GLES20.GL_DEPTH_COMPONENT16, width, height);

    unbind();
}
 
Example 2
Source File: GLSurface.java    From libcommon with Apache License 2.0 5 votes vote down vote up
/**
 * オフスクリーン描画用のフレームバッファオブジェクトを生成する
 * @param width
 * @param height
 */
@Override
protected void createFrameBuffer(final int width, final int height) {
	final int[] ids = new int[1];

	if (mAdjustPower2) {
		// テクスチャのサイズは2の乗数にする
		int w = 1;
		for (; w < width; w <<= 1) ;
		int h = 1;
		for (; h < height; h <<= 1) ;
		if (mTexWidth != w || mTexHeight != h) {
			mTexWidth = w;
			mTexHeight = h;
		}
	} else {
		mTexWidth = width;
		mTexHeight = height;
	}

	if (mHasDepthBuffer) {
		// デプスバッファが必要な場合は、レンダーバッファオブジェクトを生成・初期化する
		GLES20.glGenRenderbuffers(1, ids, 0);
		mDepthBufferObj = ids[0];
		GLES20.glBindRenderbuffer(GLES20.GL_RENDERBUFFER, mDepthBufferObj);
		// デプスバッファは16ビット
		GLES20.glRenderbufferStorage(GLES20.GL_RENDERBUFFER,
			GLES20.GL_DEPTH_COMPONENT16, mTexWidth, mTexHeight);
	}
	// フレームバッファオブジェクトを生成してbindする
	GLES20.glGenFramebuffers(1, ids, 0);
	com.serenegiant.glutils.es2.GLHelper.checkGlError("glGenFramebuffers");
	mFrameBufferObj = ids[0];
	GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, mFrameBufferObj);
	com.serenegiant.glutils.es2.GLHelper.checkGlError("glBindFramebuffer " + mFrameBufferObj);

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

}
 
Example 3
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 4
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 5
Source File: DistortionRenderer.java    From Cardboard with Apache License 2.0 4 votes vote down vote up
private int setupRenderTextureAndRenderbuffer(int width, int height) {
	if (this.mTextureId != -1) {
		GLES20.glDeleteTextures(1, new int[] { this.mTextureId }, 0);
	}
	if (this.mRenderbufferId != -1) {
		GLES20.glDeleteRenderbuffers(1, new int[] { this.mRenderbufferId },
				0);
	}
	if (this.mFramebufferId != -1) {
		GLES20.glDeleteFramebuffers(1, new int[] { this.mFramebufferId }, 0);
	}
	this.mTextureId = createTexture(width, height);
	checkGlError("setupRenderTextureAndRenderbuffer: create texture");

	int[] renderbufferIds = new int[1];
	GLES20.glGenRenderbuffers(1, renderbufferIds, 0);
	GLES20.glBindRenderbuffer(36161, renderbufferIds[0]);
	GLES20.glRenderbufferStorage(36161, 33189, width, height);

	this.mRenderbufferId = renderbufferIds[0];
	checkGlError("setupRenderTextureAndRenderbuffer: create renderbuffer");

	int[] framebufferIds = new int[1];
	GLES20.glGenFramebuffers(1, framebufferIds, 0);
	GLES20.glBindFramebuffer(36160, framebufferIds[0]);
	this.mFramebufferId = framebufferIds[0];

	GLES20.glFramebufferTexture2D(36160, 36064, 3553, this.mTextureId, 0);

	GLES20.glFramebufferRenderbuffer(36160, 36096, 36161,
			renderbufferIds[0]);

	int status = GLES20.glCheckFramebufferStatus(36160);
	if (status != 36053) {
		throw new RuntimeException("Framebuffer is not complete: "
				+ Integer.toHexString(status));
	}
	GLES20.glBindFramebuffer(36160, 0);

	return framebufferIds[0];
}
 
Example 6
Source File: Renderbuffer.java    From YetAnotherPixelDungeon with GNU General Public License v3.0 4 votes vote down vote up
public void storage( int format, int width, int height ) {
	GLES20.glRenderbufferStorage( GLES20.GL_RENDERBUFFER, format , width, height );
}
 
Example 7
Source File: MDDrawingCache.java    From MD360Player4Android with Apache License 2.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 8
Source File: MyRenderer.java    From Viewer with Apache License 2.0 4 votes vote down vote up
@Override
public void onSurfaceCreated(GL10 gl, EGLConfig config)
{
	frameBuffer = IntBuffer.allocate(1);
	renderBuffer = IntBuffer.allocate(1);

	GLES20.glEnable(GLES20.GL_TEXTURE_2D);

	GLES20.glGenFramebuffers(1, frameBuffer);
	GLES20.glGenRenderbuffers(1, renderBuffer);
	GLES20.glActiveTexture(GLES20.GL_ACTIVE_TEXTURE);
	GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, frameBuffer.get(0));
	GLES20.glClear(0);
	GLES20.glBindRenderbuffer(GLES20.GL_RENDERBUFFER, renderBuffer.get(0));

	GLES20.glRenderbufferStorage(GLES20.GL_RENDERBUFFER, GLES20.GL_DEPTH_COMPONENT16, 1280, 720);

	parameterBufferHeigth = IntBuffer.allocate(1);
	parameterBufferWidth = IntBuffer.allocate(1);
	GLES20.glGetRenderbufferParameteriv(GLES20.GL_RENDERBUFFER, GLES20.GL_RENDERBUFFER_WIDTH, parameterBufferWidth);
	GLES20.glGetRenderbufferParameteriv(GLES20.GL_RENDERBUFFER, GLES20.GL_RENDERBUFFER_HEIGHT, parameterBufferHeigth);
	GLES20.glFramebufferRenderbuffer(GLES20.GL_FRAMEBUFFER, GLES20.GL_COLOR_ATTACHMENT0, GLES20.GL_RENDERBUFFER, renderBuffer.get(0));
	if (GLES20.glCheckFramebufferStatus(GLES20.GL_FRAMEBUFFER) != GLES20.GL_FRAMEBUFFER_COMPLETE)
	{
		System.out.println("gl frame buffer status != frame buffer complete");
	}
	GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, 0);
	GLES20.glClear(0);

	mProgramObject = loadProgram(VERTEX_SHADER, FRAG_SHADER);

	mPositionLoc = GLES20.glGetAttribLocation(mProgramObject, "vPosition");
	mTexCoordLoc = GLES20.glGetAttribLocation(mProgramObject, "a_texCoord");

	GLES20.glEnable(GLES20.GL_TEXTURE_2D);
	yTexture = GLES20.glGetUniformLocation(mProgramObject, "SamplerY");
	yTextureNames = new int[1];
	GLES20.glGenTextures(1, yTextureNames, 0);

	GLES20.glEnable(GLES20.GL_TEXTURE_2D);
	uTexture = GLES20.glGetUniformLocation(mProgramObject, "SamplerU");
	uTextureNames = new int[1];
	GLES20.glGenTextures(1, uTextureNames, 0);

	GLES20.glEnable(GLES20.GL_TEXTURE_2D);
	vTexture = GLES20.glGetUniformLocation(mProgramObject, "SamplerV");
	vTextureNames = new int[1];
	GLES20.glGenTextures(1, vTextureNames, 0);

	GLES20.glClearColor(0.957f, 0.937f, 0.921f, 0.0f);
}
 
Example 9
Source File: FrameBufferSource.java    From Tanks with MIT License 4 votes vote down vote up
private FrameBuffer build()
{
  ResultRunnable<FrameBuffer> runnable = new ResultRunnable<FrameBuffer>()
  {
    @Override
    protected FrameBuffer onRun()
    {
      int width = (int) Renderer.getWidth();
      int height = (int) Renderer.getHeight();

      int[] renderTextureIds = new int[1];
      GLES20.glGenTextures(1, renderTextureIds, 0);
      GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, renderTextureIds[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);

      int[] frameBufferIds = new int[1];
      GLES20.glGenFramebuffers(1, frameBufferIds, 0);
      GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, frameBufferIds[0]);
      GLES20.glFramebufferTexture2D(GLES20.GL_FRAMEBUFFER, GLES20.GL_COLOR_ATTACHMENT0, GLES20.GL_TEXTURE_2D, renderTextureIds[0], 0);

      int[] depthTextureIds = new int[1];
      GLES20.glGenRenderbuffers(1, depthTextureIds, 0);
      GLES20.glBindRenderbuffer(GLES20.GL_RENDERBUFFER, depthTextureIds[0]);
      GLES20.glRenderbufferStorage(GLES20.GL_RENDERBUFFER, GLES20.GL_DEPTH_COMPONENT16, width, height);
      GLES20.glFramebufferRenderbuffer(GLES20.GL_FRAMEBUFFER, GLES20.GL_DEPTH_ATTACHMENT, GLES20.GL_RENDERBUFFER, depthTextureIds[0]);

      // check FBO status
      int status = GLES20.glCheckFramebufferStatus(GLES20.GL_FRAMEBUFFER);
      if (status != GLES20.GL_FRAMEBUFFER_COMPLETE)
        throw new GLException(status, "GL_FRAMEBUFFER_COMPLETE failed, CANNOT use FBO");

      return new FrameBuffer(name, frameBufferIds[0], depthTextureIds[0], renderTextureIds[0]);
    }
  };

  GameContext.glThread.sendEvent(runnable);
  return runnable.getResult();
}
 
Example 10
Source File: GlFramebufferObject.java    From GPUVideo-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 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: FURenderer.java    From PLDroidShortVideo with Apache License 2.0 4 votes vote down vote up
private void createFBO(int width, int height) {
        if (fboTex != null && (fboWidth != width || fboHeight != height)) {
            deleteFBO();
        }

        fboWidth = width;
        fboHeight = height;

        if (fboTex == null) {
            fboId = new int[4];
            fboTex = new int[4];
            renderBufferId = new int[4];

//generate fbo id
            GLES20.glGenFramebuffers(4, fboId, 0);
//generate texture
            GLES20.glGenTextures(4, fboTex, 0);
//generate render buffer
            GLES20.glGenRenderbuffers(4, renderBufferId, 0);

            for (int i = 0; i < fboId.length; i++) {
//Bind Frame buffer
                GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, fboId[i]);
//Bind texture
                GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, fboTex[i]);
//Define texture parameters
                GLES20.glTexImage2D(GLES20.GL_TEXTURE_2D, 0, GLES20.GL_RGBA, width, height, 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);
//Bind render buffer and define buffer dimension
                GLES20.glBindRenderbuffer(GLES20.GL_RENDERBUFFER, renderBufferId[i]);
                GLES20.glRenderbufferStorage(GLES20.GL_RENDERBUFFER, GLES20.GL_DEPTH_COMPONENT16, width, height);
//Attach texture FBO color attachment
                GLES20.glFramebufferTexture2D(GLES20.GL_FRAMEBUFFER, GLES20.GL_COLOR_ATTACHMENT0, GLES20.GL_TEXTURE_2D, fboTex[i], 0);
//Attach render buffer to depth attachment
                GLES20.glFramebufferRenderbuffer(GLES20.GL_FRAMEBUFFER, GLES20.GL_DEPTH_ATTACHMENT, GLES20.GL_RENDERBUFFER, renderBufferId[i]);
//we are done, reset
                GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, 0);
                GLES20.glBindRenderbuffer(GLES20.GL_RENDERBUFFER, 0);
                GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, 0);
            }
        }
    }
 
Example 13
Source File: OGLESShaderRenderer.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 4 votes vote down vote up
private void updateRenderBuffer(FrameBuffer fb, RenderBuffer rb) {
        int id = rb.getId();
        if (id == -1) {
            GLES20.glGenRenderbuffers(1, intBuf1);
//            RendererUtil.checkGLError();

            id = intBuf1.get(0);
            rb.setId(id);
        }

        if (context.boundRB != id) {
            GLES20.glBindRenderbuffer(GLES20.GL_RENDERBUFFER, id);
//            RendererUtil.checkGLError();

            context.boundRB = id;
        }

        if (fb.getWidth() > maxRBSize || fb.getHeight() > maxRBSize) {
            throw new RendererException("Resolution " + fb.getWidth()
                    + ":" + fb.getHeight() + " is not supported.");
        }

        TextureUtil.AndroidGLImageFormat imageFormat = TextureUtil.getImageFormat(rb.getFormat());
        if (imageFormat.renderBufferStorageFormat == 0) {
            throw new RendererException("The format '" + rb.getFormat() + "' cannot be used for renderbuffers.");
        }

//        if (fb.getSamples() > 1 && GLContext.getCapabilities().GL_EXT_framebuffer_multisample) {
        if (fb.getSamples() > 1) {
//            // FIXME
            throw new RendererException("Multisample FrameBuffer is not supported yet.");
//            int samples = fb.getSamples();
//            if (maxFBOSamples < samples) {
//                samples = maxFBOSamples;
//            }
//            glRenderbufferStorageMultisampleEXT(GL_RENDERBUFFER_EXT,
//                    samples,
//                    glFmt.internalFormat,
//                    fb.getWidth(),
//                    fb.getHeight());
        } else {
            GLES20.glRenderbufferStorage(GLES20.GL_RENDERBUFFER,
                    imageFormat.renderBufferStorageFormat,
                    fb.getWidth(),
                    fb.getHeight());

//            RendererUtil.checkGLError();
        }
    }
 
Example 14
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 15
Source File: Renderbuffer.java    From PD-classes with GNU General Public License v3.0 4 votes vote down vote up
public void storage( int format, int width, int height ) {
	GLES20.glRenderbufferStorage( GLES20.GL_RENDERBUFFER, format , width, height );
}
 
Example 16
Source File: FboTexture.java    From PhotoMovie with Apache License 2.0 4 votes vote down vote up
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");
    int offscreenTexture = values[0];   // expected > 0
    GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, offscreenTexture);
    GlUtil.checkGlError("glBindTexture " + offscreenTexture);

    // 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");
    int framebuffer = values[0];    // expected > 0
    GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, framebuffer);
    GlUtil.checkGlError("glBindFramebuffer " + framebuffer);

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

    // 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, mRenderBuffer);
    GlUtil.checkGlError("glFramebufferRenderbuffer");
    GLES20.glFramebufferTexture2D(GLES20.GL_FRAMEBUFFER, GLES20.GL_COLOR_ATTACHMENT0,
            GLES20.GL_TEXTURE_2D, offscreenTexture, 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");
    mFrameBuffer = framebuffer;
    mId = offscreenTexture;
}
 
Example 17
Source File: Renderbuffer.java    From remixed-dungeon with GNU General Public License v3.0 4 votes vote down vote up
public void storage( int format, int width, int height ) {
	GLES20.glRenderbufferStorage( GLES20.GL_RENDERBUFFER, format , width, height );
}
 
Example 18
Source File: GLTextureOutputRenderer.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 19
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 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());
		}
	}