Problem with Dynamic Textures


I have a number of Quad Spatials (8) rendered in an orthographic perspective each of width and height equal to that of the display windows.

Each of these Quads has a TextureState which in turn has a Texture.  These 8 textures are assigned Dynamically created images using BufferedImage objects equal to the width and height of the display window (see code extract 1).

Extract 1:

// determines offset position for translating quad
offsetWidth = display.getWidth() * i;
offsetHeight = display.getHeight() * j;

// object handles dynamic creation of image for texturing.
background = new Background(display);

texture = new Texture();
texture.setBlendColor(new ColorRGBA(1, 1, 1, 1));

textureState = display.getRenderer().createTextureState();

quad = new Quad("Background quad", background.getWidth(), background.getHeight());
quad.setLocalTranslation(new Vector3f((background.getWidth()/2) + offsetWidth, (background.getHeight()/2) + offsetHeight, 0));
quad.getLocalRotation().set(0, 0, 0, 1);
quad.getLocalScale().set(1, 1, 1);

The Background class extends com.jme.image.Image and takes a display object (with the display windows width and height) and calculates the next highest power of 2 for both the width and height of the image (see code extract 2).

Extract 2:

power = 1;

do {
   if(width <= (power*2)) {

   power *= 2;
} while(true);

if(width < (power*2)) {
   width = (power*2);

power = 1;

do {
   if(height <= (power*2)) {

   power *= 2;
} while(true);

if(height < (power*2)) {
   height = (power*2);

This buffered image is then drawn on using the Graphics2D context and subsequently applied to the aforementioned Texture class (code extract 1). These 8 Quads are used to tile two background layers (4 Quads for each layer) horizontally and vertically.

The problem is, when executing the application with a display width and height of 1280 x 960 the application terminates with an OutOfMemory (heap) error.  Im assuming this is because the next highest power of two for these values are 2048 x 1024.

So, is there no better (more efficient) method of drawing an image to an orthographic Quad.  For example; tilling a smaller image than the display width/height (whilst maintaining its resolution) - either by dynamically creating a smaller image, or importing an image file, and tilling these? (And without increasing the heap size via VM args [-xms -xmx])  These images are never/will never be repainted during the execution of the application, unless the display size is altered.

How can a simple (alpha) image consume so much memory?

It may be that each time you adjust an image, TextureCache is actually holding on to all old copies.

But I do not alter the images after they are initially set.  Is it possible to tile an image across an orthographic quad without causing the image to stretch to the quads boundaries?

Basically I just want to apply an image to a quad which doesnt stretch/squash when the quad size is altered.