Better text resolution on texture
[sixth-3d.git] / src / main / java / eu / svjatoslav / sixth / e3d / renderer / raster / RenderAggregator.java
1 /*
2  * Sixth 3D engine. Author: Svjatoslav Agejenko. 
3  * This project is released under Creative Commons Zero (CC0) license.
4  */
5 package eu.svjatoslav.sixth.e3d.renderer.raster;
6
7 import eu.svjatoslav.sixth.e3d.gui.RenderingContext;
8 import eu.svjatoslav.sixth.e3d.renderer.raster.shapes.AbstractCoordinateShape;
9
10 import java.io.Serializable;
11 import java.util.ArrayList;
12 import java.util.Comparator;
13
14 public class RenderAggregator {
15
16     private ArrayList<AbstractCoordinateShape> shapes = new ArrayList<>();
17     private ShapesZIndexComparator comparator = new ShapesZIndexComparator();
18
19     public void paint(final RenderingContext renderBuffer) {
20         shapes.sort(comparator);
21         shapes.forEach(shape -> shape.paint(renderBuffer));
22     }
23
24     public void queueShapeForRendering(final AbstractCoordinateShape shape) {
25         shapes.add(shape);
26     }
27
28     public void reset() {
29         shapes.clear();
30     }
31
32     static class ShapesZIndexComparator implements Comparator<AbstractCoordinateShape>, Serializable {
33
34         @Override
35         public int compare(final AbstractCoordinateShape o1, final AbstractCoordinateShape o2) {
36             if (o1.getZ() < o2.getZ())
37                 return 1;
38             else if (o1.getZ() > o2.getZ())
39                 return -1;
40
41             return Integer.compare(o1.shapeId, o2.shapeId);
42         }
43     }
44 }