001: /*
002: * $RCSfile: Texture3D.java,v $
003: *
004: * Copyright 1996-2008 Sun Microsystems, Inc. All Rights Reserved.
005: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
006: *
007: * This code is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU General Public License version 2 only, as
009: * published by the Free Software Foundation. Sun designates this
010: * particular file as subject to the "Classpath" exception as provided
011: * by Sun in the LICENSE file that accompanied this code.
012: *
013: * This code is distributed in the hope that it will be useful, but WITHOUT
014: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
015: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
016: * version 2 for more details (a copy is included in the LICENSE file that
017: * accompanied this code).
018: *
019: * You should have received a copy of the GNU General Public License version
020: * 2 along with this work; if not, write to the Free Software Foundation,
021: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
022: *
023: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
024: * CA 95054 USA or visit www.sun.com if you need additional information or
025: * have any questions.
026: *
027: * $Revision: 1.8 $
028: * $Date: 2008/02/28 20:17:31 $
029: * $State: Exp $
030: */
031:
032: package javax.media.j3d;
033:
034: /**
035: * Texture3D is a subclass of Texture class. It extends Texture
036: * class by adding a third coordinate, constructor and a mutator
037: * method for setting a 3D texture image.
038: * If 3D texture mapping is not supported on a particular Canvas3D,
039: * 3D texture mapping is ignored for that canvas.
040: *
041: * <p>
042: * Note that as of Java 3D 1.5, the texture width, height, and depth
043: * are no longer
044: * required to be an exact power of two. However, not all graphics devices
045: * supports non-power-of-two textures. If non-power-of-two texture mapping is
046: * unsupported on a particular Canvas3D, textures with a width, height,
047: * or depth that are not an exact power of two are ignored for that canvas.
048: *
049: * @see Canvas3D#queryProperties
050: */
051:
052: public class Texture3D extends Texture {
053:
054: // TODO KCR : NPOT
055:
056: /**
057: * Constructs a Texture3D object with default parameters.
058: * The default values are as follows:
059: * <ul>
060: * depth : 0<br>
061: * boundary mode R : WRAP<br>
062: * </ul>
063: * <p>
064: * Note that the default constructor creates a texture object with
065: * a width, height, and depth of 0 and is, therefore, not useful.
066: */
067: public Texture3D() {
068: super ();
069: }
070:
071: /**
072: * Constructs an empty Texture3D object with specified mipmapMode
073: * format, width, height, and depth. Image at base level must be set by
074: * the application using 'setImage' method. If mipmapMode is
075: * set to MULTI_LEVEL_MIPMAP, images for base level through
076: * maximum level must be set.
077: * Note that a texture with a non-power-of-two width, height, or depth will
078: * only be rendered on a graphics device that supports non-power-of-two
079: * textures.
080: *
081: * @param mipmapMode type of mipmap for this Texture: One of
082: * BASE_LEVEL, MULTI_LEVEL_MIPMAP.
083: * @param format data format of Textures saved in this object.
084: * One of INTENSITY, LUMINANCE, ALPHA, LUMINANCE_ALPHA, RGB, RGBA.
085: * @param width width of image at level 0.
086: * @param height height of image at level 0.
087: * @param depth depth of image at level 0.
088: * @exception IllegalArgumentException if width, height, or depth are not
089: * greater than 0 OR invalid format/mipmapMode is specified.
090: */
091: public Texture3D(int mipmapMode, int format, int width, int height,
092: int depth) {
093:
094: super (mipmapMode, format, width, height);
095:
096: int depthLevels = -1;
097:
098: depthLevels = getLevelsNPOT(depth);
099:
100: // TODO : Need to verify whether this is a bug. Why depthLevels isn't
101: // use to determine maxMipMapLevels ? See also Texture.java
102:
103: ((Texture3DRetained) this .retained).setDepth(depth);
104: }
105:
106: /**
107: * Constructs an empty Texture3D object with specified mipmapMode
108: * format, width, height, depth, and boundaryWidth.
109: * Image at base level must be set by
110: * the application using 'setImage' method. If mipmapMode is
111: * set to MULTI_LEVEL_MIPMAP, images for base level through
112: * maximum level must be set.
113: * Note that a texture with a non-power-of-two width, height, or depth will
114: * only be rendered on a graphics device that supports non-power-of-two
115: * textures.
116: *
117: * @param mipmapMode type of mipmap for this Texture: One of
118: * BASE_LEVEL, MULTI_LEVEL_MIPMAP.
119: * @param format data format of Textures saved in this object.
120: * One of INTENSITY, LUMINANCE, ALPHA, LUMINANCE_ALPHA, RGB, RGBA.
121: * @param width width of image at level 0. This
122: * does not include the width of the boundary.
123: * @param height height of image at level 0. This
124: * does not include the width of the boundary.
125: * @param depth depth of image at level 0. This
126: * does not include the width of the boundary.
127: * @param boundaryWidth width of the boundary, which must be 0 or 1.
128: * @exception IllegalArgumentException if width, height, or depth are not
129: * greater than 0 OR invalid format/mipmapMode is specified, or
130: * if the boundaryWidth is < 0 or > 1
131: *
132: * @since Java 3D 1.3
133: */
134: public Texture3D(int mipmapMode, int format, int width, int height,
135: int depth, int boundaryWidth) {
136:
137: super (mipmapMode, format, width, height, boundaryWidth);
138: int depthLevels = -1;
139:
140: depthLevels = getLevelsNPOT(depth);
141:
142: // TODO : Need to verify whether this is a bug. Why depthLevels isn't
143: // use to determine maxMipMapLevels ? See also Texture.java
144:
145: ((Texture3DRetained) this .retained).setDepth(depth);
146: }
147:
148: /**
149: * Sets the boundary mode for the R coordinate in this texture object.
150: * @param boundaryModeR the boundary mode for the R coordinate,
151: * one of: CLAMP, WRAP, CLAMP_TO_EDGE, or CLAMP_TO_BOUNDARY
152: * @exception RestrictedAccessException if the method is called
153: * when this object is part of live or compiled scene graph.
154: * @exception IllegalArgumentException if <code>boundaryModeR</code>
155: * is a value other than <code>CLAMP</code>, <code>WRAP</code>,
156: * <code>CLAMP_TO_EDGE</code>, or <code>CLAMP_TO_BOUNDARY</code>.
157: */
158: public void setBoundaryModeR(int boundaryModeR) {
159: checkForLiveOrCompiled();
160: switch (boundaryModeR) {
161: case Texture.CLAMP:
162: case Texture.WRAP:
163: case Texture.CLAMP_TO_EDGE:
164: case Texture.CLAMP_TO_BOUNDARY:
165: break;
166: default:
167: throw new IllegalArgumentException(J3dI18N
168: .getString("Texture31"));
169: }
170: ((Texture3DRetained) this .retained)
171: .initBoundaryModeR(boundaryModeR);
172: }
173:
174: /**
175: * Retrieves the boundary mode for the R coordinate.
176: * @return the current boundary mode for the R coordinate.
177: * @exception RestrictedAccessException if the method is called
178: * when this object is part of live or compiled scene graph.
179: */
180: public int getBoundaryModeR() {
181: if (isLiveOrCompiled())
182: if (!this .getCapability(Texture.ALLOW_BOUNDARY_MODE_READ))
183: throw new CapabilityNotSetException(J3dI18N
184: .getString("Texture3D0"));
185: return ((Texture3DRetained) this .retained).getBoundaryModeR();
186: }
187:
188: /**
189: * Retrieves the depth of this Texture3D object.
190: * @return the depth of this Texture3D object.
191: * @exception CapabilityNotSetException if appropriate capability is
192: * not set and this object is part of live or compiled scene graph
193: *
194: * @since Java 3D 1.2
195: */
196: public int getDepth() {
197: if (isLiveOrCompiled())
198: if (!this .getCapability(ALLOW_SIZE_READ))
199: throw new CapabilityNotSetException(J3dI18N
200: .getString("Texture3D2"));
201:
202: return ((Texture3DRetained) this .retained).getDepth();
203: }
204:
205: /**
206: * Creates a retained mode Texture3DRetained object that this
207: * Texture3D component object will point to.
208: */
209: void createRetained() {
210: this .retained = new Texture3DRetained();
211: this .retained.setSource(this );
212: }
213:
214: /**
215: * @deprecated replaced with cloneNodeComponent(boolean forceDuplicate)
216: */
217: public NodeComponent cloneNodeComponent() {
218: Texture3DRetained t3d = (Texture3DRetained) retained;
219: Texture3D t = new Texture3D(t3d.getMipMapMode(), t3d.format,
220: t3d.width, t3d.height, t3d.depth);
221: t.duplicateNodeComponent(this );
222: return t;
223: }
224:
225: /**
226: * NOTE: Applications should <i>not</i> call this method directly.
227: * It should only be called by the cloneNode method.
228: *
229: * @deprecated replaced with duplicateNodeComponent(
230: * NodeComponent originalNodeComponent, boolean forceDuplicate)
231: */
232: public void duplicateNodeComponent(
233: NodeComponent originalNodeComponent) {
234: checkDuplicateNodeComponent(originalNodeComponent);
235: }
236:
237: /**
238: * Copies all node information from <code>originalNodeComponent</code> into
239: * the current node. This method is called from the
240: * <code>duplicateNode</code> method. This routine does
241: * the actual duplication of all "local data" (any data defined in
242: * this object).
243: *
244: * @param originalNodeComponent the original node to duplicate.
245: * @param forceDuplicate when set to <code>true</code>, causes the
246: * <code>duplicateOnCloneTree</code> flag to be ignored. When
247: * <code>false</code>, the value of each node's
248: * <code>duplicateOnCloneTree</code> variable determines whether
249: * NodeComponent data is duplicated or copied.
250: *
251: * @see Node#cloneTree
252: * @see NodeComponent#setDuplicateOnCloneTree
253: */
254: void duplicateAttributes(NodeComponent originalNodeComponent,
255: boolean forceDuplicate) {
256: super
257: .duplicateAttributes(originalNodeComponent,
258: forceDuplicate);
259:
260: ((Texture3DRetained) retained)
261: .initBoundaryModeR(((Texture3DRetained) originalNodeComponent.retained)
262: .getBoundaryModeR());
263:
264: }
265:
266: }
|