diff --git a/core/src/processing/opengl/PGL.java b/core/src/processing/opengl/PGL.java index cf7537b28..0b4dc159c 100644 --- a/core/src/processing/opengl/PGL.java +++ b/core/src/processing/opengl/PGL.java @@ -362,6 +362,9 @@ public class PGL { /** Which texturing targets are enabled */ protected static boolean[] texturingTargets = { false, false }; + /** Which textures are bound to each target */ + protected static int[] boundTextures = { 0, 0 }; + /////////////////////////////////////////////////////////////////////////////////// // FBO for anti-aliased rendering @@ -1060,6 +1063,11 @@ public class PGL { public void glBindTexture(int target, int id) { gl.glBindTexture(target, id); + if (target == GL_TEXTURE_2D) { + boundTextures[0] = id; + } else if (target == GL_TEXTURE_RECTANGLE) { + boundTextures[1] = id; + } } @@ -1729,6 +1737,17 @@ public class PGL { } + public boolean textureIsBound(int target, int id) { + if (target == GL_TEXTURE_2D) { + return boundTextures[0] == id; + } else if (target == GL_TEXTURE_RECTANGLE) { + return boundTextures[1] == id; + } else { + return false; + } + } + + public void initTexture(int target, int format, int width, int height) { int[] texels = new int[width * height]; glTexSubImage2D(target, 0, 0, 0, width, height, format, GL_UNSIGNED_BYTE, IntBuffer.wrap(texels)); diff --git a/core/src/processing/opengl/PGraphicsOpenGL.java b/core/src/processing/opengl/PGraphicsOpenGL.java index c7cc7540e..524e13978 100644 --- a/core/src/processing/opengl/PGraphicsOpenGL.java +++ b/core/src/processing/opengl/PGraphicsOpenGL.java @@ -6717,20 +6717,6 @@ public class PGraphicsOpenGL extends PGraphics { } } } - /* - // Disabling texturing for each of the targets used - // by textures in the cache. - for (int i = 0; i < size; i++) { - PImage img = textures[i]; - if (img != null) { - Texture tex = pgPrimary.getTexture(img); - if (tex != null) { - pgl.disableTexturing(tex.glTarget); - } - } - } - */ - } } diff --git a/core/src/processing/opengl/Texture.java b/core/src/processing/opengl/Texture.java index 6c0c15468..59d3567e3 100644 --- a/core/src/processing/opengl/Texture.java +++ b/core/src/processing/opengl/Texture.java @@ -100,8 +100,6 @@ public class Texture implements PConstants { protected boolean modified; protected int mx1, my1, mx2, my2; - protected int[] tempName = { 0 }; - protected Object bufferSource; protected LinkedList bufferCache = null; protected Method disposeBufferMethod; @@ -583,7 +581,7 @@ public class Texture implements PConstants { public void unbind() { - if (boundTexture() == glName) { + if (pgl.textureIsBound(glTarget, glName)) { // We don't want to unbind another texture // that might be bound instead of this one. if (!pgl.texturingIsEnabled(glTarget)) { @@ -782,12 +780,6 @@ public class Texture implements PConstants { // Utilities - protected int boundTexture() { - pgl.glGetIntegerv(glTarget, tempName, 0); - return tempName[0]; - } - - /** * Flips intArray along the X axis. * @param intArray int[]