diff --git a/android/core/src/processing/opengl/PFontTexture.java b/android/core/src/processing/opengl/PFontTexture.java index 991f1558c..d5863891a 100644 --- a/android/core/src/processing/opengl/PFontTexture.java +++ b/android/core/src/processing/opengl/PFontTexture.java @@ -376,7 +376,7 @@ class PFontTexture implements PConstants { void updateTex() { - textures[texIndex].setNative(pixels, 0, crop[0] - 1, crop[1] + crop[3] - 1, crop[2] + 2, -crop[3] + 2); + textures[texIndex].setNative(pixels, crop[0] - 1, crop[1] + crop[3] - 1, crop[2] + 2, -crop[3] + 2); } } } \ No newline at end of file diff --git a/android/core/src/processing/opengl/PGraphicsOpenGL.java b/android/core/src/processing/opengl/PGraphicsOpenGL.java index 802a3e2f1..a0f3201ff 100644 --- a/android/core/src/processing/opengl/PGraphicsOpenGL.java +++ b/android/core/src/processing/opengl/PGraphicsOpenGL.java @@ -5577,7 +5577,6 @@ public class PGraphicsOpenGL extends PGraphics { params.sampling = textureSampling; if (params.sampling == Texture.TRILINEAR && !params.mipmaps) { params.sampling = Texture.BILINEAR; - PGraphics.showWarning("TRILINEAR texture sampling requires mipmaps, which are disabled. I will use BILINEAR instead."); } params.wrapU = textureWrap; params.wrapV = textureWrap; @@ -6312,7 +6311,7 @@ public class PGraphicsOpenGL extends PGraphics { tcmat[3] = 0; tcmat[7] = 0; tcmat[11] = 0; tcmat[15] = 0; setUniformMatrix(texcoordMatrixLoc, tcmat); } - + setUniformValue(texcoordOffsetLoc, 1.0f / tex.width, 1.0f / tex.height); } diff --git a/android/core/src/processing/opengl/Texture.java b/android/core/src/processing/opengl/Texture.java index 526abfc41..c79ffd541 100644 --- a/android/core/src/processing/opengl/Texture.java +++ b/android/core/src/processing/opengl/Texture.java @@ -381,42 +381,64 @@ public class Texture implements PConstants { updateTexels(x, y, w, h); } - + //////////////////////////////////////////////////////////// // Native set methods - - - public void setNative(int[] pix, int x, int y, int w, int h) { - setNative(pix, 0, x, y, w, h); - } - - - public void setNative(int[] pix, int level, int x, int y, int w, int h) { - setNative(IntBuffer.wrap(pix), level, x, y, w, h); - } - public void setNative(IntBuffer buffer, int x, int y, int w, int h) { - setNative(buffer, 0, x, y, w, h); - } + public void setNative(int[] pixels) { + setNative(pixels, 0, 0, width, height); + } - public void setNative(IntBuffer buffer, int level, int x, int y, int w, int h) { + public void setNative(int[] pixels, int x, int y, int w, int h) { + setNative(IntBuffer.wrap(pixels), x, y, w, h); + } + + + public void setNative(IntBuffer pixels, int x, int y, int w, int h) { + if (pixels == null) { + pixels = null; + PGraphics.showWarning("The pixel buffer is null."); + return; + } + if (pixels.capacity() != w * h) { + PGraphics.showWarning("The pixels array has a length of " + pixels.capacity() + ", but it should be " + w * h); + return; + } + + if (pixels.capacity() == 0) { + // Nothing to do (means that w == h == 0) but not an erroneous situation + return; + } + boolean enabledTex = false; if (!pgl.texturingIsEnabled(glTarget)) { pgl.enableTexturing(glTarget); enabledTex = true; } pgl.glBindTexture(glTarget, glName); - pgl.glTexSubImage2D(glTarget, level, x, y, w, h, PGL.GL_RGBA, PGL.GL_UNSIGNED_BYTE, buffer); + + if (usingMipmaps) { + if (PGraphicsOpenGL.autoMipmapGenSupported) { + pgl.glTexSubImage2D(glTarget, 0, x, y, w, h, PGL.GL_RGBA, PGL.GL_UNSIGNED_BYTE, pixels); + pgl.glGenerateMipmap(glTarget); + } else { + pgl.glTexSubImage2D(glTarget, 0, x, y, w, h, PGL.GL_RGBA, PGL.GL_UNSIGNED_BYTE, pixels); + } + } else { + pgl.glTexSubImage2D(glTarget, 0, x, y, w, h, PGL.GL_RGBA, PGL.GL_UNSIGNED_BYTE, pixels); + } + pgl.glBindTexture(glTarget, 0); if (enabledTex) { pgl.disableTexturing(glTarget); } + updateTexels(x, y, w, h); - } + } //////////////////////////////////////////////////////////// diff --git a/core/src/processing/opengl/PFontTexture.java b/core/src/processing/opengl/PFontTexture.java index 991f1558c..d5863891a 100644 --- a/core/src/processing/opengl/PFontTexture.java +++ b/core/src/processing/opengl/PFontTexture.java @@ -376,7 +376,7 @@ class PFontTexture implements PConstants { void updateTex() { - textures[texIndex].setNative(pixels, 0, crop[0] - 1, crop[1] + crop[3] - 1, crop[2] + 2, -crop[3] + 2); + textures[texIndex].setNative(pixels, crop[0] - 1, crop[1] + crop[3] - 1, crop[2] + 2, -crop[3] + 2); } } } \ No newline at end of file diff --git a/core/src/processing/opengl/PGraphicsOpenGL.java b/core/src/processing/opengl/PGraphicsOpenGL.java index a916c6570..a0f3201ff 100644 --- a/core/src/processing/opengl/PGraphicsOpenGL.java +++ b/core/src/processing/opengl/PGraphicsOpenGL.java @@ -2468,12 +2468,6 @@ public class PGraphicsOpenGL extends PGraphics { for (int i = 0; i < texCache.size; i++) { Texture tex = texCache.getTexture(i); - PApplet.println(texCache.getTextureImage(i) + " " + tex); -// if (tex != null) { -// PApplet.println(tex.width + " " + tex.height); -// } - - // If the renderer is 2D, then lights should always be false, // so no need to worry about that. PolyShader shader = getPolyShader(lights, tex != null); @@ -5583,7 +5577,6 @@ public class PGraphicsOpenGL extends PGraphics { params.sampling = textureSampling; if (params.sampling == Texture.TRILINEAR && !params.mipmaps) { params.sampling = Texture.BILINEAR; - PGraphics.showWarning("TRILINEAR texture sampling requires mipmaps, which are disabled. I will use BILINEAR instead."); } params.wrapU = textureWrap; params.wrapV = textureWrap; @@ -6319,8 +6312,6 @@ public class PGraphicsOpenGL extends PGraphics { setUniformMatrix(texcoordMatrixLoc, tcmat); } - PApplet.println(tex.maxTexcoordU + " " + tex.maxTexcoordV); - setUniformValue(texcoordOffsetLoc, 1.0f / tex.width, 1.0f / tex.height); } diff --git a/core/src/processing/opengl/PShader.java b/core/src/processing/opengl/PShader.java index f2eb29e8b..93a27d162 100644 --- a/core/src/processing/opengl/PShader.java +++ b/core/src/processing/opengl/PShader.java @@ -205,6 +205,17 @@ public class PShader { } + public void set(String name, PImage tex) { + /* + texUnit = tu; + gl.glActiveTexture(GL.GL_TEXTURE0 + texUnit); + gl.glBindTexture(texTarget, tex); + if (-1 < texUniform) { + gl.glUniform1iARB(texUniform, texUnit); + */ + } + + public void set(String name, int x) { setUniformImpl(name, UniformValue.INT1, new int[] { x }); } diff --git a/core/src/processing/opengl/Texture.java b/core/src/processing/opengl/Texture.java index 526abfc41..c79ffd541 100644 --- a/core/src/processing/opengl/Texture.java +++ b/core/src/processing/opengl/Texture.java @@ -381,42 +381,64 @@ public class Texture implements PConstants { updateTexels(x, y, w, h); } - + //////////////////////////////////////////////////////////// // Native set methods - - - public void setNative(int[] pix, int x, int y, int w, int h) { - setNative(pix, 0, x, y, w, h); - } - - - public void setNative(int[] pix, int level, int x, int y, int w, int h) { - setNative(IntBuffer.wrap(pix), level, x, y, w, h); - } - public void setNative(IntBuffer buffer, int x, int y, int w, int h) { - setNative(buffer, 0, x, y, w, h); - } + public void setNative(int[] pixels) { + setNative(pixels, 0, 0, width, height); + } - public void setNative(IntBuffer buffer, int level, int x, int y, int w, int h) { + public void setNative(int[] pixels, int x, int y, int w, int h) { + setNative(IntBuffer.wrap(pixels), x, y, w, h); + } + + + public void setNative(IntBuffer pixels, int x, int y, int w, int h) { + if (pixels == null) { + pixels = null; + PGraphics.showWarning("The pixel buffer is null."); + return; + } + if (pixels.capacity() != w * h) { + PGraphics.showWarning("The pixels array has a length of " + pixels.capacity() + ", but it should be " + w * h); + return; + } + + if (pixels.capacity() == 0) { + // Nothing to do (means that w == h == 0) but not an erroneous situation + return; + } + boolean enabledTex = false; if (!pgl.texturingIsEnabled(glTarget)) { pgl.enableTexturing(glTarget); enabledTex = true; } pgl.glBindTexture(glTarget, glName); - pgl.glTexSubImage2D(glTarget, level, x, y, w, h, PGL.GL_RGBA, PGL.GL_UNSIGNED_BYTE, buffer); + + if (usingMipmaps) { + if (PGraphicsOpenGL.autoMipmapGenSupported) { + pgl.glTexSubImage2D(glTarget, 0, x, y, w, h, PGL.GL_RGBA, PGL.GL_UNSIGNED_BYTE, pixels); + pgl.glGenerateMipmap(glTarget); + } else { + pgl.glTexSubImage2D(glTarget, 0, x, y, w, h, PGL.GL_RGBA, PGL.GL_UNSIGNED_BYTE, pixels); + } + } else { + pgl.glTexSubImage2D(glTarget, 0, x, y, w, h, PGL.GL_RGBA, PGL.GL_UNSIGNED_BYTE, pixels); + } + pgl.glBindTexture(glTarget, 0); if (enabledTex) { pgl.disableTexturing(glTarget); } + updateTexels(x, y, w, h); - } + } ////////////////////////////////////////////////////////////