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

The following examples show how to use android.opengl.GLES20#glBindRenderbuffer() . 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: 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 3
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 4
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 5
Source File: AndroidGL.java    From trekarta with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void bindRenderbuffer(int target, int renderbuffer) {
    GLES20.glBindRenderbuffer(target, renderbuffer);
}
 
Example 6
Source File: Renderbuffer.java    From YetAnotherPixelDungeon with GNU General Public License v3.0 4 votes vote down vote up
public void bind() {
	GLES20.glBindRenderbuffer( GLES20.GL_RENDERBUFFER, id );
}
 
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: Renderbuffer.java    From PD-classes with GNU General Public License v3.0 4 votes vote down vote up
public void bind() {
	GLES20.glBindRenderbuffer( GLES20.GL_RENDERBUFFER, id );
}
 
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: 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 11
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 12
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 13
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 14
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 15
Source File: RecordFBOActivity.java    From grafika with Apache License 2.0 4 votes vote down vote up
/**
 * Prepares the off-screen framebuffer.
 */
private void prepareFramebuffer(int width, int height) {
    GlUtil.checkGlError("prepareFramebuffer start");

    int[] values = new int[1];

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

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

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

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

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

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

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

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

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

    GlUtil.checkGlError("prepareFramebuffer done");
}
 
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: TwoPassFilter.java    From AndroidFastImageProcessing with MIT License 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());
		}
	} 
Example 18
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());
		}
	} 
Example 19
Source File: GLTextureOutputRenderer.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: 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());
		}
	}