protected void addToCache(Image image, Texture texture) {
    if (clearCachePolicy instanceof Number) {
      int maxSize = ((Number) clearCachePolicy).intValue();
      if (imageCache.size() > maxSize) {
        if (LOGGER.isLoggable(Level.FINE)) {
          LOGGER.fine("Clearing texture cache with size " + imageCache.size());
        }

        imageCache.clear();
      }
    }

    imageCache.put(image, texture);
  }
  @Override
  public void setG2D(GLGraphics2D g2d) {
    this.g2d = g2d;

    if (clearCachePolicy == VALUE_CLEAR_TEXTURES_CACHE_EACH_PAINT) {
      imageCache.clear();
    }
  }
  /**
   * Cache the texture if possible. I have a feeling this will run into issues later as images
   * change. Just not sure how to handle it if they do. I suspect I should be using the
   * ImageConsumer class and dumping pixels to the screen as I receive them.
   *
   * <p>If an image is a BufferedImage, turn it into a texture and cache it. If it's not, draw it to
   * a BufferedImage and see if all the image data is available. If it is, cache it. If it's not,
   * don't cache it. But if not all the image data is available, we will draw it what we have, since
   * we draw anything in the image to a BufferedImage.
   */
  protected Texture getTexture(Image image, ImageObserver observer) {
    Texture texture = imageCache.get(image);
    if (texture == null) {
      BufferedImage bufferedImage;
      if (image instanceof BufferedImage
          && ((BufferedImage) image).getType() != BufferedImage.TYPE_CUSTOM) {
        bufferedImage = (BufferedImage) image;
      } else {
        bufferedImage = toBufferedImage(image);
      }

      if (bufferedImage != null) {
        texture = create(bufferedImage);
        addToCache(image, texture);
      }
    }

    return texture;
  }
 @Override
 public void dispose() {
   imageCache.clear();
 }