diff options
Diffstat (limited to 'src/jogl/classes')
4 files changed, 54 insertions, 46 deletions
diff --git a/src/jogl/classes/com/jogamp/opengl/util/texture/Texture.java b/src/jogl/classes/com/jogamp/opengl/util/texture/Texture.java index 01c8db09d..208fd053d 100644 --- a/src/jogl/classes/com/jogamp/opengl/util/texture/Texture.java +++ b/src/jogl/classes/com/jogamp/opengl/util/texture/Texture.java @@ -434,7 +434,7 @@ public class Texture { * * @throws GLException if any OpenGL-related errors occurred */ - public void updateImage(GL gl, TextureData data, int target) throws GLException { + public void updateImage(GL gl, TextureData data, int targetOverride) throws GLException { validateTexID(gl, true); imgWidth = data.getWidth(); @@ -553,10 +553,10 @@ public class Texture { texParamTarget = texTarget; setImageSize(imgWidth, imgHeight, texTarget); - if (target != 0) { + if (targetOverride != 0) { // Allow user to override auto detection and skip bind step (for // cubemap construction) - texTarget = target; + texTarget = targetOverride; if (this.target == 0) { throw new GLException("Override of target failed; no target specified yet"); } diff --git a/src/jogl/classes/com/jogamp/opengl/util/texture/TextureIO.java b/src/jogl/classes/com/jogamp/opengl/util/texture/TextureIO.java index b89daffc9..89d840ac7 100644 --- a/src/jogl/classes/com/jogamp/opengl/util/texture/TextureIO.java +++ b/src/jogl/classes/com/jogamp/opengl/util/texture/TextureIO.java @@ -424,7 +424,7 @@ public class TextureIO { /** * Creates an OpenGL texture object from the specified TextureData - * using the current OpenGL context. + * using the given OpenGL context. * * @param data the texture data to turn into an OpenGL texture * @throws GLException if no OpenGL context is current or if an @@ -608,10 +608,10 @@ public class TextureIO { // First fetch the texture data GL _gl = GLContext.getCurrentGL(); - if (!_gl.isGL2()) { - throw new GLException("Only GL2 supports fetching compressed images, GL: " + _gl); + if (!_gl.isGL2GL3()) { + throw new GLException("Implementation only supports GL2GL3 (Use GLReadBufferUtil and the TextureData variant), have: " + _gl); } - GL2 gl = _gl.getGL2(); + GL2GL3 gl = _gl.getGL2(); texture.bind(gl); int internalFormat = glGetTexLevelParameteri(gl, GL.GL_TEXTURE_2D, 0, GL2.GL_TEXTURE_INTERNAL_FORMAT); @@ -651,11 +651,11 @@ public class TextureIO { } // Fetch using glGetTexImage - int packAlignment = glGetInteger(GL.GL_PACK_ALIGNMENT); - int packRowLength = glGetInteger(GL2.GL_PACK_ROW_LENGTH); - int packSkipRows = glGetInteger(GL2.GL_PACK_SKIP_ROWS); - int packSkipPixels = glGetInteger(GL2.GL_PACK_SKIP_PIXELS); - int packSwapBytes = glGetInteger(GL2.GL_PACK_SWAP_BYTES); + int packAlignment = glGetInteger(gl, GL.GL_PACK_ALIGNMENT); + int packRowLength = glGetInteger(gl, GL2.GL_PACK_ROW_LENGTH); + int packSkipRows = glGetInteger(gl, GL2.GL_PACK_SKIP_ROWS); + int packSkipPixels = glGetInteger(gl, GL2.GL_PACK_SKIP_PIXELS); + int packSwapBytes = glGetInteger(gl, GL2.GL_PACK_SWAP_BYTES); gl.glPixelStorei(GL.GL_PACK_ALIGNMENT, 1); gl.glPixelStorei(GL2.GL_PACK_ROW_LENGTH, 0); @@ -691,8 +691,8 @@ public class TextureIO { } public static void write(TextureData data, File file) throws IOException, GLException { - for (Iterator iter = textureWriters.iterator(); iter.hasNext(); ) { - TextureWriter writer = (TextureWriter) iter.next(); + for (Iterator<TextureWriter> iter = textureWriters.iterator(); iter.hasNext(); ) { + TextureWriter writer = iter.next(); if (writer.write(file, data)) { return; } @@ -756,8 +756,8 @@ public class TextureIO { // Internals only below this point // - private static List/*<TextureProvider>*/ textureProviders = new ArrayList/*<TextureProvider>*/(); - private static List/*<TextureWriter>*/ textureWriters = new ArrayList/*<TextureWriter>*/(); + private static List<TextureProvider> textureProviders = new ArrayList<TextureProvider>(); + private static List<TextureWriter> textureWriters = new ArrayList<TextureWriter>(); static { // ImageIO provider, the fall-back, must be the first one added @@ -816,8 +816,8 @@ public class TextureIO { fileSuffix = toLowerCase(fileSuffix); - for (Iterator iter = textureProviders.iterator(); iter.hasNext(); ) { - TextureProvider provider = (TextureProvider) iter.next(); + for (Iterator<TextureProvider> iter = textureProviders.iterator(); iter.hasNext(); ) { + TextureProvider provider = iter.next(); TextureData data = provider.newTextureData(glp, file, internalFormat, pixelFormat, @@ -847,8 +847,8 @@ public class TextureIO { stream = new BufferedInputStream(stream); } - for (Iterator iter = textureProviders.iterator(); iter.hasNext(); ) { - TextureProvider provider = (TextureProvider) iter.next(); + for (Iterator<TextureProvider> iter = textureProviders.iterator(); iter.hasNext(); ) { + TextureProvider provider = iter.next(); TextureData data = provider.newTextureData(glp, stream, internalFormat, pixelFormat, @@ -873,8 +873,8 @@ public class TextureIO { fileSuffix = toLowerCase(fileSuffix); - for (Iterator iter = textureProviders.iterator(); iter.hasNext(); ) { - TextureProvider provider = (TextureProvider) iter.next(); + for (Iterator<TextureProvider> iter = textureProviders.iterator(); iter.hasNext(); ) { + TextureProvider provider = iter.next(); TextureData data = provider.newTextureData(glp, url, internalFormat, pixelFormat, @@ -1097,13 +1097,12 @@ public class TextureIO { boolean mipmap, String fileSuffix) throws IOException { if (TGA.equals(fileSuffix)) { - TGAImage image = TGAImage.read(stream); + TGAImage image = TGAImage.read(glp, stream); if (pixelFormat == 0) { pixelFormat = image.getGLFormat(); } if (internalFormat == 0) { - GL gl = GLContext.getCurrentGL(); - if(gl.isGL2()) { + if(glp.isGL2()) { internalFormat = GL.GL_RGBA8; } else { internalFormat = (image.getBytesPerPixel()==4)?GL.GL_RGBA:GL.GL_RGB; @@ -1272,14 +1271,13 @@ public class TextureIO { // Helper routines // - private static int glGetInteger(int pname) { + private static int glGetInteger(GL gl, int pname) { int[] tmp = new int[1]; - GL gl = GLContext.getCurrentGL(); gl.glGetIntegerv(pname, tmp, 0); return tmp[0]; } - private static int glGetTexLevelParameteri(GL2 gl, int target, int level, int pname) { + private static int glGetTexLevelParameteri(GL2GL3 gl, int target, int level, int pname) { int[] tmp = new int[1]; gl.glGetTexLevelParameteriv(target, 0, pname, tmp, 0); return tmp[0]; diff --git a/src/jogl/classes/com/jogamp/opengl/util/texture/spi/DDSImage.java b/src/jogl/classes/com/jogamp/opengl/util/texture/spi/DDSImage.java index e3092162d..674e53182 100644 --- a/src/jogl/classes/com/jogamp/opengl/util/texture/spi/DDSImage.java +++ b/src/jogl/classes/com/jogamp/opengl/util/texture/spi/DDSImage.java @@ -39,13 +39,20 @@ package com.jogamp.opengl.util.texture.spi; -import java.io.*; -import java.nio.*; -import java.nio.channels.*; - -import javax.media.opengl.*; -import com.jogamp.opengl.util.*; -import com.jogamp.opengl.util.texture.*; +import java.io.BufferedInputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.PrintStream; +import java.nio.ByteBuffer; +import java.nio.ByteOrder; +import java.nio.channels.FileChannel; + +import javax.media.opengl.GL; + +import com.jogamp.opengl.util.GLBuffers; /** A reader and writer for DirectDraw Surface (.dds) files, which are used to describe textures. These files can contain multiple mipmap diff --git a/src/jogl/classes/com/jogamp/opengl/util/texture/spi/TGAImage.java b/src/jogl/classes/com/jogamp/opengl/util/texture/spi/TGAImage.java index cf35df464..c64644350 100644 --- a/src/jogl/classes/com/jogamp/opengl/util/texture/spi/TGAImage.java +++ b/src/jogl/classes/com/jogamp/opengl/util/texture/spi/TGAImage.java @@ -247,7 +247,7 @@ public class TGAImage { * it into the JimiImage structure. This was taken from the * prototype and modified for the new Jimi structure */ - private void decodeImage(LEDataInputStream dIn) throws IOException { + private void decodeImage(GLProfile glp, LEDataInputStream dIn) throws IOException { switch (header.imageType()) { case Header.UCOLORMAPPED: throw new IOException("TGADecoder Uncompressed Colormapped images not supported"); @@ -259,7 +259,7 @@ public class TGAImage { case 24: case 32: - decodeRGBImageU24_32(dIn); + decodeRGBImageU24_32(glp, dIn); break; } break; @@ -282,7 +282,7 @@ public class TGAImage { * This assumes that the body is for a 24 bit or 32 bit for a * RGB or ARGB image respectively. */ - private void decodeRGBImageU24_32(LEDataInputStream dIn) throws IOException { + private void decodeRGBImageU24_32(GLProfile glp, LEDataInputStream dIn) throws IOException { int i; // row index int y; // output row index int rawWidth = header.width() * (header.pixelDepth() / 8); @@ -300,10 +300,9 @@ public class TGAImage { System.arraycopy(rawBuf, 0, tmpData, y * rawWidth, rawBuf.length); } - GL gl = GLContext.getCurrentGL(); if (header.pixelDepth() == 24) { bpp=3; - if(gl.isGL2GL3()) { + if(glp.isGL2GL3()) { format = GL2GL3.GL_BGR; } else { format = GL.GL_RGB; @@ -312,8 +311,12 @@ public class TGAImage { } else { assert header.pixelDepth() == 32; bpp=4; - - if( gl.getContext().isTextureFormatBGRA8888Available() ) { + boolean useBGRA = glp.isGL2GL3(); + if(!useBGRA) { + final GLContext ctx = GLContext.getCurrent(); + useBGRA = null != ctx && ctx.isTextureFormatBGRA8888Available(); + } + if( useBGRA ) { format = GL.GL_BGRA; } else { format = GL.GL_RGBA; @@ -355,17 +358,17 @@ public class TGAImage { public ByteBuffer getData() { return data; } /** Reads a Targa image from the specified file. */ - public static TGAImage read(String filename) throws IOException { - return read(new FileInputStream(filename)); + public static TGAImage read(GLProfile glp, String filename) throws IOException { + return read(glp, new FileInputStream(filename)); } /** Reads a Targa image from the specified InputStream. */ - public static TGAImage read(InputStream in) throws IOException { + public static TGAImage read(GLProfile glp, InputStream in) throws IOException { LEDataInputStream dIn = new LEDataInputStream(new BufferedInputStream(in)); Header header = new Header(dIn); TGAImage res = new TGAImage(header); - res.decodeImage(dIn); + res.decodeImage(glp, dIn); return res; } |