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
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
|
/*
* Copyright 2005-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;
import javax.vecmath.Matrix3f;
import javax.vecmath.Matrix4f;
import javax.vecmath.Point2f;
import javax.vecmath.Point2i;
import javax.vecmath.Point3f;
import javax.vecmath.Point3i;
import javax.vecmath.Point4f;
import javax.vecmath.Point4i;
import javax.vecmath.Tuple2f;
import javax.vecmath.Tuple2i;
import javax.vecmath.Tuple3f;
import javax.vecmath.Tuple3i;
import javax.vecmath.Tuple4f;
import javax.vecmath.Tuple4i;
/**
* The ShaderAttributeValueRetained object encapsulates a uniform shader
* attribute whose value is specified explicitly.
*/
class ShaderAttributeValueRetained extends ShaderAttributeObjectRetained {
ShaderAttributeValueRetained() {
}
@Override
synchronized void createMirrorObject() {
// System.err.println("ShaderAttributeValueRetained : createMirrorObject");
// This method should only call by setLive().
if (mirror == null) {
ShaderAttributeValueRetained mirrorSAV = new ShaderAttributeValueRetained();
mirrorSAV.createObjectData(getValue());
mirror = mirrorSAV;
mirror.source = source;
}
initMirrorObject();
}
/**
* Computes the base class from the specified object. A
* ClassCastException is thrown if the object is not an instance
* of one of the allowed classes.
*/
@Override
int computeClassType(Object value) {
Class objClass = value.getClass();
if (objClass.isArray()) {
throw new ClassCastException(objClass + " -- array class not allowed");
}
for (int i = 0; i < classTable.length; i++) {
if (classTable[i].isInstance(value)) {
return i;
}
}
throw new ClassCastException(objClass + " -- unrecognized class");
}
/**
* Returns the base class represented by the specified class type.
*/
@Override
Class getBaseClass(int classType) {
return classTable[classType];
}
/**
* Creates an attribute wrapper object of the specified class
* type, and stores the specified object.
*/
@Override
AttrWrapper createAttrWrapper(Object value, int classType) {
ValueWrapper attrWrapper = null;
switch (classType) {
case TYPE_INTEGER:
attrWrapper = new IntegerWrapper();
break;
case TYPE_FLOAT:
attrWrapper = new FloatWrapper();
break;
// case TYPE_DOUBLE:
// attrWrapper = new DoubleWrapper();
// break;
case TYPE_TUPLE2I:
attrWrapper = new Tuple2iWrapper();
break;
case TYPE_TUPLE2F:
attrWrapper = new Tuple2fWrapper();
break;
// case TYPE_TUPLE2D:
// attrWrapper = new Tuple2dWrapper();
// break;
case TYPE_TUPLE3I:
attrWrapper = new Tuple3iWrapper();
break;
case TYPE_TUPLE3F:
attrWrapper = new Tuple3fWrapper();
break;
// case TYPE_TUPLE3D:
// attrWrapper = new Tuple3dWrapper();
// break;
case TYPE_TUPLE4I:
attrWrapper = new Tuple4iWrapper();
break;
case TYPE_TUPLE4F:
attrWrapper = new Tuple4fWrapper();
break;
// case TYPE_TUPLE4D:
// attrWrapper = new Tuple4dWrapper();
// break;
case TYPE_MATRIX3F:
attrWrapper = new Matrix3fWrapper();
break;
// case TYPE_MATRIX3D:
// attrWrapper = new Matrix3dWrapper();
// break;
case TYPE_MATRIX4F:
attrWrapper = new Matrix4fWrapper();
break;
// case TYPE_MATRIX4D:
// attrWrapper = new Matrix4dWrapper();
// break;
default:
// Should never get here
assert false;
return null;
}
attrWrapper.set(value);
return attrWrapper;
}
//
// The following wrapper classes are used to store a copy of the
// user-specified shader attribute value. There is a wrapper class
// for each supported base class.
//
// Base wrapper class for non-array attribute types
static abstract class ValueWrapper extends AttrWrapper {
// No additional fields or methods are defined in this class
}
// Wrapper class for Integer
static class IntegerWrapper extends ValueWrapper {
private int[] value = new int[1];
@Override
void set(Object value) {
this.value[0] = ((Integer)value).intValue();
}
@Override
Object get() {
return new Integer(this.value[0]);
}
@Override
Object getRef() {
return this.value;
}
}
// Wrapper class for Float
static class FloatWrapper extends ValueWrapper {
private float[] value = new float[1];
@Override
void set(Object value) {
this.value[0] = ((Float)value).floatValue();
}
@Override
Object get() {
return new Float(this.value[0]);
}
@Override
Object getRef() {
return this.value;
}
}
/*
// Wrapper class for Double
static class DoubleWrapper extends ValueWrapper {
private double[] value = new double[1];
void set(Object value) {
this.value[0] = ((Double)value).doubleValue();
}
Object get() {
return new Double(value[0]);
}
Object getRef() {
return value;
}
}
*/
// Wrapper class for Tuple2i
static class Tuple2iWrapper extends ValueWrapper {
private int[] value = new int[2];
@Override
void set(Object value) {
((Tuple2i)value).get(this.value);
}
@Override
Object get() {
return new Point2i(value);
}
@Override
Object getRef() {
return value;
}
}
// Wrapper class for Tuple2f
static class Tuple2fWrapper extends ValueWrapper {
private float[] value = new float[2];
@Override
void set(Object value) {
((Tuple2f)value).get(this.value);
}
@Override
Object get() {
return new Point2f(value);
}
@Override
Object getRef() {
return value;
}
}
/*
// Wrapper class for Tuple2d
static class Tuple2dWrapper extends ValueWrapper {
private double[] value = new double[2];
void set(Object value) {
((Tuple2d)value).get(this.value);
}
Object get() {
return new Point2d(value);
}
Object getRef() {
return value;
}
}
*/
// Wrapper class for Tuple3i
static class Tuple3iWrapper extends ValueWrapper {
private int[] value = new int[3];
@Override
void set(Object value) {
((Tuple3i)value).get(this.value);
}
@Override
Object get() {
return new Point3i(value);
}
@Override
Object getRef() {
return value;
}
}
// Wrapper class for Tuple3f
static class Tuple3fWrapper extends ValueWrapper {
private float[] value = new float[3];
@Override
void set(Object value) {
((Tuple3f)value).get(this.value);
}
@Override
Object get() {
return new Point3f(value);
}
@Override
Object getRef() {
return value;
}
}
/*
// Wrapper class for Tuple3d
static class Tuple3dWrapper extends ValueWrapper {
private double[] value = new double[3];
void set(Object value) {
((Tuple3d)value).get(this.value);
}
Object get() {
return new Point3d(value);
}
Object getRef() {
return value;
}
}
*/
// Wrapper class for Tuple4i
static class Tuple4iWrapper extends ValueWrapper {
private int[] value = new int[4];
@Override
void set(Object value) {
((Tuple4i)value).get(this.value);
}
@Override
Object get() {
return new Point4i(value);
}
@Override
Object getRef() {
return value;
}
}
// Wrapper class for Tuple4f
static class Tuple4fWrapper extends ValueWrapper {
private float[] value = new float[4];
@Override
void set(Object value) {
((Tuple4f)value).get(this.value);
}
@Override
Object get() {
return new Point4f(value);
}
@Override
Object getRef() {
return value;
}
}
/*
// Wrapper class for Tuple4d
static class Tuple4dWrapper extends ValueWrapper {
private double[] value = new double[4];
void set(Object value) {
((Tuple4d)value).get(this.value);
}
Object get() {
return new Point4d(value);
}
Object getRef() {
return value;
}
}
*/
// Wrapper class for Matrix3f
static class Matrix3fWrapper extends ValueWrapper {
private float[] value = new float[9];
@Override
void set(Object value) {
Matrix3f m = (Matrix3f)value;
this.value[0] = m.m00;
this.value[1] = m.m01;
this.value[2] = m.m02;
this.value[3] = m.m10;
this.value[4] = m.m11;
this.value[5] = m.m12;
this.value[6] = m.m20;
this.value[7] = m.m21;
this.value[8] = m.m22;
}
@Override
Object get() {
return new Matrix3f(value);
}
@Override
Object getRef() {
return value;
}
}
/*
// Wrapper class for Matrix3d
static class Matrix3dWrapper extends ValueWrapper {
private double[] value = new double[9];
void set(Object value) {
Matrix3d m = (Matrix3d)value;
this.value[0] = m.m00;
this.value[1] = m.m01;
this.value[2] = m.m02;
this.value[3] = m.m10;
this.value[4] = m.m11;
this.value[5] = m.m12;
this.value[6] = m.m20;
this.value[7] = m.m21;
this.value[8] = m.m22;
}
Object get() {
return new Matrix3d(value);
}
Object getRef() {
return value;
}
}
*/
// Wrapper class for Matrix4f
static class Matrix4fWrapper extends ValueWrapper {
private float[] value = new float[16];
@Override
void set(Object value) {
Matrix4f m = (Matrix4f)value;
this.value[0] = m.m00;
this.value[1] = m.m01;
this.value[2] = m.m02;
this.value[3] = m.m03;
this.value[4] = m.m10;
this.value[5] = m.m11;
this.value[6] = m.m12;
this.value[7] = m.m13;
this.value[8] = m.m20;
this.value[9] = m.m21;
this.value[10] = m.m22;
this.value[11] = m.m23;
this.value[12] = m.m30;
this.value[13] = m.m31;
this.value[14] = m.m32;
this.value[15] = m.m33;
}
@Override
Object get() {
return new Matrix4f(value);
}
@Override
Object getRef() {
return value;
}
}
/*
// Wrapper class for Matrix4d
static class Matrix4dWrapper extends ValueWrapper {
private double[] value = new double[16];
void set(Object value) {
Matrix4d m = (Matrix4d)value;
this.value[0] = m.m00;
this.value[1] = m.m01;
this.value[2] = m.m02;
this.value[3] = m.m03;
this.value[4] = m.m10;
this.value[5] = m.m11;
this.value[6] = m.m12;
this.value[7] = m.m13;
this.value[8] = m.m20;
this.value[9] = m.m21;
this.value[10] = m.m22;
this.value[11] = m.m23;
this.value[12] = m.m30;
this.value[13] = m.m31;
this.value[14] = m.m32;
this.value[15] = m.m33;
}
Object get() {
return new Matrix4d(value);
}
Object getRef() {
return value;
}
}
*/
}
|