diff options
author | Julien Gouesse <[email protected]> | 2014-01-30 22:32:25 +0100 |
---|---|---|
committer | Julien Gouesse <[email protected]> | 2014-01-30 22:32:25 +0100 |
commit | 50a24b65a5ef5e68d22df540fac349ad698dc129 (patch) | |
tree | 5f4ee3bc3c57ce56935cc787d0cce860b68ccb5c | |
parent | e7135433bc0623f838186f27dee81148e8e063fa (diff) |
Adds a method to convert JOGL/NEWT texture data into Ardor3D images
-rw-r--r-- | ardor3d-jogl/src/main/java/com/ardor3d/image/util/jogl/JoglImageLoader.java | 31 |
1 files changed, 23 insertions, 8 deletions
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 d3b87a1..15164a9 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 @@ -36,7 +36,7 @@ public class JoglImageLoader implements ImageLoader { public static boolean createOnHeap = false; - protected CapsUtil _capsUtil; + protected final CapsUtil _capsUtil; private enum TYPE { BYTE(ByteBuffer.class), SHORT(ShortBuffer.class), CHAR(CharBuffer.class), INT(IntBuffer.class), FLOAT( @@ -49,26 +49,32 @@ public class JoglImageLoader implements ImageLoader { } }; - private static final String[] supportedFormats = new String[] { "." + TextureIO.DDS.toUpperCase(), + 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; + return _supportedFormats; } public static void registerLoader() { - ImageLoaderUtil.registerHandler(new JoglImageLoader(), supportedFormats); + registerLoader(new JoglImageLoader(), _supportedFormats); + } + + public static void registerLoader(final JoglImageLoader joglImageLoader, final String[] supportedFormats) { + ImageLoaderUtil.registerHandler(joglImageLoader, supportedFormats); } public JoglImageLoader() { - _capsUtil = new CapsUtil(); + this(new CapsUtil()); } - @Override - public Image load(final InputStream is, final boolean flipped) throws IOException { - final TextureData textureData = TextureIO.newTextureData(_capsUtil.getProfile(), is, true, null); + public JoglImageLoader(final CapsUtil capsUtil) { + _capsUtil = capsUtil; + } + + public Image makeArdor3dImage(final TextureData textureData, final boolean flipped) { final Buffer textureDataBuffer = textureData.getBuffer(); final Image ardorImage = new Image(); final TYPE bufferDataType = getBufferDataType(textureDataBuffer); @@ -94,6 +100,15 @@ public class JoglImageLoader implements ImageLoader { } } + @Override + public Image load(final InputStream is, final boolean flipped) throws IOException { + final TextureData textureData = TextureIO.newTextureData(_capsUtil.getProfile(), is, true, null); + if (textureData == null) { + return null; + } + return makeArdor3dImage(textureData, flipped); + } + private TYPE getBufferDataType(final Buffer buffer) { TYPE bufferDataType = null; for (final TYPE type : TYPE.values()) { |