2 * Sixth 3D engine. Copyright ©2012-2016, 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.Collections;
18 import java.util.Comparator;
20 public class RenderAggregator {
22 ArrayList<AbstractCoordinateShape> shapes = new ArrayList<>();
23 ShapesComparator comparator = new ShapesComparator();
25 public void paint(final RenderingContext renderBuffer) {
27 Collections.sort(shapes, comparator);
29 for (final AbstractCoordinateShape shape : shapes)
30 shape.paint(renderBuffer);
34 public void queueShapeForRendering(final AbstractCoordinateShape shape) {
42 static class ShapesComparator implements Comparator<AbstractCoordinateShape>, Serializable {
45 public int compare(final AbstractCoordinateShape o1, final AbstractCoordinateShape o2) {
46 if (o1.getZ() < o2.getZ())
48 else if (o1.getZ() > o2.getZ())
51 return Integer.compare(o1.shapeId, o2.shapeId);