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
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
|
/*
* Copyright 1998-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 java.util.ArrayList;
import javax.vecmath.Color4f;
/**
* The TextureAttributes object defines attributes that apply to
* to texture mapping.
*/
class TextureAttributesRetained extends NodeComponentRetained {
// A list of pre-defined bits to indicate which component
// in this TextureAttributes object changed.
static final int TRANSFORM_CHANGED = 0x0001;
static final int MODE_CHANGED = 0x0002;
static final int COLOR_CHANGED = 0x0004;
static final int CORRECTION_CHANGED = 0x0008;
static final int TEXTURE_COLOR_TABLE_CHANGED = 0x0010;
static final int COMBINE_RGB_MODE_CHANGED = 0x0020;
static final int COMBINE_ALPHA_MODE_CHANGED = 0x0040;
static final int COMBINE_RGB_SRC_CHANGED = 0x0080;
static final int COMBINE_ALPHA_SRC_CHANGED = 0x0100;
static final int COMBINE_RGB_FCN_CHANGED = 0x0200;
static final int COMBINE_ALPHA_FCN_CHANGED = 0x0400;
static final int COMBINE_RGB_SCALE_CHANGED = 0x0800;
static final int COMBINE_ALPHA_SCALE_CHANGED = 0x1000;
// static class variable for enums. Currently only supports 0 - 9.
static final Integer[] enums;
// Texture transform
Transform3D transform = new Transform3D();
// Texture mode
int textureMode = TextureAttributes.REPLACE;
// Texture blend color
Color4f textureBlendColor = new Color4f(0.0f, 0.0f, 0.0f, 0.0f);
// Texture color table
int textureColorTable[] = null;
int numTextureColorTableComponents = 0;
int textureColorTableSize = 0;
// Texture Combine Mode
int combineRgbMode = TextureAttributes.COMBINE_MODULATE;
int combineAlphaMode = TextureAttributes.COMBINE_MODULATE;
// the following fields are only applicable if textureMode specifies
// COMBINE. If COMBINE mode is specified, then each of the following
// fields will be referencing an array of 3 integers, each representing
// an operand in the combine equation.
int [] combineRgbSrc = null;
int [] combineAlphaSrc = null;
int [] combineRgbFcn = null;
int [] combineAlphaFcn = null;
int combineRgbScale = 1;
int combineAlphaScale = 1;
//Perspective correction mode, used for color/texCoord interpolation
int perspCorrectionMode = TextureAttributes.NICEST;
// true when mirror texCoord component set
boolean mirrorCompDirty = false;
static {
// create some of the enums Integer to be used in the messages
// this can be eliminated if the message is modified to take
// integer itself
//
// NOTE: check with the actual enum value before using this
// list. This list only supports 0 - 9
enums = new Integer[10];
for (int i = 0; i < enums.length; i++) {
enums[i] = new Integer(i);
}
}
TextureAttributesRetained() {}
// initCombineMode -- initializes the combine mode related fields
// delay the allocation of memory to minimize
// memory footprint
final void initCombineMode(TextureAttributesRetained tr) {
tr.combineRgbSrc = new int[3];
tr.combineAlphaSrc = new int[3];
tr.combineRgbFcn = new int[3];
tr.combineAlphaFcn = new int[3];
//default values
tr.combineRgbSrc[0] = TextureAttributes.COMBINE_TEXTURE_COLOR;
tr.combineRgbSrc[1] = TextureAttributes.COMBINE_PREVIOUS_TEXTURE_UNIT_STATE;
tr.combineRgbSrc[2] = TextureAttributes.COMBINE_CONSTANT_COLOR;
tr.combineAlphaSrc[0] = TextureAttributes.COMBINE_TEXTURE_COLOR;
tr.combineAlphaSrc[1] = TextureAttributes.COMBINE_PREVIOUS_TEXTURE_UNIT_STATE;
tr.combineAlphaSrc[2] = TextureAttributes.COMBINE_CONSTANT_COLOR;
tr.combineRgbFcn[0] = TextureAttributes.COMBINE_SRC_COLOR;
tr.combineRgbFcn[1] = TextureAttributes.COMBINE_SRC_COLOR;
tr.combineRgbFcn[2] = TextureAttributes.COMBINE_SRC_COLOR;
tr.combineAlphaFcn[0] = TextureAttributes.COMBINE_SRC_ALPHA;
tr.combineAlphaFcn[1] = TextureAttributes.COMBINE_SRC_ALPHA;
tr.combineAlphaFcn[2] = TextureAttributes.COMBINE_SRC_ALPHA;
}
final void initTextureMode(int textureMode) {
this.textureMode = textureMode;
if (textureMode == TextureAttributes.COMBINE) {
if (combineRgbSrc == null) {
initCombineMode(this);
}
}
}
/**
* Sets the texture mode parameter for this
* appearance component object.
* @param textureMode the texture mode, one of: MODULATE,
* DECAL, BLEND, or REPLACE
*/
final void setTextureMode(int textureMode) {
initTextureMode(textureMode);
sendMessage(MODE_CHANGED, enums[textureMode], null);
}
/**
* Gets the texture mode parameter for this
* texture attributes object.
* @return textureMode the texture mode
*/
final int getTextureMode() {
return textureMode;
}
final void initTextureBlendColor(Color4f textureBlendColor) {
this.textureBlendColor.set(textureBlendColor);
}
/**
* Sets the texture blend color for this
* texture attributes object.
* @param textureBlendColor the texture blend color used when
* the mode is BLEND
*/
final void setTextureBlendColor(Color4f textureBlendColor) {
this.textureBlendColor.set(textureBlendColor);
sendMessage(COLOR_CHANGED, new Color4f(textureBlendColor), null);
}
final void initTextureBlendColor(float r, float g, float b, float a) {
this.textureBlendColor.set(r, g, b, a);
}
/**
* Sets the texture blend color for this
* appearance component object. This color is used when
* the mode is BLEND.
* @param r the red component of the color
* @param g the green component of the color
* @param b the blue component of the color
* @param a the alpha component of the color
*/
final void setTextureBlendColor(float r, float g, float b, float a) {
this.textureBlendColor.set(r, g, b, a);
sendMessage(COLOR_CHANGED, new Color4f(r, g, b, a), null);
}
/**
* Gets the texture blend color for this
* appearance component object.
* @param textureBlendColor the vector that will receive the texture
* blend color used when the mode is BLEND
*/
final void getTextureBlendColor(Color4f textureBlendColor) {
textureBlendColor.set(this.textureBlendColor);
}
final void initTextureTransform(Transform3D transform) {
this.transform.set(transform);
}
/**
* Sets the texture transform object used to transform texture
* coordinates. A copy of the specified Transform3D object is
* stored in this TextureAttributes object.
* @param transform the new transform object
*/
final void setTextureTransform(Transform3D transform) {
this.transform.set(transform);
sendMessage(TRANSFORM_CHANGED, new Transform3D(transform), null);
}
/**
* Retrieves a copy of the texture transform object.
* @param transform the transform object that will receive the
* current texture transform.
*/
final void getTextureTransform(Transform3D transform) {
transform.set(this.transform);
}
final void initPerspectiveCorrectionMode(int mode) {
this.perspCorrectionMode = mode;
}
/**
* Sets perspective correction mode to be used for color
* and/or texture coordinate interpolation.
* A value of NICEST indicates that perspective correction should be
* performed and that the highest quality method should be used.
* A value of FASTEST indicates that the most efficient perspective
* correction method should be used.
* @param mode one of NICEST or FASTEST.
* The default value is NICEST.
*/
final void setPerspectiveCorrectionMode(int mode) {
this.perspCorrectionMode = mode;
sendMessage(CORRECTION_CHANGED, enums[mode], null);
}
/**
* Gets perspective correction mode value.
* @return mode the value of perspective correction mode.
*/
final int getPerspectiveCorrectionMode() {
return perspCorrectionMode;
}
final void setTextureColorTable(int[][] table) {
initTextureColorTable(table);
//clone a copy of the texture for the mirror object
if (table == null) {
sendMessage(TEXTURE_COLOR_TABLE_CHANGED, null, null);
} else {
int ctable[] = new int[textureColorTableSize *
numTextureColorTableComponents];
System.arraycopy(textureColorTable, 0, ctable, 0,
textureColorTable.length);
Object args[] = new Object[3];
args[0] = new Integer(numTextureColorTableComponents);
args[1] = new Integer(textureColorTableSize);
args[2] = ctable;
sendMessage(TEXTURE_COLOR_TABLE_CHANGED, args, null);
}
}
final void initTextureColorTable(int[][] table) {
numTextureColorTableComponents = 0;
textureColorTableSize = 0;
if (table == null) {
textureColorTable = null;
return;
}
if (table.length < 3 || table.length > 4) {
throw new IllegalArgumentException(J3dI18N.getString("TextureAttributes13"));
}
if (Texture.getPowerOf2(table[0].length) == -1) {
throw new IllegalArgumentException(J3dI18N.getString("TextureAttributes14"));
}
for (int i = 1; i < table.length; i++) {
if (table[i].length != table[0].length)
throw new IllegalArgumentException(J3dI18N.getString("TextureAttributes15"));
}
numTextureColorTableComponents = table.length;
textureColorTableSize = table[0].length;
if (textureColorTable == null ||
textureColorTable.length != numTextureColorTableComponents *
textureColorTableSize) {
textureColorTable = new int[numTextureColorTableComponents *
textureColorTableSize];
}
int k = 0;
for (int i = 0; i < textureColorTableSize; i++) {
for (int j = 0; j < numTextureColorTableComponents; j++) {
textureColorTable[k++] = table[j][i];
}
}
}
final void getTextureColorTable(int[][] table) {
if (textureColorTable == null)
return;
int k = 0;
for (int i = 0; i < textureColorTableSize; i++) {
for (int j = 0; j < numTextureColorTableComponents; j++) {
table[j][i] = textureColorTable[k++];
}
}
}
final int getNumTextureColorTableComponents() {
return numTextureColorTableComponents;
}
final int getTextureColorTableSize() {
return textureColorTableSize;
}
final void initCombineRgbMode(int mode) {
combineRgbMode = mode;
}
final void setCombineRgbMode(int mode) {
initCombineRgbMode(mode);
sendMessage(COMBINE_RGB_MODE_CHANGED, enums[mode], null);
}
final int getCombineRgbMode() {
return combineRgbMode;
}
final void initCombineAlphaMode(int mode) {
combineAlphaMode = mode;
}
final void setCombineAlphaMode(int mode) {
initCombineAlphaMode(mode);
sendMessage(COMBINE_ALPHA_MODE_CHANGED, enums[mode], null);
}
final int getCombineAlphaMode() {
return combineAlphaMode;
}
final void initCombineRgbSource(int index, int src) {
if (combineRgbSrc == null) {
// it is possible to set the combineRgbSource before
// setting the texture mode to COMBINE, so need to initialize
// the combine mode related fields here
initCombineMode(this);
}
combineRgbSrc[index] = src;
}
final void setCombineRgbSource(int index, int src) {
initCombineRgbSource(index, src);
sendMessage(COMBINE_RGB_SRC_CHANGED, enums[index], enums[src]);
}
final int getCombineRgbSource(int index) {
if (combineRgbSrc == null) {
// it is possible to do a get before
// setting the texture mode to COMBINE, so need to initialize
// the combine mode related fields here
initCombineMode(this);
}
return combineRgbSrc[index];
}
final void initCombineAlphaSource(int index, int src) {
if (combineRgbSrc == null) {
// it is possible to set the combineAlphaSource before
// setting the texture mode to COMBINE, so need to initialize
// the combine mode related fields here
initCombineMode(this);
}
combineAlphaSrc[index] = src;
}
final void setCombineAlphaSource(int index, int src) {
initCombineAlphaSource(index, src);
sendMessage(COMBINE_ALPHA_SRC_CHANGED, enums[index], enums[src]);
}
final int getCombineAlphaSource(int index) {
if (combineRgbSrc == null) {
// it is possible to do a get before
// setting the texture mode to COMBINE, so need to initialize
// the combine mode related fields here
initCombineMode(this);
}
return combineAlphaSrc[index];
}
final void initCombineRgbFunction(int index, int fcn) {
if (combineRgbSrc == null) {
// it is possible to set the combineRgbFcn before
// setting the texture mode to COMBINE, so need to initialize
// the combine mode related fields here
initCombineMode(this);
}
combineRgbFcn[index] = fcn;
}
final void setCombineRgbFunction(int index, int fcn) {
initCombineRgbFunction(index, fcn);
sendMessage(COMBINE_RGB_FCN_CHANGED, enums[index], enums[fcn]);
}
final int getCombineRgbFunction(int index) {
if (combineRgbSrc == null) {
// it is possible to do a get before
// setting the texture mode to COMBINE, so need to initialize
// the combine mode related fields here
initCombineMode(this);
}
return combineRgbFcn[index];
}
final void initCombineAlphaFunction(int index, int fcn) {
if (combineRgbSrc == null) {
// it is possible to set the combineAlphaFcn before
// setting the texture mode to COMBINE, so need to initialize
// the combine mode related fields here
initCombineMode(this);
}
combineAlphaFcn[index] = fcn;
}
final void setCombineAlphaFunction(int index, int fcn) {
initCombineAlphaFunction(index, fcn);
sendMessage(COMBINE_ALPHA_FCN_CHANGED, enums[index], enums[fcn]);
}
final int getCombineAlphaFunction(int index) {
if (combineRgbSrc == null) {
// it is possible to do a get before
// setting the texture mode to COMBINE, so need to initialize
// the combine mode related fields here
initCombineMode(this);
}
return combineAlphaFcn[index];
}
final void initCombineRgbScale(int scale) {
combineRgbScale = scale;
}
final void setCombineRgbScale(int scale) {
initCombineRgbScale(scale);
sendMessage(COMBINE_RGB_SCALE_CHANGED, enums[scale], null);
}
final int getCombineRgbScale() {
return combineRgbScale;
}
final void initCombineAlphaScale(int scale) {
combineAlphaScale = scale;
}
final void setCombineAlphaScale(int scale) {
initCombineAlphaScale(scale);
sendMessage(COMBINE_ALPHA_SCALE_CHANGED, enums[scale], null);
}
final int getCombineAlphaScale() {
return combineAlphaScale;
}
void updateNative(Canvas3D cv, boolean simulate, int textureFormat) {
//System.err.println("TextureAttributes/updateNative: simulate= " + simulate + " " + this);
//if ((cv.textureExtendedFeatures & Canvas3D.TEXTURE_COLOR_TABLE)
// == 0) && textureColorTable != null) {
// System.err.println("TextureColorTable Not supported");
//}
//System.err.println("textureMode= " + textureMode);
boolean isIdentity =
((transform.getType() & Transform3D.IDENTITY) != 0);
if (simulate == false) {
if (VirtualUniverse.mc.useCombiners &&
(cv.textureExtendedFeatures &
Canvas3D.TEXTURE_REGISTER_COMBINERS) != 0) {
Pipeline.getPipeline().updateRegisterCombiners(cv.ctx,
transform.mat, isIdentity, textureMode, perspCorrectionMode,
textureBlendColor.x, textureBlendColor.y,
textureBlendColor.z, textureBlendColor.w,
textureFormat, combineRgbMode, combineAlphaMode,
combineRgbSrc, combineAlphaSrc,
combineRgbFcn, combineAlphaFcn,
combineRgbScale, combineAlphaScale);
} else {
if (textureMode == TextureAttributes.COMBINE) {
if ((cv.textureExtendedFeatures &
Canvas3D.TEXTURE_COMBINE) != 0) {
// Texture COMBINE is supported by the underlying layer
int _combineRgbMode = combineRgbMode;
int _combineAlphaMode = combineAlphaMode;
Pipeline.getPipeline().updateTextureAttributes(cv.ctx,
transform.mat, isIdentity, textureMode,
perspCorrectionMode,
textureBlendColor.x, textureBlendColor.y,
textureBlendColor.z, textureBlendColor.w,
textureFormat);
if (((combineRgbMode == TextureAttributes.COMBINE_DOT3) &&
((cv.textureExtendedFeatures &
Canvas3D.TEXTURE_COMBINE_DOT3) == 0)) ||
((combineRgbMode == TextureAttributes.COMBINE_SUBTRACT) &&
((cv.textureExtendedFeatures &
Canvas3D.TEXTURE_COMBINE_SUBTRACT) == 0))) {
// Combine DOT3/SUBTRACT is not supported by the
// underlying layer, fallback to COMBINE_REPLACE
_combineRgbMode = TextureAttributes.COMBINE_REPLACE;
}
if (((combineAlphaMode == TextureAttributes.COMBINE_DOT3) &&
((cv.textureExtendedFeatures &
Canvas3D.TEXTURE_COMBINE_DOT3) == 0)) ||
((combineAlphaMode == TextureAttributes.COMBINE_SUBTRACT) &&
((cv.textureExtendedFeatures &
Canvas3D.TEXTURE_COMBINE_SUBTRACT) == 0))) {
// Combine DOT3/SUBTRACT is not supported by the
// underlying layer, fallback to COMBINE_REPLACE
_combineAlphaMode = TextureAttributes.COMBINE_REPLACE;
}
Pipeline.getPipeline().updateCombiner(cv.ctx,
_combineRgbMode, _combineAlphaMode,
combineRgbSrc, combineAlphaSrc,
combineRgbFcn, combineAlphaFcn,
combineRgbScale, combineAlphaScale);
} else {
// Texture COMBINE is not supported by the underlying
// layer, fallback to REPLACE
Pipeline.getPipeline().updateTextureAttributes(cv.ctx,
transform.mat, isIdentity,
TextureAttributes.REPLACE,
perspCorrectionMode,
textureBlendColor.x, textureBlendColor.y,
textureBlendColor.z, textureBlendColor.w,
textureFormat);
}
} else {
Pipeline.getPipeline().updateTextureAttributes(cv.ctx,
transform.mat, isIdentity, textureMode,
perspCorrectionMode,
textureBlendColor.x, textureBlendColor.y,
textureBlendColor.z, textureBlendColor.w,
textureFormat);
}
}
if (((cv.textureExtendedFeatures & Canvas3D.TEXTURE_COLOR_TABLE)
!= 0) && textureColorTable != null) {
Pipeline.getPipeline().updateTextureColorTable(cv.ctx,
numTextureColorTableComponents,
textureColorTableSize, textureColorTable);
}
} else {
// we are in the multi-pass mode,
// in this case, set the texture Mode to replace and use
// blending to simulate the original textureMode
Pipeline.getPipeline().updateTextureAttributes(cv.ctx,
transform.mat, isIdentity, TextureAttributes.REPLACE,
perspCorrectionMode,
textureBlendColor.x, textureBlendColor.y,
textureBlendColor.z, textureBlendColor.w, textureFormat);
if (((cv.textureExtendedFeatures & Canvas3D.TEXTURE_COLOR_TABLE)
!= 0) && textureColorTable != null) {
Pipeline.getPipeline().updateTextureColorTable(cv.ctx, numTextureColorTableComponents,
textureColorTableSize, textureColorTable);
}
switch (textureMode) {
case TextureAttributes.COMBINE:
case TextureAttributes.REPLACE:
cv.setBlendFunc(cv.ctx,
TransparencyAttributes.BLEND_ONE,
TransparencyAttributes.BLEND_ZERO);
break;
case TextureAttributes.MODULATE:
cv.setBlendFunc(cv.ctx,
TransparencyAttributes.BLEND_DST_COLOR,
TransparencyAttributes.BLEND_ZERO);
break;
case TextureAttributes.DECAL:
if (textureFormat == Texture.RGBA) {
cv.setBlendFunc(cv.ctx,
TransparencyAttributes.BLEND_SRC_ALPHA,
TransparencyAttributes.BLEND_ONE_MINUS_SRC_ALPHA);
} else {
cv.setBlendFunc(cv.ctx,
TransparencyAttributes.BLEND_ONE,
TransparencyAttributes.BLEND_ZERO);
}
break;
case TextureAttributes.BLEND:
cv.setBlendColor(cv.ctx, textureBlendColor.x, textureBlendColor.y,
textureBlendColor.z, textureBlendColor.w);
cv.setBlendFunc(cv.ctx,
TransparencyAttributes.BLEND_CONSTANT_COLOR,
TransparencyAttributes.BLEND_ONE_MINUS_SRC_COLOR);
break;
}
}
}
/**
* Creates and initializes a mirror object, point the mirror object
* to the retained object if the object is not editable
*/
@Override
synchronized void createMirrorObject() {
if (mirror == null) {
// Check the capability bits and let the mirror object
// point to itself if is not editable
if (isStatic()) {
mirror = this;
} else {
TextureAttributesRetained mirrorTa = new TextureAttributesRetained();
mirrorTa.source = source;
mirrorTa.set(this);
mirror = mirrorTa;
}
} else {
((TextureAttributesRetained)mirror).set(this);
}
}
/**
* Initializes a mirror object
*/
@Override
synchronized void initMirrorObject() {
((TextureAttributesRetained)mirror).set(this);
}
/**
* Update the "component" field of the mirror object with the
* given "value"
*/
synchronized void updateMirrorObject(int component, Object value,
Object value2) {
TextureAttributesRetained mirrorTa = (TextureAttributesRetained)mirror;
mirrorTa.mirrorCompDirty = true;
if ((component & TRANSFORM_CHANGED) != 0) {
mirrorTa.transform.set((Transform3D)value);
}
else if ((component & MODE_CHANGED) != 0) {
mirrorTa.textureMode = ((Integer)value).intValue();
if ((mirrorTa.textureMode == TextureAttributes.COMBINE) &&
(mirrorTa.combineRgbSrc == null)) {
initCombineMode(mirrorTa);
}
}
else if ((component & COLOR_CHANGED) != 0) {
mirrorTa.textureBlendColor.set((Color4f)value);
}
else if ((component & CORRECTION_CHANGED) != 0) {
mirrorTa.perspCorrectionMode = ((Integer)value).intValue();
}
else if ((component & TEXTURE_COLOR_TABLE_CHANGED) != 0) {
if (value == null) {
mirrorTa.textureColorTable = null;
mirrorTa.numTextureColorTableComponents = 0;
mirrorTa.textureColorTableSize = 0;
} else {
Object args[] = (Object[])value;
mirrorTa.textureColorTable = (int[])args[2];
mirrorTa.numTextureColorTableComponents =
((Integer)args[0]).intValue();
mirrorTa.textureColorTableSize =
((Integer)args[1]).intValue();
}
}
else if ((component & COMBINE_RGB_MODE_CHANGED) != 0) {
mirrorTa.combineRgbMode = ((Integer)value).intValue();
}
else if ((component & COMBINE_ALPHA_MODE_CHANGED) != 0) {
mirrorTa.combineAlphaMode = ((Integer)value).intValue();
}
else if ((component & COMBINE_RGB_SRC_CHANGED) != 0) {
if (mirrorTa.combineRgbSrc == null) {
//initialize the memory for combine mode
initCombineMode(mirrorTa);
}
int index = ((Integer)value).intValue();
mirrorTa.combineRgbSrc[index] = ((Integer)value2).intValue();
}
else if ((component & COMBINE_ALPHA_SRC_CHANGED) != 0) {
if (mirrorTa.combineRgbSrc == null) {
//initialize the memory for combine mode
initCombineMode(mirrorTa);
}
int index = ((Integer)value).intValue();
mirrorTa.combineAlphaSrc[index] = ((Integer)value2).intValue();
}
else if ((component & COMBINE_RGB_FCN_CHANGED) != 0) {
if (mirrorTa.combineRgbSrc == null) {
//initialize the memory for combine mode
initCombineMode(mirrorTa);
}
int index = ((Integer)value).intValue();
mirrorTa.combineRgbFcn[index] = ((Integer)value2).intValue();
}
else if ((component & COMBINE_ALPHA_FCN_CHANGED) != 0) {
if (mirrorTa.combineRgbSrc == null) {
//initialize the memory for combine mode
initCombineMode(mirrorTa);
}
int index = ((Integer)value).intValue();
mirrorTa.combineAlphaFcn[index] = ((Integer)value2).intValue();
}
else if ((component & COMBINE_RGB_SCALE_CHANGED) != 0) {
mirrorTa.combineRgbScale = ((Integer)value).intValue();
}
else if ((component & COMBINE_ALPHA_SCALE_CHANGED) != 0) {
mirrorTa.combineAlphaScale = ((Integer)value).intValue();
}
}
boolean equivalent(TextureAttributesRetained tr) {
if (tr == null) {
return (false);
} else if ((this.changedFrequent != 0) || (tr.changedFrequent != 0)) {
return (this == tr);
}
if (!(tr.transform.equals(transform) &&
tr.textureBlendColor.equals(textureBlendColor) &&
(tr.textureMode == textureMode) &&
(tr.perspCorrectionMode == perspCorrectionMode))) {
return false;
}
// now check for combine mode attributes if textureMode specifies
// COMBINE
if (textureMode == TextureAttributes.COMBINE) {
if ((tr.combineRgbMode != combineRgbMode) ||
(tr.combineAlphaMode != combineAlphaMode) ||
(tr.combineRgbScale != combineRgbScale) ||
(tr.combineAlphaScale != combineAlphaScale)) {
return false;
}
// now check if the operands for the combine equations are
// equivalent
int nOpNeeded = 0;
if (combineRgbMode == TextureAttributes.COMBINE_REPLACE) {
nOpNeeded = 1;
} else if (combineRgbMode == TextureAttributes.COMBINE_INTERPOLATE) {
nOpNeeded = 3;
} else {
nOpNeeded = 2;
}
for (int i = 0; i < nOpNeeded; i++) {
if ((tr.combineRgbSrc[i] != combineRgbSrc[i]) ||
(tr.combineAlphaSrc[i] != combineAlphaSrc[i]) ||
(tr.combineRgbFcn[i] != combineRgbFcn[i]) ||
(tr.combineAlphaFcn[i] != combineAlphaFcn[i])) {
return false;
}
}
}
// now check for texture color table
if (tr.textureColorTable == null) {
if (this.textureColorTable == null)
return true;
else
return false;
} else if (this.textureColorTable == null) {
// tr.textureColorTable != null
return false;
} else {
if (tr.textureColorTable.length != this.textureColorTable.length)
return false;
for (int i = 0; i < this.textureColorTable.length; i++) {
if (this.textureColorTable[i] != tr.textureColorTable[i])
return false;
}
return true;
}
}
@Override
protected Object clone() {
TextureAttributesRetained tr = (TextureAttributesRetained)super.clone();
tr.transform = new Transform3D(transform);
tr.textureBlendColor = new Color4f(textureBlendColor);
if (textureColorTable != null) {
tr.textureColorTable = new int[textureColorTable.length];
System.arraycopy(textureColorTable, 0, tr.textureColorTable, 0,
textureColorTable.length);
} else {
tr.textureColorTable = null;
}
// clone the combine mode attributes
if (combineRgbSrc != null) {
tr.combineRgbSrc = new int[3];
tr.combineAlphaSrc = new int[3];
tr.combineRgbFcn = new int[3];
tr.combineAlphaFcn = new int[3];
for (int i = 0; i < 3; i++) {
tr.combineRgbSrc[i] = combineRgbSrc[i];
tr.combineAlphaSrc[i] = combineAlphaSrc[i];
tr.combineRgbFcn[i] = combineRgbFcn[i];
tr.combineAlphaFcn[i] = combineAlphaFcn[i];
}
}
// other attributes are copied in super.clone()
return tr;
}
protected void set(TextureAttributesRetained tr) {
super.set(tr);
transform.set(tr.transform);
textureBlendColor.set(tr.textureBlendColor);
textureMode = tr.textureMode;
perspCorrectionMode = tr.perspCorrectionMode;
// set texture color table
if (tr.textureColorTable != null) {
if (textureColorTable == null ||
textureColorTable.length != tr.textureColorTable.length) {
textureColorTable = new int[tr.textureColorTable.length];
}
System.arraycopy(tr.textureColorTable, 0, textureColorTable, 0,
tr.textureColorTable.length);
} else {
textureColorTable = null;
}
numTextureColorTableComponents = tr.numTextureColorTableComponents;
textureColorTableSize = tr.textureColorTableSize;
// set the combine mode attributes
combineRgbMode = tr.combineRgbMode;
combineAlphaMode = tr.combineAlphaMode;
combineRgbScale = tr.combineRgbScale;
combineAlphaScale = tr.combineAlphaScale;
if (tr.combineRgbSrc != null) {
if (combineRgbSrc == null) {
combineRgbSrc = new int[3];
combineAlphaSrc = new int[3];
combineRgbFcn = new int[3];
combineAlphaFcn = new int[3];
}
for (int i = 0; i < 3; i++) {
combineRgbSrc[i] = tr.combineRgbSrc[i];
combineAlphaSrc[i] = tr.combineAlphaSrc[i];
combineRgbFcn[i] = tr.combineRgbFcn[i];
combineAlphaFcn[i] = tr.combineAlphaFcn[i];
}
}
}
final void sendMessage(int attrMask, Object attr1, Object attr2) {
ArrayList<VirtualUniverse> univList = new ArrayList<VirtualUniverse>();
ArrayList<ArrayList<GeometryAtom>> gaList = Shape3DRetained.getGeomAtomsList(mirror.users, univList);
// Send to rendering attribute structure, regardless of
// whether there are users or not (alternate appearance case ..)
J3dMessage createMessage = new J3dMessage();
createMessage.threads = J3dThread.UPDATE_RENDERING_ATTRIBUTES;
createMessage.type = J3dMessage.TEXTUREATTRIBUTES_CHANGED;
createMessage.universe = null;
createMessage.args[0] = this;
createMessage.args[1] = new Integer(attrMask);
createMessage.args[2] = attr1;
createMessage.args[3] = attr2;
createMessage.args[4] = new Integer(changedFrequent);
VirtualUniverse.mc.processMessage(createMessage);
// System.err.println("univList.size is " + univList.size());
for(int i=0; i<univList.size(); i++) {
createMessage = new J3dMessage();
createMessage.threads = J3dThread.UPDATE_RENDER;
createMessage.type = J3dMessage.TEXTUREATTRIBUTES_CHANGED;
createMessage.universe = univList.get(i);
createMessage.args[0] = this;
createMessage.args[1] = new Integer(attrMask);
createMessage.args[2] = attr1;
ArrayList<GeometryAtom> gL = gaList.get(i);
GeometryAtom[] gaArr = new GeometryAtom[gL.size()];
gL.toArray(gaArr);
createMessage.args[3] = gaArr;
VirtualUniverse.mc.processMessage(createMessage);
}
}
@Override
void handleFrequencyChange(int bit) {
switch (bit) {
case TextureAttributes.ALLOW_MODE_WRITE:
case TextureAttributes.ALLOW_BLEND_COLOR_WRITE:
case TextureAttributes.ALLOW_TRANSFORM_WRITE:
case TextureAttributes.ALLOW_COLOR_TABLE_WRITE:
case TextureAttributes.ALLOW_COMBINE_WRITE: {
setFrequencyChangeMask(bit, bit);
}
default:
break;
}
}
}
|