diff options
author | Chien Yang <[email protected]> | 2007-03-21 22:54:08 +0000 |
---|---|---|
committer | Chien Yang <[email protected]> | 2007-03-21 22:54:08 +0000 |
commit | 9327277a80d538abf0fe638065a22b16be9be8bd (patch) | |
tree | bee4bc6043d6909a1bc117eed9dc15a2b6bd9ea0 /src/classes | |
parent | 48f2ad8638b490854eebcfa07ea59b811189efd9 (diff) |
1) Implemented Issue 126 : Use OpenGL automatic mipmap generation
2) Fixed Issue 408 : Poor quality of auto-generated mipmaps
git-svn-id: https://svn.java.net/svn/j3d-core~svn/trunk@799 ba19aa83-45c5-6ac9-afd3-db810772062c
Diffstat (limited to 'src/classes')
9 files changed, 165 insertions, 120 deletions
diff --git a/src/classes/jogl/javax/media/j3d/JoglPipeline.java b/src/classes/jogl/javax/media/j3d/JoglPipeline.java index c13c5ac..6fdbb9b 100644 --- a/src/classes/jogl/javax/media/j3d/JoglPipeline.java +++ b/src/classes/jogl/javax/media/j3d/JoglPipeline.java @@ -5625,12 +5625,12 @@ class JoglPipeline extends Pipeline { int textureFormat, int imageFormat, int width, int height, int boundaryWidth, - int dataType, Object data) { + int dataType, Object data, boolean useAutoMipMap) { if (VERBOSE) System.err.println("JoglPipeline.updateTexture2DImage(width=" + width + ",height=" + height + ",level=" + level + ")"); updateTexture2DImage(ctx, GL.GL_TEXTURE_2D, numLevels, level, textureFormat, imageFormat, - width, height, boundaryWidth, dataType, data); + width, height, boundaryWidth, dataType, data, useAutoMipMap); } void updateTexture2DSubImage(Context ctx, @@ -5638,7 +5638,10 @@ class JoglPipeline extends Pipeline { int textureFormat, int imageFormat, int imgXOffset, int imgYOffset, int tilew, int width, int height, - int dataType, Object data) { + int dataType, Object data, boolean useAutoMipMap) { + + /* Note: useAutoMipMap is not use for SubImage in the jogl pipe */ + if (VERBOSE) System.err.println("JoglPipeline.updateTexture2DSubImage()"); updateTexture2DSubImage(ctx, GL.GL_TEXTURE_2D, @@ -5770,7 +5773,7 @@ class JoglPipeline extends Pipeline { int textureFormat, int imageFormat, int width, int height, int depth, int boundaryWidth, - int dataType, Object data) { + int dataType, Object data, boolean useAutoMipMap) { if (VERBOSE) System.err.println("JoglPipeline.updateTexture3DImage()"); @@ -5804,6 +5807,13 @@ class JoglPipeline extends Pipeline { assert false; return; } + + if (useAutoMipMap) { + gl.glTexParameteri(GL.GL_TEXTURE_3D, GL.GL_GENERATE_MIPMAP, GL.GL_TRUE); + } + else { + gl.glTexParameteri(GL.GL_TEXTURE_3D, GL.GL_GENERATE_MIPMAP, GL.GL_FALSE); + } if((dataType == ImageComponentRetained.IMAGE_DATA_TYPE_BYTE_ARRAY) || (dataType == ImageComponentRetained.IMAGE_DATA_TYPE_BYTE_BUFFER)) { @@ -5926,10 +5936,12 @@ class JoglPipeline extends Pipeline { int imgXOffset, int imgYOffset, int imgZOffset, int tilew, int tileh, int width, int height, int depth, - int dataType, Object data) { + int dataType, Object data, boolean useAutoMipMap) { + + /* Note: useAutoMipMap is not use for SubImage in the jogl pipe */ + if (VERBOSE) System.err.println("JoglPipeline.updateTexture3DSubImage()"); - /* TODO Chien : Need to support INT, and NIO buffers */ GL gl = context(ctx).getGL(); int format = 0; @@ -6193,12 +6205,12 @@ class JoglPipeline extends Pipeline { int textureFormat, int imageFormat, int width, int height, int boundaryWidth, - int dataType, Object data) { + int dataType, Object data, boolean useAutoMipMap) { if (VERBOSE) System.err.println("JoglPipeline.updateTextureCubeMapImage()"); updateTexture2DImage(ctx, _gl_textureCubeMapFace[face], numLevels, level, textureFormat, imageFormat, - width, height, boundaryWidth, dataType, data); + width, height, boundaryWidth, dataType, data, useAutoMipMap); } void updateTextureCubeMapSubImage(Context ctx, @@ -6206,7 +6218,10 @@ class JoglPipeline extends Pipeline { int textureFormat,int imageFormat, int imgXOffset, int imgYOffset, int tilew, int width, int height, - int dataType, Object data) { + int dataType, Object data, boolean useAutoMipMap) { + + /* Note: useAutoMipMap is not use for SubImage in the jogl pipe */ + if (VERBOSE) System.err.println("JoglPipeline.updateTextureCubeMapSubImage()"); updateTexture2DSubImage(ctx, _gl_textureCubeMapFace[face], @@ -6301,7 +6316,8 @@ class JoglPipeline extends Pipeline { int height, int boundaryWidth, int dataType, - Object data) { + Object data, + boolean useAutoMipMap) { GL gl = context(ctx).getGL(); int format = 0, internalFormat = 0; @@ -6331,6 +6347,13 @@ class JoglPipeline extends Pipeline { assert false; } + if (useAutoMipMap) { + gl.glTexParameteri(target, GL.GL_GENERATE_MIPMAP, GL.GL_TRUE); + } + else { + gl.glTexParameteri(target, GL.GL_GENERATE_MIPMAP, GL.GL_FALSE); + } + if((dataType == ImageComponentRetained.IMAGE_DATA_TYPE_BYTE_ARRAY) || (dataType == ImageComponentRetained.IMAGE_DATA_TYPE_BYTE_BUFFER)) { @@ -6373,17 +6396,16 @@ class JoglPipeline extends Pipeline { return; } - if(dataType == ImageComponentRetained.IMAGE_DATA_TYPE_BYTE_ARRAY) { - - gl.glTexImage2D(target, level, internalFormat, - width, height, boundaryWidth, - format, GL.GL_UNSIGNED_BYTE, ByteBuffer.wrap((byte[])data)); - } - else { - gl.glTexImage2D(target, level, internalFormat, - width, height, boundaryWidth, - format, GL.GL_UNSIGNED_BYTE, (Buffer) data); - } + if(dataType == ImageComponentRetained.IMAGE_DATA_TYPE_BYTE_ARRAY) { + + gl.glTexImage2D(target, level, internalFormat, + width, height, boundaryWidth, + format, GL.GL_UNSIGNED_BYTE, ByteBuffer.wrap((byte[])data)); + } else { + gl.glTexImage2D(target, level, internalFormat, + width, height, boundaryWidth, + format, GL.GL_UNSIGNED_BYTE, (Buffer) data); + } } else if((dataType == ImageComponentRetained.IMAGE_DATA_TYPE_INT_ARRAY) || (dataType == ImageComponentRetained.IMAGE_DATA_TYPE_INT_BUFFER)) { @@ -6421,16 +6443,15 @@ class JoglPipeline extends Pipeline { gl.glPixelTransferf(GL.GL_ALPHA_BIAS, 1.0f); } - if(dataType == ImageComponentRetained.IMAGE_DATA_TYPE_INT_ARRAY) { - gl.glTexImage2D(target, level, internalFormat, - width, height, boundaryWidth, - format, type, IntBuffer.wrap((int[])data)); - } - else { - gl.glTexImage2D(target, level, internalFormat, - width, height, boundaryWidth, - format, type, (Buffer) data); - } + if(dataType == ImageComponentRetained.IMAGE_DATA_TYPE_INT_ARRAY) { + gl.glTexImage2D(target, level, internalFormat, + width, height, boundaryWidth, + format, type, IntBuffer.wrap((int[])data)); + } else { + gl.glTexImage2D(target, level, internalFormat, + width, height, boundaryWidth, + format, type, (Buffer) data); + } /* Restore Alpha scale and bias */ if(forceAlphaToOne) { @@ -7953,10 +7974,10 @@ class JoglPipeline extends Pipeline { gl.glPixelStorei(GL.GL_UNPACK_ALIGNMENT, 1); gl.glBindTexture(GL.GL_TEXTURE_2D, objectId); // set up texture parameter - gl.glTexParameterf(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_NEAREST); - gl.glTexParameterf(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MIN_FILTER, GL.GL_NEAREST); - gl.glTexParameterf(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_S, GL.GL_REPEAT); - gl.glTexParameterf(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_T, GL.GL_REPEAT); + gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_NEAREST); + gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MIN_FILTER, GL.GL_NEAREST); + gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_S, GL.GL_REPEAT); + gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_T, GL.GL_REPEAT); gl.glTexEnvf(GL.GL_TEXTURE_ENV, GL.GL_TEXTURE_ENV_MODE, GL.GL_REPLACE); gl.glEnable(GL.GL_BLEND); diff --git a/src/classes/share/javax/media/j3d/ExceptionStrings.properties b/src/classes/share/javax/media/j3d/ExceptionStrings.properties index 8d13787..4e65926 100644 --- a/src/classes/share/javax/media/j3d/ExceptionStrings.properties +++ b/src/classes/share/javax/media/j3d/ExceptionStrings.properties @@ -812,6 +812,7 @@ Texture44=Texture: no capability to set lod offset Texture45=Texture: no capability to get lod offset Texture46=Texture: illegal width < 1 Texture47=Texture: illegal height < 1 +Texture48=Texture: maximumLevel must be zero if mipmapMode is BASE_LEVEL Texture2D0=Texture: no capability to get detail texture information Texture2D1=Texture: Illegal detail texture mode value Texture2D2=Texture: Illegal detail texture level diff --git a/src/classes/share/javax/media/j3d/NativePipeline.java b/src/classes/share/javax/media/j3d/NativePipeline.java index 97a478a..f8ca815 100644 --- a/src/classes/share/javax/media/j3d/NativePipeline.java +++ b/src/classes/share/javax/media/j3d/NativePipeline.java @@ -2276,20 +2276,20 @@ class NativePipeline extends Pipeline { int textureFormat, int imageFormat, int width, int height, int boundaryWidth, - int imageDataType, Object data); + int imageDataType, Object data, boolean useAutoMipMap); void updateTexture2DImage(Context ctx, int numLevels, int level, int textureFormat, int imageFormat, int width, int height, int boundaryWidth, - int imageDataType, Object data) { + int imageDataType, Object data, boolean useAutoMipMap) { updateTexture2DImage(unbox(ctx), numLevels, level, textureFormat, imageFormat, width, height, boundaryWidth, - imageDataType, data); + imageDataType, data, useAutoMipMap); } native void updateTexture2DSubImage(long ctx, @@ -2297,20 +2297,20 @@ class NativePipeline extends Pipeline { int textureFormat, int imageFormat, int imgXOffset, int imgYOffset, int tilew, int width, int height, - int imageDataType, Object data); + int imageDataType, Object data, boolean useAutoMipMap); void updateTexture2DSubImage(Context ctx, int level, int xoffset, int yoffset, int textureFormat, int imageFormat, int imgXOffset, int imgYOffset, int tilew, int width, int height, - int imageDataType, Object data) { + int imageDataType, Object data, boolean useAutoMipMap) { updateTexture2DSubImage(unbox(ctx), level, xoffset, yoffset, textureFormat, imageFormat, imgXOffset, imgYOffset, tilew, width, height, - imageDataType, data); + imageDataType, data, useAutoMipMap); } native void updateTexture2DLodRange(long ctx, @@ -2409,20 +2409,20 @@ class NativePipeline extends Pipeline { int textureFormat, int imageFormat, int width, int height, int depth, int boundaryWidth, - int imageDataType, Object imageData); + int imageDataType, Object imageData, boolean useAutoMipMap); void updateTexture3DImage(Context ctx, int numLevels, int level, int textureFormat, int imageFormat, int width, int height, int depth, int boundaryWidth, - int imageDataType, Object imageData) { + int imageDataType, Object imageData, boolean useAutoMipMap) { updateTexture3DImage(unbox(ctx), numLevels, level, textureFormat, imageFormat, width, height, depth, boundaryWidth, - imageDataType, imageData); + imageDataType, imageData, useAutoMipMap); } native void updateTexture3DSubImage(long ctx, @@ -2432,7 +2432,7 @@ class NativePipeline extends Pipeline { int imgXoffset, int imgYoffset, int imgZoffset, int tilew, int tileh, int width, int height, int depth, - int imageDataType, Object imageData); + int imageDataType, Object imageData, boolean useAutoMipMap); void updateTexture3DSubImage(Context ctx, int level, @@ -2441,7 +2441,7 @@ class NativePipeline extends Pipeline { int imgXoffset, int imgYoffset, int imgZoffset, int tilew, int tileh, int width, int height, int depth, - int imageDataType, Object imageData) { + int imageDataType, Object imageData, boolean useAutoMipMap) { updateTexture3DSubImage(unbox(ctx), level, xoffset, yoffset, zoffset, @@ -2449,7 +2449,7 @@ class NativePipeline extends Pipeline { imgXoffset, imgYoffset, imgZoffset, tilew, tileh, width, height, depth, - imageDataType, imageData); + imageDataType, imageData, useAutoMipMap); } native void updateTexture3DLodRange(long ctx, @@ -2552,20 +2552,20 @@ class NativePipeline extends Pipeline { int textureFormat, int imageFormat, int width, int height, int boundaryWidth, - int imageDataType, Object imageData); + int imageDataType, Object imageData, boolean useAutoMipMap); void updateTextureCubeMapImage(Context ctx, int face, int numLevels, int level, int textureFormat, int imageFormat, int width, int height, int boundaryWidth, - int imageDataType, Object imageData) { + int imageDataType, Object imageData, boolean useAutoMipMap) { updateTextureCubeMapImage(unbox(ctx), face, numLevels, level, textureFormat, imageFormat, width, height, boundaryWidth, - imageDataType, imageData); + imageDataType, imageData, useAutoMipMap); } native void updateTextureCubeMapSubImage(long ctx, @@ -2573,20 +2573,20 @@ class NativePipeline extends Pipeline { int textureFormat, int imageFormat, int imgXOffset, int imgYOffset, int tilew, int width, int height, - int imageDataType, Object imageData); + int imageDataType, Object imageData, boolean useAutoMipMap); void updateTextureCubeMapSubImage(Context ctx, int face, int level, int xoffset, int yoffset, int textureFormat, int imageFormat, int imgXOffset, int imgYOffset, int tilew, int width, int height, - int imageDataType, Object imageData) { + int imageDataType, Object imageData, boolean useAutoMipMap) { updateTextureCubeMapSubImage(unbox(ctx), face, level, xoffset, yoffset, textureFormat, imageFormat, imgXOffset, imgYOffset, tilew, width, height, - imageDataType, imageData); + imageDataType, imageData, useAutoMipMap); } native void updateTextureCubeMapLodRange(long ctx, diff --git a/src/classes/share/javax/media/j3d/NoopPipeline.java b/src/classes/share/javax/media/j3d/NoopPipeline.java index 316df5f..394281e 100644 --- a/src/classes/share/javax/media/j3d/NoopPipeline.java +++ b/src/classes/share/javax/media/j3d/NoopPipeline.java @@ -978,7 +978,7 @@ class NoopPipeline extends Pipeline { int textureFormat, int imageFormat, int width, int height, int boundaryWidth, - int imageDataType, Object data) { + int imageDataType, Object data, boolean useAutoMipMap) { } void updateTexture2DSubImage(Context ctx, @@ -986,7 +986,7 @@ class NoopPipeline extends Pipeline { int textureFormat, int imageFormat, int imgXOffset, int imgYOffset, int tilew, int width, int height, - int imageDataType, Object data) { + int imageDataType, Object data, boolean useAutoMipMap) { } void updateTexture2DLodRange(Context ctx, @@ -1037,7 +1037,7 @@ class NoopPipeline extends Pipeline { int textureFormat, int imageFormat, int width, int height, int depth, int boundaryWidth, - int imageDataType, Object imageData) { + int imageDataType, Object imageData, boolean useAutoMipMap) { } void updateTexture3DSubImage(Context ctx, @@ -1047,7 +1047,7 @@ class NoopPipeline extends Pipeline { int imgXoffset, int imgYoffset, int imgZoffset, int tilew, int tileh, int width, int height, int depth, - int imageTypeData, Object imageData) { + int imageTypeData, Object imageData, boolean useAutoMipMap) { } void updateTexture3DLodRange(Context ctx, @@ -1099,7 +1099,7 @@ class NoopPipeline extends Pipeline { int textureFormat, int imageFormat, int width, int height, int boundaryWidth, - int imageDataType, Object imageData) { + int imageDataType, Object imageData, boolean useAutoMipMap) { } void updateTextureCubeMapSubImage(Context ctx, @@ -1107,7 +1107,7 @@ class NoopPipeline extends Pipeline { int textureFormat, int imageFormat, int imgXOffset, int imgYOffset, int tilew, int width, int height, - int imageDataType, Object imageData) { + int imageDataType, Object imageData, boolean useAutoMipMap) { } void updateTextureCubeMapLodRange(Context ctx, diff --git a/src/classes/share/javax/media/j3d/Pipeline.java b/src/classes/share/javax/media/j3d/Pipeline.java index f20628a..380e756 100644 --- a/src/classes/share/javax/media/j3d/Pipeline.java +++ b/src/classes/share/javax/media/j3d/Pipeline.java @@ -1067,14 +1067,14 @@ abstract class Pipeline { int textureFormat, int imageFormat, int width, int height, int boundaryWidth, - int imageDataType, Object data); + int imageDataType, Object data, boolean useAutoMipMap); abstract void updateTexture2DSubImage(Context ctx, int level, int xoffset, int yoffset, int textureFormat, int imageFormat, int imgXOffset, int imgYOffset, int tilew, int width, int height, - int imageDataType, Object data); + int imageDataType, Object data, boolean useAutoMipMap); abstract void updateTexture2DLodRange(Context ctx, int baseLevel, int maximumLevel, @@ -1116,7 +1116,7 @@ abstract class Pipeline { int textureFormat, int imageFormat, int width, int height, int depth, int boundaryWidth, - int imageDataType, Object imageData); + int imageDataType, Object imageData, boolean useAutoMipMap); abstract void updateTexture3DSubImage(Context ctx, int level, @@ -1125,7 +1125,7 @@ abstract class Pipeline { int imgXoffset, int imgYoffset, int imgZoffset, int tilew, int tileh, int width, int height, int depth, - int imageDataType, Object imageData); + int imageDataType, Object imageData, boolean useAutoMipMap); abstract void updateTexture3DLodRange(Context ctx, int baseLevel, int maximumLevel, @@ -1168,14 +1168,14 @@ abstract class Pipeline { int textureFormat, int imageFormat, int width, int height, int boundaryWidth, - int imageDataType, Object imageData); + int imageDataType, Object imageData, boolean useAutoMipMap); abstract void updateTextureCubeMapSubImage(Context ctx, int face, int level, int xoffset, int yoffset, int textureFormat, int imageFormat, int imgXOffset, int imgYOffset, int tilew, int width, int height, - int imageDataType, Object imageData); + int imageDataType, Object imageData, boolean useAutoMipMap); abstract void updateTextureCubeMapLodRange(Context ctx, int baseLevel, int maximumLevel, diff --git a/src/classes/share/javax/media/j3d/Texture.java b/src/classes/share/javax/media/j3d/Texture.java index 5d7bc2c..3e9086d 100644 --- a/src/classes/share/javax/media/j3d/Texture.java +++ b/src/classes/share/javax/media/j3d/Texture.java @@ -849,7 +849,7 @@ public abstract class Texture extends NodeComponent { * @param magFilter the magnification filter, one of: * FASTEST, NICEST, BASE_LEVEL_POINT, BASE_LEVEL_LINEAR, * LINEAR_SHARPEN, LINEAR_SHARPEN_RGB, LINEAR_SHARPEN_ALPHA, or FILTER4. - * + * * @exception RestrictedAccessException if the method is called * when this object is part of live or compiled scene graph. * @exception IllegalArgumentException if <code>magFilter</code> @@ -1311,6 +1311,8 @@ public abstract class Texture extends NodeComponent { * @exception IllegalArgumentException if specified * maximumLevel < baseLevel, or * if maximumLevel > <code>log<sub><font size=-2>2</font></sub>(max(width,height))</code> + * @exception IllegalArgumentException if mipMipMapMode is equal to BASE_LEVEL + * and maximumLevel is not equal to zero. * * @since Java 3D 1.3 * @see Canvas3D#queryProperties diff --git a/src/classes/share/javax/media/j3d/Texture3DRetained.java b/src/classes/share/javax/media/j3d/Texture3DRetained.java index 7be22dc..e79d537 100644 --- a/src/classes/share/javax/media/j3d/Texture3DRetained.java +++ b/src/classes/share/javax/media/j3d/Texture3DRetained.java @@ -110,11 +110,14 @@ class Texture3DRetained extends TextureRetained { int boundaryWidth, int imageDataType, Object imageData) { + boolean useAutoMipMap = useAutoMipMapGeneration && ((cv.textureExtendedFeatures & + Canvas3D.TEXTURE_AUTO_MIPMAP_GENERATION) != 0); + Pipeline.getPipeline().updateTexture3DImage(cv.ctx, numLevels, level, textureFormat, imageFormat, width, height, depth, - boundaryWidth, imageDataType, imageData); + boundaryWidth, imageDataType, imageData, useAutoMipMap); } // Wrapper around the native call for 3D textures @@ -125,13 +128,16 @@ class Texture3DRetained extends TextureRetained { int imgXOffset, int imgYOffset, int imgZOffset, int tilew, int tileh, int width, int height, int depth, int imageDataType, Object imageData) { + + boolean useAutoMipMap = useAutoMipMapGeneration && ((cv.textureExtendedFeatures & + Canvas3D.TEXTURE_AUTO_MIPMAP_GENERATION) != 0); Pipeline.getPipeline().updateTexture3DSubImage(cv.ctx, level, xoffset, yoffset, zoffset, textureFormat, imageFormat, imgXOffset, imgYOffset, imgZOffset, tilew, tileh, width, height, depth, - imageDataType, imageData); + imageDataType, imageData, useAutoMipMap); } diff --git a/src/classes/share/javax/media/j3d/TextureCubeMapRetained.java b/src/classes/share/javax/media/j3d/TextureCubeMapRetained.java index 5142241..7fa84e3 100644 --- a/src/classes/share/javax/media/j3d/TextureCubeMapRetained.java +++ b/src/classes/share/javax/media/j3d/TextureCubeMapRetained.java @@ -298,8 +298,6 @@ class TextureCubeMapRetained extends TextureRetained { } } - - // This is just a wrapper of the native method. void updateTextureImage(Canvas3D cv, int face, int numLevels, int level, @@ -308,11 +306,14 @@ class TextureCubeMapRetained extends TextureRetained { int boundaryWidth, int imageDataType, Object imageData) { + boolean useAutoMipMap = useAutoMipMapGeneration && ((cv.textureExtendedFeatures & + Canvas3D.TEXTURE_AUTO_MIPMAP_GENERATION) != 0); + Pipeline.getPipeline().updateTextureCubeMapImage(cv.ctx, face, numLevels, level, textureFormat, imageFormat, width, height, - boundaryWidth, imageDataType, imageData); + boundaryWidth, imageDataType, imageData, useAutoMipMap); } // This is just a wrapper of the native method. @@ -324,12 +325,15 @@ class TextureCubeMapRetained extends TextureRetained { int tilew, int width, int height, int imageDataType, Object imageData) { + boolean useAutoMipMap = useAutoMipMapGeneration && ((cv.textureExtendedFeatures & + Canvas3D.TEXTURE_AUTO_MIPMAP_GENERATION) != 0); + Pipeline.getPipeline().updateTextureCubeMapSubImage(cv.ctx, face, level, xoffset, yoffset, textureFormat, imageFormat, imgXOffset, imgYOffset, tilew, width, height, - imageDataType, imageData); + imageDataType, imageData, useAutoMipMap); } } diff --git a/src/classes/share/javax/media/j3d/TextureRetained.java b/src/classes/share/javax/media/j3d/TextureRetained.java index 43aef4d..95dd1f6 100644 --- a/src/classes/share/javax/media/j3d/TextureRetained.java +++ b/src/classes/share/javax/media/j3d/TextureRetained.java @@ -74,11 +74,11 @@ abstract class TextureRetained extends NodeComponentRetained { // Array of images (one for each mipmap level) ImageComponentRetained images[][]; // maximum number of levels needed for the mipmapMode of this texture - int maxLevels = 0; + int maxLevels = 0; // maximum number of mipmap levels that can be defined for this texture private int maxMipMapLevels = 0; // true if hardware auto mipmap generation is requested. - private boolean useAutoMipMapGeneration = false; + boolean useAutoMipMapGeneration = false; int numFaces = 1; // For CubeMap, it is 6 int baseLevel = 0; @@ -678,11 +678,16 @@ abstract class TextureRetained extends NodeComponentRetained { final void initMaximumLevel(int level) { - if ((level < baseLevel) || (level >= maxMipMapLevels)) { - throw new IllegalArgumentException( - J3dI18N.getString("Texture37")); - } - maximumLevel = level; + if ((level < baseLevel) || (level >= maxMipMapLevels)) { + throw new IllegalArgumentException( + J3dI18N.getString("Texture37")); + } + if((mipmapMode == Texture.BASE_LEVEL) && (level != 0)) { + throw new IllegalArgumentException( + J3dI18N.getString("Texture48")); + } + + maximumLevel = level; } final void setMaximumLevel(int level) { @@ -1140,7 +1145,16 @@ abstract class TextureRetained extends NodeComponentRetained { void updateTextureLOD(Canvas3D cv) { if ((cv.textureExtendedFeatures & Canvas3D.TEXTURE_LOD_RANGE) != 0 ) { - updateTextureLodRange(cv.ctx, baseLevel, maximumLevel, + + int max = 0; + if( mipmapMode == Texture.BASE_LEVEL ) { + max = maxMipMapLevels; + } + else { + max = maximumLevel; + } + + updateTextureLodRange(cv.ctx, baseLevel, max, minimumLod, maximumLod); } @@ -1163,7 +1177,7 @@ abstract class TextureRetained extends NodeComponentRetained { int magnificationFilter = magFilter; int minificationFilter = minFilter; - + // update sharpen texture function if applicable if ((magFilter >= Texture.LINEAR_SHARPEN) && @@ -1228,8 +1242,19 @@ abstract class TextureRetained extends NodeComponentRetained { } } + // Fallback to BASE mode if hardware mipmap generation is not supported. + if (useAutoMipMapGeneration && ((cv.textureExtendedFeatures & + Canvas3D.TEXTURE_AUTO_MIPMAP_GENERATION) == 0)) { + + if (minFilter == Texture.NICEST || + minFilter == Texture.MULTI_LEVEL_LINEAR) { + minificationFilter = Texture.BASE_LEVEL_LINEAR; + } else if (minFilter == Texture.MULTI_LEVEL_POINT) { + minificationFilter = Texture.BASE_LEVEL_POINT; + } + } + // update texture filtering modes - updateTextureFilterModes(cv.ctx, minificationFilter, magnificationFilter); @@ -1250,23 +1275,26 @@ abstract class TextureRetained extends NodeComponentRetained { // Wrapper around the native call for 2D textures; overridden for - // Texture3D and TextureCureMap + // TextureCureMap void updateTextureImage(Canvas3D cv, int face, int numLevels, int level, int textureFormat, int imageFormat, int width, int height, int boundaryWidth, int imageDataType, Object data) { - + + boolean useAutoMipMap = useAutoMipMapGeneration && ((cv.textureExtendedFeatures & + Canvas3D.TEXTURE_AUTO_MIPMAP_GENERATION) != 0); + Pipeline.getPipeline().updateTexture2DImage(cv.ctx, numLevels, level, textureFormat, imageFormat, width, height, boundaryWidth, - imageDataType, data); + imageDataType, data, useAutoMipMap); } // Wrapper around the native call for 2D textures; overridden for - // Texture3D and TextureCureMap + // TextureCureMap void updateTextureSubImage(Canvas3D cv, int face, int level, int xoffset, int yoffset, @@ -1275,12 +1303,15 @@ abstract class TextureRetained extends NodeComponentRetained { int tilew, int width, int height, int imageDataType, Object data) { + boolean useAutoMipMap = useAutoMipMapGeneration && ((cv.textureExtendedFeatures & + Canvas3D.TEXTURE_AUTO_MIPMAP_GENERATION) != 0); + Pipeline.getPipeline().updateTexture2DSubImage(cv.ctx, level, xoffset, yoffset, textureFormat, imageFormat, imgXOffset, imgYOffset, tilew, width, height, - imageDataType, data); + imageDataType, data, useAutoMipMap); } @@ -1954,43 +1985,23 @@ abstract class TextureRetained extends NodeComponentRetained { (minFilter == Texture.NICEST || minFilter == Texture.MULTI_LEVEL_POINT || minFilter == Texture.MULTI_LEVEL_LINEAR)) { - // TODO : Should this be 1 ? --- Chien. - // mirrorTexture.maxLevels = maxMipMapLevels; - mirrorTexture.maxLevels = 1; mirrorTexture.useAutoMipMapGeneration = true; - - if ((mirrorTexture.images == null) || - (mirrorTexture.images.length < numFaces) || - !(mirrorTexture.images[0].length == mirrorTexture.maxLevels)) { - mirrorTexture.images = - new ImageComponentRetained[numFaces][mirrorTexture.maxLevels]; - } + } + + mirrorTexture.maxLevels = maxLevels; + if (images != null) { for (int j = 0; j < numFaces; j++) { - mirrorTexture.images[j][0] = images[j][0]; - - // add texture to the userList of the images - if (images[j][0] != null) { - images[j][0].addUser(mirrorTexture); + for (int i = 0; i < maxLevels; i++) { + mirrorTexture.images[j][i] = images[j][i]; + + // add texture to the userList of the images + if (images[j][i] != null) { + images[j][i].addUser(mirrorTexture); + } } - } - } - else { - mirrorTexture.maxLevels = maxLevels; - if (images != null) { - - for (int j = 0; j < numFaces; j++) { - for (int i = 0; i < maxLevels; i++) { - mirrorTexture.images[j][i] = images[j][i]; - - // add texture to the userList of the images - if (images[j][i] != null) { - images[j][i].addUser(mirrorTexture); - } - } - } - } - } + } + } } |