From 54e2ff13fe45b80e845b524cb82ff6d4bfba6b9b Mon Sep 17 00:00:00 2001 From: codeanticode Date: Tue, 20 Nov 2012 22:05:21 +0000 Subject: [PATCH] support for anisotropic filtering --- android/core/src/processing/opengl/PGL.java | 19 ++++++++++++++++++- .../processing/opengl/PGraphicsOpenGL.java | 8 ++++++++ .../core/src/processing/opengl/Texture.java | 4 ++++ core/src/processing/core/PApplet.java | 2 +- core/src/processing/opengl/PGL.java | 15 +++++++++++++++ .../processing/opengl/PGraphicsOpenGL.java | 10 ++++++++++ core/src/processing/opengl/Texture.java | 4 ++++ 7 files changed, 60 insertions(+), 2 deletions(-) diff --git a/android/core/src/processing/opengl/PGL.java b/android/core/src/processing/opengl/PGL.java index b42dce582..d043f6df9 100644 --- a/android/core/src/processing/opengl/PGL.java +++ b/android/core/src/processing/opengl/PGL.java @@ -146,7 +146,7 @@ public class PGL { // The values for constants not defined in the GLES20 interface can be found // in this file: - // http://androidxref.com/source/raw/development/tools/glesv2debugger/src/com/android/glesv2debugger/GLEnum.java + // http://code.metager.de/source/xref/android/4.0.3/development/tools/glesv2debugger/src/com/android/glesv2debugger/GLEnum.java public static final int FALSE = GLES20.GL_FALSE; public static final int TRUE = GLES20.GL_TRUE; @@ -197,6 +197,9 @@ public class PGL { public static final int LINEAR_MIPMAP_LINEAR = GLES20.GL_LINEAR_MIPMAP_LINEAR; + public static final int TEXTURE_MAX_ANISOTROPY = 0x84FE; + public static final int MAX_TEXTURE_MAX_ANISOTROPY = 0x84FF; + public static final int CLAMP_TO_EDGE = GLES20.GL_CLAMP_TO_EDGE; public static final int REPEAT = GLES20.GL_REPEAT; @@ -767,6 +770,15 @@ public class PGL { } + public void getFloatv(int name, float[] values, int offset) { + if (-1 < name) { + GLES20.glGetFloatv(name, values, offset); + } else { + Arrays.fill(values, 0); + } + } + + public void getBooleanv(int name, boolean[] values, int offset) { if (-1 < name) { GLES20.glGetBooleanv(name, values, offset); @@ -899,6 +911,11 @@ public class PGL { } + public void texParameterf(int target, int param, float value) { + GLES20.glTexParameterf(target, param, value); + } + + public void getTexParameteriv(int target, int param, int[] values, int offset) { GLES20.glGetTexParameteriv(target, param, values, offset); diff --git a/android/core/src/processing/opengl/PGraphicsOpenGL.java b/android/core/src/processing/opengl/PGraphicsOpenGL.java index 8e7c27d47..3b9b9d878 100644 --- a/android/core/src/processing/opengl/PGraphicsOpenGL.java +++ b/android/core/src/processing/opengl/PGraphicsOpenGL.java @@ -110,6 +110,7 @@ public class PGraphicsOpenGL extends PGraphics { static public boolean autoMipmapGenSupported; static public boolean fboMultisampleSupported; static public boolean packedDepthStencilSupported; + static public boolean anisoSamplingSupported; static public boolean blendEqSupported; /** Some hardware limits */ @@ -117,6 +118,7 @@ public class PGraphicsOpenGL extends PGraphics { static public int maxSamples; static public float maxPointSize; static public float maxLineWidth; + static public float maxAnisoAmount; static public int depthBits; static public int stencilBits; @@ -6144,6 +6146,12 @@ public class PGraphicsOpenGL extends PGraphics { pgl.getIntegerv(PGL.STENCIL_BITS, temp, 0); stencilBits = temp[0]; + if (anisoSamplingSupported) { + float ftemp[] = new float[1]; + pgl.getFloatv(PGL.MAX_TEXTURE_MAX_ANISOTROPY, ftemp, 0); + maxAnisoAmount = ftemp[0]; + } + glParamsRead = true; } diff --git a/android/core/src/processing/opengl/Texture.java b/android/core/src/processing/opengl/Texture.java index 669769aea..3e241f784 100644 --- a/android/core/src/processing/opengl/Texture.java +++ b/android/core/src/processing/opengl/Texture.java @@ -1141,6 +1141,10 @@ public class Texture implements PConstants { pgl.texParameteri(glTarget, PGL.TEXTURE_MAG_FILTER, glMagFilter); pgl.texParameteri(glTarget, PGL.TEXTURE_WRAP_S, glWrapS); pgl.texParameteri(glTarget, PGL.TEXTURE_WRAP_T, glWrapT); + if (PGraphicsOpenGL.anisoSamplingSupported) { + pgl.texParameterf(glTarget, PGL.TEXTURE_MAX_ANISOTROPY, + PGraphicsOpenGL.maxAnisoAmount); + } // First, we use glTexImage2D to set the full size of the texture (glW/glH // might be diff from w/h in the case that the GPU doesn't support NPOT diff --git a/core/src/processing/core/PApplet.java b/core/src/processing/core/PApplet.java index 4a18a8626..48c1d7e96 100644 --- a/core/src/processing/core/PApplet.java +++ b/core/src/processing/core/PApplet.java @@ -10826,7 +10826,7 @@ public class PApplet extends Applet /** * @param kind either LINE, TRIANGLE, RECT, ELLIPSE, ARC, SPHERE, BOX - * @param p parameters that match the kind of shape + * @param p parameters that match the kind of shape */ public PShape createShape(int kind, float... p) { return g.createShape(kind, p); diff --git a/core/src/processing/opengl/PGL.java b/core/src/processing/opengl/PGL.java index 47179c478..e3855759e 100644 --- a/core/src/processing/opengl/PGL.java +++ b/core/src/processing/opengl/PGL.java @@ -218,6 +218,11 @@ public class PGL { public static final int LINEAR_MIPMAP_NEAREST = GL.GL_LINEAR_MIPMAP_NEAREST; public static final int LINEAR_MIPMAP_LINEAR = GL.GL_LINEAR_MIPMAP_LINEAR; + public static final int TEXTURE_MAX_ANISOTROPY = + GL.GL_TEXTURE_MAX_ANISOTROPY_EXT; + public static final int MAX_TEXTURE_MAX_ANISOTROPY = + GL.GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT; + public static final int CLAMP_TO_EDGE = GL.GL_CLAMP_TO_EDGE; public static final int REPEAT = GL.GL_REPEAT; @@ -905,6 +910,11 @@ public class PGL { } + public void getFloatv(int name, float[] values, int offset) { + gl.glGetFloatv(name, values, offset); + } + + public void getBooleanv(int name, boolean[] values, int offset) { if (-1 < name) { byte[] bvalues = new byte[values.length]; @@ -1043,6 +1053,11 @@ public class PGL { } + public void texParameterf(int target, int param, float value) { + gl.glTexParameterf(target, param, value); + } + + public void getTexParameteriv(int target, int param, int[] values, int offset) { gl.glGetTexParameteriv(target, param, values, offset); diff --git a/core/src/processing/opengl/PGraphicsOpenGL.java b/core/src/processing/opengl/PGraphicsOpenGL.java index b4659b80f..fe80963d2 100644 --- a/core/src/processing/opengl/PGraphicsOpenGL.java +++ b/core/src/processing/opengl/PGraphicsOpenGL.java @@ -117,6 +117,7 @@ public class PGraphicsOpenGL extends PGraphics { static public boolean autoMipmapGenSupported; static public boolean fboMultisampleSupported; static public boolean packedDepthStencilSupported; + static public boolean anisoSamplingSupported; static public boolean blendEqSupported; /** Some hardware limits */ @@ -124,6 +125,7 @@ public class PGraphicsOpenGL extends PGraphics { static public int maxSamples; static public float maxPointSize; static public float maxLineWidth; + static public float maxAnisoAmount; static public int depthBits; static public int stencilBits; @@ -6151,6 +6153,8 @@ public class PGraphicsOpenGL extends PGraphics { -1 < OPENGL_EXTENSIONS.indexOf("_framebuffer_multisample"); packedDepthStencilSupported = -1 < OPENGL_EXTENSIONS.indexOf("_packed_depth_stencil"); + anisoSamplingSupported = + -1 < OPENGL_EXTENSIONS.indexOf("_texture_filter_anisotropic"); try { pgl.blendEquation(PGL.FUNC_ADD); @@ -6179,6 +6183,12 @@ public class PGraphicsOpenGL extends PGraphics { pgl.getIntegerv(PGL.STENCIL_BITS, temp, 0); stencilBits = temp[0]; + if (anisoSamplingSupported) { + float ftemp[] = new float[1]; + pgl.getFloatv(PGL.MAX_TEXTURE_MAX_ANISOTROPY, ftemp, 0); + maxAnisoAmount = ftemp[0]; + } + glParamsRead = true; } diff --git a/core/src/processing/opengl/Texture.java b/core/src/processing/opengl/Texture.java index 67a55aca2..5badd5b5a 100644 --- a/core/src/processing/opengl/Texture.java +++ b/core/src/processing/opengl/Texture.java @@ -1141,6 +1141,10 @@ public class Texture implements PConstants { pgl.texParameteri(glTarget, PGL.TEXTURE_MAG_FILTER, glMagFilter); pgl.texParameteri(glTarget, PGL.TEXTURE_WRAP_S, glWrapS); pgl.texParameteri(glTarget, PGL.TEXTURE_WRAP_T, glWrapT); + if (PGraphicsOpenGL.anisoSamplingSupported) { + pgl.texParameterf(glTarget, PGL.TEXTURE_MAX_ANISOTROPY, + PGraphicsOpenGL.maxAnisoAmount); + } // First, we use glTexImage2D to set the full size of the texture (glW/glH // might be diff from w/h in the case that the GPU doesn't support NPOT