import eu.svjatoslav.sixth.e3d.renderer.raster.Color;
import eu.svjatoslav.sixth.e3d.renderer.raster.texture.Texture;
+import java.util.Collections;
+import java.util.Set;
+import java.util.WeakHashMap;
+
public class GlowingPoint extends ForwardOrientedTexture {
private static final int TEXTURE_SIZE = 50;
private final Color color;
+ private static final Set<GlowingPoint> glowingPoints = Collections.newSetFromMap(new WeakHashMap<GlowingPoint, Boolean>());
+
public GlowingPoint(final Point3D point, final double pointSize,
final Color color) {
super(point, pointSize, getTexture(color));
this.color = color;
+ }
- getTexture(color);
+ private static Texture getTexture(final Color color) {
+ // attempt to reuse texture from existing glowing point of the same color
+ for (GlowingPoint glowingPoint : glowingPoints)
+ if (color.equals(glowingPoint.color)) return glowingPoint.texture;
+ // existing texture not found, creating new one
+ return createTexture(color);
}
- public static Texture getTexture(final Color color) {
+ private static Texture createTexture(final Color color) {
final Texture texture = new Texture(TEXTURE_SIZE, TEXTURE_SIZE, 1);
for (int x = 0; x < TEXTURE_SIZE; x++)
for (int y = 0; y < TEXTURE_SIZE; y++) {