Browse Source

Had this one hanging around from like a month ago...
Added the ability to set the geometry comparators
for the buckets for those cases where the app may
know better.


git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@7137 75d07b2b-3a1a-0410-a2c5-0572b91ccdca

PSp..om 14 years ago
parent
commit
228a207aaf
1 changed files with 43 additions and 1 deletions
  1. 43 1
      engine/src/core/com/jme3/renderer/queue/RenderQueue.java

+ 43 - 1
engine/src/core/com/jme3/renderer/queue/RenderQueue.java

@@ -71,6 +71,48 @@ public class RenderQueue {
         Inherit
         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.
+     *
+     *  <p>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.</p>
+     *
+     *  <p>The default comparators are:</p>
+     *  <ul>
+     *  <li>Bucket.Opaque: {@link com.jme3.renderer.queue.OpaqueComparator} which sorts
+     *                     by material first and front to back within the same material.
+     *  <li>Bucket.Transparent: {@link com.jme3.renderer.queue.TransparentComparator} which
+     *                     sorts purely back to front by leading bounding edge with no material sort.
+     *  <li>Bucket.Sky: {@link com.jme3.renderer.queue.NullComparator} which does no sorting
+     *                     at all.
+     *  <li>Bucket.Gui: {@link com.jme3.renderer.queue.GuiComparator} sorts geometries back to
+     *                     front based on their Z values.
+     */
+    public void setGeometryComparator(Bucket bucket, GeometryComparator c) {
+        switch (bucket) {
+            case Gui:
+                guiList = new GeometryList(c);
+                break;
+            case Opaque:
+                opaqueList = new GeometryList(c);
+                break;
+            case Sky:
+                skyList = new GeometryList(c);
+                break;
+            case Transparent:
+                transparentList = new GeometryList(c);
+                break;
+            default:
+                throw new UnsupportedOperationException("Unknown bucket type: "+bucket);
+        }
+    }
+
     public void addToShadowQueue(Geometry g, ShadowMode shadBucket){
     public void addToShadowQueue(Geometry g, ShadowMode shadBucket){
         switch (shadBucket){
         switch (shadBucket){
             case Inherit: break;
             case Inherit: break;
@@ -125,7 +167,7 @@ public class RenderQueue {
         list.sort();
         list.sort();
         for (int i = 0; i < list.size(); i++){
         for (int i = 0; i < list.size(); i++){
             Spatial obj = list.get(i);
             Spatial obj = list.get(i);
-            assert obj != null;           
+            assert obj != null;
             //if(obj.checkCulling(cam)){
             //if(obj.checkCulling(cam)){
                 if (obj instanceof Geometry){
                 if (obj instanceof Geometry){
                     Geometry g = (Geometry) obj;
                     Geometry g = (Geometry) obj;