2 * Sixth 3D engine. Copyright ©2012-2018, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of version 3 of the GNU Lesser General Public License
6 * or later as published by the Free Software Foundation.
10 package eu.svjatoslav.sixth.e3d.renderer.raster;
12 import eu.svjatoslav.sixth.e3d.gui.RenderingContext;
13 import eu.svjatoslav.sixth.e3d.renderer.raster.shapes.AbstractCoordinateShape;
15 import java.io.Serializable;
16 import java.util.ArrayList;
17 import java.util.Comparator;
19 public class RenderAggregator {
21 private ArrayList<AbstractCoordinateShape> shapes = new ArrayList<>();
22 private ShapesZIndexComparator comparator = new ShapesZIndexComparator();
24 public void paint(final RenderingContext renderBuffer) {
25 shapes.sort(comparator);
26 shapes.forEach(shape -> shape.paint(renderBuffer));
29 public void queueShapeForRendering(final AbstractCoordinateShape shape) {
37 static class ShapesZIndexComparator implements Comparator<AbstractCoordinateShape>, Serializable {
40 public int compare(final AbstractCoordinateShape o1, final AbstractCoordinateShape o2) {
41 if (o1.getZ() < o2.getZ())
43 else if (o1.getZ() > o2.getZ())
46 return Integer.compare(o1.shapeId, o2.shapeId);