aboutsummaryrefslogtreecommitdiffstats
path: root/src/jogl
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2013-09-13 19:47:12 +0200
committerSven Gothel <[email protected]>2013-09-13 19:47:12 +0200
commit52f348c1a58e12c16bea87cf6951be344b8663ed (patch)
tree702e736dae4938833ebb0d6d7b1f37f7a7f84b0c /src/jogl
parent77196201f7e9ae3ceed493fb025264c90ed9a554 (diff)
AWTTilePainter: Fix null clip-rect (consider scaling); Fix non GL-oriented drawable, skip vertical flip and use 1:1 y-coord.
Diffstat (limited to 'src/jogl')
-rw-r--r--src/jogl/classes/javax/media/opengl/awt/GLCanvas.java2
-rw-r--r--src/jogl/classes/javax/media/opengl/awt/GLJPanel.java1
-rw-r--r--src/jogl/classes/jogamp/opengl/awt/AWTTilePainter.java86
3 files changed, 57 insertions, 32 deletions
diff --git a/src/jogl/classes/javax/media/opengl/awt/GLCanvas.java b/src/jogl/classes/javax/media/opengl/awt/GLCanvas.java
index 23898ba8c..4e0fdba5d 100644
--- a/src/jogl/classes/javax/media/opengl/awt/GLCanvas.java
+++ b/src/jogl/classes/javax/media/opengl/awt/GLCanvas.java
@@ -791,7 +791,7 @@ public class GLCanvas extends Canvas implements AWTGLAutoDrawable, WindowClosing
printGLAD = factory.createOffscreenAutoDrawable(null, caps, null, DEFAULT_PRINT_TILE_SIZE, DEFAULT_PRINT_TILE_SIZE, null);
GLDrawableUtil.swapGLContextAndAllGLEventListener(GLCanvas.this, printGLAD);
}
-
+ printAWTTiles.setIsGLOriented(printGLAD.isGLOriented());
printAWTTiles.renderer.setTileSize(printGLAD.getWidth(), printGLAD.getHeight(), 0);
printAWTTiles.renderer.attachToAutoDrawable(printGLAD);
if( DEBUG ) {
diff --git a/src/jogl/classes/javax/media/opengl/awt/GLJPanel.java b/src/jogl/classes/javax/media/opengl/awt/GLJPanel.java
index 84e3c39b4..02f4e54a7 100644
--- a/src/jogl/classes/javax/media/opengl/awt/GLJPanel.java
+++ b/src/jogl/classes/javax/media/opengl/awt/GLJPanel.java
@@ -564,6 +564,7 @@ public class GLJPanel extends JPanel implements AWTGLAutoDrawable, WindowClosing
GLDrawableUtil.swapGLContextAndAllGLEventListener(GLJPanel.this, printGLAD);
}
}
+ printAWTTiles.setIsGLOriented(printGLAD.isGLOriented());
printAWTTiles.renderer.setTileSize(printGLAD.getWidth(), printGLAD.getHeight(), 0);
printAWTTiles.renderer.attachToAutoDrawable(printGLAD);
if( DEBUG ) {
diff --git a/src/jogl/classes/jogamp/opengl/awt/AWTTilePainter.java b/src/jogl/classes/jogamp/opengl/awt/AWTTilePainter.java
index d316a6523..0ff733457 100644
--- a/src/jogl/classes/jogamp/opengl/awt/AWTTilePainter.java
+++ b/src/jogl/classes/jogamp/opengl/awt/AWTTilePainter.java
@@ -61,6 +61,7 @@ public class AWTTilePainter {
public final double scaleMatX, scaleMatY;
public final boolean verbose;
+ public boolean flipVertical;
private AWTGLPixelBuffer tBuffer = null;
private BufferedImage vFlipImage = null;
private Graphics2D g2d = null;
@@ -102,11 +103,16 @@ public class AWTTilePainter {
this.scaleMatX = scaleMatX;
this.scaleMatY = scaleMatY;
this.verbose = verbose;
+ this.flipVertical = true;
this.renderer.setRowOrder(TileRenderer.TR_TOP_TO_BOTTOM);
}
public String toString() { return renderer.toString(); }
+ public void setIsGLOriented(boolean v) {
+ flipVertical = v;
+ }
+
/**
* Caches the {@link Graphics2D} instance for rendering.
* <p>
@@ -126,23 +132,30 @@ public class AWTTilePainter {
public void setupGraphics2DAndClipBounds(Graphics2D g2d, int width, int height) {
this.g2d = g2d;
saveAT = g2d.getTransform();
+ final Rectangle gClipOrig = g2d.getClipBounds();
+ if( null == gClipOrig ) {
+ g2d.setClip(0, 0, width, height);
+ }
g2d.scale(scaleMatX, scaleMatY);
- final Rectangle gClipOrig = g2d.getClipBounds();
- final Rectangle gClip = null == gClipOrig ? new Rectangle(0, 0, width, height) : new Rectangle(gClipOrig);
- if( 0 > gClip.x ) {
- gClip.width += gClip.x;
- gClip.x = 0;
+ final Rectangle gClipScaled = g2d.getClipBounds();
+ if( 0 > gClipScaled.x ) {
+ gClipScaled.width += gClipScaled.x;
+ gClipScaled.x = 0;
}
- if( 0 > gClip.y ) {
- gClip.height += gClip.y;
- gClip.y = 0;
+ if( 0 > gClipScaled.y ) {
+ gClipScaled.height += gClipScaled.y;
+ gClipScaled.y = 0;
}
if( verbose ) {
- System.err.println("AWT print.0: "+gClipOrig+" -> "+gClip);
+ System.err.println("AWT print.0: "+gClipOrig+" -> "+gClipScaled);
+ }
+ renderer.setImageSize(gClipScaled.width, gClipScaled.height);
+ renderer.setTileOffset(gClipScaled.x, gClipScaled.y);
+ if( null == gClipOrig ) {
+ // reset
+ g2d.setClip(null);
}
- renderer.setImageSize(gClip.width, gClip.height);
- renderer.setTileOffset(gClip.x, gClip.y);
}
/** See {@ #setupGraphics2DAndClipBounds(Graphics2D)}. */
@@ -169,8 +182,7 @@ public class AWTTilePainter {
final GLEventListener preTileGLEL = new GLEventListener() {
@Override
- public void init(GLAutoDrawable drawable) {
- }
+ public void init(GLAutoDrawable drawable) {}
@Override
public void dispose(GLAutoDrawable drawable) {}
@Override
@@ -183,7 +195,11 @@ public class AWTTilePainter {
final GLPixelAttributes pixelAttribs = printBufferProvider.getAttributes(gl, componentCount);
tBuffer = printBufferProvider.allocate(gl, pixelAttribs, tWidth, tHeight, 1, true, 0);
renderer.setTileBuffer(tBuffer);
- vFlipImage = new BufferedImage(tBuffer.width, tBuffer.height, tBuffer.image.getType());
+ if( flipVertical ) {
+ vFlipImage = new BufferedImage(tBuffer.width, tBuffer.height, tBuffer.image.getType());
+ } else {
+ vFlipImage = null;
+ }
}
if( verbose ) {
System.err.println("XXX tile-pre "+renderer);
@@ -208,29 +224,37 @@ public class AWTTilePainter {
// but that's the software rendering path which is very slow anyway.
final int tWidth = renderer.getParam(TileRendererBase.TR_CURRENT_TILE_WIDTH);
final int tHeight = renderer.getParam(TileRendererBase.TR_CURRENT_TILE_HEIGHT);
- // final BufferedImage dstImage = printBuffer.image;
- final BufferedImage srcImage = tBuffer.image;
- final BufferedImage dstImage = vFlipImage;
- final int[] src = ((DataBufferInt) srcImage.getRaster().getDataBuffer()).getData();
- final int[] dst = ((DataBufferInt) dstImage.getRaster().getDataBuffer()).getData();
- final int incr = tBuffer.width;
- int srcPos = 0;
- int destPos = (tHeight - 1) * tBuffer.width;
- for (; destPos >= 0; srcPos += incr, destPos -= incr) {
- System.arraycopy(src, srcPos, dst, destPos, incr);
+ final BufferedImage dstImage;
+ if( flipVertical ) {
+ final BufferedImage srcImage = tBuffer.image;
+ dstImage = vFlipImage;
+ final int[] src = ((DataBufferInt) srcImage.getRaster().getDataBuffer()).getData();
+ final int[] dst = ((DataBufferInt) dstImage.getRaster().getDataBuffer()).getData();
+ final int incr = tBuffer.width;
+ int srcPos = 0;
+ int destPos = (tHeight - 1) * tBuffer.width;
+ for (; destPos >= 0; srcPos += incr, destPos -= incr) {
+ System.arraycopy(src, srcPos, dst, destPos, incr);
+ }
+ } else {
+ dstImage = tBuffer.image;
}
// Draw resulting image in one shot
final int tRows = renderer.getParam(TileRenderer.TR_ROWS);
final int tRow = renderer.getParam(TileRenderer.TR_CURRENT_ROW);
final int pX = renderer.getParam(TileRendererBase.TR_CURRENT_TILE_X_POS);
final int pYf;
- if( tRow == tRows - 1 ) {
- tTopRowHeight = tHeight;
- pYf = 0;
- } else if( tRow == tRows - 2 ){
- pYf = tTopRowHeight;
+ if( flipVertical ) {
+ if( tRow == tRows - 1 ) {
+ tTopRowHeight = tHeight;
+ pYf = 0;
+ } else if( tRow == tRows - 2 ){
+ pYf = tTopRowHeight;
+ } else {
+ pYf = ( tRows - 2 - tRow ) * tHeight + tTopRowHeight;
+ }
} else {
- pYf = ( tRows - 2 - tRow ) * tHeight + tTopRowHeight;
+ pYf = renderer.getParam(TileRendererBase.TR_CURRENT_TILE_Y_POS);
}
final Shape oClip = g2d.getClip();
g2d.clipRect(pX, pYf, tWidth, tHeight);
@@ -245,7 +269,7 @@ public class AWTTilePainter {
g2d.drawRect(r.x, r.y, r.width, r.height);
}
System.err.println("XXX tile-post.X "+renderer);
- System.err.println("XXX tile-post.X dst-img "+dstImage.getWidth()+"x"+dstImage.getHeight()+" -> "+pX+"/"+pYf);
+ System.err.println("XXX tile-post.X dst-img "+dstImage.getWidth()+"x"+dstImage.getHeight()+", y-flip "+flipVertical+" -> "+pX+"/"+pYf);
}
g2d.setClip(oClip);
}