using System;
using static Quik.OpenGL.GLEnum;

namespace Quik.OpenGL
{
    [System.Serializable]
    public class GraphicsException : System.Exception
    {
        public GraphicsException()
        {
            AddExtraData();
        }

        public GraphicsException(string message) : base(message)
        {
            AddExtraData();
        }

        public GraphicsException(string message, System.Exception inner) : base(message, inner)
        {
            AddExtraData();
        }

        protected GraphicsException(
            System.Runtime.Serialization.SerializationInfo info,
            System.Runtime.Serialization.StreamingContext context) : base(info, context)
        {
            AddExtraData();
        }

        private void AddExtraData()
        {
            GL.Get(GL_MAJOR_VERSION, out int major);
            GL.Get(GL_MINOR_VERSION, out int minor);

            string version = GL.GetString(GL_VERSION);
            string vendor   = GL.GetString(GL_VENDOR);
            string renderer = GL.GetString(GL_RENDERER);

            Data.Add("OpenGL Version", new Version(major, minor));
            Data.Add("OpenGL Version String", version);
            Data.Add("OpenGL Vendor", vendor);
            Data.Add("OpenGL Renderer", renderer);
        }
    }
}