001: /*
002: * $RCSfile: PointAttributesRetained.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.7 $
028: * $Date: 2008/02/28 20:17:28 $
029: * $State: Exp $
030: */
031:
032: package javax.media.j3d;
033:
034: import java.util.ArrayList;
035:
036: /**
037: * The PointAttributesRetained object defines all rendering state that can be set
038: * as a component object of a Shape3D node.
039: */
040: class PointAttributesRetained extends NodeComponentRetained {
041: // A list of pre-defined bits to indicate which component
042: // in this LineAttributesRetained object changed.
043: static final int POINT_SIZE_CHANGED = 0x01;
044: static final int POINT_AA_CHANGED = 0x02;
045:
046: // Size, in pixels, of point primitives
047: float pointSize = 1.0f;
048:
049: // Point antialiasing switch
050: boolean pointAntialiasing = false;
051:
052: /**
053: * Sets the point size for this appearance component object.
054: * @param pointSize the size, in pixels, of point primitives
055: */
056: final void initPointSize(float pointSize) {
057: this .pointSize = pointSize;
058: }
059:
060: /**
061: * Sets the point size for this appearance component object and sends a
062: * message notifying the interested structures of the change.
063: * @param pointSize the size, in pixels, of point primitives
064: */
065: final void setPointSize(float pointSize) {
066: initPointSize(pointSize);
067: sendMessage(POINT_SIZE_CHANGED, new Float(pointSize));
068: }
069:
070: /**
071: * Gets the point size for this appearance component object.
072: * @return the size, in pixels, of point primitives
073: */
074: final float getPointSize() {
075: return pointSize;
076: }
077:
078: /**
079: * Enables or disables point antialiasing
080: * for this appearance component object.
081: * @param state true or false to enable or disable point antialiasing
082: */
083: final void initPointAntialiasingEnable(boolean state) {
084: pointAntialiasing = state;
085: }
086:
087: /**
088: * Enables or disables point antialiasing
089: * for this appearance component object and sends a
090: * message notifying the interested structures of the change.
091: * @param state true or false to enable or disable point antialiasing
092: */
093: final void setPointAntialiasingEnable(boolean state) {
094: initPointAntialiasingEnable(pointAntialiasing);
095: sendMessage(POINT_AA_CHANGED, (state ? Boolean.TRUE
096: : Boolean.FALSE));
097: }
098:
099: /**
100: * Retrieves the state of the point antialiasing flag.
101: * @return true if point antialiasing is enabled,
102: * false if point antialiasing is disabled
103: */
104: final boolean getPointAntialiasingEnable() {
105: return pointAntialiasing;
106: }
107:
108: /**
109: * Creates and initializes a mirror object, point the mirror object
110: * to the retained object if the object is not editable
111: */
112: synchronized void createMirrorObject() {
113: if (mirror == null) {
114: // Check the capability bits and let the mirror object
115: // point to itself if is not editable
116: if (isStatic()) {
117: mirror = this ;
118: } else {
119: PointAttributesRetained mirrorPa = new PointAttributesRetained();
120: mirrorPa.set(this );
121: mirrorPa.source = source;
122: mirror = mirrorPa;
123: }
124: } else {
125: ((PointAttributesRetained) mirror).set(this );
126: }
127: }
128:
129: /**
130: * Update the native context
131: */
132: void updateNative(Context ctx) {
133: Pipeline.getPipeline().updatePointAttributes(ctx, pointSize,
134: pointAntialiasing);
135: }
136:
137: /**
138: * Initializes a mirror object, point the mirror object to the retained
139: * object if the object is not editable
140: */
141: synchronized void initMirrorObject() {
142: ((PointAttributesRetained) mirror).set(this );
143: }
144:
145: /**
146: * Update the "component" field of the mirror object with the
147: * given "value"
148: */
149: synchronized void updateMirrorObject(int component, Object value) {
150:
151: PointAttributesRetained mirrorPa = (PointAttributesRetained) mirror;
152:
153: if ((component & POINT_SIZE_CHANGED) != 0) {
154: mirrorPa.pointSize = ((Float) value).floatValue();
155: } else if ((component & POINT_AA_CHANGED) != 0) {
156: mirrorPa.pointAntialiasing = ((Boolean) value)
157: .booleanValue();
158: }
159: }
160:
161: boolean equivalent(PointAttributesRetained pr) {
162: return ((pr != null) && (pr.pointSize == pointSize) && (pr.pointAntialiasing == pointAntialiasing));
163: }
164:
165: protected void set(PointAttributesRetained pr) {
166: super .set(pr);
167: pointSize = pr.pointSize;
168: pointAntialiasing = pr.pointAntialiasing;
169: }
170:
171: final void sendMessage(int attrMask, Object attr) {
172: ArrayList univList = new ArrayList();
173: ArrayList gaList = Shape3DRetained.getGeomAtomsList(
174: mirror.users, univList);
175:
176: // Send to rendering attribute structure, regardless of
177: // whether there are users or not (alternate appearance case ..)
178: J3dMessage createMessage = new J3dMessage();
179: createMessage.threads = J3dThread.UPDATE_RENDERING_ATTRIBUTES;
180: createMessage.type = J3dMessage.POINTATTRIBUTES_CHANGED;
181: createMessage.universe = null;
182: createMessage.args[0] = this ;
183: createMessage.args[1] = new Integer(attrMask);
184: createMessage.args[2] = attr;
185: createMessage.args[3] = new Integer(changedFrequent);
186: VirtualUniverse.mc.processMessage(createMessage);
187:
188: // System.err.println("univList.size is " + univList.size());
189: for (int i = 0; i < univList.size(); i++) {
190: createMessage = new J3dMessage();
191: createMessage.threads = J3dThread.UPDATE_RENDER;
192: createMessage.type = J3dMessage.POINTATTRIBUTES_CHANGED;
193:
194: createMessage.universe = (VirtualUniverse) univList.get(i);
195: createMessage.args[0] = this ;
196: createMessage.args[1] = new Integer(attrMask);
197: createMessage.args[2] = attr;
198:
199: ArrayList gL = (ArrayList) gaList.get(i);
200: GeometryAtom[] gaArr = new GeometryAtom[gL.size()];
201: gL.toArray(gaArr);
202: createMessage.args[3] = gaArr;
203:
204: VirtualUniverse.mc.processMessage(createMessage);
205: }
206:
207: }
208:
209: void handleFrequencyChange(int bit) {
210: if (bit == PointAttributes.ALLOW_SIZE_WRITE
211: || bit == PointAttributes.ALLOW_ANTIALIASING_WRITE) {
212: setFrequencyChangeMask(bit, 0x1);
213: }
214: }
215:
216: }
|