2 * Sixth 3D engine. Author: Svjatoslav Agejenko.
3 * This project is released under Creative Commons Zero (CC0) license.
5 package eu.svjatoslav.sixth.e3d.renderer.raster;
7 import eu.svjatoslav.sixth.e3d.gui.RenderingContext;
8 import eu.svjatoslav.sixth.e3d.renderer.raster.shapes.AbstractCoordinateShape;
10 import java.io.Serializable;
11 import java.util.ArrayList;
12 import java.util.Comparator;
14 public class RenderAggregator {
16 private ArrayList<AbstractCoordinateShape> shapes = new ArrayList<>();
17 private ShapesZIndexComparator comparator = new ShapesZIndexComparator();
19 public void paint(final RenderingContext renderBuffer) {
20 shapes.sort(comparator);
21 shapes.forEach(shape -> shape.paint(renderBuffer));
24 public void queueShapeForRendering(final AbstractCoordinateShape shape) {
32 static class ShapesZIndexComparator implements Comparator<AbstractCoordinateShape>, Serializable {
35 public int compare(final AbstractCoordinateShape o1, final AbstractCoordinateShape o2) {
36 if (o1.getZ() < o2.getZ())
38 else if (o1.getZ() > o2.getZ())
41 return Integer.compare(o1.shapeId, o2.shapeId);