diff options
author | Kenneth Russel <[email protected]> | 2006-01-22 21:33:34 +0000 |
---|---|---|
committer | Kenneth Russel <[email protected]> | 2006-01-22 21:33:34 +0000 |
commit | a4c9e4631455d5dff7ece2e2ac23fe9f2094dcbf (patch) | |
tree | 96b821ba84542ee270d5a580252a038cf94c8544 /src/classes/com/sun/opengl/util/texture/TextureData.java | |
parent | 228c2c2320f653267170056b8178f3b25bda5151 (diff) |
Fixed Issue 190: Add TextureIO features
Added getEstimatedMemorySize() to TextureData and Texture
classes. Filled out setTexParameter* methods to include all variants
(i, f, iv, fv) in the underlying OpenGL binding.
git-svn-id: file:///usr/local/projects/SUN/JOGL/git-svn/svn-server-sync/jogl/trunk@561 232f8b59-042b-4e1e-8c03-345bb8c30851
Diffstat (limited to 'src/classes/com/sun/opengl/util/texture/TextureData.java')
-rwxr-xr-x | src/classes/com/sun/opengl/util/texture/TextureData.java | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/src/classes/com/sun/opengl/util/texture/TextureData.java b/src/classes/com/sun/opengl/util/texture/TextureData.java index 83a1c983e..91915438b 100755 --- a/src/classes/com/sun/opengl/util/texture/TextureData.java +++ b/src/classes/com/sun/opengl/util/texture/TextureData.java @@ -74,6 +74,7 @@ public class TextureData { private Buffer[] mipmapData; // ...or a series of mipmaps private Flusher flusher; private int alignment; // 1, 2, or 4 bytes + private int estimatedMemorySize; private static final ColorModel rgbaColorModel = new ComponentColorModel(ColorSpace.getInstance(ColorSpace.CS_sRGB), @@ -151,6 +152,7 @@ public class TextureData { this.buffer = buffer; this.flusher = flusher; alignment = 1; // FIXME: is this correct enough in all situations? + estimatedMemorySize = estimatedMemorySize(buffer); } /** @@ -211,6 +213,9 @@ public class TextureData { this.mipmapData = (Buffer[]) mipmapData.clone(); this.flusher = flusher; alignment = 1; // FIXME: is this correct enough in all situations? + for (int i = 0; i < mipmapData.length; i++) { + estimatedMemorySize += estimatedMemorySize(mipmapData[i]); + } } /** @@ -240,6 +245,7 @@ public class TextureData { } createFromImage(image); this.mipmap = mipmap; + estimatedMemorySize = estimatedMemorySize(buffer); } /** Returns the width in pixels of the texture data. */ @@ -293,6 +299,15 @@ public class TextureData { /** Sets the required byte alignment for the texture data. */ public void setAlignment(int alignment) { this.alignment = alignment; } + /** Returns an estimate of the amount of memory in bytes this + TextureData will consume once uploaded to the graphics card. It + should only be treated as an estimate; most applications should + not need to query this but instead let the OpenGL implementation + page textures in and out as necessary. */ + public int getEstimatedMemorySize() { + return estimatedMemorySize; + } + /** Flushes resources associated with this TextureData by calling Flusher.flush(). */ public void flush() { @@ -509,4 +524,26 @@ public class TextureData { pixelFormat = hasAlpha ? GL.GL_RGBA : GL.GL_RGB; alignment = 1; // FIXME: do we need better? } + + private int estimatedMemorySize(Buffer buffer) { + if (buffer == null) { + return 0; + } + int capacity = buffer.capacity(); + if (buffer instanceof ByteBuffer) { + return capacity; + } else if (buffer instanceof IntBuffer) { + return capacity * BufferUtil.SIZEOF_INT; + } else if (buffer instanceof FloatBuffer) { + return capacity * BufferUtil.SIZEOF_FLOAT; + } else if (buffer instanceof ShortBuffer) { + return capacity * BufferUtil.SIZEOF_SHORT; + } else if (buffer instanceof LongBuffer) { + return capacity * BufferUtil.SIZEOF_LONG; + } else if (buffer instanceof DoubleBuffer) { + return capacity * BufferUtil.SIZEOF_DOUBLE; + } + throw new RuntimeException("Unexpected buffer type " + + buffer.getClass().getName()); + } } |