// Copies source texture tex into this. protected void copyTexture( int texTarget, int texName, int texWidth, int texHeight, int x, int y, int w, int h, boolean scale) { if (tempFbo == null) { tempFbo = new FrameBuffer(parent, glWidth, glHeight); } // This texture is the color (destination) buffer of the FBO. tempFbo.setColorBuffer(this); tempFbo.disableDepthTest(); // FBO copy: pg.pushFramebuffer(); pg.setFramebuffer(tempFbo); if (scale) { // Rendering tex into "this", and scaling the source rectangle // to cover the entire destination region. pgl.drawTexture(texTarget, texName, texWidth, texHeight, x, y, w, h, 0, 0, width, height); } else { // Rendering tex into "this" but without scaling so the contents // of the source texture fall in the corresponding texels of the // destination. pgl.drawTexture(texTarget, texName, texWidth, texHeight, x, y, w, h, x, y, w, h); } pg.popFramebuffer(); updateTexels(x, y, w, h); }
// Copies source texture tex into this. protected void copyTexture(Texture tex, int x, int y, int w, int h, boolean scale) { if (tex == null) { throw new RuntimeException("Source texture is null"); } if (tempFbo == null) { tempFbo = new FrameBuffer(glWidth, glHeight); } // This texture is the color (destination) buffer of the FBO. tempFbo.setColorBuffer(this); tempFbo.disableDepthTest(); // FBO copy: PGraphicsOpenGL.pushFramebuffer(); PGraphicsOpenGL.setFramebuffer(tempFbo); // Clear the color buffer to make sure that the alpha channel is set to // full transparency pgl.clearColor(0, 0, 0, 0); pgl.clear(PGL.COLOR_BUFFER_BIT); if (scale) { // Rendering tex into "this", and scaling the source rectangle // to cover the entire destination region. pgl.drawTexture( tex.glTarget, tex.glName, tex.glWidth, tex.glHeight, tempFbo.width, tempFbo.height, x, y, w, h, 0, 0, width, height); } else { // Rendering tex into "this" but without scaling so the contents // of the source texture fall in the corresponding texels of the // destination. pgl.drawTexture( tex.glTarget, tex.glName, tex.glWidth, tex.glHeight, tempFbo.width, tempFbo.height, x, y, w, h, x, y, w, h); } PGraphicsOpenGL.popFramebuffer(); updateTexels(x, y, w, h); }