0001: /*
0002: * $RCSfile: Texture.java,v $
0003: *
0004: * Copyright 1996-2008 Sun Microsystems, Inc. All Rights Reserved.
0005: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0006: *
0007: * This code is free software; you can redistribute it and/or modify it
0008: * under the terms of the GNU General Public License version 2 only, as
0009: * published by the Free Software Foundation. Sun designates this
0010: * particular file as subject to the "Classpath" exception as provided
0011: * by Sun in the LICENSE file that accompanied this code.
0012: *
0013: * This code is distributed in the hope that it will be useful, but WITHOUT
0014: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0015: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0016: * version 2 for more details (a copy is included in the LICENSE file that
0017: * accompanied this code).
0018: *
0019: * You should have received a copy of the GNU General Public License version
0020: * 2 along with this work; if not, write to the Free Software Foundation,
0021: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0022: *
0023: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
0024: * CA 95054 USA or visit www.sun.com if you need additional information or
0025: * have any questions.
0026: *
0027: * $Revision: 1.10 $
0028: * $Date: 2008/02/28 20:17:31 $
0029: * $State: Exp $
0030: */
0031:
0032: package javax.media.j3d;
0033:
0034: import javax.vecmath.*;
0035: import java.util.Hashtable;
0036:
0037: /**
0038: * The Texture object is a component object of an Appearance object
0039: * that defines the texture properties used when texture mapping is
0040: * enabled. The Texture object is an abstract class and all texture
0041: * objects must be created as either a Texture2D object or a
0042: * Texture3D object.
0043: * <P>
0044: * Each Texture object has the following properties:<P>
0045: * <UL>
0046: * <LI>Boundary color - the texture boundary color. The texture
0047: * boundary color is used when the boundaryModeS and boundaryModeT
0048: * parameters are set to CLAMP or CLAMP_TO_BOUNDARY and if the texture
0049: * boundary is not specified. </LI><P>
0050: * <LI>Boundary Width - the texture boundary width, which must be 0 or 1.
0051: * If the texture boundary
0052: * width is 1, then all images for all mipmap levels will include a border.
0053: * The actual texture image for level 0, for example, will be of
0054: * dimension (width + 2*boundaryWidth) * (height + 2*boundaryWidth).
0055: * The boundary texels will be used when linear filtering is to be applied.
0056: * </LI><p>
0057: * <LI>Boundary ModeS and Boundary ModeT - the boundary mode for the
0058: * S and T coordinates, respectively. The boundary modes are as
0059: * follows:</LI><P>
0060: * <UL>
0061: * <LI>CLAMP - clamps texture coordinates to be in the range [0,1].
0062: * Texture boundary texels or the constant boundary color if boundary width
0063: * is 0 will be used for U,V values that fall outside this range.</LI><P>
0064: * <LI>WRAP - repeats the texture by wrapping texture coordinates
0065: * that are outside the range [0,1]. Only the fractional portion
0066: * of the texture coordinates is used. The integer portion is
0067: * discarded</LI><P>
0068: * <LI>CLAMP_TO_EDGE - clamps texture coordinates such that filtering
0069: * will not sample a texture boundary texel. Texels at the edge of the
0070: * texture will be used instead.</LI><P>
0071: * <LI>CLAMP_TO_BOUNDARY - clamps texture coordinates such that filtering
0072: * will sample only texture boundary texels, that is, it will never
0073: * get some samples from the boundary and some from the edge. This
0074: * will ensure clean unfiltered boundaries. If the texture does not
0075: * have a boundary, that is the boundary width is equal to 0, then the
0076: * constant boundary color will be used.</LI></P>
0077: * </UL>
0078: * <LI>Image - an image or an array of images for all the mipmap
0079: * levels. If only one image is provided, the MIPmap mode must be
0080: * set to BASE_LEVEL.</LI><P>
0081: * <LI>Magnification filter - the magnification filter function.
0082: * Used when the pixel being rendered maps to an area less than or
0083: * equal to one texel. The magnification filter functions are as
0084: * follows:</LI><P>
0085: * <UL>
0086: * <LI>FASTEST - uses the fastest available method for processing
0087: * geometry.</LI><P>
0088: * <LI>NICEST - uses the nicest available method for processing
0089: * geometry.</LI><P>
0090: * <LI>BASE_LEVEL_POINT - selects the nearest texel in the base level
0091: * texture image.</LI><P>
0092: * <LI>BASE_LEVEL_LINEAR - performs a bilinear interpolation on the four
0093: * nearest texels in the base level texture image. The texture value T' is
0094: * computed as follows:</LI><P>
0095: * <UL>
0096: * i<sub>0</sub> = trunc(u - 0.5)<P>
0097: * j<sub>0</sub> = trunc(v - 0.5)<P>
0098: * i<sub>1</sub> = i<sub>0</sub> + 1<P>
0099: * j<sub>1</sub> = j<sub>0</sub> + 1<P>
0100: * a = frac(u - 0.5)<P>
0101: * b = frac(v - 0.5)<P>
0102: * T' = (1-a)*(1-b)*T<sub>i<sub>0</sub>j<sub>0</sub></sub> +
0103: * a*(1-b)*T<sub>i<sub>1</sub>j<sub>0</sub></sub> +
0104: * (1-a)*b*T<sub>i<sub>0</sub>j<sub>1</sub></sub> +
0105: * a*b*T<sub>i<sub>1</sub>j<sub>1</sub></sub><P>
0106: * </UL>
0107: * <LI>LINEAR_SHARPEN - sharpens the resulting image by extrapolating
0108: * from the base level plus one image to the base level image of this
0109: * texture object.</LI><P>
0110: * <LI>LINEAR_SHARPEN_RGB - performs linear sharpen filter for the rgb
0111: * components only. The alpha component is computed using BASE_LEVEL_LINEAR
0112: * filter.</LI><P>
0113: * <LI>LINEAR_SHARPEN_ALPHA - performs linear sharpen filter for the alpha
0114: * component only. The rgb components are computed using BASE_LEVEL_LINEAR
0115: * filter.</LI><P>
0116: * <LI>FILTER4 - applies an application-supplied weight function
0117: * on the nearest 4x4 texels in the base level texture image. The
0118: * texture value T' is computed as follows:</LI><P>
0119: * <UL>
0120: * <table cellspacing=10>
0121: * <td>i<sub>1</sub> = trunc(u - 0.5)</td>
0122: * <td>i<sub>2</sub> = i<sub>1</sub> + 1</td>
0123: * <td>i<sub>3</sub> = i<sub>2</sub> + 1</td>
0124: * <td>i<sub>0</sub> = i<sub>1</sub> - 1</td>
0125: * <tr>
0126: * <td>j<sub>1</sub> = trunc(v - 0.5)</td>
0127: * <td>j<sub>3</sub> = j<sub>2</sub> + 1</td>
0128: * <td>j<sub>2</sub> = j<sub>1</sub> + 1</td>
0129: * <td>j<sub>0</sub> = j<sub>1</sub> - 1</td>
0130: * <tr>
0131: * <td>a = frac(u - 0.5)</td>
0132: * <tr>
0133: * <td>b = frac(v - 0.5)</td>
0134: * </table>
0135: * f(x) : filter4 function where 0<=x<=2<P>
0136: * T' = f(1+a) * f(1+b) * T<sub>i<sub>0</sub>j<sub>0</sub></sub> +
0137: * f(a) * f(1+b) * T<sub>i<sub>1</sub>j<sub>0</sub></sub> +
0138: * f(1-a) * f(1+b) * T<sub>i<sub>2</sub>j<sub>0</sub></sub> +
0139: * f(2-a) * f(1+b) * T<sub>i<sub>3</sub>j<sub>0</sub></sub> + <br>
0140: * f(1+a) * f(b) * T<sub>i<sub>0</sub>j<sub>1</sub></sub> +
0141: * f(a) * f(b) * T<sub>i<sub>1</sub>j<sub>1</sub></sub> +
0142: * f(1-a) * f(b) * T<sub>i<sub>2</sub>j<sub>1</sub></sub> +
0143: * f(2-a) * f(b) * T<sub>i<sub>3</sub>j<sub>1</sub></sub> + <br>
0144: * f(1+a) * f(1-b) * T<sub>i<sub>0</sub>j<sub>2</sub></sub> +
0145: * f(a) * f(1-b) * T<sub>i<sub>1</sub>j<sub>2</sub></sub> +
0146: * f(1-a) * f(1-b) * T<sub>i<sub>2</sub>j<sub>2</sub></sub> +
0147: * f(2-a) * f(1-b) * T<sub>i<sub>3</sub>j<sub>2</sub></sub> + <br>
0148: * f(1+a) * f(2-b) * T<sub>i<sub>0</sub>j<sub>3</sub></sub> +
0149: * f(a) * f(2-b) * T<sub>i<sub>1</sub>j<sub>3</sub></sub> +
0150: * f(1-a) * f(2-b) * T<sub>i<sub>2</sub>j<sub>3</sub></sub> +
0151: * f(2-a) * f(2-b) * T<sub>i<sub>3</sub>j<sub>3</sub></sub> <P>
0152: * </UL>
0153: * </UL>
0154: * <LI>Minification filter - the minification filter function. Used
0155: * when the pixel being rendered maps to an area greater than one
0156: * texel. The minifaction filter functions are as follows:</LI><P>
0157: * <UL>
0158: * <LI>FASTEST - uses the fastest available method for processing
0159: * geometry.</LI><P>
0160: * <LI>NICEST - uses the nicest available method for processing
0161: * geometry.</LI><P>
0162: * <LI>BASE_LEVEL_POINT - selects the nearest level in the base level
0163: * texture map.</LI><P>
0164: *<LI>BASE_LEVEL_LINEAR - performs a bilinear interpolation on the four
0165: * nearest texels in the base level texture map.</LI><P>
0166: * <LI>MULTI_LEVEL_POINT - selects the nearest texel in the nearest
0167: * mipmap.</LI><P>
0168: * <LI>MULTI_LEVEL_LINEAR - performs trilinear interpolation of texels
0169: * between four texels each from the two nearest mipmap levels.</LI><P>
0170: * <LI>FILTER4 - applies an application-supplied weight function
0171: * on the nearest 4x4 texels in the base level texture image.</LI><P>
0172: * </UL>
0173: * <LI>MIPmap mode - the mode used for texture mapping for this
0174: * object. The mode is one of the following:</LI><P>
0175: * <UL>
0176: * <LI>BASE_LEVEL - indicates that this Texture object only has a
0177: * base-level image. If multiple levels are needed, they will be
0178: * implicitly computed.</LI><P>
0179: * <LI>MULTI_LEVEL_MIPMAP - indicates that this Texture object has
0180: * multiple images. If MIPmap mode is set
0181: * to MULTI_LEVEL_MIPMAP, images for Base Level through Max Level
0182: * must be set.</LI><P>
0183: * </UL>
0184: * <LI>Format - the data format. The format is one of the
0185: * following:</LI><P>
0186: * <UL>
0187: * <LI>INTENSITY - the texture image contains only texture
0188: * values.</LI><P>
0189: * <LI>LUMINANCE - the texture image contains only
0190: * luminance values.</LI><P>
0191: * <LI>ALPHA - the texture image contains only alpha
0192: * values.</LI><P>
0193: * <LI>LUMINANCE_ALPHA - the texture image contains
0194: * both luminance and alpha values.</LI><P>
0195: * <LI>RGB - the texture image contains red, green,
0196: * and blue values.</LI><P>
0197: * <LI>RGBA - the texture image contains red, green, blue, and alpha
0198: * values.</LI><P></UL>
0199: * <LI>Base Level - specifies the mipmap level to be used when filter
0200: * specifies BASE_LEVEL_POINT or BASE_LEVEL_LINEAR.</LI><P>
0201: * <LI>Maximum Level - specifies the maximum level of image that needs to be
0202: * defined for this texture to be valid. Note, for this texture to be valid,
0203: * images for Base Level through Maximum Level have to be defined.</LI><P>
0204: * <LI>Minimum LOD - specifies the minimum of the LOD range. LOD smaller
0205: * than this value will be clamped to this value.</LI><P>
0206: * <LI>Maximum LOD - specifies the maximum of the LOD range. LOD larger
0207: * than this value will be clamped to this value.</LI><P>
0208: * <LI>LOD offset - specifies the offset to be used in the LOD calculation
0209: * to compensate for under or over sampled texture images.</LI></P>
0210: * <LI>Anisotropic Mode - defines how anisotropic filter is applied for
0211: * this texture object. The anisotropic modes are as follows:</LI><P>
0212: * <UL>
0213: * <LI>ANISOTROPIC_NONE - no anisotropic filtering.</LI><P>
0214: * <LI>ANISOTROPIC_SINGLE_VALUE - applies the degree of anisotropic filter
0215: * in both the minification and magnification filters.</LI><P>
0216: * </UL>
0217: * <LI>Anisotropic Filter Degree - controls the degree of anisotropy. This
0218: * property applies to both minification and magnification filtering.
0219: * If it is equal to 1.0, then an isotropic filtering as specified in the
0220: * minification or magnification filter will be used. If it is greater
0221: * than 1.0, and the anisotropic mode is equal to ANISOTROPIC_SINGLE_VALUE,
0222: * then
0223: * the degree of anisotropy will also be applied in the filtering.</LI><P>
0224: * <LI>Sharpen Texture Function - specifies the function of level-of-detail
0225: * used in combining the texture value computed from the base level image
0226: * and the texture value computed from the base level plus one image. The
0227: * final texture value is computed as follows: </LI><P>
0228: * <UL>
0229: * T' = ((1 + SharpenFunc(LOD)) * T<sub>BaseLevel</sub>) - (SharpenFunc(LOD) * T<sub>BaseLevel+1</sub>) <P>
0230: * </UL>
0231: * <LI>Filter4 Function - specifies the function to be applied to the
0232: * nearest 4x4 texels. This property includes samples of the filter
0233: * function f(x), 0<=x<=2. The number of function values supplied
0234: * has to be equal to 2<sup>m</sup> + 1 for some integer value of m
0235: * greater than or equal to 4. </LI><P>
0236: * </UL>
0237: *
0238: * <p>
0239: * Note that as of Java 3D 1.5, the texture width and height are no longer
0240: * required to be an exact power of two. However, not all graphics devices
0241: * supports non-power-of-two textures. If non-power-of-two texture mapping is
0242: * unsupported on a particular Canvas3D, textures with a width or height that
0243: * are not an exact power of two are ignored for that canvas.
0244: *
0245: * @see Canvas3D#queryProperties
0246: */
0247: public abstract class Texture extends NodeComponent {
0248: /**
0249: * Specifies that this Texture object allows reading its
0250: * enable flag.
0251: */
0252: public static final int ALLOW_ENABLE_READ = CapabilityBits.TEXTURE_ALLOW_ENABLE_READ;
0253:
0254: /**
0255: * Specifies that this Texture object allows writing its
0256: * enable flag.
0257: */
0258: public static final int ALLOW_ENABLE_WRITE = CapabilityBits.TEXTURE_ALLOW_ENABLE_WRITE;
0259:
0260: /**
0261: * Specifies that this Texture object allows reading its
0262: * boundary mode information.
0263: */
0264: public static final int ALLOW_BOUNDARY_MODE_READ = CapabilityBits.TEXTURE_ALLOW_BOUNDARY_MODE_READ;
0265:
0266: /**
0267: * Specifies that this Texture object allows reading its
0268: * filter information.
0269: */
0270: public static final int ALLOW_FILTER_READ = CapabilityBits.TEXTURE_ALLOW_FILTER_READ;
0271:
0272: /**
0273: * Specifies that this Texture object allows reading its
0274: * image component information.
0275: */
0276: public static final int ALLOW_IMAGE_READ = CapabilityBits.TEXTURE_ALLOW_IMAGE_READ;
0277:
0278: /**
0279: * Specifies that this Texture object allows writing its
0280: * image component information.
0281: *
0282: * @since Java 3D 1.2
0283: */
0284: public static final int ALLOW_IMAGE_WRITE = CapabilityBits.TEXTURE_ALLOW_IMAGE_WRITE;
0285:
0286: /**
0287: * Specifies that this Texture object allows reading its
0288: * format information.
0289: *
0290: * @since Java 3D 1.2
0291: */
0292: public static final int ALLOW_FORMAT_READ = CapabilityBits.TEXTURE_ALLOW_FORMAT_READ;
0293:
0294: /**
0295: * Specifies that this Texture object allows reading its
0296: * size information (e.g., width, height, number of mipmap levels,
0297: * boundary width).
0298: *
0299: * @since Java 3D 1.2
0300: */
0301: public static final int ALLOW_SIZE_READ = CapabilityBits.TEXTURE_ALLOW_SIZE_READ;
0302:
0303: /**
0304: * Specifies that this Texture object allows reading its
0305: * mipmap mode information.
0306: */
0307: public static final int ALLOW_MIPMAP_MODE_READ = CapabilityBits.TEXTURE_ALLOW_MIPMAP_MODE_READ;
0308:
0309: /**
0310: * Specifies that this Texture object allows reading its
0311: * boundary color information.
0312: */
0313: public static final int ALLOW_BOUNDARY_COLOR_READ = CapabilityBits.TEXTURE_ALLOW_BOUNDARY_COLOR_READ;
0314:
0315: /**
0316: * Specifies that this Texture object allows reading its LOD range
0317: * information (e.g., base level, maximum level, minimum lod,
0318: * maximum lod, lod offset)
0319: *
0320: * @since Java 3D 1.3
0321: */
0322: public static final int ALLOW_LOD_RANGE_READ = CapabilityBits.TEXTURE_ALLOW_LOD_RANGE_READ;
0323:
0324: /**
0325: * Specifies that this Texture object allows writing its LOD range
0326: * information (e.g., base level, maximum level, minimum lod,
0327: * maximum lod, lod offset)
0328: *
0329: * @since Java 3D 1.3
0330: */
0331: public static final int ALLOW_LOD_RANGE_WRITE = CapabilityBits.TEXTURE_ALLOW_LOD_RANGE_WRITE;
0332:
0333: /**
0334: * Specifies that this Texture object allows reading its anistropic
0335: * filter information (e.g., anisotropic mode, anisotropic filter)
0336: *
0337: * @since Java 3D 1.3
0338: */
0339: public static final int ALLOW_ANISOTROPIC_FILTER_READ = CapabilityBits.TEXTURE_ALLOW_ANISOTROPIC_FILTER_READ;
0340:
0341: /**
0342: * Specifies that this Texture object allows reading its sharpen
0343: * texture function information.
0344: *
0345: * @since Java 3D 1.3
0346: */
0347: public static final int ALLOW_SHARPEN_TEXTURE_READ = CapabilityBits.TEXTURE_ALLOW_SHARPEN_TEXTURE_READ;
0348:
0349: /**
0350: * Specifies that this Texture object allows reading its filter4
0351: * function information.
0352: *
0353: * @since Java 3D 1.3
0354: */
0355: public static final int ALLOW_FILTER4_READ = CapabilityBits.TEXTURE_ALLOW_FILTER4_READ;
0356:
0357: /**
0358: * Uses the fastest available method for processing geometry.
0359: * This value can be used as a parameter to setMinFilter and
0360: * setMagFilter.
0361: * @see #setMinFilter
0362: * @see #setMagFilter
0363: */
0364: public static final int FASTEST = 0;
0365: /**
0366: * Uses the nicest available method for processing geometry.
0367: * This value can be used as a parameter to setMinFilter and
0368: * setMagFilter.
0369: * @see #setMinFilter
0370: * @see #setMagFilter
0371: */
0372: public static final int NICEST = 1;
0373:
0374: /**
0375: * Select the nearest texel in level 0 texture map.
0376: * Maps to NEAREST.
0377: * @see #setMinFilter
0378: * @see #setMagFilter
0379: */
0380: public static final int BASE_LEVEL_POINT = 2;
0381:
0382: /**
0383: * Performs bilinear interpolation on the four nearest texels
0384: * in level 0 texture map.
0385: * Maps to LINEAR.
0386: * @see #setMinFilter
0387: * @see #setMagFilter
0388: */
0389: public static final int BASE_LEVEL_LINEAR = 3;
0390:
0391: /**
0392: * Selects the nearest texel in the nearest mipmap.
0393: * Maps to NEAREST_MIPMAP_NEAREST.
0394: * @see #setMinFilter
0395: */
0396: public static final int MULTI_LEVEL_POINT = 4;
0397:
0398: /**
0399: * Performs tri-linear interpolation of texels between four
0400: * texels each from two nearest mipmap levels.
0401: * Maps to LINEAR_MIPMAP_LINEAR, but an implementation can
0402: * fall back to LINEAR_MIPMAP_NEAREST or NEAREST_MIPMAP_LINEAR.
0403: * @see #setMinFilter
0404: */
0405: public static final int MULTI_LEVEL_LINEAR = 5;
0406:
0407: // NOTE: values 6, 7, and 8 are reserved for the LINEAR_DETAIL*
0408: // filter modes in Texture2D
0409:
0410: /**
0411: * Sharpens the resulting image by extrapolating
0412: * from the base level plus one image to the base level image of this
0413: * texture object.
0414: *
0415: * @since Java 3D 1.3
0416: * @see #setMagFilter
0417: */
0418: public static final int LINEAR_SHARPEN = 9;
0419:
0420: /**
0421: * Performs linear sharpen filter for the rgb
0422: * components only. The alpha component is computed using
0423: * BASE_LEVEL_LINEAR filter.
0424: *
0425: * @since Java 3D 1.3
0426: * @see #setMagFilter
0427: */
0428: public static final int LINEAR_SHARPEN_RGB = 10;
0429:
0430: /**
0431: * Performs linear sharpen filter for the alpha
0432: * component only. The rgb components are computed using
0433: * BASE_LEVEL_LINEAR filter.
0434: *
0435: * @since Java 3D 1.3
0436: * @see #setMagFilter
0437: */
0438: public static final int LINEAR_SHARPEN_ALPHA = 11;
0439:
0440: /**
0441: * Applies an application-supplied weight function
0442: * on the nearest 4x4 texels in the base level texture image.
0443: *
0444: * @since Java 3D 1.3
0445: * @see #setMinFilter
0446: * @see #setMagFilter
0447: */
0448: public static final int FILTER4 = 12;
0449:
0450: // Texture boundary mode parameter values
0451: /**
0452: * Clamps texture coordinates to be in the range [0, 1].
0453: * Texture boundary texels or the constant boundary color if boundary
0454: * width is 0 will be used for U,V values that fall
0455: * outside this range.
0456: */
0457: public static final int CLAMP = 2;
0458: /**
0459: * Repeats the texture by wrapping texture coordinates that are outside
0460: * the range [0,1]. Only the fractional portion of the texture
0461: * coordinates is used; the integer portion is discarded.
0462: */
0463: public static final int WRAP = 3;
0464: /**
0465: * Clamps texture coordinates such that filtering
0466: * will not sample a texture boundary texel. Texels at the edge of the
0467: * texture will be used instead.
0468: *
0469: * @since Java 3D 1.3
0470: */
0471: public static final int CLAMP_TO_EDGE = 4;
0472: /**
0473: * Clamps texture coordinates such that filtering
0474: * will sample only texture boundary texels. If the texture does not
0475: * have a boundary, that is the boundary width is equal to 0, then the
0476: * constant boundary color will be used.</LI></P>
0477: *
0478: * @since Java 3D 1.3
0479: */
0480: public static final int CLAMP_TO_BOUNDARY = 5;
0481:
0482: /**
0483: * Indicates that Texture object only has one level. If multiple
0484: * levels are needed, they will be implicitly computed.
0485: */
0486: public static final int BASE_LEVEL = 1;
0487:
0488: /**
0489: * Indicates that this Texture object has multiple images, one for
0490: * each mipmap level. In this mode, there are
0491: * <code>log<sub><font size=-2>2</font></sub>(max(width,height))+1</code>
0492: * separate images.
0493: */
0494: public static final int MULTI_LEVEL_MIPMAP = 2;
0495:
0496: // Texture format parameter values
0497:
0498: /**
0499: * Specifies Texture contains only Intensity values.
0500: */
0501: public static final int INTENSITY = 1;
0502:
0503: /**
0504: * Specifies Texture contains only luminance values.
0505: */
0506: public static final int LUMINANCE = 2;
0507:
0508: /**
0509: * Specifies Texture contains only Alpha values.
0510: */
0511: public static final int ALPHA = 3;
0512:
0513: /**
0514: * Specifies Texture contains Luminance and Alpha values.
0515: */
0516: public static final int LUMINANCE_ALPHA = 4;
0517:
0518: /**
0519: * Specifies Texture contains Red, Green and Blue color values.
0520: */
0521: public static final int RGB = 5;
0522:
0523: /**
0524: * Specifies Texture contains Red, Green, Blue color values
0525: * and Alpha value.
0526: */
0527: public static final int RGBA = 6;
0528:
0529: /**
0530: * No anisotropic filter.
0531: *
0532: * @since Java 3D 1.3
0533: * @see #setAnisotropicFilterMode
0534: */
0535: public static final int ANISOTROPIC_NONE = 0;
0536:
0537: /**
0538: * Uses the degree of anisotropy in both the minification and
0539: * magnification filters.
0540: *
0541: * @since Java 3D 1.3
0542: * @see #setAnisotropicFilterMode
0543: */
0544: public static final int ANISOTROPIC_SINGLE_VALUE = 1;
0545:
0546: // Array for setting default read capabilities
0547: private static final int[] readCapabilities = {
0548: ALLOW_ANISOTROPIC_FILTER_READ, ALLOW_BOUNDARY_COLOR_READ,
0549: ALLOW_BOUNDARY_MODE_READ, ALLOW_ENABLE_READ,
0550: ALLOW_FILTER4_READ, ALLOW_FILTER_READ, ALLOW_FORMAT_READ,
0551: ALLOW_IMAGE_READ, ALLOW_LOD_RANGE_READ,
0552: ALLOW_MIPMAP_MODE_READ, ALLOW_SHARPEN_TEXTURE_READ,
0553: ALLOW_SIZE_READ };
0554:
0555: /**
0556: * Constructs a Texture object with default parameters.
0557: * The default values are as follows:
0558: * <ul>
0559: * enable flag : true<br>
0560: * width : 0<br>
0561: * height : 0<br>
0562: * mipmap mode : BASE_LEVEL<br>
0563: * format : RGB<br>
0564: * boundary mode S : WRAP<br>
0565: * boundary mode T : WRAP<br>
0566: * min filter : BASE_LEVEL_POINT<br>
0567: * mag filter : BASE_LEVEL_POINT<br>
0568: * boundary color : black (0,0,0,0)<br>
0569: * boundary width : 0<br>
0570: * array of images : null<br>
0571: * baseLevel : 0<br>
0572: * maximumLevel : <code>log<sub><font size=-2>2</font></sub>(max(width,height))</code><br>
0573: * minimumLOD : -1000.0<br>
0574: * maximumLOD : 1000.0<br>
0575: * lod offset : (0, 0, 0)<br>
0576: * anisotropic mode : ANISOTROPIC_NONE<br>
0577: * anisotropic filter : 1.0<br>
0578: * sharpen texture func: null<br>
0579: * filter4 func: null<br>
0580: * </ul>
0581: * <p>
0582: * Note that the default constructor creates a texture object with
0583: * a width and height of 0 and is, therefore, not useful.
0584: */
0585: public Texture() {
0586: // Just use default values
0587: // set default read capabilities
0588: setDefaultReadCapabilities(readCapabilities);
0589: }
0590:
0591: /**
0592: * Constructs an empty Texture object with specified mipMapMode,
0593: * format, width and height. Defaults are used for all other
0594: * parameters. If <code>mipMapMode</code> is set to
0595: * <code>BASE_LEVEL</code>, then the image at level 0 must be set
0596: * by the application (using either the <code>setImage</code> or
0597: * <code>setImages</code> method). If <code>mipMapMode</code> is
0598: * set to <code>MULTI_LEVEL_MIPMAP</code>, then images for levels
0599: * Base Level through Maximum Level must be set.
0600: * Note that a texture with a non-power-of-two width or height will
0601: * only be rendered on a graphics device that supports non-power-of-two
0602: * textures.
0603: *
0604: * @param mipMapMode type of mipmap for this Texture: one of
0605: * BASE_LEVEL, MULTI_LEVEL_MIPMAP
0606: * @param format data format of Textures saved in this object.
0607: * One of INTENSITY, LUMINANCE, ALPHA, LUMINANCE_ALPHA, RGB, RGBA
0608: * @param width width of image at level 0.
0609: * @param height height of image at level 0.
0610: * @exception IllegalArgumentException if width or height are not greater
0611: * than 0, or if an invalid format or mipMapMode is specified.
0612: */
0613: public Texture(int mipMapMode, int format, int width, int height) {
0614:
0615: // set default read capabilities
0616: setDefaultReadCapabilities(readCapabilities);
0617:
0618: if ((mipMapMode != BASE_LEVEL)
0619: && (mipMapMode != MULTI_LEVEL_MIPMAP))
0620: throw new IllegalArgumentException(J3dI18N
0621: .getString("Texture0"));
0622:
0623: if ((format != INTENSITY) && (format != LUMINANCE)
0624: && (format != ALPHA) && (format != LUMINANCE_ALPHA)
0625: && (format != RGB) && (format != RGBA)) {
0626: throw new IllegalArgumentException(J3dI18N
0627: .getString("Texture1"));
0628: }
0629:
0630: if (width < 1) {
0631: throw new IllegalArgumentException(J3dI18N
0632: .getString("Texture46"));
0633: }
0634:
0635: if (height < 1) {
0636: throw new IllegalArgumentException(J3dI18N
0637: .getString("Texture47"));
0638: }
0639:
0640: int widthLevels;
0641: int heightLevels;
0642:
0643: widthLevels = getLevelsNPOT(width);
0644: heightLevels = getLevelsNPOT(height);
0645:
0646: ((TextureRetained) this .retained).initialize(format, width,
0647: widthLevels, height, heightLevels, mipMapMode, 0);
0648: }
0649:
0650: /**
0651: * Constructs an empty Texture object with specified mipMapMode,
0652: * format, width, height, and boundaryWidth.
0653: * Defaults are used for all other
0654: * parameters. If <code>mipMapMode</code> is set to
0655: * <code>BASE_LEVEL</code>, then the image at level 0 must be set
0656: * by the application (using either the <code>setImage</code> or
0657: * <code>setImages</code> method). If <code>mipMapMode</code> is
0658: * set to <code>MULTI_LEVEL_MIPMAP</code>, then images for levels
0659: * Base Level through Maximum Level must be set.
0660: * Note that a texture with a non-power-of-two width or height will
0661: * only be rendered on a graphics device that supports non-power-of-two
0662: * textures.
0663: *
0664: * @param mipMapMode type of mipmap for this Texture: one of
0665: * BASE_LEVEL, MULTI_LEVEL_MIPMAP
0666: * @param format data format of Textures saved in this object.
0667: * One of INTENSITY, LUMINANCE, ALPHA, LUMINANCE_ALPHA, RGB, RGBA
0668: * @param width width of image at level 0. This
0669: * does not include the width of the boundary.
0670: * @param height height of image at level 0. This
0671: * does not include the width of the boundary.
0672: * @param boundaryWidth width of the boundary, which must be 0 or 1.
0673: * @exception IllegalArgumentException if width or height are not greater
0674: * than 0, if an invalid format or mipMapMode is specified, or
0675: * if the boundaryWidth is < 0 or > 1
0676: *
0677: * @since Java 3D 1.3
0678: */
0679: public Texture(int mipMapMode, int format, int width, int height,
0680: int boundaryWidth) {
0681:
0682: // set default read capabilities
0683: setDefaultReadCapabilities(readCapabilities);
0684:
0685: if ((mipMapMode != BASE_LEVEL)
0686: && (mipMapMode != MULTI_LEVEL_MIPMAP))
0687: throw new IllegalArgumentException(J3dI18N
0688: .getString("Texture0"));
0689:
0690: if ((format != INTENSITY) && (format != LUMINANCE)
0691: && (format != ALPHA) && (format != LUMINANCE_ALPHA)
0692: && (format != RGB) && (format != RGBA)) {
0693: throw new IllegalArgumentException(J3dI18N
0694: .getString("Texture1"));
0695: }
0696:
0697: if (width < 1) {
0698: throw new IllegalArgumentException(J3dI18N
0699: .getString("Texture46"));
0700: }
0701:
0702: if (height < 1) {
0703: throw new IllegalArgumentException(J3dI18N
0704: .getString("Texture47"));
0705: }
0706:
0707: int widthLevels;
0708: int heightLevels;
0709:
0710: widthLevels = getLevelsNPOT(width);
0711: heightLevels = getLevelsNPOT(height);
0712:
0713: if (boundaryWidth < 0 || boundaryWidth > 1)
0714: throw new IllegalArgumentException(J3dI18N
0715: .getString("Texture30"));
0716:
0717: ((TextureRetained) this .retained).initialize(format, width,
0718: widthLevels, height, heightLevels, mipMapMode,
0719: boundaryWidth);
0720: }
0721:
0722: /**
0723: * Sets the boundary mode for the S coordinate in this texture object.
0724: * @param boundaryModeS the boundary mode for the S coordinate.
0725: * One of: CLAMP, WRAP, CLAMP_TO_EDGE, or CLAMP_TO_BOUNDARY.
0726: * @exception RestrictedAccessException if the method is called
0727: * when this object is part of live or compiled scene graph.
0728: * @exception IllegalArgumentException if <code>boundaryModeS</code>
0729: * is a value other than <code>CLAMP</code>, <code>WRAP</code>,
0730: * <code>CLAMP_TO_EDGE</code>, or <code>CLAMP_TO_BOUNDARY</code>.
0731: */
0732: public void setBoundaryModeS(int boundaryModeS) {
0733: checkForLiveOrCompiled();
0734: switch (boundaryModeS) {
0735: case Texture.CLAMP:
0736: case Texture.WRAP:
0737: case Texture.CLAMP_TO_EDGE:
0738: case Texture.CLAMP_TO_BOUNDARY:
0739: break;
0740: default:
0741: throw new IllegalArgumentException(J3dI18N
0742: .getString("Texture31"));
0743: }
0744: ((TextureRetained) this .retained)
0745: .initBoundaryModeS(boundaryModeS);
0746: }
0747:
0748: /**
0749: * Retrieves the boundary mode for the S coordinate.
0750: * @return the current boundary mode for the S coordinate.
0751: * @exception CapabilityNotSetException if appropriate capability is
0752: * not set and this object is part of live or compiled scene graph
0753: */
0754: public int getBoundaryModeS() {
0755: if (isLiveOrCompiled())
0756: if (!this .getCapability(ALLOW_BOUNDARY_MODE_READ))
0757: throw new CapabilityNotSetException(J3dI18N
0758: .getString("Texture4"));
0759: return ((TextureRetained) this .retained).getBoundaryModeS();
0760: }
0761:
0762: /**
0763: * Sets the boundary mode for the T coordinate in this texture object.
0764: * @param boundaryModeT the boundary mode for the T coordinate.
0765: * One of: CLAMP, WRAP, CLAMP_TO_EDGE, or CLAMP_TO_BOUNDARY.
0766: * @exception RestrictedAccessException if the method is called
0767: * when this object is part of live or compiled scene graph.
0768: * @exception IllegalArgumentException if <code>boundaryModeT</code>
0769: * is a value other than <code>CLAMP</code>, <code>WRAP</code>,
0770: * <code>CLAMP_TO_EDGE</code>, or <code>CLAMP_TO_BOUNDARY</code>.
0771: */
0772: public void setBoundaryModeT(int boundaryModeT) {
0773: checkForLiveOrCompiled();
0774: switch (boundaryModeT) {
0775: case Texture.CLAMP:
0776: case Texture.WRAP:
0777: case Texture.CLAMP_TO_EDGE:
0778: case Texture.CLAMP_TO_BOUNDARY:
0779: break;
0780: default:
0781: throw new IllegalArgumentException(J3dI18N
0782: .getString("Texture31"));
0783: }
0784: ((TextureRetained) this .retained)
0785: .initBoundaryModeT(boundaryModeT);
0786: }
0787:
0788: /**
0789: * Retrieves the boundary mode for the T coordinate.
0790: * @return the current boundary mode for the T coordinate.
0791: * @exception CapabilityNotSetException if appropriate capability is
0792: * not set and this object is part of live or compiled scene graph
0793: */
0794: public int getBoundaryModeT() {
0795: if (isLiveOrCompiled())
0796: if (!this .getCapability(ALLOW_BOUNDARY_MODE_READ))
0797: throw new CapabilityNotSetException(J3dI18N
0798: .getString("Texture4"));
0799: return ((TextureRetained) this .retained).getBoundaryModeT();
0800: }
0801:
0802: /**
0803: * Sets the minification filter function. This
0804: * function is used when the pixel being rendered maps to an area
0805: * greater than one texel.
0806: * @param minFilter the minification filter. One of:
0807: * FASTEST, NICEST, BASE_LEVEL_POINT, BASE_LEVEL_LINEAR,
0808: * MULTI_LEVEL_POINT, MULTI_LEVEL_LINEAR, or FILTER4
0809: * @exception RestrictedAccessException if the method is called
0810: * when this object is part of live or compiled scene graph.
0811: * @exception IllegalArgumentException if <code>minFilter</code>
0812: * is a value other than <code>FASTEST</code>, <code>NICEST</code>,
0813: * <code>BASE_LEVEL_POINT</code>, <code>BASE_LEVEL_LINEAR</code>,
0814: * <code>MULTI_LEVEL_POINT</code>, <code>MULTI_LEVEL_LINEAR</code>, or
0815: * <code>FILTER4</code>.
0816: *
0817: * @see Canvas3D#queryProperties
0818: */
0819: public void setMinFilter(int minFilter) {
0820: checkForLiveOrCompiled();
0821:
0822: switch (minFilter) {
0823: case FASTEST:
0824: case NICEST:
0825: case BASE_LEVEL_POINT:
0826: case BASE_LEVEL_LINEAR:
0827: case MULTI_LEVEL_POINT:
0828: case MULTI_LEVEL_LINEAR:
0829: case FILTER4:
0830: break;
0831: default:
0832: throw new IllegalArgumentException(J3dI18N
0833: .getString("Texture28"));
0834: }
0835:
0836: ((TextureRetained) this .retained).initMinFilter(minFilter);
0837: }
0838:
0839: /**
0840: * Retrieves the minification filter.
0841: * @return the current minification filter function.
0842: * @exception CapabilityNotSetException if appropriate capability is
0843: * not set and this object is part of live or compiled scene graph
0844: */
0845: public int getMinFilter() {
0846: if (isLiveOrCompiled())
0847: if (!this .getCapability(ALLOW_FILTER_READ))
0848: throw new CapabilityNotSetException(J3dI18N
0849: .getString("Texture6"));
0850: return ((TextureRetained) this .retained).getMinFilter();
0851: }
0852:
0853: /**
0854: * Sets the magnification filter function. This
0855: * function is used when the pixel being rendered maps to an area
0856: * less than or equal to one texel.
0857: * @param magFilter the magnification filter, one of:
0858: * FASTEST, NICEST, BASE_LEVEL_POINT, BASE_LEVEL_LINEAR,
0859: * LINEAR_SHARPEN, LINEAR_SHARPEN_RGB, LINEAR_SHARPEN_ALPHA, or FILTER4.
0860: *
0861: * @exception RestrictedAccessException if the method is called
0862: * when this object is part of live or compiled scene graph.
0863: * @exception IllegalArgumentException if <code>magFilter</code>
0864: * is a value other than <code>FASTEST</code>, <code>NICEST</code>,
0865: * <code>BASE_LEVEL_POINT</code>, <code>BASE_LEVEL_LINEAR</code>,
0866: * <code>LINEAR_SHARPEN</code>, <code>LINEAR_SHARPEN_RGB</code>,
0867: * <code>LINEAR_SHARPEN_ALPHA</code>, or
0868: * <code>FILTER4</code>.
0869: *
0870: * @see Canvas3D#queryProperties
0871: */
0872: public void setMagFilter(int magFilter) {
0873: checkForLiveOrCompiled();
0874:
0875: switch (magFilter) {
0876: case FASTEST:
0877: case NICEST:
0878: case BASE_LEVEL_POINT:
0879: case BASE_LEVEL_LINEAR:
0880: case LINEAR_SHARPEN:
0881: case LINEAR_SHARPEN_RGB:
0882: case LINEAR_SHARPEN_ALPHA:
0883: case FILTER4:
0884: break;
0885: default:
0886: throw new IllegalArgumentException(J3dI18N
0887: .getString("Texture29"));
0888: }
0889:
0890: ((TextureRetained) this .retained).initMagFilter(magFilter);
0891: }
0892:
0893: /**
0894: * Retrieves the magnification filter.
0895: * @return the current magnification filter function.
0896: * @exception CapabilityNotSetException if appropriate capability is
0897: * not set and this object is part of live or compiled scene graph
0898: */
0899: public int getMagFilter() {
0900: if (isLiveOrCompiled())
0901: if (!this .getCapability(ALLOW_FILTER_READ))
0902: throw new CapabilityNotSetException(J3dI18N
0903: .getString("Texture6"));
0904: return ((TextureRetained) this .retained).getMagFilter();
0905: }
0906:
0907: /**
0908: * Sets the image for a specified mipmap level. Note that the image size
0909: * must be the correct size for the specified mipmap level. The image size
0910: * of the base level image, that is level 0, must be the same size
0911: * in each dimension (width, height, depth) as this
0912: * texture, excluding the border, if any.
0913: * Each successive mipmap level must be 1/2 the size of the previous level,
0914: * such that <code>size[n] = floor(size[n-1]/2)</code>, exluding
0915: * the border.
0916: *
0917: * @param level mipmap level to set: 0 is the base level
0918: * @param image ImageComponent object containing the texture image
0919: * for the specified mipmap level
0920: *
0921: * @exception CapabilityNotSetException if appropriate capability is
0922: * not set and this object is part of live or compiled scene graph
0923: *
0924: * @exception IllegalArgumentException if an ImageComponent3D is
0925: * used in a Texture2D object or if an ImageComponent2D is used in a
0926: * Texture3D object.
0927: *
0928: * @exception IllegalArgumentException if the image being set at this
0929: * level is not the correct size for this level.
0930: *
0931: * @exception IllegalSharingException if this Texture is live and
0932: * the specified image is being used by a Canvas3D as an off-screen buffer.
0933: *
0934: * @exception IllegalSharingException if this Texture is
0935: * being used by an immediate mode context and
0936: * the specified image is being used by a Canvas3D as an off-screen buffer.
0937: */
0938: public void setImage(int level, ImageComponent image) {
0939: if (isLiveOrCompiled()) {
0940: if (!this .getCapability(ALLOW_IMAGE_WRITE))
0941: throw new CapabilityNotSetException(J3dI18N
0942: .getString("Texture15"));
0943: }
0944:
0945: // Do illegal sharing check
0946: validateImageIllegalSharing(image);
0947:
0948: if (isLive())
0949: ((TextureRetained) this .retained).setImage(level, image);
0950: else
0951: ((TextureRetained) this .retained).initImage(level, image);
0952: }
0953:
0954: /**
0955: * Retrieves the image for a specified mipmap level.
0956: * @param level mipmap level to get: 0 is the base level
0957: * @return the ImageComponent object containing the texture image at
0958: * the specified mipmap level.
0959: * @exception CapabilityNotSetException if appropriate capability is
0960: * not set and this object is part of live or compiled scene graph
0961: */
0962: public ImageComponent getImage(int level) {
0963: if (isLiveOrCompiled()) {
0964: if (!this .getCapability(ALLOW_IMAGE_READ))
0965: throw new CapabilityNotSetException(J3dI18N
0966: .getString("Texture9"));
0967: }
0968:
0969: return ((TextureRetained) this .retained).getImage(level);
0970: }
0971:
0972: /**
0973: * Sets the array of images for all mipmap levels. Note that the image size
0974: * of the base level image, <code>images[0]</code>, must be the same size
0975: * in each dimension (width, height, depth) as this
0976: * texture, excluding the border, if any.
0977: * Each successive mipmap level must be 1/2 the size of the previous level,
0978: * such that <code>size[n] = floor(size[n-1]/2)</code>, exluding
0979: * the border.
0980: *
0981: * @param images array of ImageComponent objects
0982: * containing the texture images for all mipmap levels
0983: * @exception CapabilityNotSetException if appropriate capability is
0984: * not set and this object is part of live or compiled scene graph
0985: *
0986: * @exception IllegalArgumentException if an ImageComponent3D is
0987: * used in a Texture2D object or if an ImageComponent2D is used in a
0988: * Texture3D object.
0989: *
0990: * @exception IllegalArgumentException if <code>images.length</code> is
0991: * not equal to the total number of mipmap levels.
0992: *
0993: * @exception IllegalArgumentException if the size of each dimension
0994: * of the image at a given level in the
0995: * <code>images</code> array is not the correct size.
0996: *
0997: * @exception IllegalSharingException if this Texture is live and
0998: * any of the specified images are being used by a Canvas3D as an
0999: * off-screen buffer.
1000: *
1001: * @exception IllegalSharingException if this Texture is
1002: * being used by an immediate mode context and
1003: * any of the specified images are being used by a Canvas3D as an
1004: * off-screen buffer.
1005: *
1006: * @since Java 3D 1.2
1007: */
1008: public void setImages(ImageComponent[] images) {
1009: if (isLiveOrCompiled()) {
1010: if (!this .getCapability(ALLOW_IMAGE_WRITE))
1011: throw new CapabilityNotSetException(J3dI18N
1012: .getString("Texture15"));
1013: }
1014:
1015: // Do illegal sharing check
1016: for (int i = 0; i < images.length; i++) {
1017: validateImageIllegalSharing(images[i]);
1018: }
1019:
1020: if (images == null)
1021: throw new IllegalArgumentException(J3dI18N
1022: .getString("Texture20"));
1023:
1024: if (isLive())
1025: ((TextureRetained) this .retained).setImages(images);
1026: else
1027: ((TextureRetained) this .retained).initImages(images);
1028: }
1029:
1030: /**
1031: * Retrieves the array of images for all mipmap levels.
1032: * @return the array of ImageComponent objects for this Texture.
1033: * @exception CapabilityNotSetException if appropriate capability is
1034: * not set and this object is part of live or compiled scene graph
1035: *
1036: * @since Java 3D 1.2
1037: */
1038: public ImageComponent[] getImages() {
1039: if (isLiveOrCompiled()) {
1040: if (!this .getCapability(ALLOW_IMAGE_READ))
1041: throw new CapabilityNotSetException(J3dI18N
1042: .getString("Texture9"));
1043: }
1044: return ((TextureRetained) this .retained).getImages();
1045: }
1046:
1047: /**
1048: * Retrieves the format of this Texture object.
1049: * @return the format of this Texture object.
1050: * @exception CapabilityNotSetException if appropriate capability is
1051: * not set and this object is part of live or compiled scene graph
1052: *
1053: * @since Java 3D 1.2
1054: */
1055: public int getFormat() {
1056: if (isLiveOrCompiled()) {
1057: if (!this .getCapability(ALLOW_FORMAT_READ))
1058: throw new CapabilityNotSetException(J3dI18N
1059: .getString("Texture19"));
1060: }
1061: return ((TextureRetained) this .retained).getFormat();
1062: }
1063:
1064: /**
1065: * Retrieves the width of this Texture object.
1066: * @return the width of this Texture object.
1067: * @exception CapabilityNotSetException if appropriate capability is
1068: * not set and this object is part of live or compiled scene graph
1069: *
1070: * @since Java 3D 1.2
1071: */
1072: public int getWidth() {
1073: if (isLiveOrCompiled()) {
1074: if (!this .getCapability(ALLOW_SIZE_READ))
1075: throw new CapabilityNotSetException(J3dI18N
1076: .getString("Texture16"));
1077: }
1078: return ((TextureRetained) this .retained).getWidth();
1079: }
1080:
1081: /**
1082: * Retrieves the height of this Texture object.
1083: * @return the height of this Texture object.
1084: * @exception CapabilityNotSetException if appropriate capability is
1085: * not set and this object is part of live or compiled scene graph
1086: *
1087: * @since Java 3D 1.2
1088: */
1089: public int getHeight() {
1090: if (isLiveOrCompiled()) {
1091: if (!this .getCapability(ALLOW_SIZE_READ))
1092: throw new CapabilityNotSetException(J3dI18N
1093: .getString("Texture17"));
1094: }
1095: return ((TextureRetained) this .retained).getHeight();
1096: }
1097:
1098: /**
1099: * Retrieves the width of the boundary of this Texture object.
1100: * @return the width of the boundary of this Texture object.
1101: * @exception CapabilityNotSetException if appropriate capability is
1102: * not set and this object is part of live or compiled scene graph
1103: *
1104: * @since Java 3D 1.3
1105: */
1106: public int getBoundaryWidth() {
1107:
1108: if (isLiveOrCompiled()) {
1109: if (!this .getCapability(ALLOW_SIZE_READ))
1110: throw new CapabilityNotSetException(J3dI18N
1111: .getString("Texture17"));
1112: }
1113:
1114: return ((TextureRetained) this .retained).getBoundaryWidth();
1115: }
1116:
1117: /**
1118: * Retrieves the number of mipmap levels needed for this Texture object.
1119: * @return (maximum Level - base Level + 1)
1120: * if <code>mipMapMode</code> is
1121: * <code>MULTI_LEVEL_MIPMAP</code>; otherwise it returns 1.
1122: * @exception CapabilityNotSetException if appropriate capability is
1123: * not set and this object is part of live or compiled scene graph
1124: *
1125: * @since Java 3D 1.2
1126: */
1127: public int numMipMapLevels() {
1128: if (isLiveOrCompiled()) {
1129: if (!this .getCapability(ALLOW_SIZE_READ))
1130: throw new CapabilityNotSetException(J3dI18N
1131: .getString("Texture18"));
1132: }
1133: return ((TextureRetained) this .retained).numMipMapLevels();
1134: }
1135:
1136: /**
1137: * Sets mipmap mode for texture mapping for this texture object.
1138: * @param mipMapMode the new mipmap mode for this object. One of:
1139: * BASE_LEVEL or MULTI_LEVEL_MIPMAP.
1140: * @exception RestrictedAccessException if the method is called
1141: * when this object is part of live or compiled scene graph.
1142: * @exception IllegalArgumentException if <code>mipMapMode</code>
1143: * is a value other than <code>BASE_LEVEL</code> or
1144: * <code>MULTI_LEVEL_MIPMAP</code>.
1145: */
1146: public void setMipMapMode(int mipMapMode) {
1147: checkForLiveOrCompiled();
1148: ((TextureRetained) this .retained).initMipMapMode(mipMapMode);
1149: }
1150:
1151: /**
1152: * Retrieves current mipmap mode.
1153: * @return current mipmap mode of this texture object.
1154: * @exception CapabilityNotSetException if appropriate capability is
1155: * not set and this object is part of live or compiled scene graph
1156: */
1157: public int getMipMapMode() {
1158: if (isLiveOrCompiled())
1159: if (!this .getCapability(ALLOW_MIPMAP_MODE_READ))
1160: throw new CapabilityNotSetException(J3dI18N
1161: .getString("Texture10"));
1162: return ((TextureRetained) this .retained).getMipMapMode();
1163: }
1164:
1165: /**
1166: * Enables or disables texture mapping for this
1167: * appearance component object.
1168: * @param state true or false to enable or disable texture mapping
1169: * @exception CapabilityNotSetException if appropriate capability is
1170: * not set and this object is part of live or compiled scene graph
1171: */
1172: public void setEnable(boolean state) {
1173: if (isLiveOrCompiled()) {
1174: if (!this .getCapability(ALLOW_ENABLE_WRITE))
1175: throw new CapabilityNotSetException(J3dI18N
1176: .getString("Texture11"));
1177: }
1178: if (isLive())
1179: ((TextureRetained) this .retained).setEnable(state);
1180: else
1181: ((TextureRetained) this .retained).initEnable(state);
1182:
1183: }
1184:
1185: /**
1186: * Retrieves the state of the texture enable flag.
1187: * @return true if texture mapping is enabled,
1188: * false if texture mapping is disabled
1189: * @exception CapabilityNotSetException if appropriate capability is
1190: * not set and this object is part of live or compiled scene graph
1191: */
1192: public boolean getEnable() {
1193: if (isLiveOrCompiled()) {
1194: if (!this .getCapability(ALLOW_ENABLE_READ))
1195: throw new CapabilityNotSetException(J3dI18N
1196: .getString("Texture12"));
1197: }
1198: return ((TextureRetained) this .retained).getEnable();
1199: }
1200:
1201: // Internal j3d usage method
1202: // Returns n if num is 2**n
1203: // Returns -1 if num is 0 or negative or if
1204: // num is NOT power of 2.
1205: // NOTE: ********** Assumes 32 bit integer******************
1206: static int getPowerOf2(int num) {
1207:
1208: int i, tmp;
1209: // Can only handle positive numbers, return error.
1210: if (num < 1)
1211: return -1;
1212:
1213: for (i = 0, tmp = num; i < 32; i++) {
1214: // Check if leftmost bit is 1
1215: if ((tmp & 0x80000000) != 0) {
1216: //Check if any other bit is 1
1217: if ((tmp & 0x7fffffff) == 0)
1218: return 31 - i;//valid power of 2 integer
1219: else
1220: return -1;//invalid non-power-of-2 integer
1221: }
1222: tmp <<= 1;
1223: }
1224: //Can't reach here because we have already checked for 0
1225: return -1;
1226: }
1227:
1228: // returns number of levels using NPOT rules for mipmap generation
1229: // which say that each level should be floor(size/2) of previous level
1230: static int getLevelsNPOT(int num) {
1231: int tmp, levels = 0;
1232: tmp = num;
1233: while (tmp > 1) {
1234: tmp = tmp / 2;
1235: levels++;
1236: }
1237: return levels;
1238: }
1239:
1240: /**
1241: * Sets the texture boundary color for this texture object. The
1242: * texture boundary color is used when boundaryModeS or boundaryModeT
1243: * is set to CLAMP or CLAMP_TO_BOUNDARY and if texture boundary is not
1244: * specified.
1245: * @param boundaryColor the new texture boundary color.
1246: * @exception RestrictedAccessException if the method is called
1247: * when this object is part of live or compiled scene graph.
1248: */
1249: public void setBoundaryColor(Color4f boundaryColor) {
1250: checkForLiveOrCompiled();
1251: ((TextureRetained) this .retained)
1252: .initBoundaryColor(boundaryColor);
1253: }
1254:
1255: /**
1256: * Sets the texture boundary color for this texture object. The
1257: * texture boundary color is used when boundaryModeS or boundaryModeT
1258: * is set to CLAMP or CLAMP_TO_BOUNDARY and if texture boundary is not
1259: * specified.
1260: * @param r the red component of the color.
1261: * @param g the green component of the color.
1262: * @param b the blue component of the color.
1263: * @param a the alpha component of the color.
1264: * @exception RestrictedAccessException if the method is called
1265: * when this object is part of live or compiled scene graph.
1266: */
1267: public void setBoundaryColor(float r, float g, float b, float a) {
1268: checkForLiveOrCompiled();
1269: ((TextureRetained) this .retained).initBoundaryColor(r, g, b, a);
1270: }
1271:
1272: /**
1273: * Retrieves the texture boundary color for this texture object.
1274: * @param boundaryColor the vector that will receive the
1275: * current texture boundary color.
1276: * @exception CapabilityNotSetException if appropriate capability is
1277: * not set and this object is part of live or compiled scene graph
1278: */
1279: public void getBoundaryColor(Color4f boundaryColor) {
1280: if (isLiveOrCompiled()) {
1281: if (!this .getCapability(ALLOW_BOUNDARY_COLOR_READ))
1282: throw new CapabilityNotSetException(J3dI18N
1283: .getString("Texture13"));
1284: }
1285: ((TextureRetained) this .retained)
1286: .getBoundaryColor(boundaryColor);
1287: }
1288:
1289: /**
1290: * Specifies the base level for this texture object.
1291: * @param baseLevel index of the lowest defined mipmap level.
1292: * @exception CapabilityNotSetException if appropriate capability is
1293: * not set and this object is part of live or compiled scene graph
1294: * @exception IllegalArgumentException if specified baseLevel < 0, or
1295: * if baseLevel > maximumLevel
1296: *
1297: * @since Java 3D 1.3
1298: * @see Canvas3D#queryProperties
1299: */
1300: public void setBaseLevel(int baseLevel) {
1301: if (isLiveOrCompiled()) {
1302: if (!this .getCapability(ALLOW_LOD_RANGE_WRITE)) {
1303: throw new CapabilityNotSetException(J3dI18N
1304: .getString("Texture32"));
1305: }
1306: }
1307:
1308: if (isLive()) {
1309: ((TextureRetained) this .retained).setBaseLevel(baseLevel);
1310: } else {
1311: ((TextureRetained) this .retained).initBaseLevel(baseLevel);
1312: }
1313: }
1314:
1315: /**
1316: * Retrieves the base level for this texture object.
1317: * @return base level for this texture object.
1318: * @exception CapabilityNotSetException if appropriate capability is
1319: * not set and this object is part of live or compiled scene graph
1320: *
1321: * @since Java 3D 1.3
1322: */
1323: public int getBaseLevel() {
1324: if (isLiveOrCompiled()) {
1325: if (!this .getCapability(ALLOW_LOD_RANGE_READ)) {
1326: throw new CapabilityNotSetException(J3dI18N
1327: .getString("Texture34"));
1328: }
1329: }
1330: return ((TextureRetained) this .retained).getBaseLevel();
1331: }
1332:
1333: /**
1334: * Specifies the maximum level for this texture object.
1335: * @param maximumLevel index of the highest defined mipmap level.
1336: * @exception CapabilityNotSetException if appropriate capability is
1337: * not set and this object is part of live or compiled scene graph
1338: * @exception IllegalArgumentException if specified
1339: * maximumLevel < baseLevel, or
1340: * if maximumLevel > <code>log<sub><font size=-2>2</font></sub>(max(width,height))</code>
1341: * @exception IllegalArgumentException if mipMipMapMode is equal to BASE_LEVEL
1342: * and maximumLevel is not equal to zero.
1343: *
1344: * @since Java 3D 1.3
1345: * @see Canvas3D#queryProperties
1346: */
1347: public void setMaximumLevel(int maximumLevel) {
1348: if (isLiveOrCompiled()) {
1349: if (!this .getCapability(ALLOW_LOD_RANGE_WRITE)) {
1350: throw new CapabilityNotSetException(J3dI18N
1351: .getString("Texture33"));
1352: }
1353: }
1354:
1355: if (isLive()) {
1356: ((TextureRetained) this .retained)
1357: .setMaximumLevel(maximumLevel);
1358: } else {
1359: ((TextureRetained) this .retained)
1360: .initMaximumLevel(maximumLevel);
1361: }
1362: }
1363:
1364: /**
1365: * Retrieves the maximum level for this texture object.
1366: * @return maximum level for this texture object.
1367: * @exception CapabilityNotSetException if appropriate capability is
1368: * not set and this object is part of live or compiled scene graph
1369: *
1370: * @since Java 3D 1.3
1371: */
1372: public int getMaximumLevel() {
1373: if (isLiveOrCompiled()) {
1374: if (!this .getCapability(ALLOW_LOD_RANGE_READ)) {
1375: throw new CapabilityNotSetException(J3dI18N
1376: .getString("Texture35"));
1377: }
1378: }
1379: return ((TextureRetained) this .retained).getMaximumLevel();
1380: }
1381:
1382: /**
1383: * Specifies the minimum level-of-detail for this texture object.
1384: * @param minimumLod the minimum level-of-detail.
1385: * @exception CapabilityNotSetException if appropriate capability is
1386: * not set and this object is part of live or compiled scene graph
1387: * @exception IllegalArgumentException if specified lod > maximum lod
1388: *
1389: * @since Java 3D 1.3
1390: * @see Canvas3D#queryProperties
1391: */
1392: public void setMinimumLOD(float minimumLod) {
1393: if (isLiveOrCompiled()) {
1394: if (!this .getCapability(ALLOW_LOD_RANGE_WRITE)) {
1395: throw new CapabilityNotSetException(J3dI18N
1396: .getString("Texture38"));
1397: }
1398: }
1399:
1400: if (isLive()) {
1401: ((TextureRetained) this .retained).setMinimumLOD(minimumLod);
1402: } else {
1403: ((TextureRetained) this .retained)
1404: .initMinimumLOD(minimumLod);
1405: }
1406: }
1407:
1408: /**
1409: * Retrieves the minimum level-of-detail for this texture object.
1410: * @return the minimum level-of-detail
1411: * @exception CapabilityNotSetException if appropriate capability is
1412: * not set and this object is part of live or compiled scene graph
1413: *
1414: * @since Java 3D 1.3
1415: */
1416: public float getMinimumLOD() {
1417: if (isLiveOrCompiled()) {
1418: if (!this .getCapability(ALLOW_LOD_RANGE_READ)) {
1419: throw new CapabilityNotSetException(J3dI18N
1420: .getString("Texture40"));
1421: }
1422: }
1423: return ((TextureRetained) this .retained).getMinimumLOD();
1424: }
1425:
1426: /**
1427: * Specifies the maximum level-of-detail for this texture object.
1428: * @param maximumLod the maximum level-of-detail.
1429: * @exception CapabilityNotSetException if appropriate capability is
1430: * not set and this object is part of live or compiled scene graph
1431: * @exception IllegalArgumentException if specified lod < minimum lod
1432: *
1433: * @since Java 3D 1.3
1434: * @see Canvas3D#queryProperties
1435: */
1436: public void setMaximumLOD(float maximumLod) {
1437: if (isLiveOrCompiled()) {
1438: if (!this .getCapability(ALLOW_LOD_RANGE_WRITE)) {
1439: throw new CapabilityNotSetException(J3dI18N
1440: .getString("Texture39"));
1441: }
1442: }
1443:
1444: if (isLive()) {
1445: ((TextureRetained) this .retained).setMaximumLOD(maximumLod);
1446: } else {
1447: ((TextureRetained) this .retained)
1448: .initMaximumLOD(maximumLod);
1449: }
1450: }
1451:
1452: /**
1453: * Retrieves the maximum level-of-detail for this texture object.
1454: * @return the maximum level-of-detail
1455: * @exception CapabilityNotSetException if appropriate capability is
1456: * not set and this object is part of live or compiled scene graph
1457: *
1458: * @since Java 3D 1.3
1459: */
1460: public float getMaximumLOD() {
1461: if (isLiveOrCompiled()) {
1462: if (!this .getCapability(ALLOW_LOD_RANGE_READ)) {
1463: throw new CapabilityNotSetException(J3dI18N
1464: .getString("Texture41"));
1465: }
1466: }
1467: return ((TextureRetained) this .retained).getMaximumLOD();
1468: }
1469:
1470: /**
1471: * Specifies the LOD offset for this texture object.
1472: * @param s the s component of the LOD offset
1473: * @param t the t component of the LOD offset
1474: * @param r the r component of the LOD offset
1475: * @exception CapabilityNotSetException if appropriate capability is
1476: * not set and this object is part of live or compiled scene graph
1477: *
1478: * @since Java 3D 1.3
1479: * @see Canvas3D#queryProperties
1480: */
1481: public void setLodOffset(float s, float t, float r) {
1482: if (isLiveOrCompiled()) {
1483: if (!this .getCapability(ALLOW_LOD_RANGE_WRITE)) {
1484: throw new CapabilityNotSetException(J3dI18N
1485: .getString("Texture44"));
1486: }
1487: }
1488:
1489: if (isLive()) {
1490: ((TextureRetained) this .retained).setLodOffset(s, t, r);
1491: } else {
1492: ((TextureRetained) this .retained).initLodOffset(s, t, r);
1493: }
1494: }
1495:
1496: /**
1497: * Specifies the LOD offset for this texture object.
1498: * @param offset the LOD offset
1499: * @exception CapabilityNotSetException if appropriate capability is
1500: * not set and this object is part of live or compiled scene graph
1501: *
1502: * @since Java 3D 1.3
1503: * @see Canvas3D#queryProperties
1504: */
1505: public void setLodOffset(Tuple3f offset) {
1506: if (isLiveOrCompiled()) {
1507: if (!this .getCapability(ALLOW_LOD_RANGE_WRITE)) {
1508: throw new CapabilityNotSetException(J3dI18N
1509: .getString("Texture44"));
1510: }
1511: }
1512:
1513: if (isLive()) {
1514: ((TextureRetained) this .retained).setLodOffset(offset.x,
1515: offset.y, offset.z);
1516: } else {
1517: ((TextureRetained) this .retained).initLodOffset(offset.x,
1518: offset.y, offset.z);
1519: }
1520: }
1521:
1522: /**
1523: * Retrieves the LOD offset for this texture object.
1524: * @param offset the vector that will receive the
1525: * current LOD offset.
1526: * @exception CapabilityNotSetException if appropriate capability is
1527: * not set and this object is part of live or compiled scene graph
1528: *
1529: * @since Java 3D 1.3
1530: */
1531: public void getLodOffset(Tuple3f offset) {
1532: if (isLiveOrCompiled()) {
1533: if (!this .getCapability(ALLOW_LOD_RANGE_READ)) {
1534: throw new CapabilityNotSetException(J3dI18N
1535: .getString("Texture45"));
1536: }
1537: }
1538: ((TextureRetained) this .retained).getLodOffset(offset);
1539: }
1540:
1541: /**
1542: * Specifies the anisotropic filter mode for this texture object.
1543: * @param mode the anisotropic filter mode. One of
1544: * ANISOTROPIC_NONE or ANISOTROPIC_SINGLE_VALUE.
1545: * @exception RestrictedAccessException if the method is called
1546: * when this object is part of live or compiled scene graph.
1547: * @exception IllegalArgumentException if
1548: * <code>mode</code> is a value other than
1549: * <code>ANISOTROPIC_NONE</code> or <code>ANISOTROPIC_SINGLE_VALUE</code>
1550: *
1551: * @since Java 3D 1.3
1552: * @see Canvas3D#queryProperties
1553: */
1554: public void setAnisotropicFilterMode(int mode) {
1555: checkForLiveOrCompiled();
1556: if ((mode != ANISOTROPIC_NONE)
1557: && (mode != ANISOTROPIC_SINGLE_VALUE)) {
1558: throw new IllegalArgumentException(J3dI18N
1559: .getString("Texture25"));
1560: }
1561: ((TextureRetained) this .retained)
1562: .initAnisotropicFilterMode(mode);
1563: }
1564:
1565: /**
1566: * Retrieves the anisotropic filter mode for this texture object.
1567: * @return the currrent anisotropic filter mode of this texture object.
1568: * @exception CapabilityNotSetException if appropriate capability is
1569: * not set and this object is part of live or compiled scene graph
1570: *
1571: * @since Java 3D 1.3
1572: */
1573: public int getAnisotropicFilterMode() {
1574: if (isLiveOrCompiled()) {
1575: if (!this .getCapability(ALLOW_ANISOTROPIC_FILTER_READ)) {
1576: throw new CapabilityNotSetException(J3dI18N
1577: .getString("Texture26"));
1578: }
1579: }
1580: return ((TextureRetained) this .retained)
1581: .getAnisotropicFilterMode();
1582: }
1583:
1584: /**
1585: * Specifies the degree of anisotropy to be
1586: * used when the anisotropic filter mode specifies
1587: * ANISOTROPIC_SINGLE_VALUE.
1588: * @param degree degree of anisotropy
1589: * @exception RestrictedAccessException if the method is called
1590: * when this object is part of live or compiled scene graph.
1591: * @exception IllegalArgumentException if
1592: * <code>degree</code> < 1.0 or
1593: * <code>degree</code> > the maximum degree of anisotropy.
1594: *
1595: * @since Java 3D 1.3
1596: * @see Canvas3D#queryProperties
1597: */
1598: public void setAnisotropicFilterDegree(float degree) {
1599: checkForLiveOrCompiled();
1600: if (degree < 1.0) {
1601: throw new IllegalArgumentException(J3dI18N
1602: .getString("Texture27"));
1603: }
1604: ((TextureRetained) this .retained)
1605: .initAnisotropicFilterDegree(degree);
1606: }
1607:
1608: /**
1609: * Retrieves the anisotropic filter degree for this texture object.
1610: * @return the current degree of anisotropy of this texture object
1611: * @exception CapabilityNotSetException if appropriate capability is
1612: * not set and this object is part of live or compiled scene graph
1613: *
1614: * @since Java 3D 1.3
1615: */
1616: public float getAnisotropicFilterDegree() {
1617: if (isLiveOrCompiled()) {
1618: if (!this .getCapability(ALLOW_ANISOTROPIC_FILTER_READ)) {
1619: throw new CapabilityNotSetException(J3dI18N
1620: .getString("Texture26"));
1621: }
1622: }
1623: return ((TextureRetained) this .retained)
1624: .getAnisotropicFilterDegree();
1625: }
1626:
1627: /**
1628: * sets the sharpen texture LOD function for this texture object.
1629: * @param lod array containing the level-of-detail values.
1630: * @param pts array containing the function values for the corresponding
1631: * level-of-detail values.
1632: *
1633: * @exception IllegalStateException if the length of <code>lod</code>
1634: * does not match the length of <code>pts</code>
1635: * @exception RestrictedAccessException if the method is called
1636: * when this object is part of live or compiled scene graph.
1637: *
1638: * @since Java 3D 1.3
1639: * @see Canvas3D#queryProperties
1640: */
1641: public void setSharpenTextureFunc(float[] lod, float[] pts) {
1642: checkForLiveOrCompiled();
1643: if (((lod != null) && (pts != null) && (lod.length == pts.length))
1644: || ((lod == null) && (pts == null))) {
1645: ((TextureRetained) this .retained).initSharpenTextureFunc(
1646: lod, pts);
1647: } else {
1648: throw new IllegalStateException(J3dI18N
1649: .getString("Texture22"));
1650: }
1651: }
1652:
1653: /**
1654: * sets the sharpen texture LOD function for this texture object.
1655: * The Point2f x,y values are defined as follows: x is the lod value,
1656: * y is the corresponding function value.
1657: *
1658: * @param pts array of Point2f containing the lod as well as the
1659: * corresponding function value.
1660: *
1661: * @exception RestrictedAccessException if the method is called
1662: * when this object is part of live or compiled scene graph.
1663: *
1664: * @since Java 3D 1.3
1665: * @see Canvas3D#queryProperties
1666: */
1667: public void setSharpenTextureFunc(Point2f[] pts) {
1668: checkForLiveOrCompiled();
1669: ((TextureRetained) this .retained).initSharpenTextureFunc(pts);
1670: }
1671:
1672: /**
1673: * Gets the number of points in the sharpen texture LOD function for this
1674: * texture object.
1675: *
1676: * @return the number of points in the sharpen texture LOD function.
1677: *
1678: * @exception CapabilityNotSetException if appropriate capability is
1679: * not set and this object is part of live or compiled scene graph
1680: *
1681: * @since Java 3D 1.3
1682: */
1683: public int getSharpenTextureFuncPointsCount() {
1684: if (isLiveOrCompiled()) {
1685: if (!this .getCapability(ALLOW_SHARPEN_TEXTURE_READ)) {
1686: throw new CapabilityNotSetException(J3dI18N
1687: .getString("Texture21"));
1688: }
1689: }
1690: return ((TextureRetained) this .retained)
1691: .getSharpenTextureFuncPointsCount();
1692: }
1693:
1694: /**
1695: * Copies the array of sharpen texture LOD function points into the
1696: * specified arrays. The arrays must be large enough to hold all the
1697: * points.
1698: *
1699: * @param lod the array to receive the level-of-detail values.
1700: * @param pts the array to receive the function values for the
1701: * corresponding level-of-detail values.
1702: *
1703: * @exception CapabilityNotSetException if appropriate capability is
1704: * not set and this object is part of live or compiled scene graph
1705: *
1706: * @since Java 3D 1.3
1707: */
1708: public void getSharpenTextureFunc(float[] lod, float[] pts) {
1709: if (isLiveOrCompiled()) {
1710: if (!this .getCapability(ALLOW_SHARPEN_TEXTURE_READ)) {
1711: throw new CapabilityNotSetException(J3dI18N
1712: .getString("Texture21"));
1713: }
1714: }
1715: ((TextureRetained) this .retained).getSharpenTextureFunc(lod,
1716: pts);
1717: }
1718:
1719: /**
1720: * Copies the array of sharpen texture LOD function points including
1721: * the lod values and the corresponding function values into the
1722: * specified array. The array must be large enough to hold all the points.
1723: * The individual array elements must be allocated by the caller as well.
1724: *
1725: * @param pts the array to receive the sharpen texture LOD function points
1726: *
1727: * @exception CapabilityNotSetException if appropriate capability is
1728: * not set and this object is part of live or compiled scene graph
1729: *
1730: * @since Java 3D 1.3
1731: */
1732: public void getSharpenTextureFunc(Point2f[] pts) {
1733: if (isLiveOrCompiled()) {
1734: if (!this .getCapability(ALLOW_SHARPEN_TEXTURE_READ)) {
1735: throw new CapabilityNotSetException(J3dI18N
1736: .getString("Texture21"));
1737: }
1738: }
1739: ((TextureRetained) this .retained).getSharpenTextureFunc(pts);
1740: }
1741:
1742: /**
1743: * sets the filter4 function for this texture object.
1744: * @param weights array containing samples of the filter4 function.
1745: *
1746: * @exception IllegalArgumentException if the length of
1747: * <code>weight</code> < 4
1748: * @exception RestrictedAccessException if the method is called
1749: * when this object is part of live or compiled scene graph.
1750: *
1751: * @since Java 3D 1.3
1752: * @see Canvas3D#queryProperties
1753: */
1754: public void setFilter4Func(float[] weights) {
1755: checkForLiveOrCompiled();
1756: if ((weights == null) || (weights.length < 4)) {
1757: throw new IllegalArgumentException(J3dI18N
1758: .getString("Texture24"));
1759: } else {
1760: ((TextureRetained) this .retained).initFilter4Func(weights);
1761: }
1762: }
1763:
1764: /**
1765: * Retrieves the number of filter4 function values for this
1766: * texture object.
1767: *
1768: * @return the number of filter4 function values
1769: *
1770: * @exception CapabilityNotSetException if appropriate capability is
1771: * not set and this object is part of live or compiled scene graph
1772: *
1773: * @since Java 3D 1.3
1774: */
1775: public int getFilter4FuncPointsCount() {
1776: if (isLiveOrCompiled()) {
1777: if (!this .getCapability(ALLOW_FILTER4_READ)) {
1778: throw new CapabilityNotSetException(J3dI18N
1779: .getString("Texture23"));
1780: }
1781: }
1782: return (((TextureRetained) this .retained)
1783: .getFilter4FuncPointsCount());
1784: }
1785:
1786: /**
1787: * Copies the array of filter4 function values into the specified
1788: * array. The array must be large enough to hold all the values.
1789: *
1790: * @param weights the array to receive the function values.
1791: *
1792: * @exception CapabilityNotSetException if appropriate capability is
1793: * not set and this object is part of live or compiled scene graph
1794: *
1795: * @since Java 3D 1.3
1796: */
1797: public void getFilter4Func(float[] weights) {
1798: if (isLiveOrCompiled()) {
1799: if (!this .getCapability(ALLOW_FILTER4_READ)) {
1800: throw new CapabilityNotSetException(J3dI18N
1801: .getString("Texture23"));
1802: }
1803: }
1804: ((TextureRetained) this .retained).getFilter4Func(weights);
1805: }
1806:
1807: /**
1808: * Copies all node information from <code>originalNodeComponent</code>
1809: * into the current node. This method is called from the
1810: * <code>duplicateNode</code> method. This routine does
1811: * the actual duplication of all "local data" (any data defined in
1812: * this object).
1813: *
1814: * @param originalNodeComponent the original node to duplicate.
1815: * @param forceDuplicate when set to <code>true</code>, causes the
1816: * <code>duplicateOnCloneTree</code> flag to be ignored. When
1817: * <code>false</code>, the value of each node's
1818: * <code>duplicateOnCloneTree</code> variable determines whether
1819: * NodeComponent data is duplicated or copied.
1820: *
1821: * @see Node#cloneTree
1822: * @see NodeComponent#setDuplicateOnCloneTree
1823: */
1824: void duplicateAttributes(NodeComponent originalNodeComponent,
1825: boolean forceDuplicate) {
1826:
1827: super
1828: .duplicateAttributes(originalNodeComponent,
1829: forceDuplicate);
1830:
1831: Hashtable hashtable = originalNodeComponent.nodeHashtable;
1832:
1833: TextureRetained tex = (TextureRetained) originalNodeComponent.retained;
1834: TextureRetained rt = (TextureRetained) retained;
1835:
1836: rt.initBoundaryModeS(tex.getBoundaryModeS());
1837: rt.initBoundaryModeT(tex.getBoundaryModeT());
1838: rt.initMinFilter(tex.getMinFilter());
1839: rt.initMagFilter(tex.getMagFilter());
1840: rt.initMipMapMode(tex.getMipMapMode());
1841: rt.initEnable(tex.getEnable());
1842: rt.initAnisotropicFilterMode(tex.getAnisotropicFilterMode());
1843: rt
1844: .initAnisotropicFilterDegree(tex
1845: .getAnisotropicFilterDegree());
1846: rt.initSharpenTextureFunc(tex.getSharpenTextureFunc());
1847: rt.initFilter4Func(tex.getFilter4Func());
1848:
1849: rt.initBaseLevel(tex.getBaseLevel());
1850: rt.initMaximumLevel(tex.getMaximumLevel());
1851: rt.initMinimumLOD(tex.getMinimumLOD());
1852: rt.initMaximumLOD(tex.getMaximumLOD());
1853:
1854: Point3f offset = new Point3f();
1855: tex.getLodOffset(offset);
1856: rt.initLodOffset(offset.x, offset.y, offset.z);
1857:
1858: Color4f c = new Color4f();
1859: tex.getBoundaryColor(c);
1860: rt.initBoundaryColor(c);
1861:
1862: // No API available to get the current level
1863: for (int i = tex.maxLevels - 1; i >= 0; i--) {
1864: ImageComponent image = (ImageComponent) getNodeComponent(
1865: tex.getImage(i), forceDuplicate, hashtable);
1866: if (image != null) {
1867: rt.initImage(i, image);
1868: }
1869: }
1870: // XXXX: clone new v1.2 attributes?
1871: // NOTE: This sppears to have already been done
1872: }
1873:
1874: /**
1875: * This function is called from getNodeComponent() to see if any of
1876: * the sub-NodeComponents duplicateOnCloneTree flag is true.
1877: * If it is the case, current NodeComponent needs to
1878: * duplicate also even though current duplicateOnCloneTree flag is false.
1879: * This should be overwrite by NodeComponent which contains sub-NodeComponent.
1880: */
1881: boolean duplicateChild() {
1882: if (getDuplicateOnCloneTree())
1883: return true;
1884:
1885: int level = ((TextureRetained) this .retained).maxLevels;
1886: TextureRetained rt = (TextureRetained) retained;
1887:
1888: for (int i = 0; i < level; i++) {
1889: ImageComponent img = rt.getImage(i);
1890: if ((img != null) && img.getDuplicateOnCloneTree())
1891: return true;
1892: }
1893: return false;
1894: }
1895:
1896: }
|