diff options
Diffstat (limited to 'src/jogl/classes/com/sun')
-rwxr-xr-x | src/jogl/classes/com/sun/opengl/util/texture/TextureData.java | 64 | ||||
-rwxr-xr-x | src/jogl/classes/com/sun/opengl/util/texture/awt/AWTTextureData.java | 45 |
2 files changed, 87 insertions, 22 deletions
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) { |