public boolean attachTexture(DrawContext dc, Texture texture, int attachment) { if (this.framebufferName == UNINITIALIZED_NAME) { this.createFramebuffer(dc); } if (this.framebufferName[0] != 0) { this.framebufferTexture(dc, texture, attachment); this.attachedTextures.put(attachment, texture); } return this.framebufferName[0] != 0; }
@Override public void release(DrawContext dc) { if (this.framebufferName[0] != 0) { this.deleteFramebuffer(dc); this.attachedTextures.clear(); } }
public boolean isFramebufferComplete(DrawContext dc) { // Get the OpenGL framebuffer object status code. int e = this.framebufferStatus(dc); return e == GLES20.GL_FRAMEBUFFER_COMPLETE; }
protected boolean drawSceneDepth(DrawContext dc) { try { Framebuffer framebuffer = dc.scratchFramebuffer(); if (!framebuffer.bindFramebuffer(dc)) { return false; // framebuffer failed to bind Texture depthTexture = framebuffer.getAttachedTexture(GLES20.GL_DEPTH_ATTACHMENT); GLES20.glViewport(0, 0, depthTexture.getWidth(), depthTexture.getHeight()); GLES20.glClear(GLES20.GL_DEPTH_BUFFER_BIT);
/** * Returns an OpenGL framebuffer object suitable for offscreen drawing. The framebuffer has a 32-bit color buffer * and a 32-bit depth buffer, both attached as OpenGL texture 2D objects. * <p> * The framebuffer may be used by any drawable and for any purpose. However, the draw context makes no guarantees * about the framebuffer's contents. Drawables must clear the framebuffer before use, and must assume its contents * may be modified by another drawable, either during the current frame or in a subsequent frame. * <p> * The OpenGL framebuffer object is created on first use and cached. Subsequent calls to this method return the * cached buffer object. * * @return the draw context's scratch OpenGL framebuffer object */ public Framebuffer scratchFramebuffer() { if (this.scratchFramebuffer != null) { return this.scratchFramebuffer; } Framebuffer framebuffer = new Framebuffer(); Texture colorAttachment = new Texture(1024, 1024, GLES20.GL_RGBA, GLES20.GL_UNSIGNED_BYTE); Texture depthAttachment = new Texture(1024, 1024, GLES20.GL_DEPTH_COMPONENT, GLES20.GL_UNSIGNED_SHORT); // TODO consider modifying Texture's tex parameter behavior in order to make this unnecessary depthAttachment.setTexParameter(GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_NEAREST); depthAttachment.setTexParameter(GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_NEAREST); framebuffer.attachTexture(this, colorAttachment, GLES20.GL_COLOR_ATTACHMENT0); framebuffer.attachTexture(this, depthAttachment, GLES20.GL_DEPTH_ATTACHMENT); return (this.scratchFramebuffer = framebuffer); }
Texture colorAttachment = dc.scratchFramebuffer().getAttachedTexture(GLES20.GL_COLOR_ATTACHMENT0); if (!colorAttachment.bindTexture(dc)) { return; // framebuffer texture failed to bind
public boolean bindFramebuffer(DrawContext dc) { if (this.framebufferName == UNINITIALIZED_NAME) { this.createFramebuffer(dc); } if (this.framebufferName[0] != 0) { dc.bindFramebuffer(this.framebufferName[0]); } return this.framebufferName[0] != 0; }
if (!framebuffer.bindFramebuffer(dc)) { return 0; // framebuffer failed to bind Texture colorAttachment = framebuffer.getAttachedTexture(GLES20.GL_COLOR_ATTACHMENT0); GLES20.glViewport(0, 0, colorAttachment.getWidth(), colorAttachment.getHeight()); GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT);
Texture depthTexture = dc.scratchFramebuffer().getAttachedTexture(GLES20.GL_DEPTH_ATTACHMENT); if (!depthTexture.bindTexture(dc)) { return; // framebuffer texture failed to bind