From d1c3191328fe9d1c15b1ac27cf0f0a05b176c300 Mon Sep 17 00:00:00 2001 From: Kenneth Russel Date: Sun, 8 Apr 2007 15:35:31 +0000 Subject: Added automatic mipmap generation support via GL_GENERATE_MIPMAP texture parameter to Texture class. Exposed this support up through the TextureRenderer and TextRenderer classes. Tested by temporarily enabling mipmap support for TextCube demo; no visual improvement, however, so left it disabled for now. git-svn-id: file:///usr/local/projects/SUN/JOGL/git-svn/svn-server-sync/jogl/trunk@1194 232f8b59-042b-4e1e-8c03-345bb8c30851 --- .../com/sun/opengl/util/j2d/TextRenderer.java | 68 +++++++++++++++++++--- 1 file changed, 61 insertions(+), 7 deletions(-) (limited to 'src/classes/com/sun/opengl/util/j2d/TextRenderer.java') diff --git a/src/classes/com/sun/opengl/util/j2d/TextRenderer.java b/src/classes/com/sun/opengl/util/j2d/TextRenderer.java index d25888be2..468590b7d 100755 --- a/src/classes/com/sun/opengl/util/j2d/TextRenderer.java +++ b/src/classes/com/sun/opengl/util/j2d/TextRenderer.java @@ -113,6 +113,9 @@ public class TextRenderer { private boolean antialiased; private boolean useFractionalMetrics; + // Whether we're attempting to use automatic mipmap generation support + private boolean mipmap; + private RectanglePacker packer; private boolean haveMaxSize; private RenderDelegate renderDelegate; @@ -227,15 +230,30 @@ public class TextRenderer { @param font the font to render with */ public TextRenderer(Font font) { - this(font, false, false); + this(font, false, false, null, false); + } + + /** Creates a new TextRenderer with the given font, using no + antialiasing or fractional metrics, and the default + RenderDelegate. If mipmap is true, attempts to use + OpenGL's automatic mipmap generation for better smoothing when + rendering the TextureRenderer's contents at a distance. + Equivalent to TextRenderer(font, false, false). + + @param font the font to render with + @param mipmap whether to attempt use of automatic mipmap generation + */ + public TextRenderer(Font font, boolean mipmap) { + this(font, false, false, null, mipmap); } /** Creates a new TextRenderer with the given Font, specified font properties, and default RenderDelegate. The antialiased and useFractionalMetrics flags provide control over the same properties at the Java 2D - level. Equivalent to TextRenderer(font, antialiased, - useFractionalMetrics, null). + level. No mipmap support is requested. Equivalent to + TextRenderer(font, antialiased, useFractionalMetrics, + null). @param font the font to render with @param antialiased whether to use antialiased fonts @@ -245,7 +263,7 @@ public class TextRenderer { public TextRenderer(Font font, boolean antialiased, boolean useFractionalMetrics) { - this(font, antialiased, useFractionalMetrics, null); + this(font, antialiased, useFractionalMetrics, null, false); } /** Creates a new TextRenderer with the given Font, specified font @@ -253,7 +271,7 @@ public class TextRenderer { antialiased and useFractionalMetrics flags provide control over the same properties at the Java 2D level. The renderDelegate provides more control - over the text rendered. + over the text rendered. No mipmap support is requested. @param font the font to render with @param antialiased whether to use antialiased fonts @@ -266,9 +284,35 @@ public class TextRenderer { boolean antialiased, boolean useFractionalMetrics, RenderDelegate renderDelegate) { + this(font, antialiased, useFractionalMetrics, renderDelegate, false); + } + + /** Creates a new TextRenderer with the given Font, specified font + properties, and given RenderDelegate. The + antialiased and useFractionalMetrics + flags provide control over the same properties at the Java 2D + level. The renderDelegate provides more control + over the text rendered. If mipmap is true, attempts + to use OpenGL's automatic mipmap generation for better smoothing + when rendering the TextureRenderer's contents at a distance. + + @param font the font to render with + @param antialiased whether to use antialiased fonts + @param useFractionalMetrics whether to use fractional font + metrics at the Java 2D level + @param renderDelegate the render delegate to use to draw the + text's bitmap, or null to use the default one + @param mipmap whether to attempt use of automatic mipmap generation + */ + public TextRenderer(Font font, + boolean antialiased, + boolean useFractionalMetrics, + RenderDelegate renderDelegate, + boolean mipmap) { this.font = font; this.antialiased = antialiased; this.useFractionalMetrics = useFractionalMetrics; + this.mipmap = mipmap; // FIXME: consider adjusting the size based on font size // (it will already automatically resize if necessary) @@ -631,6 +675,15 @@ public class TextRenderer { } needToResetColor = false; } + + // Disable future attempts to use mipmapping if TextureRenderer + // doesn't support it + if (mipmap && !getBackingStore().isUsingAutoMipmapGeneration()) { + if (DEBUG) { + System.err.println("Disabled mipmapping in TextRenderer"); + } + mipmap = false; + } } private void endRendering(boolean ortho) throws GLException { @@ -741,10 +794,11 @@ public class TextRenderer { // store (i.e., non-default Paint, foreground color, etc.), but // for now, let's just be more efficient TextureRenderer renderer; + if (renderDelegate.intensityOnly()) { - renderer = TextureRenderer.createAlphaOnlyRenderer(w, h); + renderer = TextureRenderer.createAlphaOnlyRenderer(w, h, mipmap); } else { - renderer = new TextureRenderer(w, h, true); + renderer = new TextureRenderer(w, h, true, mipmap); } if (DEBUG) { System.err.println(" TextRenderer allocating backing store " + w + " x " + h); -- cgit v1.2.3