001: /*
002: * $RCSfile: Texture2D.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: import javax.vecmath.*;
035:
036: /**
037: * Texture2D is a subclass of Texture class. It extends Texture
038: * class by adding a constructor and a mutator method for
039: * setting a 2D texture image.
040: * <p>
041: * Note that as of Java 3D 1.5, the texture width and height are no longer
042: * required to be an exact power of two. However, not all graphics devices
043: * supports non-power-of-two textures. If non-power-of-two texture mapping is
044: * unsupported on a particular Canvas3D, textures with a width or height that
045: * are not an exact power of two are ignored for that canvas.
046: *
047: * @see Canvas3D#queryProperties
048: */
049: public class Texture2D extends Texture {
050:
051: /**
052: * @deprecated As of Java 3D 1.5 the optional detail texture feature is no
053: * longer supported.
054: * Specifies that this Texture object allows reading its detail
055: * texture information (e.g., detail texture image, detail texture mode,
056: * detail texture function, detail texture function points count,
057: * detail texture level)
058: *
059: * @since Java 3D 1.3
060: */
061: public static final int ALLOW_DETAIL_TEXTURE_READ = CapabilityBits.TEXTURE2D_ALLOW_DETAIL_TEXTURE_READ;
062:
063: /**
064: * @deprecated As of Java 3D 1.5 the optional detail texture feature is no
065: * longer supported.
066: * Performs linear sampling in both the base level
067: * texture image and the detail texture image, and combines the two
068: * texture values according to the detail texture mode.
069: *
070: * @since Java 3D 1.3
071: * @see #setMagFilter
072: */
073: public static final int LINEAR_DETAIL = 6;
074:
075: /**
076: * @deprecated As of Java 3D 1.5 the optional detail texture feature is no
077: * longer supported.
078: * Performs linear detail for the rgb
079: * components only. The alpha component is computed using
080: * BASE_LEVEL_LINEAR filter.
081: *
082: * @since Java 3D 1.3
083: * @see #setMagFilter
084: */
085: public static final int LINEAR_DETAIL_RGB = 7;
086:
087: /**
088: * @deprecated As of Java 3D 1.5 the optional detail texture feature is no
089: * longer supported.
090: * Performs linear detail for the alpha
091: * component only. The rgb components are computed using
092: * BASE_LEVEL_LINEAR filter.
093: *
094: * @since Java 3D 1.3
095: * @see #setMagFilter
096: */
097: public static final int LINEAR_DETAIL_ALPHA = 8;
098:
099: /**
100: * @deprecated As of Java 3D 1.5 the optional detail texture feature is no
101: * longer supported.
102: * Adds the detail texture image to the level 0 image of this texture
103: * object
104: *
105: * @since Java 3D 1.3
106: * @see #setDetailTextureMode
107: */
108: public static final int DETAIL_ADD = 0;
109:
110: /**
111: * @deprecated As of Java 3D 1.5 the optional detail texture feature is no
112: * longer supported.
113: * Modulates the detail texture image with the level 0 image of this
114: * texture object
115: *
116: * @since Java 3D 1.3
117: * @see #setDetailTextureMode
118: */
119: public static final int DETAIL_MODULATE = 1;
120:
121: // Array for setting default read capabilities
122: private static final int[] readCapabilities = { ALLOW_DETAIL_TEXTURE_READ };
123:
124: /**
125: * Constructs a texture object using default values.
126: *
127: * The default values are as follows:
128: * <ul>
129: * detail texture image: null<br>
130: * detail texture mode: DETAIL_MODULATE<br>
131: * detail texture func: null<br>
132: * detail texture level: 2<br>
133: * </ul>
134: * <p>
135: * Note that the default constructor creates a texture object with
136: * a width and height of 0 and is, therefore, not useful.
137: */
138: public Texture2D() {
139: super ();
140: // set default read capabilities
141: setDefaultReadCapabilities(readCapabilities);
142:
143: }
144:
145: /**
146: * Constructs an empty Texture2D object with specified mipmapMode
147: * format, width and height. Image at base level must be set by
148: * the application using 'setImage' method. If mipmapMode is
149: * set to MULTI_LEVEL_MIPMAP, images for base level through maximum level
150: * must be set.
151: * Note that a texture with a non-power-of-two width or height will
152: * only be rendered on a graphics device that supports non-power-of-two
153: * textures.
154: *
155: * @param mipMapMode type of mipmap for this Texture: One of
156: * BASE_LEVEL, MULTI_LEVEL_MIPMAP.
157: * @param format data format of Textures saved in this object.
158: * One of INTENSITY, LUMINANCE, ALPHA, LUMINANCE_ALPHA, RGB, RGBA.
159: * @param width width of image at level 0.
160: * @param height height of image at level 0.
161: * @exception IllegalArgumentException if width or height are NOT
162: * greater than 0 OR invalid format/mipmapMode is specified.
163: */
164: public Texture2D(int mipMapMode, int format, int width, int height) {
165:
166: super (mipMapMode, format, width, height);
167:
168: // set default read capabilities
169: setDefaultReadCapabilities(readCapabilities);
170: }
171:
172: /**
173: * Constructs an empty Texture2D object with specified mipMapMode,
174: * format, width, height, and boundaryWidth.
175: * Defaults are used for all other
176: * parameters. If <code>mipMapMode</code> is set to
177: * <code>BASE_LEVEL</code>, then the image at level 0 must be set
178: * by the application (using either the <code>setImage</code> or
179: * <code>setImages</code> method). If <code>mipMapMode</code> is
180: * set to <code>MULTI_LEVEL_MIPMAP</code>, then images for levels
181: * Base Level through Maximum Level must be set.
182: * Note that a texture with a non-power-of-two width or height will
183: * only be rendered on a graphics device that supports non-power-of-two
184: * textures.
185: *
186: * @param mipMapMode type of mipmap for this Texture: one of
187: * BASE_LEVEL, MULTI_LEVEL_MIPMAP
188: * @param format data format of Textures saved in this object.
189: * One of INTENSITY, LUMINANCE, ALPHA, LUMINANCE_ALPHA, RGB, RGBA
190: * @param width width of image at level 0. This
191: * does not include the width of the boundary.
192: * @param height height of image at level 0. This
193: * does not include the width of the boundary.
194: * @param boundaryWidth width of the boundary, which must be 0 or 1.
195: * @exception IllegalArgumentException if width or height are not greater
196: * than 0, if an invalid format or mipMapMode is specified, or
197: * if the boundaryWidth is < 0 or > 1
198: *
199: * @since Java 3D 1.3
200: */
201: public Texture2D(int mipMapMode, int format, int width, int height,
202: int boundaryWidth) {
203:
204: super (mipMapMode, format, width, height, boundaryWidth);
205:
206: // set default read capabilities
207: setDefaultReadCapabilities(readCapabilities);
208: }
209:
210: /**
211: * Sets the magnification filter function. This
212: * function is used when the pixel being rendered maps to an area
213: * less than or equal to one texel.
214: * @param magFilter the magnification filter, one of:
215: * FASTEST, NICEST, BASE_LEVEL_POINT, BASE_LEVEL_LINEAR,
216: * LINEAR_DETAIL, LINEAR_DETAIL_RGB, LINEAR_DETAIL_ALPHA,
217: * LINEAR_SHARPEN, LINEAR_SHARPEN_RGB, LINEAR_SHARPEN_ALPHA, or FILTER4.
218: *
219: * @exception RestrictedAccessException if the method is called
220: * when this object is part of live or compiled scene graph.
221: * @exception IllegalArgumentException if <code>minFilter</code>
222: * is a value other than <code>FASTEST</code>, <code>NICEST</code>,
223: * <code>BASE_LEVEL_POINT</code>, <code>BASE_LEVEL_LINEAR</code>,
224: * <code>LINEAR_DETAIL</code>, <code>LINEAR_DETAIL_RGB</code>,
225: * <code>LINEAR_DETAIL_ALPHA</code>,
226: * <code>LINEAR_SHARPEN</code>, <code>LINEAR_SHARPEN_RGB</code>,
227: * <code>LINEAR_SHARPEN_ALPHA</code>, or
228: * <code>FILTER4</code>.
229: *
230: * @see Canvas3D#queryProperties
231: *
232: * @since Java 3D 1.3
233: */
234: public void setMagFilter(int magFilter) {
235: checkForLiveOrCompiled();
236:
237: switch (magFilter) {
238: case FASTEST:
239: case NICEST:
240: case BASE_LEVEL_POINT:
241: case BASE_LEVEL_LINEAR:
242: case LINEAR_DETAIL:
243: case LINEAR_DETAIL_RGB:
244: case LINEAR_DETAIL_ALPHA:
245: case LINEAR_SHARPEN:
246: case LINEAR_SHARPEN_RGB:
247: case LINEAR_SHARPEN_ALPHA:
248: case FILTER4:
249: break;
250: default:
251: throw new IllegalArgumentException(J3dI18N
252: .getString("Texture29"));
253: }
254:
255: ((Texture2DRetained) this .retained).initMagFilter(magFilter);
256: }
257:
258: /**
259: * @deprecated As of Java 3D 1.5 the optional detail texture feature is no
260: * longer supported.
261: *
262: * @param detailTexture ImageComponent2D object containing the
263: * detail texture image.
264: * @exception RestrictedAccessException if the method is called
265: * when this object is part of live or compiled scene graph.
266: *
267: * @since Java 3D 1.3
268: * @see Canvas3D#queryProperties
269: */
270: public void setDetailImage(ImageComponent2D detailTexture) {
271: checkForLiveOrCompiled();
272: ((Texture2DRetained) this .retained)
273: .initDetailImage(detailTexture);
274: }
275:
276: /**
277: * @deprecated As of Java 3D 1.5 the optional detail texture feature is no
278: * longer supported.
279: *
280: * @return ImageComponent2D object containing the detail texture image.
281: *
282: * @exception CapabilityNotSetException if appropriate capability is
283: * not set and this object is part of live or compiled scene graph
284: *
285: * @since Java 3D 1.3
286: */
287: public ImageComponent2D getDetailImage() {
288: if (isLiveOrCompiled()) {
289: if (!this .getCapability(ALLOW_DETAIL_TEXTURE_READ)) {
290: throw new CapabilityNotSetException(J3dI18N
291: .getString("Texture2D0"));
292: }
293: }
294: return ((Texture2DRetained) this .retained).getDetailImage();
295: }
296:
297: /**
298: * @deprecated As of Java 3D 1.5 the optional detail texture feature is no
299: * longer supported.
300: *
301: * @param mode detail texture mode. One of: DETAIL_ADD or DETAIL_MODULATE
302: *
303: * @exception IllegalArgumentException if
304: * <code>mode</code> is a value other than
305: * <code>DETAIL_ADD</code>, or <code>DETAIL_MODULATE</code>
306: * @exception RestrictedAccessException if the method is called
307: * when this object is part of live or compiled scene graph.
308: *
309: * @since Java 3D 1.3
310: * @see Canvas3D#queryProperties
311: */
312: public void setDetailTextureMode(int mode) {
313: checkForLiveOrCompiled();
314: if ((mode != DETAIL_ADD) && (mode != DETAIL_MODULATE)) {
315: throw new IllegalArgumentException(J3dI18N
316: .getString("Texture2D1"));
317: }
318: ((Texture2DRetained) this .retained).initDetailTextureMode(mode);
319: }
320:
321: /**
322: * @deprecated As of Java 3D 1.5 the optional detail texture feature is no
323: * longer supported.
324: *
325: * @return the detail texture mode.
326: *
327: * @exception CapabilityNotSetException if appropriate capability is
328: * not set and this object is part of live or compiled scene graph
329: *
330: * @since Java 3D 1.3
331: */
332: public int getDetailTextureMode() {
333: if (isLiveOrCompiled()) {
334: if (!this .getCapability(ALLOW_DETAIL_TEXTURE_READ)) {
335: throw new CapabilityNotSetException(J3dI18N
336: .getString("Texture2D0"));
337: }
338: }
339: return ((Texture2DRetained) this .retained)
340: .getDetailTextureMode();
341: }
342:
343: /**
344: * @deprecated As of Java 3D 1.5 the optional detail texture feature is no
345: * longer supported.
346: *
347: * @param level the detail texture level.
348: *
349: * @exception IllegalArgumentException if <code>level</code> < 0
350: * @exception RestrictedAccessException if the method is called
351: * when this object is part of live or compiled scene graph.
352: *
353: * @since Java 3D 1.3
354: * @see Canvas3D#queryProperties
355: */
356: public void setDetailTextureLevel(int level) {
357: checkForLiveOrCompiled();
358: if (level < 0) {
359: throw new IllegalArgumentException(J3dI18N
360: .getString("Texture2D2"));
361: }
362: ((Texture2DRetained) this .retained)
363: .initDetailTextureLevel(level);
364: }
365:
366: /**
367: * @deprecated As of Java 3D 1.5 the optional detail texture feature is no
368: * longer supported.
369: *
370: * @return the detail texture level.
371: *
372: * @exception CapabilityNotSetException if appropriate capability is
373: * not set and this object is part of live or compiled scene graph
374: *
375: * @since Java 3D 1.3
376: */
377: public int getDetailTextureLevel() {
378: if (isLiveOrCompiled()) {
379: if (!this .getCapability(ALLOW_DETAIL_TEXTURE_READ)) {
380: throw new CapabilityNotSetException(J3dI18N
381: .getString("Texture2D0"));
382: }
383: }
384: return ((Texture2DRetained) this .retained)
385: .getDetailTextureLevel();
386: }
387:
388: /**
389: * @deprecated As of Java 3D 1.5 the optional detail texture feature is no
390: * longer supported.
391: *
392: * @param lod array containing the level-of-detail values.
393: * @param pts array containing the function values for the corresponding
394: * level-of-detail values.
395: *
396: * @exception IllegalStateException if the length of <code>lod</code>
397: * does not match the length of <code>pts</code>
398: * @exception RestrictedAccessException if the method is called
399: * when this object is part of live or compiled scene graph.
400: *
401: * @since Java 3D 1.3
402: * @see Canvas3D#queryProperties
403: */
404: public void setDetailTextureFunc(float[] lod, float[] pts) {
405: checkForLiveOrCompiled();
406: if (((lod != null) && (pts != null) && (lod.length == pts.length))
407: || ((lod == null) && (pts == null))) {
408: ((Texture2DRetained) this .retained).initDetailTextureFunc(
409: lod, pts);
410: } else {
411: throw new IllegalStateException(J3dI18N
412: .getString("Texture2D3"));
413: }
414: }
415:
416: /**
417: * @deprecated As of Java 3D 1.5 the optional detail texture feature is no
418: * longer supported.
419: *
420: * @param pts array of Point2f containing the lod as well as the
421: * corresponding function value.
422: *
423: * @exception RestrictedAccessException if the method is called
424: * when this object is part of live or compiled scene graph.
425: *
426: * @since Java 3D 1.3
427: * @see Canvas3D#queryProperties
428: */
429: public void setDetailTextureFunc(Point2f[] pts) {
430: checkForLiveOrCompiled();
431: ((Texture2DRetained) this .retained).initDetailTextureFunc(pts);
432: }
433:
434: /**
435: * @deprecated As of Java 3D 1.5 the optional detail texture feature is no
436: * longer supported.
437: *
438: * @return the number of points in the detail texture LOD function.
439: *
440: * @exception CapabilityNotSetException if appropriate capability is
441: * not set and this object is part of live or compiled scene graph
442: *
443: * @since Java 3D 1.3
444: */
445: public int getDetailTextureFuncPointsCount() {
446: if (isLiveOrCompiled()) {
447: if (!this .getCapability(ALLOW_DETAIL_TEXTURE_READ)) {
448: throw new CapabilityNotSetException(J3dI18N
449: .getString("Texture2D0"));
450: }
451: }
452: return ((Texture2DRetained) this .retained)
453: .getDetailTextureFuncPointsCount();
454: }
455:
456: /**
457: * @deprecated As of Java 3D 1.5 the optional detail texture feature is no
458: * longer supported.
459: *
460: * @param lod the array to receive the level-of-detail values.
461: * @param pts the array to receive the function values for the
462: * corresponding level-of-detail values.
463: *
464: * @exception CapabilityNotSetException if appropriate capability is
465: * not set and this object is part of live or compiled scene graph
466: *
467: * @since Java 3D 1.3
468: */
469: public void getDetailTextureFunc(float[] lod, float[] pts) {
470: if (isLiveOrCompiled()) {
471: if (!this .getCapability(ALLOW_DETAIL_TEXTURE_READ)) {
472: throw new CapabilityNotSetException(J3dI18N
473: .getString("Texture2D0"));
474: }
475: }
476: ((Texture2DRetained) this .retained).getDetailTextureFunc(lod,
477: pts);
478: }
479:
480: /**
481: * @deprecated As of Java 3D 1.5 the optional detail texture feature is no
482: * longer supported.
483: *
484: * @param pts the array to receive the detail texture LOD function points
485: *
486: * @exception CapabilityNotSetException if appropriate capability is
487: * not set and this object is part of live or compiled scene graph
488: *
489: * @since Java 3D 1.3
490: */
491: public void getDetailTextureFunc(Point2f[] pts) {
492: if (isLiveOrCompiled()) {
493: if (!this .getCapability(ALLOW_DETAIL_TEXTURE_READ)) {
494: throw new CapabilityNotSetException(J3dI18N
495: .getString("Texture2D0"));
496: }
497: }
498: ((Texture2DRetained) this .retained).getDetailTextureFunc(pts);
499: }
500:
501: /**
502: * Creates a retained mode Texture2DRetained object that this
503: * Texture2D component object will point to.
504: */
505: void createRetained() {
506: this .retained = new Texture2DRetained();
507: this .retained.setSource(this );
508: }
509:
510: /**
511: * @deprecated replaced with cloneNodeComponent(boolean forceDuplicate)
512: */
513: public NodeComponent cloneNodeComponent() {
514: Texture2DRetained t2d = (Texture2DRetained) retained;
515:
516: Texture2D t = new Texture2D(t2d.getMipMapMode(), t2d.format,
517: t2d.width, t2d.height);
518: t.duplicateNodeComponent(this );
519: return t;
520: }
521:
522: /**
523: * NOTE: Applications should <i>not</i> call this method directly.
524: * It should only be called by the cloneNode method.
525: *
526: * @deprecated replaced with duplicateNodeComponent(
527: * NodeComponent originalNodeComponent, boolean forceDuplicate)
528: */
529: public void duplicateNodeComponent(
530: NodeComponent originalNodeComponent) {
531: checkDuplicateNodeComponent(originalNodeComponent);
532: }
533:
534: /**
535: * Copies all node information from <code>originalNodeComponent</code> into
536: * the current node. This method is called from the
537: * <code>duplicateNode</code> method. This routine does
538: * the actual duplication of all "local data" (any data defined in
539: * this object).
540: *
541: * @param originalNodeComponent the original node to duplicate.
542: * @param forceDuplicate when set to <code>true</code>, causes the
543: * <code>duplicateOnCloneTree</code> flag to be ignored. When
544: * <code>false</code>, the value of each node's
545: * <code>duplicateOnCloneTree</code> variable determines whether
546: * NodeComponent data is duplicated or copied.
547: *
548: * @see Node#cloneTree
549: * @see NodeComponent#setDuplicateOnCloneTree
550: */
551: void duplicateAttributes(NodeComponent originalNodeComponent,
552: boolean forceDuplicate) {
553: super
554: .duplicateAttributes(originalNodeComponent,
555: forceDuplicate);
556:
557: Texture2DRetained tex = (Texture2DRetained) originalNodeComponent.retained;
558: Texture2DRetained rt = (Texture2DRetained) retained;
559:
560: rt.initDetailImage(tex.getDetailImage());
561: rt.initDetailTextureMode(tex.getDetailTextureMode());
562: rt.initDetailTextureLevel(tex.getDetailTextureLevel());
563: rt.initDetailTextureFunc(tex.getDetailTextureFunc());
564: }
565: }
|