aboutsummaryrefslogtreecommitdiffstats
path: root/src/jogl/classes/com/jogamp/opengl/util/texture/TextureData.java
diff options
context:
space:
mode:
authorSven Gothel <sgothel@jausoft.com>2013-05-08 22:57:17 +0200
committerSven Gothel <sgothel@jausoft.com>2013-05-08 22:57:17 +0200
commit0a7bf77b8c0765f8a53dc72a8edab8e0496938ff (patch)
treef7a02fad5afda28ea58f70c9fbb00edfcc2f49e9 /src/jogl/classes/com/jogamp/opengl/util/texture/TextureData.java
parente6a234edb1318bb38f6ab65d96518471d0c7fd68 (diff)
Refactor: TextureData's PixelAttributes/PixelBufferProvider -> GLPixelBuffer/.. and enhance usage; GLJPanel: Use GLPixelBuffer* API and SingleAWTGLPixelBufferProvider if possible.
Refactor: TextureData's PixelAttributes/PixelBufferProvider -> GLPixelBuffer/.. and enhance usage - GLPixelBuffer, GLPixelAttributes and GLPixelBufferProvider have potential for wider audience, hence extract them to package 'com.jogamp.opengl.util'. - Using GLPixelBuffer, shall attempt to use pack/unpack row-stride, i.e. GL2GL3.GL_PACK_ROW_LENGTH, or GL2GL3.GL_UNPACK_ROW_LENGTH. See GLReadBufferUtil and GLJPanel - AWTGLPixelBuffer*: Attribute 'row-stride' allows reusing a bigger buffer than requested. GLJPanel: Use GLPixelBuffer* API and SingleAWTGLPixelBufferProvider if possible. - Use GLPixelBuffer API to remove redundancies - Attempts to use SingleAWTGLPixelBufferProvider to save JVM/CPU heap space for BuffereImage and IntBbuffer (readBack) Added unit new test demonstrating multiple overlapping GLJPanels reusing (or not) a singlton SingleAWTGLPixelBufferProvider.
Diffstat (limited to 'src/jogl/classes/com/jogamp/opengl/util/texture/TextureData.java')
-rw-r--r--src/jogl/classes/com/jogamp/opengl/util/texture/TextureData.java122
1 files changed, 16 insertions, 106 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. */