001: /*
002: * $RCSfile: Texture2DRetained.java,v $
003: *
004: * Copyright 1998-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.6 $
028: * $Date: 2008/02/28 20:17:31 $
029: * $State: Exp $
030: */
031:
032: package javax.media.j3d;
033:
034: import java.util.*;
035: import javax.vecmath.*;
036:
037: /**
038: * Texture2D is a subclass of Texture class. It extends Texture
039: * class by adding a constructor and a mutator method for
040: * setting a 2D texture image.
041: */
042: class Texture2DRetained extends TextureRetained {
043:
044: // Note : There is hardly any HW vendor supports detail Image.
045: // Detail Image operation is simply no-op in 1.5.
046:
047: // currently detail image is only applicable to 2D texture
048: // detail texture info
049:
050: // These members are unused except for public set and get methods.
051: private ImageComponent2DRetained detailImage = null;
052: private int detailTextureMode = Texture2D.DETAIL_MODULATE;
053: private int detailTextureLevel = 2;
054: private int numDetailTextureFuncPts = 0;
055: private float detailTextureFuncPts[] = null; // array of pairs of floats
056:
057: // first value for LOD
058: // second value for the fcn value
059:
060: /**
061: * Set detail texture image
062: */
063: final void initDetailImage(ImageComponent2D image) {
064: if (image == null) {
065: detailImage = null;
066: } else {
067: detailImage = (ImageComponent2DRetained) image.retained;
068: }
069: }
070:
071: /**
072: * Get detail texture image
073: */
074: final ImageComponent2D getDetailImage() {
075: if (detailImage != null) {
076: return (ImageComponent2D) detailImage.source;
077: } else {
078: return null;
079: }
080: }
081:
082: /**
083: * Set detail texture mode
084: */
085: final void initDetailTextureMode(int mode) {
086: detailTextureMode = mode;
087: }
088:
089: /**
090: * Get detail texture mode
091: */
092: final int getDetailTextureMode() {
093: return detailTextureMode;
094: }
095:
096: /**
097: * Set detail texture level
098: */
099: final void initDetailTextureLevel(int level) {
100: detailTextureLevel = level;
101: }
102:
103: /**
104: * Get detail texture level
105: */
106: final int getDetailTextureLevel() {
107: return detailTextureLevel;
108: }
109:
110: /**
111: * Set detail texture function
112: */
113: final void initDetailTextureFunc(float[] lod, float[] pts) {
114: if (lod == null) { // pts will be null too.
115: detailTextureFuncPts = null;
116: numDetailTextureFuncPts = 0;
117: } else {
118: numDetailTextureFuncPts = lod.length;
119: if ((detailTextureFuncPts == null)
120: || (detailTextureFuncPts.length != lod.length * 2)) {
121: detailTextureFuncPts = new float[lod.length * 2];
122: }
123: for (int i = 0, j = 0; i < lod.length; i++) {
124: detailTextureFuncPts[j++] = lod[i];
125: detailTextureFuncPts[j++] = pts[i];
126: }
127: }
128: }
129:
130: final void initDetailTextureFunc(Point2f[] pts) {
131: if (pts == null) {
132: detailTextureFuncPts = null;
133: numDetailTextureFuncPts = 0;
134: } else {
135: numDetailTextureFuncPts = pts.length;
136: if ((detailTextureFuncPts == null)
137: || (detailTextureFuncPts.length != pts.length * 2)) {
138: detailTextureFuncPts = new float[pts.length * 2];
139: }
140: for (int i = 0, j = 0; i < pts.length; i++) {
141: detailTextureFuncPts[j++] = pts[i].x;
142: detailTextureFuncPts[j++] = pts[i].y;
143: }
144: }
145: }
146:
147: final void initDetailTextureFunc(float[] pts) {
148: if (pts == null) {
149: detailTextureFuncPts = null;
150: numDetailTextureFuncPts = 0;
151: } else {
152: numDetailTextureFuncPts = pts.length / 2;
153: if ((detailTextureFuncPts == null)
154: || (detailTextureFuncPts.length != pts.length)) {
155: detailTextureFuncPts = new float[pts.length];
156: }
157: for (int i = 0; i < pts.length; i++) {
158: detailTextureFuncPts[i] = pts[i];
159: }
160: }
161: }
162:
163: /**
164: * Get number of points in the detail texture LOD function
165: */
166: final int getDetailTextureFuncPointsCount() {
167: return numDetailTextureFuncPts;
168: }
169:
170: /**
171: * Copies the array of detail texture LOD function points into the
172: * specified arrays
173: */
174: final void getDetailTextureFunc(float[] lod, float[] pts) {
175: if (detailTextureFuncPts != null) {
176: for (int i = 0, j = 0; i < numDetailTextureFuncPts; i++) {
177: lod[i] = detailTextureFuncPts[j++];
178: pts[i] = detailTextureFuncPts[j++];
179: }
180: }
181: }
182:
183: final void getDetailTextureFunc(Point2f[] pts) {
184: if (detailTextureFuncPts != null) {
185: for (int i = 0, j = 0; i < numDetailTextureFuncPts; i++) {
186: pts[i].x = detailTextureFuncPts[j++];
187: pts[i].y = detailTextureFuncPts[j++];
188: }
189: }
190: }
191:
192: /**
193: * internal method only -- returns the detail texture LOD function
194: */
195: final float[] getDetailTextureFunc() {
196: return detailTextureFuncPts;
197: }
198:
199: }
|