In this example, we explore an efficient and surprisingly powerful method for Z-sorting objects in software—without relying on traditional sorting algorithms like quicksort or merge sort.

Instead of comparing and rearranging objects, we use a Z-depth indexed array to organize our scene. Each unique Z-depth becomes a key that points to the first object at that depth, with each object linking to the next—effectively creating linked lists per depth level. At render time, we walk this structure from the farthest (highest Z) to the closest (lowest Z), drawing each object in order.




Key Highlights:

-- Demonstrates a scene with up to 1,000,000 objects rendered in software.
-- Implements a Z-buffer using a heap + depth map array.
-- Shows the benefits of a non-comparative sorting approach (similar in spirit to radix sort).
-- Discusses practical object culling, memory usage, and overdraw.
-- Demonstrates real-time rendering performance scaling with 10K, 25K, 100K, and even 1M objects.

This method is ideal for software renderers and game devs who want fast Z-sorting without complex algorithms. Whether you're coding games in PlayBASIC or just interested in alternative sorting strategies, this video offers a great breakdown of a simple but effective approach.