package client.renderer.texture;

import java.awt.image.BufferedImage;
import java.awt.image.ImageObserver;
import java.io.IOException;
import java.io.InputStream;
import java.util.List;

import client.util.FileUtils;
import common.collect.Lists;
import common.log.Log;

public class LayeredTexture extends Texture
{
    public final List<String> layers;

    public LayeredTexture(String[] layers)
    {
        this.layers = Lists.newArrayList(layers);
    }

    public void loadTexture() throws IOException
    {
        this.deleteGlTexture();
        BufferedImage bufferedimage = null;

        try
        {
            for (String s : this.layers)
            {
                if (s != null)
                {
                    InputStream inputstream = FileUtils.getResource(s);
                    BufferedImage bufferedimage1 = TextureUtil.readImage(inputstream);

                    if (bufferedimage == null)
                    {
                        bufferedimage = new BufferedImage(bufferedimage1.getWidth(), bufferedimage1.getHeight(), 2);
                    }

                    bufferedimage.getGraphics().drawImage(bufferedimage1, 0, 0, (ImageObserver)null);
                }
            }
        }
        catch (IOException ioexception)
        {
        	Log.IO.error((Throwable)ioexception, (String)"Konnte Bild mit mehreren Schichten nicht laden");
            return;
        }

        TextureUtil.uploadImage(this.getGlTextureId(), bufferedimage);
    }
}
