aboutsummaryrefslogtreecommitdiffstats
path: root/src/jogl/classes/com/jogamp/opengl
diff options
context:
space:
mode:
Diffstat (limited to 'src/jogl/classes/com/jogamp/opengl')
-rw-r--r--src/jogl/classes/com/jogamp/opengl/GLRendererQuirks.java13
-rw-r--r--src/jogl/classes/com/jogamp/opengl/util/ImmModeSink.java6
-rw-r--r--src/jogl/classes/com/jogamp/opengl/util/RandomTileRenderer.java23
-rw-r--r--src/jogl/classes/com/jogamp/opengl/util/TileRenderer.java95
-rw-r--r--src/jogl/classes/com/jogamp/opengl/util/TileRendererBase.java41
-rw-r--r--src/jogl/classes/com/jogamp/opengl/util/awt/AWTGLPixelBuffer.java39
6 files changed, 186 insertions, 31 deletions
diff --git a/src/jogl/classes/com/jogamp/opengl/GLRendererQuirks.java b/src/jogl/classes/com/jogamp/opengl/GLRendererQuirks.java
index 023a8a1aa..6ef1e0805 100644
--- a/src/jogl/classes/com/jogamp/opengl/GLRendererQuirks.java
+++ b/src/jogl/classes/com/jogamp/opengl/GLRendererQuirks.java
@@ -181,15 +181,22 @@ public class GLRendererQuirks {
*/
public static final int NoFullFBOSupport = 11;
-
+ /**
+ * GLSL is not compliant or even not stable (crash)
+ * <ul>
+ * <li>OSX < 10.7.0 (?) - NVidia Driver. Bug 818 @ https://jogamp.org/bugzilla/.</li>
+ * </ul>
+ */
+ public static final int GLSLNonCompliant = 12;
+
/** Number of quirks known. */
- public static final int COUNT = 12;
+ public static final int COUNT = 13;
private static final String[] _names = new String[] { "NoDoubleBufferedPBuffer", "NoDoubleBufferedBitmap", "NoSetSwapInterval",
"NoOffscreenBitmap", "NoSetSwapIntervalPostRetarget", "GLSLBuggyDiscard",
"GLNonCompliant", "GLFlushBeforeRelease", "DontCloseX11Display",
"NeedCurrCtx4ARBPixFmtQueries", "NeedCurrCtx4ARBCreateContext",
- "NoFullFBOSupport"
+ "NoFullFBOSupport", "GLSLNonCompliant"
};
private final int _bitmask;
diff --git a/src/jogl/classes/com/jogamp/opengl/util/ImmModeSink.java b/src/jogl/classes/com/jogamp/opengl/util/ImmModeSink.java
index dc96cb5f2..111e2509e 100644
--- a/src/jogl/classes/com/jogamp/opengl/util/ImmModeSink.java
+++ b/src/jogl/classes/com/jogamp/opengl/util/ImmModeSink.java
@@ -522,6 +522,10 @@ public class ImmModeSink {
gl.glDrawArrays(mode, 0, vElems);
}
} else {
+ // FIXME: Impl. VBO usage .. or unroll.
+ if( !gl.getContext().isCPUDataSourcingAvail() ) {
+ throw new GLException("CPU data sourcing n/a w/ "+gl.getContext());
+ }
final int type;
if(indices instanceof ByteBuffer) {
type = GL.GL_UNSIGNED_BYTE;
@@ -553,7 +557,7 @@ public class ImmModeSink {
}
}
} else {
- gl.glDrawElements(mode, idxLen, type, indices);
+ ((GL2ES1)gl).glDrawElements(mode, idxLen, type, indices);
// GL2: gl.glDrawRangeElements(mode, 0, idxLen-1, idxLen, type, indices);
}
}
diff --git a/src/jogl/classes/com/jogamp/opengl/util/RandomTileRenderer.java b/src/jogl/classes/com/jogamp/opengl/util/RandomTileRenderer.java
index 8fc7916c7..a2b7ba343 100644
--- a/src/jogl/classes/com/jogamp/opengl/util/RandomTileRenderer.java
+++ b/src/jogl/classes/com/jogamp/opengl/util/RandomTileRenderer.java
@@ -96,7 +96,28 @@ public class RandomTileRenderer extends TileRendererBase {
/**
* {@inheritDoc}
- * @throws IllegalStateException if image-size or tileRect has not been set
+ *
+ * <p>
+ * <i>end of tiling</i> is never reached w/ {@link RandomRileRenderer},
+ * i.e. method always returns false.
+ * </p>
+ */
+ @Override
+ public final boolean eot() { return false; }
+
+ /**
+ * {@inheritDoc}
+ *
+ * Reset internal states of {@link RandomTileRenderer} are: <i>none</i>.
+ */
+ @Override
+ public final void reset() { }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @throws IllegalStateException if {@link #setImageSize(int, int) image-size} has not been set or
+ * {@link #setTileRect(int, int, int, int) tile-rect} has not been set.
*/
@Override
public final void beginTile(GL gl) throws IllegalStateException, GLException {
diff --git a/src/jogl/classes/com/jogamp/opengl/util/TileRenderer.java b/src/jogl/classes/com/jogamp/opengl/util/TileRenderer.java
index f126eb7f5..deab8bc3e 100644
--- a/src/jogl/classes/com/jogamp/opengl/util/TileRenderer.java
+++ b/src/jogl/classes/com/jogamp/opengl/util/TileRenderer.java
@@ -101,7 +101,7 @@ public class TileRenderer extends TileRendererBase {
*/
public static final int TR_COLUMNS = 15;
/**
- * The current tile number. See {@link #getParam(int)}.
+ * The current tile number. Has value -1 if {@link #eot()}. See {@link #getParam(int)}.
*/
public static final int TR_CURRENT_TILE_NUM = 16;
/**
@@ -132,12 +132,13 @@ public class TileRenderer extends TileRendererBase {
private final Dimension tileSize = new Dimension(DEFAULT_TILE_WIDTH, DEFAULT_TILE_HEIGHT);
private final Dimension tileSizeNB = new Dimension(DEFAULT_TILE_WIDTH - 2 * DEFAULT_TILE_BORDER, DEFAULT_TILE_HEIGHT - 2 * DEFAULT_TILE_BORDER);
- protected Dimension imageClippingDim = null; // not set - default
+ private boolean isInit = false;
+ private Dimension imageClippingDim = null; // not set - default
private int tileBorder = DEFAULT_TILE_BORDER;
private int rowOrder = TR_BOTTOM_TO_TOP;
private int rows;
private int columns;
- private int currentTile = -1;
+ private int currentTile = 0;
private int currentRow;
private int currentColumn;
private int offsetX;
@@ -158,13 +159,25 @@ public class TileRenderer extends TileRendererBase {
}
/**
+ * {@inheritDoc}
+ * <p>
+ * Implementation {@link #reset()} internal states.
+ * </p>
+ */
+ @Override
+ public final void setImageSize(int width, int height) {
+ super.setImageSize(width, height);
+ reset();
+ }
+
+ /**
* Clips the image-size this tile-renderer iterates through,
* which can be retrieved via {@link #getClippedImageSize()}.
* <p>
* Original image-size stored in this tile-renderer is unmodified.
* </p>
* <p>
- * Method resets internal state and {@link #TR_ROWS} {@link #TR_COLUMNS} count.
+ * Implementation {@link #reset()} internal states.
* </p>
*
* @param width The image-clipping.width
@@ -178,7 +191,7 @@ public class TileRenderer extends TileRendererBase {
imageClippingDim.setWidth(width);
imageClippingDim.setHeight(height);
}
- setup();
+ reset();
}
/**
@@ -210,7 +223,7 @@ public class TileRenderer extends TileRendererBase {
* effective size of the tile depends on the border size, ie (
* width - 2*border ) * ( height - 2 * border )
* <p>
- * Method resets internal state and {@link #TR_ROWS} {@link #TR_COLUMNS} count.
+ * Implementation {@link #reset()} internal states.
* </p>
*
* @param width
@@ -236,7 +249,7 @@ public class TileRenderer extends TileRendererBase {
tileSize.setHeight( height );
tileSizeNB.setWidth( width - 2 * border );
tileSizeNB.setHeight( height - 2 * border );
- setup();
+ reset();
}
/**
@@ -251,32 +264,43 @@ public class TileRenderer extends TileRendererBase {
}
/**
- * Sets up the number of rows and columns needed
+ * {@inheritDoc}
+ *
+ * Reset internal states of {@link TileRenderer} are:
+ * <ul>
+ * <li>{@link #TR_ROWS}</li>
+ * <li>{@link #TR_COLUMNS}</li>
+ * <li>{@link #TR_CURRENT_COLUMN}</li>
+ * <li>{@link #TR_CURRENT_ROW}</li>
+ * <li>{@link #TR_CURRENT_TILE_NUM}</li>
+ * <li>{@link #TR_CURRENT_TILE_X_POS}</li>
+ * <li>{@link #TR_CURRENT_TILE_Y_POS}</li>
+ * <li>{@link #TR_CURRENT_TILE_WIDTH}</li>
+ * <li>{@link #TR_CURRENT_TILE_HEIGHT}</li>
+ *</ul>
*/
- private final void setup() throws IllegalStateException {
+ @Override
+ public final void reset() {
final DimensionImmutable clippedImageSize = getClippedImageSize();
columns = ( clippedImageSize.getWidth() + tileSizeNB.getWidth() - 1 ) / tileSizeNB.getWidth();
rows = ( clippedImageSize.getHeight() + tileSizeNB.getHeight() - 1 ) / tileSizeNB.getHeight();
+ currentRow = 0;
+ currentColumn = 0;
currentTile = 0;
currentTileXPos = 0;
currentTileYPos = 0;
currentTileWidth = 0;
currentTileHeight = 0;
- currentRow = 0;
- currentColumn = 0;
assert columns >= 0;
assert rows >= 0;
+
+ beginCalled = false;
+ isInit = true;
}
/* pp */ final int getCurrentTile() { return currentTile; }
- /**
- * Returns <code>true</code> if all tiles have been rendered or {@link #setup()}
- * has not been called, otherwise <code>false</code>.
- */
- public final boolean eot() { return 0 > currentTile; }
-
@Override
public final int getParam(int pname) {
switch (pname) {
@@ -341,16 +365,41 @@ public class TileRenderer extends TileRendererBase {
return 0 < imageSize.getWidth() && 0 < imageSize.getHeight();
}
+ /**
+ * {@inheritDoc}
+ *
+ * <p>
+ * <i>end of tiling</i> is reached w/ {@link TileRenderer}, if at least one of the following is true:
+ * <ul>
+ * <li>all tiles have been rendered, i.e. {@link #TR_CURRENT_TILE_NUM} is -1</li>
+ * <li>no tiles to render, i.e. {@link #TR_COLUMNS} or {@link #TR_ROWS} is 0</li>
+ * </ul>
+ * </p>
+ */
+ @Override
+ public final boolean eot() {
+ if ( !isInit ) { // ensure at least one reset-call
+ reset();
+ }
+ return 0 > currentTile || 0 >= columns*rows;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @throws IllegalStateException if {@link #setImageSize(int, int) image-size} has not been set or
+ * {@link #eot() end-of-tiling} has been reached.
+ */
@Override
public final void beginTile( GL gl ) throws IllegalStateException, GLException {
if( !isSetup() ) {
- throw new IllegalStateException("Image size has not been set");
+ throw new IllegalStateException("Image size has not been set: "+this);
}
- validateGL(gl);
- if (currentTile <= 0) {
- setup();
+ if ( eot() ) {
+ throw new IllegalStateException("EOT reached: "+this);
}
-
+ validateGL(gl);
+
/* which tile (by row and column) we're about to render */
if (rowOrder == TR_BOTTOM_TO_TOP) {
currentRow = currentTile / columns;
@@ -390,7 +439,7 @@ public class TileRenderer extends TileRendererBase {
gl.glViewport( 0, 0, tW, tH );
if( DEBUG ) {
- System.err.println("TileRenderer.begin.X: "+this.toString());
+ System.err.println("TileRenderer.begin: "+this.toString());
}
// Do not forget to issue:
diff --git a/src/jogl/classes/com/jogamp/opengl/util/TileRendererBase.java b/src/jogl/classes/com/jogamp/opengl/util/TileRendererBase.java
index f15c79f68..d6c36aa14 100644
--- a/src/jogl/classes/com/jogamp/opengl/util/TileRendererBase.java
+++ b/src/jogl/classes/com/jogamp/opengl/util/TileRendererBase.java
@@ -241,6 +241,7 @@ public abstract class TileRendererBase {
tileDetails(sb);
sb.append("], image[size "+imageSize+", buffer "+hashStr(imageBuffer)+"], glad["+
gladListenerCount+" listener, pre "+(null!=glEventListenerPre)+", post "+(null!=glEventListenerPost)+", preSwap "+gladRequiresPreSwap+"]");
+ sb.append(", isSetup "+isSetup());
return sb;
}
public String toString() {
@@ -284,7 +285,7 @@ public abstract class TileRendererBase {
* @param width The width of the final image
* @param height The height of the final image
*/
- public final void setImageSize(int width, int height) {
+ public void setImageSize(int width, int height) {
imageSize.setWidth(width);
imageSize.setHeight(height);
}
@@ -321,6 +322,27 @@ public abstract class TileRendererBase {
public abstract boolean isSetup();
/**
+ * Returns true if <i>end of tiling</i> has been reached, otherwise false.
+ * <p>
+ * <i>end of tiling</i> criteria is implementation specific and may never be reached.
+ * </p>
+ * <p>
+ * User needs to {@link #reset()} tiling after reaching <i>end of tiling</i>
+ * before calling {@link #beginTile(GL)} again.
+ * </p>
+ */
+ public abstract boolean eot();
+
+ /**
+ * Method resets implementation's internal state to <i>start of tiling</i>
+ * as required for {@link #beginTile(GL)} if {@link #eot() end of tiling} has been reached.
+ * <p>
+ * Implementation is a <i>nop</i> where {@link #eot() end of tiling} is never reached.
+ * </p>
+ */
+ public abstract void reset();
+
+ /**
* Begins rendering a tile.
* <p>
* This method modifies the viewport, see below.
@@ -351,10 +373,19 @@ public abstract class TileRendererBase {
* <p>
* User has to comply with the <a href="#glprequirement">GL profile requirement</a>.
* </p>
+ * <p>
+ * If {@link #eot() end of tiling} has been reached,
+ * user needs to {@link #reset()} tiling before calling this method.
+ * </p>
*
* @param gl The gl context
- * @throws IllegalStateException if image-size has not been set
+ * @throws IllegalStateException if {@link #setImageSize(int, int) image-size} is undefined,
+ * an {@link #isSetup() implementation related setup} has not be performed
+ * or {@ link #eot()} has been reached. See implementing classes.
* @throws GLException if {@link #setImageBuffer(GLPixelBuffer) image buffer} is used but <code>gl</code> instance is &lt; {@link GL2ES3}
+ * @see #isSetup()
+ * @see #eot()
+ * @see #reset()
*/
public abstract void beginTile(GL gl) throws IllegalStateException, GLException;
@@ -594,6 +625,12 @@ public abstract class TileRendererBase {
}
return;
}
+ if( eot() ) {
+ if( DEBUG ) {
+ System.err.println("TileRenderer.glel.display: EOT: "+TileRendererBase.this);
+ }
+ return;
+ }
final GL gl = drawable.getGL();
beginTile(gl);
diff --git a/src/jogl/classes/com/jogamp/opengl/util/awt/AWTGLPixelBuffer.java b/src/jogl/classes/com/jogamp/opengl/util/awt/AWTGLPixelBuffer.java
index 1f5bb6acc..9d2ef6572 100644
--- a/src/jogl/classes/com/jogamp/opengl/util/awt/AWTGLPixelBuffer.java
+++ b/src/jogl/classes/com/jogamp/opengl/util/awt/AWTGLPixelBuffer.java
@@ -28,7 +28,11 @@
package com.jogamp.opengl.util.awt;
import java.awt.image.BufferedImage;
+import java.awt.image.ColorModel;
+import java.awt.image.DataBuffer;
import java.awt.image.DataBufferInt;
+import java.awt.image.SinglePixelPackedSampleModel;
+import java.awt.image.WritableRaster;
import java.nio.Buffer;
import java.nio.IntBuffer;
@@ -36,7 +40,6 @@ import javax.media.opengl.GL;
import com.jogamp.common.nio.Buffers;
import com.jogamp.opengl.util.GLPixelBuffer;
-import com.jogamp.opengl.util.GLPixelBuffer.GLPixelAttributes;
/**
* AWT {@link GLPixelBuffer} backed by an {@link BufferedImage} of type
@@ -51,6 +54,10 @@ import com.jogamp.opengl.util.GLPixelBuffer.GLPixelAttributes;
* <p>
* See {@link AWTGLPixelBuffer#requiresNewBuffer(GL, int, int, int)} for {@link #allowRowStride} details.
* </p>
+ * <p>
+ * If using <code>allowRowStride == true</code>, user may needs to get the {@link #getAlignedImage(int, int) aligned image}
+ * since {@link #requiresNewBuffer(GL, int, int, int)} will allow different width in this case.
+ * </p>
*/
public class AWTGLPixelBuffer extends GLPixelBuffer {
public static final GLPixelAttributes awtPixelAttributesIntRGBA4 = new GLPixelAttributes(4, GL.GL_BGRA, GL.GL_UNSIGNED_BYTE);
@@ -60,6 +67,7 @@ public class AWTGLPixelBuffer extends GLPixelBuffer {
public final BufferedImage image;
/**
+ *
* @param pixelAttributes the desired {@link GLPixelAttributes}
* @param width in pixels
* @param height in pixels
@@ -68,6 +76,7 @@ public class AWTGLPixelBuffer extends GLPixelBuffer {
* @param image the AWT image
* @param buffer the backing array
* @param allowRowStride If <code>true</code>, allow row-stride, otherwise not. See {@link #requiresNewBuffer(GL, int, int, int)}.
+ * If <code>true</code>, user shall decide whether to use a {@link #getAlignedImage(int, int) width-aligned image}.
*/
public AWTGLPixelBuffer(GLPixelAttributes pixelAttributes, int width, int height, int depth, boolean pack, BufferedImage image,
Buffer buffer, boolean allowRowStride) {
@@ -81,6 +90,33 @@ public class AWTGLPixelBuffer extends GLPixelBuffer {
super.dispose();
}
+ /**
+ * Returns a width- and height-aligned image representation sharing data w/ {@link #image}.
+ * @param width
+ * @param height
+ * @return
+ * @throws IllegalArgumentException if requested size exceeds image size
+ */
+ public BufferedImage getAlignedImage(int width, int height) throws IllegalArgumentException {
+ if( width * height > image.getWidth() * image.getHeight() ) {
+ throw new IllegalArgumentException("Requested size exceeds image size: "+width+"x"+height+" > "+image.getWidth()+"x"+image.getHeight());
+ }
+ if( width == image.getWidth() ) {
+ if( height == image.getHeight() ) {
+ return image;
+ }
+ return image.getSubimage(0, 0, width, height);
+ }
+ final ColorModel cm = image.getColorModel();
+ final WritableRaster raster = image.getRaster();
+ final DataBuffer dataBuffer = raster.getDataBuffer();
+ final SinglePixelPackedSampleModel sppsm0 = (SinglePixelPackedSampleModel) raster.getSampleModel();
+ final SinglePixelPackedSampleModel sppsm1 = new SinglePixelPackedSampleModel(dataBuffer.getDataType(),
+ width, height, width /* scanLineStride */, sppsm0.getBitMasks());
+ final WritableRaster raster1 = WritableRaster.createWritableRaster(sppsm1, dataBuffer, null);
+ return new BufferedImage (cm, raster1, cm.isAlphaPremultiplied(), null);
+ }
+
public StringBuilder toString(StringBuilder sb) {
sb = super.toString(sb);
sb.append(", allowRowStride ").append(allowRowStride).append(", image [").append(image.getWidth()).append("x").append(image.getHeight()).append(", ").append(image.toString()).append("]");
@@ -99,6 +135,7 @@ public class AWTGLPixelBuffer extends GLPixelBuffer {
/**
* @param allowRowStride If <code>true</code>, allow row-stride, otherwise not.
* See {@link #getAllowRowStride()} and {@link AWTGLPixelBuffer#requiresNewBuffer(GL, int, int, int)}.
+ * If <code>true</code>, user shall decide whether to use a {@link AWTGLPixelBuffer#getAlignedImage(int, int) width-aligned image}.
*/
public AWTGLPixelBufferProvider(boolean allowRowStride) {
this.allowRowStride = allowRowStride;