aboutsummaryrefslogtreecommitdiffstats
path: root/src/jogl/classes/com/jogamp/opengl/util/texture
diff options
context:
space:
mode:
Diffstat (limited to 'src/jogl/classes/com/jogamp/opengl/util/texture')
-rw-r--r--src/jogl/classes/com/jogamp/opengl/util/texture/TextureData.java122
-rw-r--r--src/jogl/classes/com/jogamp/opengl/util/texture/awt/AWTTextureData.java96
2 files changed, 38 insertions, 180 deletions
diff --git a/src/jogl/classes/com/jogamp/opengl/util/texture/TextureData.java b/src/jogl/classes/com/jogamp/opengl/util/texture/TextureData.java
index 2f0c86255..dec1b43cf 100644
--- a/src/jogl/classes/com/jogamp/opengl/util/texture/TextureData.java
+++ b/src/jogl/classes/com/jogamp/opengl/util/texture/TextureData.java
@@ -38,14 +38,11 @@
package com.jogamp.opengl.util.texture;
import java.nio.Buffer;
-import java.nio.ByteBuffer;
-import javax.media.opengl.GL;
-import javax.media.opengl.GLContext;
import javax.media.opengl.GLProfile;
-import com.jogamp.common.nio.Buffers;
import com.jogamp.opengl.util.GLBuffers;
+import com.jogamp.opengl.util.GLPixelBuffer.GLPixelAttributes;
/**
* Represents the data for an OpenGL texture. This is separated from
@@ -62,97 +59,10 @@ public class TextureData {
/** ColorSpace of pixel data. */
public static enum ColorSpace { RGB, YCbCr, YCCK, CMYK };
- /** Pixel data attributes. */
- public static class PixelAttributes {
- /** Undefinded instance of {@link PixelAttributes}, having format:=0 and type:= 0. */
- public static final PixelAttributes UNDEF = new PixelAttributes(0, 0);
-
- /** The OpenGL pixel data format */
- public final int format;
- /** The OpenGL pixel data type */
- public final int type;
- public PixelAttributes(int dataFormat, int dataType) {
- this.format = dataFormat;
- this.type = dataType;
- }
- public String toString() {
- return "PixelAttributes[fFmt 0x"+Integer.toHexString(format)+", type 0x"+Integer.toHexString(type)+"]";
- }
- }
- /** Allows user to interface with another toolkit to define {@link PixelAttributes} and memory buffer to produce {@link TextureData}. */
- public static interface PixelBufferProvider {
- /** Called first to determine {@link PixelAttributes}. */
- PixelAttributes getAttributes(GL gl, int componentCount);
-
- /**
- * Returns true, if implementation requires a new buffer based on the new size
- * and previous aquired {@link #getAttributes(GL, int) attributes} due to pixel alignment, otherwise false.
- * @see #allocate(int, int, int)
- */
- boolean requiresNewBuffer(int width, int height);
-
- /**
- * Called after {@link #getAttributes(GL, int)} to retrieve the NIO or array backed pixel {@link Buffer}.
- * <p>
- * Being called to gather the initial {@link Buffer}, if the existing {@link Buffer} size is not sufficient,
- * or if {@link #requiresNewBuffer(int, int)} returns false.
- * </p>
- * <p>
- * Number of components was passed via {@link #getAttributes(GL, int)}.
- * </p>
- * <p>
- * The returned buffer must have at least <code>minByteSize</code> {@link Buffer#remaining() remaining}.
- * </p>
- */
- Buffer allocate(int width, int height, int minByteSize);
-
- /** Dispose resources. */
- void dispose();
- }
- /**
- * Default {@link PixelBufferProvider} utilizing best match for {@link PixelAttributes}
- * and {@link #allocate(int, int, int) allocating} a {@link ByteBuffer}.
- */
- public static class DefPixelBufferProvider implements PixelBufferProvider {
- @Override
- public PixelAttributes getAttributes(GL gl, int componentCount) {
- final GLContext ctx = gl.getContext();
- final int dFormat, dType;
-
- if(gl.isGL2GL3() && 3 == componentCount) {
- dFormat = GL.GL_RGB;
- dType = GL.GL_UNSIGNED_BYTE;
- } else {
- dFormat = ctx.getDefaultPixelDataFormat();
- dType = ctx.getDefaultPixelDataType();
- }
- return new TextureData.PixelAttributes(dFormat, dType);
- }
- @Override
- public boolean requiresNewBuffer(int width, int height) {
- return false;
- }
- /**
- * {@inheritDoc}
- * <p>
- * Returns an NIO {@link ByteBuffer} of <code>minByteSize</code>.
- * </p>
- */
- @Override
- public final Buffer allocate(int width, int height, int minByteSize) {
- return Buffers.newDirectByteBuffer(minByteSize);
- }
-
- @Override
- public void dispose() {
- // nop
- }
- }
-
protected int width;
protected int height;
private int border;
- protected PixelAttributes pixelAttributes;
+ protected GLPixelAttributes pixelAttributes;
protected int internalFormat; // perhaps inferred from pixelFormat?
protected boolean mipmap; // indicates whether mipmaps should be generated
// (ignored if mipmaps are supplied from the file)
@@ -225,7 +135,7 @@ public class TextureData {
boolean mustFlipVertically,
Buffer buffer,
Flusher flusher) throws IllegalArgumentException {
- this(glp, internalFormat, width, height, border, new PixelAttributes(pixelFormat, pixelType),
+ this(glp, internalFormat, width, height, border, new GLPixelAttributes(pixelFormat, pixelType),
mipmap, dataIsCompressed, mustFlipVertically, buffer, flusher);
}
@@ -273,7 +183,7 @@ public class TextureData {
int width,
int height,
int border,
- PixelAttributes pixelAttributes,
+ GLPixelAttributes pixelAttributes,
boolean mipmap,
boolean dataIsCompressed,
boolean mustFlipVertically,
@@ -348,7 +258,7 @@ public class TextureData {
boolean mustFlipVertically,
Buffer[] mipmapData,
Flusher flusher) throws IllegalArgumentException {
- this(glp, internalFormat, width, height, border, new PixelAttributes(pixelFormat, pixelType),
+ this(glp, internalFormat, width, height, border, new GLPixelAttributes(pixelFormat, pixelType),
dataIsCompressed, mustFlipVertically, mipmapData, flusher);
}
@@ -395,7 +305,7 @@ public class TextureData {
int width,
int height,
int border,
- PixelAttributes pixelAttributes,
+ GLPixelAttributes pixelAttributes,
boolean dataIsCompressed,
boolean mustFlipVertically,
Buffer[] mipmapData,
@@ -429,7 +339,7 @@ public class TextureData {
public void setColorSpace(ColorSpace cs) { pixelCS = cs; }
/** Used only by subclasses */
- protected TextureData(GLProfile glp) { this.glProfile = glp; this.pixelAttributes = PixelAttributes.UNDEF; }
+ protected TextureData(GLProfile glp) { this.glProfile = glp; this.pixelAttributes = GLPixelAttributes.UNDEF; }
/** Returns the width in pixels of the texture data. */
public int getWidth() { return width; }
@@ -439,8 +349,8 @@ public class TextureData {
public int getBorder() {
return border;
}
- /** Returns the intended OpenGL {@link PixelAttributes} of the texture data, i.e. format and type. */
- public PixelAttributes getPixelAttributes() {
+ /** Returns the intended OpenGL {@link GLPixelAttributes} of the texture data, i.e. format and type. */
+ public GLPixelAttributes getPixelAttributes() {
return pixelAttributes;
}
/** Returns the intended OpenGL pixel format of the texture data. */
@@ -495,27 +405,27 @@ public class TextureData {
/** Sets the border in pixels of the texture data. */
public void setBorder(int border) { this.border = border; }
/** Sets the intended OpenGL pixel format of the texture data. */
- public void setPixelAttributes(PixelAttributes pixelAttributes) { this.pixelAttributes = pixelAttributes; }
+ public void setPixelAttributes(GLPixelAttributes pixelAttributes) { this.pixelAttributes = pixelAttributes; }
/**
- * Sets the intended OpenGL pixel format component of {@link PixelAttributes} of the texture data.
+ * Sets the intended OpenGL pixel format component of {@link GLPixelAttributes} of the texture data.
* <p>
- * Use {@link #setPixelAttributes(PixelAttributes)}, if setting format and type.
+ * Use {@link #setPixelAttributes(GLPixelAttributes)}, if setting format and type.
* </p>
*/
public void setPixelFormat(int pixelFormat) {
if( pixelAttributes.format != pixelFormat ) {
- pixelAttributes = new PixelAttributes(pixelFormat, pixelAttributes.type);
+ pixelAttributes = new GLPixelAttributes(pixelFormat, pixelAttributes.type);
}
}
/**
- * Sets the intended OpenGL pixel type component of {@link PixelAttributes} of the texture data.
+ * Sets the intended OpenGL pixel type component of {@link GLPixelAttributes} of the texture data.
* <p>
- * Use {@link #setPixelAttributes(PixelAttributes)}, if setting format and type.
+ * Use {@link #setPixelAttributes(GLPixelAttributes)}, if setting format and type.
* </p>
*/
public void setPixelType(int pixelType) {
if( pixelAttributes.type != pixelType) {
- pixelAttributes = new PixelAttributes(pixelAttributes.format, pixelType);
+ pixelAttributes = new GLPixelAttributes(pixelAttributes.format, pixelType);
}
}
/** Sets the intended OpenGL internal format of the texture data. */
diff --git a/src/jogl/classes/com/jogamp/opengl/util/texture/awt/AWTTextureData.java b/src/jogl/classes/com/jogamp/opengl/util/texture/awt/AWTTextureData.java
index 7a0f00edf..d7e825c1d 100644
--- a/src/jogl/classes/com/jogamp/opengl/util/texture/awt/AWTTextureData.java
+++ b/src/jogl/classes/com/jogamp/opengl/util/texture/awt/AWTTextureData.java
@@ -66,62 +66,10 @@ import javax.media.opengl.GL2GL3;
import javax.media.opengl.GLException;
import javax.media.opengl.GLProfile;
-import com.jogamp.common.nio.Buffers;
+import com.jogamp.opengl.util.GLPixelBuffer.GLPixelAttributes;
import com.jogamp.opengl.util.texture.TextureData;
-import com.jogamp.opengl.util.texture.TextureData.PixelBufferProvider;
public class AWTTextureData extends TextureData {
- public static final PixelAttributes awtPixelAttributesIntRGB = new PixelAttributes(GL.GL_BGRA, GL.GL_UNSIGNED_BYTE);
-
- /**
- * AWT {@link PixelBufferProvider} backed by a {@link BufferedImage} of type
- * {@link BufferedImage#TYPE_INT_ARGB} or {@link BufferedImage#TYPE_INT_RGB}
- * and {@link #allocate(int, int, int) allocating} am array backed {@link IntBuffer}.
- */
- public static final class AWTPixelBufferProviderInt implements PixelBufferProvider {
- private BufferedImage image = null;
- private int componentCount = 0;
-
- @Override
- public PixelAttributes getAttributes(GL gl, int componentCount) {
- this.componentCount = componentCount;
- return awtPixelAttributesIntRGB;
- }
- @Override
- public boolean requiresNewBuffer(int width, int height) {
- return null == image || image.getWidth() != width || image.getHeight() != height;
- }
- /**
- * {@inheritDoc}
- * <p>
- * Returns an array backed {@link IntBuffer} of size <pre>width*height*{@link Buffers#SIZEOF_INT SIZEOF_INT}</code>.
- * </p>
- */
- @Override
- public Buffer allocate(int width, int height, int minByteSize) {
- image = new BufferedImage(width, height, 4 == componentCount ? BufferedImage.TYPE_INT_ARGB : BufferedImage.TYPE_INT_RGB);
- final int[] readBackIntBuffer = ((DataBufferInt) image.getRaster().getDataBuffer()).getData();
- return IntBuffer.wrap( readBackIntBuffer );
- }
-
- @Override
- public void dispose() {
- if(null != image) {
- image.flush();
- image = null;
- }
- }
-
- /** Returns the number source components being used as indicated at {@link #allocate(int, int, int)}. */
- public int getComponentCount() { return componentCount; }
-
- /** Returns the underlying {@link BufferedImage} as allocated via {@link #allocate(int, int, int)}. */
- public BufferedImage getImage() { return image; }
-
- /** Returns true if an underlying {@link BufferedImage} has been allocated via {@link #allocate(int, int, int)}. */
- public boolean hasImage() { return null != image; }
- }
-
// Mechanism for lazily converting input BufferedImages with custom
// ColorModels to standard ones for uploading to OpenGL, as well as
// backing off from the optimizations of hoping that either
@@ -198,7 +146,7 @@ public class AWTTextureData extends TextureData {
}
@Override
- public PixelAttributes getPixelAttributes() {
+ public GLPixelAttributes getPixelAttributes() {
validatePixelAttributes();
return super.getPixelAttributes();
}
@@ -229,7 +177,7 @@ public class AWTTextureData extends TextureData {
}
private void createFromImage(GLProfile glp, BufferedImage image) {
- pixelAttributes = PixelAttributes.UNDEF; // Determine from image
+ pixelAttributes = GLPixelAttributes.UNDEF; // Determine from image
mustFlipVertically = true;
width = image.getWidth();
@@ -259,21 +207,21 @@ public class AWTTextureData extends TextureData {
if (glp.isGL2GL3()) {
switch (image.getType()) {
case BufferedImage.TYPE_INT_RGB:
- pixelAttributes = new PixelAttributes(GL.GL_BGRA, GL2GL3.GL_UNSIGNED_INT_8_8_8_8_REV);
+ pixelAttributes = new GLPixelAttributes(GL.GL_BGRA, GL2GL3.GL_UNSIGNED_INT_8_8_8_8_REV);
rowLength = scanlineStride;
alignment = 4;
expectingGL12 = true;
setupLazyCustomConversion(image);
break;
case BufferedImage.TYPE_INT_ARGB_PRE:
- pixelAttributes = new PixelAttributes(GL.GL_BGRA, GL2GL3.GL_UNSIGNED_INT_8_8_8_8_REV);
+ pixelAttributes = new GLPixelAttributes(GL.GL_BGRA, GL2GL3.GL_UNSIGNED_INT_8_8_8_8_REV);
rowLength = scanlineStride;
alignment = 4;
expectingGL12 = true;
setupLazyCustomConversion(image);
break;
case BufferedImage.TYPE_INT_BGR:
- pixelAttributes = new PixelAttributes(GL.GL_RGBA, GL2GL3.GL_UNSIGNED_INT_8_8_8_8_REV);
+ pixelAttributes = new GLPixelAttributes(GL.GL_RGBA, GL2GL3.GL_UNSIGNED_INT_8_8_8_8_REV);
rowLength = scanlineStride;
alignment = 4;
expectingGL12 = true;
@@ -284,7 +232,7 @@ public class AWTTextureData extends TextureData {
// we can pass the image data directly to OpenGL only if
// we have an integral number of pixels in each scanline
if ((scanlineStride % 3) == 0) {
- pixelAttributes = new PixelAttributes(GL2GL3.GL_BGR, GL.GL_UNSIGNED_BYTE);
+ pixelAttributes = new GLPixelAttributes(GL2GL3.GL_BGR, GL.GL_UNSIGNED_BYTE);
rowLength = scanlineStride / 3;
alignment = 1;
} else {
@@ -304,7 +252,7 @@ public class AWTTextureData extends TextureData {
// the necessary byte swapping (FIXME: needs more
// investigation)
if ((scanlineStride % 4) == 0 && glp.isGL2() && false) {
- pixelAttributes = new PixelAttributes(GL2.GL_ABGR_EXT, GL.GL_UNSIGNED_BYTE);
+ pixelAttributes = new GLPixelAttributes(GL2.GL_ABGR_EXT, GL.GL_UNSIGNED_BYTE);
rowLength = scanlineStride / 4;
alignment = 4;
@@ -320,26 +268,26 @@ public class AWTTextureData extends TextureData {
}
}
case BufferedImage.TYPE_USHORT_565_RGB:
- pixelAttributes = new PixelAttributes(GL.GL_RGB, GL.GL_UNSIGNED_SHORT_5_6_5);
+ pixelAttributes = new GLPixelAttributes(GL.GL_RGB, GL.GL_UNSIGNED_SHORT_5_6_5);
rowLength = scanlineStride;
alignment = 2;
expectingGL12 = true;
setupLazyCustomConversion(image);
break;
case BufferedImage.TYPE_USHORT_555_RGB:
- pixelAttributes = new PixelAttributes(GL.GL_BGRA, GL2GL3.GL_UNSIGNED_SHORT_1_5_5_5_REV);
+ pixelAttributes = new GLPixelAttributes(GL.GL_BGRA, GL2GL3.GL_UNSIGNED_SHORT_1_5_5_5_REV);
rowLength = scanlineStride;
alignment = 2;
expectingGL12 = true;
setupLazyCustomConversion(image);
break;
case BufferedImage.TYPE_BYTE_GRAY:
- pixelAttributes = new PixelAttributes(GL.GL_LUMINANCE, GL.GL_UNSIGNED_BYTE);
+ pixelAttributes = new GLPixelAttributes(GL.GL_LUMINANCE, GL.GL_UNSIGNED_BYTE);
rowLength = scanlineStride;
alignment = 1;
break;
case BufferedImage.TYPE_USHORT_GRAY:
- pixelAttributes = new PixelAttributes(GL.GL_LUMINANCE, GL.GL_UNSIGNED_SHORT);
+ pixelAttributes = new GLPixelAttributes(GL.GL_LUMINANCE, GL.GL_UNSIGNED_SHORT);
rowLength = scanlineStride;
alignment = 2;
break;
@@ -354,11 +302,11 @@ public class AWTTextureData extends TextureData {
default:
java.awt.image.ColorModel cm = image.getColorModel();
if (cm.equals(rgbColorModel)) {
- pixelAttributes = new PixelAttributes(GL.GL_RGB, GL.GL_UNSIGNED_BYTE);
+ pixelAttributes = new GLPixelAttributes(GL.GL_RGB, GL.GL_UNSIGNED_BYTE);
rowLength = scanlineStride / 3;
alignment = 1;
} else if (cm.equals(rgbaColorModel)) {
- pixelAttributes = new PixelAttributes(GL.GL_RGBA, GL.GL_UNSIGNED_BYTE);
+ pixelAttributes = new GLPixelAttributes(GL.GL_RGBA, GL.GL_UNSIGNED_BYTE);
rowLength = scanlineStride / 4; // FIXME: correct?
alignment = 4;
} else {
@@ -370,7 +318,7 @@ public class AWTTextureData extends TextureData {
} else {
switch (image.getType()) {
case BufferedImage.TYPE_INT_RGB:
- pixelAttributes = new PixelAttributes(GL.GL_RGB, GL.GL_UNSIGNED_BYTE);
+ pixelAttributes = new GLPixelAttributes(GL.GL_RGB, GL.GL_UNSIGNED_BYTE);
rowLength = scanlineStride;
alignment = 3;
expectingGL12 = true;
@@ -385,21 +333,21 @@ public class AWTTextureData extends TextureData {
case BufferedImage.TYPE_4BYTE_ABGR_PRE:
throw new GLException("INT_BGR n.a.");
case BufferedImage.TYPE_USHORT_565_RGB:
- pixelAttributes = new PixelAttributes(GL.GL_RGB, GL.GL_UNSIGNED_SHORT_5_6_5);
+ pixelAttributes = new GLPixelAttributes(GL.GL_RGB, GL.GL_UNSIGNED_SHORT_5_6_5);
rowLength = scanlineStride;
alignment = 2;
expectingGL12 = true;
setupLazyCustomConversion(image);
break;
case BufferedImage.TYPE_USHORT_555_RGB:
- pixelAttributes = new PixelAttributes(GL.GL_RGBA, GL.GL_UNSIGNED_SHORT_5_5_5_1);
+ pixelAttributes = new GLPixelAttributes(GL.GL_RGBA, GL.GL_UNSIGNED_SHORT_5_5_5_1);
rowLength = scanlineStride;
alignment = 2;
expectingGL12 = true;
setupLazyCustomConversion(image);
break;
case BufferedImage.TYPE_BYTE_GRAY:
- pixelAttributes = new PixelAttributes(GL.GL_LUMINANCE, GL.GL_UNSIGNED_BYTE);
+ pixelAttributes = new GLPixelAttributes(GL.GL_LUMINANCE, GL.GL_UNSIGNED_BYTE);
rowLength = scanlineStride;
alignment = 1;
break;
@@ -416,11 +364,11 @@ public class AWTTextureData extends TextureData {
default:
java.awt.image.ColorModel cm = image.getColorModel();
if (cm.equals(rgbColorModel)) {
- pixelAttributes = new PixelAttributes(GL.GL_RGB, GL.GL_UNSIGNED_BYTE);
+ pixelAttributes = new GLPixelAttributes(GL.GL_RGB, GL.GL_UNSIGNED_BYTE);
rowLength = scanlineStride / 3;
alignment = 1;
} else if (cm.equals(rgbaColorModel)) {
- pixelAttributes = new PixelAttributes(GL.GL_RGBA, GL.GL_UNSIGNED_BYTE);
+ pixelAttributes = new GLPixelAttributes(GL.GL_RGBA, GL.GL_UNSIGNED_BYTE);
rowLength = scanlineStride / 4; // FIXME: correct?
alignment = 4;
} else {
@@ -465,7 +413,7 @@ public class AWTTextureData extends TextureData {
} else {
throw new RuntimeException("Unexpected DataBuffer type?");
}
- pixelAttributes = new PixelAttributes(pixelFormat, pixelType);
+ pixelAttributes = new GLPixelAttributes(pixelFormat, pixelType);
}
private void createFromCustom(BufferedImage image) {
@@ -524,7 +472,7 @@ public class AWTTextureData extends TextureData {
// and knowing we're in the process of doing the fallback code
// path, re-infer a vanilla pixel format and type compatible with
// OpenGL 1.1
- pixelAttributes = PixelAttributes.UNDEF;
+ pixelAttributes = GLPixelAttributes.UNDEF;
setupLazyCustomConversion(imageForLazyCustomConversion);
}