/* * Copyright (c) 2009-2010 jMonkeyEngine * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of 'jMonkeyEngine' nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package com.jme3.renderer.queue; import com.jme3.post.SceneProcessor; import com.jme3.renderer.Camera; import com.jme3.renderer.RenderManager; import com.jme3.scene.Geometry; import com.jme3.scene.Spatial; /** * RenderQueue is used to queue up and sort * {@link Geometry geometries} for rendering. * * @author Kirill Vainer */ public class RenderQueue { private GeometryList opaqueList; private GeometryList guiList; private GeometryList transparentList; private GeometryList translucentList; private GeometryList skyList; private GeometryList shadowRecv; private GeometryList shadowCast; /** * Creates a new RenderQueue, the default {@link GeometryComparator comparators} * are used for all {@link GeometryList geometry lists}. */ public RenderQueue() { this.opaqueList = new GeometryList(new OpaqueComparator()); this.guiList = new GeometryList(new GuiComparator()); this.transparentList = new GeometryList(new TransparentComparator()); this.translucentList = new GeometryList(new TransparentComparator()); this.skyList = new GeometryList(new NullComparator()); this.shadowRecv = new GeometryList(new OpaqueComparator()); this.shadowCast = new GeometryList(new OpaqueComparator()); } /** * The render queue Bucket specifies the bucket * to which the spatial will be placed when rendered. *

* The behavior of the rendering will differ depending on which * bucket the spatial is placed. A spatial's queue bucket can be set * via {@link Spatial#setQueueBucket(com.jme3.renderer.queue.RenderQueue.Bucket) }. */ public enum Bucket { /** * The renderer will try to find the optimal order for rendering all * objects using this mode. * You should use this mode for most normal objects, except transparent * ones, as it could give a nice performance boost to your application. */ Opaque, /** * This is the mode you should use for object with * transparency in them. It will ensure the objects furthest away are * rendered first. That ensures when another transparent object is drawn on * top of previously drawn objects, you can see those (and the object drawn * using Opaque) through the transparent parts of the newly drawn * object. */ Transparent, /** * A special mode used for rendering really far away, flat objects - * e.g. skies. In this mode, the depth is set to infinity so * spatials in this bucket will appear behind everything, the downside * to this bucket is that 3D objects will not be rendered correctly * due to lack of depth testing. */ Sky, /** * A special mode used for rendering transparent objects that * should not be effected by {@link SceneProcessor}. * Generally this would contain translucent objects, and * also objects that do not write to the depth buffer such as * particle emitters. */ Translucent, /** * This is a special mode, for drawing 2D object * without perspective (such as GUI or HUD parts). * The spatial's world coordinate system has the range * of [0, 0, -1] to [Width, Height, 1] where Width/Height is * the resolution of the screen rendered to. Any spatials * outside of that range are culled. */ Gui, /** * A special mode, that will ensure that this spatial uses the same * mode as the parent Node does. */ Inherit, } /** * ShadowMode is a marker used to specify how shadow * effects should treat the spatial. */ public enum ShadowMode { /** * Disable both shadow casting and shadow receiving for this spatial. * Generally used for special effects like particle emitters. */ Off, /** * Enable casting of shadows but not receiving them. */ Cast, /** * Enable receiving of shadows but not casting them. */ Receive, /** * Enable both receiving and casting of shadows. */ CastAndReceive, /** * Inherit the ShadowMode from the parent node. */ Inherit } /** * Sets a different geometry comparator for the specified bucket, one * of Gui, Opaque, Sky, or Transparent. The GeometryComparators are * used to sort the accumulated list of geometries before actual rendering * occurs. * *

The most significant comparator is the one for the transparent * bucket since there is no correct way to sort the transparent bucket * that will handle all geometry all the time. In certain cases, the * application may know the best way to sort and now has the option of * configuring a specific implementation.

* *

The default comparators are:

*