diff options
Diffstat (limited to 'src/classes/com/sun/opengl/util/j2d')
-rwxr-xr-x | src/classes/com/sun/opengl/util/j2d/TextRenderer.java | 14 | ||||
-rwxr-xr-x | src/classes/com/sun/opengl/util/j2d/TextureRenderer.java | 35 |
2 files changed, 34 insertions, 15 deletions
diff --git a/src/classes/com/sun/opengl/util/j2d/TextRenderer.java b/src/classes/com/sun/opengl/util/j2d/TextRenderer.java index e97c31173..027f857fe 100755 --- a/src/classes/com/sun/opengl/util/j2d/TextRenderer.java +++ b/src/classes/com/sun/opengl/util/j2d/TextRenderer.java @@ -365,6 +365,19 @@ public class TextRenderer { } } + /** Disposes of all resources this TextRenderer is using. It is not + valid to use the TextRenderer after this method is called. + + @throws GLException If an OpenGL context is not current when this method is called + */ + public void dispose() throws GLException { + packer.dispose(); + packer = null; + cachedBackingStore = null; + cachedGraphics = null; + cachedFontRenderContext = null; + } + //---------------------------------------------------------------------- // Internals only below this point // @@ -466,7 +479,6 @@ public class TextRenderer { // store (i.e., non-default Paint, foreground color, etc.), but // for now, let's just be more efficient TextureRenderer renderer = TextureRenderer.createAlphaOnlyRenderer(w, h); - renderer.setSmoothing(false); return renderer; } diff --git a/src/classes/com/sun/opengl/util/j2d/TextureRenderer.java b/src/classes/com/sun/opengl/util/j2d/TextureRenderer.java index 360a82b25..976806db3 100755 --- a/src/classes/com/sun/opengl/util/j2d/TextureRenderer.java +++ b/src/classes/com/sun/opengl/util/j2d/TextureRenderer.java @@ -74,6 +74,7 @@ public class TextureRenderer { // Whether smoothing is enabled for the OpenGL texture (switching // between GL_LINEAR and GL_NEAREST filtering) private boolean smoothing = true; + private boolean smoothingChanged; // The backing store itself private BufferedImage image; @@ -179,24 +180,15 @@ public class TextureRenderer { /** Sets whether smoothing is enabled for the OpenGL texture; if so, uses GL_LINEAR interpolation for the minification and - magnification filters. Defaults to true. + magnification filters. Defaults to true. Changes to this setting + will not take effect until the next call to {@link + #beginOrthoRendering beginOrthoRendering}. @param smoothing whether smoothing is enabled for the OpenGL texture - @throws GLException If an OpenGL context is not current when this method is called */ - public void setSmoothing(boolean smoothing) throws GLException { + public void setSmoothing(boolean smoothing) { this.smoothing = smoothing; - // This can be set lazily - if (texture != null) { - GL gl = GLU.getCurrentGL(); - if (smoothing) { - texture.setTexParameteri(GL.GL_TEXTURE_MIN_FILTER, GL.GL_LINEAR); - texture.setTexParameteri(GL.GL_TEXTURE_MAG_FILTER, GL.GL_LINEAR); - } else { - texture.setTexParameteri(GL.GL_TEXTURE_MIN_FILTER, GL.GL_NEAREST); - texture.setTexParameteri(GL.GL_TEXTURE_MAG_FILTER, GL.GL_NEAREST); - } - } + smoothingChanged = true; } /** Returns whether smoothing is enabled for the OpenGL texture; see @@ -308,12 +300,25 @@ public class TextureRenderer { gl.glMatrixMode(GL.GL_MODELVIEW); gl.glPushMatrix(); gl.glLoadIdentity(); + gl.glMatrixMode(GL.GL_TEXTURE); + gl.glPushMatrix(); + gl.glLoadIdentity(); gl.glEnable(GL.GL_BLEND); gl.glBlendFunc(GL.GL_ONE, GL.GL_ONE_MINUS_SRC_ALPHA); Texture texture = getTexture(); texture.enable(); texture.bind(); gl.glTexEnvi(GL.GL_TEXTURE_ENV, GL.GL_TEXTURE_ENV_MODE, GL.GL_REPLACE); + if (smoothingChanged) { + smoothingChanged = false; + if (smoothing) { + texture.setTexParameteri(GL.GL_TEXTURE_MIN_FILTER, GL.GL_LINEAR); + texture.setTexParameteri(GL.GL_TEXTURE_MAG_FILTER, GL.GL_LINEAR); + } else { + texture.setTexParameteri(GL.GL_TEXTURE_MIN_FILTER, GL.GL_NEAREST); + texture.setTexParameteri(GL.GL_TEXTURE_MAG_FILTER, GL.GL_NEAREST); + } + } } /** Draws an orthographically projected rectangle containing all of @@ -388,6 +393,8 @@ public class TextureRenderer { gl.glPopMatrix(); gl.glMatrixMode(GL.GL_MODELVIEW); gl.glPopMatrix(); + gl.glMatrixMode(GL.GL_TEXTURE); + gl.glPopMatrix(); gl.glPopAttrib(); } |