summaryrefslogtreecommitdiffstats
path: root/src/classes/com/sun/opengl/utils/TextureData.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/classes/com/sun/opengl/utils/TextureData.java')
-rwxr-xr-xsrc/classes/com/sun/opengl/utils/TextureData.java114
1 files changed, 94 insertions, 20 deletions
diff --git a/src/classes/com/sun/opengl/utils/TextureData.java b/src/classes/com/sun/opengl/utils/TextureData.java
index d88a18233..a6fcd9073 100755
--- a/src/classes/com/sun/opengl/utils/TextureData.java
+++ b/src/classes/com/sun/opengl/utils/TextureData.java
@@ -63,12 +63,14 @@ public class TextureData {
private int pixelFormat;
private int pixelType;
private int internalFormat; // perhaps inferred from pixelFormat?
- private int mipmapLevel;
+ private boolean mipmap; // indicates whether mipmaps should be generated
+ // (ignored if mipmaps are supplied from the file)
private boolean dataIsCompressed;
private boolean mustFlipVertically; // Must flip texture coordinates
// vertically to get OpenGL output
// to look correct
- private Buffer buffer; // the actual data
+ private Buffer buffer; // the actual data...
+ private Buffer[] mipmapData; // ...or a series of mipmaps
private Flusher flusher;
private int alignment; // 1, 2, or 4 bytes
@@ -91,9 +93,6 @@ public class TextureData {
* memory-mapped files that might otherwise require a garbage
* collection to reclaim and close.
*
- * @param mipmapLevel the mipmap level for the resulting texture
- * this data represents (FIXME: needs
- * rethinking, currently unused)
* @param internalFormat the OpenGL internal format for the
* resulting texture; must be specified, may
* not be 0
@@ -105,6 +104,10 @@ public class TextureData {
* resulting texture; must be specified, may
* not be 0
* @param pixelType the OpenGL type of the pixels of the texture
+ * @param mipmap indicates whether mipmaps should be
+ * autogenerated (using GLU) for the resulting
+ * texture. Currently if mipmap is true then
+ * dataIsCompressed may not be true.
* @param dataIsCompressed indicates whether the texture data is in
* compressed form
* (e.g. GL_COMPRESSED_RGB_S3TC_DXT1_EXT)
@@ -115,25 +118,33 @@ public class TextureData {
* @param buffer the buffer containing the texture data
* @param flusher optional flusher to perform cleanup tasks
* upon call to flush()
+ *
+ * @throws IllegalArgumentException if any parameters of the texture
+ * data were invalid, such as requesting mipmap generation for a
+ * compressed texture
*/
- public TextureData(int mipmapLevel,
- int internalFormat,
+ public TextureData(int internalFormat,
int width,
int height,
int border,
int pixelFormat,
int pixelType,
+ boolean mipmap,
boolean dataIsCompressed,
boolean mustFlipVertically,
Buffer buffer,
- Flusher flusher) {
+ Flusher flusher) throws IllegalArgumentException {
+ if (mipmap && dataIsCompressed) {
+ throw new IllegalArgumentException("Can not generate mipmaps for compressed textures");
+ }
+
this.width = width;
this.height = height;
this.border = border;
this.pixelFormat = pixelFormat;
this.pixelType = pixelType;
this.internalFormat = internalFormat;
- this.mipmapLevel = mipmapLevel;
+ this.mipmap = mipmap;
this.dataIsCompressed = dataIsCompressed;
this.mustFlipVertically = mustFlipVertically;
this.buffer = buffer;
@@ -143,11 +154,68 @@ public class TextureData {
/**
* Constructs a new TextureData object with the specified parameters
+ * and data for multiple mipmap levels contained in the given array
+ * of Buffers. The optional Flusher can be used to clean up native
+ * resources associated with this TextureData when processing is
+ * complete; for example, closing of memory-mapped files that might
+ * otherwise require a garbage collection to reclaim and close.
+ *
+ * @param internalFormat the OpenGL internal format for the
+ * resulting texture; must be specified, may
+ * not be 0
+ * @param width the width in pixels of the topmost mipmap
+ * level of the texture
+ * @param height the height in pixels of the topmost mipmap
+ * level of the texture
+ * @param border the number of pixels of border this texture
+ * data has (0 or 1)
+ * @param pixelFormat the OpenGL pixel format for the
+ * resulting texture; must be specified, may
+ * not be 0
+ * @param pixelType the OpenGL type of the pixels of the texture
+ * @param dataIsCompressed indicates whether the texture data is in
+ * compressed form
+ * (e.g. GL_COMPRESSED_RGB_S3TC_DXT1_EXT)
+ * @param mustFlipVertically indicates whether the texture
+ * coordinates must be flipped vertically
+ * in order to properly display the
+ * texture
+ * @param mipmapData the buffers containing all mipmap levels
+ * of the texture's data
+ * @param flusher optional flusher to perform cleanup tasks
+ * upon call to flush()
+ *
+ * @throws IllegalArgumentException if any parameters of the texture
+ * data were invalid, such as requesting mipmap generation for a
+ * compressed texture
+ */
+ public TextureData(int internalFormat,
+ int width,
+ int height,
+ int border,
+ int pixelFormat,
+ int pixelType,
+ boolean dataIsCompressed,
+ boolean mustFlipVertically,
+ Buffer[] mipmapData,
+ Flusher flusher) throws IllegalArgumentException {
+ this.width = width;
+ this.height = height;
+ this.border = border;
+ this.pixelFormat = pixelFormat;
+ this.pixelType = pixelType;
+ this.internalFormat = internalFormat;
+ this.dataIsCompressed = dataIsCompressed;
+ this.mustFlipVertically = mustFlipVertically;
+ this.mipmapData = (Buffer[]) mipmapData.clone();
+ this.flusher = flusher;
+ alignment = 1; // FIXME: is this correct enough in all situations?
+ }
+
+ /**
+ * Constructs a new TextureData object with the specified parameters
* and data contained in the given BufferedImage.
*
- * @param mipmapLevel the mipmap level for the resulting texture
- * this data represents (FIXME: needs
- * rethinking, currently unused)
* @param internalFormat the OpenGL internal format for the
* resulting texture; may be 0, in which case
* it is inferred from the image's type
@@ -155,11 +223,14 @@ public class TextureData {
* resulting texture; may be 0, in which case
* it is inferred from the image's type (note:
* this argument is currently always ignored)
+ * @param mipmap indicates whether mipmaps should be
+ * autogenerated (using GLU) for the resulting
+ * texture
* @param image the image containing the texture data
*/
- public TextureData(int mipmapLevel,
- int internalFormat,
+ public TextureData(int internalFormat,
int pixelFormat,
+ boolean mipmap,
BufferedImage image) {
if (internalFormat == 0) {
this.internalFormat = image.getColorModel().hasAlpha() ? GL.GL_RGBA : GL.GL_RGB;
@@ -167,7 +238,7 @@ public class TextureData {
this.internalFormat = internalFormat;
}
createFromImage(image);
- this.mipmapLevel = mipmapLevel;
+ this.mipmap = mipmap;
}
/** Returns the width in pixels of the texture data. */
@@ -182,15 +253,18 @@ public class TextureData {
public int getPixelType() { return pixelType; }
/** Returns the intended OpenGL internal format of the texture data. */
public int getInternalFormat() { return internalFormat; }
- /** Returns the intended mipmap level of the texture data. */
- public int getMipmapLevel() { return mipmapLevel; }
+ /** Returns whether mipmaps should be generated for the texture data. */
+ public boolean getMipmap() { return mipmap; }
/** Indicates whether the texture data is in compressed form. */
public boolean isDataCompressed() { return dataIsCompressed; }
/** Indicates whether the texture coordinates must be flipped
vertically for proper display. */
public boolean getMustFlipVertically() { return mustFlipVertically; }
- /** Returns the texture data. */
+ /** Returns the texture data, or null if it is specified as a set of mipmaps. */
public Buffer getBuffer() { 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; }
/** Returns the required byte alignment for the texture data. */
public int getAlignment() { return alignment; }
@@ -206,8 +280,8 @@ public class TextureData {
public void setPixelType(int pixelType) { this.pixelType = pixelType; }
/** Sets the intended OpenGL internal format of the texture data. */
public void setInternalFormat(int internalFormat) { this.internalFormat = internalFormat; }
- /** Sets the intended mipmap level of the texture data. */
- public void setMipmapLevel(int mipmapLevel) { this.mipmapLevel = mipmapLevel; }
+ /** Sets whether mipmaps should be generated for the texture data. */
+ public void setMipmap(boolean mipmap) { this.mipmap = mipmap; }
/** Sets whether the texture data is in compressed form. */
public void setIsDataCompressed(boolean compressed) { this.dataIsCompressed = compressed; }
/** Sets whether the texture coordinates must be flipped vertically