Aviatrix3D
2.1.0

org.j3d.aviatrix3d.pipeline.graphics
Class StateSortComparator

java.lang.Object
  extended by org.j3d.aviatrix3d.pipeline.graphics.StateSortComparator
All Implemented Interfaces:
java.util.Comparator<GraphicsCullOutputDetails>

public class StateSortComparator
extends java.lang.Object
implements java.util.Comparator<GraphicsCullOutputDetails>

A comparator that provides the mechanics for state sorting, given configurable priority listing.

Since this is a comparator, the basic sorting algorithm will be capped at O(n log n) as given by the lower bounds for any comparison-based sort.

Comparison Rules

The following rules are used for comparing objects of the same type:

Bias towards objects with state first over objects with no state. Thus given two objects a and b. If b is null, a is greater than b and return +1. If a is null and b is non null, return -1.

Where no explicit test is defined, use a per-object test with it's appropriate compareTo() method. If the method returns 0 then continue on with the next in the priority order, otherwise exit with the appropriate state set.

Lights

  1. Number of lights are zero, ignore the test
  2. Number of lights is not equal, -1 to the lower number
  3. Use per-light comparison

Textures

  1. Number of texture units are zero, ignore the test
  2. Number of texture units is not equal, -1 to the lower number
  3. Use per-texture unit comparison

Version:
$Revision: 3.5 $
Author:
Justin Couch

Field Summary
static int BLEND_ATTRIBS
          Priority state is checking blend attributes.
static int CLIP_PLANES
          Priority state is checking clip planes
static int DEPTH_ATTRIBS
          Priority state is checking depth buffer attributes
static int FRAGMENT_SHADERS
          Priority state is fragment shaders
static int LIGHTS
          Priority state is lights
static int LINE_ATTRIBS
          Priority state is checking line attributes
static int LOCAL_FOG
          Priority state is checking local fog
static int MATERIALS
          Priority state is material values
static int POINT_ATTRIBS
          Priority state is checking point attributes
static int POLYGON_ATTRIBS
          Priority state is checking polygon attributes
static int SHADER_OBJECTS
          Priority state is shader objects (ie GL 1.5/2.0)
static int STENCIL_ATTRIBS
          Priority state is checking stencil buffer attributes
static int TEXTURE_UNIT_0
          Priority state is texture unit 0
static int TEXTURE_UNIT_1
          Priority state is texture unit 1
static int TEXTURE_UNIT_2
          Priority state is texture unit 2
static int TEXTURE_UNIT_3
          Priority state is texture unit 3
static int VERTEX_SHADERS
          Priority state is vertex shaders
 
Constructor Summary
StateSortComparator()
          Construct an instance of this comparator using the default priority settings.
StateSortComparator(int[] priList)
          Construct an instance of this comparator given the listed set of priorities.
 
Method Summary
 int compare(GraphicsCullOutputDetails cd1, GraphicsCullOutputDetails cd2)
          Compares its two arguments for order.
 boolean equals(java.lang.Object obj)
          Indicates whether some other object is "equal to" this Comparator by checking to see if it is the same class instance, and then if the priority listing between the two is the same.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LIGHTS

public static final int LIGHTS
Priority state is lights

See Also:
Constant Field Values

MATERIALS

public static final int MATERIALS
Priority state is material values

See Also:
Constant Field Values

FRAGMENT_SHADERS

public static final int FRAGMENT_SHADERS
Priority state is fragment shaders

See Also:
Constant Field Values

VERTEX_SHADERS

public static final int VERTEX_SHADERS
Priority state is vertex shaders

See Also:
Constant Field Values

SHADER_OBJECTS

public static final int SHADER_OBJECTS
Priority state is shader objects (ie GL 1.5/2.0)

See Also:
Constant Field Values

POLYGON_ATTRIBS

public static final int POLYGON_ATTRIBS
Priority state is checking polygon attributes

See Also:
Constant Field Values

LINE_ATTRIBS

public static final int LINE_ATTRIBS
Priority state is checking line attributes

See Also:
Constant Field Values

POINT_ATTRIBS

public static final int POINT_ATTRIBS
Priority state is checking point attributes

See Also:
Constant Field Values

BLEND_ATTRIBS

public static final int BLEND_ATTRIBS
Priority state is checking blend attributes. Theoretically we should Never see this here as the blending attributes should be pre-sorted out of the listing first. But, if we're going to do that, we may have to deal with a separate set of state sorting for the blended geometry from the main geometry.

See Also:
Constant Field Values

CLIP_PLANES

public static final int CLIP_PLANES
Priority state is checking clip planes

See Also:
Constant Field Values

LOCAL_FOG

public static final int LOCAL_FOG
Priority state is checking local fog

See Also:
Constant Field Values

DEPTH_ATTRIBS

public static final int DEPTH_ATTRIBS
Priority state is checking depth buffer attributes

See Also:
Constant Field Values

STENCIL_ATTRIBS

public static final int STENCIL_ATTRIBS
Priority state is checking stencil buffer attributes

See Also:
Constant Field Values

TEXTURE_UNIT_0

public static final int TEXTURE_UNIT_0
Priority state is texture unit 0

See Also:
Constant Field Values

TEXTURE_UNIT_1

public static final int TEXTURE_UNIT_1
Priority state is texture unit 1

See Also:
Constant Field Values

TEXTURE_UNIT_2

public static final int TEXTURE_UNIT_2
Priority state is texture unit 2

See Also:
Constant Field Values

TEXTURE_UNIT_3

public static final int TEXTURE_UNIT_3
Priority state is texture unit 3

See Also:
Constant Field Values
Constructor Detail

StateSortComparator

public StateSortComparator()
Construct an instance of this comparator using the default priority settings.


StateSortComparator

public StateSortComparator(int[] priList)
Construct an instance of this comparator given the listed set of priorities. If any priority is repeated, the second (or more) instance is ignored. If the list instance is null or zero length, the default order is assumed.

Parameters:
priList - The listing of priorities to use
Method Detail

compare

public int compare(GraphicsCullOutputDetails cd1,
                   GraphicsCullOutputDetails cd2)
Compares its two arguments for order. Returns a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second.

Specified by:
compare in interface java.util.Comparator<GraphicsCullOutputDetails>
Parameters:
cd1 - The first object to be compared
cd2 - The second object to be compared
Returns:
-1, 0, or 1 depending on equality
Throws:
java.lang.ClassCastException - Can't be compared as the types are wrong

equals

public boolean equals(java.lang.Object obj)
Indicates whether some other object is "equal to" this Comparator by checking to see if it is the same class instance, and then if the priority listing between the two is the same.

Specified by:
equals in interface java.util.Comparator<GraphicsCullOutputDetails>
Overrides:
equals in class java.lang.Object

Aviatrix3D
2.1.0

Latest Info from http://aviatrix3d.j3d.org/
Copyright © 2003 - 2009 j3d.org