diff --git a/android/core/src/processing/opengl/PFontTexture.java b/android/core/src/processing/opengl/PFontTexture.java index 5d655ca3d..b4fdd28c4 100644 --- a/android/core/src/processing/opengl/PFontTexture.java +++ b/android/core/src/processing/opengl/PFontTexture.java @@ -121,12 +121,12 @@ class PFontTexture implements PConstants { if (is3D) { // Bilinear sampling ensures that the texture doesn't look pixelated either // when it is magnified or minified... - tex = new Texture(parent, w, h, new Texture.Parameters(ARGB, BILINEAR, false)); + tex = new Texture(parent, w, h, new Texture.Parameters(ARGB, Texture.BILINEAR, false)); } else { // ...however, the effect of bilinear sampling is to add some blurriness to the text // in its original size. In 2D, we assume that text will be shown at its original // size, so linear sampling is chosen instead (which only affects minimized text). - tex = new Texture(parent, w, h, new Texture.Parameters(ARGB, LINEAR, false)); + tex = new Texture(parent, w, h, new Texture.Parameters(ARGB, Texture.LINEAR, false)); } if (textures == null) { diff --git a/android/core/src/processing/opengl/PGraphicsOpenGL.java b/android/core/src/processing/opengl/PGraphicsOpenGL.java index 2580ccc9f..8951ccc19 100644 --- a/android/core/src/processing/opengl/PGraphicsOpenGL.java +++ b/android/core/src/processing/opengl/PGraphicsOpenGL.java @@ -290,6 +290,13 @@ public class PGraphicsOpenGL extends PGraphics { // ........................................................ + // Texturing: + + public int textureWrap = Texture.CLAMP; + public int textureQuality = Texture.BEST; + + // ........................................................ + // Blending: protected int blendMode; @@ -2040,6 +2047,17 @@ public class PGraphicsOpenGL extends PGraphics { } } + + public void textureWrap(int wrap) { + this.textureWrap = wrap; + } + + + public void textureQuality(int quality) { + this.textureQuality = quality; + } + + public void texture(PImage image) { if (flushMode == FLUSH_WHEN_FULL && hints[DISABLE_TEXTURE_CACHE] && image != textureImage0) { @@ -5194,17 +5212,17 @@ public class PGraphicsOpenGL extends PGraphics { } else { params.mipmaps = true; } - if (textureQuality == LOW) { + if (textureQuality == Texture.LOW) { params.sampling = POINT; - } else if (textureQuality == MEDIUM) { - params.sampling = LINEAR; - } else if (textureQuality == HIGH) { - params.sampling = BILINEAR; - } else if (textureQuality == BEST) { + } else if (textureQuality == Texture.MEDIUM) { + params.sampling = Texture.LINEAR; + } else if (textureQuality == Texture.HIGH) { + params.sampling = Texture.BILINEAR; + } else if (textureQuality == Texture.BEST) { if (params.mipmaps) { - params.sampling = TRILINEAR; + params.sampling = Texture.TRILINEAR; } else { - params.sampling = BILINEAR; + params.sampling = Texture.BILINEAR; PGraphics.showWarning("BEST texture quality requires mipmaps, will switch to HIGH."); } } @@ -5277,7 +5295,7 @@ public class PGraphicsOpenGL extends PGraphics { pgl.initOffscreenSurface(pgPrimary.pgl); pgl.updateOffscreen(pgPrimary.pgl); - loadTextureImpl(BILINEAR, false); + loadTextureImpl(Texture.BILINEAR, false); // In case of reinitialization (for example, when the smooth level // is changed), we make sure that all the OpenGL resources associated @@ -5365,17 +5383,17 @@ public class PGraphicsOpenGL extends PGraphics { public PShader loadShader(String vertFilename, String fragFilename, int kind) { - if (kind == FLAT_SHADER) { + if (kind == PShader.FLAT_SHADER) { return new PolyFlatShader(parent, vertFilename, fragFilename); - } else if (kind == LIGHT_SHADER) { + } else if (kind == PShader.LIGHT_SHADER) { return new PolyLightShader(parent, vertFilename, fragFilename); - } else if (kind == TEXTURE_SHADER) { + } else if (kind == PShader.TEXTURE_SHADER) { return new PolyTexShader(parent, vertFilename, fragFilename); - } else if (kind == FULL_SHADER) { + } else if (kind == PShader.FULL_SHADER) { return new PolyFullShader(parent, vertFilename, fragFilename); - } else if (kind == LINE3D_SHADER) { + } else if (kind == PShader.LINE3D_SHADER) { return new LineShader(parent, vertFilename, fragFilename); - } else if (kind == POINT3D_SHADER) { + } else if (kind == PShader.POINT3D_SHADER) { return new PointShader(parent, vertFilename, fragFilename); } else { PGraphics.showWarning("Wrong shader type"); @@ -5386,22 +5404,22 @@ public class PGraphicsOpenGL extends PGraphics { public PShader loadShader(String fragFilename, int kind) { PShader shader; - if (kind == FLAT_SHADER) { + if (kind == PShader.FLAT_SHADER) { shader = new PolyFlatShader(parent); shader.setVertexShader(defPolyFlatShaderVertURL); - } else if (kind == LIGHT_SHADER) { + } else if (kind == PShader.LIGHT_SHADER) { shader = new PolyLightShader(parent); shader.setVertexShader(defPolyLightShaderVertURL); - } else if (kind == TEXTURE_SHADER) { + } else if (kind == PShader.TEXTURE_SHADER) { shader = new PolyTexShader(parent); shader.setVertexShader(defPolyTexShaderVertURL); - } else if (kind == FULL_SHADER) { + } else if (kind == PShader.FULL_SHADER) { shader = new PolyFullShader(parent); shader.setVertexShader(defPolyFullShaderVertURL); - } else if (kind == LINE3D_SHADER) { + } else if (kind == PShader.LINE3D_SHADER) { shader = new LineShader(parent); shader.setVertexShader(defLineShaderVertURL); - } else if (kind == POINT3D_SHADER) { + } else if (kind == PShader.POINT3D_SHADER) { shader = new PointShader(parent); shader.setVertexShader(defPointShaderVertURL); } else { @@ -5415,17 +5433,17 @@ public class PGraphicsOpenGL extends PGraphics { public void setShader(PShader shader, int kind) { flush(); // Flushing geometry with a different shader. - if (kind == FLAT_SHADER) { + if (kind == PShader.FLAT_SHADER) { polyFlatShader = (PolyFlatShader) shader; - } else if (kind == LIGHT_SHADER) { + } else if (kind == PShader.LIGHT_SHADER) { polyLightShader = (PolyLightShader) shader; - } else if (kind == TEXTURE_SHADER) { + } else if (kind == PShader.TEXTURE_SHADER) { polyTexShader = (PolyTexShader) shader; - } else if (kind == FULL_SHADER) { + } else if (kind == PShader.FULL_SHADER) { polyFullShader = (PolyFullShader) shader; - } else if (kind == LINE3D_SHADER) { + } else if (kind == PShader.LINE3D_SHADER) { lineShader = (LineShader) shader; - } else if (kind == POINT3D_SHADER) { + } else if (kind == PShader.POINT3D_SHADER) { pointShader = (PointShader) shader; } else { PGraphics.showWarning("Wrong shader type"); @@ -5435,32 +5453,32 @@ public class PGraphicsOpenGL extends PGraphics { public void defaultShader(int kind) { flush(); // Flushing geometry with a different shader. - if (kind == FLAT_SHADER) { + if (kind == PShader.FLAT_SHADER) { if (defPolyFlatShader == null || defPolyFlatShader.contextIsOutdated()) { defPolyFlatShader = new PolyFlatShader(parent, defPolyFlatShaderVertURL, defPolyNoTexShaderFragURL); } polyFlatShader = defPolyFlatShader; - } else if (kind == LIGHT_SHADER) { + } else if (kind == PShader.LIGHT_SHADER) { if (defPolyLightShader == null || defPolyLightShader.contextIsOutdated()) { defPolyLightShader = new PolyLightShader(parent, defPolyLightShaderVertURL, defPolyNoTexShaderFragURL); } polyLightShader = defPolyLightShader; - } else if (kind == TEXTURE_SHADER) { + } else if (kind == PShader.TEXTURE_SHADER) { if (defPolyTexShader == null || defPolyTexShader.contextIsOutdated()) { defPolyTexShader = new PolyTexShader(parent, defPolyTexShaderVertURL, defPolyTexShaderFragURL); } polyTexShader = defPolyTexShader; - } else if (kind == FULL_SHADER) { + } else if (kind == PShader.FULL_SHADER) { if (defPolyFullShader == null || defPolyFullShader.contextIsOutdated()) { defPolyFullShader = new PolyFullShader(parent, defPolyFullShaderVertURL, defPolyTexShaderFragURL); } polyFullShader = defPolyFullShader; - } else if (kind == LINE3D_SHADER) { + } else if (kind == PShader.LINE3D_SHADER) { if (defLineShader == null || defLineShader.contextIsOutdated()) { defLineShader = new LineShader(parent, defLineShaderVertURL, defLineShaderFragURL); } lineShader = defLineShader; - } else if (kind == POINT3D_SHADER) { + } else if (kind == PShader.POINT3D_SHADER) { if (defPointShader == null || defPointShader.contextIsOutdated()) { defPointShader = new PointShader(parent, defPointShaderVertURL, defPointShaderFragURL); } diff --git a/android/core/src/processing/opengl/PShader.java b/android/core/src/processing/opengl/PShader.java index 42c951eba..6ee095a79 100644 --- a/android/core/src/processing/opengl/PShader.java +++ b/android/core/src/processing/opengl/PShader.java @@ -33,6 +33,14 @@ import java.net.URL; * (http://www.hardcorepawn.com/) */ public class PShader { + // shaders constants + static public final int FLAT_SHADER = 0; + static public final int LIGHT_SHADER = 1; + static public final int TEXTURE_SHADER = 2; + static public final int FULL_SHADER = 3; + static public final int LINE3D_SHADER = 4; + static public final int POINT3D_SHADER = 5; + protected PApplet parent; protected PGraphicsOpenGL pg; protected PGL pgl; diff --git a/android/core/src/processing/opengl/Texture.java b/android/core/src/processing/opengl/Texture.java index 8a6142e47..b725fcb85 100644 --- a/android/core/src/processing/opengl/Texture.java +++ b/android/core/src/processing/opengl/Texture.java @@ -40,6 +40,37 @@ import java.util.NoSuchElementException; */ public class Texture implements PConstants { public int width, height; + + // texture constants + + /** This constant identifies the texture target GL_TEXTURE_2D, that is, + * textures with normalized coordinates */ + public static final int TEXTURE2D = 0; + + /** Texture quality constants */ + public static final int LOW = 0; + public static final int MEDIUM = 1; + public static final int HIGH = 2; + public static final int BEST = 3; + + /** Point sampling: both magnification and minification filtering are set to nearest */ + //public static final int POINT = 2; // shared with shape feature + /** Linear sampling: magnification filtering is nearest, minification set to linear */ + public static final int LINEAR = 3; + /** Bilinear sampling: both magnification filtering is set to linear and minification + * either to linear-mipmap-nearest (linear interplation is used within a mipmap, but + * not between different mipmaps). */ + public static final int BILINEAR = 4; + /** Trilinear sampling: magnification filtering set to linear, minification to + * linear-mipmap-linear, which offers the best mipmap quality since linear + * interpolation to compute the value in each of two maps and then interpolates linearly + * between these two value. */ + public static final int TRILINEAR = 5; + + /** This constant identifies the clamp-to-edge wrapping mode */ + public static final int CLAMP = 0; + /** This constant identifies the repeat wrapping mode */ + public static final int REPEAT = 1; protected PApplet parent; // The Processing applet protected PGraphicsOpenGL pg; // The main renderer