aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoshua Slack <[email protected]>2013-04-07 14:06:45 -0700
committerJoshua Slack <[email protected]>2013-04-07 14:06:45 -0700
commitc4d2aeb67df31a889ea68c622f9cb2c5997f9cd9 (patch)
tree9f500298cd2cea84ca7191dc2da3a217b5fe6801
parent8c52dacf710f65965e14ed34550dfd495160f68a (diff)
parentb1541c30b828d2599cc23afccc41689a2b3d92a9 (diff)
Merge pull request #37 from gouessej/master
Switches to JOGL 2.0 RC11 post build 08
-rw-r--r--ardor3d-jogl/src/main/java/com/ardor3d/framework/jogl/CapsUtil.java15
-rw-r--r--ardor3d-jogl/src/main/java/com/ardor3d/framework/jogl/JoglCanvasRenderer.java3
-rw-r--r--ardor3d-jogl/src/main/java/com/ardor3d/image/util/jogl/JoglImageLoader.java203
-rw-r--r--ardor3d-jogl/src/main/java/com/ardor3d/renderer/jogl/JoglPbufferTextureRenderer.java3
-rw-r--r--pom.xml2
5 files changed, 157 insertions, 69 deletions
diff --git a/ardor3d-jogl/src/main/java/com/ardor3d/framework/jogl/CapsUtil.java b/ardor3d-jogl/src/main/java/com/ardor3d/framework/jogl/CapsUtil.java
index 8d4eca8..b74bea0 100644
--- a/ardor3d-jogl/src/main/java/com/ardor3d/framework/jogl/CapsUtil.java
+++ b/ardor3d-jogl/src/main/java/com/ardor3d/framework/jogl/CapsUtil.java
@@ -18,6 +18,19 @@ import com.ardor3d.util.Ardor3dException;
public class CapsUtil {
+ public static GLProfile getProfile() {
+ // tries to get the most capable profile, programmable or fixed, desktop or embedded, forward or backward
+ // compatible
+ GLProfile profile = GLProfile.getMaximum(true);
+ final boolean isForwardCompatible = (!profile.isGL4() && profile.isGL3() && !profile.isGL3bc())
+ || (profile.isGL4() && !profile.isGL4bc());
+ if (isForwardCompatible) {
+ // Ardor3D doesn't support forward compatible yet
+ profile = GLProfile.getMaxFixedFunc(true);
+ }
+ return profile;
+ }
+
public static GLCapabilities getCapsForSettings(final DisplaySettings settings) {
return getCapsForSettings(settings, true, false, false, false);
}
@@ -36,7 +49,7 @@ public class CapsUtil {
throw new Ardor3dException("Invalid pixel depth: " + settings.getColorDepth());
}
- final GLCapabilities caps = new GLCapabilities(GLProfile.getMaximum(true));
+ final GLCapabilities caps = new GLCapabilities(getProfile());
caps.setHardwareAccelerated(true);
caps.setDoubleBuffered(true);
caps.setAlphaBits(settings.getAlphaBits());
diff --git a/ardor3d-jogl/src/main/java/com/ardor3d/framework/jogl/JoglCanvasRenderer.java b/ardor3d-jogl/src/main/java/com/ardor3d/framework/jogl/JoglCanvasRenderer.java
index 7137ab6..da235c7 100644
--- a/ardor3d-jogl/src/main/java/com/ardor3d/framework/jogl/JoglCanvasRenderer.java
+++ b/ardor3d-jogl/src/main/java/com/ardor3d/framework/jogl/JoglCanvasRenderer.java
@@ -23,7 +23,6 @@ import javax.media.opengl.GL;
import javax.media.opengl.GLContext;
import javax.media.opengl.GLDrawableFactory;
import javax.media.opengl.GLException;
-import javax.media.opengl.GLProfile;
import com.ardor3d.annotation.MainThread;
import com.ardor3d.framework.CanvasRenderer;
@@ -129,7 +128,7 @@ public class JoglCanvasRenderer implements CanvasRenderer {
public void init(final DisplaySettings settings, final boolean doSwap) {
_doSwap = doSwap;
if (_context == null) {
- _context = GLDrawableFactory.getFactory(GLProfile.getMaximum(true)).createExternalGLContext();
+ _context = GLDrawableFactory.getFactory(CapsUtil.getProfile()).createExternalGLContext();
}
makeCurrentContext();
diff --git a/ardor3d-jogl/src/main/java/com/ardor3d/image/util/jogl/JoglImageLoader.java b/ardor3d-jogl/src/main/java/com/ardor3d/image/util/jogl/JoglImageLoader.java
index 33b6118..3446a27 100644
--- a/ardor3d-jogl/src/main/java/com/ardor3d/image/util/jogl/JoglImageLoader.java
+++ b/ardor3d-jogl/src/main/java/com/ardor3d/image/util/jogl/JoglImageLoader.java
@@ -14,17 +14,18 @@ import java.io.IOException;
import java.io.InputStream;
import java.nio.Buffer;
import java.nio.ByteBuffer;
+import java.nio.CharBuffer;
import java.nio.DoubleBuffer;
import java.nio.FloatBuffer;
import java.nio.IntBuffer;
import java.nio.LongBuffer;
import java.nio.ShortBuffer;
-import javax.media.opengl.GLProfile;
-
+import com.ardor3d.framework.jogl.CapsUtil;
import com.ardor3d.image.Image;
import com.ardor3d.image.PixelDataType;
import com.ardor3d.image.util.ImageLoader;
+import com.ardor3d.image.util.ImageLoaderUtil;
import com.ardor3d.scene.state.jogl.util.JoglTextureUtil;
import com.ardor3d.util.geom.BufferUtils;
import com.jogamp.common.nio.Buffers;
@@ -33,96 +34,170 @@ import com.jogamp.opengl.util.texture.TextureIO;
public class JoglImageLoader implements ImageLoader {
- // private static final Logger logger = Logger.getLogger(JoglImageLoader.class.getName());
-
private static boolean createOnHeap = false;
- private static final String[] supportedFormats = new String[] { TextureIO.DDS, TextureIO.GIF, TextureIO.JPG,
- TextureIO.JPG, TextureIO.PAM, TextureIO.PNG, TextureIO.PNG, TextureIO.PPM, TextureIO.SGI, TextureIO.TGA,
- TextureIO.TIFF };
+ private enum TYPE {
+ BYTE, SHORT, CHAR, INT, FLOAT, LONG, DOUBLE
+ };
+
+ private static final String[] supportedFormats = new String[] { "." + TextureIO.DDS.toUpperCase(),
+ "." + TextureIO.GIF.toUpperCase(), "." + TextureIO.JPG.toUpperCase(), "." + TextureIO.PAM.toUpperCase(),
+ "." + TextureIO.PNG.toUpperCase(), "." + TextureIO.PPM.toUpperCase(), "." + TextureIO.SGI.toUpperCase(),
+ "." + TextureIO.TGA.toUpperCase(), "." + TextureIO.TIFF.toUpperCase() };
public static String[] getSupportedFormats() {
return supportedFormats;
}
- public static void registerLoader() {}
+ public static void registerLoader() {
+ ImageLoaderUtil.registerHandler(new JoglImageLoader(), supportedFormats);
+ }
public JoglImageLoader() {}
@Override
public Image load(final InputStream is, final boolean flipped) throws IOException {
- final TextureData textureData = TextureIO.newTextureData(GLProfile.getMaximum(true), is, true, null);
+ final TextureData textureData = TextureIO.newTextureData(CapsUtil.getProfile(), is, true, null);
final Buffer textureDataBuffer = textureData.getBuffer();
final Image ardorImage = new Image();
-
- int dataSize = textureDataBuffer.capacity();
- if (textureDataBuffer instanceof ShortBuffer) {
- dataSize *= Buffers.SIZEOF_SHORT;
+ final TYPE bufferDataType;
+ if (textureDataBuffer instanceof ByteBuffer) {
+ bufferDataType = TYPE.BYTE;
} else {
- if (textureDataBuffer instanceof IntBuffer) {
- dataSize *= Buffers.SIZEOF_INT;
+ if (textureDataBuffer instanceof ShortBuffer) {
+ bufferDataType = TYPE.SHORT;
} else {
- if (textureDataBuffer instanceof LongBuffer) {
- dataSize *= Buffers.SIZEOF_LONG;
+ if (textureDataBuffer instanceof CharBuffer) {
+ bufferDataType = TYPE.CHAR;
} else {
- if (textureDataBuffer instanceof FloatBuffer) {
- dataSize *= Buffers.SIZEOF_FLOAT;
+ if (textureDataBuffer instanceof IntBuffer) {
+ bufferDataType = TYPE.INT;
} else {
- if (textureDataBuffer instanceof DoubleBuffer) {
- dataSize *= Buffers.SIZEOF_DOUBLE;
+ if (textureDataBuffer instanceof FloatBuffer) {
+ bufferDataType = TYPE.FLOAT;
+ } else {
+ if (textureDataBuffer instanceof LongBuffer) {
+ bufferDataType = TYPE.LONG;
+ } else {
+ if (textureDataBuffer instanceof DoubleBuffer) {
+ bufferDataType = TYPE.DOUBLE;
+ } else {
+ bufferDataType = null;
+ }
+ }
}
}
}
}
}
- final ByteBuffer scratch = createOnHeap ? BufferUtils.createByteBufferOnHeap(dataSize) : Buffers
- .newDirectByteBuffer(dataSize);
- if (textureDataBuffer instanceof ShortBuffer) {
- final ShortBuffer shortTextureDataBuffer = (ShortBuffer) textureDataBuffer;
- while (textureDataBuffer.hasRemaining()) {
- scratch.putShort(shortTextureDataBuffer.get());
- }
+ if (bufferDataType == null) {
+ throw new UnsupportedOperationException("Unknown buffer type " + textureDataBuffer.getClass().getName());
} else {
- if (textureDataBuffer instanceof IntBuffer) {
- final IntBuffer intTextureDataBuffer = (IntBuffer) textureDataBuffer;
- while (textureDataBuffer.hasRemaining()) {
- scratch.putInt(intTextureDataBuffer.get());
+ final int pixelComponentSize;
+ switch (bufferDataType) {
+ case BYTE:
+ pixelComponentSize = Buffers.SIZEOF_BYTE;
+ break;
+ case SHORT:
+ pixelComponentSize = Buffers.SIZEOF_SHORT;
+ break;
+ case CHAR:
+ pixelComponentSize = Buffers.SIZEOF_CHAR;
+ break;
+ case INT:
+ pixelComponentSize = Buffers.SIZEOF_INT;
+ break;
+ case FLOAT:
+ pixelComponentSize = Buffers.SIZEOF_FLOAT;
+ break;
+ case LONG:
+ pixelComponentSize = Buffers.SIZEOF_LONG;
+ break;
+ case DOUBLE:
+ pixelComponentSize = Buffers.SIZEOF_DOUBLE;
+ break;
+ default:
+ // it should never happen
+ pixelComponentSize = 0;
+ }
+ final int dataSize = textureDataBuffer.capacity() * pixelComponentSize;
+ final ByteBuffer scratch = createOnHeap ? BufferUtils.createByteBufferOnHeap(dataSize) : Buffers
+ .newDirectByteBuffer(dataSize);
+ if (flipped) {
+ final int bytesPerPixel = dataSize / (textureData.getWidth() * textureData.getHeight());
+ while (scratch.hasRemaining()) {
+ final int srcPixelIndex = scratch.position() / bytesPerPixel;
+ final int srcPixelComponentOffset = scratch.position() - (srcPixelIndex * bytesPerPixel);
+ // final int srcElementIndex = srcPixelIndex * bytesPerPixel + srcPixelComponentOffset;
+ final int srcColumnIndex = srcPixelIndex % textureData.getWidth();
+ final int scrRowIndex = (srcPixelIndex - srcColumnIndex) / textureData.getHeight();
+ final int dstColumnIndex = srcColumnIndex;
+ final int dstRowIndex = (textureData.getHeight() - 1) - scrRowIndex;
+ final int dstPixelIndex = dstRowIndex * textureData.getWidth() + dstColumnIndex;
+ final int dstPixelComponentOffset = srcPixelComponentOffset;
+ final int dstElementIndex = dstPixelIndex * bytesPerPixel + dstPixelComponentOffset;
+ switch (bufferDataType) {
+ case BYTE:
+ scratch.put(((ByteBuffer) textureDataBuffer).get(dstElementIndex));
+ break;
+ case SHORT:
+ scratch.putShort(((ShortBuffer) textureDataBuffer).get(dstElementIndex));
+ break;
+ case CHAR:
+ scratch.putChar(((CharBuffer) textureDataBuffer).get(dstElementIndex));
+ break;
+ case INT:
+ scratch.putInt(((IntBuffer) textureDataBuffer).get(dstElementIndex));
+ break;
+ case FLOAT:
+ scratch.putFloat(((FloatBuffer) textureDataBuffer).get(dstElementIndex));
+ break;
+ case LONG:
+ scratch.putLong(((LongBuffer) textureDataBuffer).get(dstElementIndex));
+ break;
+ case DOUBLE:
+ scratch.putDouble(((DoubleBuffer) textureDataBuffer).get(dstElementIndex));
+ break;
+ default:
+ // it should never happen
+ }
}
+
} else {
- if (textureDataBuffer instanceof LongBuffer) {
- final LongBuffer longTextureDataBuffer = (LongBuffer) textureDataBuffer;
- while (textureDataBuffer.hasRemaining()) {
- scratch.putLong(longTextureDataBuffer.get());
- }
- } else {
- if (textureDataBuffer instanceof FloatBuffer) {
- final FloatBuffer floatTextureDataBuffer = (FloatBuffer) textureDataBuffer;
- while (textureDataBuffer.hasRemaining()) {
- scratch.putFloat(floatTextureDataBuffer.get());
- }
- } else {
- if (textureDataBuffer instanceof DoubleBuffer) {
- final DoubleBuffer doubleTextureDataBuffer = (DoubleBuffer) textureDataBuffer;
- while (textureDataBuffer.hasRemaining()) {
- scratch.putDouble(doubleTextureDataBuffer.get());
- }
- } else {
- if (textureDataBuffer instanceof ByteBuffer) {
- scratch.put((ByteBuffer) textureDataBuffer);
- }
- }
- }
+ switch (bufferDataType) {
+ case BYTE:
+ scratch.put((ByteBuffer) textureDataBuffer);
+ break;
+ case SHORT:
+ scratch.asShortBuffer().put((ShortBuffer) textureDataBuffer);
+ break;
+ case CHAR:
+ scratch.asCharBuffer().put((CharBuffer) textureDataBuffer);
+ break;
+ case INT:
+ scratch.asIntBuffer().put((IntBuffer) textureDataBuffer);
+ break;
+ case FLOAT:
+ scratch.asFloatBuffer().put((FloatBuffer) textureDataBuffer);
+ case LONG:
+ scratch.asLongBuffer().put((LongBuffer) textureDataBuffer);
+ break;
+ case DOUBLE:
+ scratch.asDoubleBuffer().put((DoubleBuffer) textureDataBuffer);
+ break;
+ default:
+ // it should never happen
}
}
+ scratch.rewind();
+ textureDataBuffer.rewind();
+ ardorImage.setWidth(textureData.getWidth());
+ ardorImage.setHeight(textureData.getHeight());
+ ardorImage.setData(scratch);
+ ardorImage.setDataFormat(JoglTextureUtil.getImageDataFormat(textureData.getPixelFormat()));
+ // ardorImage.setDataType(JoglTextureUtil.getPixelDataType(textureData.getPixelType()));
+ ardorImage.setDataType(PixelDataType.UnsignedByte);
+ return ardorImage;
}
- scratch.rewind();
- textureDataBuffer.rewind();
- ardorImage.setWidth(textureData.getWidth());
- ardorImage.setHeight(textureData.getHeight());
- ardorImage.setData(scratch);
- ardorImage.setDataFormat(JoglTextureUtil.getImageDataFormat(textureData.getPixelFormat()));
- // ardorImage.setDataType(JoglTextureUtil.getPixelDataType(textureData.getPixelType()));
- ardorImage.setDataType(PixelDataType.UnsignedByte);
- return ardorImage;
}
}
diff --git a/ardor3d-jogl/src/main/java/com/ardor3d/renderer/jogl/JoglPbufferTextureRenderer.java b/ardor3d-jogl/src/main/java/com/ardor3d/renderer/jogl/JoglPbufferTextureRenderer.java
index 8cce557..cbdb2a3 100644
--- a/ardor3d-jogl/src/main/java/com/ardor3d/renderer/jogl/JoglPbufferTextureRenderer.java
+++ b/ardor3d-jogl/src/main/java/com/ardor3d/renderer/jogl/JoglPbufferTextureRenderer.java
@@ -24,6 +24,7 @@ import javax.media.opengl.GLProfile;
import com.ardor3d.framework.DisplaySettings;
import com.ardor3d.framework.Scene;
+import com.ardor3d.framework.jogl.CapsUtil;
import com.ardor3d.image.Texture;
import com.ardor3d.image.Texture.Type;
import com.ardor3d.renderer.AbstractPbufferTextureRenderer;
@@ -262,7 +263,7 @@ public class JoglPbufferTextureRenderer extends AbstractPbufferTextureRenderer {
}
// Make our GLPbuffer...
- final GLProfile profile = GLProfile.getMaximum(true);
+ final GLProfile profile = CapsUtil.getProfile();
final GLDrawableFactory fac = GLDrawableFactory.getFactory(profile);
final GLCapabilities caps = new GLCapabilities(profile);
caps.setHardwareAccelerated(true);
diff --git a/pom.xml b/pom.xml
index 7aaa75c..74fd4cd 100644
--- a/pom.xml
+++ b/pom.xml
@@ -110,7 +110,7 @@
<!-- these properties help simplify specifying some commonly occurring variables -->
<properties>
<lwjgl.version>2.8.4</lwjgl.version>
- <jogl.version>2.0-rc11post06</jogl.version>
+ <jogl.version>2.0.2-rc20130404</jogl.version>
<swt.version>3650</swt.version>
<osgi.project.version>0.9_SNAPSHOT</osgi.project.version>
</properties>