summaryrefslogtreecommitdiffstats
path: root/src/javax/media/j3d/TextureCubeMap.java
blob: 10fbdd8ae75ad49f6deaffc51efd9d10b283a503 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
/*
 * Copyright 2001-2008 Sun Microsystems, Inc.  All Rights Reserved.
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * This code is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License version 2 only, as
 * published by the Free Software Foundation.  Sun designates this
 * particular file as subject to the "Classpath" exception as provided
 * by Sun in the LICENSE file that accompanied this code.
 *
 * This code is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * version 2 for more details (a copy is included in the LICENSE file that
 * accompanied this code).
 *
 * You should have received a copy of the GNU General Public License version
 * 2 along with this work; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 *
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
 * CA 95054 USA or visit www.sun.com if you need additional information or
 * have any questions.
 *
 */

package javax.media.j3d;


/**
 * TextureCubeMap is a subclass of Texture class. It defines
 * a special kind of texture mapping which is composed of a set of six
 * 2D images representating the six faces of a cube. The texture coordinate
 * (s,t,r) is used as a 3D direction vector emanating from the center
 * of a cube to select a particular face of the cube based on the
 * largest magnitude coordinate (the major axis). A new 2D texture coordinate
 * (s,t) is then determined by dividing the other two coordinates (the minor
 * axes) by the major axis value. The new coordinate is then used for
 * texel lookup from the selected texture image of this cube map.
 *
 * The TextureCubeMap image is defined by specifying the images for each
 * face of the cube. The cube map texture can be thought of as centered at
 * the orgin of and aligned to an XYZ coordinate system. The names
 * of the cube faces are:
 *
 * <UL>
 * <LI>POSITIVE_X</LI>
 * <LI>NEGATIVE_X</LI>
 * <LI>POSITIVE_Y</LI>
 * <LI>NEGATIVE_Y</LI>
 * <LI>POSITIVE_Z</LI>
 * <LI>NEGATIVE_Z</LI>
 * </UL>
 *
 * <p>
 * Note that as of Java 3D 1.5, the texture width and height are no longer
 * required to be an exact power of two. However, not all graphics devices
 * supports non-power-of-two textures. If non-power-of-two texture mapping is
 * unsupported on a particular Canvas3D, textures with a width or height that
 * are not an exact power of two are ignored for that canvas.
 *
 * @see Canvas3D#queryProperties
 *
 * @since Java 3D 1.3
 */
public class TextureCubeMap extends Texture {

    // TODO KCR : NPOT

    /**
     * Specifies the face of the cube that is pierced by the positive x axis
     */
    public static final int POSITIVE_X = 0;

    /**
     * Specifies the face of the cube that is pierced by the negative x axis
     */
    public static final int NEGATIVE_X = 1;

    /**
     * Specifies the face of the cube that is pierced by the positive y axis
     */
    public static final int POSITIVE_Y = 2;

    /**
     * Specifies the face of the cube that is pierced by the negative y axis
     */
    public static final int NEGATIVE_Y = 3;

    /**
     * Specifies the face of the cube that is pierced by the positive z axis
     */
    public static final int POSITIVE_Z = 4;

    /**
     * Specifies the face of the cube that is pierced by the negative z axis
     */
    public static final int NEGATIVE_Z = 5;


    /**
     * Constructs a texture object using default values.
     * Note that the default constructor creates a texture object with
     * a width of 0 and is, therefore, not useful.
     */
    public TextureCubeMap() {
    	super();
    }

    /**
     * Constructs an empty TextureCubeMap object with specified mipmapMode
     * format, and width. Image at base level
     * must be set by
     * the application using 'setImage' method. If mipmapMode is
     * set to MULTI_LEVEL_MIPMAP, images for base level through maximum level
     * must be set.
     * Note that cube map is square in dimensions, hence specifying width
     * is sufficient.
     * Note also that a texture with a non-power-of-two width will
     * only be rendered on a graphics device that supports non-power-of-two
     * textures.
     *
     * @param mipmapMode type of mipmap for this Texture: One of
     * BASE_LEVEL, MULTI_LEVEL_MIPMAP.
     * @param format data format of Textures saved in this object.
     * One of INTENSITY, LUMINANCE, ALPHA, LUMINANCE_ALPHA, RGB, RGBA.
     * @param width width (and height) of image at level 0.
     * @exception IllegalArgumentException if width is not greater
     * than 0 OR invalid format/mipmapMode is specified.
     */
    public TextureCubeMap(
        int     mipmapMode,
        int     format,
        int     width){

        super(mipmapMode, format, width, width);
    }

    /**
     * Constructs an empty TextureCubeMap object with specified mipmapMode
     * format, width, and boundary width. Image at base level
     * must be set by
     * the application using 'setImage' method. If mipmapMode is
     * set to MULTI_LEVEL_MIPMAP, images for base level through maximum level
     * must be set.
     * Note that cube map is square in dimensions, hence specifying width
     * is sufficient.
     * Note also that a texture with a non-power-of-two width will
     * only be rendered on a graphics device that supports non-power-of-two
     * textures.
     *
     * @param mipmapMode type of mipmap for this Texture: One of
     * BASE_LEVEL, MULTI_LEVEL_MIPMAP.
     * @param format data format of Textures saved in this object.
     * One of INTENSITY, LUMINANCE, ALPHA, LUMINANCE_ALPHA, RGB, RGBA.
     * @param width width (and height) of image at level 0. This
     * does not include the width of the boundary.
     * @param boundaryWidth width of the boundary, which must be 0 or 1.
     *
     * @exception IllegalArgumentException if width is not
     * greater than 0 OR invalid format/mipmapMode is specified.
     */
    public TextureCubeMap(
        int     mipmapMode,
        int     format,
        int     width,
        int     boundaryWidth){

        super(mipmapMode, format, width, width, boundaryWidth);
    }

    /**
     * Sets the image for a specified mipmap level of a specified face
     * of the cube map
     *
     * @param level mipmap level
     * @param face face of the cube map. One of:
     * <code>POSITIVE_X</code>, <code>NEGATIVE_X</code>,
     * <code>POSITIVE_Y</code>, <code>NEGATIVE_Y</code>,
     * <code>POSITIVE_Z</code> or <code>NEGATIVE_Z</code>.
     * @param image ImageComponent2D object containing the image
     *
     * @exception IllegalArgumentException if
     * <code>face</code> has a value other
     * than <code>POSITIVE_X</code>, <code>NEGATIVE_X</code>,
     * <code>POSITIVE_Y</code>, <code>NEGATIVE_Y</code>,
     * <code>POSITIVE_Z</code> or <code>NEGATIVE_Z</code>.
     *
     * @exception CapabilityNotSetException if appropriate capability is
     * not set and this object is part of live or compiled scene graph
     *
     * @exception IllegalSharingException if this TextureCubeMap is live and
     * the specified image is being used by a Canvas3D as an off-screen buffer.
     *
     * @exception IllegalSharingException if this TextureCubeMap is
     * being used by an immediate mode context and
     * the specified image is being used by a Canvas3D as an off-screen buffer.
     */
    public void setImage(int level, int face, ImageComponent2D image) {
        if (isLiveOrCompiled()) {
          if(!this.getCapability(ALLOW_IMAGE_WRITE))
            throw new CapabilityNotSetException(
			J3dI18N.getString("TextureCubeMap1"));
        }

        validateImageIllegalSharing(image);

        if (isLive())
            ((TextureCubeMapRetained)this.retained).setImage(level, face, image);
        else
            ((TextureCubeMapRetained)this.retained).initImage(level, face, image);
    }

    /**
     * Sets the array of images for mipmap levels from base level through
     * max level for a specified face of the cube map
     *
     * @param face face of the cube map. One of:
     * <code>POSITIVE_X</code>, <code>NEGATIVE_X</code>,
     * <code>POSITIVE_Y</code>, <code>NEGATIVE_Y</code>,
     * <code>POSITIVE_Z</code> or <code>NEGATIVE_Z</code>.
     * @param images array of ImageComponent2D objects containing the images
     *
     * @exception IllegalArgumentException if
     * <code>face</code> has a value other
     * than <code>POSITIVE_X</code>, <code>NEGATIVE_X</code>,
     * <code>POSITIVE_Y</code>, <code>NEGATIVE_Y</code>,
     * <code>POSITIVE_Z</code> or <code>NEGATIVE_Z</code>.
     *
     * @exception CapabilityNotSetException if appropriate capability is
     * not set and this object is part of live or compiled scene graph
     *
     * @exception IllegalSharingException if this TextureCubeMap is live and
     * any of the specified images are being used by a Canvas3D as an
     * off-screen buffer.
     *
     * @exception IllegalSharingException if this TextureCubeMap is
     * being used by an immediate mode context and
     * any of the specified images are being used by a Canvas3D as an
     * off-screen buffer.
     */
    public void setImages(int face, ImageComponent2D[] images) {
        if (isLiveOrCompiled()) {
          if(!this.getCapability(ALLOW_IMAGE_WRITE))
            throw new CapabilityNotSetException(
                        J3dI18N.getString("TextureCubeMap1"));
        }

         // Do illegal sharing check
        for(int i=0; i<images.length; i++) {
            validateImageIllegalSharing(images[i]);
        }

        if (isLive())
            ((TextureCubeMapRetained)this.retained).setImages(face, images);
        else
            ((TextureCubeMapRetained)this.retained).initImages(face, images);

    }


    /**
     * Retrieves the image for a specified mipmap level of a particular
     * face of the cube map.
     * @param level mipmap level to get.
     * @param face face of the cube map. One of:
     * <code>POSITIVE_X</code>, <code>NEGATIVE_X</code>,
     * <code>POSITIVE_Y</code>, <code>NEGATIVE_Y</code>,
     * <code>POSITIVE_Z</code> or <code>NEGATIVE_Z</code>.
     * @return the ImageComponent object containing the texture image at
     * the specified mipmap level.
     *
     * @exception IllegalArgumentException if
     * <code>face</code> has a value other
     * than <code>POSITIVE_X</code>, <code>NEGATIVE_X</code>,
     * <code>POSITIVE_Y</code>, <code>NEGATIVE_Y</code>,
     * <code>POSITIVE_Z</code> or <code>NEGATIVE_Z</code>.
     *
     * @exception CapabilityNotSetException if appropriate capability is
     * not set and this object is part of live or compiled scene graph
     */
    public ImageComponent getImage(int level, int face) {
        if (isLiveOrCompiled()) {
          if(!this.getCapability(ALLOW_IMAGE_READ))
            throw new CapabilityNotSetException(
			J3dI18N.getString("TextureCubeMap2"));
        }

        return ((TextureCubeMapRetained)this.retained).getImage(level, face);
    }

    /**
     * Retrieves the array of images for all mipmap level of a particular
     * face of the cube map.
     * @param face face of the cube map. One of:
     * <code>POSITIVE_X</code>, <code>NEGATIVE_X</code>,
     * <code>POSITIVE_Y</code>, <code>NEGATIVE_Y</code>,
     * <code>POSITIVE_Z</code> or <code>NEGATIVE_Z</code>.
     * @return an array of ImageComponent object for the particular face of
     * of the cube map.
     *
     * @exception IllegalArgumentException if
     * <code>face</code> has a value other
     * than <code>POSITIVE_X</code>, <code>NEGATIVE_X</code>,
     * <code>POSITIVE_Y</code>, <code>NEGATIVE_Y</code>,
     * <code>POSITIVE_Z</code> or <code>NEGATIVE_Z</code>.
     *
     * @exception CapabilityNotSetException if appropriate capability is
     * not set and this object is part of live or compiled scene graph
     */
    public ImageComponent[] getImages(int face) {
        if (isLiveOrCompiled()) {
          if(!this.getCapability(ALLOW_IMAGE_READ))
            throw new CapabilityNotSetException(
                        J3dI18N.getString("TextureCubeMap2"));
        }

        return ((TextureCubeMapRetained)this.retained).getImages(face);
    }


    /**
     * This method is not supported for TextureCubeMap.
     * A face of the cube map has to be specified when setting an image
     * for a particular level of the cube map.
     *
     * @exception UnsupportedOperationException this method is not supported
     *
     * @since Java 3D 1.3
     */
    @Override
    public void setImage(int level, ImageComponent image) {
	throw new UnsupportedOperationException();
    }


    /**
     * This method is not supported for TextureCubeMap.
     * A face of the cube map has to be specified when setting images
     * for the cube map.
     *
     * @exception UnsupportedOperationException this method is not supported
     *
     * @since Java 3D 1.3
     */
    @Override
    public void setImages(ImageComponent[] images) {
	throw new UnsupportedOperationException();
    }

    /**
     * This method is not supported for TextureCubeMap.
     * A face of the cube map has to be specified when retrieving an image
     * for a particular level of the cube map.
     *
     * @exception UnsupportedOperationException this method is not supported
     *
     * @since Java 3D 1.3
     */
    @Override
    public ImageComponent getImage(int level) {
        throw new UnsupportedOperationException();
    }


    /**
     * This method is not supported for TextureCubeMap.
     * A face of the cube map has to be specified when retrieving images
     * for the cube map.
     *
     * @exception UnsupportedOperationException this method is not supported
     *
     * @since Java 3D 1.3
     */
    @Override
    public ImageComponent[] getImages() {
        throw new UnsupportedOperationException();
    }


    /**
     * Creates a retained mode TextureCubeMapRetained object that this
     * TextureCubeMap component object will point to.
     */
    @Override
    void createRetained() {
    	this.retained = new TextureCubeMapRetained();
    	this.retained.setSource(this);
    }

    /**
     * NOTE: Applications should not call this method directly.
     * It should only be called by the cloneNode method.
     *
     * @deprecated replaced with duplicateNodeComponent(
     *  NodeComponent originalNodeComponent, boolean forceDuplicate)
     */
    @Override
    public void duplicateNodeComponent(NodeComponent originalNodeComponent) {
    	checkDuplicateNodeComponent(originalNodeComponent);
    }
}