package client.renderer.texture;

import java.awt.image.BufferedImage;
import java.io.IOException;

import client.renderer.GlState;

public class DynamicTexture extends Texture
{
    private final int[] dynamicTextureData;

    /** width of this icon in pixels */
    private final int width;

    /** height of this icon in pixels */
    private final int height;

    public DynamicTexture(BufferedImage bufferedImage)
    {
        this(bufferedImage.getWidth(), bufferedImage.getHeight());
        bufferedImage.getRGB(0, 0, bufferedImage.getWidth(), bufferedImage.getHeight(), this.dynamicTextureData, 0, bufferedImage.getWidth());
        this.updateDynamicTexture();
    }

    public DynamicTexture(int textureWidth, int textureHeight)
    {
        this.width = textureWidth;
        this.height = textureHeight;
        this.dynamicTextureData = new int[textureWidth * textureHeight];
        TextureUtil.allocateTexture(this.getGlTextureId(), textureWidth, textureHeight);
    }

    public void loadTexture() throws IOException
    {
    }

    public void updateDynamicTexture()
    {
        GlState.bindTexture(this.getGlTextureId());
		TextureUtil.uploadTexture(this.dynamicTextureData, this.width, this.height, 0, 0);
    }

    public int[] getTextureData()
    {
        return this.dynamicTextureData;
    }
    
    public int getWidth() {
    	return this.width;
    }
    
    public int getHeight() {
    	return this.height;
    }
}
