diff options
author | Kenneth Russel <[email protected]> | 2007-01-06 00:43:17 +0000 |
---|---|---|
committer | Kenneth Russel <[email protected]> | 2007-01-06 00:43:17 +0000 |
commit | 62e346b4562371031ec4732b27ac80447e509946 (patch) | |
tree | cd00a9784a29a7bcd81efbf7ecfbf92ba6d93d60 /src | |
parent | de4c2584441a9972df8a0db3faaadb0d1d10970b (diff) |
With help from Chris Campbell, fixed incredibly stupid bug on my part
where the new Java 2D TextureRenderer was destroying and re-creating
the OpenGL texture every frame. This was why the Java 2D Overlay class
was so expensive, and why the TextRenderer wasn't as fast as it seemed
it should be. Fixed bugs in all of the Java 2D demos which were
covered up by this implicit sync, as well as in the TextRenderer class
itself where it was missing a key sync operation. Added code to the
Texture.updateSubImage() implementation to clip the incoming rectangle
to the bounds of the input data and texture, to keep OpenGL from
dropping almost-valid updates on the floor. Ran all of the Java 2D
integration demos to verify these fixes.
git-svn-id: file:///usr/local/projects/SUN/JOGL/git-svn/svn-server-sync/jogl/trunk@1071 232f8b59-042b-4e1e-8c03-345bb8c30851
Diffstat (limited to 'src')
-rwxr-xr-x | src/classes/com/sun/opengl/util/j2d/TextRenderer.java | 2 | ||||
-rwxr-xr-x | src/classes/com/sun/opengl/util/j2d/TextureRenderer.java | 8 | ||||
-rwxr-xr-x | src/classes/com/sun/opengl/util/texture/Texture.java | 38 |
3 files changed, 47 insertions, 1 deletions
diff --git a/src/classes/com/sun/opengl/util/j2d/TextRenderer.java b/src/classes/com/sun/opengl/util/j2d/TextRenderer.java index 75fc5ae70..e97c31173 100755 --- a/src/classes/com/sun/opengl/util/j2d/TextRenderer.java +++ b/src/classes/com/sun/opengl/util/j2d/TextRenderer.java @@ -310,6 +310,8 @@ public class TextRenderer { g.setColor(Color.WHITE); // Draw the string g.drawString(curStr, strx, stry); + // Sync to the OpenGL texture + getBackingStore().sync(rect.x(), rect.y(), rect.w(), rect.h()); } // OK, now draw the portion of the backing store to the screen diff --git a/src/classes/com/sun/opengl/util/j2d/TextureRenderer.java b/src/classes/com/sun/opengl/util/j2d/TextureRenderer.java index f758e4f6c..360a82b25 100755 --- a/src/classes/com/sun/opengl/util/j2d/TextureRenderer.java +++ b/src/classes/com/sun/opengl/util/j2d/TextureRenderer.java @@ -244,7 +244,12 @@ public class TextureRenderer { boolean canSkipUpdate = ensureTexture(); if (!canSkipUpdate) { - // Update specified region + // Update specified region. + // NOTE that because BufferedImage-based TextureDatas now don't + // do anything to their contents, the coordinate systems for + // OpenGL and Java 2D actually line up correctly for + // updateSubImage calls, so we don't need to do any argument + // conversion here (i.e., flipping the Y coordinate). texture.updateSubImage(textureData, 0, x, y, x, y, width, height); } } @@ -420,6 +425,7 @@ public class TextureRenderer { texture.dispose(); texture = null; } + mustReallocateTexture = false; } if (texture == null) { diff --git a/src/classes/com/sun/opengl/util/texture/Texture.java b/src/classes/com/sun/opengl/util/texture/Texture.java index d22aabc9a..68d8dffe6 100755 --- a/src/classes/com/sun/opengl/util/texture/Texture.java +++ b/src/classes/com/sun/opengl/util/texture/Texture.java @@ -744,6 +744,8 @@ public class Texture { gl.glBindTexture(newTarget, texID); int rowlen = data.getRowLength(); + int dataWidth = data.getWidth(); + int dataHeight = data.getHeight(); if (data.getMipmapData() != null) { // Compute the width, height and row length at the specified mipmap level // Note we do not support specification of the row length for @@ -751,11 +753,47 @@ public class Texture { for (int i = 0; i < mipmapLevel; i++) { width /= 2; height /= 2; + + dataWidth /= 2; + dataHeight /= 2; } rowlen = 0; buffer = data.getMipmapData()[mipmapLevel]; } + // Clip incoming rectangles to what is available both on this + // texture and in the incoming TextureData + if (srcx < 0) { + width += srcx; + srcx = 0; + } + if (srcy < 0) { + height += srcy; + srcy = 0; + } + // NOTE: not sure whether the following two are the correct thing to do + if (dstx < 0) { + width += dstx; + dstx = 0; + } + if (dsty < 0) { + height += dsty; + dsty = 0; + } + + if (srcx + width > dataWidth) { + width = dataWidth - srcx; + } + if (srcy + height > dataHeight) { + height = dataHeight - srcy; + } + if (dstx + width > texWidth) { + width = texWidth - dstx; + } + if (dsty + height > texHeight) { + height = texHeight - dsty; + } + checkCompressedTextureExtensions(data); if (data.isDataCompressed()) { |