From 8b8e270788b50636e48ee17cc9e5fc8f29d44f5c Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Thu, 25 Mar 2010 03:28:23 +0100 Subject: http://www.jogamp.org/bugzilla/show_bug.cgi?id=378 Test: Added JUNIT Test Environment: - tests: jogl.test.jar - run: 'ant junit.run' Currently only runs 1 test regarding this bug id. Adding PATH (windows) or LD_LIBRARY_PATH (unix). Test initialized AWTTextureData without a current GLContext and then uses it to render .. Solution: Pending initialization of GL depending data, offered in TextureData.glPostInit(), specialized in AWTTextureData. --- make/build-jogl.xml | 75 +++++++++++++++++++++- make/build.xml | 6 ++ make/lib/gluegen.compiler.linux-32bit.xml | 31 +++++++++ make/make.jogl.all.linux-x86.sh | 1 + make/make.jogl.cdcfp.linux-x86.sh | 1 + .../com/sun/opengl/util/texture/TextureData.java | 64 +++++++++++++++--- .../opengl/util/texture/awt/AWTTextureData.java | 45 +++++++++---- 7 files changed, 200 insertions(+), 23 deletions(-) create mode 100644 make/lib/gluegen.compiler.linux-32bit.xml diff --git a/make/build-jogl.xml b/make/build-jogl.xml index 6f97a336e..ba92540b8 100644 --- a/make/build-jogl.xml +++ b/make/build-jogl.xml @@ -215,6 +215,7 @@ + + @@ -313,6 +321,8 @@ + + @@ -411,6 +421,7 @@ + @@ -428,6 +439,25 @@ + + + + + + + + + + + + + + + + + + + @@ -2039,11 +2069,54 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + diff --git a/make/build.xml b/make/build.xml index b3a77945c..b8b3872ca 100644 --- a/make/build.xml +++ b/make/build.xml @@ -74,6 +74,10 @@ + + + + @@ -178,6 +182,8 @@ + + diff --git a/make/lib/gluegen.compiler.linux-32bit.xml b/make/lib/gluegen.compiler.linux-32bit.xml new file mode 100644 index 000000000..344d9da27 --- /dev/null +++ b/make/lib/gluegen.compiler.linux-32bit.xml @@ -0,0 +1,31 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/make/make.jogl.all.linux-x86.sh b/make/make.jogl.all.linux-x86.sh index 081d8328b..5387cf97a 100644 --- a/make/make.jogl.all.linux-x86.sh +++ b/make/make.jogl.all.linux-x86.sh @@ -17,6 +17,7 @@ fi # -Djogl.cg=1 -Dx11.cg.lib=../../lib-linux-x86 \ ant \ + -Dgluegen.user.compiler.file=`pwd`/lib/gluegen.compiler.linux-32bit.xml \ -Dbuild.noarchives=true \ -Djogl.cg=1 -Dx11.cg.lib=../../lib-linux-x86 \ -Drootrel.build=build-x86 \ diff --git a/make/make.jogl.cdcfp.linux-x86.sh b/make/make.jogl.cdcfp.linux-x86.sh index 4a2241669..d212bd81d 100644 --- a/make/make.jogl.cdcfp.linux-x86.sh +++ b/make/make.jogl.cdcfp.linux-x86.sh @@ -15,6 +15,7 @@ fi BUILD_SUBDIR=build-cdcfp-x86 ant -v \ + -Dgluegen.user.compiler.file=`pwd`/lib/gluegen.compiler.linux-32bit.xml \ -Dbuild.noarchives=true \ -Drootrel.build=$BUILD_SUBDIR \ -Dsetup.cdcfp=true \ diff --git a/src/jogl/classes/com/sun/opengl/util/texture/TextureData.java b/src/jogl/classes/com/sun/opengl/util/texture/TextureData.java index 8ac4b9b84..81124b060 100755 --- a/src/jogl/classes/com/sun/opengl/util/texture/TextureData.java +++ b/src/jogl/classes/com/sun/opengl/util/texture/TextureData.java @@ -71,6 +71,10 @@ public class TextureData { protected int alignment; // 1, 2, or 4 bytes protected int estimatedMemorySize; + // specialization of this class might need GL dependent post initialization + protected Object glPostInitSync = new Object(); + protected volatile boolean glPostInitDone = false; + // These booleans are a concession to the AWTTextureData subclass protected boolean haveEXTABGR; protected boolean haveGL12; @@ -207,45 +211,71 @@ public class TextureData { } /** Used only by subclasses */ - protected TextureData() { - } + protected TextureData() { } /** Returns the width in pixels of the texture data. */ public int getWidth() { return width; } /** Returns the height in pixels of the texture data. */ public int getHeight() { return height; } /** Returns the border in pixels of the texture data. */ - public int getBorder() { return border; } + public int getBorder() { + glPostInitInt(); + return border; + } /** Returns the intended OpenGL pixel format of the texture data. */ public int getPixelFormat() { + glPostInitInt(); return pixelFormat; } /** Returns the intended OpenGL pixel type of the texture data. */ public int getPixelType() { + glPostInitInt(); return pixelType; } /** Returns the intended OpenGL internal format of the texture data. */ - public int getInternalFormat() { return internalFormat; } + public int getInternalFormat() { + glPostInitInt(); + return internalFormat; + } /** Returns whether mipmaps should be generated for the texture data. */ - public boolean getMipmap() { return mipmap; } + public boolean getMipmap() { + glPostInitInt(); + return mipmap; + } /** Indicates whether the texture data is in compressed form. */ - public boolean isDataCompressed() { return dataIsCompressed; } + public boolean isDataCompressed() { + glPostInitInt(); + return dataIsCompressed; + } /** Indicates whether the texture coordinates must be flipped vertically for proper display. */ - public boolean getMustFlipVertically() { return mustFlipVertically; } + public boolean getMustFlipVertically() { + glPostInitInt(); + return mustFlipVertically; + } /** Returns the texture data, or null if it is specified as a set of mipmaps. */ public Buffer getBuffer() { + glPostInitInt(); return buffer; } /** Returns all mipmap levels for the texture data, or null if it is specified as a single image. */ - public Buffer[] getMipmapData() { return mipmapData; } + public Buffer[] getMipmapData() { + glPostInitInt(); + return mipmapData; + } /** Returns the required byte alignment for the texture data. */ - public int getAlignment() { return alignment; } + public int getAlignment() { + glPostInitInt(); + return alignment; + } /** Returns the row length needed for correct GL_UNPACK_ROW_LENGTH specification. This is currently only supported for non-mipmapped, non-compressed textures. */ - public int getRowLength() { return rowLength; } + public int getRowLength() { + glPostInitInt(); + return rowLength; + } /** Sets the width in pixels of the texture data. */ public void setWidth(int width) { this.width = width; } @@ -303,6 +333,7 @@ public class TextureData { /** Flushes resources associated with this TextureData by calling Flusher.flush(). */ public void flush() { + glPostInitInt(); if (flusher != null) { flusher.flush(); flusher = null; @@ -333,6 +364,19 @@ public class TextureData { // Internals only below this point // + protected void glPostInit() { } + + protected final void glPostInitInt() { + if(glPostInitDone) return; + synchronized(glPostInitSync) { + if(!glPostInitDone) { + glPostInit(); + glPostInitDone = true; + } + glPostInitSync.notifyAll(); + } + } + protected static int estimatedMemorySize(Buffer buffer) { if (buffer == null) { return 0; diff --git a/src/jogl/classes/com/sun/opengl/util/texture/awt/AWTTextureData.java b/src/jogl/classes/com/sun/opengl/util/texture/awt/AWTTextureData.java index b3cf537f6..e949883ed 100755 --- a/src/jogl/classes/com/sun/opengl/util/texture/awt/AWTTextureData.java +++ b/src/jogl/classes/com/sun/opengl/util/texture/awt/AWTTextureData.java @@ -56,6 +56,9 @@ public class AWTTextureData extends TextureData { private boolean expectingEXTABGR; private boolean expectingGL12; + private int scanlineStride; + private BufferedImage glDependingImage; // indicator wheather GL depening initialization has been passed + private static final ColorModel rgbaColorModel = new ComponentColorModel(ColorSpace.getInstance(ColorSpace.CS_sRGB), new int[] {8, 8, 8, 8}, true, true, @@ -99,20 +102,14 @@ public class AWTTextureData extends TextureData { } else { this.internalFormat = internalFormat; } - createFromImage(image); + createFromImagePre(image); + this.mipmap = mipmap; - if (buffer != null) { - estimatedMemorySize = estimatedMemorySize(buffer); - } else { - // In the lazy custom conversion case we don't yet have a buffer - if (imageForLazyCustomConversion != null) { - estimatedMemorySize = estimatedMemorySize(wrapImageDataBuffer(imageForLazyCustomConversion)); - } - } } /** Returns the intended OpenGL pixel format of the texture data. */ public int getPixelFormat() { + glPostInitInt(); if (imageForLazyCustomConversion != null) { if (!((expectingEXTABGR && haveEXTABGR) || (expectingGL12 && haveGL12))) { @@ -123,6 +120,7 @@ public class AWTTextureData extends TextureData { } /** Returns the intended OpenGL pixel type of the texture data. */ public int getPixelType() { + glPostInitInt(); if (imageForLazyCustomConversion != null) { if (!((expectingEXTABGR && haveEXTABGR) || (expectingGL12 && haveGL12))) { @@ -134,6 +132,7 @@ public class AWTTextureData extends TextureData { /** Returns the texture data, or null if it is specified as a set of mipmaps. */ public Buffer getBuffer() { + glPostInitInt(); if (imageForLazyCustomConversion != null) { if (!((expectingEXTABGR && haveEXTABGR) || (expectingGL12 && haveGL12))) { @@ -146,14 +145,13 @@ public class AWTTextureData extends TextureData { return buffer; } - private void createFromImage(BufferedImage image) { + private void createFromImagePre(BufferedImage image) { pixelType = 0; // Determine from image mustFlipVertically = true; width = image.getWidth(); height = image.getHeight(); - int scanlineStride; SampleModel sm = image.getRaster().getSampleModel(); if (sm instanceof SinglePixelPackedSampleModel) { scanlineStride = @@ -169,8 +167,22 @@ public class AWTTextureData extends TextureData { setupLazyCustomConversion(image); return; } + glDependingImage = image; // earmark for post init + } + + protected void glPostInit() { + if(null == glDependingImage) return; + + GLContext current = GLContext.getCurrent(); + if(null == current) return; - GLProfile glp = GLContext.getCurrentGL().getGLProfile(); + BufferedImage image = glDependingImage; + glDependingImage = null; + + GLProfile glp = current.getGL().getGLProfile(); + + width = image.getWidth(); + height = image.getHeight(); if (glp.isGL2()) { switch (image.getType()) { @@ -365,6 +377,15 @@ public class AWTTextureData extends TextureData { } createNIOBufferFromImage(image); + + if (buffer != null) { + estimatedMemorySize = estimatedMemorySize(buffer); + } else { + // In the lazy custom conversion case we don't yet have a buffer + if (imageForLazyCustomConversion != null) { + estimatedMemorySize = estimatedMemorySize(wrapImageDataBuffer(imageForLazyCustomConversion)); + } + } } private void setupLazyCustomConversion(BufferedImage image) { -- cgit v1.2.3