using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using VisimBox.Renderer;
using VisimBox.Resources;
using OpenTK.Graphics.OpenGL;

namespace VisimRenderGL
{
    class GLIndexManager : IndexBufferManager
    {

        public override IIndexBuffer CreateBuffer(int[] indices, VisimBox.Resources.ResourceUsage usage = ResourceUsage.Static)
        {
            GLIndexBuffer gvb;
            try
            {
                gvb = new GLIndexBuffer(indices, false, usage);
            }
            catch (Exception ex)
            {
                throw new ArgumentException("Can't create vertex buffer!", ex);
            }
            return gvb;
        }

        public override void BindBuffer(IIndexBuffer vb)
        {
            if (!(vb is GLIndexBuffer))
            {
                VisimBox.Console.DebugLine("Index buffer is not GL ibo!");
                return;
            }
            GLIndexBuffer gvb = vb as GLIndexBuffer;
            gvb.BindBuffer();
        }

        public override void UnBindBuffer()
        {
            GL.BindBuffer(BufferTarget.ElementArrayBuffer, 0);
        }
    }
}
