From b20e667256de3514f92d99f8dc8f515de19e3b5a Mon Sep 17 00:00:00 2001 From: codeanticode Date: Tue, 20 Aug 2013 11:42:30 -0400 Subject: [PATCH] set viewport in PGL.drawTexture(), fixes #1869 --- core/src/processing/opengl/PGL.java | 22 ++++++++++++++++++- .../processing/opengl/PGraphicsOpenGL.java | 4 +--- core/src/processing/opengl/Texture.java | 4 +++- 3 files changed, 25 insertions(+), 5 deletions(-) diff --git a/core/src/processing/opengl/PGL.java b/core/src/processing/opengl/PGL.java index 6fcc12f10..6c7b5f69e 100644 --- a/core/src/processing/opengl/PGL.java +++ b/core/src/processing/opengl/PGL.java @@ -407,6 +407,7 @@ public class PGL { protected ByteBuffer byteBuffer; protected IntBuffer intBuffer; + protected IntBuffer viewBuffer; protected IntBuffer colorBuffer; protected FloatBuffer depthBuffer; @@ -465,6 +466,7 @@ public class PGL { byteBuffer = allocateByteBuffer(1); intBuffer = allocateIntBuffer(1); + viewBuffer = allocateIntBuffer(4); } @@ -1448,7 +1450,7 @@ public class PGL { protected void initTexture(int target, int format, int width, int height, - int initColor) { + int initColor) { int[] glcolor = new int[16 * 16]; Arrays.fill(glcolor, javaToNativeARGB(initColor)); IntBuffer texels = PGL.allocateDirectIntBuffer(16 * 16); @@ -1544,6 +1546,11 @@ public class PGL { boolean depthMask = getDepthWriteMask(); depthMask(false); + // Making sure that the viewport matches the provided screen dimensions + viewBuffer.rewind(); + getIntegerv(VIEWPORT, viewBuffer); + viewport(0, 0, scrW, scrH); + useProgram(tex2DShaderProgram); enableVertexAttribArray(tex2DVertLoc); @@ -1610,6 +1617,9 @@ public class PGL { disable(DEPTH_TEST); } depthMask(depthMask); + + viewport(viewBuffer.get(0), viewBuffer.get(1), + viewBuffer.get(2),viewBuffer.get(3)); } } @@ -1649,6 +1659,11 @@ public class PGL { boolean depthMask = getDepthWriteMask(); depthMask(false); + // Making sure that the viewport matches the provided screen dimensions + viewBuffer.rewind(); + getIntegerv(VIEWPORT, viewBuffer); + viewport(0, 0, scrW, scrH); + useProgram(texRectShaderProgram); enableVertexAttribArray(texRectVertLoc); @@ -1715,6 +1730,9 @@ public class PGL { disable(DEPTH_TEST); } depthMask(depthMask); + + viewport(viewBuffer.get(0), viewBuffer.get(1), + viewBuffer.get(2),viewBuffer.get(3)); } } @@ -2124,12 +2142,14 @@ public class PGL { protected int maxSamples() { + intBuffer.rewind(); getIntegerv(MAX_SAMPLES, intBuffer); return intBuffer.get(0); } protected int getMaxTexUnits() { + intBuffer.rewind(); getIntegerv(MAX_TEXTURE_IMAGE_UNITS, intBuffer); return intBuffer.get(0); } diff --git a/core/src/processing/opengl/PGraphicsOpenGL.java b/core/src/processing/opengl/PGraphicsOpenGL.java index c1ee8eaf9..f861acc19 100644 --- a/core/src/processing/opengl/PGraphicsOpenGL.java +++ b/core/src/processing/opengl/PGraphicsOpenGL.java @@ -3372,10 +3372,8 @@ public class PGraphicsOpenGL extends PGraphics { if (textTex.currentTex != info.texIndex) { textTex.setTexture(info.texIndex); } - PImage tex = textTex.getCurrentTexture(); - beginShape(QUADS); - texture(tex); + texture(textTex.getCurrentTexture()); vertex(x0, y0, info.u0, info.v0); vertex(x1, y0, info.u1, info.v0); vertex(x1, y1, info.u1, info.v1); diff --git a/core/src/processing/opengl/Texture.java b/core/src/processing/opengl/Texture.java index 003b1ace8..323d6f818 100644 --- a/core/src/processing/opengl/Texture.java +++ b/core/src/processing/opengl/Texture.java @@ -1235,7 +1235,8 @@ public class Texture implements PConstants { // FBO copy: PGraphicsOpenGL.pushFramebuffer(); PGraphicsOpenGL.setFramebuffer(tempFbo); - // Clear the color buffer to make sure that the alpha of the + // 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) { @@ -1254,6 +1255,7 @@ public class Texture implements PConstants { x, y, w, h, x, y, w, h); } PGraphicsOpenGL.popFramebuffer(); + updateTexels(x, y, w, h); }