001: /*
002: * $RCSfile: VertexArrayRenderMethod.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.7 $
028: * $Date: 2008/02/28 20:17:32 $
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 VertexArrayRenderMethod implements RenderMethod {
040:
041: public boolean render(RenderMolecule rm, Canvas3D cv,
042: RenderAtomListInfo ra, int dirtyBits) {
043:
044: GeometryArrayRetained geo = (GeometryArrayRetained) ra
045: .geometry();
046: geo
047: .setVertexFormat(
048: (rm.useAlpha && ((geo.vertexFormat & GeometryArray.COLOR) != 0)),
049: rm.textureBin.attributeBin.ignoreVertexColors,
050: cv.ctx);
051:
052: if (rm.doInfinite) {
053: cv.updateState(dirtyBits);
054: while (ra != null) {
055: renderGeo(ra, rm, cv);
056: ra = ra.next;
057: }
058: return true;
059: }
060:
061: boolean isVisible = false; // True if any of the RAs is visible.
062: while (ra != null) {
063: if (cv.ra == ra.renderAtom) {
064: if (cv.raIsVisible) {
065: cv.updateState(dirtyBits);
066: renderGeo(ra, rm, cv);
067: isVisible = true;
068: }
069: } else {
070: if (!VirtualUniverse.mc.viewFrustumCulling
071: || ra.renderAtom.localeVwcBounds
072: .intersect(cv.viewFrustum)) {
073: cv.updateState(dirtyBits);
074: cv.raIsVisible = true;
075: renderGeo(ra, rm, cv);
076: isVisible = true;
077: } else {
078: cv.raIsVisible = false;
079: }
080: cv.ra = ra.renderAtom;
081: }
082:
083: ra = ra.next;
084: }
085: geo
086: .disableGlobalAlpha(
087: cv.ctx,
088: (rm.useAlpha && ((geo.vertexFormat & GeometryArray.COLOR) != 0)),
089: rm.textureBin.attributeBin.ignoreVertexColors);
090: return isVisible;
091: }
092:
093: void renderGeo(RenderAtomListInfo ra, RenderMolecule rm, Canvas3D cv) {
094: GeometryArrayRetained geo;
095: boolean useAlpha;
096:
097: useAlpha = rm.useAlpha;
098:
099: geo = (GeometryArrayRetained) ra.geometry();
100:
101: geo
102: .execute(
103: cv,
104: ra.renderAtom,
105: rm.isNonUniformScale,
106: (useAlpha && ((geo.vertexFormat & GeometryArray.COLOR) != 0)),
107: rm.alpha, cv.screen.screen,
108: rm.textureBin.attributeBin.ignoreVertexColors);
109: }
110: }
|