/// <summary>
        /// Initializes a new instance of the SDL2UltravioletInput class.
        /// </summary>
        /// <param name="uv">The Ultraviolet context.</param>
        public SDL2UltravioletInput(UltravioletContext uv)
            : base(uv)
        {
            this.softwareKeyboardService = uv.GetFactoryMethod<SoftwareKeyboardServiceFactory>()();

            this.keyboard = new SDL2KeyboardDevice(uv);
            this.mouse = new SDL2MouseDevice(uv);
            this.gamePadInfo = new GamePadDeviceInfo(uv);
            this.gamePadInfo.GamePadConnected += OnGamePadConnected;
            this.gamePadInfo.GamePadDisconnected += OnGamePadDisconnected;
            this.touchInfo = new TouchDeviceInfo(uv);
        }
        /// <summary>
        /// Initializes a new instance of the SDL2UltravioletInput class.
        /// </summary>
        /// <param name="uv">The Ultraviolet context.</param>
        public SDL2UltravioletInput(UltravioletContext uv)
            : base(uv)
        {
            this.softwareKeyboardService = uv.GetFactoryMethod <SoftwareKeyboardServiceFactory>()();

            this.keyboard    = new SDL2KeyboardDevice(uv);
            this.mouse       = new SDL2MouseDevice(uv);
            this.gamePadInfo = new GamePadDeviceInfo(uv);
            this.gamePadInfo.GamePadConnected    += OnGamePadConnected;
            this.gamePadInfo.GamePadDisconnected += OnGamePadDisconnected;
            this.touchInfo = new TouchDeviceInfo(uv);
        }
        /// <summary>
        /// Initializes a new instance of the SDL2UltravioletInput class.
        /// </summary>
        /// <param name="uv">The Ultraviolet context.</param>
        public SDL2UltravioletInput(UltravioletContext uv)
            : base(uv)
        {
            this.softwareKeyboardService = uv.GetFactoryMethod <SoftwareKeyboardServiceFactory>()();

            this.keyboard    = new SDL2KeyboardDevice(uv);
            this.mouse       = new SDL2MouseDevice(uv);
            this.gamePadInfo = new GamePadDeviceInfo(uv);
            this.gamePadInfo.GamePadConnected    += OnGamePadConnected;
            this.gamePadInfo.GamePadDisconnected += OnGamePadDisconnected;
            this.touchInfo = new TouchDeviceInfo(uv);

            LoadGameControllerMappingDatabase(uv);

            uv.Messages.Subscribe(this,
                                  UltravioletMessages.TextInputRegionChanged);
        }
        /// <summary>
        /// Initializes a new instance of the OpenGLUltravioletGraphics class.
        /// </summary>
        /// <param name="uv">The Ultraviolet context.</param>
        /// <param name="configuration">The Ultraviolet Framework configuration settings for the current context.</param>
        public unsafe OpenGLUltravioletGraphics(UltravioletContext uv, UltravioletConfiguration configuration) : base(uv)
        {
            var glGraphicsConfiguration = configuration.GraphicsConfiguration as OpenGLGraphicsConfiguration;

            if (glGraphicsConfiguration == null)
            {
                throw new InvalidOperationException(OpenGLStrings.InvalidGraphicsConfiguration);
            }

            this.OpenGLEnvironment = uv.GetFactoryMethod <OpenGLEnvironmentFactory>()(uv);

            InitOpenGLVersion(glGraphicsConfiguration, out var versionRequested, out var versionRequired, out var isGLES);
            InitOpenGLEnvironment(glGraphicsConfiguration, isGLES);

            uv.GetPlatform().InitializePrimaryWindow(configuration);

            if (this.context == IntPtr.Zero && configuration.Debug)
            {
                this.context = TryCreateOpenGLContext(uv, OpenGLEnvironment, versionRequested, versionRequired, true, false) ?? IntPtr.Zero;
            }

            if (this.context == IntPtr.Zero)
            {
                this.context = TryCreateOpenGLContext(uv, OpenGLEnvironment, versionRequested, versionRequired, false, true) ?? IntPtr.Zero;
            }

            if (!OpenGLEnvironment.SetSwapInterval(1) && uv.Platform != UltravioletPlatform.iOS)
            {
                OpenGLEnvironment.ThrowPlatformErrorException();
            }

            if (gl.Initialized)
            {
                gl.Uninitialize();
            }

            gl.Initialize(new OpenGLInitializer(OpenGLEnvironment));

            if (!gl.IsVersionAtLeast(versionRequested ?? versionRequired))
            {
                throw new InvalidOperationException(OpenGLStrings.DoesNotMeetMinimumVersionRequirement.Format(gl.MajorVersion, gl.MinorVersion, versionRequested.Major, versionRequested.Minor));
            }

            OpenGLState.ResetCache();

            if (!VerifyCapabilities())
            {
                throw new NotSupportedException(OpenGLStrings.UnsupportedGraphicsDevice);
            }

            if (configuration.Debug && configuration.DebugCallback != null)
            {
                InitializeDebugOutput(configuration);
            }

            this.Capabilities = new OpenGLGraphicsCapabilities(configuration);

            if (Capabilities.SrgbEncodingEnabled && gl.IsFramebufferSrgbAvailable)
            {
                gl.Enable(gl.GL_FRAMEBUFFER_SRGB);
                gl.ThrowIfError();
            }

            this.maxTextureStages            = gl.GetInteger(gl.GL_MAX_TEXTURE_IMAGE_UNITS);
            this.textures                    = new Texture[maxTextureStages];
            this.samplerStates               = new SamplerState[maxTextureStages];
            this.samplerObjects              = Capabilities.SupportsIndependentSamplerState ? new OpenGLSamplerObject[maxTextureStages] : null;
            this.backBufferRenderTargetUsage = glGraphicsConfiguration.BackBufferRenderTargetUsage;

            if (samplerObjects != null)
            {
                for (int i = 0; i < samplerObjects.Length; i++)
                {
                    samplerObjects[i] = new OpenGLSamplerObject(Ultraviolet);
                    samplerObjects[i].Bind((uint)i);
                }
            }

            OpenGLState.VerifyCache();
            ResetDeviceStates();
        }