All Downloads are FREE. Search and download functionalities are using the official Maven repository.

javax.media.j3d.LightBin Maven / Gradle / Ivy

/*
 * Copyright 1999-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;

/**
 * The LightBin manages a collection of EnvironmentSet objects.
 * The number of objects managed depends upon the number of Lights
 * in each EnvironmentSet and the number of lights supported by
 * the underlying rendering layer.
 */

class LightBin extends Object implements ObjectUpdate {

    /**
     * The maximum number of lights in a LightBin
     */
    int maxLights = -1;

    /**
     * The Array of Light references in this LightBin.
     * This array is always maxLights in length.
     */
    LightRetained[] lights = null;

    /**
     * An Array of reference counts for shared lights in
     * among EnvirionmentSets
     */
    int[] lightsRef = null;

    /**
     * The number of empty light slots in this LightBin
     */
    int numEmptySlots = -1;

    /**
     * The RenderBin for this object
     */
    RenderBin renderBin = null;

    /**
     * The references to the next and previous LightBins in the
     * list.
     */
    LightBin next = null;
    LightBin prev = null;

    /**
     * The list of EnvironmentSets in this LightBin.
     */
    EnvironmentSet environmentSetList = null;

/**
 * List of envSet to be added for the next iteration
 */
ArrayList insertEnvSet = new ArrayList();


    /**
     * cache of the canvasDirty
     */
    int canvasDirty = 0;

    /**
     * lightDirty Mask  cache , used to
     * mark the lightdirty bits for next frame
     */
    int lightDirtyMaskCache = 0;


    /**
     * lightDirty Mask used during rendering
     */
    int lightDirtyMask = 0;

/**
 * List of pointLts in this lightbin Need to reload these lights when vworld
 * scale changes
 */
ArrayList pointLts = new ArrayList();
    int[] pointLtsSlotIndex;

    // OrderedGroup info
    OrderedCollection orderedCollection = null;

    boolean onUpdateList = false;

    // background node that contains geometry
    BackgroundRetained geometryBackground = null;



    LightBin(int maxLights, RenderBin rb, boolean isOpaque) {
        this.maxLights = maxLights;
        this.numEmptySlots = maxLights;
	lights = new LightRetained[maxLights];
	lightsRef = new int[maxLights];
	renderBin = rb;
    }

    void reset(boolean inOpaque) {
	prev = null;
	next = null;
        orderedCollection = null;
	environmentSetList = null;
	onUpdateList = false;
        geometryBackground = null;
	// No need to reset the lights and lightRef
        if (J3dDebug.devPhase && J3dDebug.debug) {
	    for (int i=0; i numEmptySlots) {
	    return (false);
	} else {
	    return (true);
	}
    }

    /**
     * Adds the new EnvironmentSet to this LightBin.
     */
    void addEnvironmentSet(EnvironmentSet e, RenderBin rb) {
	int i, j, numEsLights;
	LightRetained light;

	numEsLights = e.lights.size();
	for (i=0; i 0) {
		e = insertEnvSet.get(0);
	    if (environmentSetList == null) {
		environmentSetList = e;
	    }
	    else {
		e.next = environmentSetList;
		environmentSetList.prev = e;
		environmentSetList = e;
	    }
	    for (i = 1; i < insertEnvSet.size(); i++) {
			e = insertEnvSet.get(i);
		e.next = environmentSetList;
		environmentSetList.prev = e;
		environmentSetList = e;
	    }
	}


	insertEnvSet.clear();
	if (canvasDirty != 0) {

	    Canvas3D canvases[] = renderBin.view.getCanvases();
	    for (i = 0; i < canvases.length; i++) {
		canvases[i].canvasDirty |= canvasDirty;
	    }
	    lightDirtyMask = lightDirtyMaskCache;
	    canvasDirty = 0;
	    lightDirtyMaskCache = 0;
	}
	onUpdateList = false;
    }



    /**
     * Removes the given EnvironmentSet from this LightBin.
     */
    void removeEnvironmentSet(EnvironmentSet e) {
	int i, j, numEsLights;
	LightRetained light;

	e.lightBin = null;
	// If envSet being remove is contained in envSet, then
	// remove the envSet from the addList
	if (insertEnvSet.contains(e)) {
	    insertEnvSet.remove(insertEnvSet.indexOf(e));
	}
	else {
	    numEsLights = e.lights.size();
	    for (i=0; i>= 1;
		i++;
	    }

	    cv.canvasDirty &= ~Canvas3D.LIGHTBIN_DIRTY;
	}
	else if ((pointLts.size() > 0) && ((cv.canvasDirty & Canvas3D.VIEW_MATRIX_DIRTY) != 0 )) {
            if (geometryBackground == null) {
		scale = cv.canvasViewCache.getVworldToCoexistenceScale();
                cv.setModelViewMatrix(cv.ctx, cv.vpcToEc.mat,
				      renderBin.vworldToVpc);
	    } else {
		scale = cv.canvasViewCache.getInfVworldToCoexistenceScale();
                cv.setModelViewMatrix(cv.ctx, cv.vpcToEc.mat,
				      renderBin.infVworldToVpc);
	    }
	    for (i = 0; i < pointLts.size(); i++) {
			PointLightRetained lt = pointLts.get(i);
		lt.update(cv.ctx, pointLtsSlotIndex[i], scale);
                cv.lights[pointLtsSlotIndex[i]] = lt;
                cv.frameCount[pointLtsSlotIndex[i]] = frameCount;
	    }
	}
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy