001: /*
002: * $RCSfile: DisplayListRenderMethod.java,v $
003: *
004: * Copyright 1999-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.8 $
028: * $Date: 2008/02/28 20:17:21 $
029: * $State: Exp $
030: */
031:
032: package javax.media.j3d;
033:
034: /**
035: * The RenderMethod interface is used to create various ways to render
036: * different geometries.
037: */
038:
039: class DisplayListRenderMethod implements RenderMethod {
040:
041: /**
042: * display list buffer size
043: */
044: final int bufferSize = 128;
045:
046: /**
047: * display list buffer
048: */
049: int[] buffer = new int[bufferSize];
050:
051: /**
052: * The actual rendering code for this RenderMethod
053: */
054: public boolean render(RenderMolecule rm, Canvas3D cv,
055: RenderAtomListInfo ra, int dirtyBits) {
056:
057: if (rm.doInfinite || !VirtualUniverse.mc.viewFrustumCulling
058: || rm.vwcBounds.intersect(cv.viewFrustum)) {
059: cv.updateState(dirtyBits);
060: cv.callDisplayList(cv.ctx, rm.displayListId,
061: rm.isNonUniformScale);
062: return true;
063: }
064: return false;
065: }
066:
067: public boolean renderSeparateDlists(RenderMolecule rm, Canvas3D cv,
068: RenderAtomListInfo r, int dirtyBits) {
069:
070: if (rm.doInfinite) {
071: cv.updateState(dirtyBits);
072: while (r != null) {
073: cv.callDisplayList(cv.ctx, ((GeometryArrayRetained) r
074: .geometry()).dlistId, rm.isNonUniformScale);
075: r = r.next;
076: }
077:
078: return true;
079: }
080:
081: boolean isVisible = false; // True if any of the RAs is visible.
082: while (r != null) {
083: if (cv.ra == r.renderAtom) {
084: if (cv.raIsVisible) {
085: cv.updateState(dirtyBits);
086: cv
087: .callDisplayList(cv.ctx,
088: ((GeometryArrayRetained) r
089: .geometry()).dlistId,
090: rm.isNonUniformScale);
091: isVisible = true;
092: }
093: } else {
094: if (r.renderAtom.localeVwcBounds
095: .intersect(cv.viewFrustum)) {
096: cv.updateState(dirtyBits);
097: cv.raIsVisible = true;
098: cv
099: .callDisplayList(cv.ctx,
100: ((GeometryArrayRetained) r
101: .geometry()).dlistId,
102: rm.isNonUniformScale);
103: isVisible = true;
104: } else {
105: cv.raIsVisible = false;
106: }
107: cv.ra = r.renderAtom;
108: }
109: r = r.next;
110: }
111:
112: return isVisible;
113: }
114:
115: public boolean renderSeparateDlistPerRinfo(RenderMolecule rm,
116: Canvas3D cv, RenderAtomListInfo r, int dirtyBits) {
117:
118: if (rm.doInfinite) {
119: cv.updateState(dirtyBits);
120: while (r != null) {
121: cv.callDisplayList(cv.ctx,
122: r.renderAtom.dlistIds[r.index],
123: rm.isNonUniformScale);
124: r = r.next;
125: }
126: return true;
127: }
128: boolean isVisible = false; // True if any of the RAs is visible.
129: while (r != null) {
130: if (cv.ra == r.renderAtom) {
131: if (cv.raIsVisible) {
132: cv.updateState(dirtyBits);
133: cv.callDisplayList(cv.ctx,
134: r.renderAtom.dlistIds[r.index],
135: rm.isNonUniformScale);
136: isVisible = true;
137: }
138: } else {
139: if (r.renderAtom.localeVwcBounds
140: .intersect(cv.viewFrustum)) {
141: cv.updateState(dirtyBits);
142: cv.raIsVisible = true;
143: cv.callDisplayList(cv.ctx,
144: r.renderAtom.dlistIds[r.index],
145: rm.isNonUniformScale);
146: isVisible = true;
147: } else {
148: cv.raIsVisible = false;
149: }
150: cv.ra = r.renderAtom;
151: }
152: r = r.next;
153: }
154: return isVisible;
155:
156: }
157:
158: void buildDisplayList(RenderMolecule rm, Canvas3D cv) {
159: RenderAtomListInfo ra;
160: boolean useAlpha;
161: GeometryArrayRetained geo;
162: useAlpha = rm.useAlpha;
163: Transform3D staticTransform;
164: Transform3D staticNormalTransform;
165:
166: if ((rm.primaryRenderAtomList != null)
167: && (rm.texCoordSetMapLen <= cv.maxTexCoordSets)) {
168:
169: cv.newDisplayList(cv.ctx, rm.displayListId);
170:
171: ra = rm.primaryRenderAtomList;
172:
173: while (ra != null) {
174: geo = (GeometryArrayRetained) ra.geometry();
175: if (ra.renderAtom.geometryAtom.source.staticTransform == null) {
176: staticTransform = null;
177: staticNormalTransform = null;
178: } else {
179: staticTransform = ra.renderAtom.geometryAtom.source.staticTransform.transform;
180: if ((geo.vertexFormat & GeometryArray.NORMALS) != 0) {
181: staticNormalTransform = ra.renderAtom.geometryAtom.source.staticTransform
182: .getNormalTransform();
183: } else {
184: staticNormalTransform = null;
185: }
186: }
187: geo
188: .buildGA(
189: cv,
190: ra.renderAtom,
191: false,
192: (useAlpha && ((geo.vertexFormat & GeometryArray.COLOR) != 0)),
193: rm.alpha,
194: rm.textureBin.attributeBin.ignoreVertexColors,
195: staticTransform, staticNormalTransform);
196: ra = ra.next;
197: }
198: cv.endDisplayList(cv.ctx);
199: }
200: }
201:
202: void buildIndividualDisplayList(RenderAtomListInfo ra, Canvas3D cv,
203: Context ctx) {
204: GeometryArrayRetained geo;
205:
206: geo = (GeometryArrayRetained) ra.geometry();
207: if ((geo.texCoordSetMap != null)
208: && (geo.texCoordSetMap.length > cv.maxTexCoordSets)) {
209: return;
210: }
211:
212: // Note, the dlistId does not change when renderer is building
213: cv.newDisplayList(ctx, geo.dlistId);
214:
215: // No need to lock when it is indexed geometry since we have
216: // our own copy
217: // Note individual dlist is only created if alpha is not modifiable
218: // so, we don't need any renderMolecule specific information
219: geo.buildGA(cv, ra.renderAtom, false, false, 1.0f, false, null,
220: null);
221: cv.endDisplayList(ctx);
222: }
223:
224: void buildDlistPerRinfo(RenderAtomListInfo ra, RenderMolecule rm,
225: Canvas3D cv) {
226: boolean useAlpha;
227: GeometryArrayRetained geo;
228: useAlpha = rm.useAlpha;
229: Transform3D staticTransform;
230: Transform3D staticNormalTransform;
231: int id;
232:
233: geo = (GeometryArrayRetained) ra.geometry();
234: if ((rm.primaryRenderAtomList != null)
235: && (rm.texCoordSetMapLen <= cv.maxTexCoordSets)) {
236:
237: id = ra.renderAtom.dlistIds[ra.index];
238: cv.newDisplayList(cv.ctx, id);
239: geo = (GeometryArrayRetained) ra.geometry();
240: if (ra.renderAtom.geometryAtom.source.staticTransform == null) {
241: staticTransform = null;
242: staticNormalTransform = null;
243: } else {
244: staticTransform = ra.renderAtom.geometryAtom.source.staticTransform.transform;
245: if ((geo.vertexFormat & GeometryArray.NORMALS) != 0) {
246: staticNormalTransform = ra.renderAtom.geometryAtom.source.staticTransform
247: .getNormalTransform();
248: } else {
249: staticNormalTransform = null;
250: }
251: }
252:
253: geo
254: .buildGA(
255: cv,
256: ra.renderAtom,
257: false,
258: (useAlpha && ((geo.vertexFormat & GeometryArray.COLOR) != 0)),
259: rm.alpha,
260: rm.textureBin.attributeBin.ignoreVertexColors,
261: staticTransform, staticNormalTransform);
262: cv.endDisplayList(cv.ctx);
263: }
264:
265: }
266:
267: }
|