diff options
author | Kenneth Russel <[email protected]> | 2007-03-27 05:38:50 +0000 |
---|---|---|
committer | Kenneth Russel <[email protected]> | 2007-03-27 05:38:50 +0000 |
commit | 2328bf37e95371c74a8d102dfd462cdf6e1df10d (patch) | |
tree | 4636f6013298f05230e7c032e86c74a0818820cd /src/classes/com | |
parent | 03be3bd1c7c33667518e618350ac75f545d2b84b (diff) |
Added a markDirty() method to TextureRenderer and removed the sync()
method. markDirty() may be called at an arbitrary point (in
particular, when no OpenGL context is current) and the union of the
dirty regions is automatically synced with the underlying texture
during the next getTexture() operation, at which point the dirty
region is cleared. Adjusted Overlay and TextRenderer classes.
git-svn-id: file:///usr/local/projects/SUN/JOGL/git-svn/svn-server-sync/jogl/trunk@1182 232f8b59-042b-4e1e-8c03-345bb8c30851
Diffstat (limited to 'src/classes/com')
-rwxr-xr-x | src/classes/com/sun/opengl/util/j2d/Overlay.java | 12 | ||||
-rwxr-xr-x | src/classes/com/sun/opengl/util/j2d/TextRenderer.java | 8 | ||||
-rwxr-xr-x | src/classes/com/sun/opengl/util/j2d/TextureRenderer.java | 67 |
3 files changed, 62 insertions, 25 deletions
diff --git a/src/classes/com/sun/opengl/util/j2d/Overlay.java b/src/classes/com/sun/opengl/util/j2d/Overlay.java index 822f0d74b..7e9caf477 100755 --- a/src/classes/com/sun/opengl/util/j2d/Overlay.java +++ b/src/classes/com/sun/opengl/util/j2d/Overlay.java @@ -89,8 +89,12 @@ public class Overlay { return contentsLost; } - /** Synchronizes the contents of the Java 2D rendering down to the - OpenGL texture. + /** Marks the given region of the overlay as dirty. This region, and + any previously set dirty regions, will be automatically + synchronized with the underlying Texture during the next {@link + #getTexture getTexture} operation, at which point the dirty + region will be cleared. It is not necessary for an OpenGL + context to be current when this method is called. @param x the x coordinate (in Java 2D coordinates -- relative to upper left) of the region to update @@ -101,8 +105,8 @@ public class Overlay { @throws GLException If an OpenGL context is not current when this method is called */ - public void sync(int x, int y, int width, int height) throws GLException { - renderer.sync(x, y, width, height); + public void markDirty(int x, int y, int width, int height) { + renderer.markDirty(x, y, width, height); } /** Draws the entire contents of the overlay on top of the OpenGL diff --git a/src/classes/com/sun/opengl/util/j2d/TextRenderer.java b/src/classes/com/sun/opengl/util/j2d/TextRenderer.java index e07935690..d25888be2 100755 --- a/src/classes/com/sun/opengl/util/j2d/TextRenderer.java +++ b/src/classes/com/sun/opengl/util/j2d/TextRenderer.java @@ -488,8 +488,8 @@ public class TextRenderer { g.setComposite(AlphaComposite.Src); // Draw the string renderDelegate.draw(g, curStr, strx, stry); - // Sync to the OpenGL texture - getBackingStore().sync(rect.x(), rect.y(), rect.w(), rect.h()); + // Mark this region of the TextureRenderer as dirty + getBackingStore().markDirty(rect.x(), rect.y(), rect.w(), rect.h()); } // OK, now draw the portion of the backing store to the screen @@ -728,7 +728,7 @@ public class TextRenderer { } if (DEBUG) { - getBackingStore().sync(0, 0, getBackingStore().getWidth(), getBackingStore().getHeight()); + getBackingStore().markDirty(0, 0, getBackingStore().getWidth(), getBackingStore().getHeight()); } } @@ -835,7 +835,7 @@ public class TextRenderer { g.dispose(); // Sync the whole surface TextureRenderer newRenderer = (TextureRenderer) newBackingStore; - newRenderer.sync(0, 0, newRenderer.getWidth(), newRenderer.getHeight()); + newRenderer.markDirty(0, 0, newRenderer.getWidth(), newRenderer.getHeight()); // Re-enter the begin / end pair if necessary if (inBeginEndPair) { if (isOrthoMode) { diff --git a/src/classes/com/sun/opengl/util/j2d/TextureRenderer.java b/src/classes/com/sun/opengl/util/j2d/TextureRenderer.java index 82ebdc5a1..be4b8b629 100755 --- a/src/classes/com/sun/opengl/util/j2d/TextureRenderer.java +++ b/src/classes/com/sun/opengl/util/j2d/TextureRenderer.java @@ -43,6 +43,7 @@ import java.awt.Color; import java.awt.Dimension; import java.awt.Graphics2D; import java.awt.Image; +import java.awt.Rectangle; import java.awt.image.*; import javax.media.opengl.*; @@ -83,6 +84,7 @@ public class TextureRenderer { private Texture texture; private TextureData textureData; private boolean mustReallocateTexture; + private Rectangle dirtyRegion; private GLU glu = new GLU(); @@ -226,8 +228,12 @@ public class TextureRenderer { return image; } - /** Synchronizes the specified region of the backing store down to - the underlying OpenGL texture. + /** Marks the given region of the TextureRenderer as dirty. This + region, and any previously set dirty regions, will be + automatically synchronized with the underlying Texture during + the next {@link #getTexture getTexture} operation, at which + point the dirty region will be cleared. It is not necessary for + an OpenGL context to be current when this method is called. @param x the x coordinate (in Java 2D coordinates -- relative to upper left) of the region to update @@ -235,30 +241,28 @@ public class TextureRenderer { upper left) of the region to update @param width the width of the region to update @param height the height of the region to update - - @throws GLException If an OpenGL context is not current when this method is called */ - public void sync(int x, int y, int width, int height) throws GLException { - // Force allocation if necessary - boolean canSkipUpdate = ensureTexture(); - - if (!canSkipUpdate) { - // 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); + public void markDirty(int x, int y, int width, int height) { + Rectangle curRegion = new Rectangle(x, y, width, height); + if (dirtyRegion == null) { + dirtyRegion = curRegion; + } else { + dirtyRegion.add(curRegion); } } /** Returns the underlying OpenGL Texture object associated with - this renderer. + this renderer, synchronizing any dirty regions of the + TextureRenderer with the underlying OpenGL texture. @throws GLException If an OpenGL context is not current when this method is called */ public Texture getTexture() throws GLException { + if (dirtyRegion != null) { + sync(dirtyRegion.x, dirtyRegion.y, dirtyRegion.width, dirtyRegion.height); + dirtyRegion = null; + } + ensureTexture(); return texture; } @@ -585,6 +589,35 @@ public class TextureRenderer { mustReallocateTexture = true; } + /** Synchronizes the specified region of the backing store down to + the underlying OpenGL texture. If {@link #markDirty markDirty} + is used instead to indicate the regions that are out of sync, + this method does not need to be called. + + @param x the x coordinate (in Java 2D coordinates -- relative to + upper left) of the region to update + @param y the y coordinate (in Java 2D coordinates -- relative to + upper left) of the region to update + @param width the width of the region to update + @param height the height of the region to update + + @throws GLException If an OpenGL context is not current when this method is called + */ + private void sync(int x, int y, int width, int height) throws GLException { + // Force allocation if necessary + boolean canSkipUpdate = ensureTexture(); + + if (!canSkipUpdate) { + // 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); + } + } + // Returns true if the texture was newly allocated, false if not private boolean ensureTexture() { if (mustReallocateTexture) { |