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[] data;
	private final int width;
	private final int height;

	public DynamicTexture(BufferedImage image) {
		this(image.getWidth(), image.getHeight());
		image.getRGB(0, 0, image.getWidth(), image.getHeight(), this.data, 0, image.getWidth());
		this.updateTexture();
	}

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

	public void loadTexture() throws IOException {
	}

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

	public int[] getData() {
		return this.data;
	}

	public int getWidth() {
		return this.width;
	}

	public int getHeight() {
		return this.height;
	}
}
