Skip to content

Commit

Permalink
naming conventions
Browse files Browse the repository at this point in the history
  • Loading branch information
i-make-robots committed Nov 30, 2023
1 parent 4432191 commit 68c96dc
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@
/**
* Creates and manages an OpenGL {@link Texture} from an {@link ImageWithEvents}.
*/
public class GLTextureFromImage implements ImageEventListener {
public class GLTextureFromImageWithEvents implements ImageEventListener {
private Texture texture;
private final ImageWithEvents imageWithEvents;

public GLTextureFromImage(ImageWithEvents imageWithEvents) {
public GLTextureFromImageWithEvents(ImageWithEvents imageWithEvents) {
if(imageWithEvents==null) {
throw new NullPointerException("imageWithEvents cannot be null.");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public ImageWithEvents(BufferedImage image) {
}

public ImageWithEvents() {
this.image = null;
this(null);
}

public void addListener(ImageEventListener listener) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,31 @@
* @since 2.11.0
*/
public class TextureManager {
private static final HashMap<String, GLTextureFromImage> texturePool = new HashMap<>();
private static final HashMap<String, GLTextureFromImageWithEvents> texturePool = new HashMap<>();

public static Texture get(String filename) {
GLTextureFromImage textureFromImage = texturePool.get(filename);
/**
* Get a texture from the pool. If the texture does not exist, use the {@link ImageFactory} create it.
* @param sourceName the name of the texture to get.
* @return the texture.
*/
public static Texture get(String sourceName) {
GLTextureFromImageWithEvents textureFromImage = texturePool.get(sourceName);
if (textureFromImage == null) {
ImageWithEvents img = ImageFactory.get(filename);
ImageWithEvents img = ImageFactory.get(sourceName);
if(img==null) {
return null;
}
if(img.image==null) {
return null;
}
textureFromImage = new GLTextureFromImage(img);
texturePool.put(filename, textureFromImage);
textureFromImage = new GLTextureFromImageWithEvents(img);
texturePool.put(sourceName, textureFromImage);
}
return textureFromImage.getTexture();
}

public static void unloadAll(GL3 gl) {
for (GLTextureFromImage t : texturePool.values()) {
for (GLTextureFromImageWithEvents t : texturePool.values()) {
t.destroy(gl);
}
}
Expand Down

0 comments on commit 68c96dc

Please sign in to comment.