001: /*
002: * $RCSfile: CompressedGeometryRenderMethod.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:20 $
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 CompressedGeometryRenderMethod implements RenderMethod {
040:
041: /**
042: * The actual rendering code for this RenderMethod.
043: */
044: public boolean render(RenderMolecule rm, Canvas3D cv,
045: RenderAtomListInfo ra, int dirtyBits) {
046:
047: CompressedGeometryRetained cgr;
048:
049: if (rm.doInfinite) {
050: cv.updateState(dirtyBits);
051: while (ra != null) {
052: renderCompressedGeo(ra, rm, cv);
053: ra = ra.next;
054: }
055: return true;
056: }
057:
058: boolean isVisible = false; // True if any of the RAs is visible.
059:
060: while (ra != null) {
061: if (cv.ra == ra.renderAtom) {
062: if (cv.raIsVisible) {
063: cv.updateState(dirtyBits);
064: renderCompressedGeo(ra, rm, cv);
065: isVisible = true;
066: }
067: } else {
068: if (!VirtualUniverse.mc.viewFrustumCulling
069: || ra.renderAtom.localeVwcBounds
070: .intersect(cv.viewFrustum)) {
071: cv.updateState(dirtyBits);
072: cv.raIsVisible = true;
073: renderCompressedGeo(ra, rm, cv);
074: isVisible = true;
075: } else {
076: cv.raIsVisible = false;
077: }
078: cv.ra = ra.renderAtom;
079: }
080:
081: ra = ra.next;
082: }
083:
084: return isVisible;
085:
086: }
087:
088: void renderCompressedGeo(RenderAtomListInfo ra, RenderMolecule rm,
089: Canvas3D cv) {
090:
091: boolean useAlpha;
092: CompressedGeometryRetained cgr;
093: useAlpha = rm.useAlpha;
094:
095: cgr = (CompressedGeometryRetained) ra.renderAtom.geometryAtom.geometryArray[ra.index];
096:
097: /* force_decompression if lighting is disabled and
098: * ignoreVertexColors is TRUE, since there is no way for openGL
099: * to ignore vertexColors in this case, force decompression
100: */
101: if (rm.textureBin.attributeBin.ignoreVertexColors
102: && rm.enableLighting == false
103: && cgr.mirrorGeometry == null) {
104: cgr.mirrorGeometry = cgr.getGeometry(true, cv);
105: } else if (cgr.mirrorGeometry == null) {
106: // cgr.getGeometry() will decompress in software and return a
107: // GeometryRetained if hardware decompression isn't available,
108: // otherwise it just returns cgr.
109: cgr.mirrorGeometry = cgr.getGeometry(false, cv);
110: if (cgr.mirrorGeometry == null)
111: // decompressor error
112: return;
113: }
114:
115: cgr.mirrorGeometry.execute(cv, ra.renderAtom,
116: rm.isNonUniformScale,
117: (useAlpha && ra.geometry().noAlpha), rm.alpha,
118: cv.screen.screen,
119: rm.textureBin.attributeBin.ignoreVertexColors);
120: }
121: }
|