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

namespace VisimRenderGL
{
    class GLVertexBufferManager : VertexBufferManager
    {
        
        public override void BindBuffer(IVertexBuffer vb)
        {
            if (!(vb is GLVertexBuffer))
            {
                VisimBox.Console.DebugLine("Vertex buffer is not GL vbo!");
                return;
            }
            GLVertexBuffer gvb = vb as GLVertexBuffer;
            gvb.BindBuffer();
        }

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

        public override IVertexBuffer CreateBuffer(IVertexArray varray, ResourceUsage usage = ResourceUsage.Static)
        {
            GLVertexBuffer gvb;
            try
            {
                gvb = new GLVertexBuffer(varray, false, usage);
            }
            catch (Exception ex)
            {
                throw new ArgumentException("Can't create vertex buffer!", ex);
            }
            return gvb;
        }
    }
}
