SortVisuals
ceramic.SortVisuals (Class)
High-performance stable merge sort implementation specifically optimized for Visual arrays.
SortVisuals provides a specialized sorting algorithm for rendering order in Ceramic.
It implements a stable merge sort that preserves the relative order of visuals with
equal sorting criteria, which is crucial for consistent rendering behavior across
all platforms.
The sorting criteria hierarchy:
- Invisible/untouchable visuals are sorted first (behind everything)
- Render target priority (higher priority renders on top)
- Depth value (higher depth renders on top)
- For Quads/Meshes with same depth:
- Texture index (lower index renders on top for batching efficiency)
- Blending mode (for draw call batching)
This implementation is heavily optimized:
- All methods are inlined for maximum performance
- Uses unsafe array access to avoid bounds checking
- Switches to insertion sort for small arrays (< 12 elements)
- Custom comparison function optimized for Visual properties
Example usage:
var visuals:Array<Visual> = [...];
SortVisuals.sort(visuals);
Note: This class is used internally by the rendering system and typically
doesn't need to be called directly unless implementing custom rendering logic.
Based on Haxe's stable sort implementation with Visual-specific optimizations.
See: ceramic.Visual For the visual hierarchy, ceramic.SortVisualsByDepth For depth-only sorting
Static Members
Sorts an array of Visual objects in place for optimal rendering order.
This operation modifies the input array directly. The sort is stable,
meaning visuals with equal sorting criteria maintain their relative order.
This is important for predictable rendering when multiple visuals have
the same depth and properties.
The algorithm automatically chooses between merge sort for larger arrays
and insertion sort for small arrays (< 12 elements) for optimal performance.
Name |
Type |
Description |
a |
Array<Visual> |
The array of visuals to sort. Modified in place. If null, behavior is undefined. |
Private Members
Compares two visuals for rendering order.
Name |
Type |
Description |
a |
Visual |
First visual to compare |
b |
Visual |
Second visual to compare |
Returns |
Description |
Int |
-1 if a should render before b, 1 if b should render before a, 0 if equal |