package speiger.src.coreengine.rendering.gui.renderer;

import java.nio.FloatBuffer;

import org.lwjgl.opengl.GL15;

import speiger.src.coreengine.rendering.models.BufferAttribute;
import speiger.src.coreengine.rendering.models.VertexArray;

public class GuiModel extends VertexArray
{
	protected int count;

	public GuiModel(int instances, BufferAttribute... attr)
	{
		bind();
		createBuffer(attr).setDataType(GL15.GL_STREAM_DRAW).allocateMemory(instances).unbind();
		unbind();
	}
		
	public static GuiModel createTextureModel(int instances)
	{
		return new GuiModel(instances * 9, new BufferAttribute(0, 3), new BufferAttribute(1, 2), new BufferAttribute(2, 4));
	}
	
	@Override
	public int getVertexCount()
	{
		return count;
	}
	
	public GuiModel setData(float[] data, int vertexes)
	{
		count = vertexes;
		getBuffer(0).bind().setBufferData(data).unbind();
		return this;
	}
	
	public GuiModel storeData(float[] data, int vertexes)
	{
		count = vertexes;
		getBuffer(0).bind().fillBuffer(0, data).unbind();
		return this;
	}
	
	public GuiModel storeData(FloatBuffer buffer)
	{
		getBuffer(0).bind().fillExternalBuffer(buffer, 0).unbind();
		return this;
	}
}
