X-Git-Url: http://www2.svjatoslav.eu/gitweb/?p=sixth-3d.git;a=blobdiff_plain;f=src%2Fmain%2Fjava%2Feu%2Fsvjatoslav%2Fsixth%2Fe3d%2Frenderer%2Fraster%2Fshapes%2Fbasic%2FGlowingPoint.java;h=2727a17a8243c4e24828967ea9f37d2e7af10d33;hp=29cad6358ae79560d3a05a4a44f70ce057ecd232;hb=e56f9b775bd49c31e8efab7204bee699036942b3;hpb=6213716671ccab6b7256de41838e1f5401ce173c diff --git a/src/main/java/eu/svjatoslav/sixth/e3d/renderer/raster/shapes/basic/GlowingPoint.java b/src/main/java/eu/svjatoslav/sixth/e3d/renderer/raster/shapes/basic/GlowingPoint.java index 29cad63..2727a17 100644 --- a/src/main/java/eu/svjatoslav/sixth/e3d/renderer/raster/shapes/basic/GlowingPoint.java +++ b/src/main/java/eu/svjatoslav/sixth/e3d/renderer/raster/shapes/basic/GlowingPoint.java @@ -1,10 +1,10 @@ /* - * Sixth - System for data storage, computation, exploration and interaction. - * Copyright ©2012-2016, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu - * + * Sixth 3D engine. Copyright ©2012-2018, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu + * * This program is free software; you can redistribute it and/or * modify it under the terms of version 3 of the GNU Lesser General Public License * or later as published by the Free Software Foundation. + * */ package eu.svjatoslav.sixth.e3d.renderer.raster.shapes.basic; @@ -13,9 +13,14 @@ import eu.svjatoslav.sixth.e3d.geometry.Point3D; 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 static final Set glowingPoints = Collections.newSetFromMap(new WeakHashMap<>()); private final Color color; public GlowingPoint(final Point3D point, final double pointSize, @@ -23,11 +28,24 @@ public class GlowingPoint extends ForwardOrientedTexture { super(point, pointSize, getTexture(color)); this.color = color; - getTexture(color); + synchronized (glowingPoints) { + glowingPoints.add(this); + } + } + + private static Texture getTexture(final Color color) { + // attempt to reuse texture from existing glowing point of the same color + synchronized (glowingPoints) { + 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++) {